private Schema getCustomProcessorInputSchema (Map config) throws IOException { return Utils.getSchemaFromConfig((Map) config.get(TopologyLayoutConstants.JSON_KEY_INPUT_SCHEMA)); }
/** * Generates the next name for the given name and suffix. * <p> * E.g. {@code getNextName("test-foo", "-foo") returns "test-foo2", * getNextName("test-foo2", "-foo") returns "test-foo3"} * </p> * @param name the current name * @param suffix the suffix without the number part * @return the next name */ public static String getNextName(String name, String suffix) { Utils.requireNonEmpty(name, "Empty name"); String prefix; String suffixWithNum; int num = getNumPart(name, suffix); if (num == -1) { prefix = name; suffixWithNum = suffix; } else { prefix = getPrefix(name, suffix); suffixWithNum = suffix + (num + 1); } return prefix + suffixWithNum; }
public StreamlineEventModelOutputs(String modelProcessorJson) { this(Utils.createObjectFromJson(modelProcessorJson, ModelProcessor.class)); }
Optional<String> getLatestCloneName(String topologyName, Collection<Topology> topologies) { return Utils.getLatestName( topologies.stream().map(Topology::getName).collect(Collectors.toSet()), Utils.getPrefix(topologyName, CLONE_SUFFIX), CLONE_SUFFIX); }
public TopologyState getTopologyState(String stateName) { Utils.requireNonEmpty(stateName, "State name cannot be empty"); TopologyState state = states.get(stateName); if (state == null) { throw new IllegalArgumentException("No such state " + stateName); } return state; }
String getNextCloneName(String topologyName) { return Utils.getNextName(topologyName, CLONE_SUFFIX); }
/** * Returns the latest name from a given list of names that matches the given prefix and suffix part. * <p> * E.g. * {@code getLatestName(["test-foo2", "test-foo10", "other", "test-foo1"], "test", "-foo") returns "test-foo10"} * </p> * @param names * @param prefix * @param suffix * @return */ public static Optional<String> getLatestName(Collection<String> names, String prefix, String suffix) { return names.stream() .filter(n -> n.startsWith(prefix)) .max((n1, n2) -> Utils.getNumPart(n1, suffix) - Utils.getNumPart(n2, suffix)); } /**
private void validateRole(Role role) { Utils.requireNonEmpty(role.getName(), "Role name"); if (StringUtils.isNumeric(role.getName())) { throw new IllegalArgumentException("Role name cannot be numeric"); } StorageUtils.ensureUnique(role, this::listRoles, QueryParam.params(User.NAME, role.getName())); }
/** * This method takes in a schema represented as a map and returns a {@link Schema} * @param schemaConfig A map representing {@link Schema} * @return schema generated from the map argument * @throws IOException */ public static Schema getSchemaFromConfig (Map schemaConfig) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); return getSchemaFromConfig(objectMapper.writeValueAsString(schemaConfig)); } /**
private void validateUser(User user) { Utils.requireNonEmpty(user.getName(), "User name"); StorageUtils.ensureUnique(user, this::listUsers, QueryParam.params(User.NAME, user.getName())); }
public RulesBolt(String rulesProcessorJson, RuleProcessorRuntime.ScriptType scriptType) { this(Utils.createObjectFromJson(rulesProcessorJson, RulesProcessor.class), scriptType); }
private Map<String, Schema> getCustomProcessorOutputSchema (Map config) throws IOException { Map<String, Schema> result = new LinkedHashMap<>(); Map<String, Object> outputSchemaConfig = (Map<String, Object>) config.get(TopologyLayoutConstants.JSON_KEY_OUTPUT_STREAMS_SCHEMA); for (Map.Entry<String, Object> entry: outputSchemaConfig.entrySet()) { result.put(entry.getKey(), Utils.getSchemaFromConfig((Map) entry.getValue())); } return result; }
public WindowRulesBolt(String rulesProcessorJson, RuleProcessorRuntime.ScriptType scriptType) { this(Utils.createObjectFromJson(rulesProcessorJson, RulesProcessor.class), scriptType); }
/** * Associate output schema that is a json string * @param outputSchemaJson * @return */ public CustomProcessorBolt outputSchema (String outputSchemaJson) { ObjectMapper mapper = new ObjectMapper(); Map<String,Schema> outputSchema = new HashMap<>(); try { Map<String, Map> output = mapper.readValue(outputSchemaJson, Map.class); for (Map.Entry<String, Map> entry: output.entrySet()) { outputSchema.put(entry.getKey(), Utils.getSchemaFromConfig(entry.getValue())); } } catch (IOException e) { LOG.error("Error during deserialization of output schema JSON string: {}", outputSchemaJson, e); throw new RuntimeException(e); } return outputSchema(outputSchema); }
public TestRunSinkBolt(String testRunSinkJson) { this(Utils.createObjectFromJson(testRunSinkJson, TestRunSink.class)); }
public static CustomProcessorInfo fromTopologyComponentBundle(TopologyComponentBundle topologyComponentBundle) throws IOException { Preconditions.checkNotNull(topologyComponentBundle, "topologyComponentBundle can not bre null"); ComponentUISpecification topologyComponentUISpecification = topologyComponentBundle.getTopologyComponentUISpecification(); List<ComponentUISpecification.UIField> uiFields = topologyComponentUISpecification.getFields(); Map<String, String> config = getPropertiesFromUIFields(uiFields); return new CustomProcessorInfo(config.get(NAME), config.get(DESCRIPTION), topologyComponentBundle.getStreamingEngine(), config.get(JAR_FILE_NAME), config.get(CUSTOM_PROCESSOR_IMPL), Utils.getSchemaFromConfig(config.get(INPUT_SCHEMA)), Utils.getSchemaFromConfig(config.get(OUTPUT_SCHEMA)), getCustomProcessorUISpecification(topologyComponentUISpecification), config.get(DIGEST)); }
public TestRunSourceSpout(String testRunSourceJson) { this(Utils.createObjectFromJson(testRunSourceJson, TestRunSource.class)); }
@Override public void validateConfig () throws ComponentConfigException { super.validateConfig(); validateStringFields(); String fieldToValidate = TopologyLayoutConstants.JSON_KEY_OUTPUT_STREAMS_SCHEMA; try { Map<String, Map> outputSchema = (Map) conf.get(fieldToValidate); if (outputSchema == null || outputSchema.keySet().isEmpty()) { throw new ComponentConfigException(String.format(TopologyLayoutConstants.ERR_MSG_MISSING_INVALID_CONFIG, fieldToValidate)); } for (Map.Entry<String, Map> entry: outputSchema.entrySet()) { Utils.getSchemaFromConfig(entry.getValue()); } this.validateCustomConfigFields(); } catch (ClassCastException|IOException e) { throw new ComponentConfigException(String.format(TopologyLayoutConstants.ERR_MSG_MISSING_INVALID_CONFIG, fieldToValidate)); } }
public NormalizationBolt(String normalizationProcessorJson) { this(Utils.createObjectFromJson(normalizationProcessorJson, NormalizationProcessor.class)); }
@Override public ModelRunner newModelRunner() { final ModelProcessor modelProcessor = Utils.createObjectFromJson(modelProcessorJson, ModelProcessor.class); PMML pmmlModel; try { pmmlModel = JpmmlFactory.newPmml( new ByteArrayInputStream(modelProcessor.getPmml().getBytes())); } catch (Exception e) { throw new RuntimeException("Exception occurred while creating PMML model object", e); } return new StreamlineJPMMLModelRunner( modelProcessor.getOutputStreams(), modelProcessor.getId(), JpmmlFactory.newEvaluator(pmmlModel), modelOutputs); } }