EAGLE-341 clean inner process alert engine code clean inner process alert engine code
Author: @yonzhang2012 <[email protected]> Closes: #341 Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/0f11a591 Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/0f11a591 Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/0f11a591 Branch: refs/heads/develop Commit: 0f11a591a1521bfd50b6646aa5f27ada4c68c402 Parents: 0f7ddab Author: yonzhang <[email protected]> Authored: Sat Aug 13 23:26:46 2016 -0700 Committer: yonzhang <[email protected]> Committed: Sat Aug 13 23:26:46 2016 -0700 ---------------------------------------------------------------------- .../eagle-alert-parent/eagle-alert-base/pom.xml | 51 --- .../eagle/alert/common/AlertEmailSender.java | 160 ------- .../eagle/alert/email/AlertEmailComponent.java | 33 -- .../eagle/alert/email/AlertEmailContext.java | 70 --- .../eagle-alert-notification-plugin/pom.xml | 84 ---- .../base/NotificationConstants.java | 35 -- .../notification/base/NotificationStatus.java | 26 -- .../notification/dao/AlertNotificationDAO.java | 36 -- .../dao/AlertNotificationDAOImpl.java | 70 --- .../notification/email/AlertEmailComponent.java | 32 -- .../notification/email/AlertEmailContext.java | 69 --- .../notification/email/AlertEmailGenerator.java | 138 ------ .../email/AlertEmailGeneratorBuilder.java | 59 --- .../notification/email/AlertEmailSender.java | 191 -------- .../plugin/AlertEagleStorePersister.java | 85 ---- .../plugin/AlertEagleStorePlugin.java | 101 ----- .../notification/plugin/AlertEmailPlugin.java | 149 ------- .../notification/plugin/AlertKafkaPlugin.java | 140 ------ .../plugin/KafkaProducerSingleton.java | 47 -- .../notification/plugin/NotificationPlugin.java | 59 --- .../plugin/NotificationPluginLoader.java | 92 ---- .../plugin/NotificationPluginManager.java | 39 -- .../plugin/NotificationPluginManagerImpl.java | 151 ------- .../utils/NotificationPluginUtils.java | 67 --- .../src/main/resources/ALERT_DEFAULT.vm | 266 ----------- .../src/main/resources/application.conf | 69 --- .../main/resources/notification-plugins-init.sh | 66 --- .../testcases/TestAlertEagleStorePlugin.java | 50 --- .../testcases/TestAlertEmailPlugin.java | 56 --- .../testcases/TestAlertKafkaPlugin.java | 57 --- .../testcases/TestGetAllNotifications.java | 41 -- .../testcases/TestNotificationPluginLoader.java | 41 -- .../TestNotificationPluginManager.java | 93 ---- .../testcases/TestNotificationPluginUtils.java | 38 -- .../src/test/resources/application.conf | 69 --- .../src/test/resources/log4j.properties | 35 -- .../eagle-alert-process/pom.xml | 137 ------ .../eagle/alert/config/DeduplicatorConfig.java | 42 -- .../alert/config/EmailNotificationConfig.java | 50 --- .../eagle/alert/config/NotificationConfig.java | 45 -- .../apache/eagle/alert/config/Remediation.java | 32 -- .../dedup/AlertDeduplicationExecutorBase.java | 188 -------- .../dedup/AlertEmailDeduplicationExecutor.java | 30 -- .../dedup/AlertEntityDeduplicationExecutor.java | 31 -- .../eagle/alert/dedup/DefaultDeduplicator.java | 130 ------ .../eagle/alert/dedup/EntityDedupKey.java | 62 --- .../eagle/alert/dedup/EntityDeduplicator.java | 35 -- .../eagle/alert/dedup/EntityTagsUniq.java | 81 ---- .../eagle/alert/executor/AlertExecutor.java | 41 -- .../executor/AlertExecutorCreationUtils.java | 111 ----- .../alert/notification/AlertEmailGenerator.java | 136 ------ .../notification/AlertNotificationExecutor.java | 128 ------ .../alert/persist/AlertPersistExecutor.java | 56 --- .../eagle/alert/persist/EaglePersist.java | 71 --- .../siddhi/SiddhiAlertAPIEntityRender.java | 109 ----- ....eagle.policy.PolicyEvaluatorServiceProvider | 16 - .../src/main/resources/table-create.script | 24 - .../src/test/java/META-INF/MANIFEST.MF | 19 - .../eagle/alert/cep/TestSiddhiEvaluator.java | 139 ------ .../eagle/alert/config/TestAlertDedup.java | 38 -- .../alert/dao/TestAlertDefinitionDAOImpl.java | 81 ---- .../dao/TestSiddhiStreamMetadataUtils.java | 60 --- .../alert/dao/TestStreamDefinitionDAOImpl.java | 67 --- .../alert/executor/TestPolicyExecutor.java | 85 ---- .../alert/policy/TestDynamicPolicyLoader.java | 113 ----- .../alert/policy/TestPolicyDistribution.java | 30 -- .../policy/TestPolicyDistributionUpdater.java | 101 ----- .../alert/policy/TestPolicyPartitioner.java | 30 -- .../alert/siddhi/TestExternalBatchWindow.java | 307 ------------- .../eagle/alert/siddhi/TestSiddhiEngine.java | 243 ---------- .../alert/siddhi/TestSiddhiSlideWindow.java | 129 ------ .../eagle/alert/siddhi/TestSiddhiStream.java | 34 -- .../eagle/alert/state/TestAggregation.java | 98 ---- .../alert/state/TestSiddhiExpiredEvents.java | 129 ------ .../src/test/resources/application.conf | 33 -- .../src/test/resources/log4j.properties | 34 -- .../src/test/resources/str.siddhiext | 39 -- .../src/test/resources/unittest.conf | 65 --- .../eagle-alert-service/pom.xml | 15 +- .../SiddhiAlertPolicyValidateProvider.java | 133 ------ .../service/alert/SiteApplicationObject.java | 62 --- .../service/alert/SiteApplicationResource.java | 189 -------- .../resolver/AttributeResolveResponse.java | 40 -- ...le.service.alert.AlertPolicyValidateProvider | 16 - ...le.service.alert.AlertPolicyValidateProvider | 16 - eagle-core/eagle-alert-parent/pom.xml | 3 - .../eagle-stream-application-manager/pom.xml | 142 ------ .../stream/application/TopologyException.java | 26 -- .../stream/application/TopologyExecutable.java | 27 -- .../stream/application/TopologyFactory.java | 55 --- .../AbstractDynamicApplication.scala | 4 +- .../stream/application/ApplicationManager.scala | 126 ------ .../application/ApplicationManagerUtils.scala | 38 -- .../ApplicationSchedulerAsyncDAO.scala | 179 -------- .../stream/application/ExecutionPlatform.scala | 30 -- .../application/ExecutionPlatformFactory.scala | 49 -- .../eagle/stream/application/TaskExecutor.scala | 41 -- .../application/impl/StormDynamicTopology.scala | 44 -- .../impl/StormExecutionPlatform.scala | 197 --------- .../scheduler/AppCommandExecutor.scala | 170 ------- .../scheduler/AppCommandLoader.scala | 78 ---- .../scheduler/ApplicationScheduler.scala | 81 ---- .../scheduler/StreamAppCoordinator.scala | 54 --- .../src/test/resources/application.conf | 42 -- .../src/test/resources/log4j.properties | 35 -- .../application/scheduler/MockTopology.scala | 30 -- .../scheduler/StormApplicationManagerSpec.scala | 40 -- .../application/scheduler/TestScheduler.scala | 61 --- eagle-core/eagle-app/pom.xml | 1 - .../eagle-stream-pipeline/README.md | 80 ---- .../eagle-stream-pipeline/pom.xml | 156 ------- .../apache/eagle/stream/pipeline/Pipeline.scala | 27 -- .../stream/pipeline/annotation/Extension.scala | 21 - .../pipeline/compiler/PipelineCompiler.scala | 61 --- .../pipeline/extension/ModuleManager.scala | 186 -------- .../eagle/stream/pipeline/parser/DataFlow.scala | 235 ---------- .../eagle/stream/pipeline/parser/Pipeline.scala | 95 ---- .../eagle/stream/pipeline/parser/Schema.scala | 152 ------- .../stream/pipeline/runner/PipelineRunner.scala | 115 ----- .../stream/pipeline/utils/Exceptions.scala | 20 - .../src/test/resources/application.conf | 34 -- .../src/test/resources/eagle-pipeline.sh | 20 - .../src/test/resources/log4j.properties | 19 - .../src/test/resources/pipeline_1.conf | 131 ------ .../src/test/resources/pipeline_2.conf | 93 ---- .../src/test/resources/pipeline_3.conf | 152 ------- .../src/test/resources/pipeline_4.conf | 125 ------ .../src/test/resources/pipeline_5.conf | 110 ----- .../eagle/stream/pipeline/ConfigSpec.scala | 37 -- .../eagle/stream/pipeline/DataFlowSpec.scala | 113 ----- .../eagle/stream/pipeline/PipelineSpec.scala | 61 --- .../eagle-stream-process-api/pom.xml | 5 - .../impl/aggregate/AggregateExecutor.java | 46 -- .../aggregate/AggregateExecutorFactory.java | 117 ----- .../impl/aggregate/AggregateResultRender.java | 45 -- .../impl/aggregate/SimpleAggregateExecutor.java | 189 -------- .../entity/AggregateDefinitionAPIEntity.java | 121 ----- .../impl/aggregate/entity/AggregateEntity.java | 43 -- .../entity/AggregateEntityRepository.java | 28 -- .../dataproc/impl/persist/IPersistService.java | 28 -- .../dataproc/impl/persist/PersistExecutor.java | 84 ---- .../druid/AggregateEntitySerializer.java | 66 --- .../impl/persist/druid/KafkaPersistService.java | 122 ----- .../hdfs/HDFSSourcedStormSpoutProvider.java | 3 - .../hdfs/UserProfileGenerationHDFSSpout.java | 299 ------------- .../datastream/JavaMapperStormExecutor.java | 83 ---- .../JavaStormExecutorForAlertWrapper.java | 62 --- .../src/main/resources/log4j.properties | 23 +- .../datastream/ExecutionEnvironments.scala | 31 -- .../core/AbstractTopologyCompiler.scala | 21 - .../core/AbstractTopologyExecutor.scala | 21 - .../eagle/datastream/core/Configuration.scala | 74 ---- .../datastream/core/ExecutionEnvironment.scala | 2 +- .../core/StreamAggregateExpansion.scala | 80 ---- .../datastream/core/StreamAlertExpansion.scala | 257 ----------- .../eagle/datastream/core/StreamBuilder.scala | 32 +- .../eagle/datastream/core/StreamConnector.scala | 97 ---- .../eagle/datastream/core/StreamDAG.scala | 70 --- .../datastream/core/StreamDAGExpansion.scala | 27 -- .../datastream/core/StreamDAGTransformer.scala | 46 -- .../core/StreamGroupbyExpansion.scala | 77 ---- .../datastream/core/StreamNameExpansion.scala | 49 -- .../core/StreamParallelismConfigExpansion.scala | 65 --- .../eagle/datastream/core/StreamProducer.scala | 10 - .../datastream/core/StreamProducerGraph.scala | 29 -- .../eagle/datastream/core/StreamProtocol.scala | 193 -------- .../datastream/core/StreamSourceBuilder.scala | 63 --- .../datastream/core/StreamUnionExpansion.scala | 71 --- .../datastream/storm/AbstractStreamBolt.scala | 119 ----- .../datastream/storm/FilterBoltWrapper.scala | 41 -- .../datastream/storm/ForeachBoltWrapper.scala | 44 -- .../datastream/storm/IterableStreamSpout.scala | 71 --- .../datastream/storm/IteratorStreamSpout.scala | 65 --- .../datastream/storm/JavaStormBoltWrapper.scala | 51 --- .../storm/JsonMessageDeserializer.scala | 49 -- .../datastream/storm/KafkaStreamMonitor.scala | 31 -- .../eagle/datastream/storm/MapBoltWrapper.scala | 66 --- .../eagle/datastream/storm/SpoutProxy.scala | 111 ----- .../datastream/storm/StormBoltFactory.scala | 5 +- .../datastream/storm/StormBoltWrapper.scala | 61 --- .../storm/StormExecutionEnvironment.scala | 39 -- .../storm/StormExecutorForAlertWrapper.scala | 44 -- .../storm/StormFlatFunctionWrapper.scala | 45 -- .../storm/StormFlatMapperWrapper.scala | 44 -- .../datastream/storm/StormSpoutFactory.scala | 69 --- .../storm/StormTopologyCompiler.scala | 118 ----- .../storm/StormTopologyExecutorImpl.scala | 107 ----- .../datastream/storm/StormWrapperUtils.scala | 28 -- .../utils/AlertExecutorConsumerUtils.scala | 74 ---- .../eagle/datastream/utils/GraphPrinter.scala | 59 --- .../datastream/utils/NodeNameSelector.scala | 28 -- .../eagle/datastream/utils/UnionUtils.scala | 43 -- .../dataproc/util/TestConfigOptionParser.java | 105 ----- .../eagle/datastream/JavaEchoExecutor.java | 45 -- .../TestExecutionEnvironmentJava.java | 41 -- .../apache/eagle/datastream/TestJavaMain.java | 57 --- .../datastream/TestJavaReflectionUtils.java | 36 -- .../datastream/TestKafkaStreamMonitor.java | 28 -- .../datastream/TestSimpleAggregateExecutor.java | 73 --- .../eagle/datastream/TestStreamAggregate.java | 152 ------- .../src/test/resources/application.conf | 79 ---- .../src/test/resources/event-metadata-init.sh | 41 -- .../src/test/resources/log4j.properties | 35 -- .../datastream/StormWrapperUtilsSpec.scala | 40 -- .../eagle/datastream/TestDAGExpansion.scala | 104 ----- .../datastream/TestExecutionEnvironment.scala | 34 -- .../org/apache/eagle/datastream/TestScala.scala | 20 - .../eagle/datastream/TestStormNodes.scala | 160 ------- .../eagle/datastream/TestStormRunner.scala | 120 ----- .../eagle/datastream/TestStreamDAGBuilder.scala | 236 ---------- .../eagle/datastream/TestTypeSafedDSL.scala | 115 ----- .../core/StreamingProcessConstants.java | 23 - .../org/apache/eagle/datastream/JavaMapper.java | 26 -- .../eagle/datastream/JavaTypeCompatible.java | 24 - .../apache/eagle/datastream/FlatMapper.scala | 25 -- .../eagle/datastream/StormStreamExecutor.scala | 69 --- eagle-core/eagle-data-process/pom.xml | 1 - .../eagle/alert/entity/AlertAPIEntity.java | 112 ----- .../alert/entity/AlertContextSerDeser.java | 98 ---- .../alert/entity/AlertDataSourceEntity.java | 68 --- .../alert/entity/AlertDefinitionAPIEntity.java | 195 -------- .../alert/entity/AlertEntityRepository.java | 38 -- .../eagle/alert/entity/AlertExecutorEntity.java | 48 -- .../alert/entity/AlertNotificationEntity.java | 81 ---- .../eagle/alert/entity/AlertStreamEntity.java | 51 --- .../entity/ApplicationDescServiceEntity.java | 94 ---- .../alert/entity/FeatureDescServiceEntity.java | 59 --- .../alert/entity/GenericResourceEntity.java | 47 -- .../entity/SiteApplicationServiceEntity.java | 60 --- .../alert/entity/SiteDescServiceEntity.java | 48 -- .../eagle/policy/DynamicPolicyLoader.java | 268 ----------- .../org/apache/eagle/policy/PartitionUtils.java | 31 -- .../policy/PolicyDistStatsDAOLogReporter.java | 47 -- .../policy/PolicyDistributionReportMethods.java | 27 -- .../eagle/policy/PolicyDistributionStats.java | 74 ---- .../policy/PolicyDistributionStatsDAO.java | 26 -- .../policy/PolicyDistroStatsLogReporter.java | 50 --- .../policy/PolicyEvaluatorServiceProvider.java | 49 -- .../eagle/policy/PolicyLifecycleMethods.java | 27 -- .../org/apache/eagle/policy/PolicyManager.java | 61 --- .../apache/eagle/policy/common/UrlBuilder.java | 63 --- .../policy/config/AbstractPolicyDefinition.java | 42 -- .../eagle/policy/dao/AlertExecutorDAO.java | 26 -- .../eagle/policy/dao/AlertExecutorDAOImpl.java | 88 ---- .../apache/eagle/policy/dao/AlertStreamDAO.java | 25 -- .../eagle/policy/dao/AlertStreamDAOImpl.java | 60 --- .../eagle/policy/dao/AlertStreamSchemaDAO.java | 25 -- .../policy/dao/AlertStreamSchemaDAOImpl.java | 84 ---- .../eagle/policy/dao/PolicyDefinitionDAO.java | 47 -- .../dao/PolicyDefinitionEntityDAOImpl.java | 118 ----- .../policy/executor/PolicyProcessExecutor.java | 442 ------------------- .../siddhi/SiddhiOutputStreamCallback.java | 68 --- .../policy/siddhi/SiddhiPolicyDefinition.java | 56 --- .../policy/siddhi/SiddhiPolicyEvaluator.java | 356 --------------- ...iddhiPolicyEvaluatorServiceProviderImpl.java | 46 -- .../policy/siddhi/SiddhiQueryCallbackImpl.java | 95 ---- .../siddhi/SiddhiStreamMetadataUtils.java | 119 ----- .../policy/siddhi/StreamMetadataManager.java | 128 ------ ....eagle.policy.PolicyEvaluatorServiceProvider | 16 - .../apache/eagle/policy/dao/TestSchemaDao.java | 37 -- eagle-examples/eagle-topology-example/pom.xml | 68 --- .../eagle-topology-example-assembly.xml | 63 --- .../NotificationPluginTestMain.java | 81 ---- .../eagle/example/persist/MetricSerializer.java | 31 -- .../example/persist/PersistTopoTestMain.java | 115 ----- .../example/persist/PersistTopoTestMain2.java | 60 --- .../add-notification-for-plugin-test.sh | 50 --- .../main/resources/application-plugintest.conf | 59 --- .../src/main/resources/application.conf | 86 ---- .../resources/create-policy-for-plugin-test.sh | 99 ----- .../resources/delete-email-for-plugin-test.sh | 50 --- .../src/main/resources/log4j.properties | 23 +- .../main/resources/persist-test-topo-init.sh | 194 -------- .../src/main/resources/persit-test-storm.yaml | 18 - eagle-examples/pom.xml | 1 - eagle-gc/pom.xml | 5 - .../eagle/gc/executor/GCLogAnalyzerBolt.java | 5 - eagle-hadoop-metric/pom.xml | 5 - .../hadoop/metric/HadoopJmxMetricMonitor.java | 34 -- eagle-security/eagle-metric-collection/pom.xml | 5 - .../kafka/KafkaMessageDistributionBolt.java | 4 - eagle-security/eagle-security-common/pom.xml | 16 +- .../resolver/MetadataAccessConfigRepo.java | 24 +- .../eagle-security-hbase-auditlog/pom.xml | 5 - .../eagle-security-hdfs-auditlog/pom.xml | 10 +- .../auditlog/FileSensitivityDataJoinBolt.java | 3 - .../auditlog/HdfsUserCommandReassembler.java | 53 ++- .../security/auditlog/IPZoneDataJoinBolt.java | 4 - .../auditlog/TestUserCommandReassembler.java | 96 +++- eagle-security/eagle-security-hive/pom.xml | 5 - .../HiveResourceSensitivityDataJoinBolt.java | 4 - .../eagle-security-maprfs-auditlog/pom.xml | 5 - .../src/main/resources/log4j.properties | 23 +- eagle-server-assembly/pom.xml | 2 +- eagle-webservice/pom.xml | 17 - 295 files changed, 155 insertions(+), 20909 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0f11a591/eagle-core/eagle-alert-parent/eagle-alert-base/pom.xml ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert-base/pom.xml b/eagle-core/eagle-alert-parent/eagle-alert-base/pom.xml deleted file mode 100644 index bc71323..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert-base/pom.xml +++ /dev/null @@ -1,51 +0,0 @@ -<?xml version="1.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. - --> - -<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-parent</artifactId> - <version>0.5.0-incubating-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - - <artifactId>eagle-alert-base</artifactId> - <packaging>jar</packaging> - <name>eagle-alert-base</name> - - <dependencies> - <dependency> - <groupId>org.apache.eagle</groupId> - <artifactId>eagle-entity-base</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.eagle</groupId> - <artifactId>eagle-client-base</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.eagle</groupId> - <artifactId>eagle-policy-base</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> -</project> - http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0f11a591/eagle-core/eagle-alert-parent/eagle-alert-base/src/main/java/org/apache/eagle/alert/common/AlertEmailSender.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert-base/src/main/java/org/apache/eagle/alert/common/AlertEmailSender.java b/eagle-core/eagle-alert-parent/eagle-alert-base/src/main/java/org/apache/eagle/alert/common/AlertEmailSender.java deleted file mode 100644 index 9761031..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert-base/src/main/java/org/apache/eagle/alert/common/AlertEmailSender.java +++ /dev/null @@ -1,160 +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.common; - -import java.lang.management.ManagementFactory; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.apache.eagle.alert.email.AlertEmailContext; -import org.apache.eagle.policy.common.Constants; -import org.apache.velocity.VelocityContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.apache.eagle.alert.email.AlertEmailComponent; -import org.apache.eagle.common.DateTimeUtil; -import org.apache.eagle.common.email.EagleMailClient; -import com.netflix.config.ConcurrentMapConfiguration; -import com.typesafe.config.ConfigObject; - -@Deprecated -public class AlertEmailSender implements Runnable { - - protected final List<Map<String, String>> alertContexts = new ArrayList<Map<String, String>>(); - protected final String configFileName; - protected final String subject; - protected final String sender; - protected final String recipents; - protected final String cc; - protected final String origin; - protected boolean sentSuccessfully = false; - - private final static Logger LOG = LoggerFactory.getLogger(AlertEmailSender.class); - private final static int MAX_RETRY_COUNT = 3; - - private static final String MAIL_HOST = "mail.host"; - private static final String MAIL_PORT = "mail.smtp.port"; - private static final String MAIL_DEBUG = "mail.debug"; - - private static final String CONF_KEY_MAIL_HOST = "mailHost"; - private static final String CONF_KEY_MAIL_PORT = "mailSmtpPort"; - private static final String CONF_KEY_MAIL_DEBUG = "mailDebug"; - - private ConfigObject eagleProps; - - - private String threadName; - /** - * Derived class may have some additional context properties to add - * @param context velocity context - * @param env environment - */ - protected void additionalContext(VelocityContext context, String env) { - // By default there's no additional context added - } - - public AlertEmailSender(AlertEmailContext alertEmail){ - this.recipents = alertEmail.getRecipients(); - this.configFileName = alertEmail.getVelocityTplFile(); - this.subject = alertEmail.getSubject(); - this.sender = alertEmail.getSender(); - this.cc = alertEmail.getCc(); - for(AlertEmailComponent bean : alertEmail.getComponents()){ - this.alertContexts.add(bean.getAlertContext().getProperties()); - } - String tmp = ManagementFactory.getRuntimeMXBean().getName(); - this.origin = tmp.split("@")[1] + "(pid:" + tmp.split("@")[0] + ")"; - threadName = Thread.currentThread().getName(); - LOG.info("Initialized "+threadName+": origin is : " + this.origin+", recipient of the email: " + this.recipents+", velocity TPL file: " + this.configFileName); - } - - public AlertEmailSender(AlertEmailContext alertEmail, ConfigObject eagleProps){ - this(alertEmail); - this.eagleProps = eagleProps; - } - - @Override - public void run() { - int count = 0; - boolean success = false; - while(count++ < MAX_RETRY_COUNT && !success){ - LOG.info("Sending email, tried: " + count+", max: "+MAX_RETRY_COUNT); - try { - final EagleMailClient client; - if (eagleProps != null) { - ConcurrentMapConfiguration con = new ConcurrentMapConfiguration(); - con.addProperty(MAIL_HOST, eagleProps.get(CONF_KEY_MAIL_HOST).unwrapped()); - con.addProperty(MAIL_PORT, eagleProps.get(CONF_KEY_MAIL_PORT).unwrapped()); - if (eagleProps.get(CONF_KEY_MAIL_DEBUG) != null) { - con.addProperty(MAIL_DEBUG, eagleProps.get(CONF_KEY_MAIL_DEBUG).unwrapped()); - } - client = new EagleMailClient(con); - } - else { - client = new EagleMailClient(); - } - String env = "prod"; - if (eagleProps != null && eagleProps.get("env") != null) { - env = (String) eagleProps.get("env").unwrapped(); - } - LOG.info("Env is: " + env); - final VelocityContext context = new VelocityContext(); - generateCommonContext(context); - LOG.info("After calling generateCommonContext..."); - additionalContext(context, env); - - if (recipents == null || recipents.equals("")) { - LOG.error("Recipients is null, skip sending emails "); - return; - } - String title = subject; - if (!env.trim().equals("prod")) { - title = "[" + env + "]" + title; - } - success = client.send(sender, recipents, cc, title, configFileName, context, null); - LOG.info("Success of sending email: " + success); - if(!success && count < MAX_RETRY_COUNT) { - LOG.info("Sleep for a while before retrying"); - Thread.sleep(10*1000); - } - } - catch (Exception e){ - LOG.warn("Sending mail exception", e); - } - } - - if(success){ - sentSuccessfully = true; - LOG.info(String.format("Successfully send email, thread: %s",threadName)); - }else{ - LOG.warn(String.format("Fail sending email after tries %s times, thread: %s",MAX_RETRY_COUNT,threadName)); - } - } - - private void generateCommonContext(VelocityContext context) { - context.put(Constants.ALERT_EMAIL_TIME_PROPERTY, DateTimeUtil.millisecondsToHumanDateWithSeconds( System.currentTimeMillis() )); - context.put(Constants.ALERT_EMAIL_COUNT_PROPERTY, alertContexts.size()); - context.put(Constants.ALERT_EMAIL_ALERTLIST_PROPERTY, alertContexts); - context.put(Constants.ALERT_EMAIL_ORIGIN_PROPERTY, origin); - } - - public boolean sentSuccessfully(){ - return this.sentSuccessfully; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0f11a591/eagle-core/eagle-alert-parent/eagle-alert-base/src/main/java/org/apache/eagle/alert/email/AlertEmailComponent.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert-base/src/main/java/org/apache/eagle/alert/email/AlertEmailComponent.java b/eagle-core/eagle-alert-parent/eagle-alert-base/src/main/java/org/apache/eagle/alert/email/AlertEmailComponent.java deleted file mode 100644 index da1078a..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert-base/src/main/java/org/apache/eagle/alert/email/AlertEmailComponent.java +++ /dev/null @@ -1,33 +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.email; - -import org.apache.eagle.common.metric.AlertContext; - -/** - * Alert email component is one part of an email, which could be an individual alert - */ -@Deprecated -public class AlertEmailComponent { - private AlertContext alertContext; - public AlertContext getAlertContext() { - return alertContext; - } - public void setAlertContext(AlertContext alertContext) { - this.alertContext = alertContext; - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0f11a591/eagle-core/eagle-alert-parent/eagle-alert-base/src/main/java/org/apache/eagle/alert/email/AlertEmailContext.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert-base/src/main/java/org/apache/eagle/alert/email/AlertEmailContext.java b/eagle-core/eagle-alert-parent/eagle-alert-base/src/main/java/org/apache/eagle/alert/email/AlertEmailContext.java deleted file mode 100644 index b2fd929..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert-base/src/main/java/org/apache/eagle/alert/email/AlertEmailContext.java +++ /dev/null @@ -1,70 +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.email; - -import java.util.List; - -/** - * alert email bean - * one email consists of a list of email component - */ -@Deprecated -public class AlertEmailContext { - private List<AlertEmailComponent> components; - private String sender; - private String subject; - private String recipients; - private String velocityTplFile; - private String cc; - - public List<AlertEmailComponent> getComponents() { - return components; - } - public void setComponents(List<AlertEmailComponent> components) { - this.components = components; - } - public String getVelocityTplFile() { - return velocityTplFile; - } - public void setVelocityTplFile(String velocityTplFile) { - this.velocityTplFile = velocityTplFile; - } - public String getRecipients() { - return recipients; - } - public void setRecipients(String recipients) { - this.recipients = recipients; - } - public String getSender() { - return sender; - } - public void setSender(String sender) { - this.sender = sender; - } - public String getSubject() { - return subject; - } - public void setSubject(String subject) { - this.subject = subject; - } - public String getCc() { - return cc; - } - public void setCc(String cc) { - this.cc = cc; - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0f11a591/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/pom.xml ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/pom.xml b/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/pom.xml deleted file mode 100644 index 0350e0e..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/pom.xml +++ /dev/null @@ -1,84 +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. - */ ---> -<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-parent</artifactId> - <version>0.5.0-incubating-SNAPSHOT</version> - </parent> - <artifactId>eagle-alert-notification-plugin</artifactId> - <name>eagle-alert-notification-plugin</name> - <description>Apache Eagle Notification Plugin to enable services to use custom or default notification </description> - <dependencies> - <dependency> - <groupId>org.apache.eagle</groupId> - <artifactId>eagle-policy-base</artifactId> - <version>${project.version}</version> - <exclusions> - <exclusion> - <groupId>org.slf4j</groupId> - <artifactId>log4j-over-slf4j</artifactId> - </exclusion> - <exclusion> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-simple</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.apache.kafka</groupId> - <artifactId>kafka-clients</artifactId> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-core</artifactId> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-annotations</artifactId> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-databind</artifactId> - </dependency> - <!--<dependency>--> - <!--<groupId>com.fasterxml.jackson.module</groupId>--> - <!--<artifactId>jackson-module-scala_${scala.version}</artifactId>--> - <!--</dependency>--> - <dependency> - <groupId>org.codehaus.jackson</groupId> - <artifactId>jackson-mapper-asl</artifactId> - </dependency> - <dependency> - <groupId>org.codehaus.jackson</groupId> - <artifactId>jackson-core-asl</artifactId> - </dependency> - <dependency> - <groupId>org.reflections</groupId> - <artifactId>reflections</artifactId> - <exclusions> - <exclusion> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-simple</artifactId> - </exclusion> - </exclusions> - </dependency> - </dependencies> -</project> http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0f11a591/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/base/NotificationConstants.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/base/NotificationConstants.java b/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/base/NotificationConstants.java deleted file mode 100644 index 1e49ac8..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/base/NotificationConstants.java +++ /dev/null @@ -1,35 +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.notification.base; - -public class NotificationConstants { - public static final String NOTIFICATION_TYPE = "notificationType"; - public static final String EMAIL_NOTIFICATION = "email"; - public static final String KAFKA_STORE = "kafka"; - public static final String EAGLE_STORE = "eagleStore"; - - // email specific constants - public static final String SUBJECT = "subject"; - public static final String SENDER = "sender"; - public static final String RECIPIENTS = "recipients"; - public static final String TPL_FILE_NAME = "tplFileName"; - - // kafka specific constants - public static final String TOPIC = "topic"; - public static final String BROKER_LIST = "kafka_broker"; -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0f11a591/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/base/NotificationStatus.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/base/NotificationStatus.java b/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/base/NotificationStatus.java deleted file mode 100644 index d57dbf9..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/base/NotificationStatus.java +++ /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. - */ - -package org.apache.eagle.notification.base; - -/** - * Object that holds the status of Notification Posted to Notification Plugin - */ -public class NotificationStatus { - public boolean successful; - public String errorMessage; -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0f11a591/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/dao/AlertNotificationDAO.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/dao/AlertNotificationDAO.java b/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/dao/AlertNotificationDAO.java deleted file mode 100644 index bf2e75e..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/dao/AlertNotificationDAO.java +++ /dev/null @@ -1,36 +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.notification.dao; - - - -import org.apache.eagle.alert.entity.AlertNotificationEntity; - -import java.util.List; - -/** - * Alert Notification Data Access Obj Interface - */ -public interface AlertNotificationDAO { - /** - * find the Alert Notification Types by querying alertNotifications Table - * @return - * @throws Exception - */ - List<AlertNotificationEntity> findAlertNotificationTypes() throws Exception; -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0f11a591/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/dao/AlertNotificationDAOImpl.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/dao/AlertNotificationDAOImpl.java b/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/dao/AlertNotificationDAOImpl.java deleted file mode 100644 index 7251da3..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/dao/AlertNotificationDAOImpl.java +++ /dev/null @@ -1,70 +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.notification.dao; - -import org.apache.commons.lang.time.DateUtils; -import org.apache.eagle.alert.entity.AlertNotificationEntity; -import org.apache.eagle.log.entity.GenericServiceAPIResponseEntity; -import org.apache.eagle.policy.common.Constants; -import org.apache.eagle.service.client.EagleServiceConnector; -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; - -/** - * Notification Service API implementation which Provides Read/Write API's of Hbase AlertNotifications Table - */ -public class AlertNotificationDAOImpl implements AlertNotificationDAO { - - private final Logger LOG = LoggerFactory.getLogger(AlertNotificationDAOImpl.class); - private final EagleServiceConnector connector; - - public AlertNotificationDAOImpl(EagleServiceConnector connector){ - this.connector = connector; - } - - /** - * Find the Alerts by NotificationType - * @return - * @throws Exception - */ - @Override - public List<AlertNotificationEntity> findAlertNotificationTypes() throws Exception { - try{ - IEagleServiceClient client = new EagleServiceClientImpl(connector); - String query = Constants.ALERT_NOTIFICATION_SERVICE_ENDPOINT_NAME+"[@enabled=\"true\"]{*}"; - GenericServiceAPIResponseEntity response = client.search(query).startTime(0) - .endTime(10 * DateUtils.MILLIS_PER_DAY) - .pageSize(Integer.MAX_VALUE) - .query(query) - .send(); - client.close(); - if (response.getException() != null) { - throw new Exception("Got an exception when query eagle service: " + response.getException()); - } - return response.getObj(); - } - catch (Exception ex) { - LOG.error("Got an exception when query alert notification service ", ex); - throw new IllegalStateException(ex); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0f11a591/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/email/AlertEmailComponent.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/email/AlertEmailComponent.java b/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/email/AlertEmailComponent.java deleted file mode 100644 index 3fe55bf..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/email/AlertEmailComponent.java +++ /dev/null @@ -1,32 +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.notification.email; - -import org.apache.eagle.common.metric.AlertContext; - -/** - * Alert email component is one part of an email, which could be an individual alert - */ -public class AlertEmailComponent { - private AlertContext alertContext; - public AlertContext getAlertContext() { - return alertContext; - } - public void setAlertContext(AlertContext alertContext) { - this.alertContext = alertContext; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0f11a591/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/email/AlertEmailContext.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/email/AlertEmailContext.java b/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/email/AlertEmailContext.java deleted file mode 100644 index f1642be..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/email/AlertEmailContext.java +++ /dev/null @@ -1,69 +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.notification.email; - -import java.util.List; - -/** - * alert email bean - * one email consists of a list of email component - */ -public class AlertEmailContext { - private List<AlertEmailComponent> components; - private String sender; - private String subject; - private String recipients; - private String velocityTplFile; - private String cc; - - public List<AlertEmailComponent> getComponents() { - return components; - } - public void setComponents(List<AlertEmailComponent> components) { - this.components = components; - } - public String getVelocityTplFile() { - return velocityTplFile; - } - public void setVelocityTplFile(String velocityTplFile) { - this.velocityTplFile = velocityTplFile; - } - public String getRecipients() { - return recipients; - } - public void setRecipients(String recipients) { - this.recipients = recipients; - } - public String getSender() { - return sender; - } - public void setSender(String sender) { - this.sender = sender; - } - public String getSubject() { - return subject; - } - public void setSubject(String subject) { - this.subject = subject; - } - public String getCc() { - return cc; - } - public void setCc(String cc) { - this.cc = cc; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0f11a591/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/email/AlertEmailGenerator.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/email/AlertEmailGenerator.java b/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/email/AlertEmailGenerator.java deleted file mode 100644 index fd6b794..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/email/AlertEmailGenerator.java +++ /dev/null @@ -1,138 +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.notification.email; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.*; - -import org.apache.eagle.common.metric.AlertContext; -import org.apache.eagle.policy.common.Constants; -import org.apache.eagle.alert.entity.AlertAPIEntity; -import com.typesafe.config.ConfigObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class AlertEmailGenerator{ - private String tplFile; - private String sender; - private String recipients; - private String subject; - private ConfigObject eagleProps; - - private ThreadPoolExecutor executorPool; - - private final static Logger LOG = LoggerFactory.getLogger(AlertEmailGenerator.class); - - private final static long MAX_TIMEOUT_MS =60000; - - public boolean sendAlertEmail(AlertAPIEntity entity) { - return sendAlertEmail(entity, recipients, null); - } - - public boolean sendAlertEmail(AlertAPIEntity entity, String recipients) { - return sendAlertEmail(entity, recipients, null); - } - - public boolean sendAlertEmail(AlertAPIEntity entity, String recipients, String cc) { - boolean sentSuccessfully = false; - AlertEmailContext email = new AlertEmailContext(); - - AlertEmailComponent component = new AlertEmailComponent(); - AlertContext context = AlertContext.fromJsonString(entity.getAlertContext()); - component.setAlertContext(context); - List<AlertEmailComponent> components = new ArrayList<AlertEmailComponent>(); - components.add(component); - email.setComponents(components); - if (context.getProperty(Constants.SUBJECT) != null) { - email.setSubject(context.getProperty(Constants.SUBJECT)); - } - else email.setSubject(subject); - email.setVelocityTplFile(tplFile); - email.setRecipients(recipients); - email.setCc(cc); - email.setSender(sender); - - /** asynchronized email sending */ - @SuppressWarnings("rawtypes") - AlertEmailSender thread = new AlertEmailSender(email, eagleProps); - - if(this.executorPool == null) throw new IllegalStateException("Invoking thread executor pool but it's is not set yet"); - - LOG.info("Sending email in asynchronous to: "+recipients+", cc: "+cc); - Future future = this.executorPool.submit(thread); - try { - future.get(MAX_TIMEOUT_MS, TimeUnit.MILLISECONDS); - sentSuccessfully = true; - LOG.info(String.format("Successfully send email to %s", recipients)); - } catch (InterruptedException | ExecutionException e) { - sentSuccessfully = false; - LOG.error(String.format("Failed to send email to %s, due to:%s",recipients,e),e); - } catch (TimeoutException e) { - sentSuccessfully = false; - LOG.error(String.format("Failed to send email to %s due to timeout exception, max timeout: %s ms ",recipients, MAX_TIMEOUT_MS),e); - } - return sentSuccessfully; - } - - public String getTplFile() { - return tplFile; - } - - public void setTplFile(String tplFile) { - this.tplFile = tplFile; - } - - public String getSender() { - return sender; - } - - public void setSender(String sender) { - this.sender = sender; - } - - public String getRecipients() { - return recipients; - } - - public void setRecipients(String recipients) { - this.recipients = recipients; - } - - public String getSubject() { - return subject; - } - - public void setSubject(String subject) { - this.subject = subject; - } - - public ConfigObject getEagleProps() { - return eagleProps; - } - - public void setEagleProps(ConfigObject eagleProps) { - this.eagleProps = eagleProps; - } - - public void setExecutorPool(ThreadPoolExecutor executorPool) { - this.executorPool = executorPool; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0f11a591/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/email/AlertEmailGeneratorBuilder.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/email/AlertEmailGeneratorBuilder.java b/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/email/AlertEmailGeneratorBuilder.java deleted file mode 100644 index 2e63dab..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/email/AlertEmailGeneratorBuilder.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.notification.email; - -import java.util.concurrent.ThreadPoolExecutor; - -import com.typesafe.config.ConfigObject; - -public class AlertEmailGeneratorBuilder { - private AlertEmailGenerator generator; - private AlertEmailGeneratorBuilder(){ - generator = new AlertEmailGenerator(); - } - public static AlertEmailGeneratorBuilder newBuilder(){ - return new AlertEmailGeneratorBuilder(); - } - public AlertEmailGeneratorBuilder withSubject(String subject){ - generator.setSubject(subject); - return this; - } - public AlertEmailGeneratorBuilder withSender(String sender){ - generator.setSender(sender); - return this; - } - public AlertEmailGeneratorBuilder withRecipients(String recipients){ - generator.setRecipients(recipients); - return this; - } - public AlertEmailGeneratorBuilder withTplFile(String tplFile){ - generator.setTplFile(tplFile); - return this; - } - public AlertEmailGeneratorBuilder withEagleProps(ConfigObject eagleProps) { - generator.setEagleProps(eagleProps); - return this; - } - public AlertEmailGeneratorBuilder withExecutorPool(ThreadPoolExecutor threadPoolExecutor) { - generator.setExecutorPool(threadPoolExecutor); - return this; - } - - public AlertEmailGenerator build(){ - return this.generator; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0f11a591/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/email/AlertEmailSender.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/email/AlertEmailSender.java b/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/email/AlertEmailSender.java deleted file mode 100644 index c2c4949..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/email/AlertEmailSender.java +++ /dev/null @@ -1,191 +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.notification.email; - -import java.lang.management.ManagementFactory; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.apache.eagle.policy.common.Constants; -import org.apache.velocity.VelocityContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.apache.eagle.common.DateTimeUtil; -import org.apache.eagle.common.email.EagleMailClient; -import com.netflix.config.ConcurrentMapConfiguration; -import com.typesafe.config.ConfigObject; -import com.typesafe.config.ConfigValue; - -public class AlertEmailSender implements Runnable { - - protected final List<Map<String, String>> alertContexts = new ArrayList<Map<String, String>>(); - protected final String configFileName; - protected final String subject; - protected final String sender; - protected final String recipents; - protected final String cc; - protected final String origin; - protected boolean sentSuccessfully = false; - - private final static Logger LOG = LoggerFactory.getLogger(AlertEmailSender.class); - private final static int MAX_RETRY_COUNT = 3; - - private static final String MAIL_AUTH = "mail.smtp.auth"; - private static final String MAIL_HOST = "mail.smtp.host"; - private static final String MAIL_PORT = "mail.smtp.port"; - private static final String MAIL_USER = "mail.user"; - private static final String MAIL_PASSWORD = "mail.password"; - private static final String MAIL_TLS_ENABLE = "mail.smtp.starttls.enable"; - private static final String MAIL_DEBUG = "mail.debug"; - - private static final String CONF_KEY_MAIL_AUTH = "mailSmtpAuth"; - private static final String CONF_KEY_MAIL_HOST = "mailHost"; - private static final String CONF_KEY_MAIL_PORT = "mailSmtpPort"; - private static final String CONF_KEY_MAIL_USER = "mailSmtpUser"; - private static final String CONF_KEY_MAIL_PASSWORD = "mailSmtpPassword"; - private static final String CONF_KEY_MAIL_SSL_ENABLE = "mailSmtpSslEnable"; - private static final String CONF_KEY_MAIL_TLS_ENABLE = "mailSmtpTlsEnable"; - private static final String CONF_KEY_MAIL_DEBUG = "mailDebug"; - - private ConfigObject eagleProps; - - - private String threadName; - /** - * Derived class may have some additional context properties to add - * @param context velocity context - * @param env environment - */ - protected void additionalContext(VelocityContext context, String env) { - // By default there's no additional context added - } - - public AlertEmailSender(AlertEmailContext alertEmail){ - this.recipents = alertEmail.getRecipients(); - this.configFileName = alertEmail.getVelocityTplFile(); - this.subject = alertEmail.getSubject(); - this.sender = alertEmail.getSender(); - this.cc = alertEmail.getCc(); - for(AlertEmailComponent bean : alertEmail.getComponents()){ - this.alertContexts.add(bean.getAlertContext().getProperties()); - } - String tmp = ManagementFactory.getRuntimeMXBean().getName(); - this.origin = tmp.split("@")[1] + "(pid:" + tmp.split("@")[0] + ")"; - threadName = Thread.currentThread().getName(); - LOG.info("Initialized "+threadName+": origin is : " + this.origin+", recipient of the email: " + this.recipents+", velocity TPL file: " + this.configFileName); - } - - public AlertEmailSender(AlertEmailContext alertEmail, ConfigObject eagleProps){ - this(alertEmail); - this.eagleProps = eagleProps; - } - - @Override - public void run() { - int count = 0; - boolean success = false; - while(count++ < MAX_RETRY_COUNT && !success){ - LOG.info("Sending email, tried: " + count+", max: "+ MAX_RETRY_COUNT); - try { - final EagleMailClient client; - if (eagleProps != null) { - ConcurrentMapConfiguration con = new ConcurrentMapConfiguration(); - con.addProperty(MAIL_HOST, eagleProps.get(CONF_KEY_MAIL_HOST).unwrapped()); - con.addProperty(MAIL_PORT, eagleProps.get(CONF_KEY_MAIL_PORT).unwrapped()); - - // Add authentication for email. - ConfigValue authValue = eagleProps.get(CONF_KEY_MAIL_AUTH); - if (authValue != null && Boolean.parseBoolean(String.valueOf(authValue.unwrapped()))) { - con.addProperty(MAIL_AUTH, authValue.unwrapped()); - con.addProperty(MAIL_USER, eagleProps.get(CONF_KEY_MAIL_USER).unwrapped()); - con.addProperty(MAIL_PASSWORD, eagleProps.get(CONF_KEY_MAIL_PASSWORD).unwrapped()); - - // Via SSL. - ConfigValue sslValue = eagleProps.get(CONF_KEY_MAIL_SSL_ENABLE); - if (sslValue != null && Boolean.parseBoolean(String.valueOf(sslValue.unwrapped()))) { - con.addProperty("mail.smtp.socketFactory.port", "465"); - con.addProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); - } - - // Via TLS. - ConfigValue tlsValue = eagleProps.get(CONF_KEY_MAIL_TLS_ENABLE); - if (tlsValue != null && Boolean.parseBoolean(String.valueOf(tlsValue.unwrapped()))) { - con.addProperty(MAIL_TLS_ENABLE, tlsValue.unwrapped()); - } - } - - ConfigValue debugValue = eagleProps.get(CONF_KEY_MAIL_DEBUG); - if (debugValue != null && Boolean.parseBoolean(String.valueOf(debugValue.unwrapped()))) { - con.addProperty(MAIL_DEBUG, debugValue.unwrapped()); - } - - client = new EagleMailClient(con); - } else { - client = new EagleMailClient(); - } - String env = "prod"; - if (eagleProps != null && eagleProps.get("env") != null) { - env = (String) eagleProps.get("env").unwrapped(); - } - - LOG.info("Env is: " + env); - final VelocityContext context = new VelocityContext(); - generateCommonContext(context); - LOG.info("After calling generateCommonContext..."); - additionalContext(context, env); - - if (recipents == null || recipents.equals("")) { - LOG.error("Recipients is null, skip sending emails "); - return; - } - String title = subject; - if (!env.trim().equals("prod")) { - title = "[" + env + "]" + title; - } - success = client.send(sender, recipents, cc, title, configFileName, context, null); - LOG.info("Success of sending email: " + success); - if(!success && count < MAX_RETRY_COUNT) { - LOG.info("Sleep for a while before retrying"); - Thread.sleep(10*1000); - } - } - catch (Exception e){ - LOG.warn("Sending mail exception", e); - } - } - - if(success){ - sentSuccessfully = true; - LOG.info(String.format("Successfully send email, thread: %s",threadName)); - }else{ - LOG.warn(String.format("Fail sending email after tries %s times, thread: %s",MAX_RETRY_COUNT,threadName)); - } - } - - private void generateCommonContext(VelocityContext context) { - context.put(Constants.ALERT_EMAIL_TIME_PROPERTY, DateTimeUtil.millisecondsToHumanDateWithSeconds( System.currentTimeMillis() )); - context.put(Constants.ALERT_EMAIL_COUNT_PROPERTY, alertContexts.size()); - context.put(Constants.ALERT_EMAIL_ALERTLIST_PROPERTY, alertContexts); - context.put(Constants.ALERT_EMAIL_ORIGIN_PROPERTY, origin); - } - - public boolean sentSuccessfully(){ - return this.sentSuccessfully; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0f11a591/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/plugin/AlertEagleStorePersister.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/plugin/AlertEagleStorePersister.java b/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/plugin/AlertEagleStorePersister.java deleted file mode 100644 index e098256..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/plugin/AlertEagleStorePersister.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.notification.plugin; - -import com.typesafe.config.Config; -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; - -/** - * Alert API entity Persistor - */ -public class AlertEagleStorePersister { - private static Logger LOG = LoggerFactory.getLogger(AlertEagleStorePersister.class); - private String eagleServiceHost; - private int eagleServicePort; - private String username; - private String password; - - - public AlertEagleStorePersister(String eagleServiceHost, int eagleServicePort) { - this(eagleServiceHost, eagleServicePort, null, null); - } - - public AlertEagleStorePersister(String eagleServiceHost, int eagleServicePort, String username, String password) { - this.eagleServiceHost = eagleServiceHost; - this.eagleServicePort = eagleServicePort; - this.username = username; - this.password = password; - } - - public AlertEagleStorePersister(Config config ) { - this.eagleServiceHost = config.getString("eagleProps.eagleService.host"); - this.eagleServicePort = config.getInt("eagleProps.eagleService.port"); - this.username = config.getString("eagleProps.eagleService.username"); - this.password =config.getString("eagleProps.eagleService.password"); - } - - /** - * Persist passes list of Entities - * @param list - * @return - */ - 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 with exception " + response.getException()); - return false; - } - } - catch (Exception ex) { - LOG.error("Got an exception in persisting entities", ex); - return false; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0f11a591/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/plugin/AlertEagleStorePlugin.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/plugin/AlertEagleStorePlugin.java b/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/plugin/AlertEagleStorePlugin.java deleted file mode 100644 index 6013a80..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/plugin/AlertEagleStorePlugin.java +++ /dev/null @@ -1,101 +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.notification.plugin; - -import com.typesafe.config.Config; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.eagle.alert.entity.AlertAPIEntity; -import org.apache.eagle.alert.entity.AlertDefinitionAPIEntity; -import org.apache.eagle.notification.base.NotificationStatus; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Vector; - -/** - * Plugin to persist alerts to Eagle Storage - */ -public class AlertEagleStorePlugin implements NotificationPlugin { - private static final Logger LOG = LoggerFactory.getLogger(AlertEagleStorePlugin.class); - private List<NotificationStatus> statusList = new Vector<>(); - private AlertEagleStorePersister persist; - - @Override - public void init(Config config, List<AlertDefinitionAPIEntity> initAlertDefs) throws Exception { - this.persist = new AlertEagleStorePersister(config); - LOG.info("initialized plugin for EagleStorePlugin"); - } - - @Override - public void update(String policyId, List<Map<String,String>> notificationConfigCollection , boolean isPolicyDelete ) throws Exception { - if(isPolicyDelete){ - LOG.info("Deleted policy ..."); - return; - } - LOG.info("created/updated plugin ..."); - } - - @Override - public List<NotificationStatus> getStatusList() { - return this.statusList; - } - - /** - * Persist AlertEntity to alert_details table - * @param alertEntity - */ - @Override - public void onAlert(AlertAPIEntity alertEntity) { - LOG.info("write alert to eagle storage " + alertEntity); - NotificationStatus status = new NotificationStatus(); - try{ - List<AlertAPIEntity> list = new ArrayList<AlertAPIEntity>(); - list.add(alertEntity); - boolean result = persist.doPersist(list); - if(result) { - status.successful = true; - status.errorMessage = ""; - }else{ - status.successful = false; - status.errorMessage = ""; - } - }catch (Exception ex ){ - status.successful = false; - status.errorMessage = ex.getMessage(); - LOG.error("Fail writing alert entity to Eagle Store", ex); - } - this.statusList.add(status); - } - - @Override - public int hashCode(){ - return new HashCodeBuilder().append(getClass().getCanonicalName()).toHashCode(); - } - - @Override - public boolean equals(Object o){ - if(o == this) - return true; - if(!(o instanceof AlertEagleStorePlugin)) - return false; - return true; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0f11a591/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/plugin/AlertEmailPlugin.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/plugin/AlertEmailPlugin.java b/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/plugin/AlertEmailPlugin.java deleted file mode 100644 index 9acb38e..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert-notification-plugin/src/main/java/org/apache/eagle/notification/plugin/AlertEmailPlugin.java +++ /dev/null @@ -1,149 +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.notification.plugin; - -import com.typesafe.config.Config; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.eagle.alert.entity.AlertAPIEntity; -import org.apache.eagle.alert.entity.AlertDefinitionAPIEntity; -import org.apache.eagle.common.config.EagleConfigFactory; -import org.apache.eagle.notification.base.NotificationConstants; -import org.apache.eagle.notification.base.NotificationStatus; -import org.apache.eagle.notification.email.AlertEmailGenerator; -import org.apache.eagle.notification.email.AlertEmailGeneratorBuilder; -import org.apache.eagle.notification.utils.NotificationPluginUtils; -import org.apache.eagle.policy.common.Constants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -/** - * Send alert to email - */ -public class AlertEmailPlugin implements NotificationPlugin { - private static final Logger LOG = LoggerFactory.getLogger(AlertEmailPlugin.class); - private Map<String, List<AlertEmailGenerator>> emailGenerators = new ConcurrentHashMap<>(); - private final static int DEFAULT_THREAD_POOL_CORE_SIZE = 4; - private final static int DEFAULT_THREAD_POOL_MAX_SIZE = 8; - private final static long DEFAULT_THREAD_POOL_SHRINK_TIME = 60000L; // 1 minute - private transient ThreadPoolExecutor executorPool; - private Vector<NotificationStatus> statusList = new Vector<>(); - private Config config; - - @Override - public void init(Config config, List<AlertDefinitionAPIEntity> initAlertDefs) throws Exception { - this.config = config; - executorPool = new ThreadPoolExecutor(DEFAULT_THREAD_POOL_CORE_SIZE, DEFAULT_THREAD_POOL_MAX_SIZE, DEFAULT_THREAD_POOL_SHRINK_TIME, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); - LOG.info(" Creating Email Generator... "); - for( AlertDefinitionAPIEntity entity : initAlertDefs ){ - List<Map<String,String>> configMaps = NotificationPluginUtils.deserializeNotificationConfig(entity.getNotificationDef()); - this.update(entity.getTags().get(Constants.POLICY_ID), configMaps, false); - } - } - - /** - * @param notificationConfigCollection - * @throws Exception - */ - @Override - public void update(String policyId, List<Map<String,String>> notificationConfigCollection, boolean isPolicyDelete) throws Exception { - if(isPolicyDelete){ - LOG.info(" Policy been deleted.. Removing reference from Notification Plugin "); - this.emailGenerators.remove(policyId); - return; - } - Vector<AlertEmailGenerator> generators = new Vector<>(); - for(Map<String, String> notificationConf: notificationConfigCollection) { - String notificationType = notificationConf.get(NotificationConstants.NOTIFICATION_TYPE); - if(notificationType == null || notificationType.equalsIgnoreCase(NotificationConstants.EMAIL_NOTIFICATION)) { - AlertEmailGenerator generator = createEmailGenerator(notificationConf); - generators.add(generator); - } - } - if(generators.size() != 0) { - this.emailGenerators.put(policyId, generators); - LOG.info("created/updated email generators for policy " + policyId); - } - } - - /** - * API to send email - * @param alertEntity - * @throws Exception - */ - @Override - public void onAlert(AlertAPIEntity alertEntity) throws Exception { - String policyId = alertEntity.getTags().get(Constants.POLICY_ID); - List<AlertEmailGenerator> generators = this.emailGenerators.get(policyId); - for(AlertEmailGenerator generator: generators) { - boolean isSuccess = generator.sendAlertEmail(alertEntity); - NotificationStatus status = new NotificationStatus(); - if( !isSuccess ) { - status.errorMessage = "Failed to send email"; - status.successful = false; - }else { - status.errorMessage = ""; - status.successful = true; - } - this.statusList.add(status); - } - } - - @Override - public List<NotificationStatus> getStatusList() { - return this.statusList; - } - - /** - * @param notificationConfig - * @return - */ - private AlertEmailGenerator createEmailGenerator( Map<String,String> notificationConfig ) { - String tplFileName = notificationConfig.get(NotificationConstants.TPL_FILE_NAME); - if (tplFileName == null || tplFileName.equals("")) { - tplFileName = "ALERT_DEFAULT.vm"; - } - AlertEmailGenerator gen = AlertEmailGeneratorBuilder.newBuilder(). - withEagleProps(this.config.getObject("eagleProps")). - withSubject(notificationConfig.get(NotificationConstants.SUBJECT)). - withSender(notificationConfig.get(NotificationConstants.SENDER)). - withRecipients(notificationConfig.get(NotificationConstants.RECIPIENTS)). - withTplFile(tplFileName). - withExecutorPool(this.executorPool).build(); - return gen; - } - - @Override - public int hashCode(){ - return new HashCodeBuilder().append(getClass().getCanonicalName()).toHashCode(); - } - - @Override - public boolean equals(Object o){ - if(o == this) - return true; - if(!(o instanceof AlertEmailPlugin)) - return false; - return true; - } -} \ No newline at end of file
