stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From isu...@apache.org
Subject git commit: bringing back alias based Startup Order conversion
Date Thu, 09 Oct 2014 09:46:33 GMT
Repository: stratos
Updated Branches:
  refs/heads/4.0.0-grouping a13091a6c -> f11401a34


bringing back alias based Startup Order conversion


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

Branch: refs/heads/4.0.0-grouping
Commit: f11401a342ec74e17fd6dc8dcf3c4d6477e221bf
Parents: a13091a
Author: Isuru Haththotuwa <isuruh@apache.org>
Authored: Thu Oct 9 15:12:54 2014 +0530
Committer: Isuru Haththotuwa <isuruh@apache.org>
Committed: Thu Oct 9 15:16:20 2014 +0530

----------------------------------------------------------------------
 .../grouping/dependency/DependencyBuilder.java  | 73 ++++++++---------
 .../parser/DefaultApplicationParser.java        |  5 +-
 .../application/parser/ParserUtils.java         | 83 ++++++++++----------
 .../cloud/controller/pojo/StartupOrder.java     | 50 ------------
 .../pojo/application/StartupOrderContext.java   | 47 -----------
 .../domain/topology/DependencyOrder.java        | 22 ++----
 .../messaging/domain/topology/StartupOrder.java | 20 +----
 7 files changed, 88 insertions(+), 212 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/f11401a3/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyBuilder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyBuilder.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyBuilder.java
index 5a1e4fd..30709e7 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyBuilder.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/grouping/dependency/DependencyBuilder.java
@@ -82,8 +82,8 @@ public class DependencyBuilder {
             }
 
             //Parsing the start up order
-            String [] startupOrders = dependencyOrder.getStartupOrders();
-            ApplicationContext foundContext = null; 
+            Set<StartupOrder> startupOrders = dependencyOrder.getStartupOrders();
+            ApplicationContext foundContext;
             if (startupOrders == null) {
             	if (log.isDebugEnabled()) {
                     log.debug("startupOrders is null, returning default dependency tree (empty)");
@@ -91,46 +91,49 @@ public class DependencyBuilder {
             	
             	return dependencyTree;
             }
-            for (String startupOrder : startupOrders) {
-            	String start = dependencyOrder.getStartStartupOrder(startupOrder);
+            for (StartupOrder startupOrder : startupOrders) {
+
                 foundContext = null;
-                
-                if (start != null) {
-                    ApplicationContext applicationContext = ApplicationContextFactory.
-                                    getApplicationContext(start, component,
-                                                            dependencyTree.isKillDependent());
-                    String id = applicationContext.getId();
-
-                    ApplicationContext existingApplicationContext =
-                            dependencyTree.findApplicationContextWithId(id);
-                    if (existingApplicationContext == null) {
-                        if (foundContext != null) {
-                            //appending the start up order to existing group/cluster
-                            foundContext.addApplicationContext(applicationContext);
-                            if (log.isDebugEnabled()) {
-                                log.debug("Found an existing [dependency] " + foundContext.getId()
+
-                                        " and adding the [dependency] " + id + " as the child");
+
+                for (String start : startupOrder.getStartList())  {
+
+                    if (start != null) {
+                        ApplicationContext applicationContext = ApplicationContextFactory.
+                                getApplicationContext(start, component, dependencyTree.isKillDependent());
+                        String id = applicationContext.getId(); //TODO change the id
+
+                        ApplicationContext existingApplicationContext =
+                                dependencyTree.findApplicationContextWithId(id);
+                        if (existingApplicationContext == null) {
+                            if (foundContext != null) {
+                                //appending the start up order to existing group/cluster
+                                foundContext.addApplicationContext(applicationContext);
+                                if (log.isDebugEnabled()) {
+                                    log.debug("Found an existing [dependency] " + foundContext.getId()
+
+                                            " and adding the [dependency] " + id + " as the
child");
+                                }
+                            } else {
+                                //adding list of startup order to the dependency tree
+                                dependencyTree.addApplicationContext(applicationContext);
                             }
                         } else {
-                            //adding list of startup order to the dependency tree
-                            dependencyTree.addApplicationContext(applicationContext);
-                        }
-                    } else {
-                        if (foundContext == null) {
-                            //assigning the found context to the later use.
-                            foundContext = existingApplicationContext;
-                            if (log.isDebugEnabled()) {
-                                log.debug("Found an existing [dependency] " + id + " and
setting it " +
-                                        "for the next dependency to follow");
+                            if (foundContext == null) {
+                                //assigning the found context to the later use.
+                                foundContext = existingApplicationContext;
+                                if (log.isDebugEnabled()) {
+                                    log.debug("Found an existing [dependency] " + id + "
and setting it " +
+                                            "for the next dependency to follow");
+                                }
+                            } else {
+                                String msg = "Startup order is not consistent. It contains
the group/cluster " +
+                                        "which has been used more than one in another startup
order";
+                                throw new DependencyBuilderException(msg);
                             }
-                        } else {
-                            String msg = "Startup order is not consistent. It contains the
group/cluster " +
-                                    "which has been used more than one in another startup
order";
-                            throw new DependencyBuilderException(msg);
-                        }
 
+                        }
                     }
                 }
+
             }
             //TODO need to parser the scalable dependencies
         }

http://git-wip-us.apache.org/repos/asf/stratos/blob/f11401a3/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/parser/DefaultApplicationParser.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/parser/DefaultApplicationParser.java
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/parser/DefaultApplicationParser.java
index efeccd7..9d909ca 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/parser/DefaultApplicationParser.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/parser/DefaultApplicationParser.java
@@ -34,7 +34,6 @@ import org.apache.stratos.cloud.controller.pojo.application.*;
 import org.apache.stratos.cloud.controller.pojo.payload.MetaDataHolder;
 import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
 import org.apache.stratos.messaging.domain.topology.*;
-import org.apache.stratos.messaging.domain.topology.StartupOrder;
 
 import java.util.*;
 
@@ -274,7 +273,7 @@ public class DefaultApplicationParser implements ApplicationParser {
                     	log.debug("parsing application ... buildCompositeAppStructure: startupOrders
!= null for app alias: " + 
                     				appCtxt.getAlias() + " #: " + startupOrders.length);
                     }
-                    appDependencyOrder.setStartupOrders(startupOrders);
+                    appDependencyOrder.setStartupOrders(ParserUtils.convert(startupOrders));
                 } else {
                 	if (log.isDebugEnabled()) {
                     	log.debug("parsing application ... buildCompositeAppStructure: startupOrders
== null for app alias: " + appCtxt.getAlias());
@@ -401,7 +400,7 @@ public class DefaultApplicationParser implements ApplicationParser {
         // create the Dependency Ordering
         String []  startupOrders = getStartupOrderForGroup(groupCtxt);
         if (startupOrders != null) {
-            dependencyOrder.setStartupOrders(startupOrders);
+            dependencyOrder.setStartupOrders(ParserUtils.convert(startupOrders, groupCtxt));
         }
         dependencyOrder.setKillbehavior(getKillbehaviour(groupCtxt.getName()));
         group.setDependencyOrder(dependencyOrder);

http://git-wip-us.apache.org/repos/asf/stratos/blob/f11401a3/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/parser/ParserUtils.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/parser/ParserUtils.java
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/parser/ParserUtils.java
index 707fd0a..62a98ab 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/parser/ParserUtils.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/parser/ParserUtils.java
@@ -23,13 +23,11 @@ import org.apache.stratos.cloud.controller.pojo.application.GroupContext;
 import org.apache.stratos.cloud.controller.pojo.application.SubscribableContext;
 import org.apache.stratos.messaging.domain.topology.StartupOrder;
 
-import java.util.HashSet;
-import java.util.Set;
+import java.util.*;
 
 public class ParserUtils {
 
-	/*
-    public static Set<StartupOrder> convert (org.apache.stratos.cloud.controller.pojo.StartupOrder
[] startupOrderArr, GroupContext groupContext) {
+    public static Set<StartupOrder> convert (String [] startupOrderArr) {
 
         Set<StartupOrder> startupOrders = new HashSet<StartupOrder>();
 
@@ -37,65 +35,66 @@ public class ParserUtils {
             return startupOrders;
         }
 
+        for (String commaSeparatedStartupOrder : startupOrderArr) {
+            startupOrders.add(new StartupOrder(Arrays.asList(commaSeparatedStartupOrder.split(","))));
+        }
+
+        return startupOrders;
+    }
+
+    public static Set<StartupOrder> convert (String [] startupOrderArr, GroupContext
groupContext) {
+
+        Set<StartupOrder> startupOrders = new HashSet<StartupOrder>();
 
-        for (int i = 0; i < startupOrderArr.length ; i++) {
+        if (startupOrderArr == null) {
+            return startupOrders;
+        }
+
+
+        for (String commaSeparatedStartupOrder : startupOrderArr) {
             // convert all Startup Orders to aliases-based
-            // start
-            String startAlias;
-            if (startupOrderArr[i].getStart().startsWith("cartridge.")) {
-                String cartridgeType = startupOrderArr[i].getStart().substring(10);
-                startAlias = getAliasForServiceType(cartridgeType, groupContext);
-                if (startAlias == null) {
-                    throw new RuntimeException("Unable convert Startup Order to alias-based;
" +
-                            "cannot find the matching alias for Service type " + cartridgeType);
-                }
+            List<String> components = Arrays.asList(commaSeparatedStartupOrder.split(","));
+            startupOrders.add(getStartupOrder(components, groupContext));
+        }
 
-                startAlias = "cartridge.".concat(startAlias);
+        return startupOrders;
+    }
 
-            } else if (startupOrderArr[i].getStart().startsWith("group."))  {
-                String groupName = startupOrderArr[i].getStart().substring(6);
-                startAlias = getAliasForGroupName(groupName, groupContext);
-                if (startAlias == null) {
-                    throw new RuntimeException("Unable convert Startup Order to alias-based;
" +
-                            "cannot find the matching alias for Group name " + groupName);
-                }
+    private static StartupOrder getStartupOrder (List<String> components, GroupContext
groupContext) {
 
-                startAlias = "group.".concat(startAlias);
+        List<String> aliasBasedComponents = new ArrayList<String>();
 
-            } else {
-                throw new RuntimeException("Incorrect Startup Order specified");
-            }
+        for (String component : components) {
+            component = component.trim();
 
-            // after
-            String afterAlias;
-            if (startupOrderArr[i].getAfter().startsWith("cartridge.")) {
-                String cartridgeType = startupOrderArr[i].getAfter().substring(10);
-                afterAlias = getAliasForServiceType(cartridgeType, groupContext);
-                if (afterAlias == null) {
+            String aliasBasedComponent;
+            if (component.startsWith("cartridge.")) {
+                String cartridgeType = component.substring(10);
+                aliasBasedComponent = getAliasForServiceType(cartridgeType, groupContext);
+                if (aliasBasedComponent == null) {
                     throw new RuntimeException("Unable convert Startup Order to alias-based;
" +
                             "cannot find the matching alias for Service type " + cartridgeType);
                 }
 
-                afterAlias = "cartridge.".concat(afterAlias);
+                aliasBasedComponent = "cartridge.".concat(aliasBasedComponent);
 
-            } else if (startupOrderArr[i].getAfter().startsWith("group."))  {
-                String groupName = startupOrderArr[i].getAfter().substring(6);
-                afterAlias = getAliasForGroupName(groupName, groupContext);
-                if (afterAlias == null) {
+            } else if (component.startsWith("group.")) {
+                String groupName = component.substring(6);
+                aliasBasedComponent = getAliasForGroupName(groupName, groupContext);
+                if (aliasBasedComponent == null) {
                     throw new RuntimeException("Unable convert Startup Order to alias-based;
" +
                             "cannot find the matching alias for Group name " + groupName);
                 }
 
-                afterAlias = "group.".concat(afterAlias);
+                aliasBasedComponent = "group.".concat(aliasBasedComponent);
 
             } else {
                 throw new RuntimeException("Incorrect Startup Order specified");
             }
-
-            startupOrders.add(new StartupOrder(startAlias, afterAlias));
+            aliasBasedComponents.add(aliasBasedComponent);
         }
 
-        return startupOrders;
+        return new StartupOrder(aliasBasedComponents);
     }
 
     private static String getAliasForGroupName (String groupName, GroupContext groupContext)
{
@@ -109,7 +108,7 @@ public class ParserUtils {
         return null;
     }
 
-*/
+
     private static String getAliasForServiceType (String serviceType, GroupContext groupContext)
{
 
         for (SubscribableContext subCtxt : groupContext.getSubscribableContexts()) {

http://git-wip-us.apache.org/repos/asf/stratos/blob/f11401a3/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/StartupOrder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/StartupOrder.java
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/StartupOrder.java
deleted file mode 100644
index ed9626b..0000000
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/StartupOrder.java
+++ /dev/null
@@ -1,50 +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.stratos.cloud.controller.pojo;
-
-import java.io.Serializable;
-
-public class StartupOrder implements Serializable {
-
-	private static final long serialVersionUID = 280860334002791396L;
-	
-	/*
-
-	private String start;
-
-    private String after;
-
-    public String getStart() {
-        return start;
-    }
-
-    public void setStart(String start) {
-        this.start = start;
-    }
-
-    public String getAfter() {
-        return after;
-    }
-
-    public void setAfter(String after) {
-        this.after = after;
-    }
-    */
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/f11401a3/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/application/StartupOrderContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/application/StartupOrderContext.java
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/application/StartupOrderContext.java
deleted file mode 100644
index 3c2a2da..0000000
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/application/StartupOrderContext.java
+++ /dev/null
@@ -1,47 +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.stratos.cloud.controller.pojo.application;
-
-public class StartupOrderContext {
-
-    private String start;
-
-    private String after;
-
-    public StartupOrderContext () {
-
-    }
-
-    public String getStart() {
-        return start;
-    }
-
-    public void setStart(String start) {
-        this.start = start;
-    }
-
-    public String getAfter() {
-        return after;
-    }
-
-    public void setAfter(String after) {
-        this.after = after;
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/f11401a3/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/DependencyOrder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/DependencyOrder.java
b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/DependencyOrder.java
index ff08a4c..1d8699f 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/DependencyOrder.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/DependencyOrder.java
@@ -21,21 +21,19 @@ package org.apache.stratos.messaging.domain.topology;
 
 import java.io.Serializable;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 public class DependencyOrder implements Serializable {
 
-    /**
-	 * 
-	 */
 	private static final long serialVersionUID = -599600831844477527L;
 
-	private String [] startupOrders;
+	private Set<StartupOrder> startupOrders;
 
     private String killbehavior;
 
     public DependencyOrder () {
-        this.setStartupOrders(null);
+
     }
 
     public String getKillbehavior() {
@@ -46,21 +44,11 @@ public class DependencyOrder implements Serializable {
         this.killbehavior = killbehavior;
     }
 
-	public String [] getStartupOrders() {
+	public Set<StartupOrder> getStartupOrders() {
 		return startupOrders;
 	}
 
-	public void setStartupOrders(String [] startupOrders) {
+	public void setStartupOrders(Set<StartupOrder> startupOrders) {
 		this.startupOrders = startupOrders;
 	}
-	
-	public String getStartStartupOrder(String startupOrder) {
-		String [] splitStartupOrder = startupOrder.split(",");
-		return splitStartupOrder[0];
-	}
-	
-	public String getAfterStartupOrder(String startupOrder) {
-		String [] splitStartupOrder = startupOrder.split(",");
-		return splitStartupOrder[1];
-	}
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/f11401a3/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/StartupOrder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/StartupOrder.java
b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/StartupOrder.java
index 6263070..4f55b6c 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/StartupOrder.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/StartupOrder.java
@@ -23,26 +23,11 @@ import java.io.Serializable;
 import java.util.List;
 
 public class StartupOrder implements Serializable {
-	
-	/*
-
-    private String start;
-
-    private String after;
 
     private List<String> startList;
 
-    public StartupOrder (String start, String after) {
-        this.start = start;
-        this.after = after;
-    }
-
-    public String getStart() {
-        return start;
-    }
-
-    public String getAfter() {
-        return after;
+    public StartupOrder (List<String> startList) {
+        this.startList = startList;
     }
 
     public List<String> getStartList() {
@@ -52,5 +37,4 @@ public class StartupOrder implements Serializable {
     public void setStartList(List<String> startList) {
         this.startList = startList;
     }
-    */
 }


Mime
View raw message