You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by is...@apache.org on 2014/10/21 16:20:55 UTC
[3/3] git commit: completing the initial flow for application
undeployment
completing the initial flow for application undeployment
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/684d71f7
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/684d71f7
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/684d71f7
Branch: refs/heads/4.0.0-grouping
Commit: 684d71f72d8150be5da1bc1e8805266fabe0fa05
Parents: ea8ee9b
Author: Isuru Haththotuwa <is...@apache.org>
Authored: Tue Oct 21 19:50:04 2014 +0530
Committer: Isuru Haththotuwa <is...@apache.org>
Committed: Tue Oct 21 19:50:04 2014 +0530
----------------------------------------------------------------------
.../grouping/topic/StatusEventPublisher.java | 15 ++
.../status/checker/StatusChecker.java | 1 +
.../controller/topology/TopologyBuilder.java | 140 ++++++++++---------
.../domain/topology/ApplicationStatus.java | 6 +-
.../messaging/domain/topology/Cluster.java | 18 +--
.../status/ApplicationTerminatedEvent.java | 11 +-
6 files changed, 115 insertions(+), 76 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/684d71f7/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/topic/StatusEventPublisher.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/topic/StatusEventPublisher.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/topic/StatusEventPublisher.java
index 2ffff81..668161a 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/topic/StatusEventPublisher.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/topic/StatusEventPublisher.java
@@ -4,10 +4,12 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.messaging.broker.publish.EventPublisher;
import org.apache.stratos.messaging.broker.publish.EventPublisherPool;
+import org.apache.stratos.messaging.domain.topology.ClusterDataHolder;
import org.apache.stratos.messaging.event.Event;
import org.apache.stratos.messaging.event.application.status.*;
import org.apache.stratos.messaging.event.application.status.ApplicationActivatedEvent;
import org.apache.stratos.messaging.event.application.status.ApplicationInactivatedEvent;
+import org.apache.stratos.messaging.event.application.status.ApplicationTerminatedEvent;
import org.apache.stratos.messaging.event.application.status.ClusterActivatedEvent;
import org.apache.stratos.messaging.event.application.status.ClusterMaintenanceModeEvent;
import org.apache.stratos.messaging.event.application.status.GroupActivatedEvent;
@@ -15,6 +17,8 @@ import org.apache.stratos.messaging.event.topology.*;
import org.apache.stratos.messaging.event.topology.GroupInActivateEvent;
import org.apache.stratos.messaging.util.Constants;
+import java.util.Set;
+
/**
* This will publish application related events to application status topic.
*/
@@ -188,6 +192,17 @@ public class StatusEventPublisher {
publishEvent(groupMaintenanceModeEvent);
}
+ public static void sendApplicationTerminatingEvent (String appId) {
+ // TODO: implement
+ }
+
+ public static void sendApplicationTerminatedEvent (String appId, Set<ClusterDataHolder> clusterData) {
+
+ ApplicationTerminatedEvent applicationTerminatedEvent =
+ new ApplicationTerminatedEvent(appId, clusterData);
+ publishEvent(applicationTerminatedEvent);
+ }
+
public static void publishEvent(Event event) {
//publishing events to application status topic
EventPublisher eventPublisher = EventPublisherPool.getPublisher(Constants.APPLICATION_STATUS_TOPIC);
http://git-wip-us.apache.org/repos/asf/stratos/blob/684d71f7/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/checker/StatusChecker.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/checker/StatusChecker.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/checker/StatusChecker.java
index 34388b8..9b39c5a 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/checker/StatusChecker.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/checker/StatusChecker.java
@@ -276,6 +276,7 @@ public class StatusChecker {
if (parent instanceof Application) {
//send application activated event
log.info("sending app terminated: " + appId);
+ StatusEventPublisher.sendApplicationTerminatedEvent(appId, parent.getClusterDataRecursively());
//StatusEventPublisher.sendApp(appId);
} else if (parent instanceof Group) {
//send activation to the parent
http://git-wip-us.apache.org/repos/asf/stratos/blob/684d71f7/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java
index d8bf319..68c96d4 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java
@@ -26,6 +26,7 @@ import org.apache.stratos.cloud.controller.pojo.*;
import org.apache.stratos.cloud.controller.pojo.Cartridge;
import org.apache.stratos.cloud.controller.pojo.payload.MetaDataHolder;
import org.apache.stratos.cloud.controller.publisher.CartridgeInstanceDataPublisher;
+import org.apache.stratos.cloud.controller.registry.RegistryManager;
import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
import org.apache.stratos.cloud.controller.util.CloudControllerUtil;
import org.apache.stratos.messaging.domain.topology.*;
@@ -39,6 +40,7 @@ import org.apache.stratos.messaging.event.topology.MemberActivatedEvent;
import org.apache.stratos.messaging.event.topology.MemberMaintenanceModeEvent;
import org.apache.stratos.messaging.event.topology.MemberReadyToShutdownEvent;
import org.apache.stratos.messaging.util.Constants;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
import java.util.*;
import java.util.Properties;
@@ -730,54 +732,6 @@ public class TopologyBuilder {
}
TopologyEventPublisher.sendApplicationUndeployedEvent(applicationId, clusterData);
-
-
-// Topology topology = TopologyManager.getTopology();
-//
-// try {
-// TopologyManager.acquireWriteLock();
-//
-// if (!topology.applicationExists(applicationId)) {
-// log.warn("Application with id [ " + applicationId + " ] doesn't exist in Topology");
-// //TopologyEventPublisher.sendApplicationRemovedEvent(applicationId, tenantId, tenantDomain);
-//
-// } else {
-// Application application = topology.getApplication(applicationId);
-// Set<ClusterDataHolder> clusterData = application.getClusterDataRecursively();
-// // remove clusters
-// for (ClusterDataHolder clusterDataHolder : clusterData) {
-// Service service = topology.getService(clusterDataHolder.getServiceType());
-// if (service != null) {
-// // remove Cluster
-// service.removeCluster(clusterDataHolder.getClusterId());
-//
-// if (log.isDebugEnabled()) {
-// log.debug("Removed cluster with id " + clusterDataHolder.getClusterId());
-// }
-// } else {
-// log.warn("Unable to remove cluster with cluster id: " + clusterDataHolder.getClusterId() + " from Topology, " +
-// " associated Service [ " + clusterDataHolder.getServiceType() + " ] npt found");
-// }
-//
-// // remove runtime data
-// dataHolder.removeClusterContext(clusterDataHolder.getClusterId());
-// if(log.isDebugEnabled()) {
-// log.debug("Removed Cluster Context for Cluster id: " + clusterDataHolder.getClusterId());
-// }
-// }
-//
-// // remove application
-// topology.removeApplication(applicationId);
-// TopologyManager.updateTopology(topology);
-//
-// log.info("Removed application [ " + applicationId + " ] from Topology");
-//
-// TopologyEventPublisher.sendApplicationRemovedEvent(applicationId, clusterData, tenantId, tenantDomain);
-// }
-//
-// } finally {
-// TopologyManager.releaseWriteLock();
-// }
}
public static void handleCompositeApplicationCreated(ConfigCompositeApplication messConfigApp) {
@@ -986,28 +940,86 @@ public class TopologyBuilder {
}
public static void handleApplicationTerminatedEvent(ApplicationTerminatedEvent event) {
- Topology topology = TopologyManager.getTopology();
- Application application = topology.getApplication(event.getAppId());
- //update the status of the Group
- if (application == null) {
- log.warn(String.format("Application %s does not exist",
- event.getAppId()));
- return;
- }
+// Topology topology = TopologyManager.getTopology();
+// Application application = topology.getApplication(event.getAppId());
+// //update the status of the Group
+// if (application == null) {
+// log.warn(String.format("Application %s does not exist",
+// event.getAppId()));
+// return;
+// }
+//
+// org.apache.stratos.messaging.event.topology.ApplicationTerminatedEvent applicationTerminatedEvent =
+// new org.apache.stratos.messaging.event.topology.ApplicationTerminatedEvent(
+// event.getAppId());
+// try {
+// TopologyManager.acquireWriteLock();
+// application.setStatus(ApplicationStatus.Terminated);
+// log.info("Application terminated adding status started for Topology");
+//
+// TopologyManager.updateTopology(topology);
+// } finally {
+// TopologyManager.releaseWriteLock();
+// }
+// //publishing data
+// TopologyEventPublisher.sendApplicationTerminatedEvent(applicationTerminatedEvent);
+
+
+ Topology topology = TopologyManager.getTopology();
- org.apache.stratos.messaging.event.topology.ApplicationTerminatedEvent applicationTerminatedEvent =
- new org.apache.stratos.messaging.event.topology.ApplicationTerminatedEvent(
- event.getAppId());
try {
TopologyManager.acquireWriteLock();
- application.setStatus(ApplicationStatus.Terminated);
- log.info("Application terminated adding status started for Topology");
- TopologyManager.updateTopology(topology);
+ if (!topology.applicationExists(event.getAppId())) {
+ log.warn("Application with id [ " + event.getAppId() + " ] doesn't exist in Topology");
+ //TopologyEventPublisher.sendApplicationRemovedEvent(applicationId, tenantId, tenantDomain);
+
+ } else {
+ Application application = topology.getApplication(event.getAppId());
+ int tenantId = application.getTenantId();
+ String tenantDomain = application.getTenantDomain();
+ Set<ClusterDataHolder> clusterData = application.getClusterDataRecursively();
+ // remove clusters
+ for (ClusterDataHolder clusterDataHolder : clusterData) {
+ Service service = topology.getService(clusterDataHolder.getServiceType());
+ if (service != null) {
+ // remove Cluster
+ service.removeCluster(clusterDataHolder.getClusterId());
+
+ if (log.isDebugEnabled()) {
+ log.debug("Removed cluster with id " + clusterDataHolder.getClusterId());
+ }
+ } else {
+ log.warn("Unable to remove cluster with cluster id: " + clusterDataHolder.getClusterId() + " from Topology, " +
+ " associated Service [ " + clusterDataHolder.getServiceType() + " ] npt found");
+ }
+
+ // remove runtime data
+ FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder.getInstance();
+ dataHolder.removeClusterContext(clusterDataHolder.getClusterId());
+ if(log.isDebugEnabled()) {
+ log.debug("Removed Cluster Context for Cluster id: " + clusterDataHolder.getClusterId());
+ }
+
+ try {
+ RegistryManager.getInstance().persist(dataHolder);
+ } catch (RegistryException e) {
+ log.error("Unable to persist data in Registry", e);
+ }
+ }
+
+ // remove application
+ topology.removeApplication(event.getAppId());
+ TopologyManager.updateTopology(topology);
+
+ log.info("Removed application [ " + event.getAppId() + " ] from Topology");
+
+ TopologyEventPublisher.sendApplicationRemovedEvent(event.getAppId(),
+ clusterData, tenantId, tenantDomain);
+ }
+
} finally {
TopologyManager.releaseWriteLock();
}
- //publishing data
- TopologyEventPublisher.sendApplicationTerminatedEvent(applicationTerminatedEvent);
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/684d71f7/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/ApplicationStatus.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/ApplicationStatus.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/ApplicationStatus.java
index 6ca8e27..cda6196 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/ApplicationStatus.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/ApplicationStatus.java
@@ -37,13 +37,15 @@ public enum ApplicationStatus implements LifeCycleState {
Active (1) {
@Override
public Set<LifeCycleState> getNextStates() {
- return new HashSet<LifeCycleState>(Arrays.asList(ApplicationStatus.Inactive));
+ return new HashSet<LifeCycleState>(Arrays.asList(ApplicationStatus.Terminating,
+ ApplicationStatus.Inactive));
}
},
Inactive (2) {
@Override
public Set<LifeCycleState> getNextStates() {
- return new HashSet<LifeCycleState>(Arrays.asList(ApplicationStatus.Terminating));
+ return new HashSet<LifeCycleState>(Arrays.asList(ApplicationStatus.Active,
+ ApplicationStatus.Terminating));
}
},
Terminating (3) {
http://git-wip-us.apache.org/repos/asf/stratos/blob/684d71f7/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Cluster.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Cluster.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Cluster.java
index 06d408c..e990903 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Cluster.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Cluster.java
@@ -50,7 +50,7 @@ public class Cluster implements Serializable, LifeCycleStateTransitionBehavior<C
@XmlJavaTypeAdapter(MapAdapter.class)
private Map<String, Member> memberMap;
- private ClusterStatus status;
+ //private ClusterStatus status;
private String appId;
@@ -70,7 +70,7 @@ public class Cluster implements Serializable, LifeCycleStateTransitionBehavior<C
this.appId = appId;
this.clusterStateManager = new LifeCycleStateManager<ClusterStatus>(ClusterStatus.Created);
// temporary; should be removed
- this.status = ClusterStatus.Created;
+ //this.status = ClusterStatus.Created;
}
public String getServiceName() {
@@ -250,12 +250,12 @@ public class Cluster implements Serializable, LifeCycleStateTransitionBehavior<C
return appId;
}
- public ClusterStatus getTempStatus() {
- return status;
- }
-
- public void setTempStatus(ClusterStatus status) {
- this.status = status;
- }
+// public ClusterStatus getTempStatus() {
+// return status;
+// }
+//
+// public void setTempStatus(ClusterStatus status) {
+// this.status = status;
+// }
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/684d71f7/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/application/status/ApplicationTerminatedEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/application/status/ApplicationTerminatedEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/application/status/ApplicationTerminatedEvent.java
index 27f7041..5151501 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/application/status/ApplicationTerminatedEvent.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/application/status/ApplicationTerminatedEvent.java
@@ -18,7 +18,10 @@
*/
package org.apache.stratos.messaging.event.application.status;
+import org.apache.stratos.messaging.domain.topology.ClusterDataHolder;
+
import java.io.Serializable;
+import java.util.Set;
/**
* This event will be fired upon the application terminated is detected.
@@ -27,12 +30,18 @@ public class ApplicationTerminatedEvent extends StatusEvent implements Serializa
private static final long serialVersionUID = 2625412714611885089L;
private String appId;
+ private Set<ClusterDataHolder> clusterData;
- public ApplicationTerminatedEvent(String appId) {
+ public ApplicationTerminatedEvent(String appId, Set<ClusterDataHolder> clusterData) {
this.appId = appId;
+ this.clusterData = clusterData;
}
public String getAppId() {
return appId;
}
+
+ public Set<ClusterDataHolder> getClusterData() {
+ return clusterData;
+ }
}