From notifications-return-41838-archive-asf-public=cust-asf.ponee.io@accumulo.apache.org Wed Jan 31 01:01:28 2018 Return-Path: X-Original-To: archive-asf-public@eu.ponee.io Delivered-To: archive-asf-public@eu.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by mx-eu-01.ponee.io (Postfix) with ESMTP id C68A118066D for ; Wed, 31 Jan 2018 01:01:28 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id B6A1C160C53; Wed, 31 Jan 2018 00:01:28 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 0CEAA160C54 for ; Wed, 31 Jan 2018 01:01:27 +0100 (CET) Received: (qmail 80126 invoked by uid 500); 31 Jan 2018 00:01:27 -0000 Mailing-List: contact notifications-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jira@apache.org Delivered-To: mailing list notifications@accumulo.apache.org Received: (qmail 80103 invoked by uid 99); 31 Jan 2018 00:01:27 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 31 Jan 2018 00:01:27 +0000 From: GitBox To: notifications@accumulo.apache.org Subject: [GitHub] keith-turner commented on a change in pull request #370: ACCUMULO-4772 Update shell to use NewTableConfiguration methods Message-ID: <151735688649.18335.7828743457997357983.gitbox@gitbox.apache.org> keith-turner commented on a change in pull request #370: ACCUMULO-4772 Update shell to use NewTableConfiguration methods URL: https://github.com/apache/accumulo/pull/370#discussion_r164916437 ########## File path: shell/src/main/java/org/apache/accumulo/shell/commands/CreateTableCommand.java ########## @@ -150,9 +169,83 @@ public int execute(final String fullCommand, final CommandLine cl, final Shell s return 0; } + /** + * Add supplied locality groups information to a NewTableConfiguration object. + * + * Used in conjunction with createtable shell command to allow locality groups to be configured upon table creation. + */ + private NewTableConfiguration setLocalityForNewTable(CommandLine cl, NewTableConfiguration ntc) { + HashMap> localityGroupMap = new HashMap<>(); + String[] options = cl.getOptionValues(createTableOptLocalityProps.getOpt()); + for (String localityInfo : options) { + final String parts[] = localityInfo.split("=", 2); + if (parts.length < 2) + throw new IllegalArgumentException("Missing '=' or there are spaces between entries"); + final String groupName = parts[0]; + final HashSet colFams = new HashSet<>(); + for (String family : parts[1].split(",")) + colFams.add(new Text(family.getBytes(Shell.CHARSET))); + if (localityGroupMap.containsKey(groupName)) + throw new IllegalArgumentException("Duplicate locality group name found. Group names must be unique"); + localityGroupMap.put(groupName, colFams); + } + ntc.setLocalityGroups(localityGroupMap); + return ntc; + } + + /** + * Add supplied iterator information to NewTableConfiguration object. + * + * Used in conjunction with createtable shell command to allow an iterator to be configured upon table creation. + */ + private NewTableConfiguration attachIteratorToNewTable(CommandLine cl, Shell shellState, NewTableConfiguration ntc) { + if (shellState.iteratorProfiles.size() == 0) + throw new IllegalArgumentException("No shell iterator profiles have been created."); + String[] options = cl.getOptionValues(createTableOptIteratorProps.getOpt()); + for (String profileInfo : options) { + String[] parts = profileInfo.split(":", 2); + if (parts.length < 2) + throw new IllegalArgumentException("Missing scope or there are spaces between parameters"); + // get profile name + String profileName = parts[0]; + IteratorSetting iteratorSetting = shellState.iteratorProfiles.get(profileName).get(0); + if (iteratorSetting == null) + throw new IllegalArgumentException("Provided iterator profile, " + profileName + ", does not exist"); + // parse scope info + List scopeList = Arrays.asList(parts[1].split(",")); Review comment: I would validate by calling `IteratorUtil.IteratorScope.valueOf()` for each item in scopeList. Could lower case the string before passing it to valueOf. I think valueOf will throw an exception if its not a valid enum. Can also add what valueOf returns to the set. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org With regards, Apache Git Services