private Schema getCustomProcessorInputSchema (Map config) throws IOException { return Utils.getSchemaFromConfig((Map) config.get(TopologyLayoutConstants.JSON_KEY_INPUT_SCHEMA)); }
/** * 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 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; }
/** * 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 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)); }
@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)); } }