stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ud...@apache.org
Subject [2/2] git commit: refactor metadata client
Date Thu, 16 Oct 2014 11:26:05 GMT
refactor metadata client


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

Branch: refs/heads/4.0.0-grouping
Commit: 35ef227936d438159571ce27b7dd7612d7a2d65c
Parents: 5f4c859
Author: Udara Liyanage <udara@wso2.com>
Authored: Thu Oct 16 11:54:34 2014 +0530
Committer: Udara Liyanage <udara@wso2.com>
Committed: Thu Oct 16 16:55:34 2014 +0530

----------------------------------------------------------------------
 .../defaults/DefaultMetaDataServiceClient.java  |  14 +--
 .../client/defaults/MetaDataServiceClient.java  |   2 +-
 .../metadataservice/listener/TopologyAgent.java |   2 +-
 .../registry/CarbonRegistry.java                | 121 +-----------------
 .../metadataservice/registry/DataStore.java     |  10 --
 .../metadataservice/registry/GRegRegistry.java  | 122 -------------------
 .../metadataservice/services/MetaDataAdmin.java |  48 --------
 7 files changed, 15 insertions(+), 304 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/35ef2279/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/defaults/DefaultMetaDataServiceClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/defaults/DefaultMetaDataServiceClient.java
b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/defaults/DefaultMetaDataServiceClient.java
index a231789..fbebab9 100644
--- a/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/defaults/DefaultMetaDataServiceClient.java
+++ b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/defaults/DefaultMetaDataServiceClient.java
@@ -42,23 +42,23 @@ public class DefaultMetaDataServiceClient implements MetaDataServiceClient
{
     private final String baseUrl;
     private RestClient restClient;
 
-    public DefaultMetaDataServiceClient() throws RestClientException {
+    public DefaultMetaDataServiceClient() throws MetaDataServiceClientException {
         MetaDataClientConfig metaDataClientConfig = MetaDataClientConfig.getInstance();
         this.baseUrl = metaDataClientConfig.getMetaDataServiceBaseUrl();
         String username = metaDataClientConfig.getUsername();
         String password = metaDataClientConfig.getPassword();
-        this.restClient = new DefaultRestClient(username, password);
+        try {
+            this.restClient = new DefaultRestClient(username, password);
+        } catch (RestClientException e) {
+            throw new MetaDataServiceClientException("Error occurred while creating REST
client ", e);
+        }
     }
 
-    public DefaultMetaDataServiceClient(String baseUrl, RestClient restClient) throws RestClientException
{
+    public DefaultMetaDataServiceClient(String baseUrl, RestClient restClient){
         this.baseUrl = baseUrl;
         this.restClient = restClient;
     }
 
-    public void initialize() {
-        // initialization, if any
-    }
-
     public void addPropertyToCluster(String appId, String clusterId, String propertyKey,
String propertyValue)
             throws MetaDataServiceClientException {
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/35ef2279/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/defaults/MetaDataServiceClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/defaults/MetaDataServiceClient.java
b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/defaults/MetaDataServiceClient.java
index d1a9e25..8fdb9a7 100644
--- a/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/defaults/MetaDataServiceClient.java
+++ b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/defaults/MetaDataServiceClient.java
@@ -26,7 +26,7 @@ public interface MetaDataServiceClient {
     /**
      * Initialize the MetaDataServiceClient. Should be called once before using the MetaDataServiceClient.
      */
-    public void initialize();
+    //public void initialize();
 
     /**
      * Adds a property key value pair for the relevant cluster of the specified app

http://git-wip-us.apache.org/repos/asf/stratos/blob/35ef2279/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/listener/TopologyAgent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/listener/TopologyAgent.java
b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/listener/TopologyAgent.java
index f9afd78..f39594a 100644
--- a/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/listener/TopologyAgent.java
+++ b/components/org.apache.stratos.metadataservice/src/main/java/org/apache/stratos/metadataservice/listener/TopologyAgent.java
@@ -86,7 +86,7 @@ public class TopologyAgent implements Runnable {
 						log.debug("Terminated event :::::::::::::::::::: " +
 					                   memberTerminatedEvent.getServiceName());
 					}
-                    DataRegistryFactory.getDataRegistryFactory(registryType).removeCartridgeMetaDataDetails("appA",
"php");
+                    //DataRegistryFactory.getDataRegistryFactory(registryType).removeCartridgeMetaDataDetails("appA",
"php");
 
 				} catch (Exception e) {
 					if (log.isErrorEnabled()) {

http://git-wip-us.apache.org/repos/asf/stratos/blob/35ef2279/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 e1526aa..e9d590d 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,20 +18,18 @@
  */
 package org.apache.stratos.metadataservice.registry;
 
-import java.util.*;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.core.Context;
-
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.metadataservice.definition.*;
+import org.apache.stratos.metadataservice.definition.NewProperty;
 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 javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Context;
+import java.util.*;
+
 
 /**
  * Carbon registry implementation
@@ -43,7 +41,7 @@ public class CarbonRegistry extends AbstractAdmin implements DataStore {
     @Context
     HttpServletRequest httpServletRequest;
 
-    private static final String mainResource = "/startos/";
+    private static final String mainResource = "/stratos/";
 
 
     public CarbonRegistry() {
@@ -52,117 +50,12 @@ public class CarbonRegistry extends AbstractAdmin implements DataStore
{
 
 
     /**
-     * Add the meta data to governance registry
-     *
-     * @param applicationName Application Name
-     * @param cartridgeType Cartridge Type
-     * @param cartridgeMetaData Cartridge Meta Data
-     * @throws Exception
-     */
-    @Override
-    public void addCartridgeMetaDataDetails(String applicationName, String cartridgeType,
-                                            CartridgeMetaData cartridgeMetaData) throws Exception
{
-        log.debug("Adding meta data details");
-
-        Registry tempRegistry = getGovernanceUserRegistry();
-
-
-        Resource resource = tempRegistry.newResource();
-
-        String type = cartridgeMetaData.type;
-
-        resource.setContent("Application description :: " + type);
-
-        String resourcePath = mainResource + applicationName + "/" + cartridgeType;
-
-        resource.addProperty("Application Name", cartridgeMetaData.applicationName);
-        resource.addProperty("Display Name", cartridgeMetaData.displayName);
-        resource.addProperty("Description", cartridgeMetaData.description);
-        resource.addProperty("Cartidge Type", cartridgeMetaData.type);
-        resource.addProperty("provider", cartridgeMetaData.provider);
-        resource.addProperty("Version", cartridgeMetaData.version);
-        resource.addProperty("Host", cartridgeMetaData.host);
-        resource.addProperty("Properties", cartridgeMetaData.properties);
-
-        tempRegistry.put(resourcePath, resource);
-
-        if (log.isDebugEnabled()) {
-            log.debug("A resource added to: " + resourcePath);
-        }
-
-
-    }
-
-    /**
-     * Get the meta data from the registry
-     *
-     * @param applicationName name of the application
-     * @param cartridgeType cartridge type
-     * @return
-     * @throws Exception
-     */
-    @Override
-    public String getCartridgeMetaDataDetails(String applicationName, String cartridgeType)
-            throws Exception {
-        Registry registry = getGovernanceUserRegistry();
-        CartridgeMetaData cartridgeMetaData = new CartridgeMetaData();
-
-
-        String resourcePath = mainResource + applicationName + "/" + cartridgeType;
-        if (registry.resourceExists(resourcePath)) {
-
-            Resource getResource = registry.get(resourcePath);
-
-            cartridgeMetaData.type = getResource.getProperty("Cartidge Type");
-            cartridgeMetaData.applicationName = getResource.getProperty("Application Name");
-            cartridgeMetaData.description = getResource.getProperty("Description");
-            cartridgeMetaData.displayName = getResource.getProperty("Display Name");
-            cartridgeMetaData.host = getResource.getProperty("host");
-            cartridgeMetaData.provider = getResource.getProperty("provider");
-            cartridgeMetaData.version = getResource.getProperty("Version");
-            cartridgeMetaData.properties = getResource.getProperty("Properties");
-
-
-        }
-
-
-        return cartridgeMetaData.toString();
-    }
-
-
-    /**
-     * Remove the meta data from the registry
-     *
-     * @param applicationName name of the application
-     * @param cartridgeType cartridge type
-     * @return
-     * @throws Exception
-     */
-    @Override
-    public boolean removeCartridgeMetaDataDetails(String applicationName, String cartridgeType)
-            throws Exception {
-        Registry registry = getGovernanceUserRegistry();
-        String resourcePath = mainResource + applicationName + "/" + cartridgeType;
-
-        if (registry != null) {
-            registry.delete(resourcePath);
-            return true;
-        } else {
-            if (log.isDebugEnabled()) {
-                log.debug("Unable to delete the meta data since the Registry is NULL");
-            }
-            return false;
-        }
-    }
-
-    /**
      * Get Properties of clustor
      * @param applicationName
      * @param clusterId
      * @return
      * @throws RegistryException
      */
-    @Override
     public List<NewProperty> getPropertiesOfCluster(String applicationName, String
clusterId) throws RegistryException {
         Registry tempRegistry = getGovernanceUserRegistry();
         String resourcePath = mainResource + applicationName + "/" + clusterId;
@@ -197,7 +90,6 @@ public class CarbonRegistry extends AbstractAdmin implements DataStore
{
      * @param property
      * @throws RegistryException
      */
-    @Override
     public void addPropertyToCluster(String applicationId, String clusterId, NewProperty
property) throws RegistryException {
         Registry tempRegistry = getGovernanceUserRegistry();
         String resourcePath = mainResource + applicationId + "/" + clusterId;
@@ -216,7 +108,6 @@ public class CarbonRegistry extends AbstractAdmin implements DataStore
{
      * @param properties
      * @throws RegistryException
      */
-    @Override
     public void addPropertiesToCluster(String applicationName, String clusterId, NewProperty[]
properties) throws RegistryException {
         Registry tempRegistry = getGovernanceUserRegistry();
         String resourcePath = mainResource + applicationName + "/" + clusterId;

http://git-wip-us.apache.org/repos/asf/stratos/blob/35ef2279/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 ea905a0..0ad8459 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
@@ -19,7 +19,6 @@
 package org.apache.stratos.metadataservice.registry;
 
 
-import org.apache.stratos.metadataservice.definition.CartridgeMetaData;
 import org.apache.stratos.metadataservice.definition.NewProperty;
 import org.wso2.carbon.registry.api.RegistryException;
 
@@ -30,15 +29,6 @@ import java.util.List;
  */
 public interface DataStore {
 
-	public void addCartridgeMetaDataDetails(String applicationName, String cartridgeType,
-	                                          CartridgeMetaData cartridgeMetaData) throws Exception;
-
-	public String getCartridgeMetaDataDetails(String applicationName, String cartridgeType)
-	                                                                                       throws
Exception;
-
-    public boolean removeCartridgeMetaDataDetails(String applicationName, String cartridgeType)
-	                                                                                       
   throws Exception;
-
     public void addPropertiesToCluster(String applicationName, String clusterId, NewProperty[]
properties)
             throws RegistryException;
     public List<NewProperty> getPropertiesOfCluster(String applicationName, String
clusterId)

http://git-wip-us.apache.org/repos/asf/stratos/blob/35ef2279/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 2be8d27..ffe38f1 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
@@ -24,13 +24,9 @@ import org.apache.commons.configuration.XMLConfiguration;
 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.NewProperty;
 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;
 
 import javax.servlet.http.HttpServletRequest;
@@ -94,124 +90,6 @@ public class GRegRegistry implements DataStore {
     }
 
 
-
-    /**
-     * Add the meta data to governance registry
-     * @param applicationName
-     * @param cartridgeType
-     * @param cartridgeMetaData
-     * @throws Exception
-     */
-    @Override
-    public void addCartridgeMetaDataDetails(String applicationName, String cartridgeType,
-                                            CartridgeMetaData cartridgeMetaData) throws Exception
{
-
-        Registry registry = setRegistry();
-        try {
-
-            Resource resource = registry.newResource();
-
-            String type = cartridgeMetaData.type;
-
-            resource.setContent("Application description :: " + type);
-
-            String resourcePath = mainResource + applicationName + "/" + cartridgeType;
-
-            resource.addProperty("Application Name", cartridgeMetaData.applicationName);
-            resource.addProperty("Display Name", cartridgeMetaData.displayName);
-            resource.addProperty("Description", cartridgeMetaData.description);
-            resource.addProperty("Cartidge Type", cartridgeMetaData.type);
-            resource.addProperty("provider", cartridgeMetaData.provider);
-            resource.addProperty("Version", cartridgeMetaData.version);
-            resource.addProperty("Host", cartridgeMetaData.host);
-            resource.addProperty("Properties", cartridgeMetaData.properties);
-            registry.put(resourcePath, resource);
-
-            registry.rateResource(resourcePath, defaultRank);
-
-            Comment comment = new Comment();
-            comment.setText("Added the " + applicationName + " " + type + " cartridge");
-            registry.addComment(resourcePath, comment);
-
-        } catch (Exception e) {
-
-            if (log.isErrorEnabled()) {
-                log.error("addCartridgeMetaDataDetails", e);
-            }
-        } finally {
-            // Close the session
-            ((WSRegistryServiceClient) registry).logut();
-        }
-
-
-    }
-
-    /**
-     * Get the meta data from the registry
-     * @param applicationName
-     * @param cartridgeType
-     * @return
-     * @throws Exception
-     */
-    @Override
-    public String getCartridgeMetaDataDetails(String applicationName, String cartridgeType)
-            throws Exception {
-        Registry registry = setRegistry();
-        CartridgeMetaData cartridgeMetaData = new CartridgeMetaData();
-        try {
-
-            String resourcePath = mainResource + applicationName + "/" + cartridgeType;
-            if (registry.resourceExists(resourcePath)) {
-
-                Resource getResource = registry.get(resourcePath);
-                if (log.isDebugEnabled()) {
-                    log.debug("Resource retrived");
-                    log.debug("Printing retrieved resource content: " +
-                            new String((byte[]) getResource.getContent()));
-                }
-
-                cartridgeMetaData.type = getResource.getProperty("Cartidge Type");
-                cartridgeMetaData.applicationName = getResource.getProperty("Application
Name");
-                cartridgeMetaData.description = getResource.getProperty("Description");
-                cartridgeMetaData.displayName = getResource.getProperty("Display Name");
-                cartridgeMetaData.host = getResource.getProperty("Host");
-                cartridgeMetaData.provider = getResource.getProperty("provider");
-                cartridgeMetaData.version = getResource.getProperty("Version");
-                cartridgeMetaData.properties = getResource.getProperty("Properties");
-
-
-
-            }
-
-        } catch (Exception e) {
-
-            if (log.isErrorEnabled()) {
-                log.error("getCartridgeMetaDataDetails", e);
-            }
-        } finally {
-            // Close the session
-            ((WSRegistryServiceClient) registry).logut();
-        }
-        return cartridgeMetaData.toString();
-    }
-
-    /**
-     * Remove catridge meta data details from the registry
-     * @param applicationName
-     * @param cartridgeType
-     * @return
-     * @throws Exception
-     */
-    @Override
-    public boolean removeCartridgeMetaDataDetails(String applicationName, String cartridgeType)
-            throws Exception {
-        Registry registry = setRegistry();
-        String resourcePath = mainResource + applicationName + "/" + cartridgeType;
-        registry.delete(resourcePath);
-        return false;
-    }
-
-
     public void addPropertiesToCluster(String applicationName, String clusterId, NewProperty[]
properties) throws RegistryException {
 
     }

http://git-wip-us.apache.org/repos/asf/stratos/blob/35ef2279/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 ce04abd..55887a3 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
@@ -22,7 +22,6 @@ 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.CartridgeMetaData;
 import org.apache.stratos.metadataservice.definition.NewProperty;
 import org.apache.stratos.metadataservice.exception.RestAPIException;
 import org.apache.stratos.metadataservice.registry.DataRegistryFactory;
@@ -60,51 +59,6 @@ public class MetaDataAdmin {
         registry = DataRegistryFactory.getDataRegistryFactory(registryType);
     }
 
-    @POST
-    @Path("/cartridge/metadata/{applicationname}/{cartridgetype}")
-    @Produces("application/json")
-    @Consumes("application/json")
-    @AuthorizationAction("/permission/protected/manage/monitor/tenants")
-    public Response addCartridgeMetaDataDetails(@PathParam("applicationname") String applicationName,
-                                                @PathParam("cartridgetype") String cartridgeType,
-                                                CartridgeMetaData cartridgeMetaData) throws
RestAPIException {
-
-
-        URI url = uriInfo.getAbsolutePathBuilder().path(applicationName + "/" + cartridgeType).build();
-        try {
-            registry.addCartridgeMetaDataDetails(applicationName, cartridgeType, cartridgeMetaData);
-        } catch (Exception err) {
-            log.error("Error occurred while adding meta data details ", err);
-        }
-
-        return Response.created(url).build();
-
-    }
-
-    @GET
-    @Path("/cartridge/metadata/{applicationname}/{cartridgetype}")
-    @Produces("application/json")
-    @Consumes("application/json")
-    @AuthorizationAction("/permission/protected/manage/monitor/tenants")
-    public Response getCartridgeMetaDataDetails(@PathParam("applicationname") String applicationName,
-                                                @PathParam("cartridgetype") String cartridgeType)
throws RestAPIException {
-
-        String result = null;
-        try {
-            result = registry.getCartridgeMetaDataDetails(applicationName, cartridgeType);
-        } catch (Exception err) {
-            log.error("Error occurred while adding meta data details ", err);
-        }
-        Response.ResponseBuilder rb;
-        if (result == null) {
-            rb = Response.status(Response.Status.NOT_FOUND);
-        } else {
-            rb = Response.ok().entity(result);
-        }
-        return rb.build();
-
-    }
-
     @GET
     @Path("/application/{application_id}/cluster/{cluster_id}/properties")
     @Produces("application/json")
@@ -188,7 +142,6 @@ public class MetaDataAdmin {
         }
 
         return Response.created(url).build();
-
     }
 
     @POST
@@ -206,7 +159,6 @@ public class MetaDataAdmin {
             log.error("Error occurred while adding properties ", e);
         }
 
-
         return Response.created(url).build();
     }
 


Mime
View raw message