private Number readNumberFromConfig(Config config, String parameterName) { try { return config.getAny(parameterName); } catch (ClassCastException e) { throw new IllegalArgumentException("Required parameter " + parameterName + " should be a number."); } }
public Map<String, Object> getNotifierFieldValues() { return getConfig().getAny(CONFIG_KEY_FIELD_VALUES); }
public Map<String, Object> getNotifierProperties() { return getConfig().getAny(CONFIG_KEY_PROPERTIES); }
@Override protected List<ServiceConfiguration> createServiceConfigurations(Config config) { ServiceConfiguration serviceConfiguration = new ServiceConfiguration(); serviceConfiguration.setName(Constants.Email.CONF_TYPE_PROPERTIES); Map<String, String> confMap = new HashMap<>(); confMap.put(PARAM_HOST, config.get(Constants.Email.PROPERTY_KEY_HOST)); confMap.put(PARAM_PORT, String.valueOf((Integer) config.getAny(Constants.Email.PROPERTY_KEY_PORT))); confMap.put(PARAM_SSL, String.valueOf((Boolean) config.getAny(Constants.Email.PROPERTY_KEY_SSL))); confMap.put(PARAM_STARTTLS, String.valueOf((Boolean) config.getAny(Constants.Email.PROPERTY_KEY_STARTTLS))); confMap.put(PARAM_PROTOCOL, config.get(Constants.Email.PROPERTY_KEY_PROTOCOL)); confMap.put(PARAM_AUTH, String.valueOf((Boolean) config.getAny(Constants.Email.PROPERTY_KEY_AUTH))); ObjectMapper objectMapper = new ObjectMapper(); try { String json = objectMapper.writeValueAsString(confMap); serviceConfiguration.setConfiguration(json); } catch (JsonProcessingException e) { throw new RuntimeException(e); } return Collections.singletonList(serviceConfiguration); }
@Override public StreamlineProcessor create(TopologyComponent component) { Object stageConfig = component.getConfig().getAny(StageProcessor.CONFIG_KEY_STAGE); ObjectMapper objectMapper = new ObjectMapper(); StageAction stageAction = objectMapper.convertValue(stageConfig, StageAction.class); StageProcessor stageProcessor = new StageProcessor(); stageProcessor.setStageAction(stageAction); return stageProcessor; } };
@Override public StreamlineProcessor create(TopologyComponent component) { Config config = component.getConfig(); Object typeObj = config.getAny(NormalizationProcessor.CONFIG_KEY_TYPE); Object normConfObj = config.getAny(NormalizationProcessor.CONFIG_KEY_NORMALIZATION); ObjectMapper objectMapper = new ObjectMapper(); NormalizationProcessor.Type type = objectMapper.convertValue(typeObj, NormalizationProcessor.Type.class); Map<String, NormalizationConfig> normConfig = objectMapper.convertValue(normConfObj, new TypeReference<Map<String, NormalizationConfig>>() { }); updateWithSchemas(component.getTopologyId(), component.getVersionId(), normConfig); Set<Stream> outputStreams; if (component instanceof TopologyOutputComponent) { outputStreams = createOutputStreams((TopologyOutputComponent) component); } else { throw new IllegalArgumentException("Component " + component + " must be an instance of TopologyOutputComponent"); } if (outputStreams.size() != 1) { throw new IllegalArgumentException("Normalization component [" + component + "] must have only one output stream"); } return new NormalizationProcessor(normConfig, outputStreams.iterator().next(), type); } };
private ServiceConfiguration buildZooCfgServiceConfiguration(Config config) { ServiceConfiguration zooCfg = new ServiceConfiguration(); zooCfg.setName(CONFIG_ZOO_CFG); Map<String, String> confMap = new HashMap<>(); if (config.contains(PARAM_ZOOKEEPER_PORT)) { Number zookeeperPort = config.getAny(PARAM_ZOOKEEPER_PORT); confMap.put(PARAM_ZOOKEEPER_PORT, String.valueOf(zookeeperPort)); } try { String json = objectMapper.writeValueAsString(confMap); zooCfg.setConfiguration(json); } catch (JsonProcessingException e) { throw new RuntimeException(e); } return zooCfg; } }
@Override public StreamlineProcessor create(TopologyComponent component) { Object splitConfig = component.getConfig().getAny(SplitProcessor.CONFIG_KEY_SPLIT); ObjectMapper objectMapper = new ObjectMapper(); SplitAction splitAction = objectMapper.convertValue(splitConfig, SplitAction.class); SplitProcessor splitProcessor = new SplitProcessor(); if (component instanceof TopologyOutputComponent) { splitProcessor.addOutputStreams(createOutputStreams((TopologyOutputComponent) component)); } else { throw new IllegalArgumentException("Component " + component + " must be an instance of TopologyOutputComponent"); } splitProcessor.setSplitAction(splitAction); return splitProcessor; } };
private Pair<Component, List<ComponentProcess>> createZookeeperServerComponent(Config config, Map<String, String> flattenConfigMap) { if (!config.contains(PARAM_ZOOKEEPER_SERVER_HOSTNAMES)) { throw new IllegalArgumentException("Required parameter " + PARAM_ZOOKEEPER_SERVER_HOSTNAMES + " not present."); } if (!config.contains(PARAM_ZOOKEEPER_PORT)) { throw new IllegalArgumentException("Required parameter " + PARAM_ZOOKEEPER_PORT + " not present."); } List<String> zookeeperServerHosts; try { zookeeperServerHosts = config.getAny(PARAM_ZOOKEEPER_SERVER_HOSTNAMES); } catch (ClassCastException e) { throw new IllegalArgumentException("Required parameter " + PARAM_ZOOKEEPER_SERVER_HOSTNAMES + " should be list of string."); } Number zookeeperPort; try { zookeeperPort = config.getAny(PARAM_ZOOKEEPER_PORT); } catch (ClassCastException e) { throw new IllegalArgumentException("Required parameter " + PARAM_ZOOKEEPER_PORT + " should be number."); } Component zookeeperServer = new Component(); zookeeperServer.setName(COMPONENT_ZOOKEEPER_SERVER); List<ComponentProcess> componentProcesses = zookeeperServerHosts.stream().map(host -> { ComponentProcess cp = new ComponentProcess(); cp.setHost(host); cp.setPort(zookeeperPort.intValue()); return cp; }).collect(toList()); return new Pair<>(zookeeperServer, componentProcesses); }
@Override public StreamlineProcessor create(TopologyComponent component) { RulesProcessor processor = new RulesProcessor(); ObjectMapper objectMapper = new ObjectMapper(); if (component instanceof TopologyOutputComponent) { Set<Stream> outputStreams = createOutputStreams((TopologyOutputComponent) component); processor.addOutputStreams(outputStreams); } else { throw new IllegalArgumentException("Component " + component + " must be an instance of TopologyOutputComponent"); } boolean processAll = component.getConfig().getBoolean(RulesProcessor.CONFIG_PROCESS_ALL, true); processor.setProcessAll(processAll); Object ruleList = component.getConfig().getAny(RulesProcessor.CONFIG_KEY_RULES); List<Long> ruleIds = objectMapper.convertValue(ruleList, new TypeReference<List<Long>>() { }); try { List<Rule> rules = new ArrayList<>(); for (Long ruleId : ruleIds) { rules.add(ruleExtractor.getRule(component.getTopologyId(), ruleId, component.getVersionId())); } processor.setRules(rules); } catch (Exception ex) { throw new RuntimeException(ex); } return processor; } };