Repository: stratos Updated Branches: refs/heads/4.0.0-grouping 24fc938ea -> 5cf073010
adding monitor message passing using notification Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/48aa865f Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/48aa865f Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/48aa865f Branch: refs/heads/4.0.0-grouping Commit: 48aa865fdaa9e7c1a4e4ff65f86b2b0338823048 Parents: 217bc54 Author: reka <[email protected]> Authored: Thu Sep 25 16:24:48 2014 +0530 Committer: reka <[email protected]> Committed: Thu Sep 25 16:24:48 2014 +0530 ---------------------------------------------------------------------- .../AutoscalerTopologyEventReceiver.java | 42 ++++++++++++++- .../monitor/AbstractClusterMonitor.java | 18 ++++++- .../stratos/autoscaler/monitor/Monitor.java | 21 +++----- .../monitor/application/ApplicationMonitor.java | 55 ++++++++++++++++---- .../monitor/cluster/ClusterMonitor.java | 10 +--- .../monitor/cluster/LbClusterMonitor.java | 9 ---- .../events/ApplicationActivatedEvent.java | 42 +++++++++++++++ .../monitor/events/ClusterActivatedEvent.java | 49 ++++++++++++++++- .../events/ClusterInMaintenanceEvent.java | 20 ++++++- .../monitor/events/GroupActivatedEvent.java | 43 ++++++++++++++- .../monitor/events/GroupInMaintenanceEvent.java | 20 ++++++- .../autoscaler/monitor/events/MonitorEvent.java | 22 +++++++- .../monitor/events/MonitorStatusEvent.java | 42 +++++++++++++++ .../autoscaler/monitor/group/GroupMonitor.java | 28 ++++++++++ 14 files changed, 372 insertions(+), 49 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/48aa865f/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java index 575e1a5..d5ebec8 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java @@ -146,12 +146,50 @@ public class AutoscalerTopologyEventReceiver implements Runnable { ApplicationMonitor appMonitor = AutoscalerContext.getInstance().getAppMonitor(appId); Monitor monitor = appMonitor.findParentMonitorOfCluster(clusterId); - monitor.notify(); + AbstractClusterMonitor clusterMonitor = AutoscalerContext.getInstance().getMonitor(clusterId); + + //TODO monitor.notify(); //starting the status checker to decide on the status of it's parent StatusChecker.getInstance().onClusterStatusChange(clusterId, appId); } }); + topologyEventReceiver.addEventListener(new GroupActivatedEventListener() { + @Override + protected void onEvent(Event event) { + + log.info("[GroupActivatedEvent] Received: " + event.getClass()); + + GroupActivatedEvent groupActivatedEvent = (GroupActivatedEvent) event; + String appId = groupActivatedEvent.getAppId(); + String groupId = groupActivatedEvent.getGroupId(); + + ApplicationMonitor appMonitor = AutoscalerContext.getInstance().getAppMonitor(appId); + Monitor monitor = appMonitor.findParentMonitorOfGroup(groupId); + + //TODO monitor.notify(); + //starting the status checker to decide on the status of it's parent + StatusChecker.getInstance().onGroupStatusChange(groupId, appId); + } + }); + + topologyEventReceiver.addEventListener(new ApplicationActivatedEventListener() { + @Override + protected void onEvent(Event event) { + + log.info("[ApplicationActivatedEvent] Received: " + event.getClass()); + + ApplicationActivatedEvent applicationActivatedEvent = (ApplicationActivatedEvent) event; + String appId = applicationActivatedEvent.getAppId(); + + ApplicationMonitor appMonitor = AutoscalerContext.getInstance().getAppMonitor(appId); + //TODO update appmonitor + //starting the status checker to decide on the status of it's parent + //StatusChecker.getInstance().onClusterStatusChange(clusterId, appId); + } + }); + + topologyEventReceiver.addEventListener(new ApplicationRemovedEventListener() { @Override @@ -408,6 +446,8 @@ public class AutoscalerTopologyEventReceiver implements Runnable { } // partitionContext.incrementCurrentActiveMemberCount(1); partitionContext.movePendingMemberToActiveMembers(memberId); + //triggering the status checker + StatusChecker.getInstance().onMemberStatusChange(e.getClusterId()); } catch (Exception e) { log.error("Error processing event", e); http://git-wip-us.apache.org/repos/asf/stratos/blob/48aa865f/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/AbstractClusterMonitor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/AbstractClusterMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/AbstractClusterMonitor.java index cb93886..ae47f63 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/AbstractClusterMonitor.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/AbstractClusterMonitor.java @@ -18,6 +18,7 @@ */ package org.apache.stratos.autoscaler.monitor; +import org.apache.stratos.autoscaler.monitor.events.MonitorStatusEvent; import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy; import java.util.Map; @@ -35,6 +36,7 @@ import org.apache.stratos.autoscaler.util.ConfUtil; import org.apache.stratos.messaging.domain.topology.Cluster; import org.apache.stratos.messaging.domain.topology.Member; import org.apache.stratos.messaging.domain.topology.Service; +import org.apache.stratos.messaging.domain.topology.Status; import org.apache.stratos.messaging.message.receiver.topology.TopologyManager; import org.drools.runtime.StatefulKnowledgeSession; import org.drools.runtime.rule.FactHandle; @@ -66,6 +68,8 @@ abstract public class AbstractClusterMonitor extends Observable implements Obser protected String serviceId; protected String appId; + protected Status status; + protected AutoscalerRuleEvaluator autoscalerRuleEvaluator; // time intereval between two runs of the Monitor. Default is 90000ms. @@ -230,10 +234,22 @@ abstract public class AbstractClusterMonitor extends Observable implements Obser @Override public void update(Observable observable, Object o) { - + //get the update from parent monitor } public int getMonitorInterval() { return monitorInterval; } + + public Status getStatus() { + return status; + } + + public void setStatus(Status status) { + log.info(String.format("[Monitor] %s is notifying the parent" + + "on its state change from %s to %s", clusterId, this.status, status)); + this.status = status; + setChanged(); + notifyObservers(new MonitorStatusEvent(status, clusterId)); + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/48aa865f/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java index 19f8298..420fc38 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java @@ -26,13 +26,13 @@ import org.apache.stratos.autoscaler.exception.PolicyValidationException; import org.apache.stratos.autoscaler.grouping.DependencyBuilder; import org.apache.stratos.autoscaler.monitor.cluster.ClusterMonitor; import org.apache.stratos.autoscaler.monitor.cluster.LbClusterMonitor; +import org.apache.stratos.autoscaler.monitor.events.MonitorStatusEvent; import org.apache.stratos.autoscaler.monitor.group.GroupMonitor; import org.apache.stratos.autoscaler.util.AutoscalerUtil; import org.apache.stratos.messaging.domain.topology.Cluster; -import org.apache.stratos.messaging.domain.topology.ClusterDataHolder; import org.apache.stratos.messaging.domain.topology.ParentBehavior; +import org.apache.stratos.messaging.domain.topology.Status; import org.apache.stratos.messaging.event.Event; -import org.apache.stratos.messaging.message.receiver.topology.TopologyManager; import java.util.*; @@ -53,10 +53,13 @@ public abstract class Monitor extends Observable implements Observer { protected ParentBehavior component; + protected Status status; + public Monitor(ParentBehavior component) { groupMonitors = new HashMap<String, GroupMonitor>(); abstractClusterMonitors = new HashMap<String, AbstractClusterMonitor>(); this.component = component; + preOrderTraverse = DependencyBuilder.getStartupOrder(component); startDependency(); } @@ -89,17 +92,6 @@ public abstract class Monitor extends Observable implements Observer { public abstract void monitor(); - @Override - public void update(Observable observable, Object arg) { - if(arg instanceof Event) { - Event event = (Event) arg; - if(log.isDebugEnabled()) { - log.debug(String.format("Event received: %s", event.getClass().getName())); - } - onEvent(event); - } - } - /** * Triggered when an event is received. * @param event @@ -162,6 +154,9 @@ public abstract class Monitor extends Observable implements Observer { } } + public Status getStatus() { + return status; + } private class ClusterMonitorAdder implements Runnable { private Cluster cluster; http://git-wip-us.apache.org/repos/asf/stratos/blob/48aa865f/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitor.java index 963b24a..c517868 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitor.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitor.java @@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.stratos.autoscaler.grouping.DependencyBuilder; import org.apache.stratos.autoscaler.monitor.AbstractClusterMonitor; import org.apache.stratos.autoscaler.monitor.Monitor; +import org.apache.stratos.autoscaler.monitor.events.MonitorStatusEvent; import org.apache.stratos.autoscaler.monitor.group.GroupMonitor; import org.apache.stratos.autoscaler.status.checker.StatusChecker; import org.apache.stratos.messaging.domain.topology.*; @@ -44,11 +45,18 @@ public class ApplicationMonitor extends Monitor { } @Override - public void update(Observable observable, Object arg) { - if(arg instanceof Event) { - + public void update(Observable observable, Object event) { + if(event instanceof MonitorStatusEvent) { + MonitorStatusEvent statusEvent = (MonitorStatusEvent) event; + Status childStatus = statusEvent.getStatus(); + String notifier = statusEvent.getNotifierId(); + log.info(String.format("[Monitor] %s got notified from the [child] %s" + + "on its state change from %s to %s", id, notifier, this.status, status)); + if(childStatus == Status.Activated) { + //start the next dependency + startDependency(); + } } - } @Override @@ -62,9 +70,7 @@ public class ApplicationMonitor extends Monitor { //TODO breadth first search in a tree and find the parallel one //TODO build up the tree with ordered manner - preOrderTraverse = DependencyBuilder.getStartupOrder(component); - - //start the first dependency + // start the first dependency if(!preOrderTraverse.isEmpty()) { String dependency = preOrderTraverse.poll(); if (dependency.contains("group")) { @@ -95,11 +101,40 @@ public class ApplicationMonitor extends Monitor { /** * Find the group monitor by traversing recursively in the hierarchical monitors. - * @param id the unique alias of the Group + * @param groupId the unique alias of the Group * @return the found GroupMonitor */ - public Monitor findGroupMonitorWithId(String id) { - return findGroupMonitor(id, groupMonitors.values()); + public Monitor findGroupMonitorWithId(String groupId) { + return findGroupMonitor(groupId, groupMonitors.values()); + + } + + /** + * Find the cluster monitor by traversing recursively in the hierarchical monitors. + * @param clusterId + * @return + */ + public AbstractClusterMonitor findClusterMonitorWithId(String clusterId) { + return findClusterMonitor(clusterId, abstractClusterMonitors.values(), groupMonitors.values()); + + } + + private AbstractClusterMonitor findClusterMonitor(String clusterId, + Collection<AbstractClusterMonitor> clusterMonitors, + Collection<GroupMonitor> groupMonitors) { + for (AbstractClusterMonitor monitor : clusterMonitors) { + // check if alias is equal, if so, return + if (monitor.equals(clusterId)) { + return monitor; + } + } + + for(GroupMonitor groupMonitor : groupMonitors) { + return findClusterMonitor(clusterId, + groupMonitor.getAbstractClusterMonitors().values(), + groupMonitor.getGroupMonitors().values()); + } + return null; } http://git-wip-us.apache.org/repos/asf/stratos/blob/48aa865f/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java index 8c1e508..1189f8f 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java @@ -46,7 +46,7 @@ public class ClusterMonitor extends AbstractClusterMonitor { private static final Log log = LogFactory.getLog(ClusterMonitor.class); private String lbReferenceType; private boolean hasPrimary; - private Status status; + public ClusterMonitor(String clusterId, String serviceId, DeploymentPolicy deploymentPolicy, AutoscalePolicy autoscalePolicy) { @@ -241,12 +241,4 @@ public class ClusterMonitor extends AbstractClusterMonitor { public void setHasPrimary(boolean hasPrimary) { this.hasPrimary = hasPrimary; } - - public Status getStatus() { - return status; - } - - public void setStatus(Status status) { - this.status = status; - } } http://git-wip-us.apache.org/repos/asf/stratos/blob/48aa865f/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/LbClusterMonitor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/LbClusterMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/LbClusterMonitor.java index 0335db9..e627503 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/LbClusterMonitor.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/LbClusterMonitor.java @@ -117,14 +117,5 @@ public class LbClusterMonitor extends AbstractClusterMonitor { } - public Status getStatus() { - return status; - } - - public void setStatus(Status status) { - this.status = status; - } - - } http://git-wip-us.apache.org/repos/asf/stratos/blob/48aa865f/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ApplicationActivatedEvent.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ApplicationActivatedEvent.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ApplicationActivatedEvent.java new file mode 100644 index 0000000..719c94f --- /dev/null +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ApplicationActivatedEvent.java @@ -0,0 +1,42 @@ +/* + * 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.stratos.autoscaler.monitor.events; + +import org.apache.stratos.messaging.domain.topology.Status; + +/** + * This will use to notify observers upon a application activation events received in Topology. + */ +public class ApplicationActivatedEvent extends MonitorEvent { + private Status status; + private String appId; + + public ApplicationActivatedEvent(Status status, String appId) { + this.status = status; + this.appId = appId; + } + + public Status getStatus() { + return status; + } + + public String getAppId() { + return appId; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/48aa865f/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ClusterActivatedEvent.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ClusterActivatedEvent.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ClusterActivatedEvent.java index e35fe74..54e6407 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ClusterActivatedEvent.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ClusterActivatedEvent.java @@ -1,7 +1,54 @@ +/* + * 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.stratos.autoscaler.monitor.events; +import org.apache.stratos.messaging.domain.topology.Status; + /** - * Created by reka on 9/21/14. + * This will use to notify observers upon a cluster activation events received in Topology. */ public class ClusterActivatedEvent extends MonitorEvent { + private Status status; + private String appId; + private String clusterId; + private String serviceName; + + public ClusterActivatedEvent(Status status, String appId, String clusterId, String serviceName) { + this.status = status; + this.appId = appId; + this.clusterId = clusterId; + this.serviceName = serviceName; + } + + public Status getStatus() { + return status; + } + + public String getAppId() { + return appId; + } + + public String getClusterId() { + return clusterId; + } + + public String getServiceName() { + return serviceName; + } } http://git-wip-us.apache.org/repos/asf/stratos/blob/48aa865f/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ClusterInMaintenanceEvent.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ClusterInMaintenanceEvent.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ClusterInMaintenanceEvent.java index f227195..14d322c 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ClusterInMaintenanceEvent.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/ClusterInMaintenanceEvent.java @@ -1,7 +1,25 @@ +/* + * 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.stratos.autoscaler.monitor.events; /** - * Created by reka on 9/21/14. + * This will use to notify observers upon a cluster maintenance events received in Topology. */ public class ClusterInMaintenanceEvent extends MonitorEvent { } http://git-wip-us.apache.org/repos/asf/stratos/blob/48aa865f/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/GroupActivatedEvent.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/GroupActivatedEvent.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/GroupActivatedEvent.java index 448df65..cd7d37d 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/GroupActivatedEvent.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/GroupActivatedEvent.java @@ -1,7 +1,48 @@ +/* + * 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.stratos.autoscaler.monitor.events; +import org.apache.stratos.messaging.domain.topology.Status; + /** - * Created by reka on 9/21/14. + * This will use to notify observers upon a group activation events received in Topology. */ public class GroupActivatedEvent extends MonitorEvent { + private Status status; + private String appId; + private String groupId; + + public GroupActivatedEvent(Status status, String appId, String groupId) { + this.status = status; + this.appId = appId; + this.groupId = groupId; + } + + public Status getStatus() { + return status; + } + + public String getAppId() { + return appId; + } + + public String getGroupId() { + return groupId; + } } http://git-wip-us.apache.org/repos/asf/stratos/blob/48aa865f/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/GroupInMaintenanceEvent.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/GroupInMaintenanceEvent.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/GroupInMaintenanceEvent.java index e7b0605..163e0d6 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/GroupInMaintenanceEvent.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/GroupInMaintenanceEvent.java @@ -1,7 +1,25 @@ +/* + * 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.stratos.autoscaler.monitor.events; /** - * Created by reka on 9/21/14. + * This will use to notify observers upon a group maintenance events received in Topology. */ public class GroupInMaintenanceEvent extends MonitorEvent { } http://git-wip-us.apache.org/repos/asf/stratos/blob/48aa865f/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorEvent.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorEvent.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorEvent.java index 8fcf782..96e2ae4 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorEvent.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorEvent.java @@ -1,9 +1,27 @@ +/* + * 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.stratos.autoscaler.monitor.events; import java.io.Serializable; /** - * Created by reka on 9/21/14. + * This event will be used to notify observers based on the status events received from Topology. */ -public abstract class MonitorEvent implements Serializable{ +public abstract class MonitorEvent implements Serializable { } http://git-wip-us.apache.org/repos/asf/stratos/blob/48aa865f/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorStatusEvent.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorStatusEvent.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorStatusEvent.java new file mode 100644 index 0000000..61fcf95 --- /dev/null +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/events/MonitorStatusEvent.java @@ -0,0 +1,42 @@ +/* + * 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.stratos.autoscaler.monitor.events; + +import org.apache.stratos.messaging.domain.topology.Status; + +/** + * Created by reka on 9/25/14. + */ +public class MonitorStatusEvent extends MonitorEvent { + private Status status; + private String notifierId; + + public MonitorStatusEvent(Status status, String notifierId) { + this.status = status; + this.notifierId = notifierId; + } + + public Status getStatus() { + return status; + } + + public String getNotifierId() { + return notifierId; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/48aa865f/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/group/GroupMonitor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/group/GroupMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/group/GroupMonitor.java index 4b5d62b..8fa20f1 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/group/GroupMonitor.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/group/GroupMonitor.java @@ -22,14 +22,17 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.autoscaler.grouping.DependencyBuilder; import org.apache.stratos.autoscaler.monitor.Monitor; +import org.apache.stratos.autoscaler.monitor.events.MonitorStatusEvent; import org.apache.stratos.messaging.domain.topology.Cluster; import org.apache.stratos.messaging.domain.topology.ClusterDataHolder; import org.apache.stratos.messaging.domain.topology.Group; +import org.apache.stratos.messaging.domain.topology.Status; import org.apache.stratos.messaging.event.Event; import org.apache.stratos.messaging.message.receiver.topology.TopologyManager; import java.util.List; import java.util.Map; +import java.util.Observable; /** * This is GroupMonitor to monitor the group which consists of @@ -48,6 +51,31 @@ public class GroupMonitor extends Monitor { } @Override + public void update(Observable observable, Object event) { + if(event instanceof MonitorStatusEvent) { + MonitorStatusEvent statusEvent = (MonitorStatusEvent) event; + Status childStatus = statusEvent.getStatus(); + String notifier = statusEvent.getNotifierId(); + log.info(String.format("[Monitor] %s got notified from the [child] %s" + + "on its state change from %s to %s", id, notifier, this.status, status)); + if(childStatus == Status.Activated) { + //start the next dependency + startDependency(); + } + + } + + } + + public void setStatus(Status status) { + log.info(String.format("[Monitor] %s is notifying the parent" + + "on its state change from %s to %s", id, this.status, status)); + this.status = status; + setChanged(); + notifyObservers(new MonitorStatusEvent(status, id)); + } + + @Override public void startDependency() { //Need to get the order every time as group/cluster might already been started //TODO breadth first search in a tree and find the parallel one
