@SuppressWarnings("unchecked") @Override public synchronized void onAlertBoltSpecChange(AlertBoltSpec spec, Map<String, StreamDefinition> sds) { List<PolicyDefinition> newPolicies = spec.getBoltPoliciesMap().get(boltId); if (newPolicies == null) { LOG.info("no new policy with AlertBoltSpec {} for this bolt {}", spec, boltId); policyGroupEvaluator.onPolicyChange(spec.getVersion(), comparator.getAdded(), comparator.getRemoved(), comparator.getModified(), sds); spec.getPublishPartitions().forEach(p -> { if (newPolicies.stream().filter(o -> o.getName().equals(p.getPolicyId())).count() > 0) { newPublishPartitions.add(p); cachedPublishPartitions = newPublishPartitions; sdf = sds; specVersion = spec.getVersion(); this.spec = spec;
private AlertBoltSpec createAlertSpec() throws Exception { AlertBoltSpec spec = new AlertBoltSpec(); spec.setVersion("version1"); spec.setTopologyName("testTopology"); List<PolicyDefinition> policies = mapper.readValue(TestStateCheckPolicy.class.getResourceAsStream("/statecheck/policies.json"), new TypeReference<List<PolicyDefinition>>() { }); Assert.assertTrue(policies.size() > 0); spec.addBoltPolicy("alertBolt1", policies.get(0).getName()); spec.getBoltPoliciesMap().put("alertBolt1", new ArrayList<>(policies)); return spec; }
AlertBoltSpec alertSpec = alertSpecs.get(u.getTopoName()); if (alertSpec == null) { alertSpec = new AlertBoltSpec(u.getTopoName()); alertSpecs.put(u.getTopoName(), alertSpec); for (String policyName : boltUsage.getPolicies()) { PolicyDefinition definition = context.getPolicies().get(policyName); alertSpec.addBoltPolicy(boltUsage.getBoltId(), definition.getName()); alertSpec.addPublishPartition(streamId, policyName, publish.getName(), publish.getPartitionColumns());
private void prePopulate(AlertBoltSpec alertSpec, List<VersionedPolicyDefinition> list) { Map<String, PolicyDefinition> policyMap = listToMap(list); for (Entry<String, List<String>> policyEntry : alertSpec.getBoltPolicyIdsMap().entrySet()) { List<PolicyDefinition> pds = alertSpec.getBoltPoliciesMap().get(policyEntry.getKey()); if (pds == null) { pds = new ArrayList<PolicyDefinition>(); alertSpec.getBoltPoliciesMap().put(policyEntry.getKey(), pds); } for (String policyName : policyEntry.getValue()) { if (policyMap.containsKey(policyName)) { pds.add(policyMap.get(policyName)); } } } }
def.setPartitionSpec(Arrays.asList(createPartition())); AlertBoltSpec boltSpecs = new AlertBoltSpec(); AlertBolt bolt = createAlertBolt(collector); boltSpecs.getBoltPoliciesMap().put(bolt.getBoltId(), Arrays.asList(def)); boltSpecs.setVersion("spec_" + System.currentTimeMillis()); sds.put(sdTest.getStreamId(), sdTest); boltSpecs.addPublishPartition(TEST_STREAM, "policy-definition", "testAlertPublish", null); Tuple t = createTuple(bolt, boltSpecs.getVersion());
Assert.assertEquals(version, alertSpec.getVersion()); String topo1 = alertSpec.getTopologyName(); LOG.info("alert spec topology name {}", topo1); for (List<String> definitions : alertSpec.getBoltPolicyIdsMap().values()) { Assert.assertEquals(1, definitions.size()); Assert.assertEquals(TEST_POLICY_1, definitions.get(0)); Assert.assertEquals(version, alertSpec.getVersion()); String topo1 = alertSpec.getTopologyName(); LOG.info("alert spec topology name {}", topo1); Assert.assertEquals(0, alertSpec.getBoltPolicyIdsMap().size());
sds.put(sdTest.getStreamId(), sdTest); AlertBoltSpec boltSpecs = new AlertBoltSpec(); boltSpecs.setVersion("spec_version_" + System.currentTimeMillis()); boltSpecs.setTopologyName("alertUnitTopology_1"); def.setOutputStreams(Arrays.asList("out")); boltSpecs.getBoltPoliciesMap().put(bolt.getBoltId(), Arrays.asList(def)); bolt = createAlertBolt(collector); bolt.onAlertBoltSpecChange(boltSpecs, sds); Tuple input = createTuple(bolt, boltSpecs.getVersion()); bolt.execute(input);
@Test public void testAlertBoltSpec() { String topologyName = "testTopology"; AlertBoltSpec spec = new AlertBoltSpec(); List<String> topics = Arrays.asList("testTopic3", "testTopic4", "testTopic5"); for (String topic : topics) { sp.setSortSpec(sortSpec); spec.setVersion("version1"); spec.setTopologyName(topologyName); PolicyDefinition pd = new PolicyDefinition(); pd.setName("policy1"); pd.getDefinition().type = PolicyStreamHandlers.SIDDHI_ENGINE; pd.getDefinition().value = String.format("from %s[value=='xyz'] select value insert into testAlertStream;", streamId); spec.addBoltPolicy("alertBolt0", pd.getName()); Assert.assertEquals(topologyName, deserializedSpec.getTopologyName());
bolt.onAlertBoltSpecChange(new AlertBoltSpec(), new HashMap()); sds.put(sdTest.getStreamId(), sdTest); AlertBoltSpec boltSpecs = new AlertBoltSpec(); boltSpecs.setVersion("specVersion-" + System.currentTimeMillis()); def.setDefinition(definition); boltSpecs.getBoltPoliciesMap().put(bolt.getBoltId(), Arrays.asList(def));
new TypeReference<List<StreamDefinition>>() { }); spec.addPublishPartition("perfmon_latency_check_output2", policies.get(0).getName(), "testPublishBolt", null); sendData(alertBolt, definitionMap, spec.getBoltPoliciesMap().values().iterator().next().get(0));
try { IMetadataServiceClient client = new MetadataServiceClientImpl(this.getConfig()); String topologyId = spec.getTopologyName(); AlertBoltSpec latestSpec = client.getVersionedSpec().getAlertSpecs().get(topologyId); if (latestSpec != null) {
@Test public void testDataSources() throws Exception { InMemScheduleConext context = loadContext("/multi/"); TestTopologyMgmtService mgmtService = new TestTopologyMgmtService(4, 10); GreedyPolicyScheduler ps = new GreedyPolicyScheduler(); ps.init(context, mgmtService); ScheduleState state = ps.schedule(new ScheduleOption()); Assert.assertNotNull(state); Assert.assertEquals(2, state.getAssignments().size()); Assert.assertEquals(1, state.getAlertSpecs().size()); Assert.assertEquals(10, state.getAlertSpecs().get("alertUnitTopology_1").getBoltPolicyIdsMap().size()); }
ss.setVersion(version);
def.setPartitionSpec(Arrays.asList(createPartition())); AlertBoltSpec boltSpecs = new AlertBoltSpec(); AlertBolt bolt = createAlertBolt(collector); boltSpecs.getBoltPoliciesMap().put(bolt.getBoltId(), Arrays.asList(def)); boltSpecs.setVersion("spec_" + System.currentTimeMillis()); sds.put(sdTest.getStreamId(), sdTest); boltSpecs.addPublishPartition(TEST_STREAM, "policy-definition", "testAlertPublish", null); def.setDefinition(definition); def.setPartitionSpec(Arrays.asList(createPartition())); boltSpecs.getBoltPoliciesMap().put(bolt.getBoltId(), Arrays.asList(def)); Tuple t = createTuple(bolt, boltSpecs.getVersion());
Assert.assertEquals(version, alertSpec.getVersion()); String topo1 = alertSpec.getTopologyName(); LOG.info("alert spec topology name {}", topo1); for (List<String> definitions : alertSpec.getBoltPolicyIdsMap().values()) { Assert.assertEquals(2, definitions.size()); Assert.assertEquals(0, spec.getBoltPolicyIdsMap().size());
Assert.assertEquals(5, as.getBoltPolicyIdsMap().size()); for (List<String> pdList : as.getBoltPolicyIdsMap().values()) { Assert.assertEquals(1, pdList.size()); Assert.assertEquals(TEST_POLICY_3, pdList.get(0));
private void pushAlertBoltSpec(StreamPartition sp, AlertBolt bolt) { Map<String, StreamDefinition> sds = new HashMap<>(); sds.put("correlatedStream", createCorrelateStream("correlatedStream")); sds.put("symptomaticAlertOutputStream", createCorrelateStream("symptomaticAlertOutputStream")); // output of updated correlatedStream sds.put("deviceDownAlertStream", createCorrelateStream("deviceDownAlertStream")); PolicyDefinition pd = new PolicyDefinition(); pd.setName("network_symptomatic"); pd.setInputStreams(Arrays.asList("correlatedStream")); pd.setOutputStreams(Arrays.asList("deviceDownAlertStream", "symptomaticAlertOutputStream")); pd.setPartitionSpec(Arrays.asList(sp)); PolicyDefinition.Definition def = new PolicyDefinition.Definition(); def.setType(PolicyStreamHandlers.SIDDHI_ENGINE); def.setValue("from correlatedStream#window.externalTime(timestamp, 3 min) select UUID() as docId, linkedSwitch, '' as parentKey, timestamp group by linkedSwitch having count() > 0 insert into deviceDownAlertStream; " + " from correlatedStream#window.externalTime(timestamp, 3 min) as left join deviceDownAlertStream#window.time(3 min) as right on left.linkedSwitch == right.linkedSwitch" + " select left.docId, left.timestamp, left.linkedSwitch, right.docId as parentKey insert into symptomaticAlertOutputStream;"); pd.setDefinition(def); AlertBoltSpec spec = new AlertBoltSpec(); spec.setVersion("version1"); spec.setTopologyName("testTopology"); spec.addBoltPolicy("alertBolt1", pd.getName()); spec.getBoltPoliciesMap().put("alertBolt1", new ArrayList<>(Arrays.asList(pd))); bolt.onAlertBoltSpecChange(spec, sds); }
sp.setType(StreamPartition.Type.GROUPBY); AlertBoltSpec spec = new AlertBoltSpec(); spec.setVersion("version1"); spec.setTopologyName("testTopology"); PolicyDefinition pd = new PolicyDefinition(); pd.setName("policy1"); pd.getDefinition().type = PolicyStreamHandlers.SIDDHI_ENGINE; pd.getDefinition().value = "from cpuUsageStream[col1=='value1' OR col1=='value2'] select col1 insert into testAlertStream;"; spec.addBoltPolicy("alertBolt1", pd.getName()); spec.getBoltPoliciesMap().put("alertBolt1", new ArrayList<PolicyDefinition>(Arrays.asList(pd))); spec.addPublishPartition("testAlertStream", "policy1", "testAlertPublish", null); bolt.onAlertBoltSpecChange(spec, sds);