eagle-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From qingwz...@apache.org
Subject incubator-eagle git commit: [MINOR] add back policy scheduler
Date Fri, 11 Nov 2016 08:37:24 GMT
Repository: incubator-eagle
Updated Branches:
  refs/heads/master aa7b0254d -> 45af18e7f


[MINOR] add back policy scheduler

Author: Zhao, Qingwen <qingwzhao@apache.org>

Closes #646 from qingwen220/minor.


Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/45af18e7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/45af18e7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/45af18e7

Branch: refs/heads/master
Commit: 45af18e7faac26eb564ae247cb702f89f9e886d2
Parents: aa7b025
Author: Zhao, Qingwen <qingwzhao@apache.org>
Authored: Fri Nov 11 16:37:16 2016 +0800
Committer: Zhao, Qingwen <qingwzhao@apache.org>
Committed: Fri Nov 11 16:37:16 2016 +0800

----------------------------------------------------------------------
 .../eagle/alert/coordinator/Coordinator.java    | 33 +++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/45af18e7/eagle-core/eagle-alert-parent/eagle-alert/alert-coordinator/src/main/java/org/apache/eagle/alert/coordinator/Coordinator.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-coordinator/src/main/java/org/apache/eagle/alert/coordinator/Coordinator.java
b/eagle-core/eagle-alert-parent/eagle-alert/alert-coordinator/src/main/java/org/apache/eagle/alert/coordinator/Coordinator.java
index 95698e8..2a0abce 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-coordinator/src/main/java/org/apache/eagle/alert/coordinator/Coordinator.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-coordinator/src/main/java/org/apache/eagle/alert/coordinator/Coordinator.java
@@ -26,6 +26,10 @@ import org.apache.eagle.alert.config.ZKConfigBuilder;
 import org.apache.eagle.alert.coordination.model.ScheduleState;
 import org.apache.eagle.alert.coordinator.impl.MetadataValdiator;
 import org.apache.eagle.alert.coordinator.provider.ScheduleContextBuilder;
+import org.apache.eagle.alert.coordinator.trigger.CoordinatorTrigger;
+import org.apache.eagle.alert.coordinator.trigger.DynamicPolicyLoader;
+import org.apache.eagle.alert.coordinator.trigger.PolicyChangeListener;
+import org.apache.eagle.alert.engine.coordinator.PolicyDefinition;
 import org.apache.eagle.alert.service.IMetadataServiceClient;
 import org.apache.eagle.alert.service.MetadataServiceClientImpl;
 import org.slf4j.Logger;
@@ -33,6 +37,8 @@ import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
 import java.text.MessageFormat;
+import java.util.Collection;
+import java.util.List;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
@@ -192,6 +198,29 @@ public class Coordinator {
         }
     }
 
+    private static class PolicyChangeHandler implements PolicyChangeListener {
+        private static final Logger LOG = LoggerFactory.getLogger(PolicyChangeHandler.class);
+        private Config config;
+        private IMetadataServiceClient client;
+
+        public PolicyChangeHandler(Config config, IMetadataServiceClient client) {
+            this.config = config;
+            this.client = client;
+        }
+
+        @Override
+        public void onPolicyChange(List<PolicyDefinition> allPolicies, Collection<String>
addedPolicies,
+                                   Collection<String> removedPolicies, Collection<String>
modifiedPolicies) {
+            LOG.info("policy changed ... ");
+            LOG.info("allPolicies: " + allPolicies + ", addedPolicies: " + addedPolicies
+ ", removedPolicies: "
+                    + removedPolicies + ", modifiedPolicies: " + modifiedPolicies);
+
+            CoordinatorTrigger trigger = new CoordinatorTrigger(config, client);
+            trigger.run();
+
+        }
+    }
+
     public static void startSchedule() {
         Config config = ConfigFactory.load().getConfig(COORDINATOR);
         String host = config.getString(METADATA_SERVICE_HOST);
@@ -208,7 +237,9 @@ public class Coordinator {
             return t;
         });
 
-        // scheduleSrv.scheduleAtFixedRate(new CoordinatorTrigger(config, client), initDelayMillis,
delayMillis, TimeUnit.MILLISECONDS);
+        DynamicPolicyLoader loader = new DynamicPolicyLoader(client);
+        loader.addPolicyChangeListener(new PolicyChangeHandler(config, client));
+        scheduleSrv.scheduleAtFixedRate(loader, initDelayMillis, delayMillis, TimeUnit.MILLISECONDS);
 
         Runtime.getRuntime().addShutdownHook(new Thread(new CoordinatorShutdownHook(scheduleSrv)));
         LOG.info("Eagle Coordinator started ...");


Mime
View raw message