You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by is...@apache.org on 2014/03/07 13:26:33 UTC
[01/12] git commit: moving LB subscription logic to SM - initial step
Repository: incubator-stratos
Updated Branches:
refs/heads/master 45775153a -> c45866344
moving LB subscription logic to SM - initial step
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/459ebb40
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/459ebb40
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/459ebb40
Branch: refs/heads/master
Commit: 459ebb409695f5a55a4be49796a1973d0c46455f
Parents: b746b90
Author: Isuru <is...@wso2.com>
Authored: Mon Feb 10 11:10:57 2014 +0530
Committer: Isuru <is...@wso2.com>
Committed: Mon Feb 10 11:10:57 2014 +0530
----------------------------------------------------------------------
.../category/DefaultLoadBalancerCategory.java | 28 ++
.../category/ExistingLoadBalancerCategory.java | 44 ++++
.../manager/lb/category/LBCategoryContext.java | 152 +++++++++++
.../manager/lb/category/LBDataContext.java | 107 ++++++++
.../lb/category/LoadBalancerCategory.java | 144 ++++++++++
.../ServiceLevelLoadBalancerCategory.java | 38 +++
.../subscription/LBCartridgeSubscription.java | 63 ++++-
.../factory/CartridgeSubscriptionFactory.java | 42 ++-
.../utils/CartridgeSubscriptionUtils.java | 263 ++++++++++++++++++-
9 files changed, 840 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/459ebb40/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/DefaultLoadBalancerCategory.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/DefaultLoadBalancerCategory.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/DefaultLoadBalancerCategory.java
new file mode 100644
index 0000000..a346bbd
--- /dev/null
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/DefaultLoadBalancerCategory.java
@@ -0,0 +1,28 @@
+/*
+ * 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.manager.lb.category;
+
+public class DefaultLoadBalancerCategory extends LoadBalancerCategory {
+
+ public DefaultLoadBalancerCategory(LBCategoryContext lbCategoryContext) {
+ super(lbCategoryContext);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/459ebb40/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/ExistingLoadBalancerCategory.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/ExistingLoadBalancerCategory.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/ExistingLoadBalancerCategory.java
new file mode 100644
index 0000000..6523df8
--- /dev/null
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/ExistingLoadBalancerCategory.java
@@ -0,0 +1,44 @@
+/*
+ * 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.manager.lb.category;
+
+import org.apache.stratos.manager.exception.ADCException;
+import org.apache.stratos.manager.exception.UnregisteredCartridgeException;
+import org.apache.stratos.manager.payload.PayloadData;
+
+public class ExistingLoadBalancerCategory extends LoadBalancerCategory {
+
+ public ExistingLoadBalancerCategory(LBCategoryContext lbCategoryContext) {
+ super(lbCategoryContext);
+ }
+
+ public void register () throws ADCException, UnregisteredCartridgeException {
+ //TODO
+ }
+
+ public PayloadData createPayload() throws ADCException {
+ //TODO;
+ return null;
+ }
+
+ public void unregister () throws ADCException {
+ //TODO
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/459ebb40/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/LBCategoryContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/LBCategoryContext.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/LBCategoryContext.java
new file mode 100644
index 0000000..e6420a9
--- /dev/null
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/LBCategoryContext.java
@@ -0,0 +1,152 @@
+/*
+ * 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.manager.lb.category;
+
+import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
+import org.apache.stratos.cloud.controller.pojo.Properties;
+import org.apache.stratos.manager.dao.Cluster;
+import org.apache.stratos.manager.payload.PayloadData;
+import org.apache.stratos.manager.subscriber.Subscriber;
+
+import java.util.Map;
+
+public class LBCategoryContext {
+
+ private String lbType;
+ private PayloadData payloadData;
+ private Properties properties;
+ private Cluster cluster;
+ private String autoscalingPolicyName;
+ private String deploymentPolicyName;
+ private Map<String, String> customPayloadEntries;
+ private CartridgeInfo cartridgeInfo;
+ private String key;
+ private String loadbalancedServiceType;
+ private String subscriptionAlias;
+ private Subscriber subscriber;
+
+ public LBCategoryContext (String lbType, Cluster cluster, String autoscalingPolicyName, String deploymentPolicyName,
+ CartridgeInfo cartridgeInfo, PayloadData payloadData, String key) {
+
+ this.lbType = lbType;
+ this.cluster = cluster;
+ this.autoscalingPolicyName = autoscalingPolicyName;
+ this.deploymentPolicyName = deploymentPolicyName;
+ this.cartridgeInfo = cartridgeInfo;
+ this.payloadData = payloadData;
+ this.key = key;
+ }
+
+ public PayloadData getPayloadData() {
+ return payloadData;
+ }
+
+ public void setPayloadData(PayloadData payloadData) {
+ this.payloadData = payloadData;
+ }
+
+ public Properties getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Properties properties) {
+ this.properties = properties;
+ }
+
+ public Cluster getCluster() {
+ return cluster;
+ }
+
+ public void setCluster(Cluster cluster) {
+ this.cluster = cluster;
+ }
+
+ public String getAutoscalingPolicyName() {
+ return autoscalingPolicyName;
+ }
+
+ public void setAutoscalingPolicyName(String autoscalingPolicyName) {
+ this.autoscalingPolicyName = autoscalingPolicyName;
+ }
+
+ public String getDeploymentPolicyName() {
+ return deploymentPolicyName;
+ }
+
+ public void setDeploymentPolicyName(String deploymentPolicyName) {
+ this.deploymentPolicyName = deploymentPolicyName;
+ }
+
+ public Map<String, String> getCustomPayloadEntries() {
+ return customPayloadEntries;
+ }
+
+ public void setCustomPayloadEntries(Map<String, String> customPayloadEntries) {
+ this.customPayloadEntries = customPayloadEntries;
+ }
+
+ public CartridgeInfo getCartridgeInfo() {
+ return cartridgeInfo;
+ }
+
+ public void setCartridgeInfo(CartridgeInfo cartridgeInfo) {
+ this.cartridgeInfo = cartridgeInfo;
+ }
+
+ public String getLbType() {
+ return lbType;
+ }
+
+ public void setLbType(String lbType) {
+ this.lbType = lbType;
+ }
+
+ public String getLoadbalancedServiceType() {
+ return loadbalancedServiceType;
+ }
+
+ public void setLoadbalancedServiceType(String loadbalancedServiceType) {
+ this.loadbalancedServiceType = loadbalancedServiceType;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getSubscriptionAlias() {
+ return subscriptionAlias;
+ }
+
+ public void setSubscriptionAlias(String subscriptionAlias) {
+ this.subscriptionAlias = subscriptionAlias;
+ }
+
+ public Subscriber getSubscriber() {
+ return subscriber;
+ }
+
+ public void setSubscriber(Subscriber subscriber) {
+ this.subscriber = subscriber;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/459ebb40/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/LBDataContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/LBDataContext.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/LBDataContext.java
new file mode 100644
index 0000000..612158e
--- /dev/null
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/LBDataContext.java
@@ -0,0 +1,107 @@
+/*
+ * 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.manager.lb.category;
+
+import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
+import org.apache.stratos.cloud.controller.pojo.Properties;
+import org.apache.stratos.cloud.controller.pojo.Property;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class LBDataContext {
+
+ private String lbCategory;
+ private int tenantId;
+ private String autoscalePolicy;
+ private String deploymentPolicy;
+ private List<Property> lbProperperties;
+ private List<Property> loadBalancedServiceProperties;
+ private CartridgeInfo lbCartridgeInfo;
+
+
+ public LBDataContext() {
+ lbProperperties = new ArrayList<Property>();
+ loadBalancedServiceProperties = new ArrayList<Property>();
+ }
+
+ public CartridgeInfo getLbCartridgeInfo() {
+ return lbCartridgeInfo;
+ }
+
+ public void setLbCartridgeInfo(CartridgeInfo lbCartridgeInfo) {
+ this.lbCartridgeInfo = lbCartridgeInfo;
+ }
+
+ public String getLbCategory() {
+ return lbCategory;
+ }
+
+ public void setLbCategory(String lbCategory) {
+ this.lbCategory = lbCategory;
+ }
+
+ public int getTenantId() {
+ return tenantId;
+ }
+
+ public void setTenantId(int tenantId) {
+ this.tenantId = tenantId;
+ }
+
+ public String getAutoscalePolicy() {
+ return autoscalePolicy;
+ }
+
+ public void setAutoscalePolicy(String autoscalePolicy) {
+ this.autoscalePolicy = autoscalePolicy;
+ }
+
+ public String getDeploymentPolicy() {
+ return deploymentPolicy;
+ }
+
+ public void setDeploymentPolicy(String deploymentPolicy) {
+ this.deploymentPolicy = deploymentPolicy;
+ }
+
+ public List<Property> getLbProperperties() {
+ return lbProperperties;
+ }
+
+ public void addLbProperperty (Property lbProperperty) {
+ this.lbProperperties.add(lbProperperty);
+ }
+
+ public void addLBProperties(Properties loadBalancedServiceProperties) {
+
+ for (Property property : loadBalancedServiceProperties.getProperties()) {
+ addLbProperperty(property);
+ }
+ }
+
+ public List<Property> getLoadBalancedServiceProperties() {
+ return loadBalancedServiceProperties;
+ }
+
+ public void addLoadBalancedServiceProperty(Property loadBalancedServiceProperty) {
+ this.loadBalancedServiceProperties.add(loadBalancedServiceProperty);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/459ebb40/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/LoadBalancerCategory.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/LoadBalancerCategory.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/LoadBalancerCategory.java
new file mode 100644
index 0000000..b2fca7b
--- /dev/null
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/LoadBalancerCategory.java
@@ -0,0 +1,144 @@
+/*
+ * 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.manager.lb.category;
+
+import org.apache.axis2.AxisFault;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
+import org.apache.stratos.cloud.controller.pojo.Property;
+import org.apache.stratos.manager.client.CloudControllerServiceClient;
+import org.apache.stratos.manager.exception.ADCException;
+import org.apache.stratos.manager.exception.UnregisteredCartridgeException;
+import org.apache.stratos.manager.payload.BasicPayloadData;
+import org.apache.stratos.manager.payload.PayloadData;
+import org.apache.stratos.manager.payload.PayloadFactory;
+import org.apache.stratos.manager.subscription.utils.CartridgeSubscriptionUtils;
+import org.apache.stratos.manager.utils.ApplicationManagementUtil;
+import org.apache.stratos.manager.utils.CartridgeConstants;
+
+import java.util.Map;
+import java.util.Set;
+
+public abstract class LoadBalancerCategory {
+
+ private static Log log = LogFactory.getLog(LoadBalancerCategory.class);
+
+ private LBCategoryContext lbCategoryContext;
+
+ public LoadBalancerCategory (LBCategoryContext lbCategoryContext) {
+ this.setLbCategoryContext(lbCategoryContext);
+ }
+
+ public void register () throws ADCException, UnregisteredCartridgeException {
+
+ log.info("Payload: " + getLbCategoryContext().getPayloadData().getCompletePayloadData().toString());
+
+ ApplicationManagementUtil.registerService(getLbCategoryContext().getLbType(),
+ getLbCategoryContext().getCluster().getClusterDomain(),
+ getLbCategoryContext().getCluster().getClusterSubDomain(),
+ getLbCategoryContext().getPayloadData().getCompletePayloadData(),
+ getLbCategoryContext().getPayloadData().getBasicPayloadData().getTenantRange(),
+ getLbCategoryContext().getCluster().getHostName(),
+ getLbCategoryContext().getAutoscalingPolicyName(),
+ getLbCategoryContext().getDeploymentPolicyName(),
+ getLbCategoryContext().getProperties());
+ }
+
+ public PayloadData createPayload() throws ADCException {
+
+ //Create the payload
+ BasicPayloadData basicPayloadData = CartridgeSubscriptionUtils.createBasicPayload(lbCategoryContext);
+ //Populate the basic payload details
+ basicPayloadData.populatePayload();
+
+ CartridgeInfo cartridgeInfo = getLbCategoryContext().getCartridgeInfo();
+ PayloadData payloadData = PayloadFactory.getPayloadDataInstance(cartridgeInfo.getProvider(),
+ cartridgeInfo.getType(), basicPayloadData);
+
+ // get the payload parameters defined in the cartridge definition file for this cartridge type
+ if (cartridgeInfo.getProperties() != null && cartridgeInfo.getProperties().length != 0) {
+
+ for (Property property : cartridgeInfo.getProperties()) {
+ // 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 (property.getName()
+ .startsWith(CartridgeConstants.CUSTOM_PAYLOAD_PARAM_NAME_PREFIX)) {
+ String payloadParamName = property.getName();
+ payloadData.add(payloadParamName.substring(payloadParamName.indexOf(".") + 1), property.getValue());
+ }
+ }
+ }
+
+ //check if there are any custom payload entries defined
+ if (getLbCategoryContext().getCustomPayloadEntries() != null) {
+ //add them to the payload
+ Map<String, String> customPayloadEntries = getLbCategoryContext().getCustomPayloadEntries();
+ Set<Map.Entry<String,String>> entrySet = customPayloadEntries.entrySet();
+ for (Map.Entry<String, String> entry : entrySet) {
+ payloadData.add(entry.getKey(), entry.getValue());
+ }
+ }
+
+ return payloadData;
+ }
+
+ public void unregister () throws ADCException {
+
+ try {
+ CloudControllerServiceClient.getServiceClient().terminateAllInstances(getLbCategoryContext().getCluster().getClusterDomain());
+
+ } catch (AxisFault e) {
+ String errorMsg = "Error in terminating cartridge subscription, cluster id: " + getLbCategoryContext().getCluster().getClusterDomain();
+ log.error(errorMsg);
+ throw new ADCException(errorMsg, e);
+
+ } catch (Exception e) {
+ String errorMsg = "Error in terminating cartridge subscription, cluster id: " + getLbCategoryContext().getCluster().getClusterDomain();
+ log.error(errorMsg);
+ throw new ADCException(errorMsg, e);
+ }
+
+ log.info("Terminated all instances of " + getLbCategoryContext().getCluster().getClusterDomain() + " " +
+ getLbCategoryContext().getCluster().getClusterSubDomain());
+
+ try {
+ CloudControllerServiceClient.getServiceClient().unregisterService(getLbCategoryContext().getCluster().getClusterDomain());
+
+ } catch (Exception e) {
+ String errorMsg = "Error in unregistering service cluster with domain " + getLbCategoryContext().getCluster().getClusterDomain() +
+ ", sub domain " + getLbCategoryContext().getCluster().getClusterSubDomain();
+ log.error(errorMsg);
+ throw new ADCException(errorMsg, e);
+ }
+
+ log.info("Unregistered service cluster, domain " + getLbCategoryContext().getCluster().getClusterDomain() + ", sub domain " +
+ getLbCategoryContext().getCluster().getClusterSubDomain());
+ }
+
+ public LBCategoryContext getLbCategoryContext() {
+ return lbCategoryContext;
+ }
+
+ public void setLbCategoryContext(LBCategoryContext lbCategoryContext) {
+ this.lbCategoryContext = lbCategoryContext;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/459ebb40/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/ServiceLevelLoadBalancerCategory.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/ServiceLevelLoadBalancerCategory.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/ServiceLevelLoadBalancerCategory.java
new file mode 100644
index 0000000..0bb979b
--- /dev/null
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/ServiceLevelLoadBalancerCategory.java
@@ -0,0 +1,38 @@
+/*
+ * 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.manager.lb.category;
+
+import org.apache.stratos.manager.exception.ADCException;
+import org.apache.stratos.manager.payload.PayloadData;
+
+public class ServiceLevelLoadBalancerCategory extends LoadBalancerCategory {
+
+ public ServiceLevelLoadBalancerCategory(LBCategoryContext lbCategoryContext) {
+ super(lbCategoryContext);
+ }
+
+ public PayloadData createPayload() throws ADCException {
+
+ // add payload entry for load balanced service type
+ PayloadData serviceLevelLbPayloadData = super.createPayload();
+ serviceLevelLbPayloadData.add("LOAD_BALANCED_SERVICE_TYPE", getLbCategoryContext().getLoadbalancedServiceType());
+ return serviceLevelLbPayloadData;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/459ebb40/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/LBCartridgeSubscription.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/LBCartridgeSubscription.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/LBCartridgeSubscription.java
index 0b349ab..fcb2616 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/LBCartridgeSubscription.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/LBCartridgeSubscription.java
@@ -19,26 +19,66 @@
package org.apache.stratos.manager.subscription;
+import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
+import org.apache.stratos.cloud.controller.pojo.Properties;
+import org.apache.stratos.cloud.controller.pojo.Property;
import org.apache.stratos.manager.dao.CartridgeSubscriptionInfo;
-import org.apache.stratos.manager.exception.ADCException;
-import org.apache.stratos.manager.exception.NotSubscribedException;
-import org.apache.stratos.manager.exception.UnregisteredCartridgeException;
+import org.apache.stratos.manager.exception.*;
+import org.apache.stratos.manager.lb.category.LoadBalancerCategory;
import org.apache.stratos.manager.repository.Repository;
+import org.apache.stratos.manager.subscriber.Subscriber;
import org.apache.stratos.manager.subscription.tenancy.SubscriptionTenancyBehaviour;
-import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
-import org.apache.stratos.cloud.controller.pojo.Properties;
+import org.apache.stratos.manager.utils.ApplicationManagementUtil;
+
+import java.util.List;
public class LBCartridgeSubscription extends CartridgeSubscription {
+ private LoadBalancerCategory loadBalancerCategory;
+
/**
* Constructor
*
* @param cartridgeInfo CartridgeInfo instance
* @param subscriptionTenancyBehaviour SubscriptionTenancyBehaviour instance
+ * @param loadBalancerCategory LoadBalancerCategory instance
*/
public LBCartridgeSubscription(CartridgeInfo cartridgeInfo, SubscriptionTenancyBehaviour
- subscriptionTenancyBehaviour) {
+ subscriptionTenancyBehaviour, LoadBalancerCategory loadBalancerCategory) {
+
super(cartridgeInfo, subscriptionTenancyBehaviour);
+ setLoadBalancerCategory(loadBalancerCategory);
+ }
+
+ public void createSubscription (Subscriber subscriber, String alias, String autoscalingPolicy,
+ String deploymentPolicyName, Repository repository, List<Property> payloadProperties)
+ throws ADCException, PolicyException, UnregisteredCartridgeException, InvalidCartridgeAliasException,
+ DuplicateCartridgeAliasException, RepositoryRequiredException, AlreadySubscribedException,
+ RepositoryCredentialsRequiredException, InvalidRepositoryException, RepositoryTransportException {
+
+ setSubscriber(subscriber);
+ setAlias(alias);
+ setAutoscalingPolicyName(autoscalingPolicy);
+ setDeploymentPolicyName(deploymentPolicyName);
+ setRepository(repository);
+ setPayloadData(getLoadBalancerCategory().createPayload());
+ }
+
+ @Override
+ public CartridgeSubscriptionInfo registerSubscription(Properties properties) throws ADCException, UnregisteredCartridgeException {
+
+ getLoadBalancerCategory().register();
+
+ return ApplicationManagementUtil.createCartridgeSubscription(getCartridgeInfo(), getAutoscalingPolicyName(),
+ getType(), getAlias(), getSubscriber().getTenantId(), getSubscriber().getTenantDomain(),
+ getRepository(), getCluster().getHostName(), getCluster().getClusterDomain(), getCluster().getClusterSubDomain(),
+ getCluster().getMgtClusterDomain(), getCluster().getMgtClusterSubDomain(), null, getSubscriptionStatus(), getSubscriptionKey());
+ }
+
+ @Override
+ public void removeSubscription() throws ADCException, NotSubscribedException {
+
+ getLoadBalancerCategory().unregister();
}
public Repository manageRepository (String repoURL, String repoUserName, String repoUserPassword,
@@ -49,14 +89,11 @@ public class LBCartridgeSubscription extends CartridgeSubscription {
return null;
}
- @Override
- public void removeSubscription() throws ADCException, NotSubscribedException {
- //TODO
+ public LoadBalancerCategory getLoadBalancerCategory() {
+ return loadBalancerCategory;
}
- @Override
- public CartridgeSubscriptionInfo registerSubscription(Properties properties) throws ADCException, UnregisteredCartridgeException {
- //TODO
- return null;
+ public void setLoadBalancerCategory(LoadBalancerCategory loadBalancerCategory) {
+ this.loadBalancerCategory = loadBalancerCategory;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/459ebb40/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/factory/CartridgeSubscriptionFactory.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/factory/CartridgeSubscriptionFactory.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/factory/CartridgeSubscriptionFactory.java
index 78cd453..ce70b89 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/factory/CartridgeSubscriptionFactory.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/factory/CartridgeSubscriptionFactory.java
@@ -19,46 +19,24 @@
package org.apache.stratos.manager.subscription.factory;
+import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
import org.apache.stratos.manager.exception.ADCException;
+import org.apache.stratos.manager.lb.category.LBDataContext;
+import org.apache.stratos.manager.lb.category.LoadBalancerCategory;
import org.apache.stratos.manager.subscription.*;
import org.apache.stratos.manager.subscription.tenancy.SubscriptionTenancyBehaviour;
import org.apache.stratos.manager.utils.CartridgeConstants;
-import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
public class CartridgeSubscriptionFactory {
/**
* Returns the relevant CartridgeSubscription object for the given criteria
*
- * @param cartridgeInfo CartridgeInfo subscription
+ * @param cartridgeInfo CartridgeInfo instance
+ * @param subscriptionTenancyBehaviour SubscriptionTenancyBehaviour instance
* @return CartridgeSubscription subscription
* @throws ADCException if no matching criteria is there to create a CartridgeSubscription object
*/
- /*public static CartridgeSubscription getCartridgeSubscriptionInstance(CartridgeInfo cartridgeInfo)
- throws ADCException {
-
- CartridgeSubscription cartridgeSubscription = null;
- if(cartridgeInfo.getMultiTenant()) {
- cartridgeSubscription = new MultiTenantCartridgeSubscription(cartridgeInfo);
-
- } else {
- if(cartridgeInfo.getProvider().equals(CartridgeConstants.DATA_CARTRIDGE_PROVIDER)) {
- cartridgeSubscription = new DataCartridgeSubscription(cartridgeInfo);
- }
- else {
- cartridgeSubscription = new SingleTenantCartridgeSubscription(cartridgeInfo);
- }
- }
-
-
-
- if(cartridgeSubscription == null) {
- throw new ADCException("Unable to create a CartridgeSubscription subscription for "
- + cartridgeInfo);
- }
-
- return cartridgeSubscription;
- }*/
public static CartridgeSubscription getCartridgeSubscriptionInstance(CartridgeInfo cartridgeInfo,
SubscriptionTenancyBehaviour subscriptionTenancyBehaviour)
@@ -88,4 +66,14 @@ public class CartridgeSubscriptionFactory {
return cartridgeSubscription;
}
+
+ public static CartridgeSubscription getLBCartridgeSubscriptionInstance (LBDataContext lbDataContext, LoadBalancerCategory loadBalancerCategory)
+ throws ADCException {
+
+ if (!lbDataContext.getLbCartridgeInfo().getProvider().equals("loadbalancer") || !lbDataContext.getLbCartridgeInfo().getProvider().equals("lb")) {
+ throw new ADCException("LB cartridge provider should be either lb or loadbalancer");
+ }
+
+ return new LBCartridgeSubscription(lbDataContext.getLbCartridgeInfo(), null, loadBalancerCategory);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/459ebb40/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
index 70ecf1c..e80b921 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
@@ -19,17 +19,28 @@
package org.apache.stratos.manager.subscription.utils;
+import org.apache.axis2.AxisFault;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy;
+import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
+import org.apache.stratos.cloud.controller.pojo.LoadbalancerConfig;
+import org.apache.stratos.cloud.controller.pojo.Properties;
+import org.apache.stratos.cloud.controller.pojo.Property;
+import org.apache.stratos.manager.client.AutoscalerServiceClient;
+import org.apache.stratos.manager.client.CloudControllerServiceClient;
import org.apache.stratos.manager.deploy.service.Service;
import org.apache.stratos.manager.exception.ADCException;
import org.apache.stratos.manager.exception.DuplicateCartridgeAliasException;
import org.apache.stratos.manager.exception.InvalidCartridgeAliasException;
+import org.apache.stratos.manager.exception.UnregisteredCartridgeException;
+import org.apache.stratos.manager.lb.category.LBCategoryContext;
+import org.apache.stratos.manager.lb.category.LBDataContext;
import org.apache.stratos.manager.payload.BasicPayloadData;
import org.apache.stratos.manager.retriever.DataInsertionAndRetrievalManager;
import org.apache.stratos.manager.subscription.CartridgeSubscription;
-import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
+import org.apache.stratos.manager.subscription.SubscriptionData;
import org.apache.stratos.messaging.broker.publish.EventPublisher;
import org.apache.stratos.messaging.event.tenant.TenantSubscribedEvent;
import org.apache.stratos.messaging.event.tenant.TenantUnSubscribedEvent;
@@ -85,6 +96,29 @@ public class CartridgeSubscriptionUtils {
return basicPayloadData;
}
+ public static BasicPayloadData createBasicPayload (LBCategoryContext lbCategoryContext) {
+
+ BasicPayloadData basicPayloadData = new BasicPayloadData();
+ basicPayloadData.setApplicationPath(lbCategoryContext.getCartridgeInfo().getBaseDir());
+ basicPayloadData.setSubscriptionKey(lbCategoryContext.getKey());
+ basicPayloadData.setClusterId(lbCategoryContext.getCluster().getClusterDomain());
+ basicPayloadData.setDeployment("default");//currently hard coded to default
+ basicPayloadData.setHostName(lbCategoryContext.getCluster().getHostName());
+ basicPayloadData.setMultitenant(String.valueOf(lbCategoryContext.getCartridgeInfo().getMultiTenant()));
+ basicPayloadData.setPortMappings(createPortMappingPayloadString(lbCategoryContext.getCartridgeInfo()));
+ basicPayloadData.setServiceName(lbCategoryContext.getLbType());
+
+ if (lbCategoryContext.getSubscriptionAlias() != null && !lbCategoryContext.getSubscriptionAlias().isEmpty()) {
+ basicPayloadData.setSubscriptionAlias(lbCategoryContext.getSubscriptionAlias());
+ }
+
+ if (lbCategoryContext.getSubscriber() != null) {
+ basicPayloadData.setTenantId(lbCategoryContext.getSubscriber().getTenantId());
+ }
+
+ return basicPayloadData;
+ }
+
private static String createPortMappingPayloadString (CartridgeInfo cartridgeInfo) {
// port mappings
@@ -169,4 +203,231 @@ public class CartridgeSubscriptionUtils {
DataInsertionAndRetrievalManager dataInsertionAndRetrievalManager = new DataInsertionAndRetrievalManager();
return (dataInsertionAndRetrievalManager.getCartridgeSubscription(tenantId, alias) == null) ? false : true;
}
+
+ public static LBDataContext getLoadBalancerDataContext (SubscriptionData subscriptionData, LoadbalancerConfig lbConfig) throws UnregisteredCartridgeException, ADCException {
+
+ String lbCartridgeType = lbConfig.getType();
+
+ LBDataContext lbDataCtxt = new LBDataContext();
+ // set tenant Id
+ lbDataCtxt.setTenantId(subscriptionData.getTenantId());
+
+ Properties lbReferenceProperties = lbConfig.getProperties();
+
+ Property lbRefProperty = new Property();
+ lbRefProperty.setName(org.apache.stratos.messaging.util.Constants.LOAD_BALANCER_REF);
+
+ for (org.apache.stratos.cloud.controller.pojo.Property prop : lbReferenceProperties.getProperties()) {
+
+ String name = prop.getName();
+ String value = prop.getValue();
+
+ // TODO make following a chain of responsibility pattern
+ if (Constants.NO_LOAD_BALANCER.equals(name)) {
+
+ if ("true".equals(value)) {
+ if (log.isDebugEnabled()) {
+ log.debug("This cartridge does not require a load balancer. " +
+ "[Type] " + subscriptionData.getCartridgeType());
+ }
+ lbRefProperty.setValue(name);
+ lbDataCtxt.addLoadBalancedServiceProperty(lbRefProperty);
+ break;
+ }
+ } else if (Constants.EXISTING_LOAD_BALANCERS.equals(name)) {
+
+ String clusterIdsVal = value;
+ if (log.isDebugEnabled()) {
+ log.debug("This cartridge refers to existing load balancers. " + "[Type] " +
+ subscriptionData.getCartridgeType() + "[Referenced Cluster Ids] " + clusterIdsVal);
+ }
+
+ String[] clusterIds = clusterIdsVal.split(",");
+
+ for (String clusterId : clusterIds) {
+ try {
+ AutoscalerServiceClient.getServiceClient().checkLBExistenceAgainstPolicy(clusterId, subscriptionData.getDeploymentPolicyName());
+ } catch (Exception ex) {
+ // we don't need to throw the error here.
+ log.error(ex.getMessage(), ex);
+ }
+ }
+
+ lbRefProperty.setValue(name);
+ lbDataCtxt.addLoadBalancedServiceProperty(lbRefProperty);
+ break;
+
+ } else if (Constants.DEFAULT_LOAD_BALANCER.equals(name)) {
+
+ if ("true".equals(value)) {
+
+ lbRefProperty.setValue(name);
+
+ CartridgeInfo lbCartridgeInfo;
+
+ try {
+ lbCartridgeInfo = CloudControllerServiceClient.getServiceClient().getCartridgeInfo(lbCartridgeType);
+
+ } catch (UnregisteredCartridgeException e) {
+ String message = lbCartridgeType + " is not a valid cartridgeSubscription type";
+ log.error(message);
+ throw e;
+
+ } catch (Exception e) {
+ String message = "Error getting info for " + lbCartridgeType;
+ log.error(message, e);
+ throw new ADCException(message, e);
+ }
+
+ lbDataCtxt.setLbCartridgeInfo(lbCartridgeInfo);
+
+ if (log.isDebugEnabled()) {
+ log.debug("This cartridge uses default load balancer. " + "[Type] " + subscriptionData.getCartridgeType());
+ }
+
+ try {
+ // get the valid policies for lb cartridge
+ DeploymentPolicy[] lbCartridgeDepPolicies =
+ getAutoscalerServiceClient().getDeploymentPolicies(lbCartridgeType);
+ // traverse deployment policies of lb cartridge
+ for (DeploymentPolicy policy : lbCartridgeDepPolicies) {
+
+ // check existence of the subscribed policy
+ if (subscriptionData.getDeploymentPolicyName().equals(policy.getId())) {
+
+ if (!getAutoscalerServiceClient().checkDefaultLBExistenceAgainstPolicy(subscriptionData.getDeploymentPolicyName())) {
+
+ Properties lbProperties = new Properties();
+
+ // if LB cartridge definition has properties as well, combine
+ if (lbCartridgeInfo.getProperties() != null && lbCartridgeInfo.getProperties().length > 0) {
+ lbProperties.setProperties(combine(lbCartridgeInfo.getProperties(), new Property[]{lbRefProperty}));
+
+ } else {
+ lbProperties.setProperties(new Property[]{lbRefProperty});
+ }
+
+ lbDataCtxt.addLBProperties(lbProperties);
+ }
+ }
+ }
+
+ } catch (Exception ex) {
+ // we don't need to throw the error here.
+ log.error(ex.getMessage(), ex);
+ }
+
+ // set deployment and autoscaling policies
+ lbDataCtxt.setDeploymentPolicy(subscriptionData.getDeploymentPolicyName());
+ lbDataCtxt.setAutoscalePolicy(lbCartridgeInfo.getDefaultAutoscalingPolicy());
+
+ lbDataCtxt.addLoadBalancedServiceProperty(lbRefProperty);
+ break;
+ }
+
+ } else if (Constants.SERVICE_AWARE_LOAD_BALANCER.equals(name)) {
+
+ if ("true".equals(value)) {
+
+ lbRefProperty.setValue(name);
+
+ CartridgeInfo lbCartridgeInfo;
+
+ try {
+ lbCartridgeInfo = CloudControllerServiceClient.getServiceClient().getCartridgeInfo(lbCartridgeType);
+
+ } catch (UnregisteredCartridgeException e) {
+ String message = lbCartridgeType + " is not a valid cartridgeSubscription type";
+ log.error(message);
+ throw e;
+
+ } catch (Exception e) {
+ String message = "Error getting info for " + lbCartridgeType;
+ log.error(message, e);
+ throw new ADCException(message, e);
+ }
+
+ lbDataCtxt.setLbCartridgeInfo(lbCartridgeInfo);
+
+ // add a property for the service type
+ Property loadBalancedServiceTypeProperty = new Property();
+ loadBalancedServiceTypeProperty.setName(Constants.LOAD_BALANCED_SERVICE_TYPE);
+ // set the load balanced service type
+ loadBalancedServiceTypeProperty.setValue(subscriptionData.getCartridgeType());
+
+ if (log.isDebugEnabled()) {
+ log.debug("This cartridge uses a service aware load balancer. [Type] " + subscriptionData.getCartridgeType());
+ }
+
+ try {
+
+ // get the valid policies for lb cartridge
+ DeploymentPolicy[] lbCartridgeDepPolicies = getAutoscalerServiceClient().getDeploymentPolicies(lbCartridgeType);
+ // traverse deployment policies of lb cartridge
+ for (DeploymentPolicy policy : lbCartridgeDepPolicies) {
+ // check existence of the subscribed policy
+ if (subscriptionData.getDeploymentPolicyName().equals(policy.getId())) {
+
+ if (!getAutoscalerServiceClient().checkServiceLBExistenceAgainstPolicy(subscriptionData.getCartridgeType(),
+ subscriptionData.getDeploymentPolicyName())) {
+
+ Properties lbProperties = new Properties();
+
+ // if LB cartridge definition has properties as well, combine
+ if (lbCartridgeInfo.getProperties() != null && lbCartridgeInfo.getProperties().length > 0) {
+ lbProperties.setProperties(combine(lbCartridgeInfo.getProperties(), new Property[]{lbRefProperty, loadBalancedServiceTypeProperty}));
+
+ } else {
+ lbProperties.setProperties(new Property[]{lbRefProperty, loadBalancedServiceTypeProperty});
+ }
+
+ // set a payload property for load balanced service type
+ Property payloadProperty = new Property();
+ payloadProperty.setName("LOAD_BALANCED_SERVICE_TYPE"); //TODO: refactor hardcoded name
+ payloadProperty.setValue(subscriptionData.getCartridgeType());
+
+ lbDataCtxt.addLBProperties(lbProperties);
+ }
+ }
+ }
+
+ } catch (Exception ex) {
+ // we don't need to throw the error here.
+ log.error(ex.getMessage(), ex);
+ }
+
+ // set deployment and autoscaling policies
+ lbDataCtxt.setDeploymentPolicy(subscriptionData.getDeploymentPolicyName());
+ lbDataCtxt.setAutoscalePolicy(lbCartridgeInfo.getDefaultAutoscalingPolicy());
+
+ lbDataCtxt.addLoadBalancedServiceProperty(lbRefProperty);
+ break;
+ }
+ }
+ }
+
+ return lbDataCtxt;
+ }
+
+ private static AutoscalerServiceClient getAutoscalerServiceClient () throws ADCException {
+
+ try {
+ return AutoscalerServiceClient.getServiceClient();
+
+ } catch (AxisFault axisFault) {
+ String errorMsg = "Error in getting AutoscalerServiceClient instance";
+ log.error(errorMsg, axisFault);
+ throw new ADCException (errorMsg, axisFault);
+ }
+ }
+
+ private static Property[] combine (Property[] propertyArray1, Property[] propertyArray2) {
+
+ int length = propertyArray1.length + propertyArray2.length;
+ Property[] combinedProperties = new Property[length];
+ System.arraycopy(propertyArray1, 0, combinedProperties, 0, propertyArray1.length);
+ System.arraycopy(propertyArray2, 0, combinedProperties, propertyArray1.length, propertyArray2.length);
+
+ return combinedProperties;
+ }
}
[07/12] adapting new changes, fixing conflicts and merging
Posted by is...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/09d0beff/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
index cafdb3f,f882461..e243ed8
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
@@@ -23,10 -23,8 +23,9 @@@ import org.apache.axis2.context.Configu
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy;
-import org.apache.stratos.cloud.controller.pojo.*;
-import org.apache.stratos.cloud.controller.pojo.Properties;
+import org.apache.stratos.cloud.controller.pojo.CartridgeConfig;
+import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
- import org.apache.stratos.cloud.controller.pojo.PersistanceMapping;
+import org.apache.stratos.cloud.controller.pojo.Property;
import org.apache.stratos.manager.client.AutoscalerServiceClient;
import org.apache.stratos.manager.client.CloudControllerServiceClient;
import org.apache.stratos.manager.deploy.service.Service;
@@@ -37,7 -35,8 +36,8 @@@ import org.apache.stratos.manager.excep
import org.apache.stratos.manager.manager.CartridgeSubscriptionManager;
import org.apache.stratos.manager.subscription.CartridgeSubscription;
import org.apache.stratos.manager.subscription.DataCartridgeSubscription;
++import org.apache.stratos.manager.subscription.PersistenceContext;
import org.apache.stratos.manager.subscription.SubscriptionData;
-import org.apache.stratos.manager.subscription.utils.CartridgeSubscriptionUtils;
import org.apache.stratos.manager.topology.model.TopologyClusterInformationModel;
import org.apache.stratos.manager.utils.ApplicationManagementUtil;
import org.apache.stratos.manager.utils.CartridgeConstants;
@@@ -809,15 -859,37 +860,13 @@@ public class ServiceUtils
throws ADCException, PolicyException, UnregisteredCartridgeException,
InvalidCartridgeAliasException, DuplicateCartridgeAliasException, RepositoryRequiredException,
AlreadySubscribedException, RepositoryCredentialsRequiredException, InvalidRepositoryException,
- RepositoryTransportException {
-
+ RepositoryTransportException, RestAPIException {
- // LB cartridges won't go thru this method.
-
- //TODO: this is a temp fix. proper fix is to move this logic to CartridgeSubscriptionManager
- // validate cartridge alias
- CartridgeSubscriptionUtils.validateCartridgeAlias(ApplicationManagementUtil.getTenantId(configurationContext), cartridgeInfoBean.getCartridgeType(), cartridgeInfoBean.getAlias());
-
- AutoscalerServiceClient autoscalerServiceClient = getAutoscalerServiceClient();
- CloudControllerServiceClient cloudControllerServiceClient =
- getCloudControllerServiceClient();
- CartridgeInfo cartridgeInfo;
-
- try {
- cartridgeInfo = cloudControllerServiceClient.getCartridgeInfo(cartridgeInfoBean.getCartridgeType());
- } catch (Exception e) {
- String msg = "Cannot get cartridge info: " + cartridgeInfoBean.getCartridgeType();
- log.error(msg, e);
- throw new ADCException(msg, e);
- }
-
- String cartridgeType = cartridgeInfoBean.getCartridgeType();
- String deploymentPolicy = cartridgeInfoBean.getDeploymentPolicy();
- String autoscalingPolicy = cartridgeInfoBean.getAutoscalePolicy();
- String dataCartridgeAlias = cartridgeInfoBean.getDataCartridgeAlias();
SubscriptionData subscriptionData = new SubscriptionData();
- subscriptionData.setCartridgeType(cartridgeType);
+ subscriptionData.setCartridgeType(cartridgeInfoBean.getCartridgeType());
subscriptionData.setCartridgeAlias(cartridgeInfoBean.getAlias().trim());
- //subscriptionData.setDataCartridgeAlias(dataCartridgeAlias);
- subscriptionData.setDataCartridgeAlias(dataCartridgeAlias);
- subscriptionData.setAutoscalingPolicyName(autoscalingPolicy);
- subscriptionData.setDeploymentPolicyName(deploymentPolicy);
+ subscriptionData.setAutoscalingPolicyName(cartridgeInfoBean.getAutoscalePolicy());
+ subscriptionData.setDeploymentPolicyName(cartridgeInfoBean.getDeploymentPolicy());
subscriptionData.setTenantDomain(tenantDomain);
subscriptionData.setTenantId(ApplicationManagementUtil.getTenantId(configurationContext));
subscriptionData.setTenantAdminUsername(tenantUsername);
@@@ -826,320 -898,303 +875,20 @@@
subscriptionData.setRepositoryUsername(cartridgeInfoBean.getRepoURL());
subscriptionData.setRepositoryPassword(cartridgeInfoBean.getRepoPassword());
- Properties properties = new Properties();
- if(cartridgeInfoBean.isPersistanceRequired()){
- /*
- PersistanceMapping persistanceMapping = new PersistanceMapping();
- persistanceMapping.setPersistanceRequired(persistanceMappingBean.persistanceRequired);
- persistanceMapping.setSize(persistanceMappingBean.size);
- persistanceMapping.setDevice(persistanceMappingBean.device);
- persistanceMapping.setRemoveOntermination(persistanceMappingBean.removeOnTermination);
- subscriptionData.setPersistanceMapping(persistanceMapping);
- */
-
- // Add persistance mapping properties to the subscription.
- Property persistanceRequiredProperty = new Property();
- persistanceRequiredProperty.setName(IS_VOLUME_REQUIRED);
- persistanceRequiredProperty.setValue(String.valueOf(cartridgeInfoBean.isPersistanceRequired()));
-
- Property sizeProperty = new Property();
- sizeProperty.setName(VOLUME_SIZE);
- sizeProperty.setValue(cartridgeInfoBean.getSize());
-
- Property deleteOnTerminationProperty = new Property();
- deleteOnTerminationProperty.setName(SHOULD_DELETE_VOLUME);
- deleteOnTerminationProperty.setValue(String.valueOf( cartridgeInfoBean.isRemoveOnTermination()));
-
- properties.setProperties(new Property[]{persistanceRequiredProperty,sizeProperty, deleteOnTerminationProperty});
- }
-
-
- // If multitenant, return for now. TODO -- fix properly
- if(cartridgeInfo != null && cartridgeInfo.getMultiTenant()) {
- log.info(" ******* MT cartridge ******* ");
-
- subscriptionData.setPrivateRepository(false);
- subscriptionData.setLbClusterId(null);
- subscriptionData.setProperties(null);
-
- CartridgeSubscription cartridgeSubscription =
- cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(subscriptionData);
- log.info(" --- ** -- ");
- return cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription, properties);
-
- }
-
- List<Property> lbRefProp = new ArrayList<Property>();
-
- // get lb config reference
- LoadbalancerConfig lbConfig = cartridgeInfo.getLbConfig();
- String lbClusterId = null;
-
- if (lbConfig == null || lbConfig.getProperties() == null) {
- if (log.isDebugEnabled()) {
- log.debug("This Service does not require a load balancer. " + "[Service Name] " +
- cartridgeType);
- }
- } else {
-
- Properties lbReferenceProperties = lbConfig.getProperties();
-
- Property property = new Property();
- property.setName(org.apache.stratos.messaging.util.Constants.LOAD_BALANCER_REF);
-
-
- for (org.apache.stratos.cloud.controller.pojo.Property prop : lbReferenceProperties.getProperties()) {
-
- String name = prop.getName();
- String value = prop.getValue();
-
- // TODO make following a chain of responsibility pattern
- if (Constants.NO_LOAD_BALANCER.equals(name)) {
- if ("true".equals(value)) {
- if (log.isDebugEnabled()) {
- log.debug("This cartridge does not require a load balancer. " +
- "[Type] " + cartridgeType);
- }
- property.setValue(name);
- lbRefProp.add(property);
- break;
- }
- } else if (Constants.EXISTING_LOAD_BALANCERS.equals(name)) {
- String clusterIdsVal = value;
- if (log.isDebugEnabled()) {
- log.debug("This cartridge refers to existing load balancers. " + "[Type] " +
- cartridgeType + "[Referenced Cluster Ids] " + clusterIdsVal);
- }
-
- String[] clusterIds = clusterIdsVal.split(",");
-
- for (String clusterId : clusterIds) {
- if (autoscalerServiceClient != null) {
- try {
- autoscalerServiceClient.checkLBExistenceAgainstPolicy(clusterId,
- deploymentPolicy);
- } catch (Exception ex) {
- // we don't need to throw the error here.
- log.error(ex.getMessage(), ex);
- }
- }
- }
-
- property.setValue(name);
- lbRefProp.add(property);
- break;
-
- } else if (Constants.DEFAULT_LOAD_BALANCER.equals(name)) {
-
- if ("true".equals(value)) {
-
- CartridgeInfo lbCartridgeInfo = null;
- String lbCartridgeType = lbConfig.getType();
- try {
- // retrieve lb Cartridge info
- if(lbCartridgeType != null) {
- lbCartridgeInfo = cloudControllerServiceClient.getCartridgeInfo(lbCartridgeType);
- }
- } catch (Exception e) {
- String msg = "Cannot get cartridge info: " + cartridgeType;
- log.error(msg, e);
- throw new ADCException(msg, e);
- }
-
- property.setValue(name);
- if (log.isDebugEnabled()) {
- log.debug("This cartridge uses default load balancer. " + "[Type] " +
- cartridgeType);
- }
- if (autoscalerServiceClient != null) {
- try {
- // get the valid policies for lb cartridge
- DeploymentPolicy[] lbCartridgeDepPolicies =
- autoscalerServiceClient.getDeploymentPolicies(lbCartridgeType);
- // traverse deployment policies of lb cartridge
- for (DeploymentPolicy policy : lbCartridgeDepPolicies) {
- // check existence of the subscribed policy
- if (deploymentPolicy.equals(policy.getId())) {
-
- if (!autoscalerServiceClient.checkDefaultLBExistenceAgainstPolicy(deploymentPolicy)) {
-
- // if lb cluster doesn't exist
- String lbAlias = "lb" + new Random().nextInt();
- if(lbCartridgeInfo != null) {
- lbCartridgeInfo.addProperties(property);
- lbClusterId = subscribeToLb(lbCartridgeType, cartridgeType,
- lbAlias,
- lbCartridgeInfo.getDefaultAutoscalingPolicy(),
- deploymentPolicy, configurationContext,
- tenantUsername, tenantDomain,
- lbCartridgeInfo.getProperties());
- } else {
- String msg = "Please specify a LB cartridge type for the cartridge: "
- + cartridgeType + " as category: " +
- Constants.DEFAULT_LOAD_BALANCER;
- log.error(msg);
- throw new ADCException(msg);
- }
- }
- }
- }
-
- } catch (Exception ex) {
- // we don't need to throw the error here.
- log.error(ex.getMessage(), ex);
- }
- }
-
- lbRefProp.add(property);
- break;
- }
-
- } else if (Constants.SERVICE_AWARE_LOAD_BALANCER.equals(name)) {
-
- if ("true".equals(value)) {
-
- CartridgeInfo lbCartridgeInfo = null;
- String lbCartridgeType = lbConfig.getType();
- try {
- // retrieve lb Cartridge info
- if(lbCartridgeType != null) {
- lbCartridgeInfo = cloudControllerServiceClient.getCartridgeInfo(lbCartridgeType);
- }
- } catch (Exception e) {
- String msg = "Cannot get cartridge info: " + cartridgeType;
- log.error(msg, e);
- throw new ADCException(msg, e);
- }
-
- // add a property for the service type
- Property loadBalancedServiceTypeProperty = new Property();
- loadBalancedServiceTypeProperty.setName(Constants.LOAD_BALANCED_SERVICE_TYPE);
-
- property.setValue(name);
- // set the load balanced service type
- loadBalancedServiceTypeProperty.setValue(cartridgeType);
- if (log.isDebugEnabled()) {
- log.debug("This cartridge uses a service aware load balancer. " +
- "[Type] " + cartridgeType);
- }
- if (autoscalerServiceClient != null) {
- try {
-
- // get the valid policies for lb cartridge
- DeploymentPolicy[] lbCartridgeDepPolicies =
- autoscalerServiceClient.getDeploymentPolicies(lbCartridgeType);
- // traverse deployment policies of lb cartridge
- for (DeploymentPolicy policy : lbCartridgeDepPolicies) {
- // check existence of the subscribed policy
- if (deploymentPolicy.equals(policy.getId())) {
-
- if (!autoscalerServiceClient.checkServiceLBExistenceAgainstPolicy(cartridgeType,
- deploymentPolicy)) {
-
- // if lb cluster doesn't exist
- String lbAlias =
- "lb" + cartridgeType +
- new Random().nextInt();
-
- if(lbCartridgeInfo != null) {
- lbCartridgeInfo.addProperties(property);
- lbCartridgeInfo.addProperties(loadBalancedServiceTypeProperty);
-
- lbClusterId = subscribeToLb(lbCartridgeType, cartridgeType,
- lbAlias,
- lbCartridgeInfo.getDefaultAutoscalingPolicy(),
- deploymentPolicy,
- configurationContext, tenantUsername,
- tenantDomain,
- lbCartridgeInfo.getProperties());
- } else {
- String msg = "Please specify a LB cartridge type for the cartridge: "
- + cartridgeType + " as category: " +
- Constants.SERVICE_AWARE_LOAD_BALANCER;
- log.error(msg);
- throw new ADCException(msg);
- }
- }
- }
- }
-
- } catch (Exception ex) {
- // we don't need to throw the error here.
- log.error(ex.getMessage(), ex);
- }
- }
+ if (cartridgeInfoBean.isPersistanceRequired()) {
- PersistanceMapping persistanceMapping = new PersistanceMapping();
- persistanceMapping.setPersistanceRequired(cartridgeInfoBean.isPersistanceRequired());
- persistanceMapping.setDevice(cartridgeInfoBean.getDevice());
- persistanceMapping.setSize(Integer.parseInt(cartridgeInfoBean.getSize()));
- persistanceMapping.setRemoveOntermination(cartridgeInfoBean.isRemoveOnTermination());
++ // Add persistence related properties to PersistenceContext
++ PersistenceContext persistenceContext = new PersistenceContext();
++ persistenceContext.setPersistanceRequiredProperty(IS_VOLUME_REQUIRED, String.valueOf(cartridgeInfoBean.isPersistanceRequired()));
++ persistenceContext.setSizeProperty(VOLUME_SIZE, cartridgeInfoBean.getSize());
++ persistenceContext.setDeleteOnTerminationProperty(SHOULD_DELETE_VOLUME, String.valueOf(cartridgeInfoBean.isRemoveOnTermination()));
- subscriptionData.setPersistanceMapping(persistanceMapping);
- lbRefProp.add(property);
- break;
- }
- }
- }
++ // set the PersistenceContext to to SubscriptionData
++ subscriptionData.setPersistanceCtxt(persistenceContext);
}
- subscriptionData.setPrivateRepository(cartridgeInfoBean.isPrivateRepo());
- subscriptionData.setLbClusterId(lbClusterId);
- subscriptionData.setProperties(lbRefProp.toArray(new Property[0]));
- CartridgeSubscription cartridgeSubscription =
- cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(subscriptionData);
-
-
- if (dataCartridgeAlias != null && !dataCartridgeAlias.trim().isEmpty()) {
-
- /*dataCartridgeAlias = dataCartridgeAlias.trim();
-
- CartridgeSubscription connectingCartridgeSubscription = null;
- try {
- connectingCartridgeSubscription =
- cartridgeSubsciptionManager.getCartridgeSubscription(tenantDomain,
- dataCartridgeAlias);
-
- } catch (NotSubscribedException e) {
- log.error(e.getMessage(), e);
- }
- if (connectingCartridgeSubscription != null) {
- try {
- cartridgeSubsciptionManager.connectCartridges(tenantDomain,
- cartridgeSubscription,
- connectingCartridgeSubscription.getAlias());
-
- } catch (NotSubscribedException e) {
- log.error(e.getMessage(), e);
-
- } catch (AxisFault axisFault) {
- log.error(axisFault.getMessage(), axisFault);
- }
- } else {
- log.error("Failed to connect. No cartridge subscription found for tenant " +
- ApplicationManagementUtil.getTenantId(configurationContext) +
- " with alias " + alias);
- }*/
- }
-
- for (Property lbRefProperty : lbRefProp) {
- properties.addProperties(lbRefProperty);
- }
-
- SubscriptionInfo registerCartridgeSubscription = cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription, properties);
-
- return registerCartridgeSubscription;
+ //subscribe
+ return cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(subscriptionData);
- // Properties properties = new Properties();
- // if(cartridgeInfoBean.isPersistanceRequired()){
- // /*
- // PersistanceMapping persistanceMapping = new PersistanceMapping();
- // persistanceMapping.setPersistanceRequired(persistanceMappingBean.persistanceRequired);
- // persistanceMapping.setSize(persistanceMappingBean.size);
- // persistanceMapping.setDevice(persistanceMappingBean.device);
- // persistanceMapping.setRemoveOntermination(persistanceMappingBean.removeOnTermination);
- // subscriptionData.setPersistanceMapping(persistanceMapping);
- // */
- //
- // // Add persistance mapping properties to the subscription.
- // Property persistanceRequiredProperty = new Property();
- // persistanceRequiredProperty.setName(IS_VOLUME_REQUIRED);
- // persistanceRequiredProperty.setValue(String.valueOf(cartridgeInfoBean.isPersistanceRequired()));
- //
- // Property sizeProperty = new Property();
- // sizeProperty.setName(VOLUME_SIZE);
- // sizeProperty.setValue(cartridgeInfoBean.getSize());
- //
- // Property deviceProperty = new Property();
- // deviceProperty.setName(DEVICE_NAME);
- // deviceProperty.setValue(String.valueOf(cartridgeInfoBean.getDevice()));
- //
- // Property deleteOnTerminationProperty = new Property();
- // deleteOnTerminationProperty.setName(SHOULD_DELETE_VOLUME);
- // deleteOnTerminationProperty.setValue(String.valueOf( cartridgeInfoBean.isRemoveOnTermination()));
- //
- // properties.setProperties(new Property[]{persistanceRequiredProperty,sizeProperty, deviceProperty, deleteOnTerminationProperty});
- // }
- //
- //
- // // If multitenant, return for now. TODO -- fix properly
- // if(cartridgeInfo != null && cartridgeInfo.getMultiTenant()) {
- // log.info(" ******* MT cartridge ******* ");
- //
- // subscriptionData.setPrivateRepository(false);
- // subscriptionData.setLbClusterId(null);
- // subscriptionData.setProperties(null);
- //
- // CartridgeSubscription cartridgeSubscription =
- // cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(subscriptionData);
- // log.info(" --- ** -- ");
- // return cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription, properties);
- //
- // }
- //
- // List<Property> lbRefProp = new ArrayList<Property>();
- //
- // // get lb config reference
- // LoadbalancerConfig lbConfig = cartridgeInfo.getLbConfig();
- // String lbClusterId = null;
- //
- // if (lbConfig == null || lbConfig.getProperties() == null) {
- // if (log.isDebugEnabled()) {
- // log.debug("This Service does not require a load balancer. " + "[Service Name] " +
- // cartridgeType);
- // }
- // } else {
- //
- // Properties lbReferenceProperties = lbConfig.getProperties();
- //
- // Property property = new Property();
- // property.setName(org.apache.stratos.messaging.util.Constants.LOAD_BALANCER_REF);
- //
- //
- // for (org.apache.stratos.cloud.controller.pojo.Property prop : lbReferenceProperties.getProperties()) {
- //
- // String name = prop.getName();
- // String value = prop.getValue();
- //
- // // TODO make following a chain of responsibility pattern
- // if (Constants.NO_LOAD_BALANCER.equals(name)) {
- // if ("true".equals(value)) {
- // if (log.isDebugEnabled()) {
- // log.debug("This cartridge does not require a load balancer. " +
- // "[Type] " + cartridgeType);
- // }
- // property.setValue(name);
- // lbRefProp.add(property);
- // break;
- // }
- // } else if (Constants.EXISTING_LOAD_BALANCERS.equals(name)) {
- // String clusterIdsVal = value;
- // if (log.isDebugEnabled()) {
- // log.debug("This cartridge refers to existing load balancers. " + "[Type] " +
- // cartridgeType + "[Referenced Cluster Ids] " + clusterIdsVal);
- // }
- //
- // String[] clusterIds = clusterIdsVal.split(",");
- //
- // for (String clusterId : clusterIds) {
- // if (autoscalerServiceClient != null) {
- // try {
- // autoscalerServiceClient.checkLBExistenceAgainstPolicy(clusterId,
- // deploymentPolicy);
- // } catch (Exception ex) {
- // // we don't need to throw the error here.
- // log.error(ex.getMessage(), ex);
- // }
- // }
- // }
- //
- // property.setValue(name);
- // lbRefProp.add(property);
- // break;
- //
- // } else if (Constants.DEFAULT_LOAD_BALANCER.equals(name)) {
- //
- // if ("true".equals(value)) {
- //
- // CartridgeInfo lbCartridgeInfo = null;
- // String lbCartridgeType = lbConfig.getType();
- // try {
- // // retrieve lb Cartridge info
- // if(lbCartridgeType != null) {
- // lbCartridgeInfo = cloudControllerServiceClient.getCartridgeInfo(lbCartridgeType);
- // }
- // } catch (Exception e) {
- // String msg = "Cannot get cartridge info: " + cartridgeType;
- // log.error(msg, e);
- // throw new ADCException(msg, e);
- // }
- //
- // property.setValue(name);
- // if (log.isDebugEnabled()) {
- // log.debug("This cartridge uses default load balancer. " + "[Type] " +
- // cartridgeType);
- // }
- // if (autoscalerServiceClient != null) {
- // try {
- // // get the valid policies for lb cartridge
- // DeploymentPolicy[] lbCartridgeDepPolicies =
- // autoscalerServiceClient.getDeploymentPolicies(lbCartridgeType);
- // // traverse deployment policies of lb cartridge
- // for (DeploymentPolicy policy : lbCartridgeDepPolicies) {
- // // check existence of the subscribed policy
- // if (deploymentPolicy.equals(policy.getId())) {
- //
- // if (!autoscalerServiceClient.checkDefaultLBExistenceAgainstPolicy(deploymentPolicy)) {
- //
- // // if lb cluster doesn't exist
- // String lbAlias = "lb" + new Random().nextInt();
- // if(lbCartridgeInfo != null) {
- // lbCartridgeInfo.addProperties(property);
- // lbClusterId = subscribeToLb(lbCartridgeType, cartridgeType,
- // lbAlias,
- // lbCartridgeInfo.getDefaultAutoscalingPolicy(),
- // deploymentPolicy, configurationContext,
- // tenantUsername, tenantDomain,
- // lbCartridgeInfo.getProperties());
- // } else {
- // String msg = "Please specify a LB cartridge type for the cartridge: "
- // + cartridgeType + " as category: " +
- // Constants.DEFAULT_LOAD_BALANCER;
- // log.error(msg);
- // throw new ADCException(msg);
- // }
- // }
- // }
- // }
- //
- // } catch (Exception ex) {
- // // we don't need to throw the error here.
- // log.error(ex.getMessage(), ex);
- // }
- // }
- //
- // lbRefProp.add(property);
- // break;
- // }
- //
- // } else if (Constants.SERVICE_AWARE_LOAD_BALANCER.equals(name)) {
- //
- // if ("true".equals(value)) {
- //
- // CartridgeInfo lbCartridgeInfo = null;
- // String lbCartridgeType = lbConfig.getType();
- // try {
- // // retrieve lb Cartridge info
- // if(lbCartridgeType != null) {
- // lbCartridgeInfo = cloudControllerServiceClient.getCartridgeInfo(lbCartridgeType);
- // }
- // } catch (Exception e) {
- // String msg = "Cannot get cartridge info: " + cartridgeType;
- // log.error(msg, e);
- // throw new ADCException(msg, e);
- // }
- //
- // // add a property for the service type
- // Property loadBalancedServiceTypeProperty = new Property();
- // loadBalancedServiceTypeProperty.setName(Constants.LOAD_BALANCED_SERVICE_TYPE);
- //
- // property.setValue(name);
- // // set the load balanced service type
- // loadBalancedServiceTypeProperty.setValue(cartridgeType);
- // if (log.isDebugEnabled()) {
- // log.debug("This cartridge uses a service aware load balancer. " +
- // "[Type] " + cartridgeType);
- // }
- // if (autoscalerServiceClient != null) {
- // try {
- //
- // // get the valid policies for lb cartridge
- // DeploymentPolicy[] lbCartridgeDepPolicies =
- // autoscalerServiceClient.getDeploymentPolicies(lbCartridgeType);
- // // traverse deployment policies of lb cartridge
- // for (DeploymentPolicy policy : lbCartridgeDepPolicies) {
- // // check existence of the subscribed policy
- // if (deploymentPolicy.equals(policy.getId())) {
- //
- // if (!autoscalerServiceClient.checkServiceLBExistenceAgainstPolicy(cartridgeType,
- // deploymentPolicy)) {
- //
- // // if lb cluster doesn't exist
- // String lbAlias =
- // "lb" + cartridgeType +
- // new Random().nextInt();
- //
- // if(lbCartridgeInfo != null) {
- // lbCartridgeInfo.addProperties(property);
- // lbCartridgeInfo.addProperties(loadBalancedServiceTypeProperty);
- //
- // lbClusterId = subscribeToLb(lbCartridgeType, cartridgeType,
- // lbAlias,
- // lbCartridgeInfo.getDefaultAutoscalingPolicy(),
- // deploymentPolicy,
- // configurationContext, tenantUsername,
- // tenantDomain,
- // lbCartridgeInfo.getProperties());
- // } else {
- // String msg = "Please specify a LB cartridge type for the cartridge: "
- // + cartridgeType + " as category: " +
- // Constants.SERVICE_AWARE_LOAD_BALANCER;
- // log.error(msg);
- // throw new ADCException(msg);
- // }
- // }
- // }
- // }
- //
- // } catch (Exception ex) {
- // // we don't need to throw the error here.
- // log.error(ex.getMessage(), ex);
- // }
- // }
- //
- // lbRefProp.add(property);
- // break;
- // }
- // }
- // }
- // }
- //
- // subscriptionData.setPrivateRepository(cartridgeInfoBean.isPrivateRepo());
- // subscriptionData.setLbClusterId(lbClusterId);
- // subscriptionData.setProperties(lbRefProp.toArray(new Property[0]));
- // CartridgeSubscription cartridgeSubscription =
- // cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(subscriptionData);
- //
- //
- // if (dataCartridgeAlias != null && !dataCartridgeAlias.trim().isEmpty()) {
- //
- // /*dataCartridgeAlias = dataCartridgeAlias.trim();
- //
- // CartridgeSubscription connectingCartridgeSubscription = null;
- // try {
- // connectingCartridgeSubscription =
- // cartridgeSubsciptionManager.getCartridgeSubscription(tenantDomain,
- // dataCartridgeAlias);
- //
- // } catch (NotSubscribedException e) {
- // log.error(e.getMessage(), e);
- // }
- // if (connectingCartridgeSubscription != null) {
- // try {
- // cartridgeSubsciptionManager.connectCartridges(tenantDomain,
- // cartridgeSubscription,
- // connectingCartridgeSubscription.getAlias());
- //
- // } catch (NotSubscribedException e) {
- // log.error(e.getMessage(), e);
- //
- // } catch (AxisFault axisFault) {
- // log.error(axisFault.getMessage(), axisFault);
- // }
- // } else {
- // log.error("Failed to connect. No cartridge subscription found for tenant " +
- // ApplicationManagementUtil.getTenantId(configurationContext) +
- // " with alias " + alias);
- // }*/
- // }
- //
- // for (Property lbRefProperty : lbRefProp) {
- // properties.addProperties(lbRefProperty);
- // }
- //
- // SubscriptionInfo registerCartridgeSubscription = cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription, properties);
- //
- // return registerCartridgeSubscription;
-
}
public static org.apache.stratos.rest.endpoint.bean.topology.Cluster getCluster (String cartridgeType, String subscriptionAlias, ConfigurationContext configurationContext) throws RestAPIException {
@@@ -1183,57 -1238,57 +932,8 @@@
new org.apache.stratos.rest.endpoint.bean.topology.Cluster[clusters.size()];
arrCluster = clusters.toArray(arrCluster);
return arrCluster;
--
--
--
- }
-
- // return the cluster id for the lb. This is a temp fix.
- private static String subscribeToLb(String cartridgeType, String loadBalancedCartridgeType, String lbAlias,
- String defaultAutoscalingPolicy, String deploymentPolicy,
- ConfigurationContext configurationContext, String userName, String tenantDomain, Property[] props) throws ADCException {
-
- CartridgeSubscription cartridgeSubscription;
-
- try {
- if(log.isDebugEnabled()) {
- log.debug("Subscribing to a load balancer [cartridge] "+cartridgeType+" [alias] "+lbAlias);
- }
-
- SubscriptionData subscriptionData = new SubscriptionData();
- subscriptionData.setCartridgeType(cartridgeType);
- subscriptionData.setCartridgeAlias(lbAlias.trim());
- subscriptionData.setAutoscalingPolicyName(defaultAutoscalingPolicy);
- subscriptionData.setDeploymentPolicyName(deploymentPolicy);
- subscriptionData.setTenantDomain(tenantDomain);
- subscriptionData.setTenantId(ApplicationManagementUtil.getTenantId(configurationContext));
- subscriptionData.setTenantAdminUsername(userName);
- subscriptionData.setRepositoryType("git");
- //subscriptionData.setProperties(props);
- subscriptionData.setPrivateRepository(false);
-
- cartridgeSubscription =
- cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(subscriptionData);
-
- //set a payload parameter to indicate the load balanced cartridge type
- cartridgeSubscription.getPayloadData().add("LOAD_BALANCED_SERVICE_TYPE", loadBalancedCartridgeType);
-
- Properties lbProperties = new Properties();
- lbProperties.setProperties(props);
- cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription, lbProperties);
-
- if(log.isDebugEnabled()) {
- log.debug("Successfully subscribed to a load balancer [cartridge] "+cartridgeType+" [alias] "+lbAlias);
- }
- } catch (Exception e) {
- String msg = "Error while subscribing to load balancer cartridge [type] "+cartridgeType;
- log.error(msg, e);
- throw new ADCException(msg, e);
- }
-
- return cartridgeSubscription.getClusterDomain();
}
- // return the cluster id for the lb. This is a temp fix.
- // private static String subscribeToLb(String cartridgeType, String loadBalancedCartridgeType, String lbAlias,
- // String defaultAutoscalingPolicy, String deploymentPolicy,
- // ConfigurationContext configurationContext, String userName, String tenantDomain, Property[] props) throws ADCException {
- //
- // CartridgeSubscription cartridgeSubscription;
- //
- // try {
- // if(log.isDebugEnabled()) {
- // log.debug("Subscribing to a load balancer [cartridge] "+cartridgeType+" [alias] "+lbAlias);
- // }
- //
- // SubscriptionData subscriptionData = new SubscriptionData();
- // subscriptionData.setCartridgeType(cartridgeType);
- // subscriptionData.setCartridgeAlias(lbAlias.trim());
- // subscriptionData.setAutoscalingPolicyName(defaultAutoscalingPolicy);
- // subscriptionData.setDeploymentPolicyName(deploymentPolicy);
- // subscriptionData.setTenantDomain(tenantDomain);
- // subscriptionData.setTenantId(ApplicationManagementUtil.getTenantId(configurationContext));
- // subscriptionData.setTenantAdminUsername(userName);
- // subscriptionData.setRepositoryType("git");
- // //subscriptionData.setProperties(props);
- // subscriptionData.setPrivateRepository(false);
- //
- // cartridgeSubscription =
- // cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(subscriptionData);
- //
- // //set a payload parameter to indicate the load balanced cartridge type
- // cartridgeSubscription.getPayloadData().add("LOAD_BALANCED_SERVICE_TYPE", loadBalancedCartridgeType);
- //
- // Properties lbProperties = new Properties();
- // lbProperties.setProperties(props);
- // cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription, lbProperties);
- //
- // if(log.isDebugEnabled()) {
- // log.debug("Successfully subscribed to a load balancer [cartridge] "+cartridgeType+" [alias] "+lbAlias);
- // }
- // } catch (Exception e) {
- // String msg = "Error while subscribing to load balancer cartridge [type] "+cartridgeType;
- // log.error(msg, e);
- // throw new ADCException(msg, e);
- // }
- //
- // return cartridgeSubscription.getClusterDomain();
- // }
-
static StratosAdminResponse unsubscribe(String alias, String tenantDomain) throws RestAPIException {
try {
[09/12] git commit: fixing confilcts and merging
Posted by is...@apache.org.
fixing confilcts and merging
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/bc336fa9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/bc336fa9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/bc336fa9
Branch: refs/heads/master
Commit: bc336fa979dbf6769f34119305a153dc64dc4e13
Parents: 09d0bef 5bd3ffe
Author: Isuru <is...@wso2.com>
Authored: Sun Mar 2 11:52:38 2014 +0530
Committer: Isuru <is...@wso2.com>
Committed: Sun Mar 2 11:52:38 2014 +0530
----------------------------------------------------------------------
.../cloud/controller/CloudControllerClient.java | 69 +-
.../exception/InvalidPartitionException.java | 8 +
.../exception/InvalidPolicyException.java | 8 +-
.../exception/NonExistingLBException.java | 13 +-
.../exception/PartitionValidationException.java | 18 +-
.../exception/PolicyValidationException.java | 14 +-
.../autoscaler/exception/SpawningException.java | 13 +-
.../exception/TerminationException.java | 12 +-
.../autoscaler/partition/PartitionManager.java | 8 +-
.../stratos/cli/RestCommandLineService.java | 44 +-
.../InvalidCartridgeDefinitionException.java | 13 +-
.../InvalidCartridgeTypeException.java | 13 +-
.../exception/InvalidClusterException.java | 13 +-
.../exception/InvalidHostException.java | 13 +-
.../exception/InvalidIaasProviderException.java | 13 +-
.../exception/InvalidMemberException.java | 13 +-
.../exception/InvalidPartitionException.java | 11 +-
.../exception/InvalidRegionException.java | 11 +
.../exception/InvalidXMLException.java | 11 +
.../exception/InvalidZoneException.java | 11 +
.../MalformedConfigurationFileException.java | 10 +
.../exception/NoInstanceFoundException.java | 11 +
.../exception/SerializationException.java | 11 +
.../UnregisteredCartridgeException.java | 11 +
.../exception/UnregisteredClusterException.java | 10 +
.../cloud/controller/iaases/AWSEC2Iaas.java | 10 +-
.../impl/CloudControllerServiceImpl.java | 233 +------
.../interfaces/CloudControllerService.java | 21 +-
.../util/CloudControllerConstants.java | 1 +
.../validate/AWSEC2PartitionValidator.java | 2 +-
.../OpenstackNovaPartitionValidator.java | 2 +-
.../manager/client/AutoscalerServiceClient.java | 268 +++-----
.../client/CloudControllerServiceClient.java | 61 +-
.../service/ServiceDeploymentManager.java | 5 +-
.../UnregisteredCartridgeException.java | 6 +
.../manager/CartridgeSubscriptionManager.java | 10 +-
.../utils/CartridgeSubscriptionUtils.java | 10 -
.../rest/endpoint/services/ServiceUtils.java | 440 ++++++++----
.../src/main/resources/AutoScalerService.wsdl | 678 ++++++++++---------
.../pom.xml | 2 +-
.../main/resources/CloudControllerService.wsdl | 96 ++-
41 files changed, 1224 insertions(+), 1003 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/bc336fa9/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/ServiceDeploymentManager.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/ServiceDeploymentManager.java
index a80aea0,11e57a1..3ea0fc6
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/ServiceDeploymentManager.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/ServiceDeploymentManager.java
@@@ -25,6 -26,8 +25,7 @@@ import org.apache.stratos.cloud.control
import org.apache.stratos.cloud.controller.pojo.LoadbalancerConfig;
import org.apache.stratos.cloud.controller.pojo.Properties;
import org.apache.stratos.cloud.controller.pojo.Property;
+ import org.apache.stratos.cloud.controller.stub.CloudControllerServiceUnregisteredCartridgeExceptionException;
-import org.apache.stratos.manager.client.AutoscalerServiceClient;
import org.apache.stratos.manager.client.CloudControllerServiceClient;
import org.apache.stratos.manager.deploy.service.multitenant.MultiTenantService;
import org.apache.stratos.manager.deploy.service.multitenant.lb.MultiTenantLBService;
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/bc336fa9/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
index 6f2880d,cb27159..5cb9721
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
@@@ -22,9 -22,9 +22,10 @@@ package org.apache.stratos.manager.mana
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
+import org.apache.stratos.cloud.controller.pojo.LoadbalancerConfig;
import org.apache.stratos.cloud.controller.pojo.Properties;
import org.apache.stratos.cloud.controller.pojo.Property;
+ import org.apache.stratos.cloud.controller.stub.CloudControllerServiceUnregisteredCartridgeExceptionException;
import org.apache.stratos.manager.client.CloudControllerServiceClient;
import org.apache.stratos.manager.dao.CartridgeSubscriptionInfo;
import org.apache.stratos.manager.dto.SubscriptionInfo;
@@@ -74,16 -85,33 +75,15 @@@ public class CartridgeSubscriptionManag
CartridgeInfo cartridgeInfo;
try {
- cartridgeInfo =
- CloudControllerServiceClient.getServiceClient().getCartridgeInfo(cartridgeType);
- /*
- if (props != null) {
- // TODO: temp fix, need to do a proper fix
- Property[] cartridgeInfoProperties = cartridgeInfo.getProperties();
- if(cartridgeInfoProperties != null) {
- int length = cartridgeInfoProperties.length + props.length;
- Property[] combined = new Property[length];
- System.arraycopy(cartridgeInfoProperties, 0, combined, 0, cartridgeInfoProperties.length);
- System.arraycopy(props, 0, combined, cartridgeInfoProperties.length, props.length);
- cartridgeInfo.setProperties(combined);
- } else {
- cartridgeInfo.setProperties(props);
- }
+ cartridgeInfo = CloudControllerServiceClient.getServiceClient().getCartridgeInfo(subscriptionData.getCartridgeType());
- } catch (UnregisteredCartridgeException e) {
- String message =
- subscriptionData.getCartridgeType() + " is not a valid cartridgeSubscription type. Please try again with a valid cartridgeSubscription type.";
- }
- */
+ } catch (CloudControllerServiceUnregisteredCartridgeExceptionException e) {
- String message =
- cartridgeType +
- " is not a valid cartridgeSubscription type. Please try again with a valid cartridgeSubscription type.";
++ String message = subscriptionData.getCartridgeType() + " is not a valid cartridgeSubscription type. Please try again with a valid cartridgeSubscription type.";
log.error(message);
- throw e;
+ throw new ADCException(message, e);
} catch (Exception e) {
- String message = "Error getting info for " + cartridgeType;
+ String message = "Error getting info for " + subscriptionData.getCartridgeType();
log.error(message, e);
throw new ADCException(message, e);
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/bc336fa9/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
index d318224,ee145f5..5fa3717
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
@@@ -221,242 -178,4 +221,232 @@@ public class CartridgeSubscriptionUtil
return source.substring(0, length);
}
+
+ public static LBDataContext getLoadBalancerDataContext (int tenantId, String serviceType, String deploymentPolicyName, LoadbalancerConfig lbConfig) throws UnregisteredCartridgeException, ADCException {
+
+ String lbCartridgeType = lbConfig.getType();
+
+ LBDataContext lbDataCtxt = new LBDataContext();
+ // set tenant Id
+ lbDataCtxt.setTenantId(tenantId);
+
+ Properties lbReferenceProperties = lbConfig.getProperties();
+
+ Property lbRefProperty = new Property();
+ lbRefProperty.setName(org.apache.stratos.messaging.util.Constants.LOAD_BALANCER_REF);
+
+ for (org.apache.stratos.cloud.controller.pojo.Property prop : lbReferenceProperties.getProperties()) {
+
+ String name = prop.getName();
+ String value = prop.getValue();
+
+ // TODO make following a chain of responsibility pattern
+ if (Constants.NO_LOAD_BALANCER.equals(name)) {
+
+ if ("true".equals(value)) {
+ if (log.isDebugEnabled()) {
+ log.debug("This cartridge does not require a load balancer. " + "[Type] " + serviceType);
+ }
+ lbRefProperty.setValue(name);
+ lbDataCtxt.addLoadBalancedServiceProperty(lbRefProperty);
+ break;
+ }
+ } else if (Constants.EXISTING_LOAD_BALANCERS.equals(name)) {
+
+ String clusterIdsVal = value;
+ if (log.isDebugEnabled()) {
+ log.debug("This cartridge refers to existing load balancers. " + "[Type] " + serviceType + "[Referenced Cluster Ids] " + clusterIdsVal);
+ }
+
+ String[] clusterIds = clusterIdsVal.split(",");
+
+ for (String clusterId : clusterIds) {
+ try {
+ AutoscalerServiceClient.getServiceClient().checkLBExistenceAgainstPolicy(clusterId, deploymentPolicyName);
+ } catch (Exception ex) {
+ // we don't need to throw the error here.
+ log.error(ex.getMessage(), ex);
+ }
+ }
+
+ lbRefProperty.setValue(name);
+ lbDataCtxt.addLoadBalancedServiceProperty(lbRefProperty);
+ break;
+
+ } else if (Constants.DEFAULT_LOAD_BALANCER.equals(name)) {
+
+ if ("true".equals(value)) {
+
+ lbRefProperty.setValue(name);
+
+ CartridgeInfo lbCartridgeInfo;
+
+ try {
+ lbCartridgeInfo = CloudControllerServiceClient.getServiceClient().getCartridgeInfo(lbCartridgeType);
+
- } catch (UnregisteredCartridgeException e) {
- String message = lbCartridgeType + " is not a valid cartridgeSubscription type";
- log.error(message);
- throw e;
-
+ } catch (Exception e) {
+ String message = "Error getting info for " + lbCartridgeType;
+ log.error(message, e);
+ throw new ADCException(message, e);
+ }
+
+ if (lbCartridgeInfo == null) {
+ String msg = "Please specify a LB cartridge type for the cartridge: " + serviceType + " as category: " +
+ Constants.DEFAULT_LOAD_BALANCER;
+ log.error(msg);
+ throw new ADCException(msg);
+ }
+
+ lbDataCtxt.setLbCartridgeInfo(lbCartridgeInfo);
+
+ if (log.isDebugEnabled()) {
+ log.debug("This cartridge uses default load balancer. " + "[Type] " + serviceType);
+ }
+
+ try {
+ // get the valid policies for lb cartridge
+ DeploymentPolicy[] lbCartridgeDepPolicies =
+ getAutoscalerServiceClient().getDeploymentPolicies(lbCartridgeType);
+ // traverse deployment policies of lb cartridge
+ for (DeploymentPolicy policy : lbCartridgeDepPolicies) {
+
+ // check existence of the subscribed policy
+ if (deploymentPolicyName.equals(policy.getId())) {
+
+ if (!getAutoscalerServiceClient().checkDefaultLBExistenceAgainstPolicy(deploymentPolicyName)) {
+
+ Properties lbProperties = new Properties();
+
+ // if LB cartridge definition has properties as well, combine
+ if (lbCartridgeInfo.getProperties() != null && lbCartridgeInfo.getProperties().length > 0) {
+ lbProperties.setProperties(combine(lbCartridgeInfo.getProperties(), new Property[]{lbRefProperty}));
+
+ } else {
+ lbProperties.setProperties(new Property[]{lbRefProperty});
+ }
+
+ lbDataCtxt.addLBProperties(lbProperties);
+ }
+ }
+ }
+
+ } catch (Exception ex) {
+ // we don't need to throw the error here.
+ log.error(ex.getMessage(), ex);
+ }
+
+ // set deployment and autoscaling policies
+ lbDataCtxt.setDeploymentPolicy(deploymentPolicyName);
+ lbDataCtxt.setAutoscalePolicy(lbCartridgeInfo.getDefaultAutoscalingPolicy());
+
+ lbDataCtxt.addLoadBalancedServiceProperty(lbRefProperty);
+ break;
+ }
+
+ } else if (Constants.SERVICE_AWARE_LOAD_BALANCER.equals(name)) {
+
+ if ("true".equals(value)) {
+
+ lbRefProperty.setValue(name);
+
+ CartridgeInfo lbCartridgeInfo;
+
+ try {
+ lbCartridgeInfo = CloudControllerServiceClient.getServiceClient().getCartridgeInfo(lbCartridgeType);
+
- } catch (UnregisteredCartridgeException e) {
- String message = lbCartridgeType + " is not a valid cartridgeSubscription type";
- log.error(message);
- throw e;
-
+ } catch (Exception e) {
+ String message = "Error getting info for " + lbCartridgeType;
+ log.error(message, e);
+ throw new ADCException(message, e);
+ }
+
+ if (lbCartridgeInfo == null) {
+ String msg = "Please specify a LB cartridge type for the cartridge: " + serviceType + " as category: " +
+ Constants.SERVICE_AWARE_LOAD_BALANCER;
+ log.error(msg);
+ throw new ADCException(msg);
+ }
+
+ lbDataCtxt.setLbCartridgeInfo(lbCartridgeInfo);
+
+ // add a property for the service type
+ Property loadBalancedServiceTypeProperty = new Property();
+ loadBalancedServiceTypeProperty.setName(Constants.LOAD_BALANCED_SERVICE_TYPE);
+ // set the load balanced service type
+ loadBalancedServiceTypeProperty.setValue(serviceType);
+
+ if (log.isDebugEnabled()) {
+ log.debug("This cartridge uses a service aware load balancer. [Type] " + serviceType);
+ }
+
+ try {
+
+ // get the valid policies for lb cartridge
+ DeploymentPolicy[] lbCartridgeDepPolicies = getAutoscalerServiceClient().getDeploymentPolicies(lbCartridgeType);
+ // traverse deployment policies of lb cartridge
+ for (DeploymentPolicy policy : lbCartridgeDepPolicies) {
+ // check existence of the subscribed policy
+ if (deploymentPolicyName.equals(policy.getId())) {
+
+ if (!getAutoscalerServiceClient().checkServiceLBExistenceAgainstPolicy(serviceType, deploymentPolicyName)) {
+
+ Properties lbProperties = new Properties();
+
+ // if LB cartridge definition has properties as well, combine
+ if (lbCartridgeInfo.getProperties() != null && lbCartridgeInfo.getProperties().length > 0) {
+ lbProperties.setProperties(combine(lbCartridgeInfo.getProperties(), new Property[]{lbRefProperty, loadBalancedServiceTypeProperty}));
+
+ } else {
+ lbProperties.setProperties(new Property[]{lbRefProperty, loadBalancedServiceTypeProperty});
+ }
+
+ // set a payload property for load balanced service type
+ Property payloadProperty = new Property();
+ payloadProperty.setName("LOAD_BALANCED_SERVICE_TYPE"); //TODO: refactor hardcoded name
+ payloadProperty.setValue(serviceType);
+
+ lbDataCtxt.addLBProperties(lbProperties);
+ }
+ }
+ }
+
+ } catch (Exception ex) {
+ // we don't need to throw the error here.
+ log.error(ex.getMessage(), ex);
+ }
+
+ // set deployment and autoscaling policies
+ lbDataCtxt.setDeploymentPolicy(deploymentPolicyName);
+ lbDataCtxt.setAutoscalePolicy(lbCartridgeInfo.getDefaultAutoscalingPolicy());
+
+ lbDataCtxt.addLoadBalancedServiceProperty(lbRefProperty);
+ break;
+ }
+ }
+ }
+
+ return lbDataCtxt;
+ }
+
+ private static AutoscalerServiceClient getAutoscalerServiceClient () throws ADCException {
+
+ try {
+ return AutoscalerServiceClient.getServiceClient();
+
+ } catch (AxisFault axisFault) {
+ String errorMsg = "Error in getting AutoscalerServiceClient instance";
+ log.error(errorMsg, axisFault);
+ throw new ADCException (errorMsg, axisFault);
+ }
+ }
+
+ private static Property[] combine (Property[] propertyArray1, Property[] propertyArray2) {
+
+ int length = propertyArray1.length + propertyArray2.length;
+ Property[] combinedProperties = new Property[length];
+ System.arraycopy(propertyArray1, 0, combinedProperties, 0, propertyArray1.length);
+ System.arraycopy(propertyArray2, 0, combinedProperties, propertyArray1.length, propertyArray2.length);
+
+ return combinedProperties;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/bc336fa9/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
index e243ed8,f95d935..ff52750
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
@@@ -23,9 -23,15 +23,15 @@@ import org.apache.axis2.context.Configu
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy;
+import org.apache.stratos.cloud.controller.pojo.CartridgeConfig;
+import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
+import org.apache.stratos.cloud.controller.pojo.Property;
+ import org.apache.stratos.autoscaler.stub.AutoScalerServiceInvalidPartitionExceptionException;
+ import org.apache.stratos.autoscaler.stub.AutoScalerServiceInvalidPolicyExceptionException;
-import org.apache.stratos.cloud.controller.pojo.*;
-import org.apache.stratos.cloud.controller.pojo.Properties;
+ import org.apache.stratos.cloud.controller.stub.CloudControllerServiceIllegalArgumentExceptionException;
+ import org.apache.stratos.cloud.controller.stub.CloudControllerServiceInvalidCartridgeDefinitionExceptionException;
+ import org.apache.stratos.cloud.controller.stub.CloudControllerServiceInvalidCartridgeTypeExceptionException;
+ import org.apache.stratos.cloud.controller.stub.CloudControllerServiceInvalidIaasProviderExceptionException;
-import org.apache.stratos.cloud.controller.stub.CloudControllerServiceUnregisteredCartridgeExceptionException;
import org.apache.stratos.manager.client.AutoscalerServiceClient;
import org.apache.stratos.manager.client.CloudControllerServiceClient;
import org.apache.stratos.manager.deploy.service.Service;
@@@ -875,19 -1024,302 +996,16 @@@ public class ServiceUtils
subscriptionData.setRepositoryUsername(cartridgeInfoBean.getRepoURL());
subscriptionData.setRepositoryPassword(cartridgeInfoBean.getRepoPassword());
- Properties properties = new Properties();
- if(cartridgeInfoBean.isPersistanceRequired()){
- /*
- PersistanceMapping persistanceMapping = new PersistanceMapping();
- persistanceMapping.setPersistanceRequired(persistanceMappingBean.persistanceRequired);
- persistanceMapping.setSize(persistanceMappingBean.size);
- persistanceMapping.setDevice(persistanceMappingBean.device);
- persistanceMapping.setRemoveOntermination(persistanceMappingBean.removeOnTermination);
- subscriptionData.setPersistanceMapping(persistanceMapping);
- */
-
- // Add persistance mapping properties to the subscription.
- Property persistanceRequiredProperty = new Property();
- persistanceRequiredProperty.setName(IS_VOLUME_REQUIRED);
- persistanceRequiredProperty.setValue(String.valueOf(cartridgeInfoBean.isPersistanceRequired()));
-
- Property sizeProperty = new Property();
- sizeProperty.setName(VOLUME_SIZE);
- sizeProperty.setValue(cartridgeInfoBean.getSize());
-
- Property deleteOnTerminationProperty = new Property();
- deleteOnTerminationProperty.setName(SHOULD_DELETE_VOLUME);
- deleteOnTerminationProperty.setValue(String.valueOf( cartridgeInfoBean.isRemoveOnTermination()));
-
- properties.setProperties(new Property[]{persistanceRequiredProperty,sizeProperty, deleteOnTerminationProperty});
- }
-
-
- // If multitenant, return for now. TODO -- fix properly
- if(cartridgeInfo != null && cartridgeInfo.getMultiTenant()) {
- log.info(" ******* MT cartridge ******* ");
-
- subscriptionData.setPrivateRepository(false);
- subscriptionData.setLbClusterId(null);
- subscriptionData.setProperties(null);
-
- CartridgeSubscription cartridgeSubscription =
- cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(subscriptionData);
- log.info(" --- ** -- ");
- return cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription, properties);
-
+ if (cartridgeInfoBean.isPersistanceRequired()) {
+ // Add persistence related properties to PersistenceContext
+ PersistenceContext persistenceContext = new PersistenceContext();
+ persistenceContext.setPersistanceRequiredProperty(IS_VOLUME_REQUIRED, String.valueOf(cartridgeInfoBean.isPersistanceRequired()));
+ persistenceContext.setSizeProperty(VOLUME_SIZE, cartridgeInfoBean.getSize());
+ persistenceContext.setDeleteOnTerminationProperty(SHOULD_DELETE_VOLUME, String.valueOf(cartridgeInfoBean.isRemoveOnTermination()));
-
- // set the PersistenceContext to to SubscriptionData
- subscriptionData.setPersistanceCtxt(persistenceContext);
}
-
- List<Property> lbRefProp = new ArrayList<Property>();
-
- // get lb config reference
- LoadbalancerConfig lbConfig = cartridgeInfo.getLbConfig();
- String lbClusterId = null;
-
- if (lbConfig == null || lbConfig.getProperties() == null) {
- if (log.isDebugEnabled()) {
- log.debug("This Service does not require a load balancer. " + "[Service Name] " +
- cartridgeType);
- }
- } else {
-
- Properties lbReferenceProperties = lbConfig.getProperties();
-
- Property property = new Property();
- property.setName(org.apache.stratos.messaging.util.Constants.LOAD_BALANCER_REF);
-
- for (org.apache.stratos.cloud.controller.pojo.Property prop : lbReferenceProperties.getProperties()) {
-
- String name = prop.getName();
- String value = prop.getValue();
-
- // TODO make following a chain of responsibility pattern
- if (Constants.NO_LOAD_BALANCER.equals(name)) {
- if ("true".equals(value)) {
- if (log.isDebugEnabled()) {
- log.debug("This cartridge does not require a load balancer. " +
- "[Type] " + cartridgeType);
- }
- property.setValue(name);
- lbRefProp.add(property);
- break;
- }
- } else if (Constants.EXISTING_LOAD_BALANCERS.equals(name)) {
- String clusterIdsVal = value;
- if (log.isDebugEnabled()) {
- log.debug("This cartridge refers to existing load balancers. " + "[Type] " +
- cartridgeType + "[Referenced Cluster Ids] " + clusterIdsVal);
- }
-
- String[] clusterIds = clusterIdsVal.split(",");
-
- for (String clusterId : clusterIds) {
- if (autoscalerServiceClient != null) {
- try {
- autoscalerServiceClient.checkLBExistenceAgainstPolicy(clusterId,
- deploymentPolicy);
- } catch (Exception ex) {
- // we don't need to throw the error here.
- log.error(ex.getMessage(), ex);
- }
- }
- }
-
- property.setValue(name);
- lbRefProp.add(property);
- break;
-
- } else if (Constants.DEFAULT_LOAD_BALANCER.equals(name)) {
-
- if ("true".equals(value)) {
-
- CartridgeInfo lbCartridgeInfo = null;
- String lbCartridgeType = lbConfig.getType();
- try {
- // retrieve lb Cartridge info
- if(lbCartridgeType != null) {
- lbCartridgeInfo = cloudControllerServiceClient.getCartridgeInfo(lbCartridgeType);
- }
- } catch (Exception e) {
- String msg = "Cannot get cartridge info: " + cartridgeType;
- log.error(msg, e);
- throw new ADCException(msg, e);
- }
-
- property.setValue(name);
- if (log.isDebugEnabled()) {
- log.debug("This cartridge uses default load balancer. " + "[Type] " +
- cartridgeType);
- }
- if (autoscalerServiceClient != null) {
- try {
- // get the valid policies for lb cartridge
- DeploymentPolicy[] lbCartridgeDepPolicies =
- autoscalerServiceClient.getDeploymentPolicies(lbCartridgeType);
- // traverse deployment policies of lb cartridge
- for (DeploymentPolicy policy : lbCartridgeDepPolicies) {
- // check existence of the subscribed policy
- if (deploymentPolicy.equals(policy.getId())) {
-
- if (!autoscalerServiceClient.checkDefaultLBExistenceAgainstPolicy(deploymentPolicy)) {
-
- // if lb cluster doesn't exist
- String lbAlias = "lb" + new Random().nextInt();
- if(lbCartridgeInfo != null) {
- lbCartridgeInfo.addProperties(property);
- lbClusterId = subscribeToLb(lbCartridgeType, cartridgeType,
- lbAlias,
- lbCartridgeInfo.getDefaultAutoscalingPolicy(),
- deploymentPolicy, configurationContext,
- tenantUsername, tenantDomain,
- lbCartridgeInfo.getProperties());
- } else {
- String msg = "Please specify a LB cartridge type for the cartridge: "
- + cartridgeType + " as category: " +
- Constants.DEFAULT_LOAD_BALANCER;
- log.error(msg);
- throw new ADCException(msg);
- }
- }
- }
- }
-
- } catch (Exception ex) {
- // we don't need to throw the error here.
- log.error(ex.getMessage(), ex);
- }
- }
-
- lbRefProp.add(property);
- break;
- }
-
- } else if (Constants.SERVICE_AWARE_LOAD_BALANCER.equals(name)) {
-
- if ("true".equals(value)) {
-
- CartridgeInfo lbCartridgeInfo = null;
- String lbCartridgeType = lbConfig.getType();
- try {
- // retrieve lb Cartridge info
- if(lbCartridgeType != null) {
- lbCartridgeInfo = cloudControllerServiceClient.getCartridgeInfo(lbCartridgeType);
- }
- } catch (Exception e) {
- String msg = "Cannot get cartridge info: " + cartridgeType+". Cause: "+e.getMessage();
- log.error(msg, e);
- throw new ADCException(msg, e);
- }
-
- // add a property for the service type
- Property loadBalancedServiceTypeProperty = new Property();
- loadBalancedServiceTypeProperty.setName(Constants.LOAD_BALANCED_SERVICE_TYPE);
-
- property.setValue(name);
- // set the load balanced service type
- loadBalancedServiceTypeProperty.setValue(cartridgeType);
- if (log.isDebugEnabled()) {
- log.debug("This cartridge uses a service aware load balancer. " +
- "[Type] " + cartridgeType);
- }
- if (autoscalerServiceClient != null) {
- try {
-
- // get the valid policies for lb cartridge
- DeploymentPolicy[] lbCartridgeDepPolicies =
- autoscalerServiceClient.getDeploymentPolicies(lbCartridgeType);
- // traverse deployment policies of lb cartridge
- for (DeploymentPolicy policy : lbCartridgeDepPolicies) {
- // check existence of the subscribed policy
- if (deploymentPolicy.equals(policy.getId())) {
-
- if (!autoscalerServiceClient.checkServiceLBExistenceAgainstPolicy(cartridgeType,
- deploymentPolicy)) {
-
- // if lb cluster doesn't exist
- String lbAlias =
- "lb" + cartridgeType +
- new Random().nextInt();
-
- if(lbCartridgeInfo != null) {
- lbCartridgeInfo.addProperties(property);
- lbCartridgeInfo.addProperties(loadBalancedServiceTypeProperty);
-
- lbClusterId = subscribeToLb(lbCartridgeType, cartridgeType,
- lbAlias,
- lbCartridgeInfo.getDefaultAutoscalingPolicy(),
- deploymentPolicy,
- configurationContext, tenantUsername,
- tenantDomain,
- lbCartridgeInfo.getProperties());
- } else {
- String msg = "Please specify a LB cartridge type for the cartridge: "
- + cartridgeType + " as category: " +
- Constants.SERVICE_AWARE_LOAD_BALANCER;
- log.error(msg);
- throw new ADCException(msg);
- }
- }
- }
- }
-
- } catch (Exception ex) {
- // we don't need to throw the error here.
- log.error(ex.getMessage(), ex);
- }
- }
-
- lbRefProp.add(property);
- break;
- }
- }
- }
- }
-
- subscriptionData.setPrivateRepository(cartridgeInfoBean.isPrivateRepo());
- subscriptionData.setLbClusterId(lbClusterId);
- subscriptionData.setProperties(lbRefProp.toArray(new Property[0]));
- CartridgeSubscription cartridgeSubscription =
- cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(subscriptionData);
-
-
- if (dataCartridgeAlias != null && !dataCartridgeAlias.trim().isEmpty()) {
-
- /*dataCartridgeAlias = dataCartridgeAlias.trim();
-
- CartridgeSubscription connectingCartridgeSubscription = null;
- try {
- connectingCartridgeSubscription =
- cartridgeSubsciptionManager.getCartridgeSubscription(tenantDomain,
- dataCartridgeAlias);
-
- } catch (NotSubscribedException e) {
- log.error(e.getMessage(), e);
- }
- if (connectingCartridgeSubscription != null) {
- try {
- cartridgeSubsciptionManager.connectCartridges(tenantDomain,
- cartridgeSubscription,
- connectingCartridgeSubscription.getAlias());
-
- } catch (NotSubscribedException e) {
- log.error(e.getMessage(), e);
-
- } catch (AxisFault axisFault) {
- log.error(axisFault.getMessage(), axisFault);
- }
- } else {
- log.error("Failed to connect. No cartridge subscription found for tenant " +
- ApplicationManagementUtil.getTenantId(configurationContext) +
- " with alias " + alias);
- }*/
- }
-
- for (Property lbRefProperty : lbRefProp) {
- properties.addProperties(lbRefProperty);
- }
-
- SubscriptionInfo registerCartridgeSubscription = cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription, properties);
-
- return registerCartridgeSubscription;
+ //subscribe
+ return cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(subscriptionData);
}
@@@ -932,8 -1364,57 +1050,55 @@@
new org.apache.stratos.rest.endpoint.bean.topology.Cluster[clusters.size()];
arrCluster = clusters.toArray(arrCluster);
return arrCluster;
+
-
-
}
+ // return the cluster id for the lb. This is a temp fix.
- private static String subscribeToLb(String cartridgeType, String loadBalancedCartridgeType, String lbAlias,
++ /*private static String subscribeToLb(String cartridgeType, String loadBalancedCartridgeType, String lbAlias,
+ String defaultAutoscalingPolicy, String deploymentPolicy,
+ ConfigurationContext configurationContext, String userName, String tenantDomain, Property[] props) throws ADCException {
+
+ CartridgeSubscription cartridgeSubscription;
+
+ try {
+ if(log.isDebugEnabled()) {
+ log.debug("Subscribing to a load balancer [cartridge] "+cartridgeType+" [alias] "+lbAlias);
+ }
+
+ SubscriptionData subscriptionData = new SubscriptionData();
+ subscriptionData.setCartridgeType(cartridgeType);
+ subscriptionData.setCartridgeAlias(lbAlias.trim());
+ subscriptionData.setAutoscalingPolicyName(defaultAutoscalingPolicy);
+ subscriptionData.setDeploymentPolicyName(deploymentPolicy);
+ subscriptionData.setTenantDomain(tenantDomain);
+ subscriptionData.setTenantId(ApplicationManagementUtil.getTenantId(configurationContext));
+ subscriptionData.setTenantAdminUsername(userName);
+ subscriptionData.setRepositoryType("git");
+ //subscriptionData.setProperties(props);
+ subscriptionData.setPrivateRepository(false);
+
+ cartridgeSubscription =
+ cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(subscriptionData);
+
+ //set a payload parameter to indicate the load balanced cartridge type
+ cartridgeSubscription.getPayloadData().add("LOAD_BALANCED_SERVICE_TYPE", loadBalancedCartridgeType);
+
+ Properties lbProperties = new Properties();
+ lbProperties.setProperties(props);
+ cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription, lbProperties);
+
+ if(log.isDebugEnabled()) {
+ log.debug("Successfully subscribed to a load balancer [cartridge] "+cartridgeType+" [alias] "+lbAlias);
+ }
+ } catch (Exception e) {
+ String msg = "Error while subscribing to load balancer cartridge [type] "+cartridgeType+". Cause: "+e.getMessage();
+ log.error(msg, e);
+ throw new ADCException(msg, e);
+ }
+
+ return cartridgeSubscription.getClusterDomain();
- }
++ } */
+
static StratosAdminResponse unsubscribe(String alias, String tenantDomain) throws RestAPIException {
try {
[10/12] git commit: changing subscription flow
Posted by is...@apache.org.
changing subscription flow
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/e9104e0d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/e9104e0d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/e9104e0d
Branch: refs/heads/master
Commit: e9104e0d7e7804ccac003690b26a999dd88e102e
Parents: bc336fa
Author: Isuru <is...@wso2.com>
Authored: Sun Mar 2 16:35:05 2014 +0530
Committer: Isuru <is...@wso2.com>
Committed: Sun Mar 2 16:35:05 2014 +0530
----------------------------------------------------------------------
.../manager/CartridgeSubscriptionManager.java | 34 +++++++++-----------
.../rest/endpoint/services/ServiceUtils.java | 1 +
2 files changed, 17 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e9104e0d/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
index 5cb9721..3703856 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
@@ -96,6 +96,8 @@ public class CartridgeSubscriptionManager {
Properties serviceCartridgeSubscriptionProperties = null;
LBDataContext lbDataCtxt = null;
+ CartridgeSubscription lbCartridgeSubscription = null;
+ Properties lbCartridgeSubscriptionProperties = null;
// get lb config reference
LoadbalancerConfig lbConfig = cartridgeInfo.getLbConfig();
@@ -112,16 +114,11 @@ public class CartridgeSubscriptionManager {
subscriptionData.getDeploymentPolicyName(), lbConfig);
// subscribe to LB
- CartridgeSubscription lbCartridgeSubscription = subscribeToLB (subscriptionData, lbDataCtxt);
+ lbCartridgeSubscription = subscribeToLB (subscriptionData, lbDataCtxt);
- if (lbCartridgeSubscription != null) {
- // register LB cartridge subscription
- Properties lbCartridgeSubscriptionProperties = new Properties();
- if (lbDataCtxt.getLbProperperties() != null && !lbDataCtxt.getLbProperperties().isEmpty()) {
- lbCartridgeSubscriptionProperties.setProperties(lbDataCtxt.getLbProperperties().toArray(new Property[0]));
- }
-
- registerCartridgeSubscription(lbCartridgeSubscription, lbCartridgeSubscriptionProperties);
+ lbCartridgeSubscriptionProperties = new Properties();
+ if (lbDataCtxt.getLbProperperties() != null && !lbDataCtxt.getLbProperperties().isEmpty()) {
+ lbCartridgeSubscriptionProperties.setProperties(lbDataCtxt.getLbProperperties().toArray(new Property[0]));
}
}
@@ -142,6 +139,11 @@ public class CartridgeSubscriptionManager {
}
}
+ if (lbCartridgeSubscription != null) {
+ // register LB cartridge subscription
+ registerCartridgeSubscription(lbCartridgeSubscription, lbCartridgeSubscriptionProperties);
+ }
+
// register service cartridge subscription
return registerCartridgeSubscription(serviceCartridgeSubscription, serviceCartridgeSubscriptionProperties);
}
@@ -206,10 +208,6 @@ public class CartridgeSubscriptionManager {
" subscribed to " + "] Cartridge with Alias " + lbAlias + ", Cartridge Type: " + lbDataContext.getLbCartridgeInfo().getType() +
", Autoscale Policy: " + lbDataContext.getAutoscalePolicy() + ", Deployment Policy: " + lbDataContext.getDeploymentPolicy());
- // Publish tenant subscribed event to message broker
- CartridgeSubscriptionUtils.publishTenantSubscribedEvent(cartridgeSubscription.getSubscriber().getTenantId(),
- cartridgeSubscription.getCartridgeInfo().getType());
-
return cartridgeSubscription;
}
@@ -258,11 +256,6 @@ public class CartridgeSubscriptionManager {
subscriptionData.getCartridgeType() + ", Repo URL: " + subscriptionData.getRepositoryURL() + ", Autoscale Policy: " +
subscriptionData.getAutoscalingPolicyName() + ", Deployment Policy: " + subscriptionData.getDeploymentPolicyName());
-
- // Publish tenant subscribed event to message broker
- CartridgeSubscriptionUtils.publishTenantSubscribedEvent(cartridgeSubscription.getSubscriber().getTenantId(),
- cartridgeSubscription.getCartridgeInfo().getType());
-
return cartridgeSubscription;
}
@@ -294,6 +287,11 @@ public class CartridgeSubscriptionManager {
}
log.info("Successful Subscription: " + cartridgeSubscription.toString());
+
+ // Publish tenant subscribed event to message broker
+ CartridgeSubscriptionUtils.publishTenantSubscribedEvent(cartridgeSubscription.getSubscriber().getTenantId(),
+ cartridgeSubscription.getCartridgeInfo().getType());
+
return ApplicationManagementUtil.
createSubscriptionResponse(cartridgeSubscriptionInfo, cartridgeSubscription.getRepository());
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e9104e0d/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
index ff52750..c24f0c4 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
@@ -1002,6 +1002,7 @@ public class ServiceUtils {
persistenceContext.setPersistanceRequiredProperty(IS_VOLUME_REQUIRED, String.valueOf(cartridgeInfoBean.isPersistanceRequired()));
persistenceContext.setSizeProperty(VOLUME_SIZE, cartridgeInfoBean.getSize());
persistenceContext.setDeleteOnTerminationProperty(SHOULD_DELETE_VOLUME, String.valueOf(cartridgeInfoBean.isRemoveOnTermination()));
+ subscriptionData.setPersistanceCtxt(persistenceContext);
}
//subscribe
[06/12] git commit: adding a check of null
Posted by is...@apache.org.
adding a check of null
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/ba644847
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/ba644847
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/ba644847
Branch: refs/heads/master
Commit: ba6448470d48ad35c31abf83e7fc00d26f5a5afd
Parents: e79a7e2
Author: Isuru <is...@wso2.com>
Authored: Sun Feb 16 20:12:10 2014 +0530
Committer: Isuru <is...@wso2.com>
Committed: Sun Feb 16 20:12:10 2014 +0530
----------------------------------------------------------------------
.../utils/CartridgeSubscriptionUtils.java | 14 ++++++++++++++
1 file changed, 14 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ba644847/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
index 122fa85..d318224 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
@@ -295,6 +295,13 @@ public class CartridgeSubscriptionUtils {
throw new ADCException(message, e);
}
+ if (lbCartridgeInfo == null) {
+ String msg = "Please specify a LB cartridge type for the cartridge: " + serviceType + " as category: " +
+ Constants.DEFAULT_LOAD_BALANCER;
+ log.error(msg);
+ throw new ADCException(msg);
+ }
+
lbDataCtxt.setLbCartridgeInfo(lbCartridgeInfo);
if (log.isDebugEnabled()) {
@@ -363,6 +370,13 @@ public class CartridgeSubscriptionUtils {
throw new ADCException(message, e);
}
+ if (lbCartridgeInfo == null) {
+ String msg = "Please specify a LB cartridge type for the cartridge: " + serviceType + " as category: " +
+ Constants.SERVICE_AWARE_LOAD_BALANCER;
+ log.error(msg);
+ throw new ADCException(msg);
+ }
+
lbDataCtxt.setLbCartridgeInfo(lbCartridgeInfo);
// add a property for the service type
[02/12] git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/incubator-stratos into
lb_logic_refactoring
Posted by is...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-stratos into lb_logic_refactoring
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/eaedb07c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/eaedb07c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/eaedb07c
Branch: refs/heads/master
Commit: eaedb07ca0dec60fc22e86bd450a8817be8d83d8
Parents: 459ebb4 d2be6fe
Author: Isuru <is...@wso2.com>
Authored: Sat Feb 15 13:15:12 2014 +0530
Committer: Isuru <is...@wso2.com>
Committed: Sat Feb 15 13:15:12 2014 +0530
----------------------------------------------------------------------
.gitignore | 3 +
.../autoscaler/NetworkPartitionLbHolder.java | 41 +-
.../stratos/autoscaler/PartitionContext.java | 17 +
.../topology/AutoscalerTopologyReceiver.java | 51 +-
.../autoscaler/partition/PartitionManager.java | 14 +
.../stratos/cartridge/agent/CartridgeAgent.java | 72 +-
.../apache/stratos/cartridge/agent/Main.java | 1 +
.../config/CartridgeAgentConfiguration.java | 15 +
.../agent/data/publisher/DataContext.java | 52 ++
.../agent/data/publisher/DataPublisher.java | 97 ++
.../publisher/DataPublisherConfiguration.java | 161 ++++
.../exception/DataPublisherException.java | 31 +
.../agent/data/publisher/log/Constants.java | 29 +
.../publisher/log/FileBasedLogPublisher.java | 109 +++
.../agent/data/publisher/log/LogPublisher.java | 49 +
.../data/publisher/log/LogPublisherManager.java | 105 +++
.../publisher/HealthStatisticsNotifier.java | 2 +-
.../publisher/HealthStatisticsReader.java | 3 +-
.../agent/util/CartridgeAgentConstants.java | 3 +
.../agent/util/CartridgeAgentUtils.java | 12 +-
.../java/org/apache/stratos/cli/CliTool.java | 2 +-
.../stratos/cli/CommandLineApplication.java | 32 +-
.../apache/stratos/cli/GenericRestClient.java | 4 +-
.../java/org/apache/stratos/cli/RestClient.java | 38 +-
.../stratos/cli/RestCommandLineService.java | 624 ++++++++++---
.../apache/stratos/cli/StratosApplication.java | 40 +-
.../stratos/cli/beans/cartridge/Cartridge.java | 18 +
.../beans/cartridge/ServiceDefinitionBean.java | 86 ++
.../cli/commands/ActivateTenantCommand.java | 70 ++
.../cli/commands/DeactivateTenantCommand.java | 70 ++
.../cli/commands/DeleteTenantCommand.java | 70 ++
.../DeployServiceDeploymentCommand.java | 139 +++
.../DescribeAutoScalingPolicyCommand.java | 2 +-
.../stratos/cli/commands/ExitCommand.java | 7 +-
.../cli/commands/ListDeployServiceCommand.java | 65 ++
.../UndeployCartridgeDefinitionCommand.java | 70 ++
.../UndeployServiceDefinitionCommand.java | 70 ++
.../apache/stratos/cli/utils/CliConstants.java | 36 +-
.../org.apache.stratos.cloud.controller/pom.xml | 3 -
.../axiom/parser/CartridgeConfigParser.java | 384 --------
.../parser/CloudControllerConfigParser.java | 2 +-
.../cloud/controller/iaases/AWSEC2Iaas.java | 114 +++
.../controller/iaases/OpenstackNovaIaas.java | 134 ++-
.../cloud/controller/iaases/VCloudIaas.java | 24 +
.../impl/CloudControllerServiceImpl.java | 104 ++-
.../cloud/controller/interfaces/Iaas.java | 29 +
.../jcloud/ComputeServiceBuilderUtil.java | 5 +
.../cloud/controller/pojo/CartridgeConfig.java | 10 +
.../cloud/controller/pojo/CartridgeInfo.java | 28 +-
.../cloud/controller/pojo/ClusterContext.java | 53 +-
.../cloud/controller/pojo/IaasProvider.java | 9 +
.../cloud/controller/pojo/MemberContext.java | 10 +
.../controller/pojo/PersistanceMapping.java | 27 +-
.../runtime/FasterLookUpDataHolder.java | 223 +----
.../controller/topology/TopologyBuilder.java | 6 +-
.../topology/TopologyEventPublisher.java | 4 +-
.../controller/util/CloudControllerUtil.java | 57 +-
.../validate/AWSEC2PartitionValidator.java | 2 +-
.../OpenstackNovaPartitionValidator.java | 2 +-
.../axiom/FasterLookupDataHolderTest.java | 92 ++
.../balancer/algorithm/AlgorithmContext.java | 10 +-
.../balancer/cache/AlgorithmContextCache.java | 45 +
.../load/balancer/cache/LoadBalancerCache.java | 130 +++
.../stratos/load/balancer/util/Constants.java | 3 +
.../balancer/test/RoundRobinAlgorithmTest.java | 70 --
.../console/cartridge_info.jag | 9 +
.../console/cartridges.jag | 4 +-
.../console/config/console.js | 23 +-
.../console/config/console.json | 8 +-
.../console/configure_stratos.jag | 20 +-
.../console/configure_stratos_wizard.jag | 16 +-
.../controllers/cartridgeDefintionSubmit.jag | 7 +-
.../controllers/cartridgeSubscribeSubmit.jag | 10 +
.../controllers/cartridgeUnsubscribeSubmit.jag | 11 +
.../console/controllers/login.jag | 2 +-
.../console/controllers/loginSubmit.jag | 3 +-
.../console/controllers/logout.jag | 5 +-
.../console/controllers/router.jag | 27 +-
.../console/controllers/wizardSubmit.jag | 33 +-
.../console/index.jag | 1 -
.../console/lbs.jag | 20 -
.../console/modules/pinch.min.js | 4 +
.../console/subscribe_cartridge.jag | 6 +-
.../console/themes/theme1/pages/index.hbs | 19 +
.../themes/theme1/partials/cartridge_info.hbs | 37 +
.../themes/theme1/partials/cartridges.hbs | 25 +-
.../partials/configure_stratos_wizard.hbs | 779 ++++++++--------
.../console/themes/theme1/partials/header.hbs | 242 +++--
.../console/themes/theme1/partials/lbs.hbs | 88 --
.../themes/theme1/partials/mycartridges.hbs | 25 +-
.../theme1/partials/subscribe_cartridge.hbs | 101 ++-
.../themes/theme1/partials/tenant_new.hbs | 4 +-
.../theme1/renderers/cartridge_deployments.js | 45 -
.../themes/theme1/renderers/cartridge_info.js | 42 +
.../themes/theme1/renderers/cartridges.js | 11 +-
.../theme1/renderers/configure_stratos.js | 54 +-
.../renderers/configure_stratos_wizard.js | 55 +-
.../console/themes/theme1/renderers/index.js | 18 +-
.../console/themes/theme1/renderers/lbs.js | 47 -
.../theme1/renderers/mt_service_deployments.js | 48 -
.../theme1/renderers/partition_deployments.js | 46 -
.../theme1/renderers/policy_deployments.js | 46 -
.../theme1/renderers/subscribe_cartridge.js | 5 +-
.../console/themes/theme1/theme.js | 7 +
.../console/themes/theme1/ui/css/main.css | 66 +-
.../themes/theme1/ui/custom-fonts/style.css | 25 +-
.../console/themes/theme1/ui/js/mycartridges.js | 12 +
.../console/themes/theme1/ui/js/popup.js | 80 ++
.../console/themes/theme1/ui/js/wizard.js | 32 +-
.../console/util/utility.jag | 85 +-
.../client/CloudControllerServiceClient.java | 6 +-
.../DataCartridgeSubscriptionConnector.java | 34 +-
.../stratos/manager/deploy/service/Service.java | 7 +-
.../service/ServiceDeploymentManager.java | 24 +
.../apache/stratos/manager/dto/Cartridge.java | 76 +-
.../internal/ADCManagementServerComponent.java | 2 -
.../manager/lookup/LookupDataHolder.java | 21 +
.../manager/lookup/SubscriptionContext.java | 2 +
.../manager/CartridgeSubscriptionManager.java | 123 ++-
.../manager/persistence/PersistenceManager.java | 2 +
.../RegistryBasedPersistenceManager.java | 95 ++
.../DataInsertionAndRetrievalManager.java | 20 +
.../service/ApplicationManagementService.java | 677 --------------
.../InstanceInformationManagementService.java | 58 --
.../service/RepoNotificationService.java | 128 ---
.../manager/service/RepositoryInfoBean.java | 3 +-
.../subscription/CartridgeSubscription.java | 97 +-
.../subscription/DataCartridgeSubscription.java | 6 +-
.../manager/subscription/SubscriptionData.java | 172 ++++
.../SubscriptionSingleTenantBehaviour.java | 12 +-
.../utils/CartridgeSubscriptionUtils.java | 9 +-
.../model/TopologyClusterInformationModel.java | 2 +-
.../utils/ApplicationManagementUtil.java | 860 +-----------------
.../manager/utils/CartridgeConstants.java | 23 -
.../manager/utils/PersistenceManager.java | 892 -------------------
.../manager/utils/RepositoryFactory.java | 131 ---
.../stratos/manager/utils/StratosDBUtils.java | 213 -----
.../src/main/resources/META-INF/services.xml | 57 +-
.../messaging/domain/topology/Service.java | 4 +-
.../event/topology/ClusterRemovedEvent.java | 8 +-
.../stratos/messaging/util/Constants.java | 11 +-
.../rest/endpoint/bean/CartridgeInfoBean.java | 36 +
.../stratos/rest/endpoint/bean/Error.java | 25 +
.../endpoint/bean/StratosAdminResponse.java | 36 +
.../definition/CartridgeDefinitionBean.java | 2 +
.../definition/PersistanceMappingBean.java | 4 +-
.../bean/util/converter/PojoConverter.java | 30 +-
.../stratos/rest/endpoint/mock/MockContext.java | 43 +
.../rest/endpoint/mock/StratosTestAdmin.java | 56 +-
.../rest/endpoint/services/ServiceUtils.java | 438 ++++++---
.../rest/endpoint/services/StratosAdmin.java | 328 +++++--
.../main/webapp/stratos/WEB-INF/cxf-servlet.xml | 2 +-
.../resources/conf/cartridge-config.properties | 64 --
.../src/main/resources/p2.inf | 1 -
.../distribution/src/main/conf/autoscaler.xml | 3 +
.../distribution/src/main/bin/stratos.sh | 12 +-
.../distribution/src/main/conf/axis2.xml | 125 ++-
.../load-balancer/modules/integration/pom.xml | 19 +-
.../tests/AlgorithmContextCacheTest.java | 55 ++
.../tests/LoadBalancerTestServerManager.java | 69 ++
.../tests/RoundRobinAlgorithmTest.java | 70 ++
.../tests/LoadBalancerTestServerManager.java | 53 --
.../src/test/resources/instrumentation.txt | 2 +-
.../src/test/resources/loadbalancer.conf | 142 +++
.../integration/src/test/resources/testng.xml | 31 +
.../src/main/conf/cartridge-config.properties | 42 +-
.../main/resources/CloudControllerService.wsdl | 32 +-
.../puppet/etc/puppet/files/cartridge-agent.sh | 13 +
tools/puppet/manifests/classes/lb_cartridge.pp | 12 +-
tools/puppet/manifests/classes/mysql.pp | 4 +-
tools/puppet/manifests/classes/php_cartridge.pp | 12 +-
tools/puppet/manifests/nodes.pp | 104 ++-
tools/stratos-installer/README.txt | 17 +-
tools/stratos-installer/conf/setup.conf | 52 +-
.../cc/repository/conf/cloud-controller.xml | 1 -
.../config/cep/repository/conf/jndi.properties | 16 +-
.../repository/conf/cartridge-config.properties | 27 -
tools/stratos-installer/ec2.sh | 12 -
tools/stratos-installer/openstack.sh | 9 -
tools/stratos-installer/setup.sh | 80 +-
180 files changed, 6295 insertions(+), 5702 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/eaedb07c/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
index e80b921,6ea9cb2..d71e107
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
@@@ -201,233 -167,13 +201,240 @@@ public class CartridgeSubscriptionUtil
public static boolean isAliasTaken (int tenantId, String alias) {
DataInsertionAndRetrievalManager dataInsertionAndRetrievalManager = new DataInsertionAndRetrievalManager();
- return (dataInsertionAndRetrievalManager.getCartridgeSubscription(tenantId, alias) == null) ? false : true;
+ // return (dataInsertionAndRetrievalManager.getCartridgeSubscription(tenantId, alias) == null) ? false : true;
+ // fixing STRATOS-427, making the alias globally unique
+ return (dataInsertionAndRetrievalManager.getCartridgeSubscriptionForAlias(alias) == null) ? false : true;
+ }
+
+ public static String limitLengthOfString (String source, int length) {
+
+ return source.substring(0, length);
}
+
+ public static LBDataContext getLoadBalancerDataContext (SubscriptionData subscriptionData, LoadbalancerConfig lbConfig) throws UnregisteredCartridgeException, ADCException {
+
+ String lbCartridgeType = lbConfig.getType();
+
+ LBDataContext lbDataCtxt = new LBDataContext();
+ // set tenant Id
+ lbDataCtxt.setTenantId(subscriptionData.getTenantId());
+
+ Properties lbReferenceProperties = lbConfig.getProperties();
+
+ Property lbRefProperty = new Property();
+ lbRefProperty.setName(org.apache.stratos.messaging.util.Constants.LOAD_BALANCER_REF);
+
+ for (org.apache.stratos.cloud.controller.pojo.Property prop : lbReferenceProperties.getProperties()) {
+
+ String name = prop.getName();
+ String value = prop.getValue();
+
+ // TODO make following a chain of responsibility pattern
+ if (Constants.NO_LOAD_BALANCER.equals(name)) {
+
+ if ("true".equals(value)) {
+ if (log.isDebugEnabled()) {
+ log.debug("This cartridge does not require a load balancer. " +
+ "[Type] " + subscriptionData.getCartridgeType());
+ }
+ lbRefProperty.setValue(name);
+ lbDataCtxt.addLoadBalancedServiceProperty(lbRefProperty);
+ break;
+ }
+ } else if (Constants.EXISTING_LOAD_BALANCERS.equals(name)) {
+
+ String clusterIdsVal = value;
+ if (log.isDebugEnabled()) {
+ log.debug("This cartridge refers to existing load balancers. " + "[Type] " +
+ subscriptionData.getCartridgeType() + "[Referenced Cluster Ids] " + clusterIdsVal);
+ }
+
+ String[] clusterIds = clusterIdsVal.split(",");
+
+ for (String clusterId : clusterIds) {
+ try {
+ AutoscalerServiceClient.getServiceClient().checkLBExistenceAgainstPolicy(clusterId, subscriptionData.getDeploymentPolicyName());
+ } catch (Exception ex) {
+ // we don't need to throw the error here.
+ log.error(ex.getMessage(), ex);
+ }
+ }
+
+ lbRefProperty.setValue(name);
+ lbDataCtxt.addLoadBalancedServiceProperty(lbRefProperty);
+ break;
+
+ } else if (Constants.DEFAULT_LOAD_BALANCER.equals(name)) {
+
+ if ("true".equals(value)) {
+
+ lbRefProperty.setValue(name);
+
+ CartridgeInfo lbCartridgeInfo;
+
+ try {
+ lbCartridgeInfo = CloudControllerServiceClient.getServiceClient().getCartridgeInfo(lbCartridgeType);
+
+ } catch (UnregisteredCartridgeException e) {
+ String message = lbCartridgeType + " is not a valid cartridgeSubscription type";
+ log.error(message);
+ throw e;
+
+ } catch (Exception e) {
+ String message = "Error getting info for " + lbCartridgeType;
+ log.error(message, e);
+ throw new ADCException(message, e);
+ }
+
+ lbDataCtxt.setLbCartridgeInfo(lbCartridgeInfo);
+
+ if (log.isDebugEnabled()) {
+ log.debug("This cartridge uses default load balancer. " + "[Type] " + subscriptionData.getCartridgeType());
+ }
+
+ try {
+ // get the valid policies for lb cartridge
+ DeploymentPolicy[] lbCartridgeDepPolicies =
+ getAutoscalerServiceClient().getDeploymentPolicies(lbCartridgeType);
+ // traverse deployment policies of lb cartridge
+ for (DeploymentPolicy policy : lbCartridgeDepPolicies) {
+
+ // check existence of the subscribed policy
+ if (subscriptionData.getDeploymentPolicyName().equals(policy.getId())) {
+
+ if (!getAutoscalerServiceClient().checkDefaultLBExistenceAgainstPolicy(subscriptionData.getDeploymentPolicyName())) {
+
+ Properties lbProperties = new Properties();
+
+ // if LB cartridge definition has properties as well, combine
+ if (lbCartridgeInfo.getProperties() != null && lbCartridgeInfo.getProperties().length > 0) {
+ lbProperties.setProperties(combine(lbCartridgeInfo.getProperties(), new Property[]{lbRefProperty}));
+
+ } else {
+ lbProperties.setProperties(new Property[]{lbRefProperty});
+ }
+
+ lbDataCtxt.addLBProperties(lbProperties);
+ }
+ }
+ }
+
+ } catch (Exception ex) {
+ // we don't need to throw the error here.
+ log.error(ex.getMessage(), ex);
+ }
+
+ // set deployment and autoscaling policies
+ lbDataCtxt.setDeploymentPolicy(subscriptionData.getDeploymentPolicyName());
+ lbDataCtxt.setAutoscalePolicy(lbCartridgeInfo.getDefaultAutoscalingPolicy());
+
+ lbDataCtxt.addLoadBalancedServiceProperty(lbRefProperty);
+ break;
+ }
+
+ } else if (Constants.SERVICE_AWARE_LOAD_BALANCER.equals(name)) {
+
+ if ("true".equals(value)) {
+
+ lbRefProperty.setValue(name);
+
+ CartridgeInfo lbCartridgeInfo;
+
+ try {
+ lbCartridgeInfo = CloudControllerServiceClient.getServiceClient().getCartridgeInfo(lbCartridgeType);
+
+ } catch (UnregisteredCartridgeException e) {
+ String message = lbCartridgeType + " is not a valid cartridgeSubscription type";
+ log.error(message);
+ throw e;
+
+ } catch (Exception e) {
+ String message = "Error getting info for " + lbCartridgeType;
+ log.error(message, e);
+ throw new ADCException(message, e);
+ }
+
+ lbDataCtxt.setLbCartridgeInfo(lbCartridgeInfo);
+
+ // add a property for the service type
+ Property loadBalancedServiceTypeProperty = new Property();
+ loadBalancedServiceTypeProperty.setName(Constants.LOAD_BALANCED_SERVICE_TYPE);
+ // set the load balanced service type
+ loadBalancedServiceTypeProperty.setValue(subscriptionData.getCartridgeType());
+
+ if (log.isDebugEnabled()) {
+ log.debug("This cartridge uses a service aware load balancer. [Type] " + subscriptionData.getCartridgeType());
+ }
+
+ try {
+
+ // get the valid policies for lb cartridge
+ DeploymentPolicy[] lbCartridgeDepPolicies = getAutoscalerServiceClient().getDeploymentPolicies(lbCartridgeType);
+ // traverse deployment policies of lb cartridge
+ for (DeploymentPolicy policy : lbCartridgeDepPolicies) {
+ // check existence of the subscribed policy
+ if (subscriptionData.getDeploymentPolicyName().equals(policy.getId())) {
+
+ if (!getAutoscalerServiceClient().checkServiceLBExistenceAgainstPolicy(subscriptionData.getCartridgeType(),
+ subscriptionData.getDeploymentPolicyName())) {
+
+ Properties lbProperties = new Properties();
+
+ // if LB cartridge definition has properties as well, combine
+ if (lbCartridgeInfo.getProperties() != null && lbCartridgeInfo.getProperties().length > 0) {
+ lbProperties.setProperties(combine(lbCartridgeInfo.getProperties(), new Property[]{lbRefProperty, loadBalancedServiceTypeProperty}));
+
+ } else {
+ lbProperties.setProperties(new Property[]{lbRefProperty, loadBalancedServiceTypeProperty});
+ }
+
+ // set a payload property for load balanced service type
+ Property payloadProperty = new Property();
+ payloadProperty.setName("LOAD_BALANCED_SERVICE_TYPE"); //TODO: refactor hardcoded name
+ payloadProperty.setValue(subscriptionData.getCartridgeType());
+
+ lbDataCtxt.addLBProperties(lbProperties);
+ }
+ }
+ }
+
+ } catch (Exception ex) {
+ // we don't need to throw the error here.
+ log.error(ex.getMessage(), ex);
+ }
+
+ // set deployment and autoscaling policies
+ lbDataCtxt.setDeploymentPolicy(subscriptionData.getDeploymentPolicyName());
+ lbDataCtxt.setAutoscalePolicy(lbCartridgeInfo.getDefaultAutoscalingPolicy());
+
+ lbDataCtxt.addLoadBalancedServiceProperty(lbRefProperty);
+ break;
+ }
+ }
+ }
+
+ return lbDataCtxt;
+ }
+
+ private static AutoscalerServiceClient getAutoscalerServiceClient () throws ADCException {
+
+ try {
+ return AutoscalerServiceClient.getServiceClient();
+
+ } catch (AxisFault axisFault) {
+ String errorMsg = "Error in getting AutoscalerServiceClient instance";
+ log.error(errorMsg, axisFault);
+ throw new ADCException (errorMsg, axisFault);
+ }
+ }
+
+ private static Property[] combine (Property[] propertyArray1, Property[] propertyArray2) {
+
+ int length = propertyArray1.length + propertyArray2.length;
+ Property[] combinedProperties = new Property[length];
+ System.arraycopy(propertyArray1, 0, combinedProperties, 0, propertyArray1.length);
+ System.arraycopy(propertyArray2, 0, combinedProperties, propertyArray1.length, propertyArray2.length);
+
+ return combinedProperties;
+ }
}
[12/12] git commit: LB subscription refactoring contd.
Posted by is...@apache.org.
LB subscription refactoring contd.
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/c4586634
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/c4586634
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/c4586634
Branch: refs/heads/master
Commit: c4586634484279eebb685903b5a3b09a5ade8bd6
Parents: 5e99f2a
Author: Isuru <is...@wso2.com>
Authored: Fri Mar 7 17:54:32 2014 +0530
Committer: Isuru <is...@wso2.com>
Committed: Fri Mar 7 17:54:32 2014 +0530
----------------------------------------------------------------------
.../service/multitenant/MultiTenantService.java | 12 ++++-----
.../manager/CartridgeSubscriptionManager.java | 12 +++------
.../factory/CartridgeSubscriptionFactory.java | 6 ++++-
.../SubscriptionSingleTenantBehaviour.java | 26 +++-----------------
.../utils/CartridgeSubscriptionUtils.java | 8 ++++++
5 files changed, 26 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c4586634/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/multitenant/MultiTenantService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/multitenant/MultiTenantService.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/multitenant/MultiTenantService.java
index 2b4fce3..5a4ff42 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/multitenant/MultiTenantService.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/multitenant/MultiTenantService.java
@@ -21,13 +21,11 @@ package org.apache.stratos.manager.deploy.service.multitenant;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
import org.apache.stratos.cloud.controller.pojo.Properties;
import org.apache.stratos.manager.deploy.service.Service;
import org.apache.stratos.manager.exception.ADCException;
import org.apache.stratos.manager.exception.UnregisteredCartridgeException;
-import org.apache.stratos.manager.utils.ApplicationManagementUtil;
-import org.apache.stratos.manager.utils.CartridgeConstants;
-import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
public class MultiTenantService extends Service {
@@ -44,8 +42,10 @@ public class MultiTenantService extends Service {
super.deploy(properties);
//register the service
- ApplicationManagementUtil.registerService(getType(), getClusterId(), CartridgeConstants.DEFAULT_SUBDOMAIN,
- getPayloadData().getCompletePayloadData(), getTenantRange(), getHostName(), getAutoscalingPolicyName(),
- getDeploymentPolicyName(), properties);
+ //ApplicationManagementUtil.registerService(getType(), getClusterId(), CartridgeConstants.DEFAULT_SUBDOMAIN,
+ // getPayloadData().getCompletePayloadData(), getTenantRange(), getHostName(), getAutoscalingPolicyName(),
+ // getDeploymentPolicyName(), properties);
+
+ register(getCartridgeInfo(), getCluster(), getPayloadData(), getAutoscalingPolicyName(), getDeploymentPolicyName(), properties);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c4586634/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
index 3703856..bfc62de 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
@@ -109,6 +109,7 @@ public class CartridgeSubscriptionManager {
}
} else {
+
// LB ref found, get relevant LB Context data
lbDataCtxt = CartridgeSubscriptionUtils.getLoadBalancerDataContext(subscriptionData.getTenantId(), subscriptionData.getCartridgeType(),
subscriptionData.getDeploymentPolicyName(), lbConfig);
@@ -154,7 +155,7 @@ public class CartridgeSubscriptionManager {
DuplicateCartridgeAliasException, PolicyException, UnregisteredCartridgeException, RepositoryRequiredException, RepositoryCredentialsRequiredException,
RepositoryTransportException, AlreadySubscribedException, InvalidRepositoryException {
- if (lbDataContext.getLbCategory().equals(Constants.NO_LOAD_BALANCER)) {
+ if (lbDataContext.getLbCategory() == null || lbDataContext.getLbCategory().equals(Constants.NO_LOAD_BALANCER)) {
// no load balancer subscription required
log.info("No LB subscription required for the Subscription with alias: " + subscriptionData.getCartridgeAlias() + ", type: " +
subscriptionData.getCartridgeType());
@@ -182,7 +183,6 @@ public class CartridgeSubscriptionManager {
if(lbDataContext.getLbCartridgeInfo().getMultiTenant()) {
throw new ADCException("LB Cartridge must be single tenant");
}
-
// Set the load balanced service type
loadBalancerCategory.setLoadBalancedServiceType(subscriptionData.getCartridgeType());
@@ -227,8 +227,7 @@ public class CartridgeSubscriptionManager {
}
// Create the CartridgeSubscription instance
- CartridgeSubscription cartridgeSubscription = CartridgeSubscriptionFactory.
- getCartridgeSubscriptionInstance(cartridgeInfo, tenancyBehaviour);
+ CartridgeSubscription cartridgeSubscription = CartridgeSubscriptionFactory.getCartridgeSubscriptionInstance(cartridgeInfo, tenancyBehaviour);
// Generate and set the key
String subscriptionKey = CartridgeSubscriptionUtils.generateSubscriptionKey();
@@ -246,11 +245,6 @@ public class CartridgeSubscriptionManager {
cartridgeSubscription.createSubscription(subscriber, subscriptionData.getCartridgeAlias(), subscriptionData.getAutoscalingPolicyName(),
subscriptionData.getDeploymentPolicyName(), repository);
- // create subscription
- cartridgeSubscription.createSubscription(subscriber, subscriptionData.getCartridgeAlias(), subscriptionData.getAutoscalingPolicyName(),
- subscriptionData.getDeploymentPolicyName(), repository);
-
-
log.info("Tenant [" + subscriptionData.getTenantId() + "] with username [" + subscriptionData.getTenantAdminUsername() +
" subscribed to " + "] Cartridge with Alias " + subscriptionData.getCartridgeAlias() + ", Cartridge Type: " +
subscriptionData.getCartridgeType() + ", Repo URL: " + subscriptionData.getRepositoryURL() + ", Autoscale Policy: " +
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c4586634/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/factory/CartridgeSubscriptionFactory.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/factory/CartridgeSubscriptionFactory.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/factory/CartridgeSubscriptionFactory.java
index ce70b89..05b68b2 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/factory/CartridgeSubscriptionFactory.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/factory/CartridgeSubscriptionFactory.java
@@ -19,6 +19,8 @@
package org.apache.stratos.manager.subscription.factory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
import org.apache.stratos.manager.exception.ADCException;
import org.apache.stratos.manager.lb.category.LBDataContext;
@@ -29,6 +31,8 @@ import org.apache.stratos.manager.utils.CartridgeConstants;
public class CartridgeSubscriptionFactory {
+ private static Log log = LogFactory.getLog(CartridgeSubscriptionFactory.class);
+
/**
* Returns the relevant CartridgeSubscription object for the given criteria
*
@@ -70,7 +74,7 @@ public class CartridgeSubscriptionFactory {
public static CartridgeSubscription getLBCartridgeSubscriptionInstance (LBDataContext lbDataContext, LoadBalancerCategory loadBalancerCategory)
throws ADCException {
- if (!lbDataContext.getLbCartridgeInfo().getProvider().equals("loadbalancer") || !lbDataContext.getLbCartridgeInfo().getProvider().equals("lb")) {
+ if (!lbDataContext.getLbCartridgeInfo().getProvider().equals("loadbalancer") && !lbDataContext.getLbCartridgeInfo().getProvider().equals("lb")) {
throw new ADCException("LB cartridge provider should be either lb or loadbalancer");
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c4586634/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/tenancy/SubscriptionSingleTenantBehaviour.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/tenancy/SubscriptionSingleTenantBehaviour.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/tenancy/SubscriptionSingleTenantBehaviour.java
index e3c2772..1b6099a 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/tenancy/SubscriptionSingleTenantBehaviour.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/tenancy/SubscriptionSingleTenantBehaviour.java
@@ -19,37 +19,19 @@
package org.apache.stratos.manager.subscription.tenancy;
-import org.apache.axis2.AxisFault;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
-import org.apache.stratos.cloud.controller.pojo.Properties;
-import org.apache.stratos.cloud.controller.pojo.Property;
import org.apache.stratos.manager.client.CloudControllerServiceClient;
-import org.apache.stratos.manager.dao.Cluster;
import org.apache.stratos.manager.exception.ADCException;
-import org.apache.stratos.manager.exception.AlreadySubscribedException;
import org.apache.stratos.manager.exception.NotSubscribedException;
-import org.apache.stratos.manager.exception.UnregisteredCartridgeException;
-import org.apache.stratos.manager.payload.BasicPayloadData;
-import org.apache.stratos.manager.payload.PayloadData;
-import org.apache.stratos.manager.payload.PayloadFactory;
-import org.apache.stratos.manager.repository.Repository;
import org.apache.stratos.manager.service.InstanceCleanupNotificationService;
-import org.apache.stratos.manager.subscriber.Subscriber;
-import org.apache.stratos.manager.subscription.utils.CartridgeSubscriptionUtils;
-import org.apache.stratos.manager.utils.ApplicationManagementUtil;
-import org.apache.stratos.manager.utils.CartridgeConstants;
-
-import java.util.Map;
-import java.util.Set;
public class SubscriptionSingleTenantBehaviour extends SubscriptionTenancyBehaviour {
private static Log log = LogFactory.getLog(SubscriptionSingleTenantBehaviour.class);
- public PayloadData create (String alias, Cluster cluster, Subscriber subscriber, Repository repository, CartridgeInfo cartridgeInfo,
+ /*public PayloadData create (String alias, Cluster cluster, Subscriber subscriber, Repository repository, CartridgeInfo cartridgeInfo,
String subscriptionKey, Map<String, String> customPayloadEntries) throws ADCException, AlreadySubscribedException {
//set the cluster and hostname
@@ -99,9 +81,9 @@ public class SubscriptionSingleTenantBehaviour extends SubscriptionTenancyBehavi
}
return payloadData;
- }
+ } */
- public void register (CartridgeInfo cartridgeInfo, Cluster cluster, PayloadData payloadData, String autoscalePolicyName,
+ /*public void register (CartridgeInfo cartridgeInfo, Cluster cluster, PayloadData payloadData, String autoscalePolicyName,
String deploymentPolicyName, Properties properties) throws ADCException, UnregisteredCartridgeException {
log.info("Payload: " + payloadData.getCompletePayloadData().toString());
@@ -115,7 +97,7 @@ public class SubscriptionSingleTenantBehaviour extends SubscriptionTenancyBehavi
autoscalePolicyName,
deploymentPolicyName,
properties);
- }
+ }*/
public void remove (String clusterId, String alias) throws ADCException, NotSubscribedException {
//sending instance cleanup notification for the cluster, so that members in the cluster would aware of the termination
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c4586634/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
index 5fa3717..e8b572c 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
@@ -244,6 +244,8 @@ public class CartridgeSubscriptionUtils {
if (Constants.NO_LOAD_BALANCER.equals(name)) {
if ("true".equals(value)) {
+ lbDataCtxt.setLbCategory(Constants.NO_LOAD_BALANCER);
+
if (log.isDebugEnabled()) {
log.debug("This cartridge does not require a load balancer. " + "[Type] " + serviceType);
}
@@ -253,6 +255,8 @@ public class CartridgeSubscriptionUtils {
}
} else if (Constants.EXISTING_LOAD_BALANCERS.equals(name)) {
+ lbDataCtxt.setLbCategory(Constants.EXISTING_LOAD_BALANCERS);
+
String clusterIdsVal = value;
if (log.isDebugEnabled()) {
log.debug("This cartridge refers to existing load balancers. " + "[Type] " + serviceType + "[Referenced Cluster Ids] " + clusterIdsVal);
@@ -277,6 +281,8 @@ public class CartridgeSubscriptionUtils {
if ("true".equals(value)) {
+ lbDataCtxt.setLbCategory(Constants.DEFAULT_LOAD_BALANCER);
+
lbRefProperty.setValue(name);
CartridgeInfo lbCartridgeInfo;
@@ -347,6 +353,8 @@ public class CartridgeSubscriptionUtils {
if ("true".equals(value)) {
+ lbDataCtxt.setLbCategory(Constants.SERVICE_AWARE_LOAD_BALANCER);
+
lbRefProperty.setValue(name);
CartridgeInfo lbCartridgeInfo;
[08/12] git commit: adapting new changes, fixing conflicts and merging
Posted by is...@apache.org.
adapting new changes, fixing conflicts and merging
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/09d0beff
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/09d0beff
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/09d0beff
Branch: refs/heads/master
Commit: 09d0beffa5cee828868dbec5a1b660b8d4eca57e
Parents: ba64484 d926386
Author: Isuru <is...@wso2.com>
Authored: Sun Mar 2 10:39:20 2014 +0530
Committer: Isuru <is...@wso2.com>
Committed: Sun Mar 2 10:39:20 2014 +0530
----------------------------------------------------------------------
.../health/AutoscalerHealthStatReceiver.java | 7 +-
.../topology/AutoscalerTopologyReceiver.java | 59 +-
.../autoscaler/partition/PartitionManager.java | 5 +-
.../autoscaler/policy/PolicyManager.java | 8 +
.../rule/AutoscalerRuleEvaluator.java | 5 +
.../stratos/cartridge/agent/CartridgeAgent.java | 14 +-
.../config/CartridgeAgentConfiguration.java | 13 +-
.../agent/data/publisher/DataPublisher.java | 6 +-
.../data/publisher/GenericDataPublisher.java | 29 +
.../publisher/CartridgeAgentEventPublisher.java | 72 +-
.../publisher/HealthStatisticsNotifier.java | 4 +-
.../publisher/HealthStatisticsReader.java | 32 +-
.../agent/util/CartridgeAgentConstants.java | 1 +
.../cartridge/agent/util/ExtensionUtils.java | 21 +
.../stratos/cli/RestCommandLineService.java | 553 ++++++----
.../apache/stratos/cli/StratosApplication.java | 5 +-
.../stratos/cli/beans/TenantInfoBean.java | 28 +
.../cli/beans/cartridge/CartridgeInfoBean.java | 30 +-
.../cli/commands/AutoscalePolicyCommand.java | 2 +-
.../DescribeAutoScalingPolicyCommand.java | 2 +-
.../DescribeDeploymentPolicyCommand.java | 2 +-
.../stratos/cli/commands/ExitCommand.java | 2 +-
.../stratos/cli/commands/ListAllTenants.java | 65 ++
.../stratos/cli/commands/PartitionCommand.java | 1 -
.../stratos/cli/commands/SubscribeCommand.java | 53 +-
.../UndeployCartridgeDefinitionCommand.java | 2 +-
.../apache/stratos/cli/utils/CliConstants.java | 16 +-
.../cloud/controller/iaases/AWSEC2Iaas.java | 136 ++-
.../controller/iaases/OpenstackNovaIaas.java | 45 +-
.../cloud/controller/iaases/VCloudIaas.java | 13 +-
.../impl/CloudControllerServiceImpl.java | 286 +++--
.../cloud/controller/interfaces/Iaas.java | 8 +-
.../cloud/controller/pojo/Cartridge.java | 43 +-
.../cloud/controller/pojo/CartridgeConfig.java | 30 +-
.../cloud/controller/pojo/CartridgeInfo.java | 22 +-
.../cloud/controller/pojo/ClusterContext.java | 53 +-
.../controller/pojo/PersistanceMapping.java | 84 --
.../cloud/controller/pojo/Persistence.java | 48 +
.../stratos/cloud/controller/pojo/Volume.java | 110 ++
.../InstanceStatusEventMessageDelegator.java | 6 +
.../controller/topology/TopologyBuilder.java | 93 +-
.../topology/TopologyEventPublisher.java | 11 +-
.../util/CloudControllerConstants.java | 1 +
.../controller/util/CloudControllerUtil.java | 9 +-
.../validate/AWSEC2PartitionValidator.java | 7 +-
.../OpenstackNovaPartitionValidator.java | 15 +-
.../validate/VCloudPartitionValidator.java | 54 +
.../apache/stratos/common/util/CommonUtil.java | 6 +-
.../balancer/LoadBalancerTenantReceiver.java | 7 +-
.../balancer/LoadBalancerTopologyReceiver.java | 7 +-
.../balancer/cache/AlgorithmContextCache.java | 4 +-
.../load/balancer/cache/LoadBalancerCache.java | 51 +-
.../TenantAwareLoadBalanceEndpoint.java | 7 +-
.../balancer/mediators/ResponseInterceptor.java | 22 +-
.../InFlightRequestDecrementCallable.java | 38 +
.../InFlightRequestIncrementCallable.java | 38 +
.../LoadBalancerStatisticsCollector.java | 159 ++-
.../LoadBalancerStatisticsExecutor.java | 56 +
.../console/cartridge_info.jag | 13 +-
.../console/controllers/acs.jag | 6 +-
.../controllers/cartridgeSubscribeSubmit.jag | 14 +-
.../controllers/cartridgeUnsubscribeSubmit.jag | 2 -
.../console/controllers/loginSubmit.jag | 3 -
.../console/controllers/manageTenants.jag | 5 +-
.../console/controllers/profileClient.jag | 3 +-
.../console/subscribe_cartridge.jag | 2 +-
.../console/tenant_management.jag | 2 +-
.../console/tenant_new.jag | 2 +-
.../console/themes/theme1/pages/index.hbs | 1 +
.../console/themes/theme1/pages/plain.hbs | 2 +-
.../themes/theme1/partials/cartridge_info.hbs | 78 +-
.../themes/theme1/partials/cartridges.hbs | 17 +-
.../partials/configure_stratos_wizard.hbs | 54 +-
.../themes/theme1/partials/mycartridges.hbs | 4 +-
.../theme1/partials/subscribe_cartridge.hbs | 188 ++--
.../themes/theme1/partials/tenant_new.hbs | 99 +-
.../themes/theme1/renderers/cartridge_info.js | 8 +-
.../themes/theme1/renderers/cartridges.js | 2 +
.../console/themes/theme1/renderers/index.js | 3 +-
.../console/themes/theme1/renderers/login.js | 2 -
.../theme1/renderers/tenant_management.js | 3 +-
.../console/themes/theme1/ui/css/main.css | 24 +-
.../console/themes/theme1/ui/img/favicon.png | Bin 0 -> 585 bytes
.../console/themes/theme1/ui/js/mycartridges.js | 2 +-
.../console/themes/theme1/ui/js/popup.js | 1 +
.../themes/theme1/ui/js/tenant_management.js | 4 +-
.../console/util/utility.jag | 54 +-
.../manager/client/AutoscalerServiceClient.java | 12 +
.../apache/stratos/manager/dto/Cartridge.java | 28 +-
.../listener/InstanceStatusListener.java | 20 +-
.../manager/CartridgeSubscriptionManager.java | 53 +-
.../manager/payload/BasicPayloadData.java | 23 +
.../ApplicationCartridgeSubscription.java | 3 +-
.../subscription/CartridgeSubscription.java | 48 +-
.../subscription/DataCartridgeSubscription.java | 5 +-
.../FrameworkCartridgeSubscription.java | 19 +
.../subscription/LBCartridgeSubscription.java | 3 +-
.../subscription/PersistenceContext.java | 67 ++
.../manager/subscription/SubscriptionData.java | 16 +-
.../SubscriptionSingleTenantBehaviour.java | 115 ++
.../StratosManagerTopologyReceiver.java | 4 +
.../utils/ApplicationManagementUtil.java | 2 +-
.../manager/utils/CartridgeConstants.java | 2 +
.../messaging/domain/topology/MemberStatus.java | 20 +-
.../status/InstanceMaintenanceModeEvent.java | 59 +
.../topology/MemberMaintenanceModeEvent.java | 79 ++
.../topology/MemberReadyToShutdownEvent.java | 18 +
.../topology/MemberMaintenanceListener.java | 24 +
.../MemberMaintenanceModeProcessor.java | 147 +++
.../topology/TopologyMessageProcessorChain.java | 7 +
.../health/stat/HealthStatReceiver.java | 7 +-
.../InstanceNotifierEventMessageReceiver.java | 7 +-
.../message/receiver/tenant/TenantReceiver.java | 7 +-
.../receiver/topology/TopologyReceiver.java | 7 +-
.../stratos/messaging/util/Constants.java | 2 +
.../rest/endpoint/bean/CartridgeInfoBean.java | 9 -
.../definition/CartridgeDefinitionBean.java | 14 +-
.../definition/PersistanceMappingBean.java | 38 -
.../cartridge/definition/PersistenceBean.java | 46 +
.../bean/cartridge/definition/VolumeBean.java | 39 +
.../rest/endpoint/bean/topology/Cluster.java | 17 +
.../rest/endpoint/bean/topology/Member.java | 17 +
.../bean/util/converter/PojoConverter.java | 43 +-
.../stratos/rest/endpoint/mock/MockContext.java | 102 +-
.../rest/endpoint/mock/StratosTestAdmin.java | 23 +-
.../rest/endpoint/services/ServiceUtils.java | 462 ++------
.../rest/endpoint/services/StratosAdmin.java | 29 +-
.../main/webapp/stratos/WEB-INF/cxf-servlet.xml | 2 +-
.../extension/FaultHandlingWindowProcessor.java | 8 +-
pom.xml | 2 +-
.../main/autoscale-policies/economyPolicy.xml | 20 +-
.../distribution/src/main/assembly/bin.xml | 1 +
.../src/main/extensions/mount_volumes.sh | 86 ++
.../distribution/src/main/conf/log4j.properties | 17 +-
.../src/main/conf/cartridge-config.properties | 3 +
.../modules/p2-profile-gen/pom.xml | 4 +-
.../main/resources/CloudControllerService.wsdl | 28 +-
tools/puppet/agent/root/bin/ec2_init.sh | 128 ++-
tools/puppet3-agent/config.sh | 94 ++
tools/puppet3-agent/init.sh | 142 +++
tools/puppet3-agent/puppetinstall/puppetinstall | 397 +++++++
tools/puppet3-agent/stratos_sendinfo.rb | 29 +
tools/puppet3/auth.conf | 116 ++
tools/puppet3/autosign.conf | 1 +
tools/puppet3/fileserver.conf | 41 +
tools/puppet3/manifests/nodes.pp | 151 +++
tools/puppet3/manifests/site.pp | 1 +
tools/puppet3/modules/agent/manifests/init.pp | 55 +
.../modules/agent/manifests/initialize.pp | 70 ++
.../modules/agent/manifests/push_templates.pp | 27 +
tools/puppet3/modules/agent/manifests/start.pp | 27 +
.../modules/agent/templates/bin/stratos.sh.erb | 48 +
.../conf/templates/jndi.properties.template.erb | 26 +
.../templates/extensions/addons/_mysql.erb | 15 +
.../agent/templates/extensions/addons/_ruby.erb | 17 +
.../extensions/artifacts-updated.sh.erb | 29 +
.../agent/templates/extensions/clean.sh.erb | 28 +
.../extensions/instance-activated.sh.erb | 28 +
.../extensions/instance-started.sh.erb | 36 +
.../templates/extensions/start-servers.sh.erb | 28 +
tools/puppet3/modules/autoscaler/LICENSE | 13 +
.../autoscaler/files/configs/bin/stratos.sh | 298 ++++++
.../configs/repository/conf/autoscaler.xml | 34 +
.../modules/autoscaler/manifests/clean.pp | 45 +
.../modules/autoscaler/manifests/deploy.pp | 43 +
.../modules/autoscaler/manifests/init.pp | 97 ++
.../modules/autoscaler/manifests/initialize.pp | 59 +
.../modules/autoscaler/manifests/params.pp | 66 ++
.../autoscaler/manifests/push_templates.pp | 26 +
.../modules/autoscaler/manifests/start.pp | 27 +
.../templates/conf/autoscaler.xml.erb | 39 +
.../templates/conf/axis2/axis2.xml.erb | 701 ++++++++++++
.../autoscaler/templates/conf/carbon.xml.erb | 625 +++++++++++
.../templates/conf/jndi.properties.erb | 4 +
.../economy-autoscale.xml.erb | 26 +
.../economy-deployment.xml.erb | 23 +
.../server/partitions/partitions.xml.erb | 19 +
tools/puppet3/modules/cc/LICENSE | 13 +
.../modules/cc/files/configs/bin/stratos.sh | 299 ++++++
.../repository/conf/cloud-controller.xml | 81 ++
....stratos.cloud.controller_4.0.0.SNAPSHOT.jar | Bin 0 -> 183364 bytes
tools/puppet3/modules/cc/manifests/clean.pp | 45 +
tools/puppet3/modules/cc/manifests/deploy.pp | 43 +
tools/puppet3/modules/cc/manifests/init.pp | 96 ++
.../puppet3/modules/cc/manifests/initialize.pp | 59 +
tools/puppet3/modules/cc/manifests/params.pp | 66 ++
.../modules/cc/manifests/push_templates.pp | 26 +
tools/puppet3/modules/cc/manifests/start.pp | 27 +
.../cc/templates/conf/axis2/axis2.xml.erb | 703 ++++++++++++
.../modules/cc/templates/conf/carbon.xml.erb | 625 +++++++++++
.../cc/templates/conf/jndi.properties.erb | 4 +
tools/puppet3/modules/cep/LICENSE | 13 +
.../modules/cep/files/configs/bin/wso2server.sh | 304 ++++++
.../dropins/activemq_client_5.8.0_1.0.0.jar | Bin 0 -> 1032400 bytes
.../dropins/andes_client_0.13.wso2v8_1.0.0.jar | Bin 0 -> 1854829 bytes
...che.stratos.cep.extension-1.0.0-SNAPSHOT.jar | Bin 0 -> 16495 bytes
.../repository/conf/siddhi/siddhi.extension | 3 +
.../repository/conf/stream-manager-config.xml | 177 +++
.../HealthStatisticsEventBuilder.xml | 10 +
.../InstanceStatusStatisticsBuilder.xml | 10 +
.../LoadBalancerStatisticsEventBuilder.xml | 10 +
.../AverageInFlightRequestsEventFormatter.xml | 11 +
.../AverageLoadAverageEventFormatter.xml | 11 +
.../AverageMemoryConsumptionEventFormatter.xml | 11 +
.../FaultMessageEventFormatter.xml | 11 +
.../GradientInFlightRequestsEventFormatter.xml | 11 +
.../GradientLoadAverageEventFormatter.xml | 11 +
.../GradientMemoryConsumptionEventFormatter.xml | 11 +
.../MemberAverageLoadAverageEventFormatter.xml | 11 +
...erAverageMemoryConsumptionEventFormatter.xml | 11 +
.../MemberGradientLoadAverageEventFormatter.xml | 11 +
...rGradientMemoryConsumptionEventFormatter.xml | 11 +
...econdDerivativeLoadAverageEventFormatter.xml | 11 +
...erivativeMemoryConsumptionEventFormatter.xml | 11 +
...DerivativeInFlightRequestsEventFormatter.xml | 11 +
...econdDerivativeLoadAverageEventFormatter.xml | 11 +
...erivativeMemoryConsumptionEventFormatter.xml | 11 +
.../executionplans/AverageHeathRequest.xml | 29 +
.../AverageInFlightRequestsFinder.xml | 19 +
.../executionplans/GradientOfHealthRequest.xml | 30 +
.../GradientOfRequestsInFlightFinder.xml | 18 +
.../SecondDerivativeOfHealthRequest.xml | 27 +
...SecondDerivativeOfRequestsInFlightFinder.xml | 19 +
.../DefaultWSO2EventInputAdaptor.xml | 3 +
.../DefaultWSO2EventOutputAdaptor.xml | 8 +
.../outputeventadaptors/JMSOutputAdaptor.xml | 8 +
.../streamdefinitions/stream-manager-config.xml | 269 +++++
tools/puppet3/modules/cep/manifests/clean.pp | 45 +
tools/puppet3/modules/cep/manifests/deploy.pp | 43 +
tools/puppet3/modules/cep/manifests/init.pp | 101 ++
.../puppet3/modules/cep/manifests/initialize.pp | 59 +
tools/puppet3/modules/cep/manifests/params.pp | 69 ++
.../modules/cep/manifests/push_templates.pp | 26 +
tools/puppet3/modules/cep/manifests/start.pp | 27 +
.../cep/templates/conf/axis2/axis2.xml.erb | 698 ++++++++++++
.../modules/cep/templates/conf/carbon.xml.erb | 609 +++++++++++
.../cep/templates/conf/jndi.properties.erb | 32 +
.../JMSOutputAdaptor.xml.erb | 8 +
tools/puppet3/modules/java/manifests/init.pp | 34 +
.../modules/java/templates/java_home.sh.erb | 1 +
tools/puppet3/modules/lb/LICENSE | 13 +
.../modules/lb/files/configs/bin/stratos.sh | 302 ++++++
tools/puppet3/modules/lb/manifests/clean.pp | 45 +
tools/puppet3/modules/lb/manifests/deploy.pp | 43 +
tools/puppet3/modules/lb/manifests/init.pp | 95 ++
.../puppet3/modules/lb/manifests/initialize.pp | 67 ++
tools/puppet3/modules/lb/manifests/params.pp | 66 ++
.../modules/lb/manifests/push_templates.pp | 26 +
tools/puppet3/modules/lb/manifests/start.pp | 27 +
.../lb/templates/conf/axis2/axis2.xml.erb | 527 +++++++++
.../lb/templates/conf/loadbalancer.conf.erb | 149 +++
tools/puppet3/modules/manager/LICENSE | 13 +
.../manager/files/configs/bin/stratos.sh | 301 ++++++
.../lib/mysql-connector-java-5.1.26-bin.jar | Bin 0 -> 855948 bytes
.../repository/conf/cartridge-config.properties | 63 ++
.../conf/datasources/master-datasources.xml | 27 +
.../conf/datasources/stratos-datasources.xml | 66 ++
.../repository/conf/stratos-datasources.xml | 66 ++
.../puppet3/modules/manager/manifests/clean.pp | 45 +
.../puppet3/modules/manager/manifests/deploy.pp | 43 +
tools/puppet3/modules/manager/manifests/init.pp | 99 ++
.../modules/manager/manifests/initialize.pp | 59 +
.../puppet3/modules/manager/manifests/params.pp | 66 ++
.../modules/manager/manifests/push_templates.pp | 26 +
.../puppet3/modules/manager/manifests/start.pp | 27 +
.../manager/templates/conf/axis2/axis2.xml.erb | 702 ++++++++++++
.../manager/templates/conf/carbon.xml.erb | 625 +++++++++++
.../conf/cartridge-config.properties.erb | 73 ++
.../conf/datasources/master-datasources.xml.erb | 27 +
.../datasources/stratos-datasources.xml.erb | 66 ++
.../manager/templates/conf/jndi.properties.erb | 4 +
tools/puppet3/modules/messagebroker/LICENSE | 13 +
.../files/configs/bin/wso2server.sh | 300 ++++++
.../modules/messagebroker/manifests/clean.pp | 45 +
.../modules/messagebroker/manifests/deploy.pp | 43 +
.../modules/messagebroker/manifests/init.pp | 99 ++
.../messagebroker/manifests/initialize.pp | 59 +
.../modules/messagebroker/manifests/params.pp | 66 ++
.../messagebroker/manifests/push_templates.pp | 26 +
.../modules/messagebroker/manifests/start.pp | 27 +
.../templates/conf/axis2/axis2.xml.erb | 719 +++++++++++++
.../messagebroker/templates/conf/carbon.xml.erb | 583 ++++++++++
tools/puppet3/modules/mysql/manifests/init.pp | 56 +
.../modules/mysql/templates/phpMyAdmin.conf.erb | 73 ++
tools/puppet3/modules/nodejs/manifests/init.pp | 52 +
tools/puppet3/modules/php/files/90forceyes | 23 +
.../modules/php/lib/facter/stratos_facts.rb | 12 +
tools/puppet3/modules/php/manifests/init.pp | 121 +++
.../puppet3/modules/php/manifests/init.pp.back | 131 +++
.../puppet3/modules/php/manifests/init.pp.cent | 94 ++
tools/puppet3/modules/php/manifests/init.pp.deb | 102 ++
tools/puppet3/modules/php/manifests/init.pp.rpm | 78 ++
.../php/templates/apache2/apache2.conf.erb | 256 +++++
.../apache2/sites-available/default-ssl.erb | 195 ++++
.../apache2/sites-available/default.erb | 64 ++
.../modules/php/templates/httpd/httpd.conf.erb | 1009 ++++++++++++++++++
tools/puppet3/modules/ruby/manifests/init.pp | 43 +
.../modules/ruby/templates/ruby-start.sh.erb | 18 +
tools/puppet3/modules/tomcat/manifests/init.pp | 51 +
.../puppet3/modules/wordpress/manifests/init.pp | 70 ++
.../wordpress/templates/httpd/httpd.conf.erb | 1009 ++++++++++++++++++
tools/puppet3/puppet.conf | 14 +
tools/stratos-installer/conf/setup.conf | 4 +
.../repository/conf/cartridge-config.properties | 2 +
tools/stratos-installer/setup.sh | 14 +
305 files changed, 21130 insertions(+), 1668 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/09d0beff/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
index 69574e1,ac4d8e6..6f2880d
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
@@@ -21,7 -21,9 +21,10 @@@ package org.apache.stratos.manager.mana
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
- import org.apache.stratos.cloud.controller.pojo.*;
+ import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
++import org.apache.stratos.cloud.controller.pojo.LoadbalancerConfig;
+ import org.apache.stratos.cloud.controller.pojo.Properties;
+ import org.apache.stratos.cloud.controller.pojo.Property;
import org.apache.stratos.manager.client.CloudControllerServiceClient;
import org.apache.stratos.manager.dao.CartridgeSubscriptionInfo;
import org.apache.stratos.manager.dto.SubscriptionInfo;
@@@ -31,6 -32,6 +34,7 @@@ import org.apache.stratos.manager.repos
import org.apache.stratos.manager.retriever.DataInsertionAndRetrievalManager;
import org.apache.stratos.manager.subscriber.Subscriber;
import org.apache.stratos.manager.subscription.CartridgeSubscription;
++import org.apache.stratos.manager.subscription.PersistenceContext;
import org.apache.stratos.manager.subscription.SubscriptionData;
import org.apache.stratos.manager.subscription.factory.CartridgeSubscriptionFactory;
import org.apache.stratos.manager.subscription.tenancy.SubscriptionMultiTenantBehaviour;
@@@ -84,140 -115,7 +88,139 @@@ public class CartridgeSubscriptionManag
throw new ADCException(message, e);
}
- //Decide tenancy behaviour
+ // check if this subscription requires Persistence Mapping, and its supported by the cartridge definition
+ Properties persistenceMappingProperties = null;
- if (subscriptionData.getPersistanceMapping() != null) {
- persistenceMappingProperties = getPersistenceMappingProperties(subscriptionData.getPersistanceMapping(), cartridgeInfo);
++ if (subscriptionData.getPersistanceContext() != null) {
++ persistenceMappingProperties = getPersistenceMappingProperties(subscriptionData.getPersistanceContext(), cartridgeInfo);
+ }
+
+ Properties serviceCartridgeSubscriptionProperties = null;
+ LBDataContext lbDataCtxt = null;
+
+ // get lb config reference
+ LoadbalancerConfig lbConfig = cartridgeInfo.getLbConfig();
+ if (lbConfig == null || lbConfig.getProperties() == null) {
+ // no LB ref
+ if (log.isDebugEnabled()) {
+ log.debug("This Service does not require a load balancer. " + "[Service Name] " +
+ subscriptionData.getCartridgeType());
+ }
+
+ } else {
+ // LB ref found, get relevant LB Context data
+ lbDataCtxt = CartridgeSubscriptionUtils.getLoadBalancerDataContext(subscriptionData.getTenantId(), subscriptionData.getCartridgeType(),
+ subscriptionData.getDeploymentPolicyName(), lbConfig);
+
+ // subscribe to LB
+ CartridgeSubscription lbCartridgeSubscription = subscribeToLB (subscriptionData, lbDataCtxt);
+
+ if (lbCartridgeSubscription != null) {
+ // register LB cartridge subscription
+ Properties lbCartridgeSubscriptionProperties = new Properties();
+ if (lbDataCtxt.getLbProperperties() != null && !lbDataCtxt.getLbProperperties().isEmpty()) {
+ lbCartridgeSubscriptionProperties.setProperties(lbDataCtxt.getLbProperperties().toArray(new Property[0]));
+ }
+
+ registerCartridgeSubscription(lbCartridgeSubscription, lbCartridgeSubscriptionProperties);
+ }
+ }
+
+ // subscribe to relevant service cartridge
+ CartridgeSubscription serviceCartridgeSubscription = subscribe (subscriptionData, cartridgeInfo);
+ serviceCartridgeSubscriptionProperties = new Properties();
+
+ // lb related properties
+ if (lbDataCtxt.getLoadBalancedServiceProperties() != null && !lbDataCtxt.getLoadBalancedServiceProperties().isEmpty()) {
+ serviceCartridgeSubscriptionProperties.setProperties(lbDataCtxt.getLoadBalancedServiceProperties().toArray(new Property[0]));
+ }
+
+ // Persistence Mapping related properties
+ if (persistenceMappingProperties != null && persistenceMappingProperties.getProperties().length > 0) {
+ // add the properties to send to CC via register method
+ for (Property persistenceMappingProperty : persistenceMappingProperties.getProperties()) {
+ serviceCartridgeSubscriptionProperties.addProperties(persistenceMappingProperty);
+ }
+ }
+
+ // register service cartridge subscription
+ return registerCartridgeSubscription(serviceCartridgeSubscription, serviceCartridgeSubscriptionProperties);
+ }
+
+ private CartridgeSubscription subscribeToLB (SubscriptionData subscriptionData, LBDataContext lbDataContext)
+
+ throws ADCException, InvalidCartridgeAliasException,
+ DuplicateCartridgeAliasException, PolicyException, UnregisteredCartridgeException, RepositoryRequiredException, RepositoryCredentialsRequiredException,
+ RepositoryTransportException, AlreadySubscribedException, InvalidRepositoryException {
+
+ if (lbDataContext.getLbCategory().equals(Constants.NO_LOAD_BALANCER)) {
+ // no load balancer subscription required
+ log.info("No LB subscription required for the Subscription with alias: " + subscriptionData.getCartridgeAlias() + ", type: " +
+ subscriptionData.getCartridgeType());
+ return null;
+ }
+
+ LoadBalancerCategory loadBalancerCategory = null;
+
+ String lbAlias = "lb" + lbDataContext.getLbCartridgeInfo().getType() + new Random().nextInt();
+
+ if (lbDataContext.getLbCategory().equals(Constants.EXISTING_LOAD_BALANCERS)) {
+ loadBalancerCategory = new ExistingLoadBalancerCategory();
+
+ } else if (lbDataContext.getLbCategory().equals(Constants.DEFAULT_LOAD_BALANCER)) {
+ loadBalancerCategory = new DefaultLoadBalancerCategory();
+
+ } else if (lbDataContext.getLbCategory().equals(Constants.SERVICE_AWARE_LOAD_BALANCER)) {
+ loadBalancerCategory = new ServiceLevelLoadBalancerCategory();
+ }
+
+ if (loadBalancerCategory == null) {
+ throw new ADCException("The given Load Balancer category " + lbDataContext.getLbCategory() + " not found");
+ }
+
+ if(lbDataContext.getLbCartridgeInfo().getMultiTenant()) {
+ throw new ADCException("LB Cartridge must be single tenant");
+ }
+
+ // Set the load balanced service type
+ loadBalancerCategory.setLoadBalancedServiceType(subscriptionData.getCartridgeType());
+
+ // Create the CartridgeSubscription instance
+ CartridgeSubscription cartridgeSubscription = CartridgeSubscriptionFactory.getLBCartridgeSubscriptionInstance(lbDataContext, loadBalancerCategory);
+
+ // Generate and set the key
+ String subscriptionKey = CartridgeSubscriptionUtils.generateSubscriptionKey();
+ cartridgeSubscription.setSubscriptionKey(subscriptionKey);
+
+ // Create repository
- Repository repository = cartridgeSubscription.manageRepository(null, "", "", false, lbAlias, lbDataContext.getLbCartridgeInfo(),
- subscriptionData.getTenantDomain());
++ Repository repository = cartridgeSubscription.manageRepository(null, "", "", false);
+
+ // Create subscriber
+ Subscriber subscriber = new Subscriber(subscriptionData.getTenantAdminUsername(), subscriptionData.getTenantId(), subscriptionData.getTenantDomain());
+
+ // create subscription
+ cartridgeSubscription.createSubscription(subscriber, lbAlias, lbDataContext.getAutoscalePolicy(),
+ lbDataContext.getDeploymentPolicy(), repository);
+
+
+ log.info("Tenant [" + subscriptionData.getTenantId() + "] with username [" + subscriptionData.getTenantAdminUsername() +
+ " subscribed to " + "] Cartridge with Alias " + lbAlias + ", Cartridge Type: " + lbDataContext.getLbCartridgeInfo().getType() +
+ ", Autoscale Policy: " + lbDataContext.getAutoscalePolicy() + ", Deployment Policy: " + lbDataContext.getDeploymentPolicy());
+
+ // Publish tenant subscribed event to message broker
+ CartridgeSubscriptionUtils.publishTenantSubscribedEvent(cartridgeSubscription.getSubscriber().getTenantId(),
+ cartridgeSubscription.getCartridgeInfo().getType());
+
+ return cartridgeSubscription;
+ }
+
+ private CartridgeSubscription subscribe (SubscriptionData subscriptionData, CartridgeInfo cartridgeInfo)
+
+ throws ADCException, InvalidCartridgeAliasException,
+ DuplicateCartridgeAliasException, PolicyException, UnregisteredCartridgeException, RepositoryRequiredException, RepositoryCredentialsRequiredException,
+ RepositoryTransportException, AlreadySubscribedException, InvalidRepositoryException {
+
+
+ // Decide tenancy behaviour
SubscriptionTenancyBehaviour tenancyBehaviour;
if(cartridgeInfo.getMultiTenant()) {
tenancyBehaviour = new SubscriptionMultiTenantBehaviour();
@@@ -229,34 -127,42 +232,34 @@@
CartridgeSubscription cartridgeSubscription = CartridgeSubscriptionFactory.
getCartridgeSubscriptionInstance(cartridgeInfo, tenancyBehaviour);
-
+ // Generate and set the key
String subscriptionKey = CartridgeSubscriptionUtils.generateSubscriptionKey();
-
- String encryptedRepoPassword = repositoryPassword != null && !repositoryPassword.isEmpty() ?
- RepoPasswordMgtUtil.encryptPassword(repositoryPassword, subscriptionKey) : "";
-
- //Create repository
- Repository repository = cartridgeSubscription.manageRepository(repositoryURL,
- repositoryUsername,
- encryptedRepoPassword,
- isPrivateRepository,
- cartridgeAlias,
- cartridgeInfo, tenantDomain);
-
- //Create subscriber
- Subscriber subscriber = new Subscriber(tenantAdminUsername, tenantId, tenantDomain);
-
- //Set the key
cartridgeSubscription.setSubscriptionKey(subscriptionKey);
+ // Create repository
- Repository repository = cartridgeSubscription.manageRepository(subscriptionData.getRepositoryURL(),
- subscriptionData.getRepositoryUsername(),
++ Repository repository = cartridgeSubscription.manageRepository(subscriptionData.getRepositoryURL(), subscriptionData.getRepositoryUsername(),
+ subscriptionData.getRepositoryPassword(),
- subscriptionData.isPrivateRepository(),
- subscriptionData.getCartridgeAlias(),
- cartridgeInfo,
- subscriptionData.getTenantDomain());
++ subscriptionData.isPrivateRepository());
+
+ // Create subscriber
+ Subscriber subscriber = new Subscriber(subscriptionData.getTenantAdminUsername(), subscriptionData.getTenantId(), subscriptionData.getTenantDomain());
+
+ //create subscription
- cartridgeSubscription.createSubscription(subscriber, cartridgeAlias, autoscalingPolicyName,
- deploymentPolicyName, repository);
++ cartridgeSubscription.createSubscription(subscriber, subscriptionData.getCartridgeAlias(), subscriptionData.getAutoscalingPolicyName(),
++ subscriptionData.getDeploymentPolicyName(), repository);
++
+ // create subscription
+ cartridgeSubscription.createSubscription(subscriber, subscriptionData.getCartridgeAlias(), subscriptionData.getAutoscalingPolicyName(),
+ subscriptionData.getDeploymentPolicyName(), repository);
- // set the lb cluster id if its available
- if (lbClusterId != null && !lbClusterId.isEmpty()) {
- cartridgeSubscription.setLbClusterId(lbClusterId);
- }
- log.info("Tenant [" + tenantId + "] with username [" + tenantAdminUsername +
- " subscribed to " + "] Cartridge Alias " + cartridgeAlias + ", Cartridge Type: " +
- cartridgeType + ", Repo URL: " + repositoryURL + ", Policy: " +
- autoscalingPolicyName);
+ log.info("Tenant [" + subscriptionData.getTenantId() + "] with username [" + subscriptionData.getTenantAdminUsername() +
+ " subscribed to " + "] Cartridge with Alias " + subscriptionData.getCartridgeAlias() + ", Cartridge Type: " +
+ subscriptionData.getCartridgeType() + ", Repo URL: " + subscriptionData.getRepositoryURL() + ", Autoscale Policy: " +
+ subscriptionData.getAutoscalingPolicyName() + ", Deployment Policy: " + subscriptionData.getDeploymentPolicyName());
- // Publish tenant subscribed envent to message broker
+ // Publish tenant subscribed event to message broker
CartridgeSubscriptionUtils.publishTenantSubscribedEvent(cartridgeSubscription.getSubscriber().getTenantId(),
cartridgeSubscription.getCartridgeInfo().getType());
@@@ -351,42 -257,7 +354,22 @@@
throw new NotSubscribedException(errorMsg, alias);
}
}
-
+
- private Properties getPersistenceMappingProperties (PersistanceMapping persistanceMapping, CartridgeInfo cartridgeInfo) throws ADCException {
-
- if (!persistanceMapping.getPersistanceRequired()) {
- // Persistence Mapping not required for this subscription
- return null;
- }
++ private Properties getPersistenceMappingProperties (PersistenceContext persistenceCtxt, CartridgeInfo cartridgeInfo) throws ADCException {
+
- if (persistanceMapping.getPersistanceRequired() && !cartridgeInfo.isPeristanceMappingsSpecified()) {
++ if (!cartridgeInfo.isPersistenceSpecified()) {
+ // Persistence Mapping not supported in the cartridge definition - error
+ String errorMsg = "Persistence Mapping not supported by the cartridge type " + cartridgeInfo.getType();
+ log.error(errorMsg);
+ throw new ADCException(errorMsg);
+ }
+
- Property persistanceRequiredProperty = new Property();
- persistanceRequiredProperty.setName(Constants.IS_VOLUME_REQUIRED);
- persistanceRequiredProperty.setValue(String.valueOf(persistanceMapping.getPersistanceRequired()));
-
- Property sizeProperty = new Property();
- sizeProperty.setName(Constants.VOLUME_SIZE);
- sizeProperty.setValue(Integer.toString(persistanceMapping.getSize()));
-
- Property deviceProperty = new Property();
- deviceProperty.setName(Constants.DEVICE_NAME);
- deviceProperty.setValue(String.valueOf(persistanceMapping.getDevice()));
-
- Property deleteOnTerminationProperty = new Property();
- deleteOnTerminationProperty.setName(Constants.SHOULD_DELETE_VOLUME);
- deleteOnTerminationProperty.setValue(String.valueOf(persistanceMapping.getRemoveOntermination()));
-
+ Properties persistenceMappingProperties = new Properties();
- persistenceMappingProperties.setProperties(new Property[]{persistanceRequiredProperty, sizeProperty, deviceProperty, deleteOnTerminationProperty});
++ persistenceMappingProperties.setProperties(new Property[]{persistenceCtxt.getPersistanceRequiredProperty(), persistenceCtxt.getSizeProperty(),
++ persistenceCtxt.getDeleteOnTerminationProperty()});
+
+ return persistenceMappingProperties;
+ }
/**
*
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/09d0beff/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/ApplicationCartridgeSubscription.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/ApplicationCartridgeSubscription.java
index eed644a,eed644a..13dd128
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/ApplicationCartridgeSubscription.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/ApplicationCartridgeSubscription.java
@@@ -41,8 -41,8 +41,7 @@@ public class ApplicationCartridgeSubscr
public Repository manageRepository (String repoURL, String repoUserName, String repoUserPassword,
-- boolean privateRepo, String cartridgeAlias, CartridgeInfo cartridgeInfo,
-- String tenantDomain) {
++ boolean privateRepo) {
//no repository for application cartridge instances
return null;
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/09d0beff/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/CartridgeSubscription.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/CartridgeSubscription.java
index 71ae249,a9ddb7f..31bb04a
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/CartridgeSubscription.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/CartridgeSubscription.java
@@@ -180,9 -178,9 +178,6 @@@ public abstract class CartridgeSubscrip
* @param repoUserName Repository Username
* @param repoUserPassword Repository password
* @param privateRepo public/private repository
-- * @param cartridgeAlias Alias of the cartridge subscription
-- * @param cartridgeInfo CartridgeInfo subscription
-- * @param tenantDomain Domain of the tenant
*
* @return Repository populated with relevant information or null of not repository is relevant to this cartridge
* subscription
@@@ -192,38 -190,38 +187,9 @@@
* @throws RepositoryTransportException
* @throws InvalidRepositoryException
*/
-- public Repository manageRepository (String repoURL, String repoUserName, String repoUserPassword,
-- boolean privateRepo, String cartridgeAlias, CartridgeInfo cartridgeInfo,
-- String tenantDomain)
--
-- throws ADCException, RepositoryRequiredException, RepositoryCredentialsRequiredException,
-- RepositoryTransportException, InvalidRepositoryException {
--
-- /*if (!new Boolean(System.getProperty(CartridgeConstants.FEATURE_INTERNAL_REPO_ENABLED))) {
-- if (log.isDebugEnabled()) {
-- log.debug("Internal repo feature is not enabled.");
-- }
-- }*/
--
-- //TODO: throw if repo is not given for this cartridge type
-- Repository repository = null;
-- if (repoURL != null && repoURL.trim().length() > 0) {
-- repository = new Repository();
-- log.info("External REPO URL is provided as [" + repoURL +
-- "]. Therefore not creating a new repo.");
-- //repository.setRepoName(repoURL.substring(0, repoURL.length()-4)); // remove .git part
-- repository.setUrl(repoURL);
-- repository.setUserName(repoUserName);
-- repository.setPassword(repoUserPassword);
-- repository.setPrivateRepository(privateRepo);
-- }
--
-- // Validate Remote Repository.
-- //ApplicationManagementUtil.validateRepository(repoURL, repoUserName, repoUserPassword, privateRepo,
-- // new Boolean(System.getProperty(CartridgeConstants.FEATURE_EXTERNAL_REPO_VAIDATION_ENABLED)));
--
-- return repository;
-- }
++ public abstract Repository manageRepository (String repoURL, String repoUserName, String repoUserPassword,
++ boolean privateRepo) throws ADCException, RepositoryRequiredException, RepositoryCredentialsRequiredException,
++ RepositoryTransportException, InvalidRepositoryException;
/**
* Cleans up the subscription information after unsubscribing
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/09d0beff/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/DataCartridgeSubscription.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/DataCartridgeSubscription.java
index d77a38b,80c95f4..5382619
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/DataCartridgeSubscription.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/DataCartridgeSubscription.java
@@@ -74,8 -72,8 +72,7 @@@ public class DataCartridgeSubscription
}
public Repository manageRepository (String repoURL, String repoUserName, String repoUserPassword,
-- boolean privateRepo, String cartridgeAlias, CartridgeInfo cartridgeInfo,
-- String tenantDomain) {
++ boolean privateRepo) {
//no repository for data cartridge instances
return null;
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/09d0beff/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/FrameworkCartridgeSubscription.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/FrameworkCartridgeSubscription.java
index ee6a210,ee6a210..2c714da
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/FrameworkCartridgeSubscription.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/FrameworkCartridgeSubscription.java
@@@ -21,6 -21,6 +21,8 @@@ package org.apache.stratos.manager.subs
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
++import org.apache.stratos.manager.exception.*;
++import org.apache.stratos.manager.repository.Repository;
import org.apache.stratos.manager.subscription.tenancy.SubscriptionTenancyBehaviour;
import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
@@@ -40,4 -40,4 +42,21 @@@ public class FrameworkCartridgeSubscrip
subscriptionTenancyBehaviour) {
super(cartridgeInfo, subscriptionTenancyBehaviour);
}
++
++ public Repository manageRepository (String repoURL, String repoUserName, String repoUserPassword,
++ boolean privateRepo)
++
++ throws ADCException, RepositoryRequiredException, RepositoryCredentialsRequiredException,
++ RepositoryTransportException, InvalidRepositoryException {
++
++ log.info("External REPO URL is provided as [" + repoURL + "]");
++
++ Repository repository = new Repository();
++ repository.setUrl(repoURL);
++ repository.setUserName(repoUserName);
++ repository.setPassword(repoUserPassword);
++ repository.setPrivateRepository(privateRepo);
++
++ return repository;
++ }
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/09d0beff/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/LBCartridgeSubscription.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/LBCartridgeSubscription.java
index 17b9eba,0b349ab..a382a73
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/LBCartridgeSubscription.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/LBCartridgeSubscription.java
@@@ -76,24 -55,8 +76,23 @@@ public class LBCartridgeSubscription ex
}
@Override
- public CartridgeSubscriptionInfo registerSubscription(Properties properties) throws ADCException, UnregisteredCartridgeException {
- //TODO
+ public void removeSubscription() throws ADCException, NotSubscribedException {
+
+ getLoadBalancerCategory().remove(getCluster().getClusterDomain(), getAlias());;
+ }
+
+ public Repository manageRepository (String repoURL, String repoUserName, String repoUserPassword,
- boolean privateRepo, String cartridgeAlias, CartridgeInfo cartridgeInfo,
- String tenantDomain) {
++ boolean privateRepo) {
+
+ //no repository for data cartridge instances
return null;
}
+
+ public LoadBalancerCategory getLoadBalancerCategory() {
+ return loadBalancerCategory;
+ }
+
+ public void setLoadBalancerCategory(LoadBalancerCategory loadBalancerCategory) {
+ this.loadBalancerCategory = loadBalancerCategory;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/09d0beff/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/PersistenceContext.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/PersistenceContext.java
index 0000000,0000000..472e3a3
new file mode 100644
--- /dev/null
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/PersistenceContext.java
@@@ -1,0 -1,0 +1,67 @@@
++/*
++ * 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.manager.subscription;
++
++import org.apache.commons.logging.Log;
++import org.apache.commons.logging.LogFactory;
++import org.apache.stratos.cloud.controller.pojo.Property;
++
++public class PersistenceContext {
++
++ private static Log log = LogFactory.getLog(PersistenceContext.class);
++
++ private Property persistanceRequiredProperty;
++ private Property sizeProperty;
++ private Property deleteOnTerminationProperty;
++
++ public PersistenceContext () {
++ persistanceRequiredProperty = new Property();
++ sizeProperty = new Property();
++ deleteOnTerminationProperty = new Property();
++ }
++
++
++ public Property getPersistanceRequiredProperty() {
++ return persistanceRequiredProperty;
++ }
++
++ public void setPersistanceRequiredProperty(String propertyName, String propertyValue) {
++ this.persistanceRequiredProperty.setName(propertyName);
++ this.persistanceRequiredProperty.setValue(propertyValue);
++ }
++
++ public Property getSizeProperty() {
++ return sizeProperty;
++ }
++
++ public void setSizeProperty(String propertyName, String propertyValue) {
++ this.sizeProperty.setName(propertyName);
++ this.sizeProperty.setValue(propertyValue);
++ }
++
++ public Property getDeleteOnTerminationProperty() {
++ return deleteOnTerminationProperty;
++ }
++
++ public void setDeleteOnTerminationProperty(String propertyName, String propertyValue) {
++ this.deleteOnTerminationProperty.setName(propertyName);
++ this.deleteOnTerminationProperty.setValue(propertyValue);
++ }
++}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/09d0beff/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/SubscriptionData.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/SubscriptionData.java
index a0801a3,94242c6..99237fa
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/SubscriptionData.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/SubscriptionData.java
@@@ -18,7 -18,7 +18,6 @@@
package org.apache.stratos.manager.subscription;
- import org.apache.stratos.cloud.controller.pojo.PersistanceMapping;
-import org.apache.stratos.cloud.controller.pojo.Persistence;
import org.apache.stratos.cloud.controller.pojo.Property;
/**
@@@ -41,8 -42,8 +40,7 @@@ public class SubscriptionData
private String repositoryPassword;
private String lbClusterId;
private Property[] properties;
-- private String dataCartridgeAlias;
- private PersistanceMapping persistanceMapping;
- private String lbAlias;
++ private PersistenceContext persistanceCtxt;
public String getCartridgeType() {
return cartridgeType;
@@@ -156,15 -157,7 +154,11 @@@
this.properties = properties;
}
-- public void setDataCartridgeAlias(String dataCartridgeAlias) {this.dataCartridgeAlias = dataCartridgeAlias; }
-
- public String getDataCartridgeAlias() {return dataCartridgeAlias;}
-
- public PersistanceMapping getPersistanceMapping() {
- return persistanceMapping;
++ public PersistenceContext getPersistanceContext() {
++ return persistanceCtxt;
+ }
- public void setPersistanceMapping(PersistanceMapping persistanceMapping) {
- this.persistanceMapping = persistanceMapping;
- public String getDataCartridgeAlias() {return dataCartridgeAlias;}
++ public void setPersistanceCtxt(PersistenceContext persistanceCtxt) {
++ this.persistanceCtxt = persistanceCtxt;
+ }
}
[03/12] git commit: lb subscription refactoring contd.
Posted by is...@apache.org.
lb subscription refactoring contd.
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/436abf4f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/436abf4f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/436abf4f
Branch: refs/heads/master
Commit: 436abf4f8dfe254eafd9b7222cce502263827ee0
Parents: eaedb07 98edba2
Author: Isuru <is...@wso2.com>
Authored: Sat Feb 15 20:59:42 2014 +0530
Committer: Isuru <is...@wso2.com>
Committed: Sat Feb 15 20:59:42 2014 +0530
----------------------------------------------------------------------
.../behaviour/CartridgeMgtBehaviour.java | 46 ++++++++
.../multitenant/lb/MultiTenantLBService.java | 17 ++-
.../manager/CartridgeSubscriptionManager.java | 91 ++++++++++++++++
.../subscription/CartridgeSubscription.java | 26 ++---
.../subscription/DataCartridgeSubscription.java | 3 +-
.../ServiceDeploymentMultiTenantBehaviour.java | 109 -------------------
.../SubscriptionMultiTenantBehaviour.java | 50 +++++----
.../SubscriptionSingleTenantBehaviour.java | 67 ++++++------
.../tenancy/SubscriptionTenancyBehaviour.java | 20 +++-
.../utils/CartridgeSubscriptionUtils.java | 34 +++---
10 files changed, 251 insertions(+), 212 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/436abf4f/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/multitenant/lb/MultiTenantLBService.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/multitenant/lb/MultiTenantLBService.java
index 55f9592,55f9592..3d8caa8
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/multitenant/lb/MultiTenantLBService.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/multitenant/lb/MultiTenantLBService.java
@@@ -26,15 -26,15 +26,19 @@@ import org.apache.stratos.cloud.control
import org.apache.stratos.manager.deploy.service.Service;
import org.apache.stratos.manager.exception.ADCException;
import org.apache.stratos.manager.exception.UnregisteredCartridgeException;
--import org.apache.stratos.manager.utils.ApplicationManagementUtil;
--import org.apache.stratos.manager.utils.CartridgeConstants;
++import org.apache.stratos.manager.lb.category.LoadBalancerCategory;
public class MultiTenantLBService extends Service {
private static Log log = LogFactory.getLog(MultiTenantLBService.class);
-- public MultiTenantLBService(String type, String autoscalingPolicyName, String deploymentPolicyName, int tenantId, CartridgeInfo cartridgeInfo, String tenantRange) {
++ private LoadBalancerCategory loadBalancerCategory;
++
++ public MultiTenantLBService(String type, String autoscalingPolicyName, String deploymentPolicyName, int tenantId,
++ CartridgeInfo cartridgeInfo, String tenantRange, LoadBalancerCategory loadBalancerCategory) {
++
super(type, autoscalingPolicyName, deploymentPolicyName, tenantId, cartridgeInfo, tenantRange);
++ this.loadBalancerCategory = loadBalancerCategory;
}
@Override
@@@ -43,8 -43,8 +47,9 @@@
super.deploy(properties);
//register the service
-- ApplicationManagementUtil.registerService(getType(), getClusterId(), CartridgeConstants.DEFAULT_SUBDOMAIN,
-- getPayloadData().getCompletePayloadData(), getTenantRange(), getHostName(), getAutoscalingPolicyName(),
-- getDeploymentPolicyName(), properties);
++ loadBalancerCategory.register();
++// ApplicationManagementUtil.registerService(getType(), getClusterId(), CartridgeConstants.DEFAULT_SUBDOMAIN,
++// getPayloadData().getCompletePayloadData(), getTenantRange(), getHostName(), getAutoscalingPolicyName(),
++// getDeploymentPolicyName(), properties);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/436abf4f/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
index 25f1a77,25f1a77..4e603c5
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
@@@ -26,8 -26,8 +26,10 @@@ import org.apache.stratos.cloud.control
import org.apache.stratos.cloud.controller.pojo.Property;
import org.apache.stratos.manager.client.CloudControllerServiceClient;
import org.apache.stratos.manager.dao.CartridgeSubscriptionInfo;
++import org.apache.stratos.manager.dao.Cluster;
import org.apache.stratos.manager.dto.SubscriptionInfo;
import org.apache.stratos.manager.exception.*;
++import org.apache.stratos.manager.lb.category.*;
import org.apache.stratos.manager.repository.Repository;
import org.apache.stratos.manager.retriever.DataInsertionAndRetrievalManager;
import org.apache.stratos.manager.subscriber.Subscriber;
@@@ -42,9 -42,9 +44,11 @@@ import org.apache.stratos.manager.topol
import org.apache.stratos.manager.utils.ApplicationManagementUtil;
import org.apache.stratos.manager.utils.CartridgeConstants;
import org.apache.stratos.manager.utils.RepoPasswordMgtUtil;
++import org.apache.stratos.messaging.util.Constants;
import org.wso2.carbon.context.CarbonContext;
import java.util.Collection;
++import java.util.Random;
/**
* Manager class for the purpose of managing CartridgeSubscriptionInfo subscriptions, groupings, etc.
@@@ -172,6 -172,6 +176,93 @@@ public class CartridgeSubscriptionManag
return cartridgeSubscription;
}
++ private CartridgeSubscription subscribeToLB (SubscriptionData subscriptionData, LBDataContext lbDataContext)
++
++ throws ADCException, InvalidCartridgeAliasException,
++ DuplicateCartridgeAliasException, PolicyException, UnregisteredCartridgeException, RepositoryRequiredException, RepositoryCredentialsRequiredException,
++ RepositoryTransportException, AlreadySubscribedException, InvalidRepositoryException {
++
++ LoadBalancerCategory loadBalancerCategory = null;
++
++ if (lbDataContext.getLbCategory().equals(Constants.NO_LOAD_BALANCER)) {
++ // no load balancer subscription required
++ return null;
++
++ }
++
++ String lbAlias = "lb" + lbDataContext.getLbCartridgeInfo().getType() + new Random().nextInt();
++
++ String lbClusterId = lbAlias + "." + lbDataContext.getLbCartridgeInfo().getType() + ".domain";
++
++ // limit the cartridge alias to 30 characters in length
++ if (lbClusterId.length() > 30) {
++ lbClusterId = CartridgeSubscriptionUtils.limitLengthOfString(lbClusterId, 30);
++ }
++
++ Cluster lbCluster = new Cluster();
++ lbCluster.setClusterDomain(lbClusterId);
++ // set hostname
++ lbCluster.setHostName(lbAlias + "." + lbDataContext.getLbCartridgeInfo().getHostName());
++
++ LBCategoryContext lbCategoryContext = new LBCategoryContext(lbDataContext.getLbCartridgeInfo().getType(), lbCluster, lbDataContext.getAutoscalePolicy(),
++ lbDataContext.getDeploymentPolicy(), lbDataContext.getLbCartridgeInfo(), );
++
++ if (lbDataContext.getLbCategory().equals(Constants.EXISTING_LOAD_BALANCERS)) {
++
++ loadBalancerCategory = new ExistingLoadBalancerCategory();
++
++ } else if (lbDataContext.getLbCategory().equals(Constants.DEFAULT_LOAD_BALANCER)) {
++ loadBalancerCategory = new DefaultLoadBalancerCategory();
++
++ } else if (lbDataContext.getLbCategory().equals(Constants.SERVICE_AWARE_LOAD_BALANCER)) {
++ loadBalancerCategory = new ServiceLevelLoadBalancerCategory();
++ }
++
++ if (loadBalancerCategory == null) {
++ throw new ADCException("The given Load Balancer category " + lbDataContext.getLbCategory() + " not found");
++ }
++
++ if(lbDataContext.getLbCartridgeInfo().getMultiTenant()) {
++ throw new ADCException("LB Cartridge must be single tenant");
++ }
++
++ // Create the CartridgeSubscription instance
++ CartridgeSubscription cartridgeSubscription = CartridgeSubscriptionFactory.getLBCartridgeSubscriptionInstance(lbDataContext, loadBalancerCategory);
++
++ // Generate and set the key
++ String subscriptionKey = CartridgeSubscriptionUtils.generateSubscriptionKey();
++ cartridgeSubscription.setSubscriptionKey(subscriptionKey);
++
++ // Create repository
++ Repository repository = cartridgeSubscription.manageRepository(null,
++ "",
++ "",
++ false,
++ lbAlias,
++ lbDataContext.getLbCartridgeInfo(),
++ subscriptionData.getTenantDomain());
++
++ // Create subscriber
++ Subscriber subscriber = new Subscriber(subscriptionData.getTenantAdminUsername(), subscriptionData.getTenantId(), subscriptionData.getTenantDomain());
++
++ // create subscription
++ cartridgeSubscription.createSubscription(subscriber, lbAlias, lbDataContext.getAutoscalePolicy(),
++ lbDataContext.getDeploymentPolicy(), repository);
++
++
++ log.info("Tenant [" + subscriptionData.getTenantId() + "] with username [" + subscriptionData.getTenantAdminUsername() +
++ " subscribed to " + "] Cartridge with Alias " + lbAlias + ", Cartridge Type: " +
++ lbCategoryContext.getLbType() + ", Autoscale Policy: " +
++ lbDataContext.getAutoscalePolicy() + ", Deployment Policy: " + lbDataContext.getDeploymentPolicy());
++
++
++ // Publish tenant subscribed event to message broker
++ CartridgeSubscriptionUtils.publishTenantSubscribedEvent(cartridgeSubscription.getSubscriber().getTenantId(),
++ cartridgeSubscription.getCartridgeInfo().getType());
++
++ return cartridgeSubscription;
++ }
++
/**
* Registers the cartridge subscription for the given CartridgeSubscriptionInfo object
*
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/436abf4f/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
index d71e107,ee145f5..30f2b74
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
@@@ -23,24 -22,16 +23,26 @@@ import org.apache.axis2.AxisFault
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy;
import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
+import org.apache.stratos.cloud.controller.pojo.LoadbalancerConfig;
+import org.apache.stratos.cloud.controller.pojo.Properties;
+import org.apache.stratos.cloud.controller.pojo.Property;
+import org.apache.stratos.manager.client.AutoscalerServiceClient;
+import org.apache.stratos.manager.client.CloudControllerServiceClient;
+ import org.apache.stratos.manager.dao.Cluster;
import org.apache.stratos.manager.deploy.service.Service;
import org.apache.stratos.manager.exception.ADCException;
import org.apache.stratos.manager.exception.DuplicateCartridgeAliasException;
import org.apache.stratos.manager.exception.InvalidCartridgeAliasException;
+import org.apache.stratos.manager.exception.UnregisteredCartridgeException;
+import org.apache.stratos.manager.lb.category.LBCategoryContext;
+import org.apache.stratos.manager.lb.category.LBDataContext;
import org.apache.stratos.manager.payload.BasicPayloadData;
+ import org.apache.stratos.manager.repository.Repository;
import org.apache.stratos.manager.retriever.DataInsertionAndRetrievalManager;
- import org.apache.stratos.manager.subscription.CartridgeSubscription;
+import org.apache.stratos.manager.subscription.SubscriptionData;
+ import org.apache.stratos.manager.subscriber.Subscriber;
import org.apache.stratos.messaging.broker.publish.EventPublisher;
import org.apache.stratos.messaging.event.tenant.TenantSubscribedEvent;
import org.apache.stratos.messaging.event.tenant.TenantUnSubscribedEvent;
[11/12] git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/incubator-stratos into
lb_logic_refactoring
Posted by is...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-stratos into lb_logic_refactoring
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/5e99f2a0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/5e99f2a0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/5e99f2a0
Branch: refs/heads/master
Commit: 5e99f2a099f721faa7537740a1835b79245eaca0
Parents: e9104e0 4577515
Author: Isuru <is...@wso2.com>
Authored: Thu Mar 6 14:27:10 2014 +0530
Committer: Isuru <is...@wso2.com>
Committed: Thu Mar 6 14:27:10 2014 +0530
----------------------------------------------------------------------
.../config/CartridgeAgentConfiguration.java | 47 +-
.../stratos/cli/RestCommandLineService.java | 19 +-
.../org.apache.stratos.cloud.controller/pom.xml | 2 +-
.../partials/configure_stratos_wizard.hbs | 12 +-
.../console/themes/theme1/renderers/index.js | 3 +
.../console/util/utility.jag | 4 -
.../CompleteTopologyMessageProcessor.java | 27 +-
.../rest/endpoint/services/ServiceUtils.java | 28 +-
.../jclouds/vcloud/1.7.1-stratos/README.txt | 6 +
.../jclouds/vcloud/1.7.1-stratos/pom.xml | 129 +++
.../vcloud/TaskInErrorStateException.java | 39 +
.../vcloud/TaskStillRunningException.java | 39 +
.../main/java/org/jclouds/vcloud/VCloudApi.java | 91 ++
.../org/jclouds/vcloud/VCloudApiMetadata.java | 103 +++
.../org/jclouds/vcloud/VCloudMediaType.java | 221 +++++
.../jclouds/vcloud/VCloudResponseException.java | 69 ++
.../java/org/jclouds/vcloud/VCloudToken.java | 37 +
.../org/jclouds/vcloud/VCloudVersionsApi.java | 38 +
.../binders/BindCPUCountToXmlPayload.java | 79 ++
.../BindCaptureVAppParamsToXmlPayload.java | 124 +++
.../binders/BindCatalogItemToXmlPayload.java | 126 +++
.../binders/BindCloneParamsToXmlPayload.java | 133 +++
.../BindCloneVAppParamsToXmlPayload.java | 65 ++
...BindCloneVAppTemplateParamsToXmlPayload.java | 60 ++
.../BindDeployVAppParamsToXmlPayload.java | 42 +
...ndGuestCustomizationSectionToXmlPayload.java | 112 +++
...stantiateVAppTemplateParamsToXmlPayload.java | 221 +++++
.../vcloud/binders/BindMemoryToXmlPayload.java | 80 ++
...indNetworkConnectionSectionToXmlPayload.java | 106 +++
.../vcloud/binders/BindParamsToXmlPayload.java | 81 ++
.../BindUndeployVAppParamsToXmlPayload.java | 42 +
.../OrgNameAndCatalogNameToEndpoint.java | 79 ++
.../binders/OrgNameAndVDCNameToEndpoint.java | 78 ++
.../OrgNameCatalogNameItemNameToEndpoint.java | 77 ++
...meCatalogNameVAppTemplateNameToEndpoint.java | 90 ++
.../OrgNameVDCNameNetworkNameToEndpoint.java | 54 ++
...NameVDCNameResourceEntityNameToEndpoint.java | 54 ++
.../OrgNameVDCNameResourceNameToEndpoint.java | 81 ++
.../VCloudComputeServiceContextModule.java | 39 +
.../VCloudComputeServiceDependenciesModule.java | 154 ++++
.../functions/FindLocationForResource.java | 69 ++
.../compute/functions/HardwareForVApp.java | 71 ++
.../functions/HardwareForVAppTemplate.java | 84 ++
.../compute/functions/ImageForVAppTemplate.java | 82 ++
.../compute/functions/VAppToNodeMetadata.java | 112 +++
...dHardwareBuilderFromResourceAllocations.java | 43 +
...EnvelopeOrThrowIllegalArgumentException.java | 77 ++
.../internal/VCloudTemplateBuilderImpl.java | 48 +
.../compute/options/VCloudTemplateOptions.java | 350 +++++++
...edIntoNameThenCustomizeDeployAndPowerOn.java | 302 +++++++
...etworkConfigurationForNetworkAndOptions.java | 80 ++
.../strategy/VCloudComputeServiceAdapter.java | 263 ++++++
.../vcloud/compute/util/VCloudComputeUtils.java | 116 +++
.../vcloud/config/DefaultCatalogForOrg.java | 63 ++
.../vcloud/config/DefaultNetworkForVDC.java | 65 ++
.../vcloud/config/DefaultOrgForUser.java | 58 ++
.../vcloud/config/DefaultTasksListForOrg.java | 53 ++
.../config/DefaultVCloudReferencesModule.java | 165 ++++
.../jclouds/vcloud/config/DefaultVDCForOrg.java | 63 ++
.../vcloud/config/VCloudHttpApiModule.java | 538 +++++++++++
.../jclouds/vcloud/domain/AllocationModel.java | 70 ++
.../org/jclouds/vcloud/domain/Capacity.java | 108 +++
.../java/org/jclouds/vcloud/domain/Catalog.java | 69 ++
.../org/jclouds/vcloud/domain/CatalogItem.java | 37 +
.../domain/GuestCustomizationSection.java | 440 +++++++++
.../domain/InstantiateVAppTemplateParams.java | 96 ++
.../vcloud/domain/NetworkConnection.java | 233 +++++
.../vcloud/domain/NetworkConnectionSection.java | 218 +++++
.../java/org/jclouds/vcloud/domain/Org.java | 86 ++
.../jclouds/vcloud/domain/ReferenceType.java | 55 ++
.../java/org/jclouds/vcloud/domain/Status.java | 246 +++++
.../java/org/jclouds/vcloud/domain/Task.java | 72 ++
.../org/jclouds/vcloud/domain/TaskStatus.java | 71 ++
.../org/jclouds/vcloud/domain/TasksList.java | 37 +
.../java/org/jclouds/vcloud/domain/VApp.java | 87 ++
.../org/jclouds/vcloud/domain/VAppTemplate.java | 97 ++
.../org/jclouds/vcloud/domain/VCloudError.java | 123 +++
.../jclouds/vcloud/domain/VCloudSession.java | 29 +
.../java/org/jclouds/vcloud/domain/VDC.java | 146 +++
.../org/jclouds/vcloud/domain/VDCStatus.java | 57 ++
.../main/java/org/jclouds/vcloud/domain/Vm.java | 108 +++
.../vcloud/domain/internal/CatalogImpl.java | 193 ++++
.../vcloud/domain/internal/CatalogItemImpl.java | 111 +++
.../vcloud/domain/internal/ErrorImpl.java | 119 +++
.../jclouds/vcloud/domain/internal/OrgImpl.java | 171 ++++
.../domain/internal/ReferenceTypeImpl.java | 103 +++
.../vcloud/domain/internal/TaskImpl.java | 165 ++++
.../vcloud/domain/internal/TasksListImpl.java | 81 ++
.../vcloud/domain/internal/VAppImpl.java | 166 ++++
.../domain/internal/VAppTemplateImpl.java | 205 +++++
.../jclouds/vcloud/domain/internal/VDCImpl.java | 292 ++++++
.../jclouds/vcloud/domain/internal/VmImpl.java | 217 +++++
.../vcloud/domain/network/DhcpService.java | 106 +++
.../jclouds/vcloud/domain/network/Features.java | 95 ++
.../vcloud/domain/network/FenceMode.java | 70 ++
.../vcloud/domain/network/FirewallService.java | 86 ++
.../domain/network/IpAddressAllocationMode.java | 52 ++
.../jclouds/vcloud/domain/network/IpRange.java | 76 ++
.../jclouds/vcloud/domain/network/IpScope.java | 170 ++++
.../vcloud/domain/network/NatService.java | 115 +++
.../vcloud/domain/network/NetworkConfig.java | 167 ++++
.../vcloud/domain/network/OrgNetwork.java | 121 +++
.../domain/network/firewall/FirewallPolicy.java | 54 ++
.../network/firewall/FirewallProtocols.java | 73 ++
.../domain/network/firewall/FirewallRule.java | 125 +++
.../domain/network/internal/OrgNetworkImpl.java | 202 +++++
.../vcloud/domain/network/nat/NatPolicy.java | 54 ++
.../vcloud/domain/network/nat/NatProtocol.java | 48 +
.../vcloud/domain/network/nat/NatRule.java | 35 +
.../vcloud/domain/network/nat/NatType.java | 61 ++
.../domain/network/nat/rules/MappingMode.java | 54 ++
.../network/nat/rules/OneToOneVmRule.java | 110 +++
.../network/nat/rules/PortForwardingRule.java | 111 +++
.../vcloud/domain/network/nat/rules/VmRule.java | 128 +++
.../EditableResourceAllocationSettingData.java | 302 +++++++
.../vcloud/domain/ovf/VCloudHardDisk.java | 330 +++++++
.../vcloud/domain/ovf/VCloudNetworkAdapter.java | 332 +++++++
.../vcloud/domain/ovf/VCloudNetworkSection.java | 80 ++
.../ovf/VCloudOperatingSystemSection.java | 118 +++
.../ovf/VCloudVirtualHardwareSection.java | 179 ++++
.../org/jclouds/vcloud/endpoints/Catalog.java | 37 +
.../org/jclouds/vcloud/endpoints/Network.java | 37 +
.../java/org/jclouds/vcloud/endpoints/Org.java | 37 +
.../org/jclouds/vcloud/endpoints/OrgList.java | 37 +
.../org/jclouds/vcloud/endpoints/TasksList.java | 37 +
.../jclouds/vcloud/endpoints/VCloudLogin.java | 38 +
.../java/org/jclouds/vcloud/endpoints/VDC.java | 37 +
.../org/jclouds/vcloud/features/CatalogApi.java | 144 +++
.../org/jclouds/vcloud/features/NetworkApi.java | 61 ++
.../org/jclouds/vcloud/features/OrgApi.java | 86 ++
.../org/jclouds/vcloud/features/TaskApi.java | 82 ++
.../org/jclouds/vcloud/features/VAppApi.java | 261 ++++++
.../vcloud/features/VAppTemplateApi.java | 180 ++++
.../org/jclouds/vcloud/features/VDCApi.java | 73 ++
.../java/org/jclouds/vcloud/features/VmApi.java | 295 ++++++
...ddVCloudAuthorizationAndCookieToRequest.java | 63 ++
.../vcloud/functions/CatalogItemsInCatalog.java | 64 ++
.../vcloud/functions/CatalogItemsInOrg.java | 57 ++
.../jclouds/vcloud/functions/CatalogsInOrg.java | 73 ++
.../functions/DefaultNetworkNameInTemplate.java | 47 +
.../jclouds/vcloud/functions/NetworksInOrg.java | 57 ++
.../vcloud/functions/OrgNameToEndpoint.java | 57 ++
.../functions/OrgNameToTasksListEndpoint.java | 62 ++
.../vcloud/functions/OrgsForLocations.java | 73 ++
.../jclouds/vcloud/functions/OrgsForNames.java | 56 ++
.../ParseLoginResponseFromHeaders.java | 105 +++
.../functions/VAppTemplatesForCatalogItems.java | 66 ++
.../vcloud/functions/VAppTemplatesInOrg.java | 65 ++
.../org/jclouds/vcloud/functions/VDCsInOrg.java | 57 ++
.../ParseVCloudErrorFromHttpResponse.java | 121 +++
.../http/filters/VCloudBasicAuthentication.java | 58 ++
.../http/filters/VCloudSupportedVersions.java | 35 +
.../jclouds/vcloud/internal/VCloudLoginApi.java | 44 +
.../org/jclouds/vcloud/loaders/OVFLoader.java | 47 +
.../vcloud/loaders/VAppTemplateLoader.java | 47 +
.../org/jclouds/vcloud/location/DefaultVDC.java | 74 ++
.../location/OrgAndVDCToLocationSupplier.java | 93 ++
.../vcloud/options/CaptureVAppOptions.java | 51 ++
.../vcloud/options/CatalogItemOptions.java | 77 ++
.../jclouds/vcloud/options/CloneOptions.java | 53 ++
.../vcloud/options/CloneVAppOptions.java | 88 ++
.../options/CloneVAppTemplateOptions.java | 42 +
.../options/InstantiateVAppTemplateOptions.java | 178 ++++
.../jclouds/vcloud/predicates/TaskSuccess.java | 65 ++
.../vcloud/reference/VCloudConstants.java | 51 ++
.../jclouds/vcloud/reference/package-info.java | 21 +
...thNameMatchingConfigurationKeyOrDefault.java | 99 ++
.../vcloud/suppliers/VAppTemplatesSupplier.java | 86 ++
.../java/org/jclouds/vcloud/util/Utils.java | 71 ++
.../org/jclouds/vcloud/util/VCloudUtils.java | 67 ++
.../org/jclouds/vcloud/xml/CatalogHandler.java | 104 +++
.../jclouds/vcloud/xml/CatalogItemHandler.java | 81 ++
.../org/jclouds/vcloud/xml/ErrorHandler.java | 45 +
.../xml/GuestCustomizationSectionHandler.java | 137 +++
.../vcloud/xml/NetworkConnectionHandler.java | 87 ++
.../xml/NetworkConnectionSectionHandler.java | 103 +++
.../java/org/jclouds/vcloud/xml/OrgHandler.java | 112 +++
.../org/jclouds/vcloud/xml/OrgListHandler.java | 54 ++
.../jclouds/vcloud/xml/OrgNetworkHandler.java | 325 +++++++
.../vcloud/xml/SupportedVersionsHandler.java | 60 ++
.../org/jclouds/vcloud/xml/TaskHandler.java | 128 +++
.../jclouds/vcloud/xml/TasksListHandler.java | 74 ++
.../org/jclouds/vcloud/xml/VAppHandler.java | 151 ++++
.../jclouds/vcloud/xml/VAppTemplateHandler.java | 152 ++++
.../xml/VCloudVirtualHardwareHandler.java | 72 ++
.../java/org/jclouds/vcloud/xml/VDCHandler.java | 167 ++++
.../java/org/jclouds/vcloud/xml/VmHandler.java | 178 ++++
.../xml/ovf/VCloudNetworkSectionHandler.java | 69 ++
.../xml/ovf/VCloudOperatingSystemHandler.java | 81 ++
...oudResourceAllocationSettingDataHandler.java | 89 ++
.../services/org.jclouds.apis.ApiMetadata | 1 +
.../jclouds/vcloud/VCloudApiMetadataTest.java | 32 +
.../java/org/jclouds/vcloud/VCloudApiTest.java | 64 ++
.../vcloud/VCloudSessionRefreshLiveTest.java | 41 +
.../jclouds/vcloud/VCloudVersionsApiTest.java | 69 ++
.../BindCatalogItemToXmlPayloadTest.java | 53 ++
.../BindCloneVAppParamsToXmlPayloadTest.java | 81 ++
...CloneVAppTemplateParamsToXmlPayloadTest.java | 89 ++
.../BindDeployVAppParamsToXmlPayloadTest.java | 61 ++
...tiateVAppTemplateParamsToXmlPayloadTest.java | 179 ++++
...etworkConnectionSectionToXmlPayloadTest.java | 68 ++
.../BindUndeployVAppParamsToXmlPayloadTest.java | 61 ++
.../BaseVCloudComputeServiceExpectTest.java | 160 ++++
.../compute/VCloudComputeServiceLiveTest.java | 54 ++
.../functions/FindLocationForResourceTest.java | 64 ++
.../functions/ListImagesInVCloudExpectTest.java | 89 ++
.../functions/VAppToNodeMetadataTest.java | 228 +++++
.../options/VCloudTemplateOptionsTest.java | 197 ++++
...ThenCustomizeDeployAndPowerOnExpectTest.java | 171 ++++
.../VCloudComputeServiceAdapterTest.java | 89 ++
.../vcloud/features/CatalogApiLiveTest.java | 53 ++
.../jclouds/vcloud/features/CatalogApiTest.java | 131 +++
.../vcloud/features/NetworkApiLiveTest.java | 29 +
.../jclouds/vcloud/features/NetworkApiTest.java | 75 ++
.../jclouds/vcloud/features/OrgApiLiveTest.java | 42 +
.../org/jclouds/vcloud/features/OrgApiTest.java | 91 ++
.../vcloud/features/TaskApiLiveTest.java | 29 +
.../jclouds/vcloud/features/TaskApiTest.java | 108 +++
.../vcloud/features/VAppApiLiveTest.java | 53 ++
.../jclouds/vcloud/features/VAppApiTest.java | 315 +++++++
.../features/VAppTemplateApiLiveTest.java | 168 ++++
.../vcloud/features/VAppTemplateApiTest.java | 238 +++++
.../jclouds/vcloud/features/VDCApiLiveTest.java | 29 +
.../org/jclouds/vcloud/features/VDCApiTest.java | 102 +++
.../jclouds/vcloud/features/VmApiLiveTest.java | 163 ++++
.../org/jclouds/vcloud/features/VmApiTest.java | 320 +++++++
...loudAuthorizationAndCookieToRequestTest.java | 55 ++
.../ParseLoginResponseFromHeadersTest.java | 147 +++
.../ParseVCloudErrorFromHttpResponseTest.java | 96 ++
.../vcloud/internal/BasePayloadTest.java | 51 ++
.../vcloud/internal/BaseVCloudApiLiveTest.java | 59 ++
.../vcloud/internal/BaseVCloudApiTest.java | 272 ++++++
.../vcloud/internal/VCloudLoginApiTest.java | 97 ++
.../InstantiateVAppTemplateOptionsTest.java | 74 ++
...meMatchingConfigurationKeyOrDefaultTest.java | 115 +++
.../org/jclouds/vcloud/utils/TestUtils.java | 32 +
.../jclouds/vcloud/xml/CatalogHandlerTest.java | 135 +++
.../vcloud/xml/CatalogItemHandlerTest.java | 86 ++
.../GuestCustomizationSectionHandlerTest.java | 75 ++
.../xml/NetworkConnectionHandlerTest.java | 57 ++
.../NetworkConnectionSectionHandlerTest.java | 63 ++
.../org/jclouds/vcloud/xml/OrgHandlerTest.java | 124 +++
.../jclouds/vcloud/xml/OrgListHandlerTest.java | 57 ++
.../vcloud/xml/OrgNetworkHandlerTest.java | 104 +++
.../xml/SupportedVersionsHandlerTest.java | 53 ++
.../org/jclouds/vcloud/xml/TaskHandlerTest.java | 135 +++
.../vcloud/xml/TasksListHandlerTest.java | 82 ++
.../org/jclouds/vcloud/xml/VAppHandlerTest.java | 77 ++
.../vcloud/xml/VAppTemplateHandlerTest.java | 164 ++++
.../org/jclouds/vcloud/xml/VDCHandlerTest.java | 136 +++
.../org/jclouds/vcloud/xml/VmHandlerTest.java | 79 ++
...VCloudOperatingSystemSectionHandlerTest.java | 61 ++
...VCloudVirtualHardwareSectionHandlerTest.java | 153 ++++
.../src/test/resources/captureVApp-default.xml | 1 +
.../src/test/resources/captureVApp.xml | 1 +
.../src/test/resources/catalog-blank.xml | 7 +
.../src/test/resources/catalog-hosting.xml | 25 +
.../src/test/resources/catalog.xml | 27 +
.../src/test/resources/catalog1.0-vcd15.xml | 9 +
...alogItem-carrenza-with-default-namespace.xml | 8 +
...talogItem-carrenza-with-vcloud-namespace.xml | 8 +
.../src/test/resources/catalogItem-hosting.xml | 14 +
.../test/resources/catalogItem-terremark.xml | 16 +
.../src/test/resources/catalogItem1.0-vcd15.xml | 8 +
.../src/test/resources/copyVApp-default.xml | 1 +
.../src/test/resources/copyVApp.xml | 1 +
.../test/resources/copyVAppTemplate-default.xml | 1 +
.../src/test/resources/copyVAppTemplate.xml | 1 +
.../src/test/resources/cpuItem.xml | 1 +
.../src/test/resources/guestCustomization.xml | 23 +
.../resources/guestCustomizationSection.xml | 3 +
.../src/test/resources/instantiatedvapp.xml | 13 +
.../instantiationparams-description.xml | 1 +
.../resources/instantiationparams-network.xml | 1 +
.../src/test/resources/instantiationparams.xml | 1 +
.../1.7.1-stratos/src/test/resources/log4j.xml | 151 ++++
.../src/test/resources/memoryItem.xml | 1 +
.../src/test/resources/moveVApp.xml | 1 +
.../src/test/resources/moveVAppTemplate.xml | 1 +
.../src/test/resources/networkconnection.xml | 7 +
.../test/resources/networkconnectionsection.xml | 18 +
.../src/test/resources/org-1.0.xml | 24 +
.../src/test/resources/org-hosting.xml | 12 +
.../src/test/resources/org-savvis.xml | 13 +
.../1.7.1-stratos/src/test/resources/org.xml | 5 +
.../src/test/resources/org1.0-vcd15.xml | 11 +
.../src/test/resources/orgList1.0-vcd15.xml | 4 +
.../src/test/resources/orglist-savvis.xml | 3 +
.../src/test/resources/orglist.xml | 3 +
.../src/test/resources/orgnetwork-bridged.xml | 20 +
.../src/test/resources/orgnetwork-isolated.xml | 31 +
.../1.7.1-stratos/src/test/resources/os.xml | 11 +
.../src/test/resources/ovf-multi-vm.xml | 285 ++++++
.../src/test/resources/ovf-ubuntu64.xml | 148 +++
.../src/test/resources/task-1.0.xml | 9 +
.../src/test/resources/task-error.xml | 9 +
.../src/test/resources/task-hosting.xml | 12 +
.../src/test/resources/task-self.xml | 11 +
.../src/test/resources/task-vcd15.xml | 5 +
.../1.7.1-stratos/src/test/resources/task.xml | 8 +
.../src/test/resources/taskslist-hosting.xml | 14 +
.../src/test/resources/taskslist.xml | 27 +
.../resources/template1.0-vcd15-multi-vm.xml | 68 ++
.../src/test/resources/template1.0-vcd15.xml | 72 ++
.../src/test/resources/vAppTemplate-copying.xml | 41 +
.../src/test/resources/vAppTemplate.xml | 143 +++
.../vAppTemplate1.0-vcd15_withNewlines.xml | 109 +++
.../src/test/resources/vapp-hosting.xml | 235 +++++
.../src/test/resources/vapp-none.xml | 237 +++++
.../src/test/resources/vapp-pool.xml | 227 +++++
.../src/test/resources/vapp-rhel-off-static.xml | 325 +++++++
.../src/test/resources/vapp-ubuntu-off-dhcp.xml | 213 +++++
.../src/test/resources/vapp-unresolved.xml | 21 +
.../src/test/resources/vapp-win-off-static.xml | 219 +++++
.../src/test/resources/vdc-1.0.xml | 49 +
.../src/test/resources/vdc-hosting.xml | 60 ++
.../src/test/resources/vdc-nonet.xml | 22 +
.../1.7.1-stratos/src/test/resources/vdc.xml | 36 +
.../src/test/resources/vdc1.0-vcd15.xml | 47 +
.../src/test/resources/versions-vcd15.xml | 906 +++++++++++++++++++
.../src/test/resources/versions.xml | 7 +
.../test/resources/virtualhardwaresection.xml | 118 +++
.../src/test/resources/vm-rhel-off-static.xml | 197 ++++
dependencies/pom.xml | 41 +
.../pom.xml | 4 +-
pom.xml | 2 +
tools/puppet3-agent/config.sh | 3 +-
tools/stratos-installer/setup.sh | 2 +-
328 files changed, 30233 insertions(+), 58 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5e99f2a0/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
index c24f0c4,45b2551..1f70896
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
@@@ -993,20 -1019,305 +991,20 @@@ public class ServiceUtils
subscriptionData.setTenantAdminUsername(tenantUsername);
subscriptionData.setRepositoryType("git");
subscriptionData.setRepositoryURL(cartridgeInfoBean.getRepoURL());
- subscriptionData.setRepositoryUsername(cartridgeInfoBean.getRepoURL());
+ subscriptionData.setRepositoryUsername(cartridgeInfoBean.getRepoUsername());
subscriptionData.setRepositoryPassword(cartridgeInfoBean.getRepoPassword());
- Properties properties = new Properties();
- if(cartridgeInfoBean.isPersistanceRequired()){
- /*
- PersistanceMapping persistanceMapping = new PersistanceMapping();
- persistanceMapping.setPersistanceRequired(persistanceMappingBean.persistanceRequired);
- persistanceMapping.setSize(persistanceMappingBean.size);
- persistanceMapping.setDevice(persistanceMappingBean.device);
- persistanceMapping.setRemoveOntermination(persistanceMappingBean.removeOnTermination);
- subscriptionData.setPersistanceMapping(persistanceMapping);
- */
-
- // Add persistance mapping properties to the subscription.
- Property persistanceRequiredProperty = new Property();
- persistanceRequiredProperty.setName(IS_VOLUME_REQUIRED);
- persistanceRequiredProperty.setValue(String.valueOf(cartridgeInfoBean.isPersistanceRequired()));
-
- Property sizeProperty = new Property();
- sizeProperty.setName(VOLUME_SIZE);
- sizeProperty.setValue(cartridgeInfoBean.getSize());
-
- Property deleteOnTerminationProperty = new Property();
- deleteOnTerminationProperty.setName(SHOULD_DELETE_VOLUME);
- deleteOnTerminationProperty.setValue(String.valueOf( cartridgeInfoBean.isRemoveOnTermination()));
-
- properties.setProperties(new Property[]{persistanceRequiredProperty,sizeProperty, deleteOnTerminationProperty});
- }
-
-
- // If multitenant, return for now. TODO -- fix properly
- if(cartridgeInfo != null && cartridgeInfo.getMultiTenant()) {
- log.info(" ******* MT cartridge ******* ");
-
- subscriptionData.setPrivateRepository(false);
- subscriptionData.setLbClusterId(null);
- subscriptionData.setProperties(null);
-
- CartridgeSubscription cartridgeSubscription =
- cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(subscriptionData);
- log.info(" --- ** -- ");
- return cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription, properties);
-
+ if (cartridgeInfoBean.isPersistanceRequired()) {
+ // Add persistence related properties to PersistenceContext
+ PersistenceContext persistenceContext = new PersistenceContext();
+ persistenceContext.setPersistanceRequiredProperty(IS_VOLUME_REQUIRED, String.valueOf(cartridgeInfoBean.isPersistanceRequired()));
+ persistenceContext.setSizeProperty(VOLUME_SIZE, cartridgeInfoBean.getSize());
+ persistenceContext.setDeleteOnTerminationProperty(SHOULD_DELETE_VOLUME, String.valueOf(cartridgeInfoBean.isRemoveOnTermination()));
+ subscriptionData.setPersistanceCtxt(persistenceContext);
}
-
- List<Property> lbRefProp = new ArrayList<Property>();
-
- // get lb config reference
- LoadbalancerConfig lbConfig = cartridgeInfo.getLbConfig();
- String lbClusterId = null;
-
- if (lbConfig == null || lbConfig.getProperties() == null) {
- if (log.isDebugEnabled()) {
- log.debug("This Service does not require a load balancer. " + "[Service Name] " +
- cartridgeType);
- }
- } else {
-
- Properties lbReferenceProperties = lbConfig.getProperties();
-
- Property property = new Property();
- property.setName(org.apache.stratos.messaging.util.Constants.LOAD_BALANCER_REF);
-
- for (org.apache.stratos.cloud.controller.pojo.Property prop : lbReferenceProperties.getProperties()) {
-
- String name = prop.getName();
- String value = prop.getValue();
-
- // TODO make following a chain of responsibility pattern
- if (Constants.NO_LOAD_BALANCER.equals(name)) {
- if ("true".equals(value)) {
- if (log.isDebugEnabled()) {
- log.debug("This cartridge does not require a load balancer. " +
- "[Type] " + cartridgeType);
- }
- property.setValue(name);
- lbRefProp.add(property);
- break;
- }
- } else if (Constants.EXISTING_LOAD_BALANCERS.equals(name)) {
- String clusterIdsVal = value;
- if (log.isDebugEnabled()) {
- log.debug("This cartridge refers to existing load balancers. " + "[Type] " +
- cartridgeType + "[Referenced Cluster Ids] " + clusterIdsVal);
- }
-
- String[] clusterIds = clusterIdsVal.split(",");
-
- for (String clusterId : clusterIds) {
- if (autoscalerServiceClient != null) {
- try {
- autoscalerServiceClient.checkLBExistenceAgainstPolicy(clusterId,
- deploymentPolicy);
- } catch (Exception ex) {
- // we don't need to throw the error here.
- log.error(ex.getMessage(), ex);
- }
- }
- }
-
- property.setValue(name);
- lbRefProp.add(property);
- break;
-
- } else if (Constants.DEFAULT_LOAD_BALANCER.equals(name)) {
-
- if ("true".equals(value)) {
-
- CartridgeInfo lbCartridgeInfo = null;
- String lbCartridgeType = lbConfig.getType();
- try {
- // retrieve lb Cartridge info
- if(lbCartridgeType != null) {
- lbCartridgeInfo = cloudControllerServiceClient.getCartridgeInfo(lbCartridgeType);
- }
- } catch (Exception e) {
- String msg = "Cannot get cartridge info: " + cartridgeType;
- log.error(msg, e);
- throw new ADCException(msg, e);
- }
-
- property.setValue(name);
- if (log.isDebugEnabled()) {
- log.debug("This cartridge uses default load balancer. " + "[Type] " +
- cartridgeType);
- }
- if (autoscalerServiceClient != null) {
- try {
- // get the valid policies for lb cartridge
- DeploymentPolicy[] lbCartridgeDepPolicies =
- autoscalerServiceClient.getDeploymentPolicies(lbCartridgeType);
- // traverse deployment policies of lb cartridge
- for (DeploymentPolicy policy : lbCartridgeDepPolicies) {
- // check existence of the subscribed policy
- if (deploymentPolicy.equals(policy.getId())) {
-
- if (!autoscalerServiceClient.checkDefaultLBExistenceAgainstPolicy(deploymentPolicy)) {
-
- // if lb cluster doesn't exist
- String lbAlias = "lb" + new Random().nextInt();
- if(lbCartridgeInfo != null) {
- lbCartridgeInfo.addProperties(property);
- lbClusterId = subscribeToLb(lbCartridgeType, cartridgeType,
- lbAlias,
- lbCartridgeInfo.getDefaultAutoscalingPolicy(),
- deploymentPolicy, configurationContext,
- tenantUsername, tenantDomain,
- lbCartridgeInfo.getProperties());
- } else {
- String msg = "Please specify a LB cartridge type for the cartridge: "
- + cartridgeType + " as category: " +
- Constants.DEFAULT_LOAD_BALANCER;
- log.error(msg);
- throw new ADCException(msg);
- }
- }
- }
- }
-
- } catch (Exception ex) {
- // we don't need to throw the error here.
- log.error(ex.getMessage(), ex);
- }
- }
-
- lbRefProp.add(property);
- break;
- }
-
- } else if (Constants.SERVICE_AWARE_LOAD_BALANCER.equals(name)) {
-
- if ("true".equals(value)) {
-
- CartridgeInfo lbCartridgeInfo = null;
- String lbCartridgeType = lbConfig.getType();
- try {
- // retrieve lb Cartridge info
- if(lbCartridgeType != null) {
- lbCartridgeInfo = cloudControllerServiceClient.getCartridgeInfo(lbCartridgeType);
- }
- } catch (Exception e) {
- String msg = "Cannot get cartridge info: " + cartridgeType+". Cause: "+e.getMessage();
- log.error(msg, e);
- throw new ADCException(msg, e);
- }
-
- // add a property for the service type
- Property loadBalancedServiceTypeProperty = new Property();
- loadBalancedServiceTypeProperty.setName(Constants.LOAD_BALANCED_SERVICE_TYPE);
-
- property.setValue(name);
- // set the load balanced service type
- loadBalancedServiceTypeProperty.setValue(cartridgeType);
- if (log.isDebugEnabled()) {
- log.debug("This cartridge uses a service aware load balancer. " +
- "[Type] " + cartridgeType);
- }
- if (autoscalerServiceClient != null) {
- try {
-
- // get the valid policies for lb cartridge
- DeploymentPolicy[] lbCartridgeDepPolicies =
- autoscalerServiceClient.getDeploymentPolicies(lbCartridgeType);
- // traverse deployment policies of lb cartridge
- for (DeploymentPolicy policy : lbCartridgeDepPolicies) {
- // check existence of the subscribed policy
- if (deploymentPolicy.equals(policy.getId())) {
-
- if (!autoscalerServiceClient.checkServiceLBExistenceAgainstPolicy(cartridgeType,
- deploymentPolicy)) {
-
- // if lb cluster doesn't exist
- String lbAlias =
- "lb" + cartridgeType +
- new Random().nextInt();
-
- if(lbCartridgeInfo != null) {
- lbCartridgeInfo.addProperties(property);
- lbCartridgeInfo.addProperties(loadBalancedServiceTypeProperty);
-
- lbClusterId = subscribeToLb(lbCartridgeType, cartridgeType,
- lbAlias,
- lbCartridgeInfo.getDefaultAutoscalingPolicy(),
- deploymentPolicy,
- configurationContext, tenantUsername,
- tenantDomain,
- lbCartridgeInfo.getProperties());
- } else {
- String msg = "Please specify a LB cartridge type for the cartridge: "
- + cartridgeType + " as category: " +
- Constants.SERVICE_AWARE_LOAD_BALANCER;
- log.error(msg);
- throw new ADCException(msg);
- }
- }
- }
- }
-
- } catch (Exception ex) {
- // we don't need to throw the error here.
- log.error(ex.getMessage(), ex);
- }
- }
-
- lbRefProp.add(property);
- break;
- }
- }
- }
- }
-
- subscriptionData.setPrivateRepository(cartridgeInfoBean.isPrivateRepo());
- subscriptionData.setLbClusterId(lbClusterId);
- subscriptionData.setProperties(lbRefProp.toArray(new Property[0]));
- CartridgeSubscription cartridgeSubscription =
- cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(subscriptionData);
-
-
- if (dataCartridgeAlias != null && !dataCartridgeAlias.trim().isEmpty()) {
-
- /*dataCartridgeAlias = dataCartridgeAlias.trim();
-
- CartridgeSubscription connectingCartridgeSubscription = null;
- try {
- connectingCartridgeSubscription =
- cartridgeSubsciptionManager.getCartridgeSubscription(tenantDomain,
- dataCartridgeAlias);
-
- } catch (NotSubscribedException e) {
- log.error(e.getMessage(), e);
- }
- if (connectingCartridgeSubscription != null) {
- try {
- cartridgeSubsciptionManager.connectCartridges(tenantDomain,
- cartridgeSubscription,
- connectingCartridgeSubscription.getAlias());
-
- } catch (NotSubscribedException e) {
- log.error(e.getMessage(), e);
-
- } catch (AxisFault axisFault) {
- log.error(axisFault.getMessage(), axisFault);
- }
- } else {
- log.error("Failed to connect. No cartridge subscription found for tenant " +
- ApplicationManagementUtil.getTenantId(configurationContext) +
- " with alias " + alias);
- }*/
- }
-
- for (Property lbRefProperty : lbRefProp) {
- properties.addProperties(lbRefProperty);
- }
-
- SubscriptionInfo registerCartridgeSubscription = cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription, properties);
-
- return registerCartridgeSubscription;
+ //subscribe
+ return cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(subscriptionData);
}
[05/12] git commit: finalizing the refactoring of LB subscription and
service deployment
Posted by is...@apache.org.
finalizing the refactoring of LB subscription and service deployment
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/e79a7e2f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/e79a7e2f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/e79a7e2f
Branch: refs/heads/master
Commit: e79a7e2f0285bd523ef2e459801a3076ac866d8a
Parents: 436abf4
Author: Isuru <is...@wso2.com>
Authored: Sun Feb 16 20:08:13 2014 +0530
Committer: Isuru <is...@wso2.com>
Committed: Sun Feb 16 20:08:13 2014 +0530
----------------------------------------------------------------------
.../behaviour/CartridgeMgtBehaviour.java | 120 ++-
.../stratos/manager/deploy/service/Service.java | 64 +-
.../service/ServiceDeploymentManager.java | 475 ++++++------
.../multitenant/lb/MultiTenantLBService.java | 6 +-
.../category/DefaultLoadBalancerCategory.java | 4 -
.../category/ExistingLoadBalancerCategory.java | 25 +-
.../manager/lb/category/LBCategoryContext.java | 152 ----
.../lb/category/LoadBalancerCategory.java | 123 +---
.../ServiceLevelLoadBalancerCategory.java | 18 +-
.../manager/CartridgeSubscriptionManager.java | 267 ++++---
.../subscription/LBCartridgeSubscription.java | 14 +-
.../manager/subscription/SubscriptionData.java | 2 -
.../SubscriptionSingleTenantBehaviour.java | 124 ----
.../tenancy/SubscriptionTenancyBehaviour.java | 27 +-
.../utils/CartridgeSubscriptionUtils.java | 104 +--
.../rest/endpoint/services/ServiceUtils.java | 731 +++++++++----------
16 files changed, 1018 insertions(+), 1238 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e79a7e2f/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/behaviour/CartridgeMgtBehaviour.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/behaviour/CartridgeMgtBehaviour.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/behaviour/CartridgeMgtBehaviour.java
index e3ea69b..0e06da6 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/behaviour/CartridgeMgtBehaviour.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/behaviour/CartridgeMgtBehaviour.java
@@ -18,29 +18,135 @@ package org.apache.stratos.manager.behaviour;
* under the License.
*/
+import org.apache.axis2.AxisFault;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
import org.apache.stratos.cloud.controller.pojo.Properties;
+import org.apache.stratos.cloud.controller.pojo.Property;
+import org.apache.stratos.manager.client.CloudControllerServiceClient;
import org.apache.stratos.manager.dao.Cluster;
import org.apache.stratos.manager.exception.ADCException;
import org.apache.stratos.manager.exception.AlreadySubscribedException;
import org.apache.stratos.manager.exception.NotSubscribedException;
import org.apache.stratos.manager.exception.UnregisteredCartridgeException;
+import org.apache.stratos.manager.payload.BasicPayloadData;
import org.apache.stratos.manager.payload.PayloadData;
+import org.apache.stratos.manager.payload.PayloadFactory;
import org.apache.stratos.manager.repository.Repository;
import org.apache.stratos.manager.subscriber.Subscriber;
+import org.apache.stratos.manager.subscription.utils.CartridgeSubscriptionUtils;
+import org.apache.stratos.manager.utils.ApplicationManagementUtil;
+import org.apache.stratos.manager.utils.CartridgeConstants;
import java.io.Serializable;
import java.util.Map;
+import java.util.Set;
-public interface CartridgeMgtBehaviour extends Serializable {
+public abstract class CartridgeMgtBehaviour implements Serializable {
+
+ private static final long serialVersionUID = 6529685098267757690L;
+
+ private static Log log = LogFactory.getLog(CartridgeMgtBehaviour.class);
public PayloadData create (String alias, Cluster cluster, Subscriber subscriber, Repository repository, CartridgeInfo cartridgeInfo,
- String subscriptionKey, Map<String, String> customPayloadEntries) throws ADCException, AlreadySubscribedException;
+ String subscriptionKey, Map<String, String> customPayloadEntries) throws ADCException, AlreadySubscribedException {
+
+
+ String clusterId = alias + "." + cartridgeInfo.getType() + ".domain";
+
+ // limit the cartridge alias to 30 characters in length
+ if (clusterId.length() > 30) {
+ clusterId = CartridgeSubscriptionUtils.limitLengthOfString(clusterId, 30);
+ }
+ cluster.setClusterDomain(clusterId);
+ // set hostname
+ cluster.setHostName(alias + "." + cluster.getHostName());
+
+ return createPayload(cartridgeInfo, subscriptionKey, subscriber, cluster, repository, alias, customPayloadEntries);
+ }
+
+ protected PayloadData createPayload (CartridgeInfo cartridgeInfo, String subscriptionKey, Subscriber subscriber, Cluster cluster,
+ Repository repository, String alias, Map<String, String> customPayloadEntries) throws ADCException {
+
+ //Create the payload
+ BasicPayloadData basicPayloadData = CartridgeSubscriptionUtils.createBasicPayload(cartridgeInfo, subscriptionKey, cluster, repository, alias, subscriber);
+ //Populate the basic payload details
+ basicPayloadData.populatePayload();
+
+ PayloadData payloadData = PayloadFactory.getPayloadDataInstance(cartridgeInfo.getProvider(),
+ cartridgeInfo.getType(), basicPayloadData);
+
+ // get the payload parameters defined in the cartridge definition file for this cartridge type
+ if (cartridgeInfo.getProperties() != null && cartridgeInfo.getProperties().length != 0) {
+
+ for (Property property : cartridgeInfo.getProperties()) {
+ // 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 (property.getName()
+ .startsWith(CartridgeConstants.CUSTOM_PAYLOAD_PARAM_NAME_PREFIX)) {
+ String payloadParamName = property.getName();
+ payloadData.add(payloadParamName.substring(payloadParamName.indexOf(".") + 1), property.getValue());
+ }
+ }
+ }
+
+ //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;
+ }
+
+ public void register(CartridgeInfo cartridgeInfo, Cluster cluster, PayloadData payloadData, String autoscalePolicyName, String deploymentPolicyName, Properties properties) throws ADCException, UnregisteredCartridgeException {
+
+ log.info("Payload: " + payloadData.getCompletePayloadData().toString());
+
+ ApplicationManagementUtil.registerService(cartridgeInfo.getType(),
+ cluster.getClusterDomain(),
+ cluster.getClusterSubDomain(),
+ payloadData.getCompletePayloadData(),
+ payloadData.getBasicPayloadData().getTenantRange(),
+ cluster.getHostName(),
+ autoscalePolicyName,
+ deploymentPolicyName,
+ properties);
+ }
+
+ public void remove(String clusterId, String alias) throws ADCException, NotSubscribedException {
+
+ try {
+ CloudControllerServiceClient.getServiceClient().terminateAllInstances(clusterId);
+
+ } catch (AxisFault e) {
+ String errorMsg = "Error in terminating cartridge subscription, cluster id: " + clusterId;
+ log.error(errorMsg);
+ throw new ADCException(errorMsg, e);
+
+ } catch (Exception e) {
+ String errorMsg = "Error in terminating cartridge subscription, cluster id: " + clusterId;
+ log.error(errorMsg);
+ throw new ADCException(errorMsg, e);
+ }
+
+ log.info("Terminated all instances of " + clusterId);
+
+ try {
+ CloudControllerServiceClient.getServiceClient().unregisterService(clusterId);
+
+ } catch (Exception e) {
+ String errorMsg = "Error in unregistering service cluster with domain " + clusterId;
+ log.error(errorMsg);
+ throw new ADCException(errorMsg, e);
+ }
- public void register (CartridgeInfo cartridgeInfo, Cluster cluster, PayloadData payloadData, String autoscalePolicyName,
- String deploymentPolicyName, Properties properties)
- throws ADCException, UnregisteredCartridgeException;
+ log.info("Unregistered service cluster, domain " + clusterId + ", sub domain ");
+ }
- public void remove (String clusterId, String alias)
- throws ADCException, NotSubscribedException;
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e79a7e2f/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/Service.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/Service.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/Service.java
index bfe275c..42405a1 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/Service.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/Service.java
@@ -23,19 +23,15 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
import org.apache.stratos.cloud.controller.pojo.Properties;
-import org.apache.stratos.cloud.controller.pojo.Property;
+import org.apache.stratos.manager.behaviour.CartridgeMgtBehaviour;
import org.apache.stratos.manager.client.CloudControllerServiceClient;
+import org.apache.stratos.manager.dao.Cluster;
import org.apache.stratos.manager.exception.ADCException;
import org.apache.stratos.manager.exception.UnregisteredCartridgeException;
-import org.apache.stratos.manager.payload.BasicPayloadData;
import org.apache.stratos.manager.payload.PayloadData;
-import org.apache.stratos.manager.payload.PayloadFactory;
import org.apache.stratos.manager.subscription.utils.CartridgeSubscriptionUtils;
-import org.apache.stratos.manager.utils.CartridgeConstants;
-import java.io.Serializable;
-
-public abstract class Service implements Serializable {
+public abstract class Service extends CartridgeMgtBehaviour {
private static Log log = LogFactory.getLog(Service.class);
@@ -43,12 +39,11 @@ public abstract class Service implements Serializable {
private String autoscalingPolicyName;
private String deploymentPolicyName;
private String tenantRange;
- private String clusterId;
- private String hostName;
private int tenantId;
private String subscriptionKey;
private CartridgeInfo cartridgeInfo;
private PayloadData payloadData;
+ private Cluster cluster;
public Service (String type, String autoscalingPolicyName, String deploymentPolicyName, int tenantId, CartridgeInfo cartridgeInfo,
String tenantRange) {
@@ -60,6 +55,7 @@ public abstract class Service implements Serializable {
this.cartridgeInfo = cartridgeInfo;
this.tenantRange = tenantRange;
this.subscriptionKey = CartridgeSubscriptionUtils.generateSubscriptionKey();
+ this.setCluster(new Cluster());
}
public void deploy (Properties properties) throws ADCException, UnregisteredCartridgeException {
@@ -74,36 +70,14 @@ public abstract class Service implements Serializable {
//host name is the hostname defined in cartridge definition
setHostName(cartridgeInfo.getHostName());
- //Create payload
- BasicPayloadData basicPayloadData = CartridgeSubscriptionUtils.createBasicPayload(this);
- //populate
- basicPayloadData.populatePayload();
- PayloadData payloadData = PayloadFactory.getPayloadDataInstance(cartridgeInfo.getProvider(),
- cartridgeInfo.getType(), basicPayloadData);
-
- // get the payload parameters defined in the cartridge definition file for this cartridge type
- if (cartridgeInfo.getProperties() != null && cartridgeInfo.getProperties().length != 0) {
-
- for (Property property : cartridgeInfo.getProperties()) {
- // 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 (property.getName()
- .startsWith(CartridgeConstants.CUSTOM_PAYLOAD_PARAM_NAME_PREFIX)) {
- String payloadParamName = property.getName();
- payloadData.add(payloadParamName.substring(payloadParamName.indexOf(".") + 1), property.getValue());
- }
- }
- }
-
- //set PayloadData instance
- setPayloadData(payloadData);
+ // create and set PayloadData instance
+ setPayloadData(createPayload(cartridgeInfo, subscriptionKey, null, cluster, null, null, null));
}
public void undeploy () throws ADCException {
try {
- CloudControllerServiceClient.getServiceClient().terminateAllInstances(clusterId);
+ CloudControllerServiceClient.getServiceClient().terminateAllInstances(cluster.getClusterDomain());
} catch (Exception e) {
String errorMsg = "Error in undeploying Service with type " + type;
@@ -114,15 +88,15 @@ public abstract class Service implements Serializable {
log.info("terminated instance with Service Type " + type);
try {
- CloudControllerServiceClient.getServiceClient().unregisterService(clusterId);
+ CloudControllerServiceClient.getServiceClient().unregisterService(cluster.getClusterDomain());
} catch (Exception e) {
- String errorMsg = "Error in unregistering service cluster with domain " + clusterId;
+ String errorMsg = "Error in unregistering service cluster with domain " + cluster.getClusterDomain();
log.error(errorMsg);
throw new ADCException(errorMsg, e);
}
- log.info("Unregistered service with domain " + clusterId);
+ log.info("Unregistered service with domain " + cluster.getClusterDomain());
}
public String getType() {
@@ -158,19 +132,19 @@ public abstract class Service implements Serializable {
}
public String getClusterId() {
- return clusterId;
+ return cluster.getClusterDomain();
}
public void setClusterId(String clusterId) {
- this.clusterId = clusterId;
+ this.cluster.setClusterDomain(clusterId);
}
public String getHostName() {
- return hostName;
+ return cluster.getHostName();
}
public void setHostName(String hostName) {
- this.hostName = hostName;
+ this.cluster.setHostName(hostName);
}
public int getTenantId() {
@@ -204,4 +178,12 @@ public abstract class Service implements Serializable {
public void setPayloadData(PayloadData payloadData) {
this.payloadData = payloadData;
}
+
+ public Cluster getCluster() {
+ return cluster;
+ }
+
+ public void setCluster(Cluster cluster) {
+ this.cluster = cluster;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e79a7e2f/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/ServiceDeploymentManager.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/ServiceDeploymentManager.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/ServiceDeploymentManager.java
index b5e3889..a80aea0 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/ServiceDeploymentManager.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/ServiceDeploymentManager.java
@@ -21,12 +21,10 @@ package org.apache.stratos.manager.deploy.service;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy;
import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
import org.apache.stratos.cloud.controller.pojo.LoadbalancerConfig;
import org.apache.stratos.cloud.controller.pojo.Properties;
import org.apache.stratos.cloud.controller.pojo.Property;
-import org.apache.stratos.manager.client.AutoscalerServiceClient;
import org.apache.stratos.manager.client.CloudControllerServiceClient;
import org.apache.stratos.manager.deploy.service.multitenant.MultiTenantService;
import org.apache.stratos.manager.deploy.service.multitenant.lb.MultiTenantLBService;
@@ -34,13 +32,13 @@ import org.apache.stratos.manager.exception.ADCException;
import org.apache.stratos.manager.exception.PersistenceManagerException;
import org.apache.stratos.manager.exception.ServiceAlreadyDeployedException;
import org.apache.stratos.manager.exception.UnregisteredCartridgeException;
+import org.apache.stratos.manager.lb.category.*;
import org.apache.stratos.manager.retriever.DataInsertionAndRetrievalManager;
import org.apache.stratos.manager.subscription.CartridgeSubscription;
+import org.apache.stratos.manager.subscription.utils.CartridgeSubscriptionUtils;
import org.apache.stratos.messaging.util.Constants;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.List;
public class ServiceDeploymentManager {
@@ -91,222 +89,244 @@ public class ServiceDeploymentManager {
throw new ADCException(errorMsg);
}
-
- // TODO - LB cartridge.... ??
- List<Property> lbRefProp = new ArrayList<Property>();
+// // TODO - LB cartridge.... ??
+//
+// List<Property> lbRefProp = new ArrayList<Property>();
+//
+// // get lb config reference
+// LoadbalancerConfig lbConfig = cartridgeInfo.getLbConfig();
+//
+// if (lbConfig == null || lbConfig.getProperties() == null) {
+//
+// if (log.isDebugEnabled()) {
+// log.debug("This Service does not require a load balancer. " + "[Service Name] " +
+// type);
+// }
+// } else {
+//
+// Service lbService;
+//
+// Properties lbReferenceProperties = lbConfig.getProperties();
+//
+// Property property = new Property();
+// property.setName(org.apache.stratos.messaging.util.Constants.LOAD_BALANCER_REF);
+//
+// for (org.apache.stratos.cloud.controller.pojo.Property prop : lbReferenceProperties.getProperties()) {
+//
+// String name = prop.getName();
+// String value = prop.getValue();
+//
+// // TODO make following a chain of responsibility pattern
+// if (Constants.NO_LOAD_BALANCER.equals(name)) {
+// if ("true".equals(value)) {
+// if (log.isDebugEnabled()) {
+// log.debug("This cartridge does not require a load balancer. " +
+// "[Type] " + type);
+// }
+// property.setValue(name);
+// lbRefProp.add(property);
+// break;
+// }
+// } else if (Constants.EXISTING_LOAD_BALANCERS.equals(name)) {
+// String clusterIdsVal = value;
+// if (log.isDebugEnabled()) {
+// log.debug("This cartridge refers to existing load balancers. " + "[Type] " +
+// type + "[Referenced Cluster Ids] " + clusterIdsVal);
+// }
+//
+// String[] clusterIds = clusterIdsVal.split(",");
+//
+// for (String clusterId : clusterIds) {
+//
+// try {
+// AutoscalerServiceClient.getServiceClient().checkLBExistenceAgainstPolicy(clusterId,
+// deploymentPolicyName);
+// } catch (Exception ex) {
+// // we don't need to throw the error here.
+// log.error(ex.getMessage(), ex);
+// }
+//
+// }
+//
+// property.setValue(name);
+// lbRefProp.add(property);
+// break;
+//
+// } else if (Constants.DEFAULT_LOAD_BALANCER.equals(name)) {
+//
+// if ("true".equals(value)) {
+//
+// CartridgeInfo lbCartridgeInfo;
+// String lbCartridgeType = lbConfig.getType();
+// try {
+// // retrieve lb Cartridge info
+// lbCartridgeInfo = CloudControllerServiceClient.getServiceClient().getCartridgeInfo(lbCartridgeType);
+// } catch (Exception e) {
+// String msg = "Cannot get cartridge info: " + type;
+// log.error(msg, e);
+// throw new ADCException(msg, e);
+// }
+//
+// property.setValue(name);
+// if (log.isDebugEnabled()) {
+// log.debug("This cartridge uses default load balancer. " + "[Type] " +
+// type);
+// }
+//
+// try {
+// // get the valid policies for lb cartridge
+// DeploymentPolicy[] lbCartridgeDepPolicies =
+// AutoscalerServiceClient.getServiceClient().getDeploymentPolicies(lbCartridgeType);
+// // traverse deployment policies of lb cartridge
+// for (DeploymentPolicy policy : lbCartridgeDepPolicies) {
+// // check existence of the subscribed policy
+// if (deploymentPolicyName.equals(policy.getId())) {
+//
+// if (!AutoscalerServiceClient.getServiceClient().checkDefaultLBExistenceAgainstPolicy(deploymentPolicyName)) {
+//
+// // if lb cluster doesn't exist
+// lbService = new MultiTenantLBService(lbCartridgeType,
+// lbCartridgeInfo.getDefaultAutoscalingPolicy(),
+// deploymentPolicyName, tenantId,
+// lbCartridgeInfo,
+// tenantRange);
+//
+// Properties lbDeploymentProperties = new Properties();
+//
+// // check if there are properties in LB cartridge info
+// Property [] cartridgeInfoProps = lbCartridgeInfo.getProperties();
+// if (cartridgeInfoProps != null && cartridgeInfoProps.length > 0) {
+// lbDeploymentProperties.setProperties(combine(lbCartridgeInfo.getProperties(), new Property[]{property}));
+// } else {
+// lbDeploymentProperties.setProperties(new Property[]{property});
+// }
+//
+// lbService.deploy(lbDeploymentProperties);
+//
+// // persist
+// persist(lbService);
+// }
+// }
+// }
+//
+// } catch (Exception ex) {
+// // we don't need to throw the error here.
+// log.error(ex.getMessage(), ex);
+// }
+//
+//
+// lbRefProp.add(property);
+// break;
+// }
+// } else if (Constants.SERVICE_AWARE_LOAD_BALANCER.equals(name)) {
+//
+// if ("true".equals(value)) {
+//
+// CartridgeInfo lbCartridgeInfo;
+// String lbCartridgeType = lbConfig.getType();
+// try {
+// // retrieve lb Cartridge info
+// lbCartridgeInfo = CloudControllerServiceClient.getServiceClient().getCartridgeInfo(lbCartridgeType);
+// } catch (Exception e) {
+// String msg = "Cannot get cartridge info: " + type;
+// log.error(msg, e);
+// throw new ADCException(msg, e);
+// }
+//
+// property.setValue(name);
+// if (log.isDebugEnabled()) {
+// log.debug("This cartridge uses a service aware load balancer. " +
+// "[Type] " + type);
+// }
+//
+// // add a property for the service type
+// Property loadBalancedServiceTypeProperty = new Property();
+// loadBalancedServiceTypeProperty.setName(Constants.LOAD_BALANCED_SERVICE_TYPE);
+// loadBalancedServiceTypeProperty.setValue(type);
+//
+// try {
+//
+// // get the valid policies for lb cartridge
+// DeploymentPolicy[] lbCartridgeDepPolicies =
+// AutoscalerServiceClient.getServiceClient().getDeploymentPolicies(lbCartridgeType);
+// // traverse deployment policies of lb cartridge
+// for (DeploymentPolicy policy : lbCartridgeDepPolicies) {
+//
+// // check existence of the subscribed policy
+// if (deploymentPolicyName.equals(policy.getId())) {
+//
+// if (!AutoscalerServiceClient.getServiceClient().checkServiceLBExistenceAgainstPolicy(type,
+// deploymentPolicyName)) {
+//
+// lbCartridgeInfo.addProperties(property);
+// lbCartridgeInfo.addProperties(loadBalancedServiceTypeProperty);
+//
+// lbService = new MultiTenantLBService(lbCartridgeType,
+// lbCartridgeInfo.getDefaultAutoscalingPolicy(),
+// deploymentPolicyName, tenantId,
+// lbCartridgeInfo,
+// tenantRange);
+//
+// Properties lbDeploymentProperties = new Properties();
+//
+// // check if there are properties in LB cartridge info
+// Property [] cartridgeInfoProps = lbCartridgeInfo.getProperties();
+// if (cartridgeInfoProps != null && cartridgeInfoProps.length > 0) {
+// lbDeploymentProperties.setProperties(combine(lbCartridgeInfo.getProperties(), new Property[]{property, loadBalancedServiceTypeProperty}));
+// } else {
+// lbDeploymentProperties.setProperties(new Property[]{property, loadBalancedServiceTypeProperty});
+// }
+//
+// lbService.deploy(lbDeploymentProperties);
+//
+// // persist
+// persist(lbService);
+// }
+// }
+// }
+//
+// } catch (Exception ex) {
+// // we don't need to throw the error here.
+// log.error(ex.getMessage(), ex);
+// }
+//
+//
+// lbRefProp.add(property);
+// break;
+// }
+// }
+// }
+// }
+
+ LBDataContext lbDataCtxt = null;
// get lb config reference
LoadbalancerConfig lbConfig = cartridgeInfo.getLbConfig();
-
if (lbConfig == null || lbConfig.getProperties() == null) {
-
+ // no LB ref
if (log.isDebugEnabled()) {
- log.debug("This Service does not require a load balancer. " + "[Service Name] " +
- type);
+ log.debug("This Service does not require a load balancer. " + "[Service Name] " + type);
}
+
} else {
+ // LB ref found, get relevant LB Context data
+ lbDataCtxt = CartridgeSubscriptionUtils.getLoadBalancerDataContext(-1234, type, deploymentPolicyName, lbConfig);
- Service lbService;
-
- Properties lbReferenceProperties = lbConfig.getProperties();
-
- Property property = new Property();
- property.setName(org.apache.stratos.messaging.util.Constants.LOAD_BALANCER_REF);
-
- for (org.apache.stratos.cloud.controller.pojo.Property prop : lbReferenceProperties.getProperties()) {
-
- String name = prop.getName();
- String value = prop.getValue();
-
- // TODO make following a chain of responsibility pattern
- if (Constants.NO_LOAD_BALANCER.equals(name)) {
- if ("true".equals(value)) {
- if (log.isDebugEnabled()) {
- log.debug("This cartridge does not require a load balancer. " +
- "[Type] " + type);
- }
- property.setValue(name);
- lbRefProp.add(property);
- break;
- }
- } else if (Constants.EXISTING_LOAD_BALANCERS.equals(name)) {
- String clusterIdsVal = value;
- if (log.isDebugEnabled()) {
- log.debug("This cartridge refers to existing load balancers. " + "[Type] " +
- type + "[Referenced Cluster Ids] " + clusterIdsVal);
- }
-
- String[] clusterIds = clusterIdsVal.split(",");
-
- for (String clusterId : clusterIds) {
-
- try {
- AutoscalerServiceClient.getServiceClient().checkLBExistenceAgainstPolicy(clusterId,
- deploymentPolicyName);
- } catch (Exception ex) {
- // we don't need to throw the error here.
- log.error(ex.getMessage(), ex);
- }
-
- }
-
- property.setValue(name);
- lbRefProp.add(property);
- break;
-
- } else if (Constants.DEFAULT_LOAD_BALANCER.equals(name)) {
-
- if ("true".equals(value)) {
-
- CartridgeInfo lbCartridgeInfo;
- String lbCartridgeType = lbConfig.getType();
- try {
- // retrieve lb Cartridge info
- lbCartridgeInfo = CloudControllerServiceClient.getServiceClient().getCartridgeInfo(lbCartridgeType);
- } catch (Exception e) {
- String msg = "Cannot get cartridge info: " + type;
- log.error(msg, e);
- throw new ADCException(msg, e);
- }
-
- property.setValue(name);
- if (log.isDebugEnabled()) {
- log.debug("This cartridge uses default load balancer. " + "[Type] " +
- type);
- }
-
- try {
- // get the valid policies for lb cartridge
- DeploymentPolicy[] lbCartridgeDepPolicies =
- AutoscalerServiceClient.getServiceClient().getDeploymentPolicies(lbCartridgeType);
- // traverse deployment policies of lb cartridge
- for (DeploymentPolicy policy : lbCartridgeDepPolicies) {
- // check existence of the subscribed policy
- if (deploymentPolicyName.equals(policy.getId())) {
-
- if (!AutoscalerServiceClient.getServiceClient().checkDefaultLBExistenceAgainstPolicy(deploymentPolicyName)) {
-
- // if lb cluster doesn't exist
- lbService = new MultiTenantLBService(lbCartridgeType,
- lbCartridgeInfo.getDefaultAutoscalingPolicy(),
- deploymentPolicyName, tenantId,
- lbCartridgeInfo,
- tenantRange);
-
- Properties lbDeploymentProperties = new Properties();
-
- // check if there are properties in LB cartridge info
- Property [] cartridgeInfoProps = lbCartridgeInfo.getProperties();
- if (cartridgeInfoProps != null && cartridgeInfoProps.length > 0) {
- lbDeploymentProperties.setProperties(combine(lbCartridgeInfo.getProperties(), new Property[]{property}));
- } else {
- lbDeploymentProperties.setProperties(new Property[]{property});
- }
-
- lbService.deploy(lbDeploymentProperties);
-
- // persist
- persist(lbService);
- }
- }
- }
-
- } catch (Exception ex) {
- // we don't need to throw the error here.
- log.error(ex.getMessage(), ex);
- }
-
-
- lbRefProp.add(property);
- break;
- }
- } else if (Constants.SERVICE_AWARE_LOAD_BALANCER.equals(name)) {
-
- if ("true".equals(value)) {
-
- CartridgeInfo lbCartridgeInfo;
- String lbCartridgeType = lbConfig.getType();
- try {
- // retrieve lb Cartridge info
- lbCartridgeInfo = CloudControllerServiceClient.getServiceClient().getCartridgeInfo(lbCartridgeType);
- } catch (Exception e) {
- String msg = "Cannot get cartridge info: " + type;
- log.error(msg, e);
- throw new ADCException(msg, e);
- }
-
- property.setValue(name);
- if (log.isDebugEnabled()) {
- log.debug("This cartridge uses a service aware load balancer. " +
- "[Type] " + type);
- }
-
- // add a property for the service type
- Property loadBalancedServiceTypeProperty = new Property();
- loadBalancedServiceTypeProperty.setName(Constants.LOAD_BALANCED_SERVICE_TYPE);
- loadBalancedServiceTypeProperty.setValue(type);
-
- try {
-
- // get the valid policies for lb cartridge
- DeploymentPolicy[] lbCartridgeDepPolicies =
- AutoscalerServiceClient.getServiceClient().getDeploymentPolicies(lbCartridgeType);
- // traverse deployment policies of lb cartridge
- for (DeploymentPolicy policy : lbCartridgeDepPolicies) {
-
- // check existence of the subscribed policy
- if (deploymentPolicyName.equals(policy.getId())) {
-
- if (!AutoscalerServiceClient.getServiceClient().checkServiceLBExistenceAgainstPolicy(type,
- deploymentPolicyName)) {
-
- lbCartridgeInfo.addProperties(property);
- lbCartridgeInfo.addProperties(loadBalancedServiceTypeProperty);
-
- lbService = new MultiTenantLBService(lbCartridgeType,
- lbCartridgeInfo.getDefaultAutoscalingPolicy(),
- deploymentPolicyName, tenantId,
- lbCartridgeInfo,
- tenantRange);
-
- Properties lbDeploymentProperties = new Properties();
-
- // check if there are properties in LB cartridge info
- Property [] cartridgeInfoProps = lbCartridgeInfo.getProperties();
- if (cartridgeInfoProps != null && cartridgeInfoProps.length > 0) {
- lbDeploymentProperties.setProperties(combine(lbCartridgeInfo.getProperties(), new Property[]{property, loadBalancedServiceTypeProperty}));
- } else {
- lbDeploymentProperties.setProperties(new Property[]{property, loadBalancedServiceTypeProperty});
- }
-
- lbService.deploy(lbDeploymentProperties);
-
- // persist
- persist(lbService);
- }
- }
- }
-
- } catch (Exception ex) {
- // we don't need to throw the error here.
- log.error(ex.getMessage(), ex);
- }
-
-
- lbRefProp.add(property);
- break;
- }
- }
- }
+ // deploy LB service cluster
+ deployLBCluster(type, lbDataCtxt, tenantRange);
}
Service service = new MultiTenantService(type, autoscalingPolicyName, deploymentPolicyName, tenantId, cartridgeInfo, tenantRange);
+ Properties serviceClusterProperties = null;
+ if (lbDataCtxt.getLoadBalancedServiceProperties() != null && !lbDataCtxt.getLoadBalancedServiceProperties().isEmpty()) {
+ serviceClusterProperties = new Properties();
+ serviceClusterProperties.setProperties(lbDataCtxt.getLoadBalancedServiceProperties().toArray(new Property[0]));
+ }
+
//deploy the service
- Properties serviceDeploymentProperties = new Properties();
- serviceDeploymentProperties.setProperties(lbRefProp.toArray(new Property[0]));
- service.deploy(serviceDeploymentProperties);
+ service.deploy(serviceClusterProperties);
// persist
persist(service);
@@ -314,6 +334,49 @@ public class ServiceDeploymentManager {
return service;
}
+ private void deployLBCluster (String loadBalancedService, LBDataContext lbDataCtxt, String tenantRange) throws ADCException, UnregisteredCartridgeException {
+
+ if (lbDataCtxt.getLbCategory().equals(Constants.NO_LOAD_BALANCER)) {
+ // no load balancer required
+ return;
+ }
+
+ LoadBalancerCategory loadBalancerCategory = null;
+
+ if (lbDataCtxt.getLbCategory().equals(Constants.EXISTING_LOAD_BALANCERS)) {
+ loadBalancerCategory = new ExistingLoadBalancerCategory();
+
+ } else if (lbDataCtxt.getLbCategory().equals(Constants.DEFAULT_LOAD_BALANCER)) {
+ loadBalancerCategory = new DefaultLoadBalancerCategory();
+
+ } else if (lbDataCtxt.getLbCategory().equals(Constants.SERVICE_AWARE_LOAD_BALANCER)) {
+ loadBalancerCategory = new ServiceLevelLoadBalancerCategory();
+ }
+
+ if (loadBalancerCategory == null) {
+ throw new ADCException("The given Load Balancer category " + lbDataCtxt.getLbCategory() + " not found");
+ }
+
+ // Set the load balanced service type
+ loadBalancerCategory.setLoadBalancedServiceType(loadBalancedService);
+
+ Service lbService = new MultiTenantLBService(lbDataCtxt.getLbCartridgeInfo().getType(), lbDataCtxt.getAutoscalePolicy(),
+ lbDataCtxt.getDeploymentPolicy(), -1234, lbDataCtxt.getLbCartridgeInfo(),
+ tenantRange, loadBalancerCategory);
+
+ Properties lbProperties = null;
+ if (lbDataCtxt.getLbProperperties() != null && !lbDataCtxt.getLbProperperties().isEmpty()) {
+ lbProperties = new Properties();
+ lbProperties.setProperties(lbDataCtxt.getLbProperperties().toArray(new Property[0]));
+ }
+
+ // delpoy
+ lbService.deploy(lbProperties);
+
+ // persist
+ persist(lbService);
+ }
+
private void persist (Service service) throws ADCException {
DataInsertionAndRetrievalManager dataInsertionAndRetrievalManager = new DataInsertionAndRetrievalManager();
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e79a7e2f/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/multitenant/lb/MultiTenantLBService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/multitenant/lb/MultiTenantLBService.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/multitenant/lb/MultiTenantLBService.java
index 3d8caa8..2fe829d 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/multitenant/lb/MultiTenantLBService.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/multitenant/lb/MultiTenantLBService.java
@@ -47,9 +47,7 @@ public class MultiTenantLBService extends Service {
super.deploy(properties);
//register the service
- loadBalancerCategory.register();
-// ApplicationManagementUtil.registerService(getType(), getClusterId(), CartridgeConstants.DEFAULT_SUBDOMAIN,
-// getPayloadData().getCompletePayloadData(), getTenantRange(), getHostName(), getAutoscalingPolicyName(),
-// getDeploymentPolicyName(), properties);
+ loadBalancerCategory.register(getCartridgeInfo(), getCluster(), getPayloadData(), getAutoscalingPolicyName(), getDeploymentPolicyName(),
+ properties);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e79a7e2f/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/DefaultLoadBalancerCategory.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/DefaultLoadBalancerCategory.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/DefaultLoadBalancerCategory.java
index a346bbd..0df3589 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/DefaultLoadBalancerCategory.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/DefaultLoadBalancerCategory.java
@@ -21,8 +21,4 @@ package org.apache.stratos.manager.lb.category;
public class DefaultLoadBalancerCategory extends LoadBalancerCategory {
- public DefaultLoadBalancerCategory(LBCategoryContext lbCategoryContext) {
- super(lbCategoryContext);
- }
-
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e79a7e2f/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/ExistingLoadBalancerCategory.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/ExistingLoadBalancerCategory.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/ExistingLoadBalancerCategory.java
index 6523df8..15450bf 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/ExistingLoadBalancerCategory.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/ExistingLoadBalancerCategory.java
@@ -19,26 +19,35 @@
package org.apache.stratos.manager.lb.category;
+import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
+import org.apache.stratos.cloud.controller.pojo.Properties;
+import org.apache.stratos.manager.dao.Cluster;
import org.apache.stratos.manager.exception.ADCException;
+import org.apache.stratos.manager.exception.AlreadySubscribedException;
+import org.apache.stratos.manager.exception.NotSubscribedException;
import org.apache.stratos.manager.exception.UnregisteredCartridgeException;
import org.apache.stratos.manager.payload.PayloadData;
+import org.apache.stratos.manager.repository.Repository;
+import org.apache.stratos.manager.subscriber.Subscriber;
+
+import java.util.Map;
public class ExistingLoadBalancerCategory extends LoadBalancerCategory {
- public ExistingLoadBalancerCategory(LBCategoryContext lbCategoryContext) {
- super(lbCategoryContext);
+ public PayloadData create (String alias, Cluster cluster, Subscriber subscriber, Repository repository, CartridgeInfo cartridgeInfo,
+ String subscriptionKey, Map<String, String> customPayloadEntries) throws ADCException, AlreadySubscribedException {
+
+ // TODO
+ return null;
}
- public void register () throws ADCException, UnregisteredCartridgeException {
+ public void register (CartridgeInfo cartridgeInfo, Cluster cluster, PayloadData payloadData, String autoscalePolicyName, String deploymentPolicyName, Properties properties) throws ADCException, UnregisteredCartridgeException {
+
//TODO
}
- public PayloadData createPayload() throws ADCException {
- //TODO;
- return null;
- }
+ public void remove(String clusterId, String alias) throws ADCException, NotSubscribedException {
- public void unregister () throws ADCException {
//TODO
}
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e79a7e2f/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/LBCategoryContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/LBCategoryContext.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/LBCategoryContext.java
deleted file mode 100644
index e6420a9..0000000
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/LBCategoryContext.java
+++ /dev/null
@@ -1,152 +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.manager.lb.category;
-
-import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
-import org.apache.stratos.cloud.controller.pojo.Properties;
-import org.apache.stratos.manager.dao.Cluster;
-import org.apache.stratos.manager.payload.PayloadData;
-import org.apache.stratos.manager.subscriber.Subscriber;
-
-import java.util.Map;
-
-public class LBCategoryContext {
-
- private String lbType;
- private PayloadData payloadData;
- private Properties properties;
- private Cluster cluster;
- private String autoscalingPolicyName;
- private String deploymentPolicyName;
- private Map<String, String> customPayloadEntries;
- private CartridgeInfo cartridgeInfo;
- private String key;
- private String loadbalancedServiceType;
- private String subscriptionAlias;
- private Subscriber subscriber;
-
- public LBCategoryContext (String lbType, Cluster cluster, String autoscalingPolicyName, String deploymentPolicyName,
- CartridgeInfo cartridgeInfo, PayloadData payloadData, String key) {
-
- this.lbType = lbType;
- this.cluster = cluster;
- this.autoscalingPolicyName = autoscalingPolicyName;
- this.deploymentPolicyName = deploymentPolicyName;
- this.cartridgeInfo = cartridgeInfo;
- this.payloadData = payloadData;
- this.key = key;
- }
-
- public PayloadData getPayloadData() {
- return payloadData;
- }
-
- public void setPayloadData(PayloadData payloadData) {
- this.payloadData = payloadData;
- }
-
- public Properties getProperties() {
- return properties;
- }
-
- public void setProperties(Properties properties) {
- this.properties = properties;
- }
-
- public Cluster getCluster() {
- return cluster;
- }
-
- public void setCluster(Cluster cluster) {
- this.cluster = cluster;
- }
-
- public String getAutoscalingPolicyName() {
- return autoscalingPolicyName;
- }
-
- public void setAutoscalingPolicyName(String autoscalingPolicyName) {
- this.autoscalingPolicyName = autoscalingPolicyName;
- }
-
- public String getDeploymentPolicyName() {
- return deploymentPolicyName;
- }
-
- public void setDeploymentPolicyName(String deploymentPolicyName) {
- this.deploymentPolicyName = deploymentPolicyName;
- }
-
- public Map<String, String> getCustomPayloadEntries() {
- return customPayloadEntries;
- }
-
- public void setCustomPayloadEntries(Map<String, String> customPayloadEntries) {
- this.customPayloadEntries = customPayloadEntries;
- }
-
- public CartridgeInfo getCartridgeInfo() {
- return cartridgeInfo;
- }
-
- public void setCartridgeInfo(CartridgeInfo cartridgeInfo) {
- this.cartridgeInfo = cartridgeInfo;
- }
-
- public String getLbType() {
- return lbType;
- }
-
- public void setLbType(String lbType) {
- this.lbType = lbType;
- }
-
- public String getLoadbalancedServiceType() {
- return loadbalancedServiceType;
- }
-
- public void setLoadbalancedServiceType(String loadbalancedServiceType) {
- this.loadbalancedServiceType = loadbalancedServiceType;
- }
-
- public String getKey() {
- return key;
- }
-
- public void setKey(String key) {
- this.key = key;
- }
-
- public String getSubscriptionAlias() {
- return subscriptionAlias;
- }
-
- public void setSubscriptionAlias(String subscriptionAlias) {
- this.subscriptionAlias = subscriptionAlias;
- }
-
- public Subscriber getSubscriber() {
- return subscriber;
- }
-
- public void setSubscriber(Subscriber subscriber) {
- this.subscriber = subscriber;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e79a7e2f/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/LoadBalancerCategory.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/LoadBalancerCategory.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/LoadBalancerCategory.java
index b2fca7b..906d2a9 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/LoadBalancerCategory.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/LoadBalancerCategory.java
@@ -19,126 +19,17 @@
package org.apache.stratos.manager.lb.category;
-import org.apache.axis2.AxisFault;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
-import org.apache.stratos.cloud.controller.pojo.Property;
-import org.apache.stratos.manager.client.CloudControllerServiceClient;
-import org.apache.stratos.manager.exception.ADCException;
-import org.apache.stratos.manager.exception.UnregisteredCartridgeException;
-import org.apache.stratos.manager.payload.BasicPayloadData;
-import org.apache.stratos.manager.payload.PayloadData;
-import org.apache.stratos.manager.payload.PayloadFactory;
-import org.apache.stratos.manager.subscription.utils.CartridgeSubscriptionUtils;
-import org.apache.stratos.manager.utils.ApplicationManagementUtil;
-import org.apache.stratos.manager.utils.CartridgeConstants;
+import org.apache.stratos.manager.behaviour.CartridgeMgtBehaviour;
-import java.util.Map;
-import java.util.Set;
+public abstract class LoadBalancerCategory extends CartridgeMgtBehaviour {
-public abstract class LoadBalancerCategory {
+ private String loadBalancedServiceType;
- private static Log log = LogFactory.getLog(LoadBalancerCategory.class);
-
- private LBCategoryContext lbCategoryContext;
-
- public LoadBalancerCategory (LBCategoryContext lbCategoryContext) {
- this.setLbCategoryContext(lbCategoryContext);
- }
-
- public void register () throws ADCException, UnregisteredCartridgeException {
-
- log.info("Payload: " + getLbCategoryContext().getPayloadData().getCompletePayloadData().toString());
-
- ApplicationManagementUtil.registerService(getLbCategoryContext().getLbType(),
- getLbCategoryContext().getCluster().getClusterDomain(),
- getLbCategoryContext().getCluster().getClusterSubDomain(),
- getLbCategoryContext().getPayloadData().getCompletePayloadData(),
- getLbCategoryContext().getPayloadData().getBasicPayloadData().getTenantRange(),
- getLbCategoryContext().getCluster().getHostName(),
- getLbCategoryContext().getAutoscalingPolicyName(),
- getLbCategoryContext().getDeploymentPolicyName(),
- getLbCategoryContext().getProperties());
- }
-
- public PayloadData createPayload() throws ADCException {
-
- //Create the payload
- BasicPayloadData basicPayloadData = CartridgeSubscriptionUtils.createBasicPayload(lbCategoryContext);
- //Populate the basic payload details
- basicPayloadData.populatePayload();
-
- CartridgeInfo cartridgeInfo = getLbCategoryContext().getCartridgeInfo();
- PayloadData payloadData = PayloadFactory.getPayloadDataInstance(cartridgeInfo.getProvider(),
- cartridgeInfo.getType(), basicPayloadData);
-
- // get the payload parameters defined in the cartridge definition file for this cartridge type
- if (cartridgeInfo.getProperties() != null && cartridgeInfo.getProperties().length != 0) {
-
- for (Property property : cartridgeInfo.getProperties()) {
- // 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 (property.getName()
- .startsWith(CartridgeConstants.CUSTOM_PAYLOAD_PARAM_NAME_PREFIX)) {
- String payloadParamName = property.getName();
- payloadData.add(payloadParamName.substring(payloadParamName.indexOf(".") + 1), property.getValue());
- }
- }
- }
-
- //check if there are any custom payload entries defined
- if (getLbCategoryContext().getCustomPayloadEntries() != null) {
- //add them to the payload
- Map<String, String> customPayloadEntries = getLbCategoryContext().getCustomPayloadEntries();
- Set<Map.Entry<String,String>> entrySet = customPayloadEntries.entrySet();
- for (Map.Entry<String, String> entry : entrySet) {
- payloadData.add(entry.getKey(), entry.getValue());
- }
- }
-
- return payloadData;
- }
-
- public void unregister () throws ADCException {
-
- try {
- CloudControllerServiceClient.getServiceClient().terminateAllInstances(getLbCategoryContext().getCluster().getClusterDomain());
-
- } catch (AxisFault e) {
- String errorMsg = "Error in terminating cartridge subscription, cluster id: " + getLbCategoryContext().getCluster().getClusterDomain();
- log.error(errorMsg);
- throw new ADCException(errorMsg, e);
-
- } catch (Exception e) {
- String errorMsg = "Error in terminating cartridge subscription, cluster id: " + getLbCategoryContext().getCluster().getClusterDomain();
- log.error(errorMsg);
- throw new ADCException(errorMsg, e);
- }
-
- log.info("Terminated all instances of " + getLbCategoryContext().getCluster().getClusterDomain() + " " +
- getLbCategoryContext().getCluster().getClusterSubDomain());
-
- try {
- CloudControllerServiceClient.getServiceClient().unregisterService(getLbCategoryContext().getCluster().getClusterDomain());
-
- } catch (Exception e) {
- String errorMsg = "Error in unregistering service cluster with domain " + getLbCategoryContext().getCluster().getClusterDomain() +
- ", sub domain " + getLbCategoryContext().getCluster().getClusterSubDomain();
- log.error(errorMsg);
- throw new ADCException(errorMsg, e);
- }
-
- log.info("Unregistered service cluster, domain " + getLbCategoryContext().getCluster().getClusterDomain() + ", sub domain " +
- getLbCategoryContext().getCluster().getClusterSubDomain());
- }
-
- public LBCategoryContext getLbCategoryContext() {
- return lbCategoryContext;
+ public String getLoadBalancedServiceType() {
+ return loadBalancedServiceType;
}
- public void setLbCategoryContext(LBCategoryContext lbCategoryContext) {
- this.lbCategoryContext = lbCategoryContext;
+ public void setLoadBalancedServiceType(String loadBalancedServiceType) {
+ this.loadBalancedServiceType = loadBalancedServiceType;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e79a7e2f/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/ServiceLevelLoadBalancerCategory.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/ServiceLevelLoadBalancerCategory.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/ServiceLevelLoadBalancerCategory.java
index 0bb979b..5e94047 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/ServiceLevelLoadBalancerCategory.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lb/category/ServiceLevelLoadBalancerCategory.java
@@ -19,20 +19,26 @@
package org.apache.stratos.manager.lb.category;
+import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
+import org.apache.stratos.manager.dao.Cluster;
import org.apache.stratos.manager.exception.ADCException;
+import org.apache.stratos.manager.exception.AlreadySubscribedException;
import org.apache.stratos.manager.payload.PayloadData;
+import org.apache.stratos.manager.repository.Repository;
+import org.apache.stratos.manager.subscriber.Subscriber;
+
+import java.util.Map;
public class ServiceLevelLoadBalancerCategory extends LoadBalancerCategory {
- public ServiceLevelLoadBalancerCategory(LBCategoryContext lbCategoryContext) {
- super(lbCategoryContext);
- }
+ public PayloadData create (String alias, Cluster cluster, Subscriber subscriber, Repository repository, CartridgeInfo cartridgeInfo,
+ String subscriptionKey, Map<String, String> customPayloadEntries) throws ADCException, AlreadySubscribedException {
- public PayloadData createPayload() throws ADCException {
// add payload entry for load balanced service type
- PayloadData serviceLevelLbPayloadData = super.createPayload();
- serviceLevelLbPayloadData.add("LOAD_BALANCED_SERVICE_TYPE", getLbCategoryContext().getLoadbalancedServiceType());
+ PayloadData serviceLevelLbPayloadData = super.create(alias, cluster, subscriber, repository, cartridgeInfo, subscriptionKey,
+ customPayloadEntries);
+ serviceLevelLbPayloadData.add("LOAD_BALANCED_SERVICE_TYPE", getLoadBalancedServiceType());
return serviceLevelLbPayloadData;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e79a7e2f/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
index 4e603c5..69574e1 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
@@ -21,12 +21,9 @@ package org.apache.stratos.manager.manager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
-import org.apache.stratos.cloud.controller.pojo.Properties;
-import org.apache.stratos.cloud.controller.pojo.Property;
+import org.apache.stratos.cloud.controller.pojo.*;
import org.apache.stratos.manager.client.CloudControllerServiceClient;
import org.apache.stratos.manager.dao.CartridgeSubscriptionInfo;
-import org.apache.stratos.manager.dao.Cluster;
import org.apache.stratos.manager.dto.SubscriptionInfo;
import org.apache.stratos.manager.exception.*;
import org.apache.stratos.manager.lb.category.*;
@@ -43,7 +40,6 @@ import org.apache.stratos.manager.subscription.utils.CartridgeSubscriptionUtils;
import org.apache.stratos.manager.topology.model.TopologyClusterInformationModel;
import org.apache.stratos.manager.utils.ApplicationManagementUtil;
import org.apache.stratos.manager.utils.CartridgeConstants;
-import org.apache.stratos.manager.utils.RepoPasswordMgtUtil;
import org.apache.stratos.messaging.util.Constants;
import org.wso2.carbon.context.CarbonContext;
@@ -58,7 +54,7 @@ public class CartridgeSubscriptionManager {
private static Log log = LogFactory.getLog(CartridgeSubscriptionManager.class);
//private static DataInsertionAndRetrievalManager dataInsertionAndRetrievalManager = new DataInsertionAndRetrievalManager();
- public CartridgeSubscription subscribeToCartridgeWithProperties(SubscriptionData subscriptionData) throws ADCException,
+ public SubscriptionInfo subscribeToCartridgeWithProperties(SubscriptionData subscriptionData) throws ADCException,
InvalidCartridgeAliasException,
DuplicateCartridgeAliasException,
PolicyException,
@@ -69,111 +65,81 @@ public class CartridgeSubscriptionManager {
AlreadySubscribedException,
InvalidRepositoryException {
- int tenantId = subscriptionData.getTenantId();
- String cartridgeType = subscriptionData.getCartridgeType();
- String cartridgeAlias = subscriptionData.getCartridgeAlias();
- Property [] props = subscriptionData.getProperties();
- String repositoryPassword = subscriptionData.getRepositoryPassword();
- String repositoryUsername = subscriptionData.getRepositoryUsername();
- boolean isPrivateRepository = subscriptionData.isPrivateRepository();
- String repositoryURL = subscriptionData.getRepositoryURL();
- String tenantDomain = subscriptionData.getTenantDomain();
- String tenantAdminUsername = subscriptionData.getTenantAdminUsername();
- String autoscalingPolicyName = subscriptionData.getAutoscalingPolicyName();
- String deploymentPolicyName = subscriptionData.getDeploymentPolicyName();
- String lbClusterId = subscriptionData.getLbClusterId();
-
// validate cartridge alias
- CartridgeSubscriptionUtils.validateCartridgeAlias(tenantId, cartridgeType, cartridgeAlias);
+ CartridgeSubscriptionUtils.validateCartridgeAlias(subscriptionData.getTenantId(), subscriptionData.getCartridgeType(), subscriptionData.getCartridgeAlias());
CartridgeInfo cartridgeInfo;
try {
- cartridgeInfo =
- CloudControllerServiceClient.getServiceClient().getCartridgeInfo(cartridgeType);
- /*
- if (props != null) {
- // TODO: temp fix, need to do a proper fix
- Property[] cartridgeInfoProperties = cartridgeInfo.getProperties();
- if(cartridgeInfoProperties != null) {
- int length = cartridgeInfoProperties.length + props.length;
- Property[] combined = new Property[length];
- System.arraycopy(cartridgeInfoProperties, 0, combined, 0, cartridgeInfoProperties.length);
- System.arraycopy(props, 0, combined, cartridgeInfoProperties.length, props.length);
- cartridgeInfo.setProperties(combined);
- } else {
- cartridgeInfo.setProperties(props);
- }
+ cartridgeInfo = CloudControllerServiceClient.getServiceClient().getCartridgeInfo(subscriptionData.getCartridgeType());
- }
- */
} catch (UnregisteredCartridgeException e) {
String message =
- cartridgeType +
- " is not a valid cartridgeSubscription type. Please try again with a valid cartridgeSubscription type.";
+ subscriptionData.getCartridgeType() + " is not a valid cartridgeSubscription type. Please try again with a valid cartridgeSubscription type.";
log.error(message);
throw e;
} catch (Exception e) {
- String message = "Error getting info for " + cartridgeType;
+ String message = "Error getting info for " + subscriptionData.getCartridgeType();
log.error(message, e);
throw new ADCException(message, e);
}
- //Decide tenancy behaviour
- SubscriptionTenancyBehaviour tenancyBehaviour;
- if(cartridgeInfo.getMultiTenant()) {
- tenancyBehaviour = new SubscriptionMultiTenantBehaviour();
- } else {
- tenancyBehaviour = new SubscriptionSingleTenantBehaviour();
+ // check if this subscription requires Persistence Mapping, and its supported by the cartridge definition
+ Properties persistenceMappingProperties = null;
+ if (subscriptionData.getPersistanceMapping() != null) {
+ persistenceMappingProperties = getPersistenceMappingProperties(subscriptionData.getPersistanceMapping(), cartridgeInfo);
}
- //Create the CartridgeSubscription instance
- CartridgeSubscription cartridgeSubscription = CartridgeSubscriptionFactory.
- getCartridgeSubscriptionInstance(cartridgeInfo, tenancyBehaviour);
-
+ Properties serviceCartridgeSubscriptionProperties = null;
+ LBDataContext lbDataCtxt = null;
- String subscriptionKey = CartridgeSubscriptionUtils.generateSubscriptionKey();
-
- String encryptedRepoPassword = repositoryPassword != null && !repositoryPassword.isEmpty() ?
- RepoPasswordMgtUtil.encryptPassword(repositoryPassword, subscriptionKey) : "";
-
- //Create repository
- Repository repository = cartridgeSubscription.manageRepository(repositoryURL,
- repositoryUsername,
- encryptedRepoPassword,
- isPrivateRepository,
- cartridgeAlias,
- cartridgeInfo, tenantDomain);
-
- //Create subscriber
- Subscriber subscriber = new Subscriber(tenantAdminUsername, tenantId, tenantDomain);
-
- //Set the key
- cartridgeSubscription.setSubscriptionKey(subscriptionKey);
-
- // Set persistance mappings
- cartridgeSubscription.setPersistanceMapping(subscriptionData.getPersistanceMapping());
+ // get lb config reference
+ LoadbalancerConfig lbConfig = cartridgeInfo.getLbConfig();
+ if (lbConfig == null || lbConfig.getProperties() == null) {
+ // no LB ref
+ if (log.isDebugEnabled()) {
+ log.debug("This Service does not require a load balancer. " + "[Service Name] " +
+ subscriptionData.getCartridgeType());
+ }
- //create subscription
- cartridgeSubscription.createSubscription(subscriber, cartridgeAlias, autoscalingPolicyName,
- deploymentPolicyName, repository);
+ } else {
+ // LB ref found, get relevant LB Context data
+ lbDataCtxt = CartridgeSubscriptionUtils.getLoadBalancerDataContext(subscriptionData.getTenantId(), subscriptionData.getCartridgeType(),
+ subscriptionData.getDeploymentPolicyName(), lbConfig);
+
+ // subscribe to LB
+ CartridgeSubscription lbCartridgeSubscription = subscribeToLB (subscriptionData, lbDataCtxt);
+
+ if (lbCartridgeSubscription != null) {
+ // register LB cartridge subscription
+ Properties lbCartridgeSubscriptionProperties = new Properties();
+ if (lbDataCtxt.getLbProperperties() != null && !lbDataCtxt.getLbProperperties().isEmpty()) {
+ lbCartridgeSubscriptionProperties.setProperties(lbDataCtxt.getLbProperperties().toArray(new Property[0]));
+ }
- // set the lb cluster id if its available
- if (lbClusterId != null && !lbClusterId.isEmpty()) {
- cartridgeSubscription.setLbClusterId(lbClusterId);
+ registerCartridgeSubscription(lbCartridgeSubscription, lbCartridgeSubscriptionProperties);
+ }
}
- log.info("Tenant [" + tenantId + "] with username [" + tenantAdminUsername +
- " subscribed to " + "] Cartridge Alias " + cartridgeAlias + ", Cartridge Type: " +
- cartridgeType + ", Repo URL: " + repositoryURL + ", Policy: " +
- autoscalingPolicyName);
+ // subscribe to relevant service cartridge
+ CartridgeSubscription serviceCartridgeSubscription = subscribe (subscriptionData, cartridgeInfo);
+ serviceCartridgeSubscriptionProperties = new Properties();
+ // lb related properties
+ if (lbDataCtxt.getLoadBalancedServiceProperties() != null && !lbDataCtxt.getLoadBalancedServiceProperties().isEmpty()) {
+ serviceCartridgeSubscriptionProperties.setProperties(lbDataCtxt.getLoadBalancedServiceProperties().toArray(new Property[0]));
+ }
- // Publish tenant subscribed envent to message broker
- CartridgeSubscriptionUtils.publishTenantSubscribedEvent(cartridgeSubscription.getSubscriber().getTenantId(),
- cartridgeSubscription.getCartridgeInfo().getType());
+ // Persistence Mapping related properties
+ if (persistenceMappingProperties != null && persistenceMappingProperties.getProperties().length > 0) {
+ // add the properties to send to CC via register method
+ for (Property persistenceMappingProperty : persistenceMappingProperties.getProperties()) {
+ serviceCartridgeSubscriptionProperties.addProperties(persistenceMappingProperty);
+ }
+ }
- return cartridgeSubscription;
+ // register service cartridge subscription
+ return registerCartridgeSubscription(serviceCartridgeSubscription, serviceCartridgeSubscriptionProperties);
}
private CartridgeSubscription subscribeToLB (SubscriptionData subscriptionData, LBDataContext lbDataContext)
@@ -182,33 +148,18 @@ public class CartridgeSubscriptionManager {
DuplicateCartridgeAliasException, PolicyException, UnregisteredCartridgeException, RepositoryRequiredException, RepositoryCredentialsRequiredException,
RepositoryTransportException, AlreadySubscribedException, InvalidRepositoryException {
- LoadBalancerCategory loadBalancerCategory = null;
-
if (lbDataContext.getLbCategory().equals(Constants.NO_LOAD_BALANCER)) {
// no load balancer subscription required
+ log.info("No LB subscription required for the Subscription with alias: " + subscriptionData.getCartridgeAlias() + ", type: " +
+ subscriptionData.getCartridgeType());
return null;
-
- }
-
- String lbAlias = "lb" + lbDataContext.getLbCartridgeInfo().getType() + new Random().nextInt();
-
- String lbClusterId = lbAlias + "." + lbDataContext.getLbCartridgeInfo().getType() + ".domain";
-
- // limit the cartridge alias to 30 characters in length
- if (lbClusterId.length() > 30) {
- lbClusterId = CartridgeSubscriptionUtils.limitLengthOfString(lbClusterId, 30);
}
- Cluster lbCluster = new Cluster();
- lbCluster.setClusterDomain(lbClusterId);
- // set hostname
- lbCluster.setHostName(lbAlias + "." + lbDataContext.getLbCartridgeInfo().getHostName());
+ LoadBalancerCategory loadBalancerCategory = null;
- LBCategoryContext lbCategoryContext = new LBCategoryContext(lbDataContext.getLbCartridgeInfo().getType(), lbCluster, lbDataContext.getAutoscalePolicy(),
- lbDataContext.getDeploymentPolicy(), lbDataContext.getLbCartridgeInfo(), );
+ String lbAlias = "lb" + lbDataContext.getLbCartridgeInfo().getType() + new Random().nextInt();
if (lbDataContext.getLbCategory().equals(Constants.EXISTING_LOAD_BALANCERS)) {
-
loadBalancerCategory = new ExistingLoadBalancerCategory();
} else if (lbDataContext.getLbCategory().equals(Constants.DEFAULT_LOAD_BALANCER)) {
@@ -226,6 +177,9 @@ public class CartridgeSubscriptionManager {
throw new ADCException("LB Cartridge must be single tenant");
}
+ // Set the load balanced service type
+ loadBalancerCategory.setLoadBalancedServiceType(subscriptionData.getCartridgeType());
+
// Create the CartridgeSubscription instance
CartridgeSubscription cartridgeSubscription = CartridgeSubscriptionFactory.getLBCartridgeSubscriptionInstance(lbDataContext, loadBalancerCategory);
@@ -234,12 +188,7 @@ public class CartridgeSubscriptionManager {
cartridgeSubscription.setSubscriptionKey(subscriptionKey);
// Create repository
- Repository repository = cartridgeSubscription.manageRepository(null,
- "",
- "",
- false,
- lbAlias,
- lbDataContext.getLbCartridgeInfo(),
+ Repository repository = cartridgeSubscription.manageRepository(null, "", "", false, lbAlias, lbDataContext.getLbCartridgeInfo(),
subscriptionData.getTenantDomain());
// Create subscriber
@@ -251,9 +200,60 @@ public class CartridgeSubscriptionManager {
log.info("Tenant [" + subscriptionData.getTenantId() + "] with username [" + subscriptionData.getTenantAdminUsername() +
- " subscribed to " + "] Cartridge with Alias " + lbAlias + ", Cartridge Type: " +
- lbCategoryContext.getLbType() + ", Autoscale Policy: " +
- lbDataContext.getAutoscalePolicy() + ", Deployment Policy: " + lbDataContext.getDeploymentPolicy());
+ " subscribed to " + "] Cartridge with Alias " + lbAlias + ", Cartridge Type: " + lbDataContext.getLbCartridgeInfo().getType() +
+ ", Autoscale Policy: " + lbDataContext.getAutoscalePolicy() + ", Deployment Policy: " + lbDataContext.getDeploymentPolicy());
+
+ // Publish tenant subscribed event to message broker
+ CartridgeSubscriptionUtils.publishTenantSubscribedEvent(cartridgeSubscription.getSubscriber().getTenantId(),
+ cartridgeSubscription.getCartridgeInfo().getType());
+
+ return cartridgeSubscription;
+ }
+
+ private CartridgeSubscription subscribe (SubscriptionData subscriptionData, CartridgeInfo cartridgeInfo)
+
+ throws ADCException, InvalidCartridgeAliasException,
+ DuplicateCartridgeAliasException, PolicyException, UnregisteredCartridgeException, RepositoryRequiredException, RepositoryCredentialsRequiredException,
+ RepositoryTransportException, AlreadySubscribedException, InvalidRepositoryException {
+
+
+ // Decide tenancy behaviour
+ SubscriptionTenancyBehaviour tenancyBehaviour;
+ if(cartridgeInfo.getMultiTenant()) {
+ tenancyBehaviour = new SubscriptionMultiTenantBehaviour();
+ } else {
+ tenancyBehaviour = new SubscriptionSingleTenantBehaviour();
+ }
+
+ // Create the CartridgeSubscription instance
+ CartridgeSubscription cartridgeSubscription = CartridgeSubscriptionFactory.
+ getCartridgeSubscriptionInstance(cartridgeInfo, tenancyBehaviour);
+
+ // Generate and set the key
+ String subscriptionKey = CartridgeSubscriptionUtils.generateSubscriptionKey();
+ cartridgeSubscription.setSubscriptionKey(subscriptionKey);
+
+ // Create repository
+ Repository repository = cartridgeSubscription.manageRepository(subscriptionData.getRepositoryURL(),
+ subscriptionData.getRepositoryUsername(),
+ subscriptionData.getRepositoryPassword(),
+ subscriptionData.isPrivateRepository(),
+ subscriptionData.getCartridgeAlias(),
+ cartridgeInfo,
+ subscriptionData.getTenantDomain());
+
+ // Create subscriber
+ Subscriber subscriber = new Subscriber(subscriptionData.getTenantAdminUsername(), subscriptionData.getTenantId(), subscriptionData.getTenantDomain());
+
+ // create subscription
+ cartridgeSubscription.createSubscription(subscriber, subscriptionData.getCartridgeAlias(), subscriptionData.getAutoscalingPolicyName(),
+ subscriptionData.getDeploymentPolicyName(), repository);
+
+
+ log.info("Tenant [" + subscriptionData.getTenantId() + "] with username [" + subscriptionData.getTenantAdminUsername() +
+ " subscribed to " + "] Cartridge with Alias " + subscriptionData.getCartridgeAlias() + ", Cartridge Type: " +
+ subscriptionData.getCartridgeType() + ", Repo URL: " + subscriptionData.getRepositoryURL() + ", Autoscale Policy: " +
+ subscriptionData.getAutoscalingPolicyName() + ", Deployment Policy: " + subscriptionData.getDeploymentPolicyName());
// Publish tenant subscribed event to message broker
@@ -272,7 +272,7 @@ public class CartridgeSubscriptionManager {
* @throws ADCException
* @throws UnregisteredCartridgeException
*/
- public SubscriptionInfo registerCartridgeSubscription(CartridgeSubscription cartridgeSubscription, Properties properties)
+ private SubscriptionInfo registerCartridgeSubscription(CartridgeSubscription cartridgeSubscription, Properties properties)
throws ADCException, UnregisteredCartridgeException {
CartridgeSubscriptionInfo cartridgeSubscriptionInfo = cartridgeSubscription.registerSubscription(properties);
@@ -351,7 +351,42 @@ public class CartridgeSubscriptionManager {
throw new NotSubscribedException(errorMsg, alias);
}
}
-
+
+ private Properties getPersistenceMappingProperties (PersistanceMapping persistanceMapping, CartridgeInfo cartridgeInfo) throws ADCException {
+
+ if (!persistanceMapping.getPersistanceRequired()) {
+ // Persistence Mapping not required for this subscription
+ return null;
+ }
+
+ if (persistanceMapping.getPersistanceRequired() && !cartridgeInfo.isPeristanceMappingsSpecified()) {
+ // Persistence Mapping not supported in the cartridge definition - error
+ String errorMsg = "Persistence Mapping not supported by the cartridge type " + cartridgeInfo.getType();
+ log.error(errorMsg);
+ throw new ADCException(errorMsg);
+ }
+
+ Property persistanceRequiredProperty = new Property();
+ persistanceRequiredProperty.setName(Constants.IS_VOLUME_REQUIRED);
+ persistanceRequiredProperty.setValue(String.valueOf(persistanceMapping.getPersistanceRequired()));
+
+ Property sizeProperty = new Property();
+ sizeProperty.setName(Constants.VOLUME_SIZE);
+ sizeProperty.setValue(Integer.toString(persistanceMapping.getSize()));
+
+ Property deviceProperty = new Property();
+ deviceProperty.setName(Constants.DEVICE_NAME);
+ deviceProperty.setValue(String.valueOf(persistanceMapping.getDevice()));
+
+ Property deleteOnTerminationProperty = new Property();
+ deleteOnTerminationProperty.setName(Constants.SHOULD_DELETE_VOLUME);
+ deleteOnTerminationProperty.setValue(String.valueOf(persistanceMapping.getRemoveOntermination()));
+
+ Properties persistenceMappingProperties = new Properties();
+ persistenceMappingProperties.setProperties(new Property[]{persistanceRequiredProperty, sizeProperty, deviceProperty, deleteOnTerminationProperty});
+
+ return persistenceMappingProperties;
+ }
/**
*
[04/12] finalizing the refactoring of LB subscription and service
deployment
Posted by is...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e79a7e2f/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/LBCartridgeSubscription.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/LBCartridgeSubscription.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/LBCartridgeSubscription.java
index fcb2616..17b9eba 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/LBCartridgeSubscription.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/LBCartridgeSubscription.java
@@ -21,7 +21,6 @@ package org.apache.stratos.manager.subscription;
import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
import org.apache.stratos.cloud.controller.pojo.Properties;
-import org.apache.stratos.cloud.controller.pojo.Property;
import org.apache.stratos.manager.dao.CartridgeSubscriptionInfo;
import org.apache.stratos.manager.exception.*;
import org.apache.stratos.manager.lb.category.LoadBalancerCategory;
@@ -30,8 +29,6 @@ import org.apache.stratos.manager.subscriber.Subscriber;
import org.apache.stratos.manager.subscription.tenancy.SubscriptionTenancyBehaviour;
import org.apache.stratos.manager.utils.ApplicationManagementUtil;
-import java.util.List;
-
public class LBCartridgeSubscription extends CartridgeSubscription {
private LoadBalancerCategory loadBalancerCategory;
@@ -51,7 +48,7 @@ public class LBCartridgeSubscription extends CartridgeSubscription {
}
public void createSubscription (Subscriber subscriber, String alias, String autoscalingPolicy,
- String deploymentPolicyName, Repository repository, List<Property> payloadProperties)
+ String deploymentPolicyName, Repository repository)
throws ADCException, PolicyException, UnregisteredCartridgeException, InvalidCartridgeAliasException,
DuplicateCartridgeAliasException, RepositoryRequiredException, AlreadySubscribedException,
RepositoryCredentialsRequiredException, InvalidRepositoryException, RepositoryTransportException {
@@ -61,13 +58,16 @@ public class LBCartridgeSubscription extends CartridgeSubscription {
setAutoscalingPolicyName(autoscalingPolicy);
setDeploymentPolicyName(deploymentPolicyName);
setRepository(repository);
- setPayloadData(getLoadBalancerCategory().createPayload());
+
+ setPayloadData(getLoadBalancerCategory().create(getAlias(), getCluster(), getSubscriber(), getRepository(), getCartridgeInfo(),
+ getSubscriptionKey(), getCustomPayloadEntries()));
}
@Override
public CartridgeSubscriptionInfo registerSubscription(Properties properties) throws ADCException, UnregisteredCartridgeException {
- getLoadBalancerCategory().register();
+ getLoadBalancerCategory().register (getCartridgeInfo(), getCluster(), getPayloadData(), getAutoscalingPolicyName(),
+ getDeploymentPolicyName(), properties);
return ApplicationManagementUtil.createCartridgeSubscription(getCartridgeInfo(), getAutoscalingPolicyName(),
getType(), getAlias(), getSubscriber().getTenantId(), getSubscriber().getTenantDomain(),
@@ -78,7 +78,7 @@ public class LBCartridgeSubscription extends CartridgeSubscription {
@Override
public void removeSubscription() throws ADCException, NotSubscribedException {
- getLoadBalancerCategory().unregister();
+ getLoadBalancerCategory().remove(getCluster().getClusterDomain(), getAlias());;
}
public Repository manageRepository (String repoURL, String repoUserName, String repoUserPassword,
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e79a7e2f/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/SubscriptionData.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/SubscriptionData.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/SubscriptionData.java
index ecd80c0..a0801a3 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/SubscriptionData.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/SubscriptionData.java
@@ -29,7 +29,6 @@ public class SubscriptionData {
private String cartridgeType;
private String cartridgeAlias;
-
private String autoscalingPolicyName;
private String deploymentPolicyName;
private String tenantDomain;
@@ -43,7 +42,6 @@ public class SubscriptionData {
private String lbClusterId;
private Property[] properties;
private String dataCartridgeAlias;
- private String lbAlias;
private PersistanceMapping persistanceMapping;
public String getCartridgeType() {
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e79a7e2f/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/tenancy/SubscriptionSingleTenantBehaviour.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/tenancy/SubscriptionSingleTenantBehaviour.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/tenancy/SubscriptionSingleTenantBehaviour.java
index 95edc25..e734d86 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/tenancy/SubscriptionSingleTenantBehaviour.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/tenancy/SubscriptionSingleTenantBehaviour.java
@@ -19,130 +19,6 @@
package org.apache.stratos.manager.subscription.tenancy;
-import org.apache.axis2.AxisFault;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
-import org.apache.stratos.cloud.controller.pojo.Properties;
-import org.apache.stratos.cloud.controller.pojo.Property;
-import org.apache.stratos.manager.client.CloudControllerServiceClient;
-import org.apache.stratos.manager.dao.Cluster;
-import org.apache.stratos.manager.exception.ADCException;
-import org.apache.stratos.manager.exception.AlreadySubscribedException;
-import org.apache.stratos.manager.exception.NotSubscribedException;
-import org.apache.stratos.manager.exception.UnregisteredCartridgeException;
-import org.apache.stratos.manager.payload.BasicPayloadData;
-import org.apache.stratos.manager.payload.PayloadData;
-import org.apache.stratos.manager.payload.PayloadFactory;
-import org.apache.stratos.manager.repository.Repository;
-import org.apache.stratos.manager.subscriber.Subscriber;
-import org.apache.stratos.manager.subscription.utils.CartridgeSubscriptionUtils;
-import org.apache.stratos.manager.utils.ApplicationManagementUtil;
-import org.apache.stratos.manager.utils.CartridgeConstants;
-
-import java.util.Map;
-import java.util.Set;
-
-
public class SubscriptionSingleTenantBehaviour extends SubscriptionTenancyBehaviour {
- private static Log log = LogFactory.getLog(SubscriptionSingleTenantBehaviour.class);
-
- public PayloadData create (String alias, Cluster cluster, Subscriber subscriber, Repository repository, CartridgeInfo cartridgeInfo,
- String subscriptionKey, Map<String, String> customPayloadEntries) throws ADCException, AlreadySubscribedException {
-
- //set the cluster and hostname
- //cartridgeSubscription.getCluster().setClusterDomain(cartridgeSubscription.getAlias() + "." +
- // cartridgeSubscription.getCluster().getHostName() + "." + cartridgeSubscription.getType() + ".domain");
- String clusterId = alias + "." + cartridgeInfo.getType() + ".domain";
-
- // limit the cartridge alias to 30 characters in length
- if (clusterId.length() > 30) {
- clusterId = CartridgeSubscriptionUtils.limitLengthOfString(clusterId, 30);
- }
- cluster.setClusterDomain(clusterId);
- // set hostname
- cluster.setHostName(alias + "." + cluster.getHostName());
-
- //Create the payload
- BasicPayloadData basicPayloadData = CartridgeSubscriptionUtils.createBasicPayload(cartridgeInfo, subscriptionKey, cluster, repository,
- alias, subscriber);
- //Populate the basic payload details
- basicPayloadData.populatePayload();
-
- PayloadData payloadData = PayloadFactory.getPayloadDataInstance(cartridgeInfo.getProvider(),
- cartridgeInfo.getType(), basicPayloadData);
-
- // get the payload parameters defined in the cartridge definition file for this cartridge type
- if (cartridgeInfo.getProperties() != null && cartridgeInfo.getProperties().length != 0) {
-
- for (Property property : cartridgeInfo.getProperties()) {
- // 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 (property.getName()
- .startsWith(CartridgeConstants.CUSTOM_PAYLOAD_PARAM_NAME_PREFIX)) {
- String payloadParamName = property.getName();
- payloadData.add(payloadParamName.substring(payloadParamName.indexOf(".") + 1), property.getValue());
- }
- }
- }
-
- //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;
- }
-
- public void register (CartridgeInfo cartridgeInfo, Cluster cluster, PayloadData payloadData, String autoscalePolicyName,
- String deploymentPolicyName, Properties properties) throws ADCException, UnregisteredCartridgeException {
-
- log.info("Payload: " + payloadData.getCompletePayloadData().toString());
-
- ApplicationManagementUtil.registerService(cartridgeInfo.getType(),
- cluster.getClusterDomain(),
- cluster.getClusterSubDomain(),
- payloadData.getCompletePayloadData(),
- payloadData.getBasicPayloadData().getTenantRange(),
- cluster.getHostName(),
- autoscalePolicyName,
- deploymentPolicyName,
- properties);
- }
-
- public void remove (String clusterId, String alias) throws ADCException, NotSubscribedException {
-
- try {
- CloudControllerServiceClient.getServiceClient().terminateAllInstances(clusterId);
-
- } catch (AxisFault e) {
- String errorMsg = "Error in terminating cartridge subscription, alias " + alias;
- log.error(errorMsg);
- throw new ADCException(errorMsg, e);
-
- } catch (Exception e) {
- String errorMsg = "Error in terminating cartridge subscription, alias " + alias;
- log.error(errorMsg);
- throw new ADCException(errorMsg, e);
- }
-
- log.info("Terminated all instances of " + clusterId);
-
- try {
- CloudControllerServiceClient.getServiceClient().unregisterService(clusterId);
-
- } catch (Exception e) {
- String errorMsg = "Error in unregistering service cluster with domain " + clusterId;
- log.error(errorMsg);
- throw new ADCException(errorMsg, e);
- }
-
- log.info("Unregistered service cluster, domain " + clusterId);
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e79a7e2f/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/tenancy/SubscriptionTenancyBehaviour.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/tenancy/SubscriptionTenancyBehaviour.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/tenancy/SubscriptionTenancyBehaviour.java
index c367545..1e16d33 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/tenancy/SubscriptionTenancyBehaviour.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/tenancy/SubscriptionTenancyBehaviour.java
@@ -19,33 +19,8 @@
package org.apache.stratos.manager.subscription.tenancy;
-import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
-import org.apache.stratos.cloud.controller.pojo.Properties;
import org.apache.stratos.manager.behaviour.CartridgeMgtBehaviour;
-import org.apache.stratos.manager.dao.Cluster;
-import org.apache.stratos.manager.exception.ADCException;
-import org.apache.stratos.manager.exception.AlreadySubscribedException;
-import org.apache.stratos.manager.exception.NotSubscribedException;
-import org.apache.stratos.manager.exception.UnregisteredCartridgeException;
-import org.apache.stratos.manager.payload.PayloadData;
-import org.apache.stratos.manager.repository.Repository;
-import org.apache.stratos.manager.subscriber.Subscriber;
-import java.io.Serializable;
-import java.util.Map;
+public abstract class SubscriptionTenancyBehaviour extends CartridgeMgtBehaviour {
-public abstract class SubscriptionTenancyBehaviour implements CartridgeMgtBehaviour, Serializable {
-
- private static final long serialVersionUID = 6529685098267757690L;
-
- public abstract PayloadData create (String alias, Cluster cluster, Subscriber subscriber, Repository repository, CartridgeInfo cartridgeInfo,
- String subscriptionKey, Map<String, String> customPayloadEntries)
- throws ADCException, AlreadySubscribedException;
-
- public abstract void register (CartridgeInfo cartridgeInfo, Cluster cluster, PayloadData payloadData, String autoscalePolicyName,
- String deploymentPolicyName, Properties properties)
- throws ADCException, UnregisteredCartridgeException;
-
- public abstract void remove (String clusterId, String alias)
- throws ADCException, NotSubscribedException;
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e79a7e2f/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
index 30f2b74..122fa85 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
@@ -36,12 +36,10 @@ import org.apache.stratos.manager.exception.ADCException;
import org.apache.stratos.manager.exception.DuplicateCartridgeAliasException;
import org.apache.stratos.manager.exception.InvalidCartridgeAliasException;
import org.apache.stratos.manager.exception.UnregisteredCartridgeException;
-import org.apache.stratos.manager.lb.category.LBCategoryContext;
import org.apache.stratos.manager.lb.category.LBDataContext;
import org.apache.stratos.manager.payload.BasicPayloadData;
import org.apache.stratos.manager.repository.Repository;
import org.apache.stratos.manager.retriever.DataInsertionAndRetrievalManager;
-import org.apache.stratos.manager.subscription.SubscriptionData;
import org.apache.stratos.manager.subscriber.Subscriber;
import org.apache.stratos.messaging.broker.publish.EventPublisher;
import org.apache.stratos.messaging.event.tenant.TenantSubscribedEvent;
@@ -60,17 +58,28 @@ public class CartridgeSubscriptionUtils {
BasicPayloadData basicPayloadData = new BasicPayloadData();
basicPayloadData.setApplicationPath(cartridgeInfo.getBaseDir());
basicPayloadData.setSubscriptionKey(subscriptionKey);
- basicPayloadData.setClusterId(cluster.getClusterDomain());
basicPayloadData.setDeployment("default");//currently hard coded to default
- if(repository != null) {
- basicPayloadData.setGitRepositoryUrl(repository.getUrl());
- }
- basicPayloadData.setHostName(cluster.getHostName());
basicPayloadData.setMultitenant(String.valueOf(cartridgeInfo.getMultiTenant()));
basicPayloadData.setPortMappings(createPortMappingPayloadString(cartridgeInfo));
basicPayloadData.setServiceName(cartridgeInfo.getType());
- basicPayloadData.setSubscriptionAlias(alias);
- basicPayloadData.setTenantId(subscriber.getTenantId());
+
+ if(repository != null) {
+ basicPayloadData.setGitRepositoryUrl(repository.getUrl());
+ }
+
+ if (cluster != null) {
+ basicPayloadData.setClusterId(cluster.getClusterDomain());
+ basicPayloadData.setHostName(cluster.getHostName());
+ }
+
+ if (alias != null) {
+ basicPayloadData.setSubscriptionAlias(alias);
+ }
+
+ if (subscriber != null) {
+ basicPayloadData.setTenantId(subscriber.getTenantId());
+ }
+
//TODO:remove. we do not want to know about the tenant rance in subscription!
if(cartridgeInfo.getMultiTenant() || subscriber.getTenantId() == -1234) { //TODO: fix properly
basicPayloadData.setTenantRange("*");
@@ -98,28 +107,28 @@ public class CartridgeSubscriptionUtils {
return basicPayloadData;
}
- public static BasicPayloadData createBasicPayload (LBCategoryContext lbCategoryContext) {
-
- BasicPayloadData basicPayloadData = new BasicPayloadData();
- basicPayloadData.setApplicationPath(lbCategoryContext.getCartridgeInfo().getBaseDir());
- basicPayloadData.setSubscriptionKey(lbCategoryContext.getKey());
- basicPayloadData.setClusterId(lbCategoryContext.getCluster().getClusterDomain());
- basicPayloadData.setDeployment("default");//currently hard coded to default
- basicPayloadData.setHostName(lbCategoryContext.getCluster().getHostName());
- basicPayloadData.setMultitenant(String.valueOf(lbCategoryContext.getCartridgeInfo().getMultiTenant()));
- basicPayloadData.setPortMappings(createPortMappingPayloadString(lbCategoryContext.getCartridgeInfo()));
- basicPayloadData.setServiceName(lbCategoryContext.getLbType());
-
- if (lbCategoryContext.getSubscriptionAlias() != null && !lbCategoryContext.getSubscriptionAlias().isEmpty()) {
- basicPayloadData.setSubscriptionAlias(lbCategoryContext.getSubscriptionAlias());
- }
-
- if (lbCategoryContext.getSubscriber() != null) {
- basicPayloadData.setTenantId(lbCategoryContext.getSubscriber().getTenantId());
- }
-
- return basicPayloadData;
- }
+// public static BasicPayloadData createBasicPayload (LBCategoryContext lbCategoryContext) {
+//
+// BasicPayloadData basicPayloadData = new BasicPayloadData();
+// basicPayloadData.setApplicationPath(lbCategoryContext.getCartridgeInfo().getBaseDir());
+// basicPayloadData.setSubscriptionKey(lbCategoryContext.getKey());
+// basicPayloadData.setClusterId(lbCategoryContext.getCluster().getClusterDomain());
+// basicPayloadData.setDeployment("default");//currently hard coded to default
+// basicPayloadData.setHostName(lbCategoryContext.getCluster().getHostName());
+// basicPayloadData.setMultitenant(String.valueOf(lbCategoryContext.getCartridgeInfo().getMultiTenant()));
+// basicPayloadData.setPortMappings(createPortMappingPayloadString(lbCategoryContext.getCartridgeInfo()));
+// basicPayloadData.setServiceName(lbCategoryContext.getLbType());
+//
+// if (lbCategoryContext.getSubscriptionAlias() != null && !lbCategoryContext.getSubscriptionAlias().isEmpty()) {
+// basicPayloadData.setSubscriptionAlias(lbCategoryContext.getSubscriptionAlias());
+// }
+//
+// if (lbCategoryContext.getSubscriber() != null) {
+// basicPayloadData.setTenantId(lbCategoryContext.getSubscriber().getTenantId());
+// }
+//
+// return basicPayloadData;
+// }
private static String createPortMappingPayloadString (CartridgeInfo cartridgeInfo) {
@@ -213,13 +222,13 @@ public class CartridgeSubscriptionUtils {
return source.substring(0, length);
}
- public static LBDataContext getLoadBalancerDataContext (SubscriptionData subscriptionData, LoadbalancerConfig lbConfig) throws UnregisteredCartridgeException, ADCException {
+ public static LBDataContext getLoadBalancerDataContext (int tenantId, String serviceType, String deploymentPolicyName, LoadbalancerConfig lbConfig) throws UnregisteredCartridgeException, ADCException {
String lbCartridgeType = lbConfig.getType();
LBDataContext lbDataCtxt = new LBDataContext();
// set tenant Id
- lbDataCtxt.setTenantId(subscriptionData.getTenantId());
+ lbDataCtxt.setTenantId(tenantId);
Properties lbReferenceProperties = lbConfig.getProperties();
@@ -236,8 +245,7 @@ public class CartridgeSubscriptionUtils {
if ("true".equals(value)) {
if (log.isDebugEnabled()) {
- log.debug("This cartridge does not require a load balancer. " +
- "[Type] " + subscriptionData.getCartridgeType());
+ log.debug("This cartridge does not require a load balancer. " + "[Type] " + serviceType);
}
lbRefProperty.setValue(name);
lbDataCtxt.addLoadBalancedServiceProperty(lbRefProperty);
@@ -247,15 +255,14 @@ public class CartridgeSubscriptionUtils {
String clusterIdsVal = value;
if (log.isDebugEnabled()) {
- log.debug("This cartridge refers to existing load balancers. " + "[Type] " +
- subscriptionData.getCartridgeType() + "[Referenced Cluster Ids] " + clusterIdsVal);
+ log.debug("This cartridge refers to existing load balancers. " + "[Type] " + serviceType + "[Referenced Cluster Ids] " + clusterIdsVal);
}
String[] clusterIds = clusterIdsVal.split(",");
for (String clusterId : clusterIds) {
try {
- AutoscalerServiceClient.getServiceClient().checkLBExistenceAgainstPolicy(clusterId, subscriptionData.getDeploymentPolicyName());
+ AutoscalerServiceClient.getServiceClient().checkLBExistenceAgainstPolicy(clusterId, deploymentPolicyName);
} catch (Exception ex) {
// we don't need to throw the error here.
log.error(ex.getMessage(), ex);
@@ -291,7 +298,7 @@ public class CartridgeSubscriptionUtils {
lbDataCtxt.setLbCartridgeInfo(lbCartridgeInfo);
if (log.isDebugEnabled()) {
- log.debug("This cartridge uses default load balancer. " + "[Type] " + subscriptionData.getCartridgeType());
+ log.debug("This cartridge uses default load balancer. " + "[Type] " + serviceType);
}
try {
@@ -302,9 +309,9 @@ public class CartridgeSubscriptionUtils {
for (DeploymentPolicy policy : lbCartridgeDepPolicies) {
// check existence of the subscribed policy
- if (subscriptionData.getDeploymentPolicyName().equals(policy.getId())) {
+ if (deploymentPolicyName.equals(policy.getId())) {
- if (!getAutoscalerServiceClient().checkDefaultLBExistenceAgainstPolicy(subscriptionData.getDeploymentPolicyName())) {
+ if (!getAutoscalerServiceClient().checkDefaultLBExistenceAgainstPolicy(deploymentPolicyName)) {
Properties lbProperties = new Properties();
@@ -327,7 +334,7 @@ public class CartridgeSubscriptionUtils {
}
// set deployment and autoscaling policies
- lbDataCtxt.setDeploymentPolicy(subscriptionData.getDeploymentPolicyName());
+ lbDataCtxt.setDeploymentPolicy(deploymentPolicyName);
lbDataCtxt.setAutoscalePolicy(lbCartridgeInfo.getDefaultAutoscalingPolicy());
lbDataCtxt.addLoadBalancedServiceProperty(lbRefProperty);
@@ -362,10 +369,10 @@ public class CartridgeSubscriptionUtils {
Property loadBalancedServiceTypeProperty = new Property();
loadBalancedServiceTypeProperty.setName(Constants.LOAD_BALANCED_SERVICE_TYPE);
// set the load balanced service type
- loadBalancedServiceTypeProperty.setValue(subscriptionData.getCartridgeType());
+ loadBalancedServiceTypeProperty.setValue(serviceType);
if (log.isDebugEnabled()) {
- log.debug("This cartridge uses a service aware load balancer. [Type] " + subscriptionData.getCartridgeType());
+ log.debug("This cartridge uses a service aware load balancer. [Type] " + serviceType);
}
try {
@@ -375,10 +382,9 @@ public class CartridgeSubscriptionUtils {
// traverse deployment policies of lb cartridge
for (DeploymentPolicy policy : lbCartridgeDepPolicies) {
// check existence of the subscribed policy
- if (subscriptionData.getDeploymentPolicyName().equals(policy.getId())) {
+ if (deploymentPolicyName.equals(policy.getId())) {
- if (!getAutoscalerServiceClient().checkServiceLBExistenceAgainstPolicy(subscriptionData.getCartridgeType(),
- subscriptionData.getDeploymentPolicyName())) {
+ if (!getAutoscalerServiceClient().checkServiceLBExistenceAgainstPolicy(serviceType, deploymentPolicyName)) {
Properties lbProperties = new Properties();
@@ -393,7 +399,7 @@ public class CartridgeSubscriptionUtils {
// set a payload property for load balanced service type
Property payloadProperty = new Property();
payloadProperty.setName("LOAD_BALANCED_SERVICE_TYPE"); //TODO: refactor hardcoded name
- payloadProperty.setValue(subscriptionData.getCartridgeType());
+ payloadProperty.setValue(serviceType);
lbDataCtxt.addLBProperties(lbProperties);
}
@@ -406,7 +412,7 @@ public class CartridgeSubscriptionUtils {
}
// set deployment and autoscaling policies
- lbDataCtxt.setDeploymentPolicy(subscriptionData.getDeploymentPolicyName());
+ lbDataCtxt.setDeploymentPolicy(deploymentPolicyName);
lbDataCtxt.setAutoscalePolicy(lbCartridgeInfo.getDefaultAutoscalingPolicy());
lbDataCtxt.addLoadBalancedServiceProperty(lbRefProperty);
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e79a7e2f/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
index cedf8c9..cafdb3f 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
@@ -23,8 +23,10 @@ import org.apache.axis2.context.ConfigurationContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy;
-import org.apache.stratos.cloud.controller.pojo.*;
-import org.apache.stratos.cloud.controller.pojo.Properties;
+import org.apache.stratos.cloud.controller.pojo.CartridgeConfig;
+import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
+import org.apache.stratos.cloud.controller.pojo.PersistanceMapping;
+import org.apache.stratos.cloud.controller.pojo.Property;
import org.apache.stratos.manager.client.AutoscalerServiceClient;
import org.apache.stratos.manager.client.CloudControllerServiceClient;
import org.apache.stratos.manager.deploy.service.Service;
@@ -36,14 +38,12 @@ import org.apache.stratos.manager.manager.CartridgeSubscriptionManager;
import org.apache.stratos.manager.subscription.CartridgeSubscription;
import org.apache.stratos.manager.subscription.DataCartridgeSubscription;
import org.apache.stratos.manager.subscription.SubscriptionData;
-import org.apache.stratos.manager.subscription.utils.CartridgeSubscriptionUtils;
import org.apache.stratos.manager.topology.model.TopologyClusterInformationModel;
import org.apache.stratos.manager.utils.ApplicationManagementUtil;
import org.apache.stratos.manager.utils.CartridgeConstants;
import org.apache.stratos.messaging.domain.topology.Cluster;
import org.apache.stratos.messaging.domain.topology.Member;
import org.apache.stratos.messaging.domain.topology.MemberStatus;
-import org.apache.stratos.messaging.util.Constants;
import org.apache.stratos.rest.endpoint.bean.CartridgeInfoBean;
import org.apache.stratos.rest.endpoint.bean.StratosAdminResponse;
import org.apache.stratos.rest.endpoint.bean.autoscaler.partition.Partition;
@@ -810,36 +810,14 @@ public class ServiceUtils {
InvalidCartridgeAliasException, DuplicateCartridgeAliasException, RepositoryRequiredException,
AlreadySubscribedException, RepositoryCredentialsRequiredException, InvalidRepositoryException,
RepositoryTransportException {
- // LB cartridges won't go thru this method.
- //TODO: this is a temp fix. proper fix is to move this logic to CartridgeSubscriptionManager
- // validate cartridge alias
- CartridgeSubscriptionUtils.validateCartridgeAlias(ApplicationManagementUtil.getTenantId(configurationContext), cartridgeInfoBean.getCartridgeType(), cartridgeInfoBean.getAlias());
-
- AutoscalerServiceClient autoscalerServiceClient = getAutoscalerServiceClient();
- CloudControllerServiceClient cloudControllerServiceClient =
- getCloudControllerServiceClient();
- CartridgeInfo cartridgeInfo;
-
- try {
- cartridgeInfo = cloudControllerServiceClient.getCartridgeInfo(cartridgeInfoBean.getCartridgeType());
- } catch (Exception e) {
- String msg = "Cannot get cartridge info: " + cartridgeInfoBean.getCartridgeType();
- log.error(msg, e);
- throw new ADCException(msg, e);
- }
-
- String cartridgeType = cartridgeInfoBean.getCartridgeType();
- String deploymentPolicy = cartridgeInfoBean.getDeploymentPolicy();
- String autoscalingPolicy = cartridgeInfoBean.getAutoscalePolicy();
- String dataCartridgeAlias = cartridgeInfoBean.getDataCartridgeAlias();
SubscriptionData subscriptionData = new SubscriptionData();
- subscriptionData.setCartridgeType(cartridgeType);
+ subscriptionData.setCartridgeType(cartridgeInfoBean.getCartridgeType());
subscriptionData.setCartridgeAlias(cartridgeInfoBean.getAlias().trim());
- subscriptionData.setDataCartridgeAlias(dataCartridgeAlias);
- subscriptionData.setAutoscalingPolicyName(autoscalingPolicy);
- subscriptionData.setDeploymentPolicyName(deploymentPolicy);
+ //subscriptionData.setDataCartridgeAlias(dataCartridgeAlias);
+ subscriptionData.setAutoscalingPolicyName(cartridgeInfoBean.getAutoscalePolicy());
+ subscriptionData.setDeploymentPolicyName(cartridgeInfoBean.getDeploymentPolicy());
subscriptionData.setTenantDomain(tenantDomain);
subscriptionData.setTenantId(ApplicationManagementUtil.getTenantId(configurationContext));
subscriptionData.setTenantAdminUsername(tenantUsername);
@@ -848,306 +826,319 @@ public class ServiceUtils {
subscriptionData.setRepositoryUsername(cartridgeInfoBean.getRepoURL());
subscriptionData.setRepositoryPassword(cartridgeInfoBean.getRepoPassword());
- Properties properties = new Properties();
- if(cartridgeInfoBean.isPersistanceRequired()){
- /*
+ if (cartridgeInfoBean.isPersistanceRequired()) {
PersistanceMapping persistanceMapping = new PersistanceMapping();
- persistanceMapping.setPersistanceRequired(persistanceMappingBean.persistanceRequired);
- persistanceMapping.setSize(persistanceMappingBean.size);
- persistanceMapping.setDevice(persistanceMappingBean.device);
- persistanceMapping.setRemoveOntermination(persistanceMappingBean.removeOnTermination);
- subscriptionData.setPersistanceMapping(persistanceMapping);
- */
-
- // Add persistance mapping properties to the subscription.
- Property persistanceRequiredProperty = new Property();
- persistanceRequiredProperty.setName(IS_VOLUME_REQUIRED);
- persistanceRequiredProperty.setValue(String.valueOf(cartridgeInfoBean.isPersistanceRequired()));
-
- Property sizeProperty = new Property();
- sizeProperty.setName(VOLUME_SIZE);
- sizeProperty.setValue(cartridgeInfoBean.getSize());
-
- Property deviceProperty = new Property();
- deviceProperty.setName(DEVICE_NAME);
- deviceProperty.setValue(String.valueOf(cartridgeInfoBean.getDevice()));
-
- Property deleteOnTerminationProperty = new Property();
- deleteOnTerminationProperty.setName(SHOULD_DELETE_VOLUME);
- deleteOnTerminationProperty.setValue(String.valueOf( cartridgeInfoBean.isRemoveOnTermination()));
-
- properties.setProperties(new Property[]{persistanceRequiredProperty,sizeProperty, deviceProperty, deleteOnTerminationProperty});
- }
-
-
- // If multitenant, return for now. TODO -- fix properly
- if(cartridgeInfo != null && cartridgeInfo.getMultiTenant()) {
- log.info(" ******* MT cartridge ******* ");
-
- subscriptionData.setPrivateRepository(false);
- subscriptionData.setLbClusterId(null);
- subscriptionData.setProperties(null);
-
- CartridgeSubscription cartridgeSubscription =
- cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(subscriptionData);
- log.info(" --- ** -- ");
- return cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription, properties);
-
- }
-
- List<Property> lbRefProp = new ArrayList<Property>();
-
- // get lb config reference
- LoadbalancerConfig lbConfig = cartridgeInfo.getLbConfig();
- String lbClusterId = null;
-
- if (lbConfig == null || lbConfig.getProperties() == null) {
- if (log.isDebugEnabled()) {
- log.debug("This Service does not require a load balancer. " + "[Service Name] " +
- cartridgeType);
- }
- } else {
-
- Properties lbReferenceProperties = lbConfig.getProperties();
-
- Property property = new Property();
- property.setName(org.apache.stratos.messaging.util.Constants.LOAD_BALANCER_REF);
-
-
- for (org.apache.stratos.cloud.controller.pojo.Property prop : lbReferenceProperties.getProperties()) {
-
- String name = prop.getName();
- String value = prop.getValue();
-
- // TODO make following a chain of responsibility pattern
- if (Constants.NO_LOAD_BALANCER.equals(name)) {
- if ("true".equals(value)) {
- if (log.isDebugEnabled()) {
- log.debug("This cartridge does not require a load balancer. " +
- "[Type] " + cartridgeType);
- }
- property.setValue(name);
- lbRefProp.add(property);
- break;
- }
- } else if (Constants.EXISTING_LOAD_BALANCERS.equals(name)) {
- String clusterIdsVal = value;
- if (log.isDebugEnabled()) {
- log.debug("This cartridge refers to existing load balancers. " + "[Type] " +
- cartridgeType + "[Referenced Cluster Ids] " + clusterIdsVal);
- }
-
- String[] clusterIds = clusterIdsVal.split(",");
-
- for (String clusterId : clusterIds) {
- if (autoscalerServiceClient != null) {
- try {
- autoscalerServiceClient.checkLBExistenceAgainstPolicy(clusterId,
- deploymentPolicy);
- } catch (Exception ex) {
- // we don't need to throw the error here.
- log.error(ex.getMessage(), ex);
- }
- }
- }
-
- property.setValue(name);
- lbRefProp.add(property);
- break;
-
- } else if (Constants.DEFAULT_LOAD_BALANCER.equals(name)) {
-
- if ("true".equals(value)) {
-
- CartridgeInfo lbCartridgeInfo = null;
- String lbCartridgeType = lbConfig.getType();
- try {
- // retrieve lb Cartridge info
- if(lbCartridgeType != null) {
- lbCartridgeInfo = cloudControllerServiceClient.getCartridgeInfo(lbCartridgeType);
- }
- } catch (Exception e) {
- String msg = "Cannot get cartridge info: " + cartridgeType;
- log.error(msg, e);
- throw new ADCException(msg, e);
- }
-
- property.setValue(name);
- if (log.isDebugEnabled()) {
- log.debug("This cartridge uses default load balancer. " + "[Type] " +
- cartridgeType);
- }
- if (autoscalerServiceClient != null) {
- try {
- // get the valid policies for lb cartridge
- DeploymentPolicy[] lbCartridgeDepPolicies =
- autoscalerServiceClient.getDeploymentPolicies(lbCartridgeType);
- // traverse deployment policies of lb cartridge
- for (DeploymentPolicy policy : lbCartridgeDepPolicies) {
- // check existence of the subscribed policy
- if (deploymentPolicy.equals(policy.getId())) {
-
- if (!autoscalerServiceClient.checkDefaultLBExistenceAgainstPolicy(deploymentPolicy)) {
-
- // if lb cluster doesn't exist
- String lbAlias = "lb" + new Random().nextInt();
- if(lbCartridgeInfo != null) {
- lbCartridgeInfo.addProperties(property);
- lbClusterId = subscribeToLb(lbCartridgeType, cartridgeType,
- lbAlias,
- lbCartridgeInfo.getDefaultAutoscalingPolicy(),
- deploymentPolicy, configurationContext,
- tenantUsername, tenantDomain,
- lbCartridgeInfo.getProperties());
- } else {
- String msg = "Please specify a LB cartridge type for the cartridge: "
- + cartridgeType + " as category: " +
- Constants.DEFAULT_LOAD_BALANCER;
- log.error(msg);
- throw new ADCException(msg);
- }
- }
- }
- }
-
- } catch (Exception ex) {
- // we don't need to throw the error here.
- log.error(ex.getMessage(), ex);
- }
- }
-
- lbRefProp.add(property);
- break;
- }
-
- } else if (Constants.SERVICE_AWARE_LOAD_BALANCER.equals(name)) {
-
- if ("true".equals(value)) {
-
- CartridgeInfo lbCartridgeInfo = null;
- String lbCartridgeType = lbConfig.getType();
- try {
- // retrieve lb Cartridge info
- if(lbCartridgeType != null) {
- lbCartridgeInfo = cloudControllerServiceClient.getCartridgeInfo(lbCartridgeType);
- }
- } catch (Exception e) {
- String msg = "Cannot get cartridge info: " + cartridgeType;
- log.error(msg, e);
- throw new ADCException(msg, e);
- }
-
- // add a property for the service type
- Property loadBalancedServiceTypeProperty = new Property();
- loadBalancedServiceTypeProperty.setName(Constants.LOAD_BALANCED_SERVICE_TYPE);
-
- property.setValue(name);
- // set the load balanced service type
- loadBalancedServiceTypeProperty.setValue(cartridgeType);
- if (log.isDebugEnabled()) {
- log.debug("This cartridge uses a service aware load balancer. " +
- "[Type] " + cartridgeType);
- }
- if (autoscalerServiceClient != null) {
- try {
-
- // get the valid policies for lb cartridge
- DeploymentPolicy[] lbCartridgeDepPolicies =
- autoscalerServiceClient.getDeploymentPolicies(lbCartridgeType);
- // traverse deployment policies of lb cartridge
- for (DeploymentPolicy policy : lbCartridgeDepPolicies) {
- // check existence of the subscribed policy
- if (deploymentPolicy.equals(policy.getId())) {
-
- if (!autoscalerServiceClient.checkServiceLBExistenceAgainstPolicy(cartridgeType,
- deploymentPolicy)) {
-
- // if lb cluster doesn't exist
- String lbAlias =
- "lb" + cartridgeType +
- new Random().nextInt();
-
- if(lbCartridgeInfo != null) {
- lbCartridgeInfo.addProperties(property);
- lbCartridgeInfo.addProperties(loadBalancedServiceTypeProperty);
-
- lbClusterId = subscribeToLb(lbCartridgeType, cartridgeType,
- lbAlias,
- lbCartridgeInfo.getDefaultAutoscalingPolicy(),
- deploymentPolicy,
- configurationContext, tenantUsername,
- tenantDomain,
- lbCartridgeInfo.getProperties());
- } else {
- String msg = "Please specify a LB cartridge type for the cartridge: "
- + cartridgeType + " as category: " +
- Constants.SERVICE_AWARE_LOAD_BALANCER;
- log.error(msg);
- throw new ADCException(msg);
- }
- }
- }
- }
-
- } catch (Exception ex) {
- // we don't need to throw the error here.
- log.error(ex.getMessage(), ex);
- }
- }
-
- lbRefProp.add(property);
- break;
- }
- }
- }
- }
-
- subscriptionData.setPrivateRepository(cartridgeInfoBean.isPrivateRepo());
- subscriptionData.setLbClusterId(lbClusterId);
- subscriptionData.setProperties(lbRefProp.toArray(new Property[0]));
- CartridgeSubscription cartridgeSubscription =
- cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(subscriptionData);
-
-
- if (dataCartridgeAlias != null && !dataCartridgeAlias.trim().isEmpty()) {
+ persistanceMapping.setPersistanceRequired(cartridgeInfoBean.isPersistanceRequired());
+ persistanceMapping.setDevice(cartridgeInfoBean.getDevice());
+ persistanceMapping.setSize(Integer.parseInt(cartridgeInfoBean.getSize()));
+ persistanceMapping.setRemoveOntermination(cartridgeInfoBean.isRemoveOnTermination());
- /*dataCartridgeAlias = dataCartridgeAlias.trim();
-
- CartridgeSubscription connectingCartridgeSubscription = null;
- try {
- connectingCartridgeSubscription =
- cartridgeSubsciptionManager.getCartridgeSubscription(tenantDomain,
- dataCartridgeAlias);
-
- } catch (NotSubscribedException e) {
- log.error(e.getMessage(), e);
- }
- if (connectingCartridgeSubscription != null) {
- try {
- cartridgeSubsciptionManager.connectCartridges(tenantDomain,
- cartridgeSubscription,
- connectingCartridgeSubscription.getAlias());
-
- } catch (NotSubscribedException e) {
- log.error(e.getMessage(), e);
-
- } catch (AxisFault axisFault) {
- log.error(axisFault.getMessage(), axisFault);
- }
- } else {
- log.error("Failed to connect. No cartridge subscription found for tenant " +
- ApplicationManagementUtil.getTenantId(configurationContext) +
- " with alias " + alias);
- }*/
- }
-
- for (Property lbRefProperty : lbRefProp) {
- properties.addProperties(lbRefProperty);
+ subscriptionData.setPersistanceMapping(persistanceMapping);
}
- SubscriptionInfo registerCartridgeSubscription = cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription, properties);
-
- return registerCartridgeSubscription;
+ //subscribe
+ return cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(subscriptionData);
+
+// Properties properties = new Properties();
+// if(cartridgeInfoBean.isPersistanceRequired()){
+// /*
+// PersistanceMapping persistanceMapping = new PersistanceMapping();
+// persistanceMapping.setPersistanceRequired(persistanceMappingBean.persistanceRequired);
+// persistanceMapping.setSize(persistanceMappingBean.size);
+// persistanceMapping.setDevice(persistanceMappingBean.device);
+// persistanceMapping.setRemoveOntermination(persistanceMappingBean.removeOnTermination);
+// subscriptionData.setPersistanceMapping(persistanceMapping);
+// */
+//
+// // Add persistance mapping properties to the subscription.
+// Property persistanceRequiredProperty = new Property();
+// persistanceRequiredProperty.setName(IS_VOLUME_REQUIRED);
+// persistanceRequiredProperty.setValue(String.valueOf(cartridgeInfoBean.isPersistanceRequired()));
+//
+// Property sizeProperty = new Property();
+// sizeProperty.setName(VOLUME_SIZE);
+// sizeProperty.setValue(cartridgeInfoBean.getSize());
+//
+// Property deviceProperty = new Property();
+// deviceProperty.setName(DEVICE_NAME);
+// deviceProperty.setValue(String.valueOf(cartridgeInfoBean.getDevice()));
+//
+// Property deleteOnTerminationProperty = new Property();
+// deleteOnTerminationProperty.setName(SHOULD_DELETE_VOLUME);
+// deleteOnTerminationProperty.setValue(String.valueOf( cartridgeInfoBean.isRemoveOnTermination()));
+//
+// properties.setProperties(new Property[]{persistanceRequiredProperty,sizeProperty, deviceProperty, deleteOnTerminationProperty});
+// }
+//
+//
+// // If multitenant, return for now. TODO -- fix properly
+// if(cartridgeInfo != null && cartridgeInfo.getMultiTenant()) {
+// log.info(" ******* MT cartridge ******* ");
+//
+// subscriptionData.setPrivateRepository(false);
+// subscriptionData.setLbClusterId(null);
+// subscriptionData.setProperties(null);
+//
+// CartridgeSubscription cartridgeSubscription =
+// cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(subscriptionData);
+// log.info(" --- ** -- ");
+// return cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription, properties);
+//
+// }
+//
+// List<Property> lbRefProp = new ArrayList<Property>();
+//
+// // get lb config reference
+// LoadbalancerConfig lbConfig = cartridgeInfo.getLbConfig();
+// String lbClusterId = null;
+//
+// if (lbConfig == null || lbConfig.getProperties() == null) {
+// if (log.isDebugEnabled()) {
+// log.debug("This Service does not require a load balancer. " + "[Service Name] " +
+// cartridgeType);
+// }
+// } else {
+//
+// Properties lbReferenceProperties = lbConfig.getProperties();
+//
+// Property property = new Property();
+// property.setName(org.apache.stratos.messaging.util.Constants.LOAD_BALANCER_REF);
+//
+//
+// for (org.apache.stratos.cloud.controller.pojo.Property prop : lbReferenceProperties.getProperties()) {
+//
+// String name = prop.getName();
+// String value = prop.getValue();
+//
+// // TODO make following a chain of responsibility pattern
+// if (Constants.NO_LOAD_BALANCER.equals(name)) {
+// if ("true".equals(value)) {
+// if (log.isDebugEnabled()) {
+// log.debug("This cartridge does not require a load balancer. " +
+// "[Type] " + cartridgeType);
+// }
+// property.setValue(name);
+// lbRefProp.add(property);
+// break;
+// }
+// } else if (Constants.EXISTING_LOAD_BALANCERS.equals(name)) {
+// String clusterIdsVal = value;
+// if (log.isDebugEnabled()) {
+// log.debug("This cartridge refers to existing load balancers. " + "[Type] " +
+// cartridgeType + "[Referenced Cluster Ids] " + clusterIdsVal);
+// }
+//
+// String[] clusterIds = clusterIdsVal.split(",");
+//
+// for (String clusterId : clusterIds) {
+// if (autoscalerServiceClient != null) {
+// try {
+// autoscalerServiceClient.checkLBExistenceAgainstPolicy(clusterId,
+// deploymentPolicy);
+// } catch (Exception ex) {
+// // we don't need to throw the error here.
+// log.error(ex.getMessage(), ex);
+// }
+// }
+// }
+//
+// property.setValue(name);
+// lbRefProp.add(property);
+// break;
+//
+// } else if (Constants.DEFAULT_LOAD_BALANCER.equals(name)) {
+//
+// if ("true".equals(value)) {
+//
+// CartridgeInfo lbCartridgeInfo = null;
+// String lbCartridgeType = lbConfig.getType();
+// try {
+// // retrieve lb Cartridge info
+// if(lbCartridgeType != null) {
+// lbCartridgeInfo = cloudControllerServiceClient.getCartridgeInfo(lbCartridgeType);
+// }
+// } catch (Exception e) {
+// String msg = "Cannot get cartridge info: " + cartridgeType;
+// log.error(msg, e);
+// throw new ADCException(msg, e);
+// }
+//
+// property.setValue(name);
+// if (log.isDebugEnabled()) {
+// log.debug("This cartridge uses default load balancer. " + "[Type] " +
+// cartridgeType);
+// }
+// if (autoscalerServiceClient != null) {
+// try {
+// // get the valid policies for lb cartridge
+// DeploymentPolicy[] lbCartridgeDepPolicies =
+// autoscalerServiceClient.getDeploymentPolicies(lbCartridgeType);
+// // traverse deployment policies of lb cartridge
+// for (DeploymentPolicy policy : lbCartridgeDepPolicies) {
+// // check existence of the subscribed policy
+// if (deploymentPolicy.equals(policy.getId())) {
+//
+// if (!autoscalerServiceClient.checkDefaultLBExistenceAgainstPolicy(deploymentPolicy)) {
+//
+// // if lb cluster doesn't exist
+// String lbAlias = "lb" + new Random().nextInt();
+// if(lbCartridgeInfo != null) {
+// lbCartridgeInfo.addProperties(property);
+// lbClusterId = subscribeToLb(lbCartridgeType, cartridgeType,
+// lbAlias,
+// lbCartridgeInfo.getDefaultAutoscalingPolicy(),
+// deploymentPolicy, configurationContext,
+// tenantUsername, tenantDomain,
+// lbCartridgeInfo.getProperties());
+// } else {
+// String msg = "Please specify a LB cartridge type for the cartridge: "
+// + cartridgeType + " as category: " +
+// Constants.DEFAULT_LOAD_BALANCER;
+// log.error(msg);
+// throw new ADCException(msg);
+// }
+// }
+// }
+// }
+//
+// } catch (Exception ex) {
+// // we don't need to throw the error here.
+// log.error(ex.getMessage(), ex);
+// }
+// }
+//
+// lbRefProp.add(property);
+// break;
+// }
+//
+// } else if (Constants.SERVICE_AWARE_LOAD_BALANCER.equals(name)) {
+//
+// if ("true".equals(value)) {
+//
+// CartridgeInfo lbCartridgeInfo = null;
+// String lbCartridgeType = lbConfig.getType();
+// try {
+// // retrieve lb Cartridge info
+// if(lbCartridgeType != null) {
+// lbCartridgeInfo = cloudControllerServiceClient.getCartridgeInfo(lbCartridgeType);
+// }
+// } catch (Exception e) {
+// String msg = "Cannot get cartridge info: " + cartridgeType;
+// log.error(msg, e);
+// throw new ADCException(msg, e);
+// }
+//
+// // add a property for the service type
+// Property loadBalancedServiceTypeProperty = new Property();
+// loadBalancedServiceTypeProperty.setName(Constants.LOAD_BALANCED_SERVICE_TYPE);
+//
+// property.setValue(name);
+// // set the load balanced service type
+// loadBalancedServiceTypeProperty.setValue(cartridgeType);
+// if (log.isDebugEnabled()) {
+// log.debug("This cartridge uses a service aware load balancer. " +
+// "[Type] " + cartridgeType);
+// }
+// if (autoscalerServiceClient != null) {
+// try {
+//
+// // get the valid policies for lb cartridge
+// DeploymentPolicy[] lbCartridgeDepPolicies =
+// autoscalerServiceClient.getDeploymentPolicies(lbCartridgeType);
+// // traverse deployment policies of lb cartridge
+// for (DeploymentPolicy policy : lbCartridgeDepPolicies) {
+// // check existence of the subscribed policy
+// if (deploymentPolicy.equals(policy.getId())) {
+//
+// if (!autoscalerServiceClient.checkServiceLBExistenceAgainstPolicy(cartridgeType,
+// deploymentPolicy)) {
+//
+// // if lb cluster doesn't exist
+// String lbAlias =
+// "lb" + cartridgeType +
+// new Random().nextInt();
+//
+// if(lbCartridgeInfo != null) {
+// lbCartridgeInfo.addProperties(property);
+// lbCartridgeInfo.addProperties(loadBalancedServiceTypeProperty);
+//
+// lbClusterId = subscribeToLb(lbCartridgeType, cartridgeType,
+// lbAlias,
+// lbCartridgeInfo.getDefaultAutoscalingPolicy(),
+// deploymentPolicy,
+// configurationContext, tenantUsername,
+// tenantDomain,
+// lbCartridgeInfo.getProperties());
+// } else {
+// String msg = "Please specify a LB cartridge type for the cartridge: "
+// + cartridgeType + " as category: " +
+// Constants.SERVICE_AWARE_LOAD_BALANCER;
+// log.error(msg);
+// throw new ADCException(msg);
+// }
+// }
+// }
+// }
+//
+// } catch (Exception ex) {
+// // we don't need to throw the error here.
+// log.error(ex.getMessage(), ex);
+// }
+// }
+//
+// lbRefProp.add(property);
+// break;
+// }
+// }
+// }
+// }
+//
+// subscriptionData.setPrivateRepository(cartridgeInfoBean.isPrivateRepo());
+// subscriptionData.setLbClusterId(lbClusterId);
+// subscriptionData.setProperties(lbRefProp.toArray(new Property[0]));
+// CartridgeSubscription cartridgeSubscription =
+// cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(subscriptionData);
+//
+//
+// if (dataCartridgeAlias != null && !dataCartridgeAlias.trim().isEmpty()) {
+//
+// /*dataCartridgeAlias = dataCartridgeAlias.trim();
+//
+// CartridgeSubscription connectingCartridgeSubscription = null;
+// try {
+// connectingCartridgeSubscription =
+// cartridgeSubsciptionManager.getCartridgeSubscription(tenantDomain,
+// dataCartridgeAlias);
+//
+// } catch (NotSubscribedException e) {
+// log.error(e.getMessage(), e);
+// }
+// if (connectingCartridgeSubscription != null) {
+// try {
+// cartridgeSubsciptionManager.connectCartridges(tenantDomain,
+// cartridgeSubscription,
+// connectingCartridgeSubscription.getAlias());
+//
+// } catch (NotSubscribedException e) {
+// log.error(e.getMessage(), e);
+//
+// } catch (AxisFault axisFault) {
+// log.error(axisFault.getMessage(), axisFault);
+// }
+// } else {
+// log.error("Failed to connect. No cartridge subscription found for tenant " +
+// ApplicationManagementUtil.getTenantId(configurationContext) +
+// " with alias " + alias);
+// }*/
+// }
+//
+// for (Property lbRefProperty : lbRefProp) {
+// properties.addProperties(lbRefProperty);
+// }
+//
+// SubscriptionInfo registerCartridgeSubscription = cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription, properties);
+//
+// return registerCartridgeSubscription;
}
@@ -1198,50 +1189,50 @@ public class ServiceUtils {
}
// return the cluster id for the lb. This is a temp fix.
- private static String subscribeToLb(String cartridgeType, String loadBalancedCartridgeType, String lbAlias,
- String defaultAutoscalingPolicy, String deploymentPolicy,
- ConfigurationContext configurationContext, String userName, String tenantDomain, Property[] props) throws ADCException {
-
- CartridgeSubscription cartridgeSubscription;
-
- try {
- if(log.isDebugEnabled()) {
- log.debug("Subscribing to a load balancer [cartridge] "+cartridgeType+" [alias] "+lbAlias);
- }
-
- SubscriptionData subscriptionData = new SubscriptionData();
- subscriptionData.setCartridgeType(cartridgeType);
- subscriptionData.setCartridgeAlias(lbAlias.trim());
- subscriptionData.setAutoscalingPolicyName(defaultAutoscalingPolicy);
- subscriptionData.setDeploymentPolicyName(deploymentPolicy);
- subscriptionData.setTenantDomain(tenantDomain);
- subscriptionData.setTenantId(ApplicationManagementUtil.getTenantId(configurationContext));
- subscriptionData.setTenantAdminUsername(userName);
- subscriptionData.setRepositoryType("git");
- //subscriptionData.setProperties(props);
- subscriptionData.setPrivateRepository(false);
-
- cartridgeSubscription =
- cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(subscriptionData);
-
- //set a payload parameter to indicate the load balanced cartridge type
- cartridgeSubscription.getPayloadData().add("LOAD_BALANCED_SERVICE_TYPE", loadBalancedCartridgeType);
-
- Properties lbProperties = new Properties();
- lbProperties.setProperties(props);
- cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription, lbProperties);
-
- if(log.isDebugEnabled()) {
- log.debug("Successfully subscribed to a load balancer [cartridge] "+cartridgeType+" [alias] "+lbAlias);
- }
- } catch (Exception e) {
- String msg = "Error while subscribing to load balancer cartridge [type] "+cartridgeType;
- log.error(msg, e);
- throw new ADCException(msg, e);
- }
-
- return cartridgeSubscription.getClusterDomain();
- }
+// private static String subscribeToLb(String cartridgeType, String loadBalancedCartridgeType, String lbAlias,
+// String defaultAutoscalingPolicy, String deploymentPolicy,
+// ConfigurationContext configurationContext, String userName, String tenantDomain, Property[] props) throws ADCException {
+//
+// CartridgeSubscription cartridgeSubscription;
+//
+// try {
+// if(log.isDebugEnabled()) {
+// log.debug("Subscribing to a load balancer [cartridge] "+cartridgeType+" [alias] "+lbAlias);
+// }
+//
+// SubscriptionData subscriptionData = new SubscriptionData();
+// subscriptionData.setCartridgeType(cartridgeType);
+// subscriptionData.setCartridgeAlias(lbAlias.trim());
+// subscriptionData.setAutoscalingPolicyName(defaultAutoscalingPolicy);
+// subscriptionData.setDeploymentPolicyName(deploymentPolicy);
+// subscriptionData.setTenantDomain(tenantDomain);
+// subscriptionData.setTenantId(ApplicationManagementUtil.getTenantId(configurationContext));
+// subscriptionData.setTenantAdminUsername(userName);
+// subscriptionData.setRepositoryType("git");
+// //subscriptionData.setProperties(props);
+// subscriptionData.setPrivateRepository(false);
+//
+// cartridgeSubscription =
+// cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(subscriptionData);
+//
+// //set a payload parameter to indicate the load balanced cartridge type
+// cartridgeSubscription.getPayloadData().add("LOAD_BALANCED_SERVICE_TYPE", loadBalancedCartridgeType);
+//
+// Properties lbProperties = new Properties();
+// lbProperties.setProperties(props);
+// cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription, lbProperties);
+//
+// if(log.isDebugEnabled()) {
+// log.debug("Successfully subscribed to a load balancer [cartridge] "+cartridgeType+" [alias] "+lbAlias);
+// }
+// } catch (Exception e) {
+// String msg = "Error while subscribing to load balancer cartridge [type] "+cartridgeType;
+// log.error(msg, e);
+// throw new ADCException(msg, e);
+// }
+//
+// return cartridgeSubscription.getClusterDomain();
+// }
static StratosAdminResponse unsubscribe(String alias, String tenantDomain) throws RestAPIException {