http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/resource/OpResult.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/resource/OpResult.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/resource/OpResult.java deleted file mode 100644 index 9f5ce7f..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/resource/OpResult.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.eagle.alert.metadata.resource; - -/** - * @since Apr 11, 2016. - */ -public class OpResult { - - public int code = 200; - public String message = ""; - - public static final int SUCCESS = 200; - public static final int FAILURE = 500; - - public static OpResult of(int code, String messsage) { - OpResult opResult = new OpResult(); - opResult.code = code; - opResult.message = messsage; - return opResult; - } - - public static OpResult success(String messsage) { - OpResult opResult = new OpResult(); - opResult.code = SUCCESS; - opResult.message = messsage; - return opResult; - } - - public static OpResult fail(String messsage) { - OpResult opResult = new OpResult(); - opResult.code = FAILURE; - opResult.message = messsage; - return opResult; - } -}
http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/alert/metadata/TestMetadataUtils.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/alert/metadata/TestMetadataUtils.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/alert/metadata/TestMetadataUtils.java deleted file mode 100644 index 1191dcb..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/alert/metadata/TestMetadataUtils.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.eagle.alert.metadata; - -import org.apache.eagle.alert.coordination.model.ScheduleState; -import org.apache.eagle.alert.coordination.model.internal.PolicyAssignment; -import org.apache.eagle.alert.engine.coordinator.StreamDefinition; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -/** - * Created by luokun on 2016/11/16. - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest(MetadataUtils.class) -public class TestMetadataUtils { - - @Rule - public ExpectedException thrown= ExpectedException.none(); - - @Test - public void testGetKey() throws Exception { - StreamDefinition stream = new StreamDefinition(); - Assert.assertNull(MetadataUtils.getKey(stream)); - PolicyAssignment policyAssignment = new PolicyAssignment(); - policyAssignment.setPolicyName("test"); - Assert.assertEquals("test", MetadataUtils.getKey(policyAssignment)); - ScheduleState scheduleState = new ScheduleState(); - scheduleState.setVersion("1.0"); - Assert.assertEquals("1.0", MetadataUtils.getKey(scheduleState)); - } - - @Test - public void testGetKeyThrowable() { - thrown.expect(RuntimeException.class); - Object obj = new Object(); - MetadataUtils.getKey(obj); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/alert/metadata/impl/InMemoryTest.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/alert/metadata/impl/InMemoryTest.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/alert/metadata/impl/InMemoryTest.java deleted file mode 100644 index 138a538..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/alert/metadata/impl/InMemoryTest.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.eagle.alert.metadata.impl; - -import com.typesafe.config.ConfigFactory; -import org.apache.eagle.alert.coordination.model.Kafka2TupleMetadata; -import org.apache.eagle.alert.coordination.model.ScheduleState; -import org.apache.eagle.alert.engine.coordinator.PolicyDefinition; -import org.apache.eagle.alert.engine.coordinator.StreamingCluster; -import org.apache.eagle.alert.engine.model.AlertPublishEvent; -import org.apache.eagle.alert.metadata.IMetadataDao; -import org.apache.eagle.alert.metadata.resource.OpResult; - -import org.junit.Assert; -import org.junit.Test; -import org.slf4j.LoggerFactory; - -/** - * @since May 1, 2016 - */ -public class InMemoryTest { - - private IMetadataDao dao = new InMemMetadataDaoImpl(ConfigFactory.load()); - - @Test - public void test_AddPolicy() { - - LoggerFactory.getLogger(InMemoryTest.class); - - MetadataDaoFactory.getInstance().getMetadataDao(); - - PolicyDefinition pd = new PolicyDefinition(); - pd.setName("pd1"); - dao.addPolicy(pd); - - Assert.assertEquals(1, dao.listPolicies().size()); - } - - @Test - public void testAddCluster(){ - StreamingCluster cluster1 = new StreamingCluster(); - cluster1.setName("test1"); - StreamingCluster cluster2 = new StreamingCluster(); - cluster2.setName("test2"); - StreamingCluster cluster3 = new StreamingCluster(); - cluster3.setName("test2"); - OpResult opResult1 = dao.addCluster(cluster1); - Assert.assertEquals(OpResult.SUCCESS,opResult1.code); - OpResult opResult2 = dao.addCluster(cluster2); - Assert.assertEquals(OpResult.SUCCESS,opResult2.code); - OpResult opResult3 = dao.addCluster(cluster3); - Assert.assertEquals(OpResult.SUCCESS,opResult3.code); - Assert.assertTrue(opResult3.message.contains("replace")); - dao.clear(); - } - - @Test - public void testRemoveDataSource(){ - Kafka2TupleMetadata dataSource1 = new Kafka2TupleMetadata(); - Kafka2TupleMetadata dataSource2 = new Kafka2TupleMetadata(); - dataSource1.setName("test1"); - dataSource2.setName("test2"); - dao.addDataSource(dataSource1); - dao.addDataSource(dataSource2); - OpResult opResult1 = dao.removeDataSource("test1"); - Assert.assertEquals(OpResult.SUCCESS, opResult1.code); - OpResult opResult2 = dao.removeDataSource("test1"); - Assert.assertEquals(OpResult.SUCCESS, opResult2.code); - Assert.assertTrue(opResult2.message.contains("no configuration")); - dao.clear(); - } - - @Test - public void testListAlertPublishEvent(){ - dao.addAlertPublishEvent(new AlertPublishEvent()); - dao.addAlertPublishEvent(new AlertPublishEvent()); - Assert.assertEquals(2,dao.listAlertPublishEvent(5).size()); - } - - @Test - public void testGetAlertPublishEventByPolicyId(){ - AlertPublishEvent alert1 = new AlertPublishEvent(); - AlertPublishEvent alert2 = new AlertPublishEvent(); - alert1.setAlertId("1"); - alert1.setPolicyId("1"); - alert2.setAlertId("2"); - alert2.setPolicyId("1"); - dao.addAlertPublishEvent(alert1); - dao.addAlertPublishEvent(alert2); - Assert.assertNotNull(dao.getAlertPublishEvent("1")); - Assert.assertEquals(2, dao.getAlertPublishEventsByPolicyId("1", 2).size()); - } - - @Test - public void testAddScheduleState(){ - ScheduleState scheduleState = new ScheduleState(); - scheduleState.setVersion("1"); - Assert.assertEquals(OpResult.SUCCESS,dao.addScheduleState(scheduleState).code); - } - -} http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/alert/metadata/impl/JdbcImplTest.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/alert/metadata/impl/JdbcImplTest.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/alert/metadata/impl/JdbcImplTest.java deleted file mode 100644 index 566525e..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/alert/metadata/impl/JdbcImplTest.java +++ /dev/null @@ -1,282 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.eagle.alert.metadata.impl; - -import com.typesafe.config.Config; -import com.typesafe.config.ConfigFactory; -import org.apache.commons.collections.CollectionUtils; -import org.apache.eagle.alert.coordination.model.Kafka2TupleMetadata; -import org.apache.eagle.alert.coordination.model.ScheduleState; -import org.apache.eagle.alert.coordination.model.internal.PolicyAssignment; -import org.apache.eagle.alert.coordination.model.internal.Topology; -import org.apache.eagle.alert.engine.coordinator.PolicyDefinition; -import org.apache.eagle.alert.engine.coordinator.Publishment; -import org.apache.eagle.alert.engine.coordinator.PublishmentType; -import org.apache.eagle.alert.engine.coordinator.StreamingCluster; -import org.apache.eagle.alert.engine.model.AlertPublishEvent; -import org.apache.eagle.alert.metadata.IMetadataDao; - -import org.apache.eagle.alert.metadata.resource.OpResult; -import org.junit.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.sql.SQLException; -import java.util.*; - -public class JdbcImplTest { - private static Logger LOG = LoggerFactory.getLogger(JdbcImplTest.class); - static IMetadataDao dao; - - @BeforeClass - public static void setup() { - ConfigFactory.invalidateCaches(); - Config config = ConfigFactory.load("application-jdbc.conf"); - dao = new JdbcMetadataDaoImpl(config); - } - - @AfterClass - public static void teardown() { - if (dao != null) { - try { - dao.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - private String TOPO_NAME = "topoName"; - - @Test - public void test_apis() { - // publishment - { - Publishment publishment = new Publishment(); - publishment.setName("pub-"); - OpResult result = dao.addPublishment(publishment); - Assert.assertEquals(200, result.code); - List<Publishment> assigns = dao.listPublishment(); - Assert.assertEquals(1, assigns.size()); - result = dao.removePublishment("pub-"); - Assert.assertTrue(200 == result.code); - } - // topology - { - OpResult result = dao.addTopology(new Topology(TOPO_NAME, 3, 5)); - System.out.println(result.message); - Assert.assertEquals(200, result.code); - List<Topology> topos = dao.listTopologies(); - Assert.assertEquals(1, topos.size()); - // add again: replace existing one - dao.addTopology(new Topology(TOPO_NAME, 4, 5)); - topos = dao.listTopologies(); - Assert.assertEquals(1, topos.size()); - Assert.assertEquals(TOPO_NAME, topos.get(0).getName()); - Assert.assertEquals(4, topos.get(0).getNumOfGroupBolt()); - } - // assignment - { - PolicyAssignment assignment = new PolicyAssignment(); - assignment.setPolicyName("policy1"); - OpResult result = dao.addAssignment(assignment); - Assert.assertEquals(200, result.code); - List<PolicyAssignment> assigns = dao.listAssignments(); - Assert.assertEquals(1, assigns.size()); - } - // cluster - { - StreamingCluster cluster = new StreamingCluster(); - cluster.setName("dd"); - OpResult result = dao.addCluster(cluster); - Assert.assertEquals(200, result.code); - List<StreamingCluster> assigns = dao.listClusters(); - Assert.assertEquals(1, assigns.size()); - dao.removeCluster("dd"); - Assert.assertEquals(0, dao.listClusters().size()); - } - // data source - { - Kafka2TupleMetadata dataSource = new Kafka2TupleMetadata(); - dataSource.setName("ds"); - OpResult result = dao.addDataSource(dataSource); - Assert.assertEquals(200, result.code); - List<Kafka2TupleMetadata> assigns = dao.listDataSources(); - Assert.assertEquals(1, assigns.size()); - } - // policy - { - PolicyDefinition policy = new PolicyDefinition(); - policy.setName("ds"); - OpResult result = dao.addPolicy(policy); - Assert.assertEquals(200, result.code); - List<PolicyDefinition> assigns = dao.listPolicies(); - Assert.assertEquals(1, assigns.size()); - } - - // publishmentType - { - PublishmentType publishmentType = new PublishmentType(); - publishmentType.setName("KAFKA"); - publishmentType.setType("org.apache.eagle.alert.engine.publisher.impl.AlertKafkaPublisher"); - List<Map<String, String>> fields = new ArrayList<>(); - Map<String, String> field1 = new HashMap<>(); - field1.put("name", "kafka_broker"); - field1.put("value", "sandbox.hortonworks.com:6667"); - Map<String, String> field2 = new HashMap<>(); - field2.put("name", "topic"); - fields.add(field1); - fields.add(field2); - publishmentType.setFields(fields); - OpResult result = dao.addPublishmentType(publishmentType); - Assert.assertEquals(200, result.code); - List<PublishmentType> types = dao.listPublishmentType(); - Assert.assertEquals(6, types.size()); - - dao.removePublishmentType("KAFKA"); - types = dao.listPublishmentType(); - Assert.assertTrue(types.size() == 5); - } - } - - @Test - public void test_addstate() { - ScheduleState state = new ScheduleState(); - String versionId = "state-" + System.currentTimeMillis(); - state.setVersion(versionId); - state.setGenerateTime(String.valueOf(new Date().getTime())); - OpResult result = dao.addScheduleState(state); - Assert.assertEquals(200, result.code); - state = dao.getScheduleState(); - Assert.assertEquals(state.getVersion(), versionId); - } - - @Test - public void test_readCurrentState() { - test_addstate(); - ScheduleState state = dao.getScheduleState(); - Assert.assertNotNull(state); - - LOG.debug(state.getVersion()); - LOG.debug(state.getGenerateTime()); - } - - @Test - public void test_clearScheduleState() { - int maxCapacity = 4; - List<String> reservedOnes = new ArrayList<>(); - for (int i = 0; i < 10; i++) { - ScheduleState state = new ScheduleState(); - String versionId = "state-" + (System.currentTimeMillis() + i); - state.setVersion(versionId); - state.setGenerateTime(String.valueOf(new Date().getTime())); - dao.addScheduleState(state); - if (i >= 10 - maxCapacity) { - reservedOnes.add(versionId); - } - } - dao.clearScheduleState(maxCapacity); - List<ScheduleState> scheduleStates = dao.listScheduleStates(); - Assert.assertTrue(scheduleStates.size() == maxCapacity); - List<String> targetOnes = new ArrayList<>(); - scheduleStates.stream().forEach(state -> targetOnes.add(state.getVersion())); - LOG.info("reservedOne={}",reservedOnes); - LOG.info("targetOne={}", targetOnes); - Assert.assertTrue(CollectionUtils.isEqualCollection(reservedOnes, targetOnes)); - } - - @Test - public void testUpdate() throws SQLException { - OpResult updateResult; - // update - Publishment publishment = new Publishment(); - publishment.setName("pub-"); - publishment.setType("type1"); - updateResult = dao.addPublishment(publishment); - Assert.assertTrue(updateResult.code == OpResult.SUCCESS); - - publishment.setType("type2"); - updateResult = dao.addPublishment(publishment); - Assert.assertTrue(updateResult.code == OpResult.SUCCESS); - Assert.assertTrue(dao.listPublishment().get(0).getType().equals("type2")); - - // remove - updateResult = dao.removePublishment("pub-"); - Assert.assertTrue(updateResult.code == OpResult.SUCCESS); - Assert.assertTrue(dao.listPublishment().size() == 0); - - // update alert event - AlertPublishEvent alert = new AlertPublishEvent(); - String alertId = UUID.randomUUID().toString(); - alert.setAlertTimestamp(System.currentTimeMillis()); - alert.setAlertId(alertId); - alert.setPolicyId("policyId"); - alert.setPolicyValue("from HDFS_AUDIT_LOG_ENRICHED_STREAM_SANDBOX[str:contains(src,'/tmp/test') and ((cmd=='rename' and str:contains(dst, '.Trash')) or cmd=='delete')] select * insert into hdfs_audit_log_enriched_stream_out"); - Map<String, Object> alertData = new HashMap<>(); - alertData.put("siteId", "sandbox"); - alertData.put("policyId", "sample"); - alert.setAlertData(alertData); - List<String> appIds = new ArrayList<>(); - appIds.add("app1"); - appIds.add("app2"); - alert.setAppIds(appIds); - updateResult = dao.addAlertPublishEvent(alert); - Assert.assertTrue(updateResult.code == OpResult.SUCCESS); - AlertPublishEvent event = dao.getAlertPublishEvent(alertId); - Assert.assertTrue(CollectionUtils.isEqualCollection(appIds, event.getAppIds())); - Assert.assertTrue(alertData.equals(event.getAlertData())); - } - - @Test - public void testUpdatePublishmentsByPolicyId() { - OpResult updateResult; - // add publishment - String policyId = "policy"; - Publishment pub1 = new Publishment(); - pub1.setName("pub1"); - pub1.setType("type1"); - updateResult = dao.addPublishment(pub1); - Assert.assertTrue(updateResult.code == OpResult.SUCCESS); - - Publishment pub2 = new Publishment(); - pub2.setName("pub2"); - pub2.setType("type2"); - updateResult = dao.addPublishment(pub2); - Assert.assertTrue(updateResult.code == OpResult.SUCCESS); - - // add policy - PolicyDefinition policy = new PolicyDefinition(); - policy.setName(policyId); - OpResult result = dao.addPolicy(policy); - Assert.assertEquals(200, result.code); - - // get publishments by policyId - List<String> publishmentIds = new ArrayList<>(); - publishmentIds.add("pub1"); - publishmentIds.add("pub2"); - dao.addPublishmentsToPolicy(policyId, publishmentIds); - List<Publishment> publishments = dao.getPublishmentsByPolicyId(policyId); - Assert.assertTrue(publishments.size() == 2); - - publishments = dao.listPublishment(); - Assert.assertTrue(publishments.size() == 2); - } - -} http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/alert/metadata/impl/MongoImplTest.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/alert/metadata/impl/MongoImplTest.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/alert/metadata/impl/MongoImplTest.java deleted file mode 100644 index cd9a0a9..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/alert/metadata/impl/MongoImplTest.java +++ /dev/null @@ -1,344 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.eagle.alert.metadata.impl; - -import com.typesafe.config.Config; -import com.typesafe.config.ConfigFactory; -import de.flapdoodle.embed.mongo.MongodExecutable; -import de.flapdoodle.embed.mongo.MongodProcess; -import de.flapdoodle.embed.mongo.MongodStarter; -import de.flapdoodle.embed.mongo.config.MongodConfigBuilder; -import de.flapdoodle.embed.mongo.config.Net; -import de.flapdoodle.embed.mongo.distribution.Version; -import de.flapdoodle.embed.process.runtime.Network; -import org.apache.commons.lang3.exception.ExceptionUtils; -import org.apache.eagle.alert.coordination.model.*; -import org.apache.eagle.alert.coordination.model.internal.MonitoredStream; -import org.apache.eagle.alert.coordination.model.internal.PolicyAssignment; -import org.apache.eagle.alert.coordination.model.internal.StreamGroup; -import org.apache.eagle.alert.coordination.model.internal.Topology; -import org.apache.eagle.alert.engine.coordinator.*; -import org.apache.eagle.alert.engine.model.AlertPublishEvent; -import org.apache.eagle.alert.metadata.IMetadataDao; -import org.apache.eagle.alert.metadata.MetadataUtils; -import org.apache.eagle.alert.metadata.resource.OpResult; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.*; - -/** - * @since May 1, 2016 - */ -public class MongoImplTest { - private static Logger LOG = LoggerFactory.getLogger(MongoImplTest.class); - static IMetadataDao dao; - - private static MongodExecutable mongodExe; - private static MongodProcess mongod; - - public static void before() { - try { - MongodStarter starter = MongodStarter.getDefaultInstance(); - mongodExe = starter.prepare(new MongodConfigBuilder().version(Version.V3_2_1) - .net(new Net(27017, Network.localhostIsIPv6())).build()); - mongod = mongodExe.start(); - } catch (Exception e) { - LOG.error("start embed mongod failed, assume some external mongo running. continue run test!", e); - } - } - - @BeforeClass - public static void setup() { - before(); - - System.setProperty("config.resource", "/application-mongo.conf"); - ConfigFactory.invalidateCaches(); - Config config = ConfigFactory.load(); - dao = new MongoMetadataDaoImpl(config.getConfig(MetadataUtils.META_DATA)); - - } - - @AfterClass - public static void teardown() { - if (mongod != null) { - try { - mongod.stop(); - } catch (IllegalStateException e) { - // catch this exception for the unstable stopping mongodb - // reason: the exception is usually thrown out with below message format when stop() returns null value, - // but actually this should have been captured in ProcessControl.stopOrDestroyProcess() by destroying - // the process ultimately - if (e.getMessage() != null && e.getMessage().matches("^Couldn't kill.*process!.*")) { - // if matches, do nothing, just ignore the exception - } else { - LOG.warn(String.format("Ignored error for stopping mongod process, see stack trace: %s", ExceptionUtils.getStackTrace(e))); - } - } - mongodExe.stop(); - } - } - - private String TOPO_NAME = "topoName"; - - @Test - public void test_apis() throws Exception { - // topology - { - OpResult result = dao.addTopology(new Topology(TOPO_NAME, 3, 5)); - System.out.println(result.message); - Assert.assertEquals(200, result.code); - List<Topology> topos = dao.listTopologies(); - Assert.assertEquals(1, topos.size()); - - result = dao.addTopology(new Topology(TOPO_NAME + "-new", 3, 5)); - topos = dao.listTopologies(); - Assert.assertEquals(2, topos.size()); - // add again: replace existing one - result = dao.addTopology(new Topology(TOPO_NAME, 4, 5)); - topos = dao.listTopologies(); - Assert.assertEquals(2, topos.size()); - Assert.assertEquals(TOPO_NAME, topos.get(0).getName()); - Assert.assertEquals(4, topos.get(0).getNumOfGroupBolt()); - } - // assignment - { - PolicyAssignment assignment = new PolicyAssignment(); - assignment.setPolicyName("policy1"); - OpResult result = dao.addAssignment(assignment); - Assert.assertEquals(200, result.code); - List<PolicyAssignment> assigns = dao.listAssignments(); - Assert.assertEquals(1, assigns.size()); - } - // cluster - { - StreamingCluster cluster = new StreamingCluster(); - cluster.setName("dd"); - OpResult result = dao.addCluster(cluster); - Assert.assertEquals(200, result.code); - List<StreamingCluster> assigns = dao.listClusters(); - Assert.assertEquals(1, assigns.size()); - } - // data source - { - Kafka2TupleMetadata dataSource = new Kafka2TupleMetadata(); - dataSource.setName("ds"); - OpResult result = dao.addDataSource(dataSource); - Assert.assertEquals(200, result.code); - List<Kafka2TupleMetadata> assigns = dao.listDataSources(); - Assert.assertEquals(1, assigns.size()); - } - // policy - { - PolicyDefinition policy = new PolicyDefinition(); - policy.setName("ds"); - OpResult result = dao.addPolicy(policy); - Assert.assertEquals(200, result.code); - List<PolicyDefinition> assigns = dao.listPolicies(); - Assert.assertEquals(1, assigns.size()); - } - // publishment - { - Publishment publishment = new Publishment(); - publishment.setName("pub-"); - OpResult result = dao.addPublishment(publishment); - Assert.assertEquals(200, result.code); - List<Publishment> assigns = dao.listPublishment(); - Assert.assertEquals(1, assigns.size()); - } - // publishmentType - { - PublishmentType publishmentType = new PublishmentType(); - publishmentType.setName("KAFKA"); - OpResult result = dao.addPublishmentType(publishmentType); - Assert.assertEquals(200, result.code); - List<PublishmentType> assigns = dao.listPublishmentType(); - Assert.assertEquals(1, assigns.size()); - } - - // schedule state - { - ScheduleState state = new ScheduleState(); - state.setVersion("001"); - state.setScheduleTimeMillis(3000); - state.setCode(200); - OpResult result = dao.addScheduleState(state); - Assert.assertEquals(200, result.code); - - Thread.sleep(1000); - - state = new ScheduleState(); - state.setScheduleTimeMillis(3000); - state.setVersion("002"); - state.setCode(201); - result = dao.addScheduleState(state); - Assert.assertEquals(200, result.code); - - ScheduleState getState = dao.getScheduleState(); - Assert.assertEquals(201, getState.getCode()); - } - // stream - { - StreamDefinition stream = new StreamDefinition(); - stream.setStreamId("stream"); - OpResult result = dao.createStream(stream); - Assert.assertEquals(200, result.code); - List<StreamDefinition> assigns = dao.listStreams(); - Assert.assertEquals(1, assigns.size()); - } - // alert - { - AlertPublishEvent alert = new AlertPublishEvent(); - alert.setAlertTimestamp(System.currentTimeMillis()); - alert.setAlertId(UUID.randomUUID().toString()); - OpResult result = dao.addAlertPublishEvent(alert); - Assert.assertEquals(200, result.code); - List<AlertPublishEvent> alerts = dao.listAlertPublishEvent(2); - Assert.assertEquals(1, alerts.size()); - } - } - - private void test_addstate() { - ScheduleState state = new ScheduleState(); - state.setVersion("state-" + System.currentTimeMillis()); - state.setGenerateTime(String.valueOf(new Date().getTime())); - OpResult result = dao.addScheduleState(state); - Assert.assertEquals(200, result.code); - } - - @Test - public void test_readCurrentState() { - test_addstate(); - ScheduleState state = dao.getScheduleState(); - Assert.assertNotNull(state); - - System.out.println(state.getVersion()); - System.out.println(state.getGenerateTime()); - } - - private void test_addCompleteScheduleState() { - Long timestamp = System.currentTimeMillis(); - String version = "state-" + timestamp; - - // SpoutSpec - Map<String, SpoutSpec> spoutSpecsMap = new HashMap<>(); - SpoutSpec spoutSpec1 = new SpoutSpec(); - String topologyId1 = "testUnitTopology1_" + timestamp; - spoutSpec1.setTopologyId(topologyId1); - - Map<String, Kafka2TupleMetadata> kafka2TupleMetadataMap = new HashMap<>(); - Kafka2TupleMetadata kafka2TupleMetadata = new Kafka2TupleMetadata(); - kafka2TupleMetadata.setType("KAFKA"); - kafka2TupleMetadataMap.put("preprocess.network-sherlock.events", kafka2TupleMetadata); - spoutSpec1.setKafka2TupleMetadataMap(kafka2TupleMetadataMap); - - Map<String, List<StreamRepartitionMetadata>> streamRepartitionMetadataMap= new HashMap<>(); - List<StreamRepartitionMetadata> StreamRepartitionMetadataList = new ArrayList<>(); - StreamRepartitionMetadata streamRepartitionMetadata = new StreamRepartitionMetadata(); - List<StreamRepartitionStrategy> groupingStrategies = new ArrayList(); - StreamRepartitionStrategy streamRepartitionStrategy = new StreamRepartitionStrategy(); - streamRepartitionStrategy.setStartSequence(4); - groupingStrategies.add(streamRepartitionStrategy); - streamRepartitionMetadata.setGroupingStrategies(groupingStrategies); - StreamRepartitionMetadataList.add(streamRepartitionMetadata); - streamRepartitionMetadataMap.put("preprocess.network-nervecenter.events", StreamRepartitionMetadataList); - spoutSpec1.setStreamRepartitionMetadataMap(streamRepartitionMetadataMap); - spoutSpecsMap.put(topologyId1, spoutSpec1); - - SpoutSpec spoutSpec2 = new SpoutSpec(); - String topologyId2 = "testUnitTopology2_" + timestamp; - spoutSpec2.setTopologyId(topologyId2); - spoutSpec2.setKafka2TupleMetadataMap(kafka2TupleMetadataMap); - spoutSpec2.setStreamRepartitionMetadataMap(streamRepartitionMetadataMap); - spoutSpecsMap.put(topologyId2, spoutSpec2); - - // Alert Spec - Map<String, AlertBoltSpec> alertSpecsMap = new HashMap<>(); - alertSpecsMap.put(topologyId1, new AlertBoltSpec(topologyId1)); - - // GroupSpec - Map<String, RouterSpec> groupSpecsMap = new HashMap<>(); - groupSpecsMap.put(topologyId1, new RouterSpec(topologyId1)); - - // PublishSpec - Map<String, PublishSpec> pubMap = new HashMap<>(); - pubMap.put(topologyId1, new PublishSpec(topologyId1, "testPublishBolt")); - - // Policy Snapshots - Collection<PolicyDefinition> policySnapshots = new ArrayList<>(); - PolicyDefinition policy = new PolicyDefinition(); - policy.setName("testPolicyDefinition"); - PolicyDefinition.Definition def = new PolicyDefinition.Definition(); - def.setValue("1,jobID,job1,daily_rule,14:00:00,15:00:00"); - def.setType("absencealert"); - policy.setDefinition(def); - policySnapshots.add(policy); - - // Stream Snapshots - Collection<StreamDefinition> streams = new ArrayList<>(); - StreamDefinition stream = new StreamDefinition(); - stream.setStreamId("testStream"); - streams.add(stream); - - // Monitored Streams - Collection<MonitoredStream> monitoredStreams = new ArrayList<>(); - StreamPartition partition = new StreamPartition(); - partition.setType(StreamPartition.Type.GLOBAL); - partition.setStreamId("s1"); - partition.setColumns(Arrays.asList("f1", "f2")); - StreamGroup sg = new StreamGroup(); - sg.addStreamPartition(partition); - MonitoredStream monitoredStream = new MonitoredStream(sg); - monitoredStreams.add(monitoredStream); - - // Assignments - Collection<PolicyAssignment> assignments = new ArrayList<>(); - assignments.add(new PolicyAssignment("syslog_regex", "SG[syslog_stream-]" + timestamp)); - - ScheduleState state = new ScheduleState(version, spoutSpecsMap, groupSpecsMap, alertSpecsMap, pubMap, - assignments, monitoredStreams, policySnapshots, streams); - - OpResult result = dao.addScheduleState(state); - Assert.assertEquals(200, result.code); - } - - @Test - public void test_readCompleteScheduleState() { - test_addCompleteScheduleState(); - - ScheduleState state = dao.getScheduleState(); - Assert.assertNotNull(state); - Assert.assertEquals(2, state.getSpoutSpecs().size()); - Assert.assertEquals(1, state.getAlertSpecs().size()); - Assert.assertEquals(1, state.getGroupSpecs().size()); - Assert.assertEquals(1, state.getPublishSpecs().size()); - Assert.assertEquals(1, state.getPolicySnapshots().size()); - Assert.assertEquals(1, state.getStreamSnapshots().size()); - Assert.assertEquals(1, state.getMonitoredStreams().size()); - Assert.assertEquals(1, state.getAssignments().size()); - - - System.out.println(state.getVersion()); - System.out.println(state.getGenerateTime()); - - - } -} http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/application-jdbc.conf ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/application-jdbc.conf b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/application-jdbc.conf deleted file mode 100644 index 9c71a28..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/application-jdbc.conf +++ /dev/null @@ -1,25 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -metadata { - metadataDao = org.apache.eagle.alert.metadata.impl.JdbcMetadataDaoImpl - jdbc { - username = null - password = null - driverClassName = "org.h2.Driver" - connection = "jdbc:h2:mem:test;INIT=RUNSCRIPT FROM './src/test/resources/init.sql'" - connectionProperties = "encoding=UTF8;timeout=60" - } -} http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/application-mongo.conf ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/application-mongo.conf b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/application-mongo.conf deleted file mode 100644 index 80adeae..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/application-mongo.conf +++ /dev/null @@ -1,25 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -metadata { - metadataDao = org.apache.eagle.alert.metadata.impl.InMemMetadataDaoImpl - mongo { - connection = "mongodb://localhost:27017" - cappedSize = 20000 - database = testdb - } -} - http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/application.conf ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/application.conf b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/application.conf deleted file mode 100644 index 2304cd2..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/application.conf +++ /dev/null @@ -1,26 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -metadata { - metadataDao = org.apache.eagle.alert.metadata.impl.InMemMetadataDaoImpl - jdbc { - url = "localhost:27017" - } - properties { - - } -} - http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/init.sql ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/init.sql b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/init.sql deleted file mode 100644 index 71ffa6e..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/init.sql +++ /dev/null @@ -1,88 +0,0 @@ --- /* --- * Licensed to the Apache Software Foundation (ASF) under one or more --- * contributor license agreements. See the NOTICE file distributed with --- * this work for additional information regarding copyright ownership. --- * The ASF licenses this file to You under the Apache License, Version 2.0 --- * (the "License"); you may not use this file except in compliance with --- * the License. You may obtain a copy of the License at --- * --- * http://www.apache.org/licenses/LICENSE-2.0 --- * --- * Unless required by applicable law or agreed to in writing, software --- * distributed under the License is distributed on an "AS IS" BASIS, --- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- * See the License for the specific language governing permissions and --- * limitations under the License. --- * --- */ - -CREATE TABLE IF NOT EXISTS stream_cluster ( - id VARCHAR (50) PRIMARY KEY, - content longtext DEFAULT NULL -); - -CREATE TABLE IF NOT EXISTS stream_definition ( - id VARCHAR (50) PRIMARY KEY, - content longtext DEFAULT NULL -); - -CREATE TABLE IF NOT EXISTS Kafka_tuple_metadata ( - id VARCHAR (50) PRIMARY KEY, - content longtext DEFAULT NULL -); - -CREATE TABLE IF NOT EXISTS policy_definition ( - id VARCHAR (50) PRIMARY KEY, - content longtext DEFAULT NULL -); - -CREATE TABLE IF NOT EXISTS publishment ( - id VARCHAR (50) PRIMARY KEY, - content longtext DEFAULT NULL -); - -CREATE TABLE IF NOT EXISTS schedule_state ( - id VARCHAR (50) PRIMARY KEY, - content longtext DEFAULT NULL -); - -CREATE TABLE IF NOT EXISTS policy_assignment ( - id VARCHAR (50) PRIMARY KEY, - content longtext DEFAULT NULL -); - -CREATE TABLE IF NOT EXISTS topology ( - id VARCHAR (50) PRIMARY KEY, - content longtext DEFAULT NULL -); - -CREATE TABLE IF NOT EXISTS publishment_type ( - id VARCHAR (50) PRIMARY KEY, - content longtext DEFAULT NULL -); - -CREATE TABLE IF NOT EXISTS policy_publishment ( - policyId VARCHAR(50), - publishmentName VARCHAR(50), - PRIMARY KEY(policyId, publishmentName), - CONSTRAINT `policy_id_fk` FOREIGN KEY (`policyId`) REFERENCES `policy_definition` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `publishment_id_fk` FOREIGN KEY (`publishmentName`) REFERENCES `publishment` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -); - -CREATE TABLE IF NOT EXISTS alert_event ( - alertId VARCHAR (50) PRIMARY KEY, - siteId VARCHAR (50) DEFAULT NULL, - appIds VARCHAR (255) DEFAULT NULL, - policyId VARCHAR (50) DEFAULT NULL, - alertTimestamp bigint(20) DEFAULT NULL, - policyValue mediumtext DEFAULT NULL, - alertData mediumtext DEFAULT NULL -); - -INSERT INTO publishment_type(id, content) VALUES -('Kafka', '{"name":"Kafka","type":"org.apache.eagle.alert.engine.publisher.impl.AlertKafkaPublisher","description":null,"fields":[{"name":"kafka_broker","value":"sandbox.hortonworks.com:6667"},{"name":"topic"}]}'), -('Email', '{"name":"Email","type":"org.apache.eagle.alert.engine.publisher.impl.AlertEmailPublisher","description":null,"fields":[{"name":"subject"},{"name":"sender"}, {"name":"recipients"}]}'), -('Slack', '{"name":"Slack","type":"org.apache.eagle.alert.engine.publisher.impl.AlertSlackPublisher","description":null,"fields":[{"name":"token"},{"name":"channels"}, {"name":"severitys"}, {"name":"urltemplate"}]}'), -('HBaseStorage', '{"name":"HBaseStorage","type":"org.apache.eagle.alert.app.AlertEagleStorePlugin","description":null,"fields":[]}'), -('JDBCStorage', '{"name":"JDBCStorage","type":"org.apache.eagle.alert.engine.publisher.impl.AlertEagleStorePlugin","description":null,"fields":[]}'); - http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/policy-sample.json ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/policy-sample.json b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/policy-sample.json deleted file mode 100644 index 56a53e7..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/policy-sample.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "policy1", - "description": "test policy", - "inputStreams": [ - "in-stream-1", - "in-stream-2" - ], - "outputStreams": [ - "out-stream-1" - ], - "definition": { - "type": "siddhiCEPEngine", - "value": "select count(*) from in-stream-1" - }, - "partitionSpec": [ - { - "streamId": "in-stream-1", - "type": "GROUPBY", - "columns": [ - "col-1", - "col-2" - ], - "sortSpec": { - "column": "col-1", - "windowPeriod": "60", - "order": "asc", - "windowMargin": 30000 - } - } - ], - "parallelismHint": 2 -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/pom.xml ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/pom.xml b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/pom.xml deleted file mode 100644 index f269b57..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/pom.xml +++ /dev/null @@ -1,30 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- ~ Licensed to the Apache Software Foundation (ASF) under one or more - ~ contributor license agreements. See the NOTICE file distributed with ~ - this work for additional information regarding copyright ownership. ~ The - ASF licenses this file to You under the Apache License, Version 2.0 ~ (the - "License"); you may not use this file except in compliance with ~ the License. - You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ ~ Unless required by applicable law or agreed to in writing, software ~ - distributed under the License is distributed on an "AS IS" BASIS, ~ WITHOUT - WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ~ See the - License for the specific language governing permissions and ~ limitations - under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.eagle</groupId> - <artifactId>eagle-alert</artifactId> - <version>0.5.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - <artifactId>alert-metadata-parent</artifactId> - <name>Eagle::Core::Alert::Metadata</name> - <packaging>pom</packaging> - - <modules> - <module>alert-metadata</module> - <module>alert-metadata-service</module> - </modules> -</project> http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-alert-parent/eagle-alert/alert-service/pom.xml ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-service/pom.xml b/eagle-core/eagle-alert-parent/eagle-alert/alert-service/pom.xml deleted file mode 100644 index f078d2a..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-service/pom.xml +++ /dev/null @@ -1,222 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- ~ Licensed to the Apache Software Foundation (ASF) under one or more - ~ contributor license agreements. See the NOTICE file distributed with ~ - this work for additional information regarding copyright ownership. ~ The - ASF licenses this file to You under the Apache License, Version 2.0 ~ (the - "License"); you may not use this file except in compliance with ~ the License. - You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ ~ Unless required by applicable law or agreed to in writing, software ~ - distributed under the License is distributed on an "AS IS" BASIS, ~ WITHOUT - WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ~ See the - License for the specific language governing permissions and ~ limitations - under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <parent> - <artifactId>eagle-alert</artifactId> - <groupId>org.apache.eagle</groupId> - <version>0.5.0-SNAPSHOT</version> - </parent> - <modelVersion>4.0.0</modelVersion> - - <artifactId>alert-service</artifactId> - <name>Eagle::Core::Alert::ServiceApp</name> - <description>Alert Service: Coordinator + Metadata</description> - <packaging>jar</packaging> - - <dependencies> - <dependency> - <groupId>org.apache.eagle</groupId> - <artifactId>alert-coordinator</artifactId> - <version>${project.version}</version> - <exclusions> - <exclusion> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - </exclusion> - <exclusion> - <artifactId>storm-core</artifactId> - <groupId>org.apache.storm</groupId> - </exclusion> - <exclusion> - <artifactId>servlet-api</artifactId> - <groupId>javax.servlet</groupId> - </exclusion> - <exclusion> - <artifactId>jetty</artifactId> - <groupId>org.mortbay.jetty</groupId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.apache.eagle</groupId> - <artifactId>alert-metadata-service</artifactId> - <version>${project.version}</version> - <exclusions> - <exclusion> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - </exclusion> - <exclusion> - <artifactId>storm-core</artifactId> - <groupId>org.apache.storm</groupId> - </exclusion> - </exclusions> - </dependency> - - <dependency> - <groupId>com.sun.jersey</groupId> - <artifactId>jersey-json</artifactId> - </dependency> - <!-- dropwizard --> - <dependency> - <groupId>io.dropwizard</groupId> - <artifactId>dropwizard-core</artifactId> - <exclusions> - <exclusion> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>io.dropwizard</groupId> - <artifactId>dropwizard-jersey</artifactId> - <exclusions> - <exclusion> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>io.dropwizard</groupId> - <artifactId>dropwizard-testing</artifactId> - <exclusions> - <exclusion> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>io.swagger</groupId> - <artifactId>swagger-jersey-jaxrs</artifactId> - <scope>compile</scope> - <exclusions> - <exclusion> - <groupId>com.sun.jersey</groupId> - <artifactId>*</artifactId> - </exclusion> - </exclusions> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.eclipse.jetty</groupId> - <artifactId>jetty-maven-plugin</artifactId> - <version>9.2.11.v20150529</version> - <configuration> - <scanIntervalSeconds>5</scanIntervalSeconds> - </configuration> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> - <version>1.4</version> - <configuration> - <filters> - <filter> - <artifact>*:*</artifact> - <excludes> - <exclude>META-INF/*.SF</exclude> - <exclude>META-INF/*.DSA</exclude> - <exclude>META-INF/*.RSA</exclude> - </excludes> - </filter> - </filters> - </configuration> - <executions> - <execution> - <phase>package</phase> - <goals> - <goal>shade</goal> - </goals> - - <configuration> - <shadedArtifactAttached>true</shadedArtifactAttached> - <shadedClassifierName>shaded</shadedClassifierName> - <transformers> - <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> - <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> - <mainClass>org.apache.eagle.service.app.ServiceApp</mainClass> - </transformer> - </transformers> - - <artifactSet> - <excludes> - <exclude>org.slf4j:slf4j-log4j12</exclude> - </excludes> - </artifactSet> - - </configuration> - </execution> - </executions> - </plugin> - - <!-- change project to war, and use maven-war-plugin to build the war --> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-war-plugin</artifactId> - <version>2.6</version> - <executions> - <execution> - <phase>package</phase> - <goals> - <goal>war</goal> - </goals> - </execution> - </executions> - </plugin> - - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>build-helper-maven-plugin</artifactId> - <version>1.12</version> - <executions> - <execution> - <id>attach-artifacts</id> - <phase>package</phase> - <goals> - <goal>attach-artifact</goal> - </goals> - <configuration> - <artifacts> - <artifact> - <file>target/alert-service-${project.version}.war</file> - <type>war</type> - </artifact> - </artifacts> - </configuration> - </execution> - </executions> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-source-plugin</artifactId> - <version>2.1.2</version> - <executions> - <execution> - <id>attach-sources</id> - <phase>verify</phase> - <goals> - <goal>jar-no-fork</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> -</project> http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/java/org/apache/eagle/service/app/AlertDropWizardConfiguration.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/java/org/apache/eagle/service/app/AlertDropWizardConfiguration.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/java/org/apache/eagle/service/app/AlertDropWizardConfiguration.java deleted file mode 100644 index c44a950..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/java/org/apache/eagle/service/app/AlertDropWizardConfiguration.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.eagle.service.app; - -import io.dropwizard.Configuration; - -import javax.validation.Valid; - -/** - * @since Jun 27, 2016. - */ -public class AlertDropWizardConfiguration extends Configuration { - - @Valid - private String applicationConfPath; - - public String getApplicationConfPath() { - return applicationConfPath; - } - - public void setApplicationConfPath(String applicationConfPath) { - this.applicationConfPath = applicationConfPath; - } - -} http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/java/org/apache/eagle/service/app/ServiceApp.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/java/org/apache/eagle/service/app/ServiceApp.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/java/org/apache/eagle/service/app/ServiceApp.java deleted file mode 100644 index 0f8b57e..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/java/org/apache/eagle/service/app/ServiceApp.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.eagle.service.app; - -import org.apache.eagle.alert.coordinator.CoordinatorListener; -import org.apache.eagle.alert.coordinator.resource.CoordinatorResource; -import org.apache.eagle.alert.resource.SimpleCORSFiler; -import org.apache.eagle.service.metadata.resource.MetadataResource; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.typesafe.config.ConfigFactory; -import io.dropwizard.Application; -import io.dropwizard.setup.Bootstrap; -import io.dropwizard.setup.Environment; -import io.swagger.jaxrs.config.BeanConfig; -import io.swagger.jaxrs.listing.ApiListingResource; -import org.apache.commons.lang3.StringUtils; - -import java.util.EnumSet; -import javax.servlet.DispatcherType; - -/** - * @since Jun 27, 2016. - */ -public class ServiceApp extends Application<AlertDropWizardConfiguration> { - - public static void main(String[] args) throws Exception { - new ServiceApp().run(args); - } - - @Override - public String getName() { - return "alert-engine metadata server and coordinator server!"; - } - - @Override - public void initialize(Bootstrap<AlertDropWizardConfiguration> bootstrap) { - } - - @Override - public void run(AlertDropWizardConfiguration configuration, Environment environment) throws Exception { - if (StringUtils.isNotEmpty(configuration.getApplicationConfPath())) { - // setup config if given - System.setProperty("config.resource", configuration.getApplicationConfPath()); - ConfigFactory.invalidateCaches(); - ConfigFactory.load(); - } - - environment.getApplicationContext().setContextPath("/rest"); - environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL); - - environment.jersey().register(MetadataResource.class); - environment.jersey().register(CoordinatorResource.class); - - // swagger resources - environment.jersey().register(new ApiListingResource()); - BeanConfig swaggerConfig = new BeanConfig(); - swaggerConfig.setTitle("Alert engine service: metadata and coordinator"); - swaggerConfig.setVersion("v1.2"); - swaggerConfig.setBasePath("/rest"); - swaggerConfig - .setResourcePackage("org.apache.eagle.alert.coordinator.resource,org.apache.eagle.service.metadata.resource"); - swaggerConfig.setScan(true); - - // simple CORS filter - environment.servlets().addFilter("corsFilter", new SimpleCORSFiler()) - .addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*"); - - // context listener - environment.servlets().addServletListeners(new CoordinatorListener()); - } - -} http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/resources/application.conf ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/resources/application.conf b/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/resources/application.conf deleted file mode 100644 index db78706..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/resources/application.conf +++ /dev/null @@ -1,61 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -{ - "coordinator": { - "policiesPerBolt": 30, - "boltParallelism": 5, - "policyDefaultParallelism": 5, - "boltLoadUpbound": 0.8, - "topologyLoadUpbound": 0.8, - "numOfAlertBoltsPerTopology": 20, - "zkConfig": { - "zkQuorum": "127.0.0.1:2181", - "zkRoot": "/alert", - "zkSessionTimeoutMs": 10000, - "connectionTimeoutMs": 10000, - "zkRetryTimes": 3, - "zkRetryInterval": 3000 - }, - "metadataService": { - "host": "localhost", - "port": 8080, - "context": "/rest", - mailSmtpServer = "localhost", - mailSmtpPort = 25, - mailSmtpAuth = "false" - //mailSmtpConn = "plaintext", - //mailSmtpUsername = "" - //mailSmtpPassword = "" - //mailSmtpDebug = false - }, - "metadataDynamicCheck": { - "initDelayMillis": 1000, - "delayMillis": 30000 - }, - "kafkaProducer": { - "bootstrapServers": "127.0.0.1:9092" - }, - "email": { - "sender": "[email protected]", - "recipients": "[email protected]", - "mailSmtpHost": "test.eagle.com", - "mailSmtpPort": "25" - } - }, - "datastore": { - "metadataDao": "org.apache.eagle.alert.metadata.impl.InMemMetadataDaoImpl" - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/resources/log4j.properties b/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/resources/log4j.properties deleted file mode 100644 index 5337cae..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/resources/log4j.properties +++ /dev/null @@ -1,19 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -log4j.rootLogger=ERROR, stdout -# standard output -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} %p [%t] %c{2}[%L]: %m%n http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/webapp/WEB-INF/web.xml ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/webapp/WEB-INF/web.xml b/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 956d724..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,96 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one or more - ~ contributor license agreements. See the NOTICE file distributed with - ~ this work for additional information regarding copyright ownership. - ~ The ASF licenses this file to You under the Apache License, Version 2.0 - ~ (the "License"); you may not use this file except in compliance with - ~ the License. You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, software - ~ distributed under the License is distributed on an "AS IS" BASIS, - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ~ See the License for the specific language governing permissions and - ~ limitations under the License. - --> -<web-app xmlns="http://java.sun.com/xml/ns/javaee" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://java.sun.com/xml/ns/javaee - http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" - version="3.0"> - <welcome-file-list> - <welcome-file>index.html</welcome-file> - </welcome-file-list> - - <listener> - <listener-class>org.apache.eagle.alert.coordinator.CoordinatorListener</listener-class> - </listener> - - <servlet> - <servlet-name>Jersey Web Application</servlet-name> - <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> - <init-param> - <param-name>com.sun.jersey.config.property.packages</param-name> - <param-value>io.swagger.jaxrs.json,io.swagger.jaxrs.listing,org.apache.eagle,org.fasterxml.jackson.jaxrs - </param-value> - </init-param> - <init-param> - <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name> - <param-value> - com.sun.jersey.api.container.filter.GZIPContentEncodingFilter;com.sun.jersey.api.container.filter.PostReplaceFilter - </param-value> - </init-param> - <init-param> - <param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name> - <param-value>com.sun.jersey.api.container.filter.GZIPContentEncodingFilter</param-value> - </init-param> - <load-on-startup>1</load-on-startup> - </servlet> - <!-- Servlet for swagger initialization only, no URL mapping. --> - <servlet> - <servlet-name>swaggerConfig</servlet-name> - <servlet-class>io.swagger.jaxrs.config.DefaultJaxrsConfig</servlet-class> - <init-param> - <param-name>api.version</param-name> - <param-value>1.0.0</param-value> - </init-param> - <init-param> - <param-name>swagger.api.basepath</param-name> - <param-value>/rest</param-value> - </init-param> - <load-on-startup>2</load-on-startup> - </servlet> - <servlet-mapping> - <servlet-name>Jersey Web Application</servlet-name> - <url-pattern>/rest/*</url-pattern> - </servlet-mapping> - <filter> - <filter-name>CorsFilter</filter-name> - <!-- this should be replaced by tomcat ones, see also metadata resource --> - <filter-class>org.apache.eagle.alert.resource.SimpleCORSFiler</filter-class> - <init-param> - <param-name>cors.allowed.origins</param-name> - <param-value>*</param-value> - </init-param> - <init-param> - <param-name>cors.allowed.headers</param-name> - <param-value>Authorization,Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, - Cache-Control, Expires, Content-Type, X-E4M-With, Accept - </param-value> - </init-param> - <init-param> - <param-name>cors.allowed.methods</param-name> - <param-value>GET,POST,HEAD,OPTIONS,PUT,DELETE</param-value> - </init-param> - <init-param> - <param-name>cors.support.credentials</param-name> - <param-value>true</param-value> - </init-param> - </filter> - <filter-mapping> - <filter-name>CorsFilter</filter-name> - <url-pattern>/*</url-pattern> - </filter-mapping> -</web-app> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/webapp/index.html ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/webapp/index.html b/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/webapp/index.html deleted file mode 100644 index ef8bf54..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/webapp/index.html +++ /dev/null @@ -1,19 +0,0 @@ -<!-- - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - --> - -Alert Services: Coordinator + Metadata Service \ No newline at end of file http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/test/java/com/apache/eagle/service/app/AlertServiceTestBase.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/test/java/com/apache/eagle/service/app/AlertServiceTestBase.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/test/java/com/apache/eagle/service/app/AlertServiceTestBase.java deleted file mode 100644 index 3f6ae0b..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/test/java/com/apache/eagle/service/app/AlertServiceTestBase.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.apache.eagle.service.app; - -import org.apache.eagle.alert.utils.ZookeeperEmbedded; -import org.apache.eagle.service.app.ServiceApp; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Start embedded zookeeper, coordinator and alert service. - */ -public class AlertServiceTestBase { - private static final Logger LOG = LoggerFactory.getLogger(AlertServiceTestBase.class); - - private static ZookeeperEmbedded zkEmbed; - private static int zkPort; - private static int serverPort; - private static Thread serverThread; - - @BeforeClass - public static void startZookeeperAndServiceServer() throws Throwable { - zkEmbed = new ZookeeperEmbedded(2181); - zkPort = zkEmbed.start(); - System.setProperty("coordinator.zkConfig.zkQuorum", "localhost:" + zkPort); - - System.setProperty("dw.server.applicationConnectors[0].port", "7777"); - System.setProperty("dw.server.adminConnectors[0].port", "7771"); - serverPort = tryStartServerApp(8080); - - LOG.info("Started Zookeeper on port {} and Service on port {}", zkPort, serverPort); - } - - /** - * @param initialPort initial server port - * @return bind server port - * @throws Exception throws if failed more then 3 times. - */ - private static int tryStartServerApp(int initialPort) throws Throwable { - final AtomicInteger port = new AtomicInteger(initialPort); - final AtomicBoolean success = new AtomicBoolean(false); - serverThread = new Thread(() -> { - String userDir = System.getProperty("user.dir"); - String serverConf = userDir + "/src/test/resources/configuration.yml"; - Throwable lastException = null; - int tried = 0; - while (!success.get() && tried < 3) { - LOG.info("Starting server in port {}", port); - System.setProperty("dw.server.applicationConnectors[0].port", String.valueOf(port.intValue())); - System.setProperty("dw.server.adminConnectors[0].port", String.valueOf(port.intValue() + 1)); - try { - new ServiceApp().run(new String[] {"server", serverConf}); - success.set(true); - } catch (Throwable e) { - LOG.warn(e.getMessage(), e); - tried++; - port.incrementAndGet(); - lastException = e; - } - } - if (!success.get()) { - LOG.error("Failed to start server after tried 3 times"); - throw new IllegalStateException(lastException); - } - }); - serverThread.start(); - serverThread.join(); - return port.get(); - } - - public static int getBindServerPort() { - return serverPort; - } - - public static int getBindZkPort() { - return zkPort; - } - - @AfterClass - public static void shutdownZookeeperAndServiceServer() throws Exception { - if (zkEmbed != null) { - zkEmbed.shutdown(); - } - if (serverThread != null && serverThread.isAlive()) { - serverThread.interrupt(); - } - } -} http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/test/java/com/apache/eagle/service/app/TestServiceTestAppWithZk.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/test/java/com/apache/eagle/service/app/TestServiceTestAppWithZk.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/test/java/com/apache/eagle/service/app/TestServiceTestAppWithZk.java deleted file mode 100644 index ef82ca6..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/test/java/com/apache/eagle/service/app/TestServiceTestAppWithZk.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.apache.eagle.service.app; - -import com.typesafe.config.Config; -import com.typesafe.config.ConfigFactory; -import org.apache.eagle.alert.engine.coordinator.PolicyDefinition; -import org.apache.eagle.alert.engine.coordinator.PolicyDefinition.Definition; -import org.apache.eagle.alert.service.IMetadataServiceClient; -import org.apache.eagle.alert.service.MetadataServiceClientImpl; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; - -import java.io.IOException; -import java.util.Collections; -import java.util.List; - -public class TestServiceTestAppWithZk extends AlertServiceTestBase { - @Ignore - @Test - public void testMain() throws Exception { - System.setProperty("coordinator.zkConfig.zkQuorum", "localhost:" + getBindZkPort()); - Config config = ConfigFactory.load().getConfig("coordinator"); - // build dynamic policy loader - String host = config.getString("metadataService.host"); - String context = config.getString("metadataService.context"); - IMetadataServiceClient client = new MetadataServiceClientImpl(host, getBindServerPort(), context); - - List<PolicyDefinition> policies = client.listPolicies(); - - Assert.assertEquals(0, policies.size()); - - PolicyDefinition def = new PolicyDefinition(); - def.setName("test-policy-1"); - def.setInputStreams(Collections.singletonList("testStreamDef")); - def.setOutputStreams(Collections.singletonList("test-datasource-1")); - def.setParallelismHint(5); - def.setDefinition(new Definition()); - client.addPolicy(def); - - policies = client.listPolicies(); - - Assert.assertEquals(1, policies.size()); - - try { - client.close(); - } catch (IOException e) { - // ignore - } - } - -} http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/test/resources/configuration.yml ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/test/resources/configuration.yml b/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/test/resources/configuration.yml deleted file mode 100644 index 6dc864d..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/test/resources/configuration.yml +++ /dev/null @@ -1,22 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -server: - applicationConnectors: - - type: http - port: 9090 - adminConnectors: - - type: http - port: 9091 \ No newline at end of file
