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/01/10 08:46:20 UTC

git commit: service deployment, undeployment and Rest api support

Updated Branches:
  refs/heads/master e03ac9844 -> a1dbda1ed


service deployment, undeployment and Rest api support


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

Branch: refs/heads/master
Commit: a1dbda1ed0c7f61235b2011597187936a330acb7
Parents: e03ac98
Author: Isuru <is...@wso2.com>
Authored: Fri Jan 10 13:15:33 2014 +0530
Committer: Isuru <is...@wso2.com>
Committed: Fri Jan 10 13:15:33 2014 +0530

----------------------------------------------------------------------
 .../stratos/manager/deploy/service/Service.java | 19 ++++-
 .../service/ServiceDeploymentManager.java       | 79 ++++++++++++++++----
 .../service/multitenant/MultiTenantService.java |  5 --
 .../multitenant/lb/MultiTenantLBService.java    |  5 --
 .../ServiceAlreadyDeployedException.java        | 49 ++++++++++++
 .../rest/endpoint/services/ServiceUtils.java    | 28 ++++++-
 .../rest/endpoint/services/StratosAdmin.java    | 14 +++-
 7 files changed, 169 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a1dbda1e/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 2dc29bc..fdac49f 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
@@ -19,7 +19,10 @@
 
 package org.apache.stratos.manager.deploy.service;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 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;
@@ -33,6 +36,8 @@ import java.io.Serializable;
 
 public abstract class Service implements Serializable {
 
+    private static Log log = LogFactory.getLog(Service.class);
+
     private String type;
     private String autoscalingPolicyName;
     private String deploymentPolicyName;
@@ -89,7 +94,19 @@ public abstract class Service implements Serializable {
         setPayloadData(payloadData);
     }
 
-    public abstract void undeploy (String clusterId) throws ADCException;
+    public void undeploy () throws ADCException {
+
+        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 with domain " + clusterId);
+    }
 
     public String getType() {
         return type;

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a1dbda1e/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 195b0cf..7d3b7fb 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
@@ -28,12 +28,13 @@ 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.lb.MultiTenantLBService;
 import org.apache.stratos.manager.deploy.service.multitenant.MultiTenantService;
+import org.apache.stratos.manager.deploy.service.multitenant.lb.MultiTenantLBService;
 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.manager.CartridgeSubscriptionManager;
-import org.apache.stratos.manager.utils.PersistenceManager;
+import org.apache.stratos.manager.retriever.DataInsertionAndRetrievalManager;
 import org.apache.stratos.messaging.util.Constants;
 
 import java.util.ArrayList;
@@ -42,11 +43,29 @@ import java.util.List;
 public class ServiceDeploymentManager {
 
     private static Log log = LogFactory.getLog(ServiceDeploymentManager.class);
-    private CartridgeSubscriptionManager cartridgeSubsciptionManager = new CartridgeSubscriptionManager();
     
     public Service deployService (String type, String autoscalingPolicyName, String deploymentPolicyName, int tenantId, String tenantRange,
     		String tenantDomain, String userName)
-        throws ADCException, UnregisteredCartridgeException {
+            throws ADCException, UnregisteredCartridgeException, ServiceAlreadyDeployedException {
+
+        //check if already we have a Multitenant service deployed for the same type
+        DataInsertionAndRetrievalManager dataInsertionAndRetrievalManager = new DataInsertionAndRetrievalManager();
+
+        Service deployedService;
+        try {
+            deployedService = dataInsertionAndRetrievalManager.getService(type);
+
+        } catch (PersistenceManagerException e) {
+            String errorMsg = "Error in checking if Service is available is PersistenceManager";
+            log.error(errorMsg, e);
+            throw new ADCException(errorMsg, e);
+        }
+
+        if (deployedService != null) {
+            String errorMsg = "There is an already deployed Service for type " + type;
+            log.error(errorMsg);
+            throw new ServiceAlreadyDeployedException(errorMsg, type);
+        }
 
         //get deployed Cartridge Definition information
         CartridgeInfo cartridgeInfo;
@@ -283,25 +302,57 @@ public class ServiceDeploymentManager {
         service.deploy();
 
         //persist Service
-        try {
+        /*try {
 			PersistenceManager.persistService(service);
 		} catch (Exception e) {
             String message = "Error getting info for " + type;
             log.error(message, e);
             throw new ADCException(message, e);
+        }*/
+
+        try {
+            dataInsertionAndRetrievalManager.persistService(service);
+
+        } catch (PersistenceManagerException e) {
+            String errorMsg = "Error in persisting Service in PersistenceManager";
+            log.error(errorMsg, e);
+            throw new ADCException(errorMsg, e);
         }
+
         return service;
     }
 
-    public void undeployService (String clusterId) {
+    public void undeployService (String type) throws ADCException {
 
-        //TODO:
-    }
-    
-  private void configureLBDeployment() {
-    	
-    	
-    	
+        DataInsertionAndRetrievalManager dataInsertionAndRetrievalManager = new DataInsertionAndRetrievalManager();
+
+        Service service;
+        try {
+            service = dataInsertionAndRetrievalManager.getService(type);
+
+        } catch (PersistenceManagerException e) {
+            String errorMsg = "Error in checking if Service is available is PersistenceManager";
+            log.error(errorMsg, e);
+            throw new ADCException(errorMsg, e);
+        }
+
+        if (service == null) {
+            String errorMsg = "No service found for type " + type;
+            log.error(errorMsg);
+            throw new ADCException(errorMsg);
+        }
+
+        // if service is found, undeploy
+        service.undeploy();
+
+        try {
+            dataInsertionAndRetrievalManager.removeService(type);
+
+        } catch (PersistenceManagerException e) {
+            String errorMsg = "Error in removing Service from PersistenceManager";
+            log.error(errorMsg, e);
+            throw new ADCException(errorMsg, e);
+        }
     }
     
     /*private void subscribeToLb(String cartridgeType, String lbAlias,

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a1dbda1e/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 65cbbb0..8dee8b6 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
@@ -47,9 +47,4 @@ public class MultiTenantService extends Service {
                 getPayloadData().getCompletePayloadData(), getTenantRange(), getHostName(), getAutoscalingPolicyName(),
                 getDeploymentPolicyName(), null);
     }
-
-    @Override
-    public void undeploy(String clusterId) throws ADCException {
-
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a1dbda1e/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 34b140c..07bb6f1 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
@@ -46,9 +46,4 @@ public class MultiTenantLBService extends Service {
                 getPayloadData().getCompletePayloadData(), getTenantRange(), getHostName(), getAutoscalingPolicyName(),
                 getDeploymentPolicyName(), null);
     }
-
-    @Override
-    public void undeploy(String clusterId) throws ADCException {
-        //To change body of implemented methods use File | Settings | File Templates.
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a1dbda1e/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/exception/ServiceAlreadyDeployedException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/exception/ServiceAlreadyDeployedException.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/exception/ServiceAlreadyDeployedException.java
new file mode 100644
index 0000000..1e8fcff
--- /dev/null
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/exception/ServiceAlreadyDeployedException.java
@@ -0,0 +1,49 @@
+/*
+ * 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.exception;
+
+public class ServiceAlreadyDeployedException extends Exception {
+
+    private static final long serialVersionUID = 1L;
+
+    private final String message;
+
+    private final String type;
+
+    public ServiceAlreadyDeployedException (String message, String type, Throwable cause) {
+        super(message, cause);
+        this.message = message;
+        this.type = type;
+    }
+
+    public ServiceAlreadyDeployedException (String message, String type) {
+        super(message);
+        this.message = message;
+        this.type = type;
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    public String getType() {
+        return type;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a1dbda1e/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 c895029..2dcc03d 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
@@ -905,9 +905,17 @@ public class ServiceUtils {
         }
     }
 
-    static void unsubscribe(String alias, String tenantDomain) throws ADCException, NotSubscribedException {
+    static void unsubscribe(String alias, String tenantDomain) throws RestAPIException {
 
-        cartridgeSubsciptionManager.unsubscribeFromCartridge(tenantDomain, alias);
+        try {
+            cartridgeSubsciptionManager.unsubscribeFromCartridge(tenantDomain, alias);
+
+        } catch (ADCException e) {
+            throw new RestAPIException(e);
+
+        } catch (NotSubscribedException e) {
+            throw new RestAPIException(e);
+        }
     }
     
     /**
@@ -920,13 +928,25 @@ public class ServiceUtils {
      * 
      */
     static void deployService (String cartridgeType, String alias, String autoscalingPolicy, String deploymentPolicy, 
-    		String tenantDomain, String tenantUsername, int tenantId, String clusterDomain, String clusterSubdomain, String tenantRange) {
+    		String tenantDomain, String tenantUsername, int tenantId, String clusterDomain, String clusterSubdomain, String tenantRange) throws RestAPIException {
     	log.info("Deploying service..");
     	try {
     		serviceDeploymentManager.deployService(cartridgeType, autoscalingPolicy, deploymentPolicy, tenantId, tenantRange, tenantDomain, tenantUsername);
+
 		} catch (Exception e) {
-			e.printStackTrace();
+			throw new RestAPIException(e);
 		}
     }
 
+    static void undeployService (String serviceType) throws RestAPIException {
+
+        try {
+            serviceDeploymentManager.undeployService(serviceType);
+
+        } catch (Exception e) {
+            throw new RestAPIException(e);
+        }
+
+
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a1dbda1e/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java
index ba7ed9b..dd114cc 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/StratosAdmin.java
@@ -329,7 +329,7 @@ public class StratosAdmin extends AbstractAdmin {
     @Path("/cartridge/unsubscribe")
     @Consumes("application/json")
     @AuthorizationAction("/permission/protected/manage/monitor/tenants")
-    public void unsubscribe(String alias){
+    public void unsubscribe(String alias) throws RestAPIException {
         try {
             ServiceUtils.unsubscribe(alias, getTenantDomain());
         } catch (Exception exception) {
@@ -689,6 +689,18 @@ public class StratosAdmin extends AbstractAdmin {
     		   serviceDefinitionBean.getTenantRange());
     }
 
+    @DELETE
+    @Path("/service/definition/{serviceType}")
+    @Produces("application/json")
+    @Consumes("application/json")
+    @AuthorizationAction("/permission/protected/manage/monitor/tenants")
+    @SuperTenantService(true)
+    public void unDeployService (@PathParam("serviceType") String serviceType)
+            throws RestAPIException {
+
+        ServiceUtils.undeployService(serviceType);
+    }
+
 
     private List<TenantInfoBean> getAllTenants() throws Exception {
         TenantManager tenantManager = ServiceHolder.getTenantManager();