stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From im...@apache.org
Subject [2/2] git commit: Adding update autoscaling/deployment policy methods to the REST API
Date Fri, 24 Oct 2014 13:49:35 GMT
Adding update autoscaling/deployment policy methods to the REST API


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

Branch: refs/heads/master
Commit: 62c7056788d4fde8eb22683038ba58e7c21652e2
Parents: db94b09
Author: Imesh Gunaratne <imesh@apache.org>
Authored: Fri Oct 24 19:19:23 2014 +0530
Committer: Imesh Gunaratne <imesh@apache.org>
Committed: Fri Oct 24 19:19:23 2014 +0530

----------------------------------------------------------------------
 .../manager/client/AutoscalerServiceClient.java |   12 +
 .../policy/deployment/DeploymentPolicy.java     |   50 +-
 .../bean/util/converter/PojoConverter.java      |   18 +-
 .../stratos/rest/endpoint/mock/MockContext.java |   14 +-
 .../rest/endpoint/services/ServiceUtils.java    |   57 +-
 .../rest/endpoint/services/StratosAdmin.java    |   30 +-
 .../src/main/resources/AutoScalerService.wsdl   | 1554 ++++++++++--------
 7 files changed, 986 insertions(+), 749 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/62c70567/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/client/AutoscalerServiceClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/client/AutoscalerServiceClient.java
b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/client/AutoscalerServiceClient.java
index cd35075..c1f0df8 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/client/AutoscalerServiceClient.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/client/AutoscalerServiceClient.java
@@ -189,11 +189,23 @@ public class AutoscalerServiceClient {
 
     }
 
+    public boolean updateDeploymentPolicy(DeploymentPolicy deploymentPolicy) throws RemoteException,
+            AutoScalerServiceInvalidPolicyExceptionException {
+
+        return stub.updateDeploymentPolicy(deploymentPolicy);
+
+    }
+
     public boolean deployAutoscalingPolicy(AutoscalePolicy autoScalePolicy) throws RemoteException,
             AutoScalerServiceInvalidPolicyExceptionException {
 
         return stub.addAutoScalingPolicy(autoScalePolicy);
+    }
+
+    public boolean updateAutoscalingPolicy(AutoscalePolicy autoScalePolicy) throws RemoteException,
+            AutoScalerServiceInvalidPolicyExceptionException {
 
+        return stub.updateAutoScalingPolicy(autoScalePolicy);
     }
 
     public boolean deployPartition(Partition partition) throws RemoteException,

http://git-wip-us.apache.org/repos/asf/stratos/blob/62c70567/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/autoscaler/policy/deployment/DeploymentPolicy.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/autoscaler/policy/deployment/DeploymentPolicy.java
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/autoscaler/policy/deployment/DeploymentPolicy.java
index d9bde05..419d295 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/autoscaler/policy/deployment/DeploymentPolicy.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/autoscaler/policy/deployment/DeploymentPolicy.java
@@ -29,15 +29,55 @@ import java.util.List;
 @XmlRootElement
 public class DeploymentPolicy {
 
-    public String id;
+    private String id;
     
-    public String description;
+    private String description;
     
-    public boolean isPublic;
+    private boolean isPublic;
 
     //partition groups
-    public List<PartitionGroup> partitionGroup;
+    private List<PartitionGroup> partitionGroup;
 
     //partitions
-    public List<Partition> partition;
+    private List<Partition> partition;
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public boolean isPublic() {
+        return isPublic;
+    }
+
+    public void setPublic(boolean isPublic) {
+        this.isPublic = isPublic;
+    }
+
+    public List<PartitionGroup> getPartitionGroup() {
+        return partitionGroup;
+    }
+
+    public void setPartitionGroup(List<PartitionGroup> partitionGroup) {
+        this.partitionGroup = partitionGroup;
+    }
+
+    public List<Partition> getPartition() {
+        return partition;
+    }
+
+    public void setPartition(List<Partition> partition) {
+        this.partition = partition;
+    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/62c70567/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/util/converter/PojoConverter.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/util/converter/PojoConverter.java
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/util/converter/PojoConverter.java
index 1f37880..40cc88d 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/util/converter/PojoConverter.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/util/converter/PojoConverter.java
@@ -335,11 +335,11 @@ public class PojoConverter {
         org.apache.stratos.autoscaler.stub.deployment.policy.DeploymentPolicy deploymentPolicy
= new
                 org.apache.stratos.autoscaler.stub.deployment.policy.DeploymentPolicy();
 
-        deploymentPolicy.setId(deploymentPolicyBean.id);
-        deploymentPolicy.setDescription(deploymentPolicyBean.description);
-        deploymentPolicy.setIsPublic(deploymentPolicyBean.isPublic);
-        if(deploymentPolicyBean.partitionGroup != null && !deploymentPolicyBean.partitionGroup.isEmpty())
{
-            deploymentPolicy.setPartitionGroups(convertToCCPartitionGroup(deploymentPolicyBean.partitionGroup));
+        deploymentPolicy.setId(deploymentPolicyBean.getId());
+        deploymentPolicy.setDescription(deploymentPolicyBean.getDescription());
+        deploymentPolicy.setIsPublic(deploymentPolicyBean.isPublic());
+        if(deploymentPolicyBean.getPartitionGroup() != null && !deploymentPolicyBean.getPartitionGroup().isEmpty())
{
+            deploymentPolicy.setPartitionGroups(convertToCCPartitionGroup(deploymentPolicyBean.getPartitionGroup()));
         }
 
         return deploymentPolicy;
@@ -606,12 +606,12 @@ public class PojoConverter {
             return deploymentPolicyBean;
         }
 
-        deploymentPolicyBean.id = deploymentPolicy.getId();
-        deploymentPolicyBean.description = deploymentPolicy.getDescription();
-        deploymentPolicyBean.isPublic = deploymentPolicy.getIsPublic();
+        deploymentPolicyBean.setId(deploymentPolicy.getId());
+        deploymentPolicyBean.setDescription(deploymentPolicy.getDescription());
+        deploymentPolicyBean.setPublic(deploymentPolicy.getIsPublic());
 
         if (deploymentPolicy.getPartitionGroups() != null && deploymentPolicy.getPartitionGroups().length
> 0) {
-            deploymentPolicyBean.partitionGroup = Arrays.asList(populatePartitionGroupPojos(deploymentPolicy.getPartitionGroups()));
+            deploymentPolicyBean.setPartitionGroup(Arrays.asList(populatePartitionGroupPojos(deploymentPolicy.getPartitionGroups())));
         }
 
         /*if (deploymentPolicy.getAllPartitions() != null && deploymentPolicy.getAllPartitions().length
> 0) {

http://git-wip-us.apache.org/repos/asf/stratos/blob/62c70567/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/mock/MockContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/mock/MockContext.java
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/mock/MockContext.java
index d8d75cc..648e4cd 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/mock/MockContext.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/mock/MockContext.java
@@ -551,7 +551,7 @@ public class MockContext {
     	int tenantId = getTenantId();
     	Map<String,DeploymentPolicy> policies;
     	
-    	if(!deploymentPolicy.isPublic){
+    	if(!deploymentPolicy.isPublic()){
     		if (deploymentPolicyMap.containsKey(tenantId)){
         		policies = deploymentPolicyMap.get(tenantId);
         	}
@@ -570,7 +570,7 @@ public class MockContext {
     		}
     	}
     	
-    	policies.put(deploymentPolicy.id,deploymentPolicy);
+    	policies.put(deploymentPolicy.getId(),deploymentPolicy);
         StratosAdminResponse stratosAdminResponse = new StratosAdminResponse();
         stratosAdminResponse.setMessage("Successfully deployed deployment policy definition");
         return stratosAdminResponse;
@@ -622,14 +622,14 @@ public class MockContext {
     			if(!(deploymentPolicyMap.get(PUBLIC_DEFINITION)).containsKey(deploymentPolicyId)){
         			throw new RestAPIException(Status.NO_CONTENT,"There is no deployment policy with
id: " + deploymentPolicyId);
         		}
-        		return (deploymentPolicyMap.get(PUBLIC_DEFINITION)).get(deploymentPolicyId).partition.toArray(new
Partition[0]);
+        		return (deploymentPolicyMap.get(PUBLIC_DEFINITION)).get(deploymentPolicyId).getPartition().toArray(new
Partition[0]);
     		}
     	}
         	
     	if(!(deploymentPolicyMap.get(tenantId)).containsKey(deploymentPolicyId)){
     		throw new RestAPIException(Status.NO_CONTENT,"There is no deployment policy with id:
" + deploymentPolicyId);
         }
-    	return (deploymentPolicyMap.get(tenantId)).get(deploymentPolicyId).partition.toArray(new
Partition[0]);
+    	return (deploymentPolicyMap.get(tenantId)).get(deploymentPolicyId).getPartition().toArray(new
Partition[0]);
     }
 
     public PartitionGroup[] getPartitionGroups(String deploymentPolicyId)  throws RestAPIException{
@@ -642,14 +642,14 @@ public class MockContext {
     			if(!(deploymentPolicyMap.get(PUBLIC_DEFINITION)).containsKey(deploymentPolicyId)){
         			throw new RestAPIException(Status.NO_CONTENT,"There is no deployment policy with
id: " + deploymentPolicyId);
         		}
-        		return (deploymentPolicyMap.get(PUBLIC_DEFINITION)).get(deploymentPolicyId).partitionGroup.toArray(new
PartitionGroup[0]);
+        		return (deploymentPolicyMap.get(PUBLIC_DEFINITION)).get(deploymentPolicyId).getPartitionGroup().toArray(new
PartitionGroup[0]);
     		}
     	}
         	
     	if(!(deploymentPolicyMap.get(tenantId)).containsKey(deploymentPolicyId)){
     		throw new RestAPIException(Status.NO_CONTENT,"There is no deployment policy with id:
" + deploymentPolicyId);
         }
-    	return (deploymentPolicyMap.get(tenantId)).get(deploymentPolicyId).partitionGroup.toArray(new
PartitionGroup[0]);
+    	return (deploymentPolicyMap.get(tenantId)).get(deploymentPolicyId).getPartitionGroup().toArray(new
PartitionGroup[0]);
     }
 
     public AutoscalePolicy[] getAutoscalePolicies()  throws RestAPIException{
@@ -811,7 +811,7 @@ public class MockContext {
     	}
         	  	
         Partition[] partitions = null;
-         for(PartitionGroup partitionGroup : deploymentPolicy.partitionGroup){
+         for(PartitionGroup partitionGroup : deploymentPolicy.getPartitionGroup()){
              if(partitionGroup.id.equals(partitionGroupId)){
                  partitions =  partitionGroup.partition.toArray(new Partition[0]);
              }

http://git-wip-us.apache.org/repos/asf/stratos/blob/62c70567/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 14c5331..da0adcc 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
@@ -25,9 +25,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.autoscaler.stub.*;
 import org.apache.stratos.autoscaler.stub.deployment.policy.DeploymentPolicy;
-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.pojo.CartridgeConfig;
 import org.apache.stratos.cloud.controller.stub.pojo.CartridgeInfo;
 import org.apache.stratos.cloud.controller.stub.pojo.Property;
@@ -171,7 +169,7 @@ public class ServiceUtils {
 
     public static void deployAutoscalingPolicy(AutoscalePolicy autoscalePolicyBean) throws
RestAPIException {
 
-        //log.info("***** " + cartridgeDefinitionBean.toString() + " *****");
+        log.info(String.format("Deploying autoscaling policy: %s", autoscalePolicyBean.getDescription()));
 
         AutoscalerServiceClient autoscalerServiceClient = getAutoscalerServiceClient();
         if (autoscalerServiceClient != null) {
@@ -191,7 +189,29 @@ public class ServiceUtils {
                 log.error(message, e);
                 throw new RestAPIException(message, e);
             }
+        }
+    }
+
+    public static void updateAutoscalingPolicy(AutoscalePolicy autoscalePolicyBean) throws
RestAPIException {
+
+        log.info(String.format("Updating autoscaling policy: %s", autoscalePolicyBean.getDescription()));
+
+        AutoscalerServiceClient autoscalerServiceClient = getAutoscalerServiceClient();
+        if (autoscalerServiceClient != null) {
+
+            org.apache.stratos.autoscaler.stub.policy.model.AutoscalePolicy autoscalePolicy
= PojoConverter.
+                    convertToCCAutoscalerPojo(autoscalePolicyBean);
 
+            try {
+                autoscalerServiceClient.updateAutoscalingPolicy(autoscalePolicy);
+            } catch (RemoteException e) {
+                log.error(e.getMessage(), e);
+                throw new RestAPIException(e.getMessage(), e);
+            } catch (AutoScalerServiceInvalidPolicyExceptionException e) {
+                String message = e.getFaultMessage().getInvalidPolicyException().getMessage();
+                log.error(message, e);
+                throw new RestAPIException(message, e);
+            }
         }
     }
 
@@ -199,7 +219,7 @@ public class ServiceUtils {
             org.apache.stratos.rest.endpoint.bean.autoscaler.policy.deployment.DeploymentPolicy
deploymentPolicyBean)
             throws RestAPIException {
 
-        //log.info("***** " + cartridgeDefinitionBean.toString() + " *****");
+        log.info(String.format("Deploying deployment policy: %s", deploymentPolicyBean.getDescription()));
 
         AutoscalerServiceClient autoscalerServiceClient = getAutoscalerServiceClient();
         if (autoscalerServiceClient != null) {
@@ -208,8 +228,7 @@ public class ServiceUtils {
                     PojoConverter.convetToCCDeploymentPolicyPojo(deploymentPolicyBean);
 
             try {
-                autoscalerServiceClient
-                        .deployDeploymentPolicy(deploymentPolicy);
+                autoscalerServiceClient.deployDeploymentPolicy(deploymentPolicy);
             } catch (RemoteException e) {
                 log.error(e.getMessage(), e);
                 throw new RestAPIException(e.getMessage(), e);
@@ -222,6 +241,32 @@ public class ServiceUtils {
         }
     }
 
+    public static void updateDeploymentPolicy(
+            org.apache.stratos.rest.endpoint.bean.autoscaler.policy.deployment.DeploymentPolicy
deploymentPolicyBean)
+            throws RestAPIException {
+
+        log.info(String.format("Updating deployment policy: %s", deploymentPolicyBean.getDescription()));
+
+        AutoscalerServiceClient autoscalerServiceClient = getAutoscalerServiceClient();
+        if (autoscalerServiceClient != null) {
+
+            org.apache.stratos.autoscaler.stub.deployment.policy.DeploymentPolicy deploymentPolicy
=
+                    PojoConverter.convetToCCDeploymentPolicyPojo(deploymentPolicyBean);
+
+
+            try {
+                autoscalerServiceClient.updateDeploymentPolicy(deploymentPolicy);
+            } catch (RemoteException e) {
+                log.error(e.getMessage(), e);
+                throw new RestAPIException(e.getMessage(), e);
+            } catch (AutoScalerServiceInvalidPolicyExceptionException e) {
+                String message = e.getFaultMessage().getInvalidPolicyException().getMessage();
+                log.error(message, e);
+                throw new RestAPIException(message, e);
+            }
+        }
+    }
+
     private static CloudControllerServiceClient getCloudControllerServiceClient() throws
RestAPIException {
 
         try {

http://git-wip-us.apache.org/repos/asf/stratos/blob/62c70567/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 bb9c1a3..2157b58 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
@@ -30,7 +30,6 @@ import org.apache.stratos.manager.dto.SubscriptionInfo;
 import org.apache.stratos.manager.exception.DomainMappingExistsException;
 import org.apache.stratos.manager.exception.ServiceDoesNotExistException;
 import org.apache.stratos.manager.subscription.CartridgeSubscription;
-import org.apache.stratos.manager.subscription.SubscriptionDomain;
 import org.apache.stratos.manager.user.mgt.StratosUserManager;
 import org.apache.stratos.manager.user.mgt.beans.UserInfoBean;
 import org.apache.stratos.manager.user.mgt.exception.UserManagerException;
@@ -50,7 +49,6 @@ import org.apache.stratos.rest.endpoint.bean.kubernetes.KubernetesGroup;
 import org.apache.stratos.rest.endpoint.bean.kubernetes.KubernetesHost;
 import org.apache.stratos.rest.endpoint.bean.kubernetes.KubernetesMaster;
 import org.apache.stratos.rest.endpoint.bean.repositoryNotificationInfoBean.Payload;
-import org.apache.stratos.rest.endpoint.bean.repositoryNotificationInfoBean.Repository;
 import org.apache.stratos.rest.endpoint.bean.subscription.domain.SubscriptionDomainBean;
 import org.apache.stratos.rest.endpoint.bean.topology.Cluster;
 import org.apache.stratos.rest.endpoint.exception.RestAPIException;
@@ -179,6 +177,19 @@ public class StratosAdmin extends AbstractAdmin {
         return Response.created(url).build();
     }
 
+    @PUT
+    @Path("/policy/autoscale")
+    @Produces("application/json")
+    @Consumes("application/json")
+    @AuthorizationAction("/permission/admin/manage/add/autoscalingPolicy")
+    public Response updateAutoscalingPolicyDefintion(AutoscalePolicy autoscalePolicy)
+            throws RestAPIException {
+
+        ServiceUtils.updateAutoscalingPolicy(autoscalePolicy);
+        URI url = uriInfo.getAbsolutePathBuilder().path(autoscalePolicy.getId()).build();
+        return Response.ok(url).build();
+    }
+
     @POST
     @Path("/policy/deployment")
     @Produces("application/json")
@@ -188,10 +199,23 @@ public class StratosAdmin extends AbstractAdmin {
             throws RestAPIException {
 
         ServiceUtils.deployDeploymentPolicy(deploymentPolicy);
-        URI url = uriInfo.getAbsolutePathBuilder().path(deploymentPolicy.id).build();
+        URI url = uriInfo.getAbsolutePathBuilder().path(deploymentPolicy.getId()).build();
         return Response.created(url).build();
     }
 
+    @PUT
+    @Path("/policy/deployment")
+    @Produces("application/json")
+    @Consumes("application/json")
+    @AuthorizationAction("/permission/admin/manage/add/deploymentPolicy")
+    public Response updateDeploymentPolicyDefinition(DeploymentPolicy deploymentPolicy)
+            throws RestAPIException {
+
+        ServiceUtils.updateDeploymentPolicy(deploymentPolicy);
+        URI url = uriInfo.getAbsolutePathBuilder().path(deploymentPolicy.getId()).build();
+        return Response.ok(url).build();
+    }
+
     @GET
     @Path("/partition")
     @Produces("application/json")


Mime
View raw message