http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0ea130ef/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/executor/AlertExecutorCreationUtils.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/executor/AlertExecutorCreationUtils.java b/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/executor/AlertExecutorCreationUtils.java deleted file mode 100644 index 8ab290e..0000000 --- a/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/executor/AlertExecutorCreationUtils.java +++ /dev/null @@ -1,111 +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.executor; - -import java.util.List; -import java.util.Map; - -import org.apache.eagle.policy.dao.PolicyDefinitionDAO; -import org.apache.eagle.alert.entity.AlertDefinitionAPIEntity; -import org.apache.eagle.policy.DefaultPolicyPartitioner; -import org.apache.eagle.policy.PolicyPartitioner; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.typesafe.config.Config; -import com.typesafe.config.ConfigValue; - -/** - * Create alert executors and provide callback for programmer to link alert executor to immediate parent executors - * - * <br/><br/> - * Explanations for programId, alertExecutorId and policy<br/><br/> - * - programId - distributed or single-process program for example one storm topology<br/> - * - alertExecutorId - one process/thread which executes multiple policies<br/> - * - policy - some rules to be evaluated<br/> - * - * <br/> - * - * Normally the mapping is like following: - * <pre> - * programId (1:N) alertExecutorId - * alertExecutorId (1:N) policy - * </pre> - */ -public class AlertExecutorCreationUtils { - private final static Logger LOG = LoggerFactory.getLogger(AlertExecutorCreationUtils.class); - - - /** - * Build DAG Tasks based on persisted alert definition and schemas from eagle store. - * - * <h3>Require configuration:</h3> - * - * <ul> - * <li>eagleProps.site: program site id.</li> - * <li>eagleProps.dataSource: program data source.</li> - * <li>alertExecutorConfigs: only configured executor will be built into execution tasks.</li> - * </ul> - * - * <h3>Steps:</h3> - * - * <ol> - * <li>(upstreamTasks) => Map[streamName:String,upstreamTask:Task]</li> - * <li>(dataSource) => Map[alertExecutorId:String,streamName:List[String]]</li> - * <li>(site,dataSource) => Map[alertExecutorId,Map[policyId,alertDefinition]]</li> - * <li>(config["alertExecutorConfigs"]) => AlertExecutor(alertExecutorID, partitioner, numPartitions, partitionSeq, alertDefs, alertDefDAO, sourceStreams)[]</li> - * </ol> - */ - public static AlertExecutor[] createAlertExecutors(Config config, PolicyDefinitionDAO<AlertDefinitionAPIEntity> alertDefDAO, - List<String> streamNames, String alertExecutorId) throws Exception{ - // Read `alertExecutorConfigs` from configuration and get config for this alertExecutorId - int numPartitions =1; - String partitionerCls = DefaultPolicyPartitioner.class.getCanonicalName(); - String alertExecutorConfigsKey = "alertExecutorConfigs"; - if(config.hasPath(alertExecutorConfigsKey)) { - Map<String, ConfigValue> alertExecutorConfigs = config.getObject(alertExecutorConfigsKey); - if(alertExecutorConfigs !=null && alertExecutorConfigs.containsKey(alertExecutorId)) { - Map<String, Object> alertExecutorConfig = (Map<String, Object>) alertExecutorConfigs.get(alertExecutorId).unwrapped(); - int parts = 0; - if(alertExecutorConfig.containsKey("parallelism")) parts = (int) (alertExecutorConfig.get("parallelism")); - numPartitions = parts == 0 ? 1 : parts; - if(alertExecutorConfig.containsKey("partitioner")) partitionerCls = (String) alertExecutorConfig.get("partitioner"); - } - } - - return createAlertExecutors(alertDefDAO, streamNames, alertExecutorId, numPartitions, partitionerCls); - } - - /** - * Build alert executors and assign alert definitions between these executors by partitioner (alertExecutorConfigs["${alertExecutorId}"]["partitioner"]) - */ - public static AlertExecutor[] createAlertExecutors(PolicyDefinitionDAO alertDefDAO, List<String> sourceStreams, - String alertExecutorID, int numPartitions, String partitionerCls) throws Exception{ - LOG.info("Creating alert executors with alertExecutorID: " + alertExecutorID + ", numPartitions: " + numPartitions + ", Partition class is: "+ partitionerCls); - - // TODO: Create sourceStreams with alertExecutorID into AlertExecutorService - - PolicyPartitioner partitioner = (PolicyPartitioner)Class.forName(partitionerCls).newInstance(); - AlertExecutor[] alertExecutors = new AlertExecutor[numPartitions]; - String[] _sourceStreams = sourceStreams.toArray(new String[0]); - - for(int i = 0; i < numPartitions; i++){ - alertExecutors[i] = new AlertExecutor(alertExecutorID, partitioner, numPartitions, i, alertDefDAO,_sourceStreams); - } - return alertExecutors; - } -}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0ea130ef/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/notification/AlertNotificationExecutor.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/notification/AlertNotificationExecutor.java b/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/notification/AlertNotificationExecutor.java deleted file mode 100644 index b024c39..0000000 --- a/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/notification/AlertNotificationExecutor.java +++ /dev/null @@ -1,128 +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.notification; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import org.apache.eagle.notification.plugin.NotificationPluginManagerImpl; -import org.apache.eagle.policy.dao.PolicyDefinitionDAO; -import org.apache.eagle.alert.entity.AlertAPIEntity; -import org.apache.eagle.alert.entity.AlertDefinitionAPIEntity; -import org.apache.eagle.policy.DynamicPolicyLoader; -import org.apache.eagle.policy.PolicyLifecycleMethods; -import org.apache.eagle.datastream.Collector; -import org.apache.eagle.datastream.JavaStormStreamExecutor1; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.typesafe.config.Config; -import scala.Tuple1; - -/** - * notify alert by email, kafka message, storage or other means - */ -public class AlertNotificationExecutor extends JavaStormStreamExecutor1<String> implements PolicyLifecycleMethods<AlertDefinitionAPIEntity> { - private static final long serialVersionUID = 1690354365435407034L; - private static final Logger LOG = LoggerFactory.getLogger(AlertNotificationExecutor.class); - private Config config; - /** Notification Manager - Responsible for forward and invoke configured Notification Plugin **/ - private NotificationPluginManagerImpl notificationManager; - - private List<String> alertExecutorIdList; - private PolicyDefinitionDAO dao; - - - public AlertNotificationExecutor(List<String> alertExecutorIdList, PolicyDefinitionDAO dao){ - this.alertExecutorIdList = alertExecutorIdList; - this.dao = dao; - } - - @Override - public void init() { - String site = config.getString("eagleProps.site"); - String application = config.getString("eagleProps.application"); - Map<String, Map<String, AlertDefinitionAPIEntity>> initialAlertDefs; - try { - initialAlertDefs = dao.findActivePoliciesGroupbyExecutorId( site, application ); - } - catch (Exception ex) { - LOG.error("fail to initialize initialAlertDefs: ", ex); - throw new IllegalStateException("fail to initialize initialAlertDefs: ", ex); - } - - if(initialAlertDefs == null || initialAlertDefs.isEmpty()){ - LOG.warn("No alert definitions found for site: "+site+", application: "+ application); - } - try{ - notificationManager = new NotificationPluginManagerImpl(config); - }catch (Exception ex ){ - LOG.error("Fail to initialize NotificationManager: ", ex); - throw new IllegalStateException("Fail to initialize NotificationManager: ", ex); - } - - DynamicPolicyLoader<AlertDefinitionAPIEntity> policyLoader = DynamicPolicyLoader.getInstanceOf(AlertDefinitionAPIEntity.class); - policyLoader.init(initialAlertDefs, dao, config); - for (String alertExecutorId : alertExecutorIdList) { - policyLoader.addPolicyChangeListener(alertExecutorId, this); - } - } - - @Override - public void prepareConfig(Config config) { - this.config = config; - } - - @Override - public void flatMap(java.util.List<Object> input, Collector<Tuple1<String>> outputCollector){ - AlertAPIEntity alertEntity = (AlertAPIEntity) input.get(1); - processAlerts(Arrays.asList(alertEntity)); - } - - private void processAlerts(List<AlertAPIEntity> list) { - for (AlertAPIEntity entity : list) { - notificationManager.notifyAlert(entity); - } - } - - @Override - public void onPolicyCreated(Map<String, AlertDefinitionAPIEntity> added) { - if(LOG.isDebugEnabled()) LOG.debug(" alert notification config changed : " + added); - for(AlertDefinitionAPIEntity alertDef : added.values()){ - LOG.info("alert notification config really changed " + alertDef); - notificationManager.updateNotificationPlugins( alertDef , false ); - } - } - - @Override - public void onPolicyChanged(Map<String, AlertDefinitionAPIEntity> changed) { - if(LOG.isDebugEnabled()) LOG.debug("alert notification config to be added : " + changed); - for(AlertDefinitionAPIEntity alertDef : changed.values()){ - LOG.info("alert notification config really added " + alertDef); - notificationManager.updateNotificationPlugins( alertDef , false ); - } - } - - @Override - public void onPolicyDeleted(Map<String, AlertDefinitionAPIEntity> deleted) { - if(LOG.isDebugEnabled()) LOG.debug("alert notification config to be deleted : " + deleted); - for(AlertDefinitionAPIEntity alertDef : deleted.values()){ - LOG.info("alert notification config really deleted " + alertDef); - notificationManager.updateNotificationPlugins( alertDef , true ); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0ea130ef/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/persist/AlertPersistExecutor.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/persist/AlertPersistExecutor.java b/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/persist/AlertPersistExecutor.java deleted file mode 100644 index 61bb7dc..0000000 --- a/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/persist/AlertPersistExecutor.java +++ /dev/null @@ -1,56 +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.persist; - -import org.apache.eagle.alert.entity.AlertAPIEntity; -import com.typesafe.config.Config; -import org.apache.eagle.common.config.EagleConfigConstants; -import org.apache.eagle.datastream.Collector; -import org.apache.eagle.datastream.JavaStormStreamExecutor1; -import scala.Tuple1; - -import java.util.Arrays; - -public class AlertPersistExecutor extends JavaStormStreamExecutor1<String> { - - private static final long serialVersionUID = 1L; - private Config config; - private EaglePersist persist; - - public AlertPersistExecutor(){ - } - @Override - public void prepareConfig(Config config) { - this.config = config; - } - - @Override - public void init() { - String host = config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.HOST); - int port = config.getInt(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PORT); - String username = config.hasPath(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.USERNAME) - ? config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.USERNAME) : null; - String password = config.hasPath(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PASSWORD) - ? config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PASSWORD) : null; - this.persist = new EaglePersist(host, port, username, password); - } - - @Override - public void flatMap(java.util.List<Object> input, Collector<Tuple1<String>> outputCollector){ - persist.doPersist(Arrays.asList((AlertAPIEntity)(input.get(1)))); - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0ea130ef/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/persist/EaglePersist.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/persist/EaglePersist.java b/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/persist/EaglePersist.java deleted file mode 100644 index ebba518..0000000 --- a/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/persist/EaglePersist.java +++ /dev/null @@ -1,71 +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.persist; - -import org.apache.eagle.log.base.taggedlog.TaggedLogAPIEntity; -import org.apache.eagle.log.entity.GenericServiceAPIResponseEntity; -import org.apache.eagle.service.client.IEagleServiceClient; -import org.apache.eagle.service.client.impl.EagleServiceClientImpl; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; - -public class EaglePersist { - - private static Logger LOG = LoggerFactory.getLogger(EaglePersist.class); - private String eagleServiceHost; - private int eagleServicePort; - private String username; - private String password; - - public EaglePersist(String eagleServiceHost, int eagleServicePort) { - this(eagleServiceHost, eagleServicePort, null, null); - } - - public EaglePersist(String eagleServiceHost, int eagleServicePort, String username, String password) { - this.eagleServiceHost = eagleServiceHost; - this.eagleServicePort = eagleServicePort; - this.username = username; - this.password = password; - } - - public boolean doPersist(List<? extends TaggedLogAPIEntity> list) { - if (list.isEmpty()) return false; - LOG.info("Going to persist entities, type: " + " " + list.get(0).getClass().getSimpleName() + ", list size: " + list.size()); - try { - IEagleServiceClient client = new EagleServiceClientImpl(eagleServiceHost, eagleServicePort, username, password); - GenericServiceAPIResponseEntity<String> response = client.create(list); - client.close(); - if (response.isSuccess()) { - LOG.info("Successfully create entities " + list.toString()); - return true; - } - else { - LOG.error("Fail to create entities"); - return false; - } - } - catch (Exception ex) { - LOG.error("Got an exception in persisting entities" + ex.getMessage(), ex); - return false; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0ea130ef/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/siddhi/SiddhiAlertAPIEntityRender.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/siddhi/SiddhiAlertAPIEntityRender.java b/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/siddhi/SiddhiAlertAPIEntityRender.java deleted file mode 100644 index d1e1bdc..0000000 --- a/eagle-core/eagle-alert/eagle-alert-process/src/main/java/org/apache/eagle/alert/siddhi/SiddhiAlertAPIEntityRender.java +++ /dev/null @@ -1,109 +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.siddhi; - -import com.typesafe.config.Config; -import org.apache.eagle.alert.entity.AlertAPIEntity; -import org.apache.eagle.alert.entity.AlertDefinitionAPIEntity; -import org.apache.eagle.alert.entity.AlertStreamSchemaEntity; -import org.apache.eagle.common.DateTimeUtil; -import org.apache.eagle.common.config.EagleConfigConstants; -import org.apache.eagle.common.metric.AlertContext; -import org.apache.eagle.policy.PolicyEvaluationContext; -import org.apache.eagle.policy.ResultRender; -import org.apache.eagle.policy.common.Constants; -import org.apache.eagle.policy.common.UrlBuilder; -import org.apache.eagle.policy.siddhi.SiddhiPolicyEvaluator; -import org.apache.eagle.policy.siddhi.SiddhiQueryCallbackImpl; -import org.apache.eagle.policy.siddhi.StreamMetadataManager; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.Serializable; -import java.lang.management.ManagementFactory; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -public class SiddhiAlertAPIEntityRender implements ResultRender<AlertDefinitionAPIEntity, AlertAPIEntity>, Serializable { - - public static final Logger LOG = LoggerFactory.getLogger(SiddhiAlertAPIEntityRender.class); - public static final String source = ManagementFactory.getRuntimeMXBean().getName(); - - @Override - @SuppressWarnings("unchecked") - public AlertAPIEntity render(Config config, List<Object> results, PolicyEvaluationContext<AlertDefinitionAPIEntity, AlertAPIEntity> siddhiAlertContext, long timestamp) { - List<String> rets = SiddhiQueryCallbackImpl.convertToString(results); - SiddhiPolicyEvaluator<AlertDefinitionAPIEntity, AlertAPIEntity> evaluator = (SiddhiPolicyEvaluator<AlertDefinitionAPIEntity, AlertAPIEntity>) siddhiAlertContext.evaluator; - String alertExecutorId = siddhiAlertContext.alertExecutor.getExecutorId(); - AlertAPIEntity entity = new AlertAPIEntity(); - AlertContext context = new AlertContext(); - String sourceStreams = evaluator.getAdditionalContext().get(Constants.SOURCE_STREAMS); - String[] sourceStreamsArr = sourceStreams.split(","); - List<String> attrRenameList = evaluator.getOutputStreamAttrNameList(); - Map<String, String> tags = new HashMap<String, String>(); - for (String sourceStream : sourceStreamsArr) { - List<AlertStreamSchemaEntity> list = StreamMetadataManager.getInstance().getMetadataEntitiesForStream(sourceStream.trim()); - for (AlertStreamSchemaEntity alertStream : list) { - if (alertStream.getUsedAsTag() != null && alertStream.getUsedAsTag() == true) { - String attrName = alertStream.getTags().get(Constants.ATTR_NAME); - tags.put(attrName, rets.get(attrRenameList.indexOf(attrName))); - } - } - } - - for (int index = 0; index < rets.size(); index++) { - //attrRenameList.get(0) -> "eagleAlertContext". We need to skip "eagleAlertContext", index is from 1 for attRenameList. - context.addProperty(attrRenameList.get(index), rets.get(index)); - } - - StringBuilder sb = new StringBuilder(); - for (Entry<String, String> entry : context.getProperties().entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - sb.append(key + "=\"" + value + "\" "); - } - context.addAll(evaluator.getAdditionalContext()); - String policyId = context.getProperty(Constants.POLICY_ID); - String alertMessage = "The Policy \"" + policyId + "\" has been detected with the below information: " + sb.toString() ; - String site = config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.SITE); - String application = config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.APPLICATION); - String host = config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.HOST); - Integer port = config.getInt(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PORT); - - context.addProperty(Constants.ALERT_EVENT, sb.toString()); - context.addProperty(Constants.ALERT_MESSAGE, alertMessage); - context.addProperty(Constants.ALERT_TIMESTAMP_PROPERTY, DateTimeUtil.millisecondsToHumanDateWithSeconds(System.currentTimeMillis())); - context.addProperty(EagleConfigConstants.APPLICATION, application); - context.addProperty(EagleConfigConstants.SITE, site); - entity.setTimestamp(timestamp); - /** If we need to add severity tag, we should add severity filed in AbstractpolicyDefinition, and pass it down **/ - tags.put(EagleConfigConstants.SITE, site); - tags.put(EagleConfigConstants.APPLICATION, application); - tags.put(Constants.SOURCE_STREAMS, context.getProperty(Constants.SOURCE_STREAMS)); - tags.put(Constants.POLICY_ID, context.getProperty(Constants.POLICY_ID)); - tags.put(Constants.ALERT_SOURCE, source); - tags.put(Constants.ALERT_EXECUTOR_ID, alertExecutorId); - entity.setTags(tags); - - context.addProperty(Constants.POLICY_DETAIL_URL, UrlBuilder.buiildPolicyDetailUrl(host, port, tags)); - context.addProperty(Constants.ALERT_DETAIL_URL, UrlBuilder.buildAlertDetailUrl(host, port, entity)); - entity.setAlertContext(context); - return entity; - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0ea130ef/eagle-core/eagle-alert/eagle-alert-process/src/main/resources/ALERT_DEFAULT.vm ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-process/src/main/resources/ALERT_DEFAULT.vm b/eagle-core/eagle-alert/eagle-alert-process/src/main/resources/ALERT_DEFAULT.vm deleted file mode 100644 index d4571f3..0000000 --- a/eagle-core/eagle-alert/eagle-alert-process/src/main/resources/ALERT_DEFAULT.vm +++ /dev/null @@ -1,266 +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. - --> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml"> - <head> - <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> - <meta name="viewport" content="width=device-width"/> - <style> - body { - width:100% !important; - min-width: 100%; - -webkit-text-size-adjust:100%; - -ms-text-size-adjust:100%; - margin:0; - padding:0; - } - - table { - border-spacing: 0; - border-collapse: collapse; - } - - table th, - table td { - padding: 3px 0 3px 0; - } - - .body { - width: 100%; - } - - p,a,h1,h2,h3,ul,ol,li { - font-family: Helvetica, Arial, sans-serif; - font-weight: normal; - margin: 0; - padding: 0; - } - p { - font-size: 14px; - line-height: 19px; - } - a { - color: #3294b1; - } - h1 { - font-size: 36px; - margin: 15px 0 5px 0; - } - h2 { - font-size: 32px; - } - h3 { - font-size: 28px; - } - - ul,ol { - margin: 0 0 0 25px; - padding: 0; - } - - .btn { - background: #2ba6cb !important; - border: 1px solid #2284a1; - padding: 10px 20px 10px 20px; - text-align: center; - } - .btn:hover { - background: #2795b6 !important; - } - .btn a { - color: #FFFFFF; - text-decoration: none; - font-weight: bold; - padding: 10px 20px 10px 20px; - } - - .tableBordered { - border-top: 1px solid #b9e5ff; - } - .tableBordered th { - background: #ECF8FF; - } - .tableBordered th p { - font-weight: bold; - color: #3294b1; - } - .tableBordered th, - .tableBordered td { - color: #333333; - border-bottom: 1px solid #b9e5ff; - text-align: center; - padding-bottom: 5px; - } - - .panel { - height: 100px; - } - </style> - </head> - <body> - #set ( $elem = $alertList[0] ) - #set ( $alertUrl = $elem["alertDetailUrl"] ) - #set ( $policyUrl = $elem["policyDetailUrl"] ) - <table class="body"> - <tr> - <td align="center" valign="top" style="background: #999999; padding: 0 0 0 0;"> - <!-- Eagle Header --> - <table width="580"> - <tr> - <td style="padding: 0 0 0 0;" align="left" > - <p style="color:#FFFFFF;font-weight: bold; font-size: 24px">Eagle</p> - </td> - </tr> - </table> - </td> - </tr> - - <tr> - <td align="center" valign="top"> - <!-- Eagle Body --> - <table width="580"> - <tr> - <!-- Title --> - <td align="center"> - <h1>$elem["dataSource"] Alert Detected</h1> - </td> - </tr> - <tr> - <!-- Time --> - <td> - <table width="580"> - <tr> - <td> - <p><b>Detected Time: $elem["alertTimestamp"]</b></p> - </td> - #set ( $severity = $elem["severity"] ) - #if (!$severity || ("$severity" == "")) - #set ( $elem["severity"] = "WARNING") - #end - <td align="right"> - <p><b> - Severity: - #if ($elem["severity"] == "WARNING") - <span>$elem["severity"]</span> - #else - <span style="color: #FF0000;">$elem["severity"]</span> - #end - </b></p> - </td> - </tr> - </table> - </td> - </tr> - <tr> - <!-- Description --> - <td valign="top" style="background: #ECF8FF; border: 1px solid #b9e5ff; padding: 10px 10px 12px 10px;"> - <p>$elem["alertMessage"]</p> - </td> - </tr> - <tr> - <!-- View Detail --> - <td align="center" style="padding: 10px 0 0 0;"> - <table width="580"> - <tr> - <td class="btn"> - <a href="$alertUrl">View Alert Details on Eagle Web</a> - </td> - </tr> - </table> - </td> - </tr> - <tr> - <!-- Basic Information --> - <td style="padding: 20px 0 0 0;"> - <p><b>Basic Information:</b></p> - </td> - </tr> - <tr> - <!-- Basic Information Content --> - <td> - <table class="tableBordered" width="580"> - <tr> - <th> - <p>Site</p> - </th> - <th> - <p>Data Source</p> - </th> - </tr> - <tr> - <td> - <p>$elem["site"]</p> - </td> - <td> - <p>$elem["dataSource"]</p> - </td> - </tr> - <tr> - <th> - <p>Policy Name</p> - </th> - <th> - <p>Severity</p> - </th> - </tr> - <tr> - <td> - <p>$elem["policyId"]</p> - </td> - <td> - <p>$elem["severity"]</p> - </td> - </tr> - </table> - </td> - </tr> - <tr> - <!-- View Detail --> - <td align="center" style="padding: 10px 0 0 0;"> - <table width="580"> - <tr> - <td class="btn"> - <a href="$policyUrl">View Policy Details on Eagle Web</a> - </td> - </tr> - </table> - </td> - </tr> - <tr> - <!-- Actions Required --> - <td style="padding: 20px 0 0 0;"> - <p><b>Actions Required:</b></p> - </td> - </tr> - <tr> - <!-- Possible Root Causes Content --> - <td class="panel" valign="top" style="background: #F4F4F4; border: 1px solid #AAAAAA; padding: 10px 10px 12px 10px;"> - <p> $elem["dataSource"] alert found, please check.</p> - </td> - </tr> - <tr> - <!-- Copyright --> - <td align="center"> - <p><a href="http://123.xyz.com/alerts/alertlist.html">Copyright 2014 @ Hadoop Eagle</a></p> - </td> - </tr> - </table> - </td> - </tr> - </table> - </body> -</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0ea130ef/eagle-core/eagle-alert/eagle-alert-process/src/main/resources/META-INF/services/org.apache.eagle.policy.PolicyEvaluatorServiceProvider ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-process/src/main/resources/META-INF/services/org.apache.eagle.policy.PolicyEvaluatorServiceProvider b/eagle-core/eagle-alert/eagle-alert-process/src/main/resources/META-INF/services/org.apache.eagle.policy.PolicyEvaluatorServiceProvider deleted file mode 100644 index eac2bfd..0000000 --- a/eagle-core/eagle-alert/eagle-alert-process/src/main/resources/META-INF/services/org.apache.eagle.policy.PolicyEvaluatorServiceProvider +++ /dev/null @@ -1,16 +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. - -org.apache.eagle.policy.siddhi.SiddhiPolicyEvaluatorServiceProviderImpl \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0ea130ef/eagle-core/eagle-alert/eagle-alert-process/src/main/resources/table-create.script ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-process/src/main/resources/table-create.script b/eagle-core/eagle-alert/eagle-alert-process/src/main/resources/table-create.script deleted file mode 100644 index d4d3795..0000000 --- a/eagle-core/eagle-alert/eagle-alert-process/src/main/resources/table-create.script +++ /dev/null @@ -1,24 +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 alert related tables -create 'eagle_metric', {NAME => 'f', VERSIONS => '3', BLOOMFILTER => 'ROW', COMPRESSION => 'SNAPPY'} -create 'alertdetail', {NAME => 'f', VERSIONS => '3', BLOOMFILTER => 'ROW', COMPRESSION => 'SNAPPY'} - -create 'alertDataSource', {NAME => 'f', VERSIONS => '3', BLOOMFILTER => 'ROW', COMPRESSION => 'SNAPPY'} -create 'alertStream', {NAME => 'f', VERSIONS => '3', BLOOMFILTER => 'ROW', COMPRESSION => 'SNAPPY'} -create 'alertExecutor', {NAME => 'f', VERSIONS => '3', BLOOMFILTER => 'ROW', COMPRESSION => 'SNAPPY'} -create 'alertStreamSchema', {NAME => 'f', VERSIONS => '3', BLOOMFILTER => 'ROW', COMPRESSION => 'SNAPPY'} -create 'alertdef', {NAME => 'f', VERSIONS => '3', BLOOMFILTER => 'ROW', COMPRESSION => 'SNAPPY'} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0ea130ef/eagle-core/eagle-alert/eagle-alert-process/src/test/java/META-INF/MANIFEST.MF ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/META-INF/MANIFEST.MF b/eagle-core/eagle-alert/eagle-alert-process/src/test/java/META-INF/MANIFEST.MF deleted file mode 100644 index edfb15f..0000000 --- a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/META-INF/MANIFEST.MF +++ /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. - */ -Manifest-Version: 1.0 -Class-Path: - http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0ea130ef/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/cep/TestSiddhiEvaluator.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/cep/TestSiddhiEvaluator.java b/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/cep/TestSiddhiEvaluator.java deleted file mode 100644 index 602e117..0000000 --- a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/cep/TestSiddhiEvaluator.java +++ /dev/null @@ -1,135 +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.cep; - -import com.typesafe.config.Config; -import com.typesafe.config.ConfigFactory; -import junit.framework.Assert; -import org.apache.eagle.alert.entity.AbstractPolicyDefinitionEntity; -import org.apache.eagle.alert.entity.AlertAPIEntity; -import org.apache.eagle.alert.entity.AlertDefinitionAPIEntity; -import org.apache.eagle.alert.entity.AlertStreamSchemaEntity; -import org.apache.eagle.alert.executor.AlertExecutor; -import org.apache.eagle.alert.siddhi.SiddhiAlertAPIEntityRender; -import org.apache.eagle.dataproc.core.ValuesArray; -import org.apache.eagle.datastream.Collector; -import org.apache.eagle.policy.PolicyEvaluationContext; -import org.apache.eagle.policy.common.Constants; -import org.apache.eagle.policy.dao.*; -import org.apache.eagle.policy.siddhi.SiddhiPolicyDefinition; -import org.apache.eagle.policy.siddhi.SiddhiPolicyEvaluator; -import org.apache.eagle.policy.siddhi.StreamMetadataManager; -import org.apache.eagle.service.client.EagleServiceConnector; -import org.junit.Test; -import scala.Tuple2; - -import java.util.*; - -public class TestSiddhiEvaluator { - - int alertCount = 0; - - public AlertStreamSchemaEntity createStreamMetaEntity(String attrName, String type) { - AlertStreamSchemaEntity entity = new AlertStreamSchemaEntity(); - Map<String, String> tags = new HashMap<String, String>(); - tags.put("application", "hdfsAuditLog"); - tags.put("streamName", "hdfsAuditLogEventStream"); - tags.put("attrName", attrName); - entity.setTags(tags); - entity.setAttrType(type); - return entity; - } - - @Test - public void test() throws Exception{ - Config config = ConfigFactory.load("unittest.conf"); - AlertStreamSchemaDAO streamDao = new AlertStreamSchemaDAOImpl(null, null) { - @Override - public List<AlertStreamSchemaEntity> findAlertStreamSchemaByApplication(String dataSource) throws Exception { - List<AlertStreamSchemaEntity> list = new ArrayList<AlertStreamSchemaEntity>(); - list.add(createStreamMetaEntity("cmd", "string")); - list.add(createStreamMetaEntity("dst", "string")); - list.add(createStreamMetaEntity("src", "string")); - list.add(createStreamMetaEntity("host", "string")); - list.add(createStreamMetaEntity("user", "string")); - list.add(createStreamMetaEntity("timestamp", "long")); - list.add(createStreamMetaEntity("securityZone", "string")); - list.add(createStreamMetaEntity("sensitivityType", "string")); - list.add(createStreamMetaEntity("allowed", "string")); - return list; - } - }; - StreamMetadataManager.getInstance().reset(); - StreamMetadataManager.getInstance().init(config, streamDao); - - Map<String, Object> data1 = new TreeMap<String, Object>(){{ - put("cmd", "open"); - put("dst", ""); - put("src", ""); - put("host", ""); - put("user", ""); - put("timestamp", String.valueOf(System.currentTimeMillis())); - put("securityZone", ""); - put("sensitivityType", ""); - put("allowed", "true"); - }}; - final SiddhiPolicyDefinition policyDef = new SiddhiPolicyDefinition(); - policyDef.setType("siddhiCEPEngine"); - String expression = "from hdfsAuditLogEventStream[cmd=='open'] " + - "select * " + - "insert into outputStream ;"; - policyDef.setExpression(expression); - - PolicyDefinitionDAO alertDao = new PolicyDefinitionEntityDAOImpl(new EagleServiceConnector(null, null), - Constants.ALERT_DEFINITION_SERVICE_ENDPOINT_NAME) { - @Override - public Map<String, Map<String, AlertDefinitionAPIEntity>> findActivePoliciesGroupbyExecutorId(String site, String dataSource) throws Exception { - return null; - } - - @Override - public void updatePolicyDetails(AbstractPolicyDefinitionEntity entity) { /* do nothing */ } - }; - - AlertExecutor alertExecutor = new AlertExecutor("alertExecutorId", null, 3, 1, alertDao, new String[]{"hdfsAuditLogEventStream"}) { - @Override - protected Map<String, String> getDimensions(String policyId) { - return new HashMap<String, String>(); - } - }; - alertExecutor.prepareConfig(config); - alertExecutor.init(); - - PolicyEvaluationContext<AlertDefinitionAPIEntity, AlertAPIEntity> context = new PolicyEvaluationContext<>(); - context.alertExecutor = alertExecutor; - context.policyId = "testPolicy"; - context.resultRender = new SiddhiAlertAPIEntityRender(); - context.outputCollector = new Collector<Tuple2<String, AlertAPIEntity>> () { - @Override - public void collect(Tuple2<String, AlertAPIEntity> stringAlertAPIEntityTuple2) { - alertCount++; - } - }; - - SiddhiPolicyEvaluator<AlertDefinitionAPIEntity, AlertAPIEntity> evaluator = - new SiddhiPolicyEvaluator<>(config, context, policyDef, new String[]{"hdfsAuditLogEventStream"}, false); - - evaluator.evaluate(new ValuesArray(context.outputCollector, "hdfsAuditLogEventStream", data1)); - Thread.sleep(2 * 1000); - Assert.assertEquals(alertCount, 1); - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0ea130ef/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/config/TestAlertDedup.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/config/TestAlertDedup.java b/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/config/TestAlertDedup.java deleted file mode 100644 index 4295bdc..0000000 --- a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/config/TestAlertDedup.java +++ /dev/null @@ -1,38 +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.config; - -import org.junit.Assert; -import org.junit.Test; - -import org.apache.eagle.dataproc.core.JsonSerDeserUtils; - -public class TestAlertDedup { - - @Test - public void test() throws Exception{ - String alertDef = "{\"alertDedupIntervalMin\":\"720\",\"emailDedupIntervalMin\":\"1440\"}"; - DeduplicatorConfig dedupConfig = JsonSerDeserUtils.deserialize(alertDef, DeduplicatorConfig.class); - Assert.assertEquals(dedupConfig.getAlertDedupIntervalMin(), 720); - Assert.assertEquals(dedupConfig.getEmailDedupIntervalMin(), 1440); - - alertDef = "null"; - dedupConfig = JsonSerDeserUtils.deserialize(alertDef, DeduplicatorConfig.class); - Assert.assertEquals(dedupConfig, null); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0ea130ef/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/dao/TestAlertDefinitionDAOImpl.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/dao/TestAlertDefinitionDAOImpl.java b/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/dao/TestAlertDefinitionDAOImpl.java deleted file mode 100644 index f7dcdde..0000000 --- a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/dao/TestAlertDefinitionDAOImpl.java +++ /dev/null @@ -1,81 +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.dao; - -import com.typesafe.config.Config; -import com.typesafe.config.ConfigFactory; -import org.apache.eagle.alert.entity.AbstractPolicyDefinitionEntity; -import org.apache.eagle.alert.entity.AlertDefinitionAPIEntity; -import org.apache.eagle.common.config.EagleConfigConstants; -import org.apache.eagle.policy.common.Constants; -import org.apache.eagle.policy.dao.PolicyDefinitionDAO; -import org.apache.eagle.policy.dao.PolicyDefinitionEntityDAOImpl; -import org.apache.eagle.service.client.EagleServiceConnector; -import org.junit.Assert; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class TestAlertDefinitionDAOImpl { - - public AlertDefinitionAPIEntity buildTestAlertDefEntity(String site, String programId, String alertExecutorId, String policyId, String policyType) { - AlertDefinitionAPIEntity entity = new AlertDefinitionAPIEntity(); - entity.setEnabled(true); - Map<String, String> tags = new HashMap<String, String>(); - tags.put("site", site); - tags.put("programId", programId); - tags.put("alertExecutorId", alertExecutorId); - tags.put("policyId", policyId); - tags.put("policyType", policyType); - entity.setTags(tags); - return entity; - } - - @Test - public void test() throws Exception{ - Config config = ConfigFactory.load(); - String eagleServiceHost = config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.HOST); - int eagleServicePort = config.getInt(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PORT); - - String site = "sandbox"; - String dataSource = "UnitTest"; - PolicyDefinitionDAO dao = new PolicyDefinitionEntityDAOImpl(new EagleServiceConnector(eagleServiceHost, eagleServicePort), - Constants.ALERT_DEFINITION_SERVICE_ENDPOINT_NAME) { - @Override - public List<AlertDefinitionAPIEntity> findActivePolicies(String site, String dataSource) throws Exception { - List<AlertDefinitionAPIEntity> list = new ArrayList<AlertDefinitionAPIEntity>(); - list.add(buildTestAlertDefEntity(site, dataSource, "TestExecutor1", "TestPolicyIDA", "TestPolicyTypeA")); - list.add(buildTestAlertDefEntity(site, dataSource, "TestExecutor1", "TestPolicyIDB", "TestPolicyTypeB")); - list.add(buildTestAlertDefEntity(site, dataSource, "TestExecutor2", "TestPolicyIDC", "TestPolicyTypeC")); - list.add(buildTestAlertDefEntity(site, dataSource, "TestExecutor2", "TestPolicyIDD", "TestPolicyTypeD")); - return list; - } - - @Override - public void updatePolicyDetails(AbstractPolicyDefinitionEntity entity) { /* do nothing */ } - }; - - Map<String, Map<String, AlertDefinitionAPIEntity>> retMap = dao.findActivePoliciesGroupbyExecutorId(site, dataSource); - - Assert.assertEquals(2, retMap.size()); - Assert.assertEquals(2, retMap.get("TestExecutor1").size()); - Assert.assertEquals(2, retMap.get("TestExecutor2").size()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0ea130ef/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/dao/TestSiddhiStreamMetadataUtils.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/dao/TestSiddhiStreamMetadataUtils.java b/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/dao/TestSiddhiStreamMetadataUtils.java deleted file mode 100644 index a2b8a2d..0000000 --- a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/dao/TestSiddhiStreamMetadataUtils.java +++ /dev/null @@ -1,60 +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.dao; - -import com.typesafe.config.Config; -import com.typesafe.config.ConfigFactory; -import junit.framework.Assert; -import org.apache.eagle.alert.entity.AlertStreamSchemaEntity; -import org.apache.eagle.policy.dao.AlertStreamSchemaDAO; -import org.apache.eagle.policy.siddhi.SiddhiStreamMetadataUtils; -import org.apache.eagle.policy.siddhi.StreamMetadataManager; -import org.junit.Test; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; - -public class TestSiddhiStreamMetadataUtils { - @Test - public void test() throws Exception { - Config config = ConfigFactory.load(); - StreamMetadataManager.getInstance().reset(); - StreamMetadataManager.getInstance().init(config, new AlertStreamSchemaDAO() { - @Override - public List<AlertStreamSchemaEntity> findAlertStreamSchemaByApplication( - String application) { - return Arrays.asList(generateStreamMetadataAPIEntity("attrName1", "STRING"), - generateStreamMetadataAPIEntity("attrName2", "LONG") - ); - } - }); - String siddhiStreamDef = SiddhiStreamMetadataUtils.convertToStreamDef("testStreamName"); - Assert.assertEquals("define stream " + "testStreamName" + "(attrName1 string,attrName2 long);", siddhiStreamDef); - } - - private AlertStreamSchemaEntity generateStreamMetadataAPIEntity(final String attrName, String attrType){ - AlertStreamSchemaEntity entity = new AlertStreamSchemaEntity(); - entity.setTags(new HashMap<String, String>(){{ - put("programId", "testProgramId"); - put("streamName", "testStreamName"); - put("attrName", attrName); - }}); - entity.setAttrType(attrType); - return entity; - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0ea130ef/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/dao/TestStreamDefinitionDAOImpl.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/dao/TestStreamDefinitionDAOImpl.java b/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/dao/TestStreamDefinitionDAOImpl.java deleted file mode 100644 index 0bbfc4a..0000000 --- a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/dao/TestStreamDefinitionDAOImpl.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 org.apache.eagle.alert.dao; - -import com.typesafe.config.Config; -import com.typesafe.config.ConfigFactory; -import org.apache.eagle.policy.dao.AlertStreamSchemaDAO; -import org.apache.eagle.policy.dao.AlertStreamSchemaDAOImpl; -import org.apache.eagle.alert.entity.AlertStreamSchemaEntity; -import org.apache.eagle.policy.siddhi.StreamMetadataManager; -import org.junit.Assert; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class TestStreamDefinitionDAOImpl { - - public AlertStreamSchemaEntity buildTestStreamDefEntity(String programId, String streamName, String attrName) { - AlertStreamSchemaEntity entity = new AlertStreamSchemaEntity(); - entity.setAttrType("String"); - entity.setAttrValueResolver("DefaultAttrValueResolver"); - entity.setCategory("SimpleType"); - Map<String, String> tags = new HashMap<String, String>(); - tags.put("programId", programId); - tags.put("streamName", streamName); - tags.put("attrName", attrName); - entity.setTags(tags); - return entity; - } - - @Test - public void test() throws Exception{ - Config config = ConfigFactory.load(); - AlertStreamSchemaDAO dao = new AlertStreamSchemaDAOImpl(null, null) { - public List<AlertStreamSchemaEntity> findAlertStreamSchemaByApplication(String application) throws Exception { - List<AlertStreamSchemaEntity> list = new ArrayList<AlertStreamSchemaEntity>(); - String programId = "UnitTest"; - list.add(buildTestStreamDefEntity(programId, "TestStream", "Attr1")); - list.add(buildTestStreamDefEntity(programId, "TestStream", "Attr2")); - list.add(buildTestStreamDefEntity(programId, "TestStream", "Attr3")); - list.add(buildTestStreamDefEntity(programId, "TestStream", "Attr4")); - return list; - } - }; - StreamMetadataManager.getInstance().reset(); - StreamMetadataManager.getInstance().init(config, dao); - Map<String, List<AlertStreamSchemaEntity>> retMap = StreamMetadataManager.getInstance().getMetadataEntitiesForAllStreams(); - Assert.assertTrue(retMap.get("TestStream").size() == 4); - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0ea130ef/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/executor/TestPolicyExecutor.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/executor/TestPolicyExecutor.java b/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/executor/TestPolicyExecutor.java deleted file mode 100644 index 90353be..0000000 --- a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/executor/TestPolicyExecutor.java +++ /dev/null @@ -1,85 +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.executor; - -import org.apache.eagle.policy.common.Constants; -import org.apache.eagle.policy.config.AbstractPolicyDefinition; -import org.apache.eagle.policy.dao.AlertStreamSchemaDAOImpl; -import org.apache.eagle.alert.entity.AbstractPolicyDefinitionEntity; -import org.apache.eagle.alert.entity.AlertDefinitionAPIEntity; -import org.apache.eagle.policy.PolicyEvaluator; -import org.apache.eagle.policy.PolicyManager; -import org.apache.eagle.policy.siddhi.SiddhiPolicyDefinition; -import org.apache.eagle.policy.siddhi.StreamMetadataManager; -import org.apache.eagle.dataproc.core.JsonSerDeserUtils; -import org.junit.Ignore; -import org.junit.Test; - -import com.typesafe.config.Config; -import com.typesafe.config.ConfigFactory; - -import junit.framework.Assert; - -/** - * @since Dec 18, 2015 - * - */ -public class TestPolicyExecutor { - - public static class T2 extends AbstractPolicyDefinitionEntity { - @Override - public String getPolicyDef() { - return null; - } - @Override - public boolean isEnabled() { - return false; - } - } - - // not feasible to Unit test, it requires the local service. - @Ignore - @Test - public void testReflectCreatePolicyEvaluator() throws Exception { - System.setProperty("config.resource", "/unittest.conf"); - String policyType = Constants.policyType.siddhiCEPEngine.name(); - Class<? extends PolicyEvaluator> evalCls = PolicyManager.getInstance().getPolicyEvaluator(policyType); - Config config = ConfigFactory.load(); - - String def = "{\"expression\":\"from hdfsAuditLogEventStream select * insert into outputStream;\",\"type\":\"siddhiCEPEngine\"}"; - // test1 : test json deserialization - AbstractPolicyDefinition policyDef = null; - policyDef = JsonSerDeserUtils.deserialize(def, AbstractPolicyDefinition.class, - PolicyManager.getInstance().getPolicyModules(policyType)); - // Assert conversion succeed - Assert.assertEquals(SiddhiPolicyDefinition.class, policyDef.getClass()); - - // make sure meta data manager initialized - StreamMetadataManager.getInstance().init(config, new AlertStreamSchemaDAOImpl(config)); - - String[] sourceStreams = new String[] { "hdfsAuditLogEventStream" }; - // test2 : test evaluator - PolicyEvaluator pe = evalCls.getConstructor(Config.class, String.class, AbstractPolicyDefinition.class, - String[].class, boolean.class).newInstance(config, "policy-id", policyDef, sourceStreams, false); - - PolicyEvaluator<AlertDefinitionAPIEntity> e1 = (PolicyEvaluator<AlertDefinitionAPIEntity>) pe; - - PolicyEvaluator<T2> e2 = (PolicyEvaluator<T2>) pe; - - } - -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0ea130ef/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/policy/TestDynamicPolicyLoader.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/policy/TestDynamicPolicyLoader.java b/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/policy/TestDynamicPolicyLoader.java deleted file mode 100644 index 0504784..0000000 --- a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/policy/TestDynamicPolicyLoader.java +++ /dev/null @@ -1,114 +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.policy; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.eagle.alert.entity.AbstractPolicyDefinitionEntity; -import org.apache.eagle.policy.DynamicPolicyLoader; -import org.apache.eagle.policy.PolicyLifecycleMethods; -import org.apache.eagle.policy.dao.PolicyDefinitionDAO; -import org.apache.eagle.alert.entity.AlertDefinitionAPIEntity; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.typesafe.config.Config; -import com.typesafe.config.ConfigFactory; - -import junit.framework.Assert; - -public class TestDynamicPolicyLoader { - private final static Logger LOG = LoggerFactory.getLogger(TestDynamicPolicyLoader.class); - - @Test - public void test() throws Exception{ - System.setProperty("config.resource", "/unittest.conf"); - Config config = ConfigFactory.load(); - Map<String, PolicyLifecycleMethods<AlertDefinitionAPIEntity>> policyChangeListeners = new HashMap<String, PolicyLifecycleMethods<AlertDefinitionAPIEntity>>(); - policyChangeListeners.put("testAlertExecutorId", new PolicyLifecycleMethods<AlertDefinitionAPIEntity>() { - @Override - public void onPolicyDeleted(Map<String, AlertDefinitionAPIEntity> deleted) { - LOG.info("deleted : " + deleted); - } - - @Override - public void onPolicyCreated(Map<String, AlertDefinitionAPIEntity> added) { - Assert.assertTrue(added.size() == 1); - LOG.info("added : " + added); - } - - @Override - public void onPolicyChanged(Map<String, AlertDefinitionAPIEntity> changed) { - Assert.assertTrue(changed.size() == 1); - LOG.info("changed :" + changed); - } - }); - - Map<String, Map<String, AlertDefinitionAPIEntity>> initialAlertDefs = new HashMap<String, Map<String, AlertDefinitionAPIEntity>>(); - initialAlertDefs.put("testAlertExecutorId", new HashMap<String, AlertDefinitionAPIEntity>()); - Map<String, AlertDefinitionAPIEntity> map = initialAlertDefs.get("testAlertExecutorId"); - map.put("policyId_1", buildTestAlertDefEntity("testProgramId", "testAlertExecutorId", "policyId_1", "siddhi", "policyDef_1")); - map.put("policyId_3", buildTestAlertDefEntity("testProgramId", "testAlertExecutorId", "policyId_3", "siddhi", "policyDef_3")); - - PolicyDefinitionDAO<AlertDefinitionAPIEntity> dao = new PolicyDefinitionDAO<AlertDefinitionAPIEntity>() { - @Override - public Map<String, Map<String, AlertDefinitionAPIEntity>> findActivePoliciesGroupbyExecutorId( - String site, String dataSource) { - Map<String, Map<String, AlertDefinitionAPIEntity>> currentAlertDefs = new HashMap<String, Map<String, AlertDefinitionAPIEntity>>(); - currentAlertDefs.put("testAlertExecutorId", new HashMap<String, AlertDefinitionAPIEntity>()); - Map<String, AlertDefinitionAPIEntity> map = currentAlertDefs.get("testAlertExecutorId"); - map.put("policyId_1", buildTestAlertDefEntity("testProgramId", "testAlertExecutorId", "policyId_1", "siddhi", "policyDef_1_1")); - map.put("policyId_2", buildTestAlertDefEntity("testProgramId", "testAlertExecutorId", "policyId_2", "siddhi", "policyDef_2")); - return currentAlertDefs; - } - - @Override - public List<AlertDefinitionAPIEntity> findActivePolicies(String site, String dataSource) { - return null; - } - - @Override - public void updatePolicyDetails(AlertDefinitionAPIEntity entity) { /* do nothing */ } - }; - - DynamicPolicyLoader<AlertDefinitionAPIEntity> loader = DynamicPolicyLoader.getInstanceOf(AlertDefinitionAPIEntity.class); - loader.init(initialAlertDefs, dao, config); - - try{ - Thread.sleep(5000); - }catch(Exception ex){ - - } - } - - public AlertDefinitionAPIEntity buildTestAlertDefEntity(String programId, String alertExecutorId, String policyId, String policyType, String policyDef) { - AlertDefinitionAPIEntity entity = new AlertDefinitionAPIEntity(); - entity.setEnabled(true); - Map<String, String> tags = new HashMap<String, String>(); - tags.put("programId", programId); - tags.put("alertExecutorId", alertExecutorId); - tags.put("policyId", policyId); - tags.put("policyType", policyType); - entity.setTags(tags); - entity.setPolicyDef(policyDef); - return entity; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0ea130ef/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/policy/TestPolicyDistribution.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/policy/TestPolicyDistribution.java b/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/policy/TestPolicyDistribution.java deleted file mode 100644 index 77aaec3..0000000 --- a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/policy/TestPolicyDistribution.java +++ /dev/null @@ -1,30 +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.policy; - -import org.apache.eagle.policy.DefaultPolicyPartitioner; -import org.junit.Test; - -public class TestPolicyDistribution { - @Test - public void test(){ - DefaultPolicyPartitioner p = new DefaultPolicyPartitioner(); - System.out.println(p.partition(2, "siddhiCEPEngine", "readtmpPII")); - System.out.println(p.partition(2, "siddhiCEPEngine", "readtmpPII2")); - System.out.println(p.partition(2, "siddhiCEPEngine", "tmpPIIpii")); - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0ea130ef/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/policy/TestPolicyDistributionUpdater.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/policy/TestPolicyDistributionUpdater.java b/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/policy/TestPolicyDistributionUpdater.java deleted file mode 100644 index 1fb97fd..0000000 --- a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/policy/TestPolicyDistributionUpdater.java +++ /dev/null @@ -1,99 +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.policy; - -import com.typesafe.config.Config; -import com.typesafe.config.ConfigFactory; -import junit.framework.Assert; -import org.apache.eagle.alert.entity.AbstractPolicyDefinitionEntity; -import org.apache.eagle.alert.entity.AlertDefinitionAPIEntity; -import org.apache.eagle.alert.entity.AlertStreamSchemaEntity; -import org.apache.eagle.alert.executor.AlertExecutor; -import org.apache.eagle.policy.DefaultPolicyPartitioner; -import org.apache.eagle.policy.common.Constants; -import org.apache.eagle.policy.dao.AlertStreamSchemaDAO; -import org.apache.eagle.policy.dao.PolicyDefinitionDAO; -import org.apache.eagle.policy.dao.PolicyDefinitionEntityDAOImpl; -import org.apache.eagle.service.client.EagleServiceConnector; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class TestPolicyDistributionUpdater { - private static Logger LOG = LoggerFactory.getLogger(TestPolicyDistributionUpdater.class); - - @Test - public void testPolicyDistributionReporter() throws Exception{ - PolicyDefinitionDAO alertDao = new PolicyDefinitionEntityDAOImpl(new EagleServiceConnector(null, 1), - Constants.ALERT_DEFINITION_SERVICE_ENDPOINT_NAME) { - @Override - public Map<String, Map<String, AlertDefinitionAPIEntity>> findActivePoliciesGroupbyExecutorId(String site, String dataSource) throws Exception { - final AlertDefinitionAPIEntity entity = new AlertDefinitionAPIEntity(); - entity.setTags(new HashMap<String, String>() {{ - put(Constants.POLICY_TYPE, "siddhiCEPEngine"); - put(Constants.POLICY_ID, "policyId_1"); - }}); - Map<String, Map<String, AlertDefinitionAPIEntity>> map = new HashMap<String, Map<String, AlertDefinitionAPIEntity>>(); - map.put("alertExecutorId_1", new HashMap<String, AlertDefinitionAPIEntity>() {{ - put("policyId_1", entity); - }}); - entity.setPolicyDef("{\"type\":\"siddhiCEPEngine\",\"expression\":\"from testStream select name insert into outputStream ;\"}"); - return map; - } - - @Override - public void updatePolicyDetails(AbstractPolicyDefinitionEntity entity) { /* do nothing */ } - }; - - AlertExecutor alertExecutor = new AlertExecutor("alertExecutorId_1", new DefaultPolicyPartitioner(), 1, 0, alertDao, new String[]{"testStream"}){ - public AlertStreamSchemaDAO getAlertStreamSchemaDAO(Config config){ - return new AlertStreamSchemaDAO(){ - @Override - public List<AlertStreamSchemaEntity> findAlertStreamSchemaByApplication(String application) throws Exception { - AlertStreamSchemaEntity entity = new AlertStreamSchemaEntity(); - entity.setTags(new HashMap<String, String>(){{ - put("application", "UnitTest"); - put("streamName", "testStream"); - put("attrName", "name"); - }}); - entity.setAttrType("string"); - return Arrays.asList(entity); - } - }; - } - - @Override - public void report() { - Assert.assertEquals(1, getPolicyEvaluators().size()); - LOG.info("successuflly reported"); - } - }; - - Config config = ConfigFactory.load(); - alertExecutor.prepareConfig(config); - alertExecutor.init(); - Thread.sleep(100); - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0ea130ef/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/policy/TestPolicyPartitioner.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/policy/TestPolicyPartitioner.java b/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/policy/TestPolicyPartitioner.java deleted file mode 100644 index c3bc4c9..0000000 --- a/eagle-core/eagle-alert/eagle-alert-process/src/test/java/org/apache/eagle/alert/policy/TestPolicyPartitioner.java +++ /dev/null @@ -1,30 +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.policy; - -import org.apache.eagle.policy.DefaultPolicyPartitioner; -import org.junit.Test; - -public class TestPolicyPartitioner { - @Test - public void test(){ - DefaultPolicyPartitioner p = new DefaultPolicyPartitioner(); - System.out.println(p.partition(2, "siddhiCEPEngine", "readtmpPII")); - System.out.println(p.partition(2, "siddhiCEPEngine", "readtmpPII2")); - System.out.println(p.partition(2, "siddhiCEPEngine", "tmpPIIpii")); - } -}