/** * Verify the provided properties are valid table properties. */ private void checkTableProperties(Map<String,String> props) { props.keySet().forEach((key) -> { if (!key.startsWith(Property.TABLE_PREFIX.toString())) { throw new IllegalArgumentException("'" + key + "' is not a valid table property"); } }); } }
@Override public void removeConstraint(String namespace, int number) throws AccumuloException, AccumuloSecurityException, NamespaceNotFoundException { this.removeProperty(namespace, Property.TABLE_CONSTRAINT_PREFIX.toString() + number); }
@Override public void removeConstraint(String tableName, int number) throws AccumuloException, AccumuloSecurityException { this.removeProperty(tableName, Property.TABLE_CONSTRAINT_PREFIX.toString() + number); }
@Override public Map<String,Integer> listConstraints(String namespace) throws AccumuloException, NamespaceNotFoundException, AccumuloSecurityException { Map<String,Integer> constraints = new TreeMap<>(); for (Entry<String,String> property : this.getProperties(namespace)) { if (property.getKey().startsWith(Property.TABLE_CONSTRAINT_PREFIX.toString())) { if (constraints.containsKey(property.getValue())) throw new AccumuloException("Same constraint configured twice: " + property.getKey() + "=" + Property.TABLE_CONSTRAINT_PREFIX + constraints.get(property.getValue()) + "=" + property.getKey()); try { constraints.put(property.getValue(), Integer.parseInt( property.getKey().substring(Property.TABLE_CONSTRAINT_PREFIX.toString().length()))); } catch (NumberFormatException e) { throw new AccumuloException("Bad key for existing constraint: " + property); } } } return constraints; } }
@Override public Map<String,Integer> listConstraints(String tableName) throws AccumuloException, TableNotFoundException { Map<String,Integer> constraints = new TreeMap<>(); for (Entry<String,String> property : this.getProperties(tableName)) { if (property.getKey().startsWith(Property.TABLE_CONSTRAINT_PREFIX.toString())) { if (constraints.containsKey(property.getValue())) throw new AccumuloException("Same constraint configured twice: " + property.getKey() + "=" + Property.TABLE_CONSTRAINT_PREFIX + constraints.get(property.getValue()) + "=" + property.getKey()); try { constraints.put(property.getValue(), Integer.parseInt( property.getKey().substring(Property.TABLE_CONSTRAINT_PREFIX.toString().length()))); } catch (NumberFormatException e) { throw new AccumuloException("Bad key for existing constraint: " + property); } } } return constraints; } }
@Override public int addConstraint(String tableName, String constraintClassName) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { TreeSet<Integer> constraintNumbers = new TreeSet<>(); TreeMap<String,Integer> constraintClasses = new TreeMap<>(); int i; for (Entry<String,String> property : this.getProperties(tableName)) { if (property.getKey().startsWith(Property.TABLE_CONSTRAINT_PREFIX.toString())) { try { i = Integer.parseInt( property.getKey().substring(Property.TABLE_CONSTRAINT_PREFIX.toString().length())); } catch (NumberFormatException e) { throw new AccumuloException("Bad key for existing constraint: " + property); } constraintNumbers.add(i); constraintClasses.put(property.getValue(), i); } } i = 1; while (constraintNumbers.contains(i)) i++; if (constraintClasses.containsKey(constraintClassName)) throw new AccumuloException("Constraint " + constraintClassName + " already exists for table " + tableName + " with number " + constraintClasses.get(constraintClassName)); this.setProperty(tableName, Property.TABLE_CONSTRAINT_PREFIX.toString() + i, constraintClassName); return i; }
@Override public int addConstraint(String namespace, String constraintClassName) throws AccumuloException, AccumuloSecurityException, NamespaceNotFoundException { TreeSet<Integer> constraintNumbers = new TreeSet<>(); TreeMap<String,Integer> constraintClasses = new TreeMap<>(); int i; for (Entry<String,String> property : this.getProperties(namespace)) { if (property.getKey().startsWith(Property.TABLE_CONSTRAINT_PREFIX.toString())) { try { i = Integer.parseInt( property.getKey().substring(Property.TABLE_CONSTRAINT_PREFIX.toString().length())); } catch (NumberFormatException e) { throw new AccumuloException("Bad key for existing constraint: " + property); } constraintNumbers.add(i); constraintClasses.put(property.getValue(), i); } } i = 1; while (constraintNumbers.contains(i)) i++; if (constraintClasses.containsKey(constraintClassName)) throw new AccumuloException( "Constraint " + constraintClassName + " already exists for namespace " + namespace + " with number " + constraintClasses.get(constraintClassName)); this.setProperty(namespace, Property.TABLE_CONSTRAINT_PREFIX.toString() + i, constraintClassName); return i; }
if (entry.getKey().startsWith(Property.INSTANCE_PREFIX.toString())) { md.update(entry.getKey().getBytes(UTF_8)); md.update(entry.getValue().getBytes(UTF_8));
@Override protected void removePlugin(final CommandLine cl, final Shell shellState, final String tableName) throws AccumuloException, AccumuloSecurityException { super.removePlugin(cl, shellState, tableName); if (cl.hasOption(interpeterOption.getOpt())) { shellState.getAccumuloClient().tableOperations().removeProperty(tableName, Property.TABLE_INTERPRETER_CLASS.toString()); } } }
@Override protected void setPlugin(final CommandLine cl, final Shell shellState, final String tableName, final String className) throws AccumuloException, AccumuloSecurityException { super.setPlugin(cl, shellState, tableName, className); if (cl.hasOption(interpeterOption.getOpt())) { shellState.getAccumuloClient().tableOperations().setProperty(tableName, Property.TABLE_INTERPRETER_CLASS.toString(), className); } }
if (ent.getKey().equals(pluginProp.toString())) { Class<? extends T> pluginClazz; String[] args = new String[2];
protected void removePlugin(final CommandLine cl, final Shell shellState, final String tableName) throws AccumuloException, AccumuloSecurityException { shellState.getAccumuloClient().tableOperations().removeProperty(tableName, tableProp.toString()); }
protected void setPlugin(final CommandLine cl, final Shell shellState, final String tableName, final String className) throws AccumuloException, AccumuloSecurityException { shellState.getAccumuloClient().tableOperations().setProperty(tableName, tableProp.toString(), className); }
private static synchronized void loadSpanReceivers(Configuration conf) { if (!receivers.isEmpty()) { log.info("Already loaded span receivers, enable tracing does not need to be called again"); return; } String[] receiverNames = conf.getTrimmedStrings(Property.TRACE_SPAN_RECEIVERS.toString()); if (receiverNames == null || receiverNames.length == 0) { return; } for (String className : receiverNames) { SpanReceiverBuilder builder = new SpanReceiverBuilder(wrapHadoopConf(conf)); SpanReceiver rcvr = builder.spanReceiverClass(className.trim()).build(); if (rcvr == null) { log.warn("Failed to load SpanReceiver {}", className); } else { receivers.add(rcvr); log.debug("SpanReceiver {} was loaded successfully.", className); } } for (SpanReceiver rcvr : receivers) { org.apache.htrace.Trace.addReceiver(rcvr); } }
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception { final String tableName = OptUtil.getTableOpt(cl, shellState); if (cl.hasOption(removePluginOption.getOpt())) { // Remove the property removePlugin(cl, shellState, tableName); shellState.getReader().println("Removed " + pluginType + " on " + tableName); } else if (cl.hasOption(listPluginOption.getOpt())) { // Get the options for this table final Iterator<Entry<String,String>> iter = shellState.getAccumuloClient().tableOperations() .getProperties(tableName).iterator(); while (iter.hasNext()) { Entry<String,String> ent = iter.next(); // List all parameters with the property name if (ent.getKey().startsWith(tableProp.toString())) { shellState.getReader().println(ent.getKey() + ": " + ent.getValue()); } } } else { // Set the plugin with the provided options String className = cl.getOptionValue(pluginClassOption.getOpt()); // Set the plugin property on the table setPlugin(cl, shellState, tableName, className); } return 0; }
private static void enableTracing(String hostname, String service, String spanReceivers, String zookeepers, long timeout, String zkPath, Map<String,String> properties) { Configuration conf = new Configuration(false); conf.set(Property.TRACE_SPAN_RECEIVERS.toString(), spanReceivers); // remaining properties will be parsed through an HTraceConfiguration by SpanReceivers setProperty(conf, TRACER_ZK_HOST, zookeepers); setProperty(conf, TRACER_ZK_TIMEOUT, (int) timeout); setProperty(conf, TRACER_ZK_PATH, zkPath); for (Entry<String,String> property : properties.entrySet()) { setProperty(conf, property.getKey().substring(Property.TRACE_SPAN_RECEIVER_PREFIX.getKey().length()), property.getValue()); } if (hostname != null) { setProperty(conf, TRACE_HOST_PROPERTY, hostname); } if (service != null) { setProperty(conf, TRACE_SERVICE_PROPERTY, service); } org.apache.htrace.Trace.setProcessId(service); ShutdownHookManager.get().addShutdownHook(() -> { Trace.off(); closeReceivers(); }, 0); loadSpanReceivers(conf); }
@Override public void registerCompletion(final Token root, final Map<Command.CompletionSet,Set<String>> completionSet) { final Token cmd = new Token(getName()); final Token sub = new Token("-" + setOpt.getOpt()); for (Property p : Property.values()) { if (!(p.getKey().endsWith(".")) && !p.isExperimental()) { sub.addSubcommand(new Token(p.toString())); } } cmd.addSubcommand(sub); root.addSubcommand(cmd); }
Property.TABLE_FORMATTER_CLASS.toString(), formatterClass);
@Override public void removeConstraint(String namespace, int number) throws AccumuloException, AccumuloSecurityException, NamespaceNotFoundException { this.removeProperty(namespace, Property.TABLE_CONSTRAINT_PREFIX.toString() + number); }
protected void setPlugin(final CommandLine cl, final Shell shellState, final String tableName, final String className) throws AccumuloException, AccumuloSecurityException { shellState.getConnector().tableOperations().setProperty(tableName, tableProp.toString(), className); }