Updated Branches:
  refs/heads/master 9ced6550c -> 7a1a99989

committing partition listing through Rest API


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

Branch: refs/heads/master
Commit: 19b1f539243467b3b40f13a4131ea36dac79d46d
Parents: 419a460
Author: Isuru <[email protected]>
Authored: Thu Dec 5 17:51:58 2013 +0530
Committer: Isuru <[email protected]>
Committed: Thu Dec 5 17:51:58 2013 +0530

----------------------------------------------------------------------
 .../org.apache.stratos.rest.endpoint/pom.xml    |  6 +-
 .../bean/autoscaler/partition/Partition.java    | 39 ++++++++++
 .../bean/util/convert/PojoConverter.java        | 25 +++++++
 .../service/client/AutoscalerServiceClient.java | 79 ++++++++++++++++++++
 .../rest/endpoint/services/ServiceUtils.java    | 70 ++++++++++++++++-
 .../rest/endpoint/services/StratosAdmin.java    | 11 +++
 .../pom.xml                                     |  1 +
 7 files changed, 224 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19b1f539/components/org.apache.stratos.rest.endpoint/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/pom.xml 
b/components/org.apache.stratos.rest.endpoint/pom.xml
index 71bb563..0effd27 100644
--- a/components/org.apache.stratos.rest.endpoint/pom.xml
+++ b/components/org.apache.stratos.rest.endpoint/pom.xml
@@ -100,11 +100,11 @@
             <version>4.0.0-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
-        <!--dependency>
+        <dependency>
             <groupId>org.apache.stratos</groupId>
-            
<artifactId>org.apache.stratos.cartridge.mgt.service.stub</artifactId>
+            <artifactId>org.apache.stratos.autoscaler.service.stub</artifactId>
             <version>4.0.0-SNAPSHOT</version>
             <scope>provided</scope>
-        </dependency-->
+        </dependency>
     </dependencies>
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19b1f539/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/autoscaler/partition/Partition.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/autoscaler/partition/Partition.java
 
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/autoscaler/partition/Partition.java
new file mode 100644
index 0000000..b3d832a
--- /dev/null
+++ 
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/autoscaler/partition/Partition.java
@@ -0,0 +1,39 @@
+/*
+ * 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.rest.endpoint.bean.autoscaler.partition;
+
+import org.apache.stratos.rest.endpoint.bean.cartridge.definition.PropertyBean;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.List;
+
+@XmlRootElement
+public class Partition {
+
+    public String id;
+
+    public int partitionMin;
+
+    public int partitionMax;
+
+    public String provider;
+
+    public List<PropertyBean> property;
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19b1f539/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/util/convert/PojoConverter.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/util/convert/PojoConverter.java
 
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/util/convert/PojoConverter.java
new file mode 100644
index 0000000..41e17b9
--- /dev/null
+++ 
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/bean/util/convert/PojoConverter.java
@@ -0,0 +1,25 @@
+/*
+ * 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.rest.endpoint.bean.util.convert;
+
+public class PojoConverter {
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19b1f539/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/service/client/AutoscalerServiceClient.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/service/client/AutoscalerServiceClient.java
 
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/service/client/AutoscalerServiceClient.java
new file mode 100644
index 0000000..8046953
--- /dev/null
+++ 
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/service/client/AutoscalerServiceClient.java
@@ -0,0 +1,79 @@
+/*
+ * 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.rest.endpoint.service.client;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.autoscaler.stub.AutoScalerServiceStub;
+import org.apache.stratos.rest.endpoint.ServiceHolder;
+
+import java.rmi.RemoteException;
+
+public class AutoscalerServiceClient {
+
+    private AutoScalerServiceStub stub;
+
+    private static final Log log = 
LogFactory.getLog(AutoscalerServiceClient.class);
+    private static volatile AutoscalerServiceClient serviceClient;
+    private static final String AUTOSCALER_SERVICE_URL = 
"autoscaler.service.url";
+
+    public AutoscalerServiceClient(String epr) throws AxisFault {
+
+        ConfigurationContext clientConfigContext = 
ServiceHolder.getConfigurationContext().getClientConfigContext();
+        try {
+            stub = new AutoScalerServiceStub(clientConfigContext, epr);
+            
stub._getServiceClient().getOptions().setTimeOutInMilliSeconds(300000);
+
+        } catch (AxisFault axisFault) {
+            String msg = "Failed to initiate AutoscalerService client. " + 
axisFault.getMessage();
+            log.error(msg, axisFault);
+            throw new AxisFault(msg, axisFault);
+        }
+    }
+
+    public static AutoscalerServiceClient getServiceClient() throws AxisFault {
+        if (serviceClient == null) {
+            synchronized (AutoscalerServiceClient.class) {
+                if (serviceClient == null) {
+                    serviceClient = new 
AutoscalerServiceClient(System.getProperty(AUTOSCALER_SERVICE_URL));
+                }
+            }
+        }
+        return serviceClient;
+    }
+
+    public 
org.apache.stratos.cloud.controller.deployment.partition.Partition[] 
getAvailablePartitions ()
+            throws Exception {
+
+        org.apache.stratos.cloud.controller.deployment.partition.Partition[] 
partitions;
+        try {
+             partitions = stub.getAllAvailablePartitions();
+
+        } catch (RemoteException e) {
+            String errorMsg = "Error in getting available partitions";
+            log.error(errorMsg, e);
+            throw new Exception(errorMsg, e);
+        }
+
+        return partitions;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19b1f539/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 3dfb32e..2310255 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
@@ -35,11 +35,13 @@ import org.apache.stratos.adc.mgt.utils.CartridgeConstants;
 import org.apache.stratos.adc.mgt.utils.PersistenceManager;
 import org.apache.stratos.adc.topology.mgt.service.TopologyManagementService;
 import org.apache.stratos.cloud.controller.pojo.*;
+import org.apache.stratos.rest.endpoint.bean.autoscaler.partition.Partition;
 import 
org.apache.stratos.rest.endpoint.bean.cartridge.definition.CartridgeDefinitionBean;
 import 
org.apache.stratos.rest.endpoint.bean.cartridge.definition.IaasProviderBean;
 import 
org.apache.stratos.rest.endpoint.bean.cartridge.definition.PortMappingBean;
 import org.apache.stratos.rest.endpoint.bean.cartridge.definition.PropertyBean;
 import org.apache.stratos.rest.endpoint.exception.RestAPIException;
+import org.apache.stratos.rest.endpoint.service.client.AutoscalerServiceClient;
 import org.wso2.carbon.context.PrivilegedCarbonContext;
 
 import java.util.ArrayList;
@@ -176,6 +178,22 @@ public class ServiceUtils {
         return properties;
     }
 
+    private static List<PropertyBean> getPropertyBeans (Properties properties) 
{
+
+        List<PropertyBean> propertyBeans = null;
+        if(properties.getProperties() != null && 
properties.getProperties().length != 0) {
+            Property [] propertyArr = properties.getProperties();
+            propertyBeans = new ArrayList<PropertyBean>();
+            for (int i = 0; i < propertyArr.length ; i++) {
+                PropertyBean propertyBean = new PropertyBean();
+                propertyBean.name = propertyArr[i].getName();
+                propertyBean.value = propertyArr[i].getValue();
+                propertyBeans.add(propertyBean);
+            }
+        }
+        return propertyBeans;
+    }
+
     static void undeployCartridge (String cartridgeType) throws 
RestAPIException {
 
         CloudControllerServiceClient cloudControllerServiceClient = 
getCloudControllerServiceClient();
@@ -201,17 +219,61 @@ public class ServiceUtils {
         return null;
     }
 
-    /*private static CartridgeMgtServiceClient getCartridgeMgtServiceClient () 
{
+    public static Partition[] getAvailablePartitions () throws 
RestAPIException {
+
+        org.apache.stratos.cloud.controller.deployment.partition.Partition[] 
partitions = null;
+        AutoscalerServiceClient autoscalerServiceClient = 
getAutoscalerServiceClient();
+        if (autoscalerServiceClient != null) {
+            try {
+                partitions = autoscalerServiceClient.getAvailablePartitions();
+
+            } catch (Exception e) {
+                String errorMsg = "Error getting available partitions";
+                log.error(errorMsg, e);
+                throw new RestAPIException(errorMsg, e);
+            }
+        }
+
+        return populatePartitionPojo(partitions);
+    }
+
+    private static AutoscalerServiceClient getAutoscalerServiceClient () {
 
         try {
-            return CartridgeMgtServiceClient.getServiceClient();
+            return AutoscalerServiceClient.getServiceClient();
 
         } catch (AxisFault axisFault) {
-            String errorMsg = "Error in getting CartridgeMgtServiceClient 
instance";
+            String errorMsg = "Error in getting AutoscalerServiceClient 
instance";
             log.error(errorMsg, axisFault);
         }
         return null;
-    }*/
+    }
+
+    private static Partition[] populatePartitionPojo 
(org.apache.stratos.cloud.controller.deployment.partition.Partition[]
+                                                       partitions) {
+
+        Partition [] partitionBeans;
+        if(partitions == null) {
+            partitionBeans = new Partition[0];
+            return partitionBeans;
+        }
+
+        partitionBeans = new Partition[partitions.length];
+        for (int i = 0 ; i < partitions.length ; i++) {
+            Partition partition = new Partition();
+            partition.id = partitions[i].getId();
+            partition.provider = partitions[i].getProvider();
+            partition.partitionMin = partitions[i].getPartitionMin();
+            partition.partitionMax = partitions[i].getPartitionMax();
+            //properties are not added currently, TODO if required
+            //if(partitions[i].getProperties() != null) {
+            //    List<PropertyBean> propertyBeans = 
getPropertyBeans(partitions[i].getProperties());
+            //    partition.property = propertyBeans;
+            //}
+            partitionBeans[i] = partition;
+        }
+        return partitionBeans;
+    }
 
     static List<Cartridge> getAvailableCartridges(String 
cartridgeSearchString, Boolean multiTenant, ConfigurationContext 
configurationContext) throws ADCException {
         List<Cartridge> cartridges = new ArrayList<Cartridge>();

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19b1f539/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 cd82c07..707bd78 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
@@ -31,6 +31,7 @@ import org.apache.stratos.rest.endpoint.ServiceHolder;
 import org.apache.stratos.rest.endpoint.annotation.AuthorizationAction;
 import org.apache.stratos.rest.endpoint.annotation.SuperTenantService;
 import org.apache.stratos.rest.endpoint.bean.CartridgeInfoBean;
+import org.apache.stratos.rest.endpoint.bean.autoscaler.partition.Partition;
 import 
org.apache.stratos.rest.endpoint.bean.cartridge.definition.CartridgeDefinitionBean;
 import org.apache.stratos.rest.endpoint.exception.RestAPIException;
 import org.apache.stratos.tenant.mgt.util.TenantMgtUtil;
@@ -77,6 +78,16 @@ public class StratosAdmin extends AbstractAdmin {
     }
 
     @GET
+    @Path("/partition")
+    @Produces("application/json")
+    @Consumes("application/json")
+    @AuthorizationAction("/permission/protected/manage/monitor/tenants")
+    public Partition[] getPartitions () throws RestAPIException {
+
+        return ServiceUtils.getAvailablePartitions();
+    }
+
+    @GET
     @Path("/cartridge/tenanted/list")
     @Produces("application/json")
     @Consumes("application/json")

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19b1f539/service-stubs/org.apache.stratos.autoscaler.service.stub/pom.xml
----------------------------------------------------------------------
diff --git a/service-stubs/org.apache.stratos.autoscaler.service.stub/pom.xml 
b/service-stubs/org.apache.stratos.autoscaler.service.stub/pom.xml
index 287344e..ff2eb5e 100644
--- a/service-stubs/org.apache.stratos.autoscaler.service.stub/pom.xml
+++ b/service-stubs/org.apache.stratos.autoscaler.service.stub/pom.xml
@@ -87,6 +87,7 @@
                         
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                         <Bundle-Name>${project.artifactId}</Bundle-Name>
                         <Export-Package>
+                           org.apache.stratos.autoscaler.stub.*; 
version=${project.version},
                             org.apache.stratos.autoscaler.deployment.policy.*; 
version=${project.version},
                             org.apache.stratos.autoscaler.policy.model.*; 
version=${project.version},
                             org.apache.stratos.autoscaler.exception.*; 
version=${project.version},

Reply via email to