Repository: stratos
Updated Branches:
  refs/heads/master 4ed5e0040 -> c9bcd6ef5


adding network partition support for application monitor


Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/c9bcd6ef
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/c9bcd6ef
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/c9bcd6ef

Branch: refs/heads/master
Commit: c9bcd6ef5f056b99393e60e7c58a14633a96d21d
Parents: 4ed5e00
Author: reka <[email protected]>
Authored: Fri Nov 28 14:27:59 2014 +0530
Committer: reka <[email protected]>
Committed: Fri Nov 28 14:28:20 2014 +0530

----------------------------------------------------------------------
 ...ApplicationLevelNetworkPartitionContext.java |   8 ++
 .../ParentMonitorNotFoundException.java         |  56 ++++++++++
 .../monitor/ParentComponentMonitor.java         | 105 ++++++++++++++-----
 .../monitor/application/ApplicationMonitor.java |  43 ++++++--
 .../autoscaler/monitor/group/GroupMonitor.java  |   3 -
 5 files changed, 177 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/c9bcd6ef/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/network/ApplicationLevelNetworkPartitionContext.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/network/ApplicationLevelNetworkPartitionContext.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/network/ApplicationLevelNetworkPartitionContext.java
index a65b764..73d6555 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/network/ApplicationLevelNetworkPartitionContext.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/network/ApplicationLevelNetworkPartitionContext.java
@@ -32,6 +32,7 @@ import java.util.Map;
 public class ApplicationLevelNetworkPartitionContext extends 
NetworkPartitionContext implements Serializable {
     private static final Log log = 
LogFactory.getLog(ApplicationLevelNetworkPartitionContext.class);
     private final String id;
+    private boolean createdOnBurst;
 
     //group instances kept inside a partition
     private Map<String, ApplicationInstance> instanceIdToInstanceContextMap;
@@ -94,4 +95,11 @@ public class ApplicationLevelNetworkPartitionContext extends 
NetworkPartitionCon
         return id;
     }
 
+    public boolean isCreatedOnBurst() {
+        return createdOnBurst;
+    }
+
+    public void setCreatedOnBurst(boolean createdOnBurst) {
+        this.createdOnBurst = createdOnBurst;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/c9bcd6ef/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/ParentMonitorNotFoundException.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/ParentMonitorNotFoundException.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/ParentMonitorNotFoundException.java
new file mode 100644
index 0000000..d22dbaa
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/ParentMonitorNotFoundException.java
@@ -0,0 +1,56 @@
+/*
+ * 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.exception;
+
+/**
+ * This will throw when required monitor not found
+ */
+public class ParentMonitorNotFoundException extends Exception{
+    private static final long serialVersionUID = -9163807860189126883L;
+    private String message;
+
+    public ParentMonitorNotFoundException(final String message, final 
Exception exception) {
+
+        super(message, exception);
+        this.setMessage(message);
+
+    }
+
+    public ParentMonitorNotFoundException(final Exception exception) {
+
+        super(exception);
+
+    }
+
+    public ParentMonitorNotFoundException(final String msg) {
+
+        super(msg);
+        this.setMessage(msg);
+
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/c9bcd6ef/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java
index d7c3716..92e2a54 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java
@@ -32,10 +32,7 @@ import 
org.apache.stratos.autoscaler.applications.dependency.context.ClusterChil
 import 
org.apache.stratos.autoscaler.applications.dependency.context.GroupChildContext;
 import org.apache.stratos.autoscaler.applications.topic.ApplicationBuilder;
 import 
org.apache.stratos.autoscaler.event.publisher.ClusterStatusEventPublisher;
-import org.apache.stratos.autoscaler.exception.DependencyBuilderException;
-import org.apache.stratos.autoscaler.exception.PartitionValidationException;
-import org.apache.stratos.autoscaler.exception.PolicyValidationException;
-import org.apache.stratos.autoscaler.exception.TopologyInConsistentException;
+import org.apache.stratos.autoscaler.exception.*;
 import 
org.apache.stratos.autoscaler.monitor.application.ApplicationMonitorFactory;
 import org.apache.stratos.autoscaler.monitor.cluster.AbstractClusterMonitor;
 import org.apache.stratos.autoscaler.monitor.group.GroupMonitor;
@@ -94,6 +91,20 @@ public abstract class ParentComponentMonitor extends Monitor 
{
      * This will start the parallel dependencies at once from the top level.
      * it will get invoked when the monitor starts up only.
      */
+    public void startDependency(ParentComponent component, String instanceId)
+                                                            throws 
TopologyInConsistentException,
+                                                                    
ParentMonitorNotFoundException {
+        //start the first dependency
+        List<ApplicationChildContext> applicationContexts = 
this.startupDependencyTree.
+                getStarAbleDependencies();
+        startDependency(applicationContexts, instanceId);
+
+    }
+
+    /**
+     * This will start the parallel dependencies at once from the top level.
+     * it will get invoked when the monitor starts up only.
+     */
     public void startDependency(ParentComponent component) throws 
TopologyInConsistentException {
         //start the first dependency
         List<ApplicationChildContext> applicationContexts = 
this.startupDependencyTree.
@@ -101,7 +112,7 @@ public abstract class ParentComponentMonitor extends 
Monitor {
         Collection<Instance> contexts = 
component.getInstanceIdToInstanceContextMap().values();
         //traversing through all the Instance context and start them
         List<String> instanceIds = new ArrayList<String>();
-        for(Instance context : contexts) {
+        for (Instance context : contexts) {
             instanceIds.add(context.getInstanceId());
         }
         startDependency(applicationContexts, instanceIds);
@@ -135,7 +146,8 @@ public abstract class ParentComponentMonitor extends 
Monitor {
         //start the first dependency which went to terminated
         List<ApplicationChildContext> applicationContexts = 
this.startupDependencyTree.
                 getStarAbleDependenciesByTermination();
-        startDependency(applicationContexts, null);
+        //FIXME to create new instanceIds
+        //startDependency(applicationContexts, null);
 
     }
 
@@ -162,10 +174,10 @@ public abstract class ParentComponentMonitor extends 
Monitor {
             } else {
                 //starting a new instance of the child
                 Monitor monitor = 
aliasToActiveMonitorsMap.get(context.getId());
-                for(String instanceId : instanceIds) {
-                    if(context instanceof ClusterChildContext) {
+                for (String instanceId : instanceIds) {
+                    if (context instanceof ClusterChildContext) {
                         MonitorStatusEventBuilder.notifyChildCluster(monitor, 
ClusterStatus.Created, instanceId);
-                    } else if(context instanceof GroupChildContext) {
+                    } else if (context instanceof GroupChildContext) {
                         MonitorStatusEventBuilder.notifyChildGroup(monitor, 
GroupStatus.Created, instanceId);
                     }
                 }
@@ -177,6 +189,43 @@ public abstract class ParentComponentMonitor extends 
Monitor {
 
     }
 
+    /**
+     * To start the dependency of the given application contexts
+     *
+     * @param applicationContexts the found applicationContexts to be started
+     */
+    private boolean startDependency(List<ApplicationChildContext> 
applicationContexts, String instanceId)
+            throws ParentMonitorNotFoundException {
+        if (applicationContexts != null && applicationContexts.isEmpty()) {
+            //all the groups/clusters have been started and waiting for 
activation
+            log.info("There is no child found for the [group]: " + this.id);
+            return false;
+
+        }
+        for (ApplicationChildContext context : applicationContexts) {
+            if (log.isDebugEnabled()) {
+                log.debug("Dependency check for the Group " + context.getId() 
+ " started");
+            }
+            //FIXME whether to start new monitor or throw exception
+            if (!this.aliasToActiveMonitorsMap.containsKey(context.getId())) {
+                String msg = "Required Monitor cannot be fount in the 
hierarchy";
+                throw new ParentMonitorNotFoundException(msg);
+            } else {
+                //starting a new instance of the child
+                Monitor monitor = 
aliasToActiveMonitorsMap.get(context.getId());
+                if (context instanceof ClusterChildContext) {
+                    MonitorStatusEventBuilder.notifyChildCluster(monitor, 
ClusterStatus.Created, instanceId);
+                } else if (context instanceof GroupChildContext) {
+                    MonitorStatusEventBuilder.notifyChildGroup(monitor, 
GroupStatus.Created, instanceId);
+                }
+
+            }
+        }
+
+        return true;
+
+    }
+
     protected String generateInstanceId(ParentComponent component) {
         String instanceId = component.getUniqueIdentifier() + "_" +
                 (component.getInstanceContextCount() + 1);
@@ -498,6 +547,25 @@ public abstract class ParentComponentMonitor extends 
Monitor {
         this.terminatingMonitorsList = terminatingMonitorsList;
     }
 
+    public AutoscaleAlgorithm getAutoscaleAlgorithm(String partitionAlgorithm) 
{
+        AutoscaleAlgorithm autoscaleAlgorithm = null;
+        if (log.isDebugEnabled()) {
+            log.debug(String.format("Partition algorithm is ", 
partitionAlgorithm));
+        }
+        if (Constants.ROUND_ROBIN_ALGORITHM_ID.equals(partitionAlgorithm)) {
+
+            autoscaleAlgorithm = new RoundRobin();
+        } else if 
(Constants.ONE_AFTER_ANOTHER_ALGORITHM_ID.equals(partitionAlgorithm)) {
+
+            autoscaleAlgorithm = new OneAfterAnother();
+        } else {
+            if (log.isErrorEnabled()) {
+                log.error(String.format("Partition algorithm %s could not be 
identified !", partitionAlgorithm));
+            }
+        }
+        return autoscaleAlgorithm;
+    }
+
     private class MonitorAdder implements Runnable {
         private ApplicationChildContext context;
         private ParentComponentMonitor parent;
@@ -568,24 +636,5 @@ public abstract class ParentComponentMonitor extends 
Monitor {
         }
     }
 
-    public AutoscaleAlgorithm getAutoscaleAlgorithm(String partitionAlgorithm) 
{
-        AutoscaleAlgorithm autoscaleAlgorithm = null;
-        if (log.isDebugEnabled()) {
-            log.debug(String.format("Partition algorithm is ", 
partitionAlgorithm));
-        }
-        if (Constants.ROUND_ROBIN_ALGORITHM_ID.equals(partitionAlgorithm)) {
-
-            autoscaleAlgorithm = new RoundRobin();
-        } else if 
(Constants.ONE_AFTER_ANOTHER_ALGORITHM_ID.equals(partitionAlgorithm)) {
-
-            autoscaleAlgorithm = new OneAfterAnother();
-        } else {
-            if (log.isErrorEnabled()) {
-                log.error(String.format("Partition algorithm %s could not be 
identified !", partitionAlgorithm));
-            }
-        }
-        return autoscaleAlgorithm;
-    }
-
 
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/c9bcd6ef/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 81bb030..7bcb234 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
@@ -24,6 +24,7 @@ import 
org.apache.stratos.autoscaler.context.partition.network.ApplicationLevelN
 import org.apache.stratos.autoscaler.applications.ApplicationHolder;
 import org.apache.stratos.autoscaler.applications.topic.ApplicationBuilder;
 import org.apache.stratos.autoscaler.exception.DependencyBuilderException;
+import org.apache.stratos.autoscaler.exception.ParentMonitorNotFoundException;
 import org.apache.stratos.autoscaler.exception.PolicyValidationException;
 import org.apache.stratos.autoscaler.exception.TopologyInConsistentException;
 import org.apache.stratos.autoscaler.monitor.Monitor;
@@ -194,26 +195,54 @@ public class ApplicationMonitor extends 
ParentComponentMonitor {
         DeploymentPolicy deploymentPolicy = getDeploymentPolicy(application);
         String instanceId;
         for (PartitionGroup partitionGroup : 
deploymentPolicy.getPartitionGroups()) {
-            ApplicationLevelNetworkPartitionContext context =
-                            new 
ApplicationLevelNetworkPartitionContext(partitionGroup.getId());
-            instanceId = createApplicationInstance(application, 
partitionGroup.getId());
-            
context.addInstanceContext(application.getInstanceContexts(instanceId));
+            if(partitionGroup.isActiveByDefault()) {
+                ApplicationLevelNetworkPartitionContext context =
+                        new 
ApplicationLevelNetworkPartitionContext(partitionGroup.getId());
+                instanceId = createApplicationInstance(application, 
partitionGroup.getId());
+                
context.addInstanceContext(application.getInstanceContexts(instanceId));
 
-            this.networkPartitionCtxts.put(context.getId(), context);
+                this.networkPartitionCtxts.put(context.getId(), context);
+
+                instanceIds.add(instanceId);
+            }
 
-            instanceIds.add(instanceId);
         }
         startDependency(application, instanceIds);
 
 
     }
 
-    public void createInstanceOnBurstingForApplication() throws 
TopologyInConsistentException {
+    public void createInstanceOnBurstingForApplication() throws 
TopologyInConsistentException,
+                                                                
PolicyValidationException,
+                                                                
ParentMonitorNotFoundException {
         //TODO get lock
         Application application = 
ApplicationHolder.getApplications().getApplication(appId);
         if(application == null) {
             String msg = "Application cannot be found in the Topology.";
+            throw new TopologyInConsistentException(msg);
+        }
+        DeploymentPolicy deploymentPolicy = getDeploymentPolicy(application);
+        String instanceId = null;
+        //Find out the inActive network partition
+        boolean burstNPFound = false;
+        for (PartitionGroup partitionGroup : 
deploymentPolicy.getPartitionGroups()) {
+            if(!partitionGroup.isActiveByDefault()) {
+                ApplicationLevelNetworkPartitionContext context =
+                        new 
ApplicationLevelNetworkPartitionContext(partitionGroup.getId());
+                context.setCreatedOnBurst(true);
+                instanceId = createApplicationInstance(application, 
partitionGroup.getId());
+                
context.addInstanceContext(application.getInstanceContexts(instanceId));
+                this.networkPartitionCtxts.put(context.getId(), context);
+                burstNPFound = true;
+            }
         }
+
+        if(!burstNPFound) {
+            log.warn("[Application] " + appId + " cannot be burst as no 
available resources found");
+        } else {
+            startDependency(application, instanceId);
+        }
+
     }
 
     private DeploymentPolicy getDeploymentPolicy(Application application) 
throws PolicyValidationException {

http://git-wip-us.apache.org/repos/asf/stratos/blob/c9bcd6ef/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 6581e72..a487df6 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
@@ -304,9 +304,6 @@ public class GroupMonitor extends ParentComponentMonitor 
implements EventHandler
             }
             instanceId = createGroupInstance(group, parentInstanceId);
             instanceIds.add(instanceId);
-
-
-
         }
         startDependency(group, instanceIds);
     }

Reply via email to