Repository: stratos
Updated Branches:
  refs/heads/4.0.0-grouping 4b46efe15 -> 4fc28dbba


adding grouping details in metadata service


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

Branch: refs/heads/4.0.0-grouping
Commit: 4fc28dbbaf91d88da54c01478ce9be3deae0cf07
Parents: 4b46efe
Author: Udara Liyanage <[email protected]>
Authored: Mon Sep 22 15:03:18 2014 +0530
Committer: Udara Liyanage <[email protected]>
Committed: Mon Sep 22 15:03:18 2014 +0530

----------------------------------------------------------------------
 .../definition/ApplicationBean.java             |  70 +++++
 .../metadataservice/definition/ClusterBean.java |  59 ++++
 .../metadataservice/definition/NewProperty.java |  68 ++++
 .../registry/CarbonRegistry.java                | 149 ++++++++-
 .../metadataservice/registry/DataStore.java     |  17 +
 .../metadataservice/registry/GRegRegistry.java  |  27 ++
 .../metadataservice/services/MetaDataAdmin.java | 309 ++++++++++++++++++-
 .../WEB-INF/cxf-servlet.xml                     |   1 +
 8 files changed, 694 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/4fc28dbb/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/definition/ApplicationBean.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/definition/ApplicationBean.java
 
b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/definition/ApplicationBean.java
new file mode 100644
index 0000000..8ef1907
--- /dev/null
+++ 
b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/definition/ApplicationBean.java
@@ -0,0 +1,70 @@
+/**
+ * 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.metadataservice.definition;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.ArrayList;
+import java.util.List;
+
+@XmlRootElement(name="application")
+public class ApplicationBean {
+    private String appId;
+    private List<ClusterBean> clusters;
+
+    public ApplicationBean(){
+        this.clusters = new ArrayList<ClusterBean>();
+    }
+
+    public ApplicationBean(String appId){
+        this.appId = appId;
+        this.clusters = new ArrayList<ClusterBean>();
+    }
+
+    public String getAppId() {
+        return appId;
+    }
+
+    public void setAppId(String appId) {
+        this.appId = appId;
+    }
+
+    public List<ClusterBean> getClusters() {
+        return clusters;
+    }
+
+    public ClusterBean getCluster(String clusterId){
+
+        for(ClusterBean clusterBean : clusters){
+            if(clusterBean.getClusterId().equals(clusterId)){
+                return clusterBean;
+            }
+        }
+
+        return null;
+    }
+
+    public void setClusters(List<ClusterBean> clusters) {
+        this.clusters = clusters;
+    }
+
+    public void addCluster(ClusterBean cluster){
+        this.clusters.add(cluster);
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/4fc28dbb/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/definition/ClusterBean.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/definition/ClusterBean.java
 
b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/definition/ClusterBean.java
new file mode 100644
index 0000000..5c5187a
--- /dev/null
+++ 
b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/definition/ClusterBean.java
@@ -0,0 +1,59 @@
+package org.apache.stratos.metadataservice.definition;
+/**
+ * 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.
+ */
+
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.ArrayList;
+import java.util.List;
+
+@XmlRootElement(name="clusters")
+public class ClusterBean {
+
+    private String clusterId;
+    private List<NewProperty> properties;
+
+    public ClusterBean(){
+        this.setProperties(new ArrayList<NewProperty>());
+    }
+
+    public ClusterBean(String id){
+        this.setClusterId(id);
+        this.setProperties(new ArrayList<NewProperty>());
+    }
+
+    public String getClusterId() {
+        return clusterId;
+    }
+
+    public void setClusterId(String clusterId) {
+        this.clusterId = clusterId;
+    }
+
+    public List<NewProperty> getProperties() {
+        return properties;
+    }
+
+    public void setProperties(List<NewProperty> properties) {
+        this.properties = properties;
+    }
+
+    public void addProperty(NewProperty property){
+        this.properties.add(property);
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/4fc28dbb/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/definition/NewProperty.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/definition/NewProperty.java
 
b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/definition/NewProperty.java
new file mode 100644
index 0000000..552d29f
--- /dev/null
+++ 
b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/definition/NewProperty.java
@@ -0,0 +1,68 @@
+/**
+ * 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.metadataservice.definition;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementRef;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+@XmlRootElement(name="properties")
+public class NewProperty implements Serializable{
+
+    private String key;
+    private List<String> values = new ArrayList<String>();
+
+    public NewProperty(){}
+    public NewProperty(String key, String value){
+        this.key=key;
+        this.values.add(value);
+    }
+    
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    public String[] getValues(){
+        String[] values = new String[this.values.size()];
+        values = this.values.toArray(values);
+        return values;
+    }
+
+    public void setValues(String[] values) {
+        this.values.addAll(Arrays.asList(values));
+    }
+
+
+    public void setValues(String value) {
+        this.values.add(value);
+    }
+
+    public void addValue(String value){
+        this.values.add(value);
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/4fc28dbb/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/CarbonRegistry.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/CarbonRegistry.java
 
b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/CarbonRegistry.java
index 71e3b70..94cdc52 100644
--- 
a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/CarbonRegistry.java
+++ 
b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/CarbonRegistry.java
@@ -18,8 +18,7 @@
  */
 package org.apache.stratos.metadataservice.registry;
 
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.core.Context;
@@ -27,10 +26,10 @@ import javax.ws.rs.core.Context;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.metadataservice.definition.CartridgeMetaData;
-import org.apache.stratos.metadataservice.definition.PropertyBean;
+import org.apache.stratos.metadataservice.definition.*;
 import org.wso2.carbon.core.AbstractAdmin;
 import org.wso2.carbon.registry.api.Registry;
+import org.wso2.carbon.registry.api.RegistryException;
 import org.wso2.carbon.registry.api.Resource;
 import org.wso2.carbon.registry.core.Comment;
 import org.wso2.carbon.registry.core.service.RegistryService;
@@ -181,4 +180,146 @@ public class CarbonRegistry extends AbstractAdmin 
implements DataStore {
                return false;
        }
 
+
+
+    public List<NewProperty> getPropertiesOfCluster(String applicationName, 
String clusterId) throws Exception {
+        Registry tempRegistry = getGovernanceUserRegistry();
+        String resourcePath = mainResource + applicationName + "/" + clusterId;
+        if(!tempRegistry.resourceExists(resourcePath)){
+            return null;
+            //throw new RegistryException("Cluster does not exist at " + 
resourcePath);
+        }
+        Resource regResource = tempRegistry.get(resourcePath);
+
+        ArrayList<NewProperty> newProperties = new ArrayList<NewProperty>();
+
+        Properties props = regResource.getProperties();
+        Enumeration<?> x = props.propertyNames();
+        while(x.hasMoreElements())
+        {
+            String key = (String) x.nextElement();
+            List<String>  values = regResource.getPropertyValues(key);
+            NewProperty property = new NewProperty();
+            property.setKey(key);
+            String[] valueArr = new String[values.size()];
+            property.setValues(values.toArray(valueArr));
+
+            newProperties.add(property);
+
+        }
+
+        return newProperties;
+    }
+
+    public void addPropertyToCluster(String applicationId, String clusterId, 
NewProperty property) throws RegistryException {
+        Registry tempRegistry = getGovernanceUserRegistry();
+        String resourcePath = mainResource + applicationId + "/" + clusterId;
+        Resource regResource = createOrGetResourceforCluster(tempRegistry, 
resourcePath);
+
+        regResource.setProperty(property.getKey(), 
Arrays.asList(property.getValues()));
+        tempRegistry.put(regResource.getPath(), regResource);
+
+    }
+
+    @Override
+    public void addPropertiesToCluster(String applicationName, String 
clusterId, NewProperty[] properties) throws Exception {
+        Registry tempRegistry = getGovernanceUserRegistry();
+        String resourcePath = mainResource + applicationName + "/" + clusterId;
+        Resource regResource;
+        regResource = createOrGetResourceforCluster(tempRegistry, 
resourcePath);
+        try {
+            for(NewProperty property : properties){
+                regResource.setProperty(property.getKey(), 
(Arrays.asList(property.getValues())));
+
+            }
+            tempRegistry.put(resourcePath, regResource);
+            if(log.isDebugEnabled()){
+                log.debug("A resource added to: " + resourcePath);
+            }
+
+        } catch (Exception e) {
+            if (log.isErrorEnabled()) {
+                log.error("addCartridgeMetaDataDetails", e);
+            }
+        } finally {
+            // Close the session
+
+        }
+    }
+
+    public void addPropertiesToApplication(String applicationId, NewProperty[] 
properties) throws RegistryException {
+        Registry tempRegistry = getGovernanceUserRegistry();
+        String resourcePath = mainResource + applicationId;
+        Resource regResource = createOrGetResourceforApplication(tempRegistry, 
resourcePath);
+
+        for(NewProperty property : properties){
+            regResource.setProperty(property.getKey(), 
(Arrays.asList(property.getValues())));
+
+        }
+        tempRegistry.put(resourcePath, regResource);
+    }
+
+    public void addPropertyToApplication(String applicationId, NewProperty 
property) throws RegistryException {
+        Registry tempRegistry = getGovernanceUserRegistry();
+        String resourcePath = mainResource + applicationId;
+        Resource regResource = createOrGetResourceforApplication(tempRegistry, 
resourcePath);
+        regResource.setProperty(property.getKey(), 
(Arrays.asList(property.getValues())));
+    }
+
+    public List<NewProperty> getPropertiesOfApplication(String applicationId) 
throws RegistryException {
+        Registry tempRegistry = getGovernanceUserRegistry();
+        String resourcePath = mainResource + applicationId;
+        if(!tempRegistry.resourceExists(resourcePath)){
+            return null;
+            //throw new RegistryException("Cluster does not exist at " + 
resourcePath);
+        }
+        Resource regResource = tempRegistry.get(resourcePath);
+
+        ArrayList<NewProperty> newProperties = new ArrayList<NewProperty>();
+
+        Properties props = regResource.getProperties();
+        Enumeration<?> x = props.propertyNames();
+        while(x.hasMoreElements())
+        {
+            String key = (String) x.nextElement();
+            List<String>  values = regResource.getPropertyValues(key);
+            NewProperty property = new NewProperty();
+            property.setKey(key);
+            String[] valueArr = new String[values.size()];
+            property.setValues(values.toArray(valueArr));
+
+            newProperties.add(property);
+
+        }
+        if(newProperties.size() == 0){
+            return null;
+        }
+        return newProperties;
+    }
+
+
+    private Resource createOrGetResourceforApplication(Registry tempRegistry, 
String resourcePath) throws RegistryException {
+        Resource regResource;
+        if(tempRegistry.resourceExists(resourcePath)) {
+            regResource = tempRegistry.get(resourcePath);
+        }else{
+            regResource = tempRegistry.newCollection();
+        }
+        return regResource;
+    }
+
+    private Resource createOrGetResourceforCluster(Registry tempRegistry, 
String resourcePath) throws RegistryException {
+
+        int index = resourcePath.lastIndexOf('/');
+        String applicationResourcePath = resourcePath.substring(0,index);
+        createOrGetResourceforApplication(tempRegistry, 
applicationResourcePath);
+        Resource regResource;
+        if(tempRegistry.resourceExists(resourcePath)) {
+            regResource = tempRegistry.get(resourcePath);
+        }else{
+            regResource = tempRegistry.newResource();
+        }
+        return regResource;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/4fc28dbb/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/DataStore.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/DataStore.java
 
b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/DataStore.java
index 93302b7..51cb587 100644
--- 
a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/DataStore.java
+++ 
b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/DataStore.java
@@ -18,7 +18,12 @@
  */
 package org.apache.stratos.metadataservice.registry;
 
+import org.apache.stratos.metadataservice.definition.ApplicationBean;
 import org.apache.stratos.metadataservice.definition.CartridgeMetaData;
+import org.apache.stratos.metadataservice.definition.NewProperty;
+import org.wso2.carbon.registry.api.RegistryException;
+
+import java.util.List;
 
 /*
  * Interface of the Data Store
@@ -33,4 +38,16 @@ public interface DataStore {
        public boolean removeCartridgeMetaDataDetails(String applicationName, 
String cartridgeType)
                                                                                
                   throws Exception;
 
+    public void addPropertiesToCluster(String applicationName, String 
clusterId, NewProperty[] properties)
+            throws Exception;
+    public List<NewProperty> getPropertiesOfCluster(String applicationName, 
String clusterId)
+            throws Exception;
+
+    public void addPropertyToCluster(String applicationId, String clusterId, 
NewProperty property) throws RegistryException;
+
+    void addPropertiesToApplication(String applicationId, NewProperty[] 
properties) throws RegistryException;
+
+    void addPropertyToApplication(String applicationId, NewProperty property) 
throws RegistryException;
+
+    List<NewProperty> getPropertiesOfApplication(String applicationId) throws 
RegistryException;
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/4fc28dbb/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/GRegRegistry.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/GRegRegistry.java
 
b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/GRegRegistry.java
index 3829303..ec464c8 100644
--- 
a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/GRegRegistry.java
+++ 
b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/registry/GRegRegistry.java
@@ -30,10 +30,13 @@ import org.apache.axis2.context.ConfigurationContextFactory;
 import org.apache.commons.configuration.XMLConfiguration;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.metadataservice.definition.ApplicationBean;
 import org.apache.stratos.metadataservice.definition.CartridgeMetaData;
+import org.apache.stratos.metadataservice.definition.NewProperty;
 import org.apache.stratos.metadataservice.definition.PropertyBean;
 import org.apache.stratos.metadataservice.util.ConfUtil;
 import org.wso2.carbon.registry.api.Registry;
+import org.wso2.carbon.registry.api.RegistryException;
 import org.wso2.carbon.registry.api.Resource;
 import org.wso2.carbon.registry.core.Comment;
 import org.wso2.carbon.registry.ws.client.registry.WSRegistryServiceClient;
@@ -219,4 +222,28 @@ public class GRegRegistry implements DataStore {
                return false;
        }
 
+    public void addPropertiesToCluster(String applicationName, String 
clusterId, NewProperty[] properties) throws Exception {
+
+    }
+
+    public List<NewProperty> getPropertiesOfCluster(String applicationName, 
String clusterId) throws Exception {
+        return null;
+    }
+
+    public void addPropertyToCluster(String applicationId, String clusterId, 
NewProperty property) throws RegistryException {
+        
+    }
+
+    public void addPropertiesToApplication(String applicationId, NewProperty[] 
properties) throws RegistryException {
+
+    }
+
+    public void addPropertyToApplication(String applicationId, NewProperty 
property) {
+
+    }
+
+    public List<NewProperty> getPropertiesOfApplication(String applicationId) 
throws RegistryException {
+        return null;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/4fc28dbb/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/services/MetaDataAdmin.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/services/MetaDataAdmin.java
 
b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/services/MetaDataAdmin.java
index e30ffec..670c01b 100644
--- 
a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/services/MetaDataAdmin.java
+++ 
b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/services/MetaDataAdmin.java
@@ -8,18 +8,30 @@ import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
 
 import org.apache.commons.configuration.XMLConfiguration;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.metadataservice.annotation.AuthorizationAction;
+import org.apache.stratos.metadataservice.definition.ApplicationBean;
 import org.apache.stratos.metadataservice.definition.CartridgeMetaData;
+import org.apache.stratos.metadataservice.definition.ClusterBean;
+import org.apache.stratos.metadataservice.definition.NewProperty;
 import org.apache.stratos.metadataservice.exception.RestAPIException;
 import org.apache.stratos.metadataservice.registry.DataRegistryFactory;
 import org.apache.stratos.metadataservice.util.ConfUtil;
+import org.wso2.carbon.registry.api.RegistryException;
 
-@Path("/metadataservice/")
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+@Path("/")
 public class MetaDataAdmin {
+    @Context
+    UriInfo uriInfo;
 
        private static Log log = LogFactory.getLog(MetaDataAdmin.class);
        @Context
@@ -52,7 +64,7 @@ public class MetaDataAdmin {
                                                     defaultRegType);
                return DataRegistryFactory.getDataRegistryFactory(registryType)
                                          
.addCartridgeMetaDataDetails(applicationName, cartridgeType,
-                                                                      
cartridgeMetaData);
+                                                                         
cartridgeMetaData);
 
        }
 
@@ -84,4 +96,297 @@ public class MetaDataAdmin {
                                          
.removeCartridgeMetaDataDetails(applicationName, cartridgeType);
 
        }
+
+    @GET
+    @Path("/application/{application_id}/cluster/{cluster_id}/properties")
+    @Produces("application/json")
+    @Consumes("application/json")
+    @AuthorizationAction("/permission/protected/manage/monitor/tenants")
+    public Response getClusterProperties(@PathParam("application_id") String 
applicationId, @PathParam("cluster_id") String clusterId){
+        conf = ConfUtil.getInstance(null).getConfiguration();
+
+        String registryType =
+                conf.getString("metadataservice.govenanceregistrytype",
+                        defaultRegType);
+        List<NewProperty> properties = null;
+        NewProperty[] propertiesArr = null;
+        try {
+            properties = 
DataRegistryFactory.getDataRegistryFactory(registryType)
+                    .getPropertiesOfCluster(applicationId, clusterId);
+            if(properties != null) {
+                propertiesArr = new NewProperty[properties.size()];
+                propertiesArr = properties.toArray(propertiesArr);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        Response.ResponseBuilder rb=null;
+        if(propertiesArr == null){
+            rb = Response.status(Response.Status.NOT_FOUND);
+        }else{
+            rb = Response.ok().entity(propertiesArr);
+        }
+        return rb.build();
+    }
+
+    @GET
+    @Path("/application/{application_id}/properties")
+    @Produces("application/json")
+    @Consumes("application/json")
+    @AuthorizationAction("/permission/protected/manage/monitor/tenants")
+    public Response getApplicationProperties(@PathParam("application_id") 
String applicationId){
+        conf = ConfUtil.getInstance(null).getConfiguration();
+
+        String registryType =
+                conf.getString("metadataservice.govenanceregistrytype",
+                        defaultRegType);
+        List<NewProperty> properties = null;
+        NewProperty[] propertiesArr = null;
+        try {
+            properties = 
DataRegistryFactory.getDataRegistryFactory(registryType)
+                    .getPropertiesOfApplication(applicationId);
+            if(properties != null) {
+                propertiesArr = new NewProperty[properties.size()];
+                propertiesArr = properties.toArray(propertiesArr);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        Response.ResponseBuilder rb=null;
+        if(propertiesArr == null){
+            rb = Response.status(Response.Status.NOT_FOUND);
+        }else{
+            rb = Response.ok().entity(propertiesArr);
+        }
+        return rb.build();
+    }
+
+    @GET
+    @Path("/application/{application_id}/property/{property_name}")
+    @Produces("application/json")
+    @Consumes("application/json")
+    @AuthorizationAction("/permission/protected/manage/monitor/tenants")
+    public Response getApplicationProperty(@PathParam("application_id") String 
applicationId, @PathParam("property_name") String propertyName){
+        conf = ConfUtil.getInstance(null).getConfiguration();
+        String registryType =
+                conf.getString("metadataservice.govenanceregistrytype",
+                        defaultRegType);
+        List<NewProperty> properties = null;
+        NewProperty property = null;
+
+        try {
+            properties = 
DataRegistryFactory.getDataRegistryFactory(registryType)
+                    .getPropertiesOfApplication(applicationId);
+            if(properties == null){
+                return Response.status(Response.Status.NOT_FOUND).build();
+            }
+            for(NewProperty p : properties){
+                if(propertyName.equals(p.getKey())){
+                    property = p;
+                    break;
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        Response.ResponseBuilder rb=null;
+        if(property == null){
+            rb = Response.status(Response.Status.NOT_FOUND);
+        }else{
+            rb = Response.ok().entity(property);
+        }
+        return rb.build();
+    }
+
+    @GET
+    
@Path("/application/{application_id}/cluster/{cluster_id}/property/{property_name}")
+    @Produces("application/json")
+    @Consumes("application/json")
+    @AuthorizationAction("/permission/protected/manage/monitor/tenants")
+    public Response getClusterProperty(@PathParam("application_id") String 
applicationId, @PathParam("cluster_id") String clusterId, 
@PathParam("property_name") String propertyName){
+        conf = ConfUtil.getInstance(null).getConfiguration();
+        String registryType =
+                conf.getString("metadataservice.govenanceregistrytype",
+                        defaultRegType);
+        List<NewProperty> properties = null;
+        NewProperty property = null;
+
+        try {
+            properties = 
DataRegistryFactory.getDataRegistryFactory(registryType)
+                    .getPropertiesOfCluster(applicationId, clusterId);
+            for(NewProperty p : properties){
+                if(propertyName.equals(p.getKey())){
+                    property = p;
+                    break;
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        Response.ResponseBuilder rb=null;
+        if(property == null){
+            rb = Response.status(Response.Status.NOT_FOUND);
+        }else{
+            rb = Response.ok().entity(property);
+        }
+        return rb.build();
+    }
+
+    @GET
+    @Path("/application/{application_id}/cluster/{cluster_id}/dependencies")
+    @Produces("application/json")
+    @Consumes("application/json")
+    @AuthorizationAction("/permission/protected/manage/monitor/tenants")
+    public Response getClusterDependencies(@PathParam("application_id") String 
applicationId, @PathParam("cluster_id") String clusterId){
+        conf = ConfUtil.getInstance(null).getConfiguration();
+        String registryType =
+                conf.getString("metadataservice.govenanceregistrytype",
+                        defaultRegType);
+        List<NewProperty> properties = null;
+        NewProperty property = null;
+
+        try {
+            properties = 
DataRegistryFactory.getDataRegistryFactory(registryType)
+                    .getPropertiesOfCluster(applicationId, clusterId);
+            if(properties == null){
+                return Response.status(Response.Status.NOT_FOUND).build();
+            }
+            for(NewProperty p : properties){
+                if("dependencies".equals(p.getKey())){
+                    property = p;
+                    break;
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        Response.ResponseBuilder rb=null;
+        if(property == null){
+            rb = Response.status(Response.Status.NOT_FOUND);
+        }else{
+            rb = Response.ok().entity(property);
+        }
+        return rb.build();
+    }
+
+
+    @POST
+    @Path("/application/{application_id}/cluster/{cluster_id}/dependencies")
+    @Produces("application/json")
+    @Consumes("application/json")
+    @AuthorizationAction("/permission/protected/manage/monitor/tenants")
+    public Response addClusterDependencies(@PathParam("application_id") String 
applicationId, @PathParam("cluster_id") String clusterId,  NewProperty 
property) throws RestAPIException {
+
+        if(!property.getKey().equals("dependencies")){
+            throw new RestAPIException("Property name should be dependencies");
+        }
+        URI url =  uriInfo.getAbsolutePathBuilder().path(applicationId + "/" + 
clusterId + "/" + property.getKey()).build();
+        conf = ConfUtil.getInstance(null).getConfiguration();
+
+        String registryType = 
conf.getString("metadataservice.govenanceregistrytype", defaultRegType);
+        try {
+            
DataRegistryFactory.getDataRegistryFactory(registryType).addPropertyToCluster(applicationId,
 clusterId, property);
+        } catch (RegistryException e) {
+            e.printStackTrace();
+        }
+        return Response.created(url).build();
+    }
+
+    @POST
+    @Path("application/{application_id}/cluster/{cluster_id}/property")
+    @Produces("application/json")
+    @Consumes("applicsetPropertyation/json")
+    @AuthorizationAction("/permission/protected/manage/monitor/tenants")
+    public Response addPropertyToACluster(@PathParam("application_id") String 
applicationId, @PathParam("cluster_id") String clusterId, NewProperty property)
+            throws RestAPIException {
+
+        URI url =  uriInfo.getAbsolutePathBuilder().path(applicationId + "/" + 
clusterId + "/" + property.getKey()).build();
+        conf = ConfUtil.getInstance(null).getConfiguration();
+
+        String registryType = 
conf.getString("metadataservice.govenanceregistrytype", defaultRegType);
+        try {
+            
DataRegistryFactory.getDataRegistryFactory(registryType).addPropertyToCluster(applicationId,
 clusterId, property);
+        } catch (RegistryException e) {
+            e.printStackTrace();
+        }
+
+        return Response.created(url).build();
+
+    }
+
+    @POST
+    @Path("application/{application_id}/cluster/{cluster_id}/properties")
+    @Produces("application/json")
+    @Consumes("application/json")
+    @AuthorizationAction("/permission/protected/manage/monitor/tenants")
+    public Response addPropertiesToACluster(@PathParam("application_id") 
String applicationId, @PathParam("cluster_id") String clusterId, NewProperty[] 
properties)
+            throws RestAPIException {
+        URI url =  uriInfo.getAbsolutePathBuilder().path(applicationId + "/" + 
clusterId).build();
+
+        conf = ConfUtil.getInstance(null).getConfiguration();
+
+        String registryType =
+                conf.getString("metadataservice.govenanceregistrytype",
+                        defaultRegType);
+        try {
+            
DataRegistryFactory.getDataRegistryFactory(registryType).addPropertiesToCluster(applicationId,
 clusterId, properties);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+
+        return Response.created(url).build();
+    }
+
+    @POST
+    @Path("application/{application_id}/properties")
+    @Produces("application/json")
+    @Consumes("application/json")
+    @AuthorizationAction("/permission/protected/manage/monitor/tenants")
+    public Response addPropertiesToApplication(@PathParam("application_id") 
String applicationId,NewProperty[] properties)
+            throws RestAPIException {
+        URI url =  
uriInfo.getAbsolutePathBuilder().path(applicationId).build();
+
+        conf = ConfUtil.getInstance(null).getConfiguration();
+
+        String registryType =
+                conf.getString("metadataservice.govenanceregistrytype",
+                        defaultRegType);
+        try {
+            
DataRegistryFactory.getDataRegistryFactory(registryType).addPropertiesToApplication(applicationId,
 properties);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+
+        return Response.created(url).build();
+    }
+
+    @POST
+    @Path("application/{application_id}/property")
+    @Produces("application/json")
+    @Consumes("application/json")
+    @AuthorizationAction("/permission/protected/manage/monitor/tenants")
+    public Response addPropertyToApplication(@PathParam("application_id") 
String applicationId, NewProperty property)
+            throws RestAPIException {
+        URI url =  
uriInfo.getAbsolutePathBuilder().path(applicationId).build();
+
+        conf = ConfUtil.getInstance(null).getConfiguration();
+
+        String registryType =
+                conf.getString("metadataservice.govenanceregistrytype",
+                        defaultRegType);
+        try {
+            
DataRegistryFactory.getDataRegistryFactory(registryType).addPropertyToApplication(applicationId,
 property);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+
+        return Response.created(url).build();
+    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/4fc28dbb/components/org.apache.stratos.metadataservice/src/main/webapp/stratosmetadataservice/WEB-INF/cxf-servlet.xml
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.metadataservice/src/main/webapp/stratosmetadataservice/WEB-INF/cxf-servlet.xml
 
b/components/org.apache.stratos.metadataservice/src/main/webapp/stratosmetadataservice/WEB-INF/cxf-servlet.xml
index bf40055..e015301 100644
--- 
a/components/org.apache.stratos.metadataservice/src/main/webapp/stratosmetadataservice/WEB-INF/cxf-servlet.xml
+++ 
b/components/org.apache.stratos.metadataservice/src/main/webapp/stratosmetadataservice/WEB-INF/cxf-servlet.xml
@@ -59,6 +59,7 @@
     <bean id="jsonProvider" 
class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
         <property name="supportUnwrapped" value="true"/>
         <property name="serializeAsArray" value="true"/>
+       <property name="dropRootElement" value="true" />
         <property name="arrayKeys">
             <list>
                 <value>partitions</value>

Reply via email to