stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From im...@apache.org
Subject [24/50] [abbrv] git commit: add delete application to metadata service
Date Thu, 30 Oct 2014 04:13:48 GMT
add delete application to metadata service


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

Branch: refs/heads/docker-grouping-merge
Commit: c947820858960606a5d7b3c5e90c5086aadbdabb
Parents: 4bca87e
Author: Udara Liyanage <udara@wso2.com>
Authored: Tue Oct 28 10:45:47 2014 +0530
Committer: Udara Liyanage <udara@wso2.com>
Committed: Tue Oct 28 13:22:27 2014 +0530

----------------------------------------------------------------------
 .../defaults/DefaultMetaDataServiceClient.java  | 11 +++++++++
 .../client/defaults/MetaDataServiceClient.java  |  2 ++
 .../metadata/client/rest/DefaultRestClient.java |  2 ++
 .../registry/CarbonRegistry.java                | 25 +++++++++++++++++++-
 .../metadataservice/registry/DataStore.java     |  1 +
 .../metadataservice/registry/GRegRegistry.java  |  4 ++++
 .../metadataservice/services/MetaDataAdmin.java | 22 +++++++++++++++++
 7 files changed, 66 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/c9478208/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 fbebab9..ff7ac4a 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
@@ -96,6 +96,17 @@ public class DefaultMetaDataServiceClient implements MetaDataServiceClient
{
         return gson.fromJson(responseContent, PropertyBean.class);
     }
 
+    public void deleteApplicationProperties(String appId) throws MetaDataServiceClientException{
+        StringBuilder applicationPath = new StringBuilder(baseUrl).append("application/").append(appId);
+        HttpResponse response;
+        try {
+            response = restClient.doDelete(String.valueOf(applicationPath));
+        } catch (RestClientException e) {
+            String msg= "Error occured while deleting application";
+            throw new MetaDataServiceClientException(msg, e);
+        }
+    }
+
     private String readResponseContent(HttpResponse response) throws IOException {
 
         BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(),
"UTF-8"));

http://git-wip-us.apache.org/repos/asf/stratos/blob/c9478208/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 8fdb9a7..4703e77 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
@@ -60,6 +60,8 @@ public interface MetaDataServiceClient {
      */
     public org.apache.stratos.metadata.client.beans.PropertyBean getProperty(String appId,
String clusterID, String propertyKey) throws MetaDataServiceClientException;
 
+    public void deleteApplicationProperties(String applicationId) throws MetaDataServiceClientException;
+
     /**
      * Shutdown the MetaDataServiceClient. Should be called once after using the client.
      */

http://git-wip-us.apache.org/repos/asf/stratos/blob/c9478208/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/rest/DefaultRestClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/rest/DefaultRestClient.java
b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/rest/DefaultRestClient.java
index 160ca15..d3a3f7f 100644
--- a/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/rest/DefaultRestClient.java
+++ b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/rest/DefaultRestClient.java
@@ -122,6 +122,7 @@ public class DefaultRestClient implements RestClient {
     public HttpResponse doGet(String resourcePath) throws RestClientException {
 
         HttpGet get = new HttpGet(resourcePath);
+        setAuthHeader(get);
 
         try {
             return httpClient.execute(get);
@@ -138,6 +139,7 @@ public class DefaultRestClient implements RestClient {
     public HttpResponse doDelete(String resourcePath) throws RestClientException {
 
         HttpDelete delete = new HttpDelete(resourcePath);
+        setAuthHeader(delete);
 
         try {
             return httpClient.execute(delete);

http://git-wip-us.apache.org/repos/asf/stratos/blob/c9478208/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 e9d590d..89250b3 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,6 +18,7 @@
  */
 package org.apache.stratos.metadataservice.registry;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.metadataservice.definition.NewProperty;
@@ -102,7 +103,29 @@ public class CarbonRegistry extends AbstractAdmin implements DataStore
{
     }
 
     /**
-     * Add properties to clustor
+     * Delete the resource identified by the applicationId, if exist.
+     * @param applicationId ID of the application.
+     * @return True if resource exist and able to delete, else false.
+     * @throws RegistryException
+     */
+    public boolean deleteApplication(String applicationId) throws RegistryException {
+        if(StringUtils.isEmpty(applicationId)){
+            throw new IllegalArgumentException("Application ID can not be null");
+        }
+        Registry tempRegistry = getGovernanceUserRegistry();
+        String resourcePath = mainResource + applicationId;
+
+        if(tempRegistry.resourceExists(resourcePath)){
+            tempRegistry.delete(resourcePath);
+            log.info(String.format("Application removed from registry %s", applicationId));
+            return true;
+        }
+
+        return false;
+    }
+
+    /**
+     * Add properties to cluster
      * @param applicationName
      * @param clusterId
      * @param properties

http://git-wip-us.apache.org/repos/asf/stratos/blob/c9478208/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 0ad8459..33f3229 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
@@ -36,4 +36,5 @@ public interface DataStore {
 
     public void addPropertyToCluster(String applicationId, String clusterId, NewProperty
property) throws RegistryException;
 
+    public boolean deleteApplication(String applicationId) throws RegistryException;
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/c9478208/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 ffe38f1..c2ba22e 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
@@ -102,4 +102,8 @@ public class GRegRegistry implements DataStore {
 
     }
 
+    public boolean deleteApplication(String applicationId) {
+        return false;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/c9478208/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 55887a3..e88bc2a 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
@@ -162,5 +162,27 @@ public class MetaDataAdmin {
         return Response.created(url).build();
     }
 
+    @DELETE
+    @Path("application/{application_id}")
+    @Produces("application/json")
+    @Consumes("application/json")
+    @AuthorizationAction("/permission/protected/manage/monitor/tenants")
+    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(" ", e);
+        }
+
+        return Response.ok().build();
+    }
+
 
 }


Mime
View raw message