You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2015/05/15 11:06:47 UTC

stratos git commit: Renaming metadata api implementation class to MetadataApi

Repository: stratos
Updated Branches:
  refs/heads/master 84ee5f490 -> 144c0014f


Renaming metadata api implementation class to MetadataApi


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

Branch: refs/heads/master
Commit: 144c0014f1d37815a615137df4e22455d08786c2
Parents: 84ee5f4
Author: Imesh Gunaratne <im...@apache.org>
Authored: Fri May 15 14:36:19 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Fri May 15 14:36:34 2015 +0530

----------------------------------------------------------------------
 .../metadata/service/api/MetadataApi.java       | 259 ++++++++++++++++++
 .../service/services/MetaDataAdmin.java         | 263 -------------------
 .../webapp/metadata/WEB-INF/cxf-servlet.xml     |   2 +-
 3 files changed, 260 insertions(+), 264 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/144c0014/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/api/MetadataApi.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/api/MetadataApi.java b/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/api/MetadataApi.java
new file mode 100644
index 0000000..38002ba
--- /dev/null
+++ b/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/api/MetadataApi.java
@@ -0,0 +1,259 @@
+/*
+ * 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.metadata.service.api;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.metadata.service.definition.Property;
+import org.apache.stratos.metadata.service.exception.RestAPIException;
+import org.apache.stratos.metadata.service.registry.CarbonRegistry;
+import org.apache.stratos.metadata.service.registry.DataStore;
+import org.wso2.carbon.registry.api.RegistryException;
+
+import javax.ws.rs.*;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import java.net.URI;
+import java.util.List;
+
+@Path("/")
+public class MetadataApi {
+    private static Log log = LogFactory.getLog(MetadataApi.class);
+    @Context
+    UriInfo uriInfo;
+    private DataStore registry;
+
+    /**
+     * Meta data admin configuration loading
+     */
+    public MetadataApi() {
+        registry = new CarbonRegistry();
+    }
+
+    @GET
+    @Path("/applications/{application_id}/properties")
+    @Produces("application/json")
+    @Consumes("application/json")
+    public Response getApplicationProperties(@PathParam("application_id") String applicationId)
+            throws RestAPIException {
+
+        List<Property> properties;
+        Property[] propertiesArr = null;
+        try {
+            properties = registry
+                    .getApplicationProperties(applicationId);
+            if (properties != null) {
+                propertiesArr = new Property[properties.size()];
+                propertiesArr = properties.toArray(propertiesArr);
+            }
+        } catch (RegistryException e) {
+            String msg = "Error occurred while getting properties ";
+            log.error(msg, e);
+            throw new RestAPIException(msg, e);
+        }
+
+        Response.ResponseBuilder rb;
+        if (propertiesArr == null) {
+            rb = Response.status(Response.Status.NOT_FOUND);
+        } else {
+            rb = Response.ok().entity(propertiesArr);
+        }
+        return rb.build();
+    }
+
+    @GET
+    @Path("/applications/{application_id}/clusters/{cluster_id}/properties")
+    @Produces("application/json")
+    @Consumes("application/json")
+    public Response getClusterProperties(@PathParam("application_id") String applicationId, @PathParam("cluster_id") String clusterId) throws RestAPIException {
+
+        List<Property> properties;
+        Property[] propertiesArr = null;
+        try {
+            properties = registry
+                    .getClusterProperties(applicationId, clusterId);
+            if (properties != null) {
+                propertiesArr = new Property[properties.size()];
+                propertiesArr = properties.toArray(propertiesArr);
+            }
+        } catch (RegistryException e) {
+            String msg = "Error occurred while getting properties ";
+            log.error(msg, e);
+            throw new RestAPIException(msg, e);
+        }
+
+        Response.ResponseBuilder rb;
+        if (propertiesArr == null) {
+            rb = Response.status(Response.Status.NOT_FOUND);
+        } else {
+            rb = Response.ok().entity(propertiesArr);
+        }
+        return rb.build();
+    }
+
+    @GET
+    @Path("/applications/{application_id}/properties/{property_name}")
+    @Produces("application/json")
+    @Consumes("application/json")
+    public Response getApplicationProperty(@PathParam("application_id") String applicationId,
+                                           @PathParam("property_name") String propertyName)
+            throws RestAPIException {
+        List<Property> properties;
+
+
+        Property property = null;
+        try {
+            properties = registry.getApplicationProperties(applicationId);
+            if (properties == null) {
+                return Response.status(Response.Status.NOT_FOUND).build();
+            }
+            for (Property p : properties) {
+                if (propertyName.equals(p.getKey())) {
+                    property = p;
+                    break;
+                }
+            }
+        } catch (RegistryException e) {
+            String msg = "Error occurred while getting property";
+            log.error(msg, e);
+            throw new RestAPIException(msg, e);
+        }
+
+        Response.ResponseBuilder rb;
+        if (property == null) {
+            rb = Response.status(Response.Status.NOT_FOUND);
+        } else {
+            rb = Response.ok().entity(property);
+        }
+        return rb.build();
+    }
+
+    @GET
+    @Path("/applications/{application_id}/cluster/{cluster_id}/properties/{property_name}")
+    @Produces("application/json")
+    @Consumes("application/json")
+    public Response getClusterProperty(@PathParam("application_id") String applicationId, @PathParam("cluster_id") String clusterId, @PathParam("property_name") String propertyName) throws RestAPIException {
+        List<Property> properties;
+
+        Property property = null;
+        try {
+            properties = registry.getClusterProperties(applicationId, clusterId);
+            if (properties == null) {
+                return Response.status(Response.Status.NOT_FOUND).build();
+            }
+            for (Property p : properties) {
+                if (propertyName.equals(p.getKey())) {
+                    property = p;
+                    break;
+                }
+            }
+        } catch (RegistryException e) {
+            String msg = "Error occurred while getting property";
+            log.error(msg, e);
+            throw new RestAPIException(msg, e);
+        }
+
+        Response.ResponseBuilder rb;
+        if (property == null) {
+            rb = Response.status(Response.Status.NOT_FOUND);
+        } else {
+            rb = Response.ok().entity(property);
+        }
+        return rb.build();
+    }
+
+    @POST
+    @Path("applications/{application_id}/properties")
+    @Produces("application/json")
+    @Consumes("application/json")
+    public Response addPropertyToApplication(@PathParam("application_id") String applicationId,
+                                               Property property)
+            throws RestAPIException {
+        URI url = uriInfo.getAbsolutePathBuilder().path(applicationId).build();
+
+        try {
+            registry.addPropertyToApplication(applicationId, property);
+        } catch (RegistryException e) {
+            String msg = "Error occurred while adding properties ";
+            log.error(msg, e);
+            throw new RestAPIException(msg, e);
+        }
+        return Response.created(url).build();
+    }
+
+    @POST
+    @Path("applications/{application_id}/clusters/{cluster_id}/properties")
+    @Produces("application/json")
+    @Consumes("application/json")
+    public Response addPropertyToCluster(@PathParam("application_id") String applicationId,
+                                         @PathParam("cluster_id") String clusterId, Property property)
+            throws RestAPIException {
+        URI url = uriInfo.getAbsolutePathBuilder().path(applicationId + "/" + clusterId).build();
+
+        try {
+            registry.addPropertyToCluster(applicationId, clusterId, property);
+        } catch (RegistryException e) {
+            String msg = "Error occurred while adding properties ";
+            log.error(msg, e);
+            throw new RestAPIException(msg, e);
+        }
+        return Response.created(url).build();
+    }
+
+    @DELETE
+    @Path("applications/{application_id}/properties")
+    @Produces("application/json")
+    @Consumes("application/json")
+    public Response deleteApplicationProperties(@PathParam("application_id") String applicationId)
+            throws RestAPIException {
+
+        try {
+            boolean deleted = registry.deleteApplication(applicationId);
+            if (!deleted) {
+                log.warn(String.format(
+                        "Either no metadata is associated with given appId %s Or resources could not be deleted",
+                        applicationId));
+            }
+        } catch (RegistryException e) {
+            String msg = "Resource attached with appId could not be deleted";
+            log.error(msg, e);
+            throw new RestAPIException(msg, e);
+        }
+        return Response.ok().build();
+    }
+
+    @DELETE
+    @Path("applications/{application_id}/properties/{property_name}/value/{value}")
+    @Produces("application/json")
+    @Consumes("application/json")
+    public Response deleteApplicationPropertValue(@PathParam("application_id") String applicationId, @PathParam("property_name") String propertyName,
+                                                  @PathParam("value") String propertyValue                      )
+            throws RestAPIException {
+
+        try {
+            registry.removePropertyFromApplication(applicationId, propertyName, propertyValue);
+        } catch (RegistryException e) {
+            String msg = "Resource value deletion failed ";
+            log.error(msg, e);
+            throw new RestAPIException(msg, e);
+        }
+        return Response.ok().build();
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/144c0014/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/services/MetaDataAdmin.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/services/MetaDataAdmin.java b/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/services/MetaDataAdmin.java
deleted file mode 100644
index 6362f3e..0000000
--- a/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/services/MetaDataAdmin.java
+++ /dev/null
@@ -1,263 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.metadata.service.services;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.metadata.service.definition.Property;
-import org.apache.stratos.metadata.service.exception.RestAPIException;
-import org.apache.stratos.metadata.service.registry.CarbonRegistry;
-import org.apache.stratos.metadata.service.registry.DataStore;
-import org.wso2.carbon.registry.api.RegistryException;
-
-import javax.ws.rs.*;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-import java.net.URI;
-import java.util.List;
-
-@Path("/")
-public class MetaDataAdmin {
-    private static Log log = LogFactory.getLog(MetaDataAdmin.class);
-    @Context
-    UriInfo uriInfo;
-    private DataStore registry;
-
-    /**
-     * Meta data admin configuration loading
-     */
-    public MetaDataAdmin() {
-        registry = new CarbonRegistry();
-    }
-
-    @GET
-    @Path("/applications/{application_id}/properties")
-    @Produces("application/json")
-    @Consumes("application/json")
-    public Response getApplicationProperties(@PathParam("application_id") String applicationId)
-            throws RestAPIException {
-
-        List<Property> properties;
-        Property[] propertiesArr = null;
-        try {
-            properties = registry
-                    .getApplicationProperties(applicationId);
-            if (properties != null) {
-                propertiesArr = new Property[properties.size()];
-                propertiesArr = properties.toArray(propertiesArr);
-            }
-        } catch (RegistryException e) {
-            String msg = "Error occurred while getting properties ";
-            log.error(msg, e);
-            throw new RestAPIException(msg, e);
-        }
-
-        Response.ResponseBuilder rb;
-        if (propertiesArr == null) {
-            rb = Response.status(Response.Status.NOT_FOUND);
-        } else {
-            rb = Response.ok().entity(propertiesArr);
-        }
-        return rb.build();
-    }
-
-    @GET
-    @Path("/applications/{application_id}/clusters/{cluster_id}/properties")
-    @Produces("application/json")
-    @Consumes("application/json")
-    public Response getClusterProperties(@PathParam("application_id") String applicationId, @PathParam("cluster_id") String clusterId) throws RestAPIException {
-
-        List<Property> properties;
-        Property[] propertiesArr = null;
-        try {
-            properties = registry
-                    .getClusterProperties(applicationId, clusterId);
-            if (properties != null) {
-                propertiesArr = new Property[properties.size()];
-                propertiesArr = properties.toArray(propertiesArr);
-            }
-        } catch (RegistryException e) {
-            String msg = "Error occurred while getting properties ";
-            log.error(msg, e);
-            throw new RestAPIException(msg, e);
-        }
-
-        Response.ResponseBuilder rb;
-        if (propertiesArr == null) {
-            rb = Response.status(Response.Status.NOT_FOUND);
-        } else {
-            rb = Response.ok().entity(propertiesArr);
-        }
-        return rb.build();
-    }
-
-    @GET
-    @Path("/applications/{application_id}/properties/{property_name}")
-    @Produces("application/json")
-    @Consumes("application/json")
-    public Response getApplicationProperty(@PathParam("application_id") String applicationId,
-                                           @PathParam("property_name") String propertyName)
-            throws RestAPIException {
-        List<Property> properties;
-
-
-        Property property = null;
-        try {
-            properties = registry.getApplicationProperties(applicationId);
-            if (properties == null) {
-                return Response.status(Response.Status.NOT_FOUND).build();
-            }
-            for (Property p : properties) {
-                if (propertyName.equals(p.getKey())) {
-                    property = p;
-                    break;
-                }
-            }
-        } catch (RegistryException e) {
-            String msg = "Error occurred while getting property";
-            log.error(msg, e);
-            throw new RestAPIException(msg, e);
-        }
-
-        Response.ResponseBuilder rb;
-        if (property == null) {
-            rb = Response.status(Response.Status.NOT_FOUND);
-        } else {
-            rb = Response.ok().entity(property);
-        }
-        return rb.build();
-    }
-
-    @GET
-    @Path("/applications/{application_id}/cluster/{cluster_id}/properties/{property_name}")
-    @Produces("application/json")
-    @Consumes("application/json")
-    public Response getClusterProperty(@PathParam("application_id") String applicationId, @PathParam("cluster_id") String clusterId, @PathParam("property_name") String propertyName) throws RestAPIException {
-        List<Property> properties;
-
-        Property property = null;
-        try {
-            properties = registry.getClusterProperties(applicationId, clusterId);
-            if (properties == null) {
-                return Response.status(Response.Status.NOT_FOUND).build();
-            }
-            for (Property p : properties) {
-                if (propertyName.equals(p.getKey())) {
-                    property = p;
-                    break;
-                }
-            }
-        } catch (RegistryException e) {
-            String msg = "Error occurred while getting property";
-            log.error(msg, e);
-            throw new RestAPIException(msg, e);
-        }
-
-        Response.ResponseBuilder rb;
-        if (property == null) {
-            rb = Response.status(Response.Status.NOT_FOUND);
-        } else {
-            rb = Response.ok().entity(property);
-        }
-        return rb.build();
-    }
-
-    @POST
-    @Path("applications/{application_id}/properties")
-    @Produces("application/json")
-    @Consumes("application/json")
-    public Response addPropertyToApplication(@PathParam("application_id") String applicationId,
-                                               Property property)
-            throws RestAPIException {
-        URI url = uriInfo.getAbsolutePathBuilder().path(applicationId).build();
-
-        try {
-            registry.addPropertyToApplication(applicationId, property);
-        } catch (RegistryException e) {
-            String msg = "Error occurred while adding properties ";
-            log.error(msg, e);
-            throw new RestAPIException(msg, e);
-        }
-        return Response.created(url).build();
-    }
-
-    @POST
-    @Path("applications/{application_id}/clusters/{cluster_id}/properties")
-    @Produces("application/json")
-    @Consumes("application/json")
-    public Response addPropertyToCluster(@PathParam("application_id") String applicationId,
-                                         @PathParam("cluster_id") String clusterId, Property property)
-            throws RestAPIException {
-        URI url = uriInfo.getAbsolutePathBuilder().path(applicationId + "/" + clusterId).build();
-
-        try {
-            registry.addPropertyToCluster(applicationId, clusterId, property);
-        } catch (RegistryException e) {
-            String msg = "Error occurred while adding properties ";
-            log.error(msg, e);
-            throw new RestAPIException(msg, e);
-        }
-
-        return Response.created(url).build();
-    }
-
-    @DELETE
-    @Path("applications/{application_id}/properties")
-    @Produces("application/json")
-    @Consumes("application/json")
-    public Response deleteApplicationProperties(@PathParam("application_id") String applicationId)
-            throws RestAPIException {
-
-        try {
-            boolean deleted = registry.deleteApplication(applicationId);
-            if (!deleted) {
-                log.warn(String.format(
-                        "Either no metadata is associated with given appId %s Or resources could not be deleted",
-                        applicationId));
-            }
-        } catch (RegistryException e) {
-            String msg = "Resource attached with appId could not be deleted";
-            log.error(msg, e);
-            throw new RestAPIException(msg, e);
-        }
-
-        return Response.ok().build();
-    }
-
-    @DELETE
-    @Path("applications/{application_id}/properties/{property_name}/value/{value}")
-    @Produces("application/json")
-    @Consumes("application/json")
-    public Response deleteApplicationPropertValue(@PathParam("application_id") String applicationId, @PathParam("property_name") String propertyName,
-                                                  @PathParam("value") String propertyValue                      )
-            throws RestAPIException {
-
-        try {
-            registry.removePropertyFromApplication(applicationId, propertyName, propertyValue);
-        } catch (RegistryException e) {
-            String msg = "Resource value deletion failed ";
-            log.error(msg, e);
-            throw new RestAPIException(msg, e);
-        }
-
-        return Response.ok().build();
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/144c0014/components/org.apache.stratos.metadata.service/src/main/webapp/metadata/WEB-INF/cxf-servlet.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.metadata.service/src/main/webapp/metadata/WEB-INF/cxf-servlet.xml b/components/org.apache.stratos.metadata.service/src/main/webapp/metadata/WEB-INF/cxf-servlet.xml
index 62bfe5c..3a2363a 100644
--- a/components/org.apache.stratos.metadata.service/src/main/webapp/metadata/WEB-INF/cxf-servlet.xml
+++ b/components/org.apache.stratos.metadata.service/src/main/webapp/metadata/WEB-INF/cxf-servlet.xml
@@ -39,7 +39,7 @@
         </jaxrs:providers>
     </jaxrs:server>
 
-    <bean id="stratosRestEndpointBean" class="org.apache.stratos.metadata.service.services.MetaDataAdmin"/>
+    <bean id="stratosRestEndpointBean" class="org.apache.stratos.metadata.service.api.MetadataApi"/>
     <bean id="exceptionHandler" class="org.apache.stratos.metadata.service.handlers.CustomExceptionMapper"/>
     <bean id="genericExceptionHandler" class="org.apache.stratos.metadata.service.handlers.GenericExceptionMapper"/>
     <bean id="throwableExceptionHandler"