more refactoring
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/572cbe32 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/572cbe32 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/572cbe32 Branch: refs/heads/docker-grouping-merge Commit: 572cbe329bfd8008df899919787ec0732c387b85 Parents: 16f9ec3 Author: Isuru Haththotuwa <[email protected]> Authored: Sun Nov 2 15:42:36 2014 +0530 Committer: Isuru Haththotuwa <[email protected]> Committed: Sun Nov 2 15:42:36 2014 +0530 ---------------------------------------------------------------------- .../applications/parser/ApplicationParser.java | 4 +- .../parser/DefaultApplicationParser.java | 10 +- .../applications/topic/ApplicationBuilder.java | 4 +- .../application/ApplicationUtils.java | 291 ----- .../application/ClusterInformation.java | 27 - .../application/MTClusterInformation.java | 45 - .../application/STClusterInformation.java | 55 - .../parser/DefaultApplicationParser.java | 634 ---------- .../application/parser/ParserUtils.java | 142 --- .../ApplicationCartridgePayloadData.java | 27 - .../application/payload/BasicPayloadData.java | 311 ----- .../payload/DataCartridgePayloadData.java | 27 - .../payload/FrameworkCartridgePayloadData.java | 27 - .../LoadBalancerCartridgePayloadData.java | 27 - .../application/payload/PayloadData.java | 69 -- .../application/payload/PayloadFactory.java | 59 - .../impl/CloudControllerServiceImpl.java | 50 +- .../interfaces/ApplicationParser.java | 53 - .../interfaces/CloudControllerService.java | 17 - .../pojo/application/ApplicationContext.java | 93 -- .../pojo/application/ComponentContext.java | 54 - .../pojo/application/DependencyContext.java | 44 - .../pojo/application/GroupContext.java | 84 -- .../pojo/application/SubscribableContext.java | 44 - .../application/SubscribableInfoContext.java | 103 -- .../controller/pojo/payload/MetaDataHolder.java | 99 -- .../CompositeApplicationParseTest.java | 1108 +++++++++--------- .../client/CloudControllerServiceClient.java | 17 - .../domain/applications/ClusterDataHolder.java | 1 - .../rest/endpoint/services/ServiceUtils.java | 1 - .../pom.xml | 3 +- .../main/resources/CloudControllerService.wsdl | 622 ++++------ 32 files changed, 826 insertions(+), 3326 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/572cbe32/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/ApplicationParser.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/ApplicationParser.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/ApplicationParser.java index 529c1f8..f1f59e5 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/ApplicationParser.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/ApplicationParser.java @@ -26,7 +26,9 @@ import org.apache.stratos.messaging.domain.applications.Application; import java.util.Set; - +/** + * Parses the Application Definition + */ public interface ApplicationParser { /** http://git-wip-us.apache.org/repos/asf/stratos/blob/572cbe32/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java index a2c8ce5..fa31385 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java @@ -40,12 +40,14 @@ import org.apache.stratos.messaging.domain.applications.Group; import java.util.*; +/** + * Default implementation of the Application Parser. One Application should be processed by one + * instance of the DefaultApplicationParser. + */ public class DefaultApplicationParser implements ApplicationParser { private static Log log = LogFactory.getLog(DefaultApplicationParser.class); -// private static FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder.getInstance(); - private Set<ApplicationClusterContext> applicationClusterContexts; public DefaultApplicationParser () { @@ -466,7 +468,7 @@ public class DefaultApplicationParser implements ApplicationParser { */ private String [] getStartupOrderForGroup(GroupContext groupContext) throws ApplicationDefinitionException { - ServiceGroup serviceGroup = null; + ServiceGroup serviceGroup; try { serviceGroup = RegistryManager.getInstance().getServiceGroup(groupContext.getName()); } catch (Exception e) { @@ -512,7 +514,7 @@ public class DefaultApplicationParser implements ApplicationParser { */ private String getKillbehaviour (String serviceGroupName) throws ApplicationDefinitionException { - ServiceGroup serviceGroup = null; + ServiceGroup serviceGroup; try { serviceGroup = RegistryManager.getInstance().getServiceGroup(serviceGroupName); } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/stratos/blob/572cbe32/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java index 07ddfb6..6adf3b1 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java @@ -143,8 +143,8 @@ public class ApplicationBuilder { ApplicationsEventPublisher.sendApplicationUndeployedEvent(applicationId, clusterData); }*/ - public static void handleApplicationCreated (Application application, - Set<ApplicationClusterContext> appClusterCtxts) { + public static synchronized void handleApplicationCreated (Application application, + Set<ApplicationClusterContext> appClusterContexts) { Applications applications = ApplicationHolder.getApplications(); http://git-wip-us.apache.org/repos/asf/stratos/blob/572cbe32/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/ApplicationUtils.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/ApplicationUtils.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/ApplicationUtils.java deleted file mode 100644 index 35600c4..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/ApplicationUtils.java +++ /dev/null @@ -1,291 +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.application; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.cloud.controller.application.payload.BasicPayloadData; -import org.apache.stratos.cloud.controller.application.payload.PayloadData; -import org.apache.stratos.cloud.controller.application.payload.PayloadFactory; -import org.apache.stratos.cloud.controller.exception.ApplicationDefinitionException; -import org.apache.stratos.cloud.controller.pojo.Cartridge; -import org.apache.stratos.cloud.controller.pojo.PortMapping; -import org.apache.stratos.cloud.controller.pojo.application.SubscribableContext; -import org.apache.stratos.cloud.controller.pojo.application.SubscribableInfoContext; -import org.apache.stratos.cloud.controller.pojo.payload.MetaDataHolder; - -import java.util.*; -import java.util.regex.Pattern; - -public class ApplicationUtils { - private static final Log log = LogFactory.getLog(ApplicationUtils.class); - - public static boolean isAliasValid (String alias) { - - String patternString = "([a-z0-9]+([-][a-z0-9])*)+"; - Pattern pattern = Pattern.compile(patternString); - - return pattern.matcher(alias).matches(); - } - - public static boolean isValid (String arg) { - - if (arg == null || arg.isEmpty()) { - return false; - } else { - return true; - } - } - - public static Properties getGlobalPayloadData () { - - Properties globalProperties = new Properties(); - - if (System.getProperty("puppet.ip") != null) { - globalProperties.setProperty("PUPPET_IP", System.getProperty("puppet.ip")); - } - if (System.getProperty("puppet.hostname") != null) { - globalProperties.setProperty("PUPPET_HOSTNAME", System.getProperty("puppet.hostname")); - } - if (System.getProperty("puppet.env") != null) { - globalProperties.setProperty("PUPPET_ENV", System.getProperty("puppet.env")); - } - if (System.getProperty("puppet.dns.available") != null) { - globalProperties.setProperty("PUPPET_DNS_AVAILABLE", System.getProperty("puppet.dns.available")); - } - - return globalProperties; - } - - public static MetaDataHolder getClusterLevelPayloadData (String appId, String groupName, int tenantId, String key, - String hostname, String tenantRange, String clusterId, - SubscribableContext subscribableCtxt, - SubscribableInfoContext subscribableInfoCtxt, - Cartridge cartridge) { - - MetaDataHolder metaDataHolder; - if (groupName != null) { - metaDataHolder = new MetaDataHolder(appId, groupName, clusterId); - } else { - metaDataHolder = new MetaDataHolder(appId, clusterId); - } - - Properties clusterLevelPayloadProperties = new Properties(); - // app id - clusterLevelPayloadProperties.setProperty("APP_ID", appId); - // group name - if (groupName != null) { - clusterLevelPayloadProperties.setProperty("GROUP_NAME", groupName); - } - // service name - if (subscribableCtxt.getType() != null) { - clusterLevelPayloadProperties.put("SERVICE_NAME", subscribableCtxt.getType()); - } - // host name - if (hostname != null) { - clusterLevelPayloadProperties.put("HOST_NAME", hostname); - } - // multi tenant - clusterLevelPayloadProperties.put("MULTITENANT", String.valueOf(cartridge.isMultiTenant())); - // tenant range - if (tenantRange != null) { - clusterLevelPayloadProperties.put("TENANT_RANGE", tenantRange); - } - // cartridge alias - if (subscribableCtxt.getAlias() != null) { - clusterLevelPayloadProperties.put("CARTRIDGE_ALIAS", subscribableCtxt.getAlias()); - } - // cluster id - if (clusterId != null) { - clusterLevelPayloadProperties.put("CLUSTER_ID", clusterId); - } - // repo url - if (subscribableInfoCtxt.getRepoUrl() != null) { - clusterLevelPayloadProperties.put("REPO_URL", subscribableInfoCtxt.getRepoUrl()); - } - // ports -// if (createPortMappingPayloadString(cartridge) != null) { -// clusterLevelPayloadProperties.put("PORTS", createPortMappingPayloadString(cartridge)); -// } - // provider - if (cartridge.getProvider() != null) { - clusterLevelPayloadProperties.put("PROVIDER", cartridge.getProvider()); - } - // tenant id - clusterLevelPayloadProperties.setProperty("TENANT_ID", String.valueOf(tenantId)); - // cartridge key - clusterLevelPayloadProperties.setProperty("CARTRIDGE_KEY", key); - // get global payload params - //clusterLevelPayloadProperties.putAll(ApplicationUtils.getGlobalPayloadData()); - - metaDataHolder.setProperties(clusterLevelPayloadProperties); - return metaDataHolder; - } - - private static String createPortMappingPayloadString (Cartridge cartridge) { - - // port mappings - StringBuilder portMapBuilder = new StringBuilder(); - List<PortMapping> portMappings = cartridge.getPortMappings(); - for (PortMapping portMapping : portMappings) { - String port = portMapping.getPort(); - portMapBuilder.append(port).append("|"); - } - - // remove last "|" character - String portMappingString = portMapBuilder.toString().replaceAll("\\|$", ""); - - return portMappingString; - } - - public static StringBuilder getTextPayload (String appId, String groupName, String clusterId) { - - StringBuilder payloadBuilder = new StringBuilder(); - payloadBuilder.append("APP_ID=" + appId); - if (groupName != null) { - payloadBuilder.append(","); - payloadBuilder.append("GROUP_NAME=" + groupName); - } - payloadBuilder.append(","); - payloadBuilder.append("CLUSTER_ID=" + clusterId); - // puppet related - if (System.getProperty("puppet.ip") != null) { - payloadBuilder.append(","); - payloadBuilder.append("PUPPET_IP=" + System.getProperty("puppet.ip")); - } - if (System.getProperty("puppet.hostname") != null) { - payloadBuilder.append(","); - payloadBuilder.append("PUPPET_HOSTNAME=" + System.getProperty("puppet.hostname")); - } - if (System.getProperty("puppet.env") != null) { - payloadBuilder.append(","); - payloadBuilder.append("PUPPET_ENV=" + System.getProperty("puppet.env")); - } - if (System.getProperty("puppet.dns.available") != null) { - payloadBuilder.append(","); - payloadBuilder.append("PUPPET_DNS_AVAILABLE=" + System.getProperty("puppet.dns.available")); - } - // meta data endpoint - // if (MetaDataClientConfig.getInstance().getMetaDataServiceBaseUrl() != null) { - // TODO - //payloadBuilder.append(","); - //payloadBuilder.append("METADATA_ENDPOINT=" + MetaDataClientConfig.getInstance().getMetaDataServiceBaseUrl()); - // } - payloadBuilder.append(","); - - return payloadBuilder; - } - - public static PayloadData createPayload(String appId, String groupName, Cartridge cartridge, String subscriptionKey, int tenantId, String clusterId, - String hostName, String repoUrl, String alias, Map<String, String> customPayloadEntries, String[] dependencyAliases) - throws ApplicationDefinitionException { - - //Create the payload - BasicPayloadData basicPayloadData = createBasicPayload(appId, groupName, cartridge, subscriptionKey, - clusterId, hostName, repoUrl, alias, tenantId, dependencyAliases); - //Populate the basic payload details - basicPayloadData.populatePayload(); - - PayloadData payloadData = PayloadFactory.getPayloadDataInstance(cartridge.getProvider(), - cartridge.getType(), basicPayloadData); - - boolean isDeploymentParam = false; - // get the payload parameters defined in the cartridge definition file for this cartridge type - if (cartridge.getProperties() != null && !cartridge.getProperties().isEmpty()) { - - for (Map.Entry<String, String> propertyEntry : cartridge.getProperties().entrySet()) { - // check if a property is related to the payload. Currently this is done by checking if the - // property name starts with 'payload_parameter.' suffix. If so the payload param name will - // be taken as the substring from the index of '.' to the end of the property name. - if (propertyEntry.getKey() - .startsWith("payload_parameter.")) { - String payloadParamName = propertyEntry.getKey(); - String payloadParamSubstring = payloadParamName.substring(payloadParamName.indexOf(".") + 1); - if("DEPLOYMENT".equals(payloadParamSubstring)) { - isDeploymentParam = true; - } - payloadData.add(payloadParamSubstring, propertyEntry.getValue()); - } - } - } - - // DEPLOYMENT payload param must be set because its used by puppet agent - // to generate the hostname. Therefore, if DEPLOYMENT is not set in cartridge properties, - // adding the DEPLOYMENT="default" param - if(!isDeploymentParam) { - payloadData.add("DEPLOYMENT", "default"); - } - //check if there are any custom payload entries defined - if (customPayloadEntries != null) { - //add them to the payload - Set<Map.Entry<String,String>> entrySet = customPayloadEntries.entrySet(); - for (Map.Entry<String, String> entry : entrySet) { - payloadData.add(entry.getKey(), entry.getValue()); - } - } - - return payloadData; - } - - private static BasicPayloadData createBasicPayload(String appId, String groupName, Cartridge cartridge, - String subscriptionKey, String clusterId, - String hostName, String repoUrl, String alias, - int tenantId, String[] dependencyAliases) { - - BasicPayloadData basicPayloadData = new BasicPayloadData(); - basicPayloadData.setAppId(appId); - basicPayloadData.setGroupName(groupName); - basicPayloadData.setApplicationPath(cartridge.getBaseDir()); - basicPayloadData.setSubscriptionKey(subscriptionKey); - //basicPayloadData.setDeployment("default");//currently hard coded to default - basicPayloadData.setMultitenant(String.valueOf(cartridge.isMultiTenant())); - basicPayloadData.setPortMappings(createPortMappingPayloadString(cartridge)); - basicPayloadData.setServiceName(cartridge.getType()); - basicPayloadData.setProvider(cartridge.getProvider()); - - if(repoUrl != null) { - basicPayloadData.setGitRepositoryUrl(repoUrl); - } - - if (clusterId != null) { - basicPayloadData.setClusterId(clusterId); - } - - if (hostName != null) { - basicPayloadData.setHostName(hostName); - } - - if (alias != null) { - basicPayloadData.setSubscriptionAlias(alias); - } - - basicPayloadData.setTenantId(tenantId); - - basicPayloadData.setTenantRange("*"); - basicPayloadData.setDependencyAliases(dependencyAliases); - if(cartridge.getExportingProperties() != null){ - basicPayloadData.setExportingProperties(cartridge.getExportingProperties()); - log.info("testing1 getExportingProperties " + cartridge.getExportingProperties()); - - } - - return basicPayloadData; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/572cbe32/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/ClusterInformation.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/ClusterInformation.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/ClusterInformation.java deleted file mode 100644 index 5fd6d57..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/ClusterInformation.java +++ /dev/null @@ -1,27 +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.application; - -public interface ClusterInformation { - - public String getClusterId (String alias, String cartridgeType); - - public String getHostName (String alias, String cartridgeDefinitionHostName); -} http://git-wip-us.apache.org/repos/asf/stratos/blob/572cbe32/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/MTClusterInformation.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/MTClusterInformation.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/MTClusterInformation.java deleted file mode 100644 index ef3b255..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/MTClusterInformation.java +++ /dev/null @@ -1,45 +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.application; - -public class MTClusterInformation implements ClusterInformation { - - @Override - public String getClusterId(String alias, String cartridgeType) { - - if (!ApplicationUtils.isValid(cartridgeType)) { - // cannot happen - throw new IllegalArgumentException("Invalid cartridge type value provided: [ " + cartridgeType + " ]"); - } - - return cartridgeType + ".domain"; - } - - @Override - public String getHostName(String alias, String cartridgeDefinitionHostName) { - - if (!ApplicationUtils.isValid(cartridgeDefinitionHostName)) { - // cannot happen - throw new IllegalArgumentException("Invalid host name value provided: [ " + cartridgeDefinitionHostName + " ]"); - } - - return cartridgeDefinitionHostName; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/572cbe32/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/STClusterInformation.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/STClusterInformation.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/STClusterInformation.java deleted file mode 100644 index c8c3d9b..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/STClusterInformation.java +++ /dev/null @@ -1,55 +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.application; - -public class STClusterInformation implements ClusterInformation { - - @Override - public String getClusterId(String alias, String cartridgeType) { - - if (!ApplicationUtils.isValid(alias)) { - // cannot happen - throw new IllegalArgumentException("Invalid alias value provided: [ " + alias + " ]"); - } - - if (!ApplicationUtils.isValid(cartridgeType)) { - // cannot happen - throw new IllegalArgumentException("Invalid cartridge type value provided: [ " + cartridgeType + " ]"); - } - - return alias + "." + cartridgeType + ".domain"; - } - - @Override - public String getHostName(String alias, String cartridgeDefinitionHostName) { - - if (!ApplicationUtils.isValid(alias)) { - // cannot happen - throw new IllegalArgumentException("Invalid alias value provided: [ " + alias + " ]"); - } - - if (!ApplicationUtils.isValid(cartridgeDefinitionHostName)) { - // cannot happen - throw new IllegalArgumentException("Invalid host name value provided: [ " + cartridgeDefinitionHostName + " ]"); - } - - return alias + "." + cartridgeDefinitionHostName; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/572cbe32/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 deleted file mode 100644 index c75e883..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/parser/DefaultApplicationParser.java +++ /dev/null @@ -1,634 +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.application.parser; - -import org.apache.commons.lang.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.cloud.controller.application.ApplicationUtils; -import org.apache.stratos.cloud.controller.application.ClusterInformation; -import org.apache.stratos.cloud.controller.application.MTClusterInformation; -import org.apache.stratos.cloud.controller.application.STClusterInformation; -import org.apache.stratos.cloud.controller.exception.ApplicationDefinitionException; -import org.apache.stratos.cloud.controller.interfaces.ApplicationParser; -import org.apache.stratos.cloud.controller.pojo.*; -import org.apache.stratos.cloud.controller.pojo.Cartridge; -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.applications.Application; -import org.apache.stratos.messaging.domain.applications.ClusterDataHolder; -import org.apache.stratos.messaging.domain.applications.DependencyOrder; -import org.apache.stratos.messaging.domain.applications.Group; - -import java.util.*; - -public class DefaultApplicationParser implements ApplicationParser { - - private static Log log = LogFactory.getLog(DefaultApplicationParser.class); - -// private static FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder.getInstance(); - - private Set<ApplicationClusterContext> applicationClusterContexts; - - private Set<MetaDataHolder> metaDataHolders; - - public DefaultApplicationParser () { - - this.applicationClusterContexts = new HashSet<ApplicationClusterContext>(); - this.metaDataHolders = new HashSet<MetaDataHolder>(); - } - - @Override - public Application parse(Object obj) throws ApplicationDefinitionException { - - ApplicationContext applicationCtxt = (ApplicationContext) obj; - - if (applicationCtxt == null) { - handleError("Invalid Composite Application Definition"); - } - - assert applicationCtxt != null; - if (applicationCtxt.getAlias() == null || applicationCtxt.getAlias().isEmpty()) { - handleError("Invalid alias specified"); - } - - if (applicationCtxt.getApplicationId() == null || applicationCtxt.getApplicationId().isEmpty()) { - handleError("Invalid Composite App id specified"); - } - - // get the defined groups - Map<String, GroupContext> definedGroups = getDefinedGroups(applicationCtxt); - if (log.isDebugEnabled()) { - if (definedGroups != null) { - Set<Map.Entry<String, GroupContext>> groupEntries = definedGroups.entrySet(); - log.debug("Defined Groups: [ "); - for (Map.Entry<String, GroupContext> groupEntry : groupEntries) { - log.debug("Group alias: " + groupEntry.getKey()); - } - log.debug(" ]"); - } else { - log.debug("No Group definitions found in app id " + applicationCtxt.getApplicationId()); - } - } - - // get the Subscribables Information - Map<String, SubscribableInfoContext> subscribablesInfo = getSubscribableInformation(applicationCtxt); - if (log.isDebugEnabled()) { - Set<Map.Entry<String, SubscribableInfoContext>> subscribableInfoCtxtEntries = subscribablesInfo.entrySet(); - log.debug("Defined Subscribable Information: [ "); - for (Map.Entry<String, SubscribableInfoContext> subscribableInfoCtxtEntry : subscribableInfoCtxtEntries) { - log.debug("Subscribable Information alias: " + subscribableInfoCtxtEntry.getKey()); - } - log.debug(" ]"); - } - - if (subscribablesInfo == null) { - handleError("Invalid Composite Application Definition, no Subscribable Information specified"); - } - - return buildCompositeAppStructure (applicationCtxt, definedGroups, subscribablesInfo); - } - - @Override - public Set<ApplicationClusterContext> getApplicationClusterContexts() throws ApplicationDefinitionException { - return applicationClusterContexts; - } - - @Override - public Set<MetaDataHolder> getPayloadData() throws ApplicationDefinitionException { - return metaDataHolders; - } - - /** - * Extract Group information from Application Definition - * - * @param appCtxt ApplicationContext object with Application information - * @return Map [group alias -> Group] - * - * @throws ApplicationDefinitionException if the Group information is invalid - */ - private Map<String, GroupContext> getDefinedGroups (ApplicationContext appCtxt) throws - ApplicationDefinitionException { - - // map [group alias -> Group Definition] - Map<String, GroupContext> definedGroups = null; - - if (appCtxt.getComponents() != null) { - if (appCtxt.getComponents().getGroupContexts() != null) { - definedGroups = new HashMap<String, GroupContext>(); - - for (GroupContext groupContext : appCtxt.getComponents().getGroupContexts()) { - - // check validity of group name - if (StringUtils.isEmpty(groupContext.getName())) { - handleError("Invalid Group name specified"); - } - - // check if group is deployed - if(!isGroupDeployed(groupContext.getName())) { - handleError("Group with name " + groupContext.getName() + " not deployed"); - } - - // check validity of group alias - - if (StringUtils.isEmpty(groupContext.getAlias()) || !ApplicationUtils.isAliasValid(groupContext.getAlias())) { - handleError("Invalid Group alias specified: [ " + groupContext.getAlias() + " ]"); - } - - // check if a group is already defined under the same alias - if(definedGroups.get(groupContext.getAlias()) != null) { - // a group with same alias already exists, can't continue - handleError("A Group with alias " + groupContext.getAlias() + " already exists"); - } - - definedGroups.put(groupContext.getAlias(), groupContext); - if (log.isDebugEnabled()) { - log.debug("Added Group Definition [ " + groupContext.getName() +" , " + groupContext.getAlias() + " ] to map [group alias -> Group Definition]"); - } - } - } - } - - return definedGroups; - } - - /** - * Extract Subscription Information from the Application Definition - * - * @param appCtxt ApplicationContext object with Application information - * @return Map [cartridge alias -> Group] - * - * @throws ApplicationDefinitionException if the Subscription information is invalid - */ - private Map<String, SubscribableInfoContext> getSubscribableInformation (ApplicationContext appCtxt) throws - ApplicationDefinitionException { - - // map [cartridge alias -> Subscribable Information] - Map<String, SubscribableInfoContext> subscribableInformation = null; - - if (appCtxt.getSubscribableInfoContext() != null) { - subscribableInformation = new HashMap<String, SubscribableInfoContext>(); - - for (SubscribableInfoContext subscribableInfoCtxt : appCtxt.getSubscribableInfoContext()) { - - if (StringUtils.isEmpty(subscribableInfoCtxt.getAlias()) || - !ApplicationUtils.isAliasValid(subscribableInfoCtxt.getAlias())) { - handleError("Invalid alias specified for Subscribable Information Obj: [ " + subscribableInfoCtxt.getAlias() + " ]"); - } - - // check if a group is already defined under the same alias - if(subscribableInformation.get(subscribableInfoCtxt.getAlias()) != null) { - // a group with same alias already exists, can't continue - handleError("A Subscribable Info obj with alias " + subscribableInfoCtxt.getAlias() + " already exists"); - } - - subscribableInformation.put(subscribableInfoCtxt.getAlias(), subscribableInfoCtxt); - if (log.isDebugEnabled()) { - log.debug("Added Subcribables Info obj [ " + subscribableInfoCtxt.getAlias() + " ] to map [cartridge alias -> Subscribable Information]"); - } - } - } - - return subscribableInformation; - } - - /** - * Check if a Group Definition is deployed - * - * @param serviceGroupName Group name - * @return true if the Group is deployed, else false - * - * @throws ApplicationDefinitionException - */ - private boolean isGroupDeployed (String serviceGroupName) throws ApplicationDefinitionException { - - return FasterLookUpDataHolder.getInstance().getServiceGroup(serviceGroupName) != null; - } - - /** - * Builds the Application structure - * - * @param appCtxt ApplicationContext object with Application information - * @param definedGroupCtxts Map [cartridge alias -> Group] with extracted Group Information - * @param subscribableInfoCtxts Map [cartridge alias -> Group] with extracted Subscription Information - * @return Application Application object denoting the Application structure - * - * @throws ApplicationDefinitionException If an error occurs in building the Application structure - */ - private Application buildCompositeAppStructure (ApplicationContext appCtxt, - Map<String, GroupContext> definedGroupCtxts, - Map<String, SubscribableInfoContext> subscribableInfoCtxts) - throws ApplicationDefinitionException { - - Application application = new Application(appCtxt.getApplicationId()); - - // set tenant related information - application.setTenantId(appCtxt.getTenantId()); - application.setTenantDomain(appCtxt.getTenantDomain()); - application.setTenantAdminUserName(appCtxt.getTeantAdminUsername()); - - // following keeps track of all Clusters created for this application - //Set<Cluster> clusters = new HashSet<Cluster>(); - //ClusterDataHolder clusterDataHolder = null; - Map<String, ClusterDataHolder> clusterDataMap; - - if (appCtxt.getComponents() != null) { - // get top level Subscribables - if (appCtxt.getComponents().getSubscribableContexts() != null) { - clusterDataMap = parseLeafLevelSubscriptions(appCtxt.getApplicationId(), appCtxt.getTenantId(), - application.getKey(), null, Arrays.asList(appCtxt.getComponents().getSubscribableContexts()), - subscribableInfoCtxts); - application.setClusterData(clusterDataMap); - //clusters.addAll(clusterDataHolder.getApplicationClusterContexts()); - } - - // get Groups - if (appCtxt.getComponents().getGroupContexts() != null) { - application.setGroups(parseGroups(appCtxt.getApplicationId(), appCtxt.getTenantId(), - application.getKey(), Arrays.asList(appCtxt.getComponents().getGroupContexts()), - subscribableInfoCtxts, definedGroupCtxts)); - } - - // get top level Dependency definitions - if (appCtxt.getComponents().getDependencyContext() != null) { - DependencyOrder appDependencyOrder = new DependencyOrder(); - String [] startupOrders = appCtxt.getComponents().getDependencyContext().getStartupOrdersContexts(); - if (startupOrders != null) { - if (log.isDebugEnabled()) { - log.debug("parsing application ... buildCompositeAppStructure: startupOrders != null for app alias: " + - appCtxt.getAlias() + " #: " + startupOrders.length); - } - appDependencyOrder.setStartupOrders(ParserUtils.convert(startupOrders)); - } else { - if (log.isDebugEnabled()) { - log.debug("parsing application ... buildCompositeAppStructure: startupOrders == null for app alias: " + appCtxt.getAlias()); - } - } - String terminationBehavior = appCtxt.getComponents().getDependencyContext().getTerminationBehaviour(); - validateTerminationBehavior(terminationBehavior); - appDependencyOrder.setTerminationBehaviour(terminationBehavior); - - application.setDependencyOrder(appDependencyOrder); - } - } - - log.info("Application with id " + appCtxt.getApplicationId() + " parsed successfully"); - - return application; - } - - /** - * Validates terminationBehavior. The terminationBehavior should be one of the following: - * 1. terminate-none - * 2. terminate-dependents - * 3. terminate-all - * - * @throws ApplicationDefinitionException if terminationBehavior is different to what is - * listed above - */ - private static void validateTerminationBehavior (String terminationBehavior) throws ApplicationDefinitionException { - - if (!(terminationBehavior == null || "terminate-none".equals(terminationBehavior) || - "terminate-dependents".equals(terminationBehavior) || "terminate-all".equals(terminationBehavior))) { - throw new ApplicationDefinitionException("Invalid Termination Behaviour specified: [ " + - terminationBehavior + " ], should be one of 'terminate-none', 'terminate-dependents', " + - " 'terminate-all' "); - } - } - - /** - * Parse Group information - * - * @param appId Application id - * @param tenantId tenant id of tenant which deployed the Application - * @param key Generated key for the Application - * @param groupCtxts Group information - * @param subscribableInformation Subscribable Information - * @param definedGroupCtxts Map [group alias -> Group] with extracted Group Information - * @return Map [alias -> Group] - * - * @throws ApplicationDefinitionException if an error occurs in parsing Group Information - */ - private Map<String, Group> parseGroups (String appId, int tenantId, String key, List<GroupContext> groupCtxts, - Map<String, SubscribableInfoContext> subscribableInformation, - Map<String, GroupContext> definedGroupCtxts) - throws ApplicationDefinitionException { - - Map<String, Group> groupAliasToGroup = new HashMap<String, Group>(); - - for (GroupContext groupCtxt : groupCtxts) { - Group group = parseGroup(appId, tenantId, key, groupCtxt, subscribableInformation, definedGroupCtxts); - groupAliasToGroup.put(group.getAlias(), group); - } - - //Set<GroupContext> topLevelGroupContexts = getTopLevelGroupContexts(groupAliasToGroup); - Set<Group> nestedGroups = new HashSet<Group>(); - getNestedGroupContexts(nestedGroups, groupAliasToGroup.values()); - filterDuplicatedGroupContexts(groupAliasToGroup.values(), nestedGroups); - - return groupAliasToGroup; - } - - /** - * Extracts nested Group information recursively - * - * @param nestedGroups Nested Groups set to be populated recursively - * @param groups Collection of Groups - */ - private void getNestedGroupContexts (Set<Group> nestedGroups, Collection<Group> groups) { - - if (groups != null) { - for (Group group : groups) { - if (group.getGroups() != null) { - nestedGroups.addAll(group.getGroups()); - getNestedGroupContexts(nestedGroups, group.getGroups()); - } - } - } - } - - /** - * Filters duplicated Groups from top level - * - * @param topLevelGroups Top level Groups - * @param nestedGroups nested Groups - */ - private void filterDuplicatedGroupContexts (Collection<Group> topLevelGroups, Set<Group> nestedGroups) { - - for (Group nestedGroup : nestedGroups) { - filterNestedGroupFromTopLevel(topLevelGroups, nestedGroup); - } - } - - private void filterNestedGroupFromTopLevel (Collection<Group> topLevelGroups, Group nestedGroup) { - - Iterator<Group> parentIterator = topLevelGroups.iterator(); - while (parentIterator.hasNext()) { - Group parentGroup = parentIterator.next(); - // if there is an exactly similar nested Group Context and a top level Group Context - // it implies that they are duplicates. Should be removed from top level. - if (parentGroup.equals(nestedGroup)) { - parentIterator.remove(); - } - } - } - - /** - * Parses an individual Group - * - * @param appId Application id - * @param tenantId tenant id of tenant which deployed the Application - * @param key Generated key for the Application - * @param groupCtxt Group definition information - * @param subscribableInfoCtxts Map [cartridge alias -> Group] with extracted Subscription Information - * @param definedGroupCtxts Map [group alias -> Group] with extracted Group Information - * @return Group object - * - * @throws ApplicationDefinitionException if unable to parse - */ - private Group parseGroup (String appId, int tenantId, String key, GroupContext groupCtxt, - Map<String, SubscribableInfoContext> subscribableInfoCtxts, - Map<String, GroupContext> definedGroupCtxts) - throws ApplicationDefinitionException { - - // check if are in the defined Group set - GroupContext definedGroupDef = definedGroupCtxts.get(groupCtxt.getAlias()); - if (definedGroupDef == null) { - handleError("Group Definition with name: " + groupCtxt.getName() + ", alias: " + - groupCtxt.getAlias() + " is not found in the all Group Definitions collection"); - } - - Group group = new Group(appId, groupCtxt.getName(), groupCtxt.getAlias()); - - group.setAutoscalingPolicy(groupCtxt.getAutoscalingPolicy()); - group.setDeploymentPolicy(groupCtxt.getDeploymentPolicy()); - DependencyOrder dependencyOrder = new DependencyOrder(); - // create the Dependency Ordering - String [] startupOrders = getStartupOrderForGroup(groupCtxt); - if (startupOrders != null) { - dependencyOrder.setStartupOrders(ParserUtils.convert(startupOrders, groupCtxt)); - } - dependencyOrder.setTerminationBehaviour(getKillbehaviour(groupCtxt.getName())); - group.setDependencyOrder(dependencyOrder); - - Map<String, ClusterDataHolder> clusterDataMap; - - // get group level Subscribables - if (groupCtxt.getSubscribableContexts() != null) { - clusterDataMap = parseLeafLevelSubscriptions(appId, tenantId, key, groupCtxt.getName(), - Arrays.asList(groupCtxt.getSubscribableContexts()), subscribableInfoCtxts); - group.setClusterData(clusterDataMap); - } - - // get nested groups - if (groupCtxt.getGroupContexts() != null) { - Map<String, Group> nestedGroups = new HashMap<String, Group>(); - // check sub groups - for (GroupContext subGroupCtxt : groupCtxt.getGroupContexts()) { - // get the complete Group Definition - subGroupCtxt = definedGroupCtxts.get(subGroupCtxt.getAlias()); - Group nestedGroup = parseGroup(appId, tenantId, key, subGroupCtxt, - subscribableInfoCtxts, - definedGroupCtxts); - nestedGroups.put(nestedGroup.getAlias(), nestedGroup); - } - - group.setGroups(nestedGroups); - } - - return group; - } - - /** - * Find the startup order - * - * @param groupContext GroupContext with Group defintion information - * @return Set of Startup Orders which are defined in the Group - * - * @throws ApplicationDefinitionException - */ - private String [] getStartupOrderForGroup(GroupContext groupContext) throws ApplicationDefinitionException { - - ServiceGroup serviceGroup = FasterLookUpDataHolder.getInstance().getServiceGroup(groupContext.getName()); - - if (serviceGroup == null) { - handleError("Service Group Definition not found for name " + groupContext.getName()); - } - - if (log.isDebugEnabled()) { - log.debug("parsing application ... getStartupOrderForGroup: " + groupContext.getName()); - } - - assert serviceGroup != null; - if (serviceGroup.getDependencies() != null) { - if (log.isDebugEnabled()) { - log.debug("parsing application ... getStartupOrderForGroup: dependencies != null " ); - } - if (serviceGroup.getDependencies().getStartupOrders() != null) { - - String [] startupOrders = serviceGroup.getDependencies().getStartupOrders(); - if (log.isDebugEnabled()) { - log.debug("parsing application ... getStartupOrderForGroup: startupOrders != null # of: " + startupOrders.length); - } - return startupOrders; - } - } - - return null; - } - - /** - * Get kill behaviour related to a Group - * - * @param serviceGroupName Group name - * @return String indicating the kill behavior - * - * @throws ApplicationDefinitionException if an error occurs - */ - private String getKillbehaviour (String serviceGroupName) throws ApplicationDefinitionException { - - ServiceGroup serviceGroup = FasterLookUpDataHolder.getInstance().getServiceGroup(serviceGroupName); - - if (serviceGroup == null) { - handleError("Service Group Definition not found for name " + serviceGroupName); - } - - assert serviceGroup != null; - if (serviceGroup.getDependencies() != null) { - return serviceGroup.getDependencies().getKillBehaviour(); - } - - return null; - - } - - /** - * Parse Subscription Information - * - * @param appId Application id - * @param tenantId Tenant id of tenant which deployed the Application - * @param key Generated key for the Application - * @param groupName Group name (if relevant) - * @param subscribableCtxts Subscribable Information - * @param subscribableInfoCtxts Map [cartridge alias -> Group] with extracted Subscription Information - * @return Map [subscription alias -> ClusterDataHolder] - * - * @throws ApplicationDefinitionException - */ - private Map<String, ClusterDataHolder> parseLeafLevelSubscriptions (String appId, int tenantId, String key, String groupName, - List<SubscribableContext> subscribableCtxts, - Map<String, SubscribableInfoContext> subscribableInfoCtxts) - throws ApplicationDefinitionException { - - Map<String, ClusterDataHolder> clusterDataMap = new HashMap<String, ClusterDataHolder>(); - - for (SubscribableContext subscribableCtxt : subscribableCtxts) { - - // check is there is a related Subscribable Information - SubscribableInfoContext subscribableInfoCtxt = subscribableInfoCtxts.get(subscribableCtxt.getAlias()); - if (subscribableInfoCtxt == null) { - handleError("Related Subscribable Information Ctxt not found for Subscribable with alias: " - + subscribableCtxt.getAlias()); - } - - // check if Cartridge Type is valid - if (StringUtils.isEmpty(subscribableCtxt.getType())) { - handleError("Invalid Cartridge Type specified : [ " - + subscribableCtxt.getType() + " ]"); - } - - // check if a cartridge with relevant type is already deployed. else, can't continue - Cartridge cartridge = getCartridge(subscribableCtxt.getType()); - if (cartridge == null) { - handleError("No deployed Cartridge found with type [ " + subscribableCtxt.getType() + - " ] for Composite Application"); - } - - // get hostname and cluster id - ClusterInformation clusterInfo; - assert cartridge != null; - if (cartridge.isMultiTenant()) { - clusterInfo = new MTClusterInformation(); - } else { - clusterInfo = new STClusterInformation(); - } - - String hostname = clusterInfo.getHostName(subscribableCtxt.getAlias(), cartridge.getHostName()); - String clusterId = clusterInfo.getClusterId(subscribableCtxt.getAlias(), subscribableCtxt.getType()); - - // create and collect this cluster's information - assert subscribableInfoCtxt != null; - ApplicationClusterContext appClusterCtxt = createApplicationClusterContext(appId, groupName, cartridge, - key, tenantId, subscribableInfoCtxt.getRepoUrl(), subscribableCtxt.getAlias(), - clusterId, hostname, subscribableInfoCtxt.getDeploymentPolicy(), false, subscribableInfoCtxt.getDependencyAliases()); - - appClusterCtxt.setAutoscalePolicyName(subscribableInfoCtxt.getAutoscalingPolicy()); - this.applicationClusterContexts.add(appClusterCtxt); - - // add relevant information to the map - clusterDataMap.put(subscribableCtxt.getAlias(), new ClusterDataHolder(subscribableCtxt.getType(), clusterId)); - } - - return clusterDataMap; - } - - /** - * Creates a ApplicationClusterContext object to keep information related to a Cluster in this Application - * - * @param appId Application id - * @param groupName Group name - * @param cartridge Cartridge information - * @param subscriptionKey Generated key for the Application - * @param tenantId Tenant Id of the tenant which deployed the Application - * @param repoUrl Repository URL - * @param alias alias specified for this Subscribable in the Application Definition - * @param clusterId Cluster id - * @param hostname Hostname - * @param deploymentPolicy Deployment policy used - * @param isLB if this cluster is an LB - * @return ApplicationClusterContext object with relevant information - * - * @throws ApplicationDefinitionException If any error occurs - */ - private ApplicationClusterContext createApplicationClusterContext (String appId, String groupName, Cartridge cartridge, - String subscriptionKey, int tenantId, String repoUrl, - String alias, String clusterId, String hostname, - String deploymentPolicy, boolean isLB, String[] dependencyAliases) - throws ApplicationDefinitionException { - - // Create text payload - String textPayload = ApplicationUtils.createPayload(appId, groupName, cartridge, subscriptionKey, tenantId, clusterId, - hostname, repoUrl, alias, null, dependencyAliases).toString(); - - return new ApplicationClusterContext(cartridge.getType(), clusterId, hostname, textPayload, deploymentPolicy, isLB); - } - - private Cartridge getCartridge (String cartridgeType) { - - return FasterLookUpDataHolder.getInstance().getCartridge(cartridgeType); - } - - private void handleError (String errorMsg) throws ApplicationDefinitionException { - log.error(errorMsg); - throw new ApplicationDefinitionException(errorMsg); - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/572cbe32/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 deleted file mode 100644 index e6cdda0..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/parser/ParserUtils.java +++ /dev/null @@ -1,142 +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.application.parser; - -import org.apache.stratos.cloud.controller.exception.ApplicationDefinitionException; -import org.apache.stratos.cloud.controller.pojo.application.GroupContext; -import org.apache.stratos.cloud.controller.pojo.application.SubscribableContext; -import org.apache.stratos.messaging.domain.applications.StartupOrder; - -import java.util.*; - -public class ParserUtils { - - public static Set<StartupOrder> convert (String [] startupOrderArr) throws ApplicationDefinitionException { - - Set<StartupOrder> startupOrders = new HashSet<StartupOrder>(); - - if (startupOrderArr == null) { - return startupOrders; - } - - for (String commaSeparatedStartupOrder : startupOrderArr) { - startupOrders.add(getStartupOrder(commaSeparatedStartupOrder)); - } - - return startupOrders; - } - - private static StartupOrder getStartupOrder (String commaSeparatedStartupOrder) throws ApplicationDefinitionException{ - - List<String> startupOrders = new ArrayList<String>(); - - for (String startupOrder : Arrays.asList(commaSeparatedStartupOrder.split(","))) { - startupOrder = startupOrder.trim(); - if (!startupOrder.startsWith("cartridge.") && !startupOrder.startsWith("group.")) { - throw new ApplicationDefinitionException("Incorrect Startup Order specified, should start with 'cartridge.' or 'group.'"); - } - - startupOrders.add(startupOrder); - } - - return new StartupOrder(startupOrders); - } - - public static Set<StartupOrder> convert (String [] startupOrderArr, GroupContext groupContext) - throws ApplicationDefinitionException { - - Set<StartupOrder> startupOrders = new HashSet<StartupOrder>(); - - if (startupOrderArr == null) { - return startupOrders; - } - - - for (String commaSeparatedStartupOrder : startupOrderArr) { - // convert all Startup Orders to aliases-based - List<String> components = Arrays.asList(commaSeparatedStartupOrder.split(",")); - startupOrders.add(getStartupOrder(components, groupContext)); - } - - return startupOrders; - } - - private static StartupOrder getStartupOrder (List<String> components, GroupContext groupContext) - throws ApplicationDefinitionException { - - List<String> aliasBasedComponents = new ArrayList<String>(); - - for (String component : components) { - component = component.trim(); - - String aliasBasedComponent; - if (component.startsWith("cartridge.")) { - String cartridgeType = component.substring(10); - aliasBasedComponent = getAliasForServiceType(cartridgeType, groupContext); - if (aliasBasedComponent == null) { - throw new ApplicationDefinitionException("Unable convert Startup Order to alias-based; " + - "cannot find the matching alias for Service type " + cartridgeType); - } - - aliasBasedComponent = "cartridge.".concat(aliasBasedComponent); - - } else if (component.startsWith("group.")) { - String groupName = component.substring(6); - aliasBasedComponent = getAliasForGroupName(groupName, groupContext); - if (aliasBasedComponent == null) { - throw new ApplicationDefinitionException("Unable convert Startup Order to alias-based; " + - "cannot find the matching alias for Group name " + groupName); - } - - aliasBasedComponent = "group.".concat(aliasBasedComponent); - - } else { - throw new ApplicationDefinitionException("Incorrect Startup Order specified, " + - "should start with 'cartridge.' or 'group.'"); - } - aliasBasedComponents.add(aliasBasedComponent); - } - - return new StartupOrder(aliasBasedComponents); - } - - private static String getAliasForGroupName (String groupName, GroupContext groupContext) { - - for (GroupContext groupCtxt : groupContext.getGroupContexts()) { - if (groupName.equals(groupCtxt.getName())) { - return groupCtxt.getAlias(); - } - } - - return null; - } - - - private static String getAliasForServiceType (String serviceType, GroupContext groupContext) { - - for (SubscribableContext subCtxt : groupContext.getSubscribableContexts()) { - if (serviceType.equals(subCtxt.getType())) { - return subCtxt.getAlias(); - } - } - - return null; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/572cbe32/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/payload/ApplicationCartridgePayloadData.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/payload/ApplicationCartridgePayloadData.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/payload/ApplicationCartridgePayloadData.java deleted file mode 100644 index 870c22c..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/payload/ApplicationCartridgePayloadData.java +++ /dev/null @@ -1,27 +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.application.payload; - -public class ApplicationCartridgePayloadData extends PayloadData { - - public ApplicationCartridgePayloadData(BasicPayloadData basicPayloadData) { - super(basicPayloadData); - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/572cbe32/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/payload/BasicPayloadData.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/payload/BasicPayloadData.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/payload/BasicPayloadData.java deleted file mode 100644 index c655b1b..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/payload/BasicPayloadData.java +++ /dev/null @@ -1,311 +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.application.payload; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import java.io.Serializable; - -/** - * Contains basic payload data fields - */ -public class BasicPayloadData implements Serializable { - - private static Log log = LogFactory.getLog(BasicPayloadData.class); - - private String appId; - private String groupName; - private String serviceName; - private String clusterId; - private String hostName; - private int tenantId; - private String tenantRange; - private String subscriptionAlias; - private String deployment; - private String puppetIp; - private String puppetHostName; - private String puppetEnvironment; - private String subscriptionKey; - private String applicationPath; - private String gitRepositoryUrl; - private String portMappings; - private String multitenant; - private String provider; - private String[] dependencyAliases; - private String[] exportingProperties; - - protected StringBuilder payloadBuilder; - - public BasicPayloadData() { - - } - - public void populatePayload () { - - payloadBuilder = new StringBuilder(); - - payloadBuilder.append("APP_ID=" + getAppId()); - payloadBuilder.append(","); - payloadBuilder.append("GROUP_NAME=" + getGroupName()); - payloadBuilder.append(","); - payloadBuilder.append("SERVICE_NAME=" + getServiceName()); - payloadBuilder.append(","); - payloadBuilder.append("HOST_NAME=" + getHostName()); - payloadBuilder.append(","); - payloadBuilder.append("MULTITENANT=" + getMultitenant()); - payloadBuilder.append(","); - payloadBuilder.append("TENANT_ID=" + getTenantId()); - payloadBuilder.append(","); - payloadBuilder.append("TENANT_RANGE=" + getTenantRange()); - payloadBuilder.append(","); - payloadBuilder.append("CARTRIDGE_ALIAS=" + getSubscriptionAlias()); - payloadBuilder.append(","); - payloadBuilder.append("CLUSTER_ID=" + getClusterId()); - payloadBuilder.append(","); - payloadBuilder.append("CARTRIDGE_KEY=" + getSubscriptionKey()); - payloadBuilder.append(","); - //payloadBuilder.append("DEPLOYMENT=" + getDeployment()); - //payloadBuilder.append(","); - //payloadBuilder.append("APP_PATH=" + getApplicationPath()); - //payloadBuilder.append(","); - payloadBuilder.append("REPO_URL=" + getGitRepositoryUrl()); - payloadBuilder.append(","); - payloadBuilder.append("PORTS=" + getPortMappings()); - payloadBuilder.append(","); - payloadBuilder.append("PROVIDER=" + getProvider()); - - //Payload Data exposed as system variables - payloadBuilder.append(","); - payloadBuilder.append("PUPPET_IP=" + System.getProperty("puppet.ip")); - payloadBuilder.append(","); - payloadBuilder.append("PUPPET_HOSTNAME=" + System.getProperty("puppet.hostname")); - payloadBuilder.append(","); - payloadBuilder.append("PUPPET_DNS_AVAILABLE=" + System.getProperty("puppet.env")); - payloadBuilder.append(","); - payloadBuilder.append("PUPPET_ENV=" + System.getProperty("puppet.dns.available")); - payloadBuilder.append(","); - if(getDependencyAliasesPayloadString() != null){ - payloadBuilder.append("DEPENDECNY_ALIASES=" + getDependencyAliasesPayloadString()); - } - payloadBuilder.append(","); - if(getExportingPropertiesPayloadString() != null){ - payloadBuilder.append("EXPORTING_PROPERTIES=" + getExportingPropertiesPayloadString()); - } - - } - - public String getServiceName() { - return serviceName; - } - - public void setServiceName(String serviceName) { - this.serviceName = serviceName; - } - - public String getClusterId() { - return clusterId; - } - - public void setClusterId(String clusterId) { - this.clusterId = clusterId; - } - - public String getHostName() { - return hostName; - } - - public void setHostName(String hostName) { - this.hostName = hostName; - } - - public int getTenantId() { - return tenantId; - } - - public void setTenantId(int tenantId) { - this.tenantId = tenantId; - } - - public String getTenantRange() { - return tenantRange; - } - - public void setTenantRange(String tenantRange) { - this.tenantRange = tenantRange; - } - - public String getSubscriptionAlias() { - return subscriptionAlias; - } - - public void setSubscriptionAlias(String subscriptionAlias) { - this.subscriptionAlias = subscriptionAlias; - } - - public String getDeployment() { - return deployment; - } - - public void setDeployment(String deployment) { - this.deployment = deployment; - } - - public String getPuppetIp() { - return puppetIp; - } - - public void setPuppetIp(String puppetIp) { - this.puppetIp = puppetIp; - } - - public String getSubscriptionKey() { - return subscriptionKey; - } - - public void setSubscriptionKey(String subscriptionKey) { - this.subscriptionKey = subscriptionKey; - } - - public StringBuilder getPayloadData () { - - return payloadBuilder; - } - - public String getApplicationPath() { - return applicationPath; - } - - public void setApplicationPath(String applicationPath) { - this.applicationPath = applicationPath; - } - - public String getGitRepositoryUrl() { - return gitRepositoryUrl; - } - - public void setGitRepositoryUrl(String gitRepositoryUrl) { - this.gitRepositoryUrl = gitRepositoryUrl; - } - - public String getPortMappings() { - return portMappings; - } - - public void setPortMappings(String portMappings) { - this.portMappings = portMappings; - } - - public String getMultitenant() { - return multitenant; - } - - public void setMultitenant(String multitenant) { - this.multitenant = multitenant; - } - - public String getPuppetHostName() { - return puppetHostName; - } - - public void setPuppetHostName(String puppetHostName) { - this.puppetHostName = puppetHostName; - } - - public String getPuppetEnvironment() { - return puppetEnvironment; - } - - public void setPuppetEnvironment(String puppetEnvironment) { - this.puppetEnvironment = puppetEnvironment; - } - - public String getProvider() { - return provider; - } - - public void setProvider(String provider) { - this.provider = provider; - } - - public String getAppId() { - return appId; - } - - public void setAppId(String appId) { - this.appId = appId; - } - - public String getGroupName() { - return groupName; - } - - public void setGroupName(String groupName) { - this.groupName = groupName; - } - - public String[] getDependencyAliases() { - return dependencyAliases; - } - - public void setDependencyAliases(String[] dependencyAliases) { - this.dependencyAliases = dependencyAliases; - } - - private String getDependencyAliasesPayloadString(){ - if(dependencyAliases == null){ - return null; - } - - StringBuilder dependencyAliasesPayload = new StringBuilder(); - for(int i=0; i< dependencyAliases.length; i++){ - dependencyAliasesPayload.append(dependencyAliases[i]); - if(i != dependencyAliases.length -1){ - dependencyAliasesPayload.append("|"); - } - } - log.info("testing1 getDependencyAliasesPayloadString " + dependencyAliasesPayload); - return dependencyAliasesPayload.toString(); - } - - private String getExportingPropertiesPayloadString(){ - if(exportingProperties == null){ - return null; - } - - StringBuilder exportingPropertiesPayload = new StringBuilder(); - for(int i=0; i< exportingProperties.length; i++){ - exportingPropertiesPayload.append(exportingProperties[i]); - if(i != exportingProperties.length -1){ - exportingPropertiesPayload.append("|"); - } - } - log.info("testing1 getExportingPropertiesPayloadString " + exportingPropertiesPayload); - return exportingPropertiesPayload.toString(); - } - - public String[] getExportingProperties() { - return exportingProperties; - } - - public void setExportingProperties(String[] exportingProperties) { - this.exportingProperties = exportingProperties; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/572cbe32/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/payload/DataCartridgePayloadData.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/payload/DataCartridgePayloadData.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/payload/DataCartridgePayloadData.java deleted file mode 100644 index 1848b6d..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/payload/DataCartridgePayloadData.java +++ /dev/null @@ -1,27 +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.application.payload; - -public class DataCartridgePayloadData extends PayloadData { - - public DataCartridgePayloadData(BasicPayloadData basicPayloadData) { - super(basicPayloadData); - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/572cbe32/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/payload/FrameworkCartridgePayloadData.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/payload/FrameworkCartridgePayloadData.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/payload/FrameworkCartridgePayloadData.java deleted file mode 100644 index a22d40b..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/payload/FrameworkCartridgePayloadData.java +++ /dev/null @@ -1,27 +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.application.payload; - -public class FrameworkCartridgePayloadData extends PayloadData { - - public FrameworkCartridgePayloadData(BasicPayloadData basicPayloadData) { - super(basicPayloadData); - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/572cbe32/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/payload/LoadBalancerCartridgePayloadData.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/payload/LoadBalancerCartridgePayloadData.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/payload/LoadBalancerCartridgePayloadData.java deleted file mode 100644 index 6ceeba9..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/payload/LoadBalancerCartridgePayloadData.java +++ /dev/null @@ -1,27 +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.application.payload; - -public class LoadBalancerCartridgePayloadData extends PayloadData { - - public LoadBalancerCartridgePayloadData(BasicPayloadData basicPayloadData) { - super(basicPayloadData); - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/572cbe32/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/payload/PayloadData.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/payload/PayloadData.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/payload/PayloadData.java deleted file mode 100644 index 35b1fe6..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/application/payload/PayloadData.java +++ /dev/null @@ -1,69 +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.application.payload; - -import java.io.Serializable; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -public abstract class PayloadData implements Serializable { - - private BasicPayloadData basicPayloadData; - private Map<String, String> completePayloadMap; - public PayloadData(BasicPayloadData basicPayloadData) { - - this.setBasicPayloadData(basicPayloadData); - completePayloadMap = new HashMap<String, String>(); - } - - public void add (String payloadDataName, String payloadDataValue) { - completePayloadMap.put(payloadDataName, payloadDataValue); - } - - public StringBuilder getCompletePayloadData () { - - //return completePayloadMap; - StringBuilder completePayload = new StringBuilder(); - completePayload.append(basicPayloadData.getPayloadData()); - Iterator< String > iter = completePayloadMap.keySet().iterator(); - while(iter.hasNext()) { - String key = iter.next(); - String val = completePayloadMap.get(key); - if(completePayload.length() > 0){ - completePayload.append(","); - } - completePayload.append(key + "=" + val); - } - return completePayload; - } - - public BasicPayloadData getBasicPayloadData() { - return basicPayloadData; - } - - public void setBasicPayloadData(BasicPayloadData basicPayloadData) { - this.basicPayloadData = basicPayloadData; - } - - public String toString () { - return getCompletePayloadData().toString(); - } -}
