private static ComponentUISpecification getCustomProcessorUISpecification (ComponentUISpecification componentUISpecification) { ComponentUISpecification result = new ComponentUISpecification(); List<ComponentUISpecification.UIField> fields = new ArrayList<>(); for (ComponentUISpecification.UIField uiField: componentUISpecification.getFields()) { if (uiField.getFieldName().startsWith(TopologyLayoutConstants.JSON_KEY_CUSTOM_PROCESSOR_PREFIX)) { ComponentUISpecification.UIField newUIField = new ComponentUISpecification.UIField(uiField); newUIField.setFieldName(uiField.getFieldName().replaceFirst(TopologyLayoutConstants.JSON_KEY_CUSTOM_PROCESSOR_PREFIX_REGEX, "")); fields.add(newUIField); } } result.setFields(fields); return (result.getFields().isEmpty() ? null : result); }
private List<ComponentUISpecification.UIField> getCustomProcessorUIFieldsWithPrefix () { List<ComponentUISpecification.UIField> result = new ArrayList<>(); if (topologyComponentUISpecification != null) { for (ComponentUISpecification.UIField uiField : this.topologyComponentUISpecification.getFields()) { ComponentUISpecification.UIField newUIField = new ComponentUISpecification.UIField(uiField); newUIField.setFieldName(TopologyLayoutConstants.JSON_KEY_CUSTOM_PROCESSOR_PREFIX + uiField.getFieldName()); result.add(newUIField); } } return result; }
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)); }
private Collection<TopologyComponentBundle> listCustomProcessorBundlesWithFilter(List<QueryParam> params) throws IOException { List<QueryParam> queryParamsForTopologyComponent = new ArrayList<>(); queryParamsForTopologyComponent.add(new QueryParam(TopologyComponentBundle.SUB_TYPE, TopologyLayoutConstants.JSON_KEY_CUSTOM_PROCESSOR_SUB_TYPE)); for (QueryParam qp : params) { if (qp.getName().equals(TopologyComponentBundle.STREAMING_ENGINE)) { queryParamsForTopologyComponent.add(qp); } } Collection<TopologyComponentBundle> customProcessors = this.listTopologyComponentBundlesForTypeWithFilter(TopologyComponentBundle.TopologyComponentType .PROCESSOR, queryParamsForTopologyComponent); Collection<TopologyComponentBundle> result = new ArrayList<>(); for (TopologyComponentBundle cp : customProcessors) { Map<String, Object> config = new HashMap<>(); for (ComponentUISpecification.UIField uiField: cp.getTopologyComponentUISpecification().getFields()) { config.put(uiField.getFieldName(), uiField.getDefaultValue()); } boolean matches = true; for (QueryParam qp : params) { if (!qp.getName().equals(TopologyComponentBundle.STREAMING_ENGINE) && !qp.getValue().equals(config.get(qp.getName()))) { matches = false; break; } } if (matches) { result.add(cp); } } return result; }
List<String> fileFieldNames = specification.getFields().stream() .filter(uiField -> uiField.getType().equals(ComponentUISpecification.UIFieldType.FILE)) .map(uiField -> uiField.getFieldName())