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/03/01 10:49:31 UTC
stratos git commit: Adding metadata service api methods to manager
properties against applications
Repository: stratos
Updated Branches:
refs/heads/master 716d5176a -> dd8d3d64f
Adding metadata service api methods to manager properties against applications
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/dd8d3d64
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/dd8d3d64
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/dd8d3d64
Branch: refs/heads/master
Commit: dd8d3d64f24f2f5e295ba116163d4fecfe9f6360
Parents: 716d517
Author: Imesh Gunaratne <im...@apache.org>
Authored: Sun Mar 1 15:19:16 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Sun Mar 1 15:19:16 2015 +0530
----------------------------------------------------------------------
.../service/registry/CarbonRegistry.java | 73 ++++++++++-
.../metadata/service/registry/DataStore.java | 9 +-
.../service/services/MetaDataAdmin.java | 126 ++++++++++++++++++-
3 files changed, 198 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/dd8d3d64/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/CarbonRegistry.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/CarbonRegistry.java b/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/CarbonRegistry.java
index e52c028..559a492 100644
--- a/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/CarbonRegistry.java
+++ b/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/CarbonRegistry.java
@@ -48,6 +48,35 @@ public class CarbonRegistry implements DataStore {
public CarbonRegistry() {
}
+ public List<NewProperty> getApplicationProperties(String applicationName) throws RegistryException {
+ Registry tempRegistry = getRegistry();
+ String resourcePath = mainResource + applicationName;
+
+ if (!tempRegistry.resourceExists(resourcePath)) {
+ return null;
+ }
+
+ PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
+ ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
+ ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
+
+ 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;
+ }
/**
* Get Properties of clustor
@@ -57,7 +86,7 @@ public class CarbonRegistry implements DataStore {
* @return
* @throws RegistryException
*/
- public List<NewProperty> getPropertiesOfCluster(String applicationName, String clusterId) throws RegistryException {
+ public List<NewProperty> getClusterProperties(String applicationName, String clusterId) throws RegistryException {
Registry tempRegistry = getRegistry();
String resourcePath = mainResource + applicationName + "/" + clusterId;
@@ -91,6 +120,46 @@ public class CarbonRegistry implements DataStore {
return newProperties;
}
+ public void addPropertiesToApplication(String applicationId, NewProperty[] properties) throws RegistryException {
+ for (NewProperty property : properties) {
+ addPropertyToApplication(applicationId, property);
+ }
+ }
+
+ public void addPropertyToApplication(String applicationId, NewProperty property) throws RegistryException {
+ Registry registry = getRegistry();
+ String resourcePath = mainResource + applicationId;
+
+ try {
+ PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
+ ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
+ ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
+
+ registry.beginTransaction();
+ Resource nodeResource = null;
+ if (registry.resourceExists(resourcePath)) {
+ nodeResource = registry.get(resourcePath);
+ } else {
+ nodeResource = registry.newResource();
+ if (log.isDebugEnabled()) {
+ log.debug("Registry resource is create at path for application: " + nodeResource.getPath());
+ }
+ }
+
+ nodeResource.setProperty(property.getKey(), Arrays.asList(property.getValues()));
+ registry.put(resourcePath, nodeResource);
+ registry.commitTransaction();
+
+ log.info(String.format("Registry property is persisted: [resource-path] %s [Property Name] %s [Property Values] %s",
+ resourcePath, property.getKey(), Arrays.asList(property.getValues())));
+ } catch (Exception e) {
+ String msg = "Failed to persist properties in registry: " + resourcePath;
+ registry.rollbackTransaction();
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+ }
+
/**
* Add property to cluster
*
@@ -133,7 +202,6 @@ public class CarbonRegistry implements DataStore {
log.error(msg, e);
throw new RegistryException(msg, e);
}
-
}
private UserRegistry getRegistry() throws RegistryException {
@@ -185,7 +253,6 @@ public class CarbonRegistry implements DataStore {
public void addPropertiesToCluster(String applicationName, String clusterId, NewProperty[] properties) throws RegistryException {
for (NewProperty property : properties) {
this.addPropertyToCluster(applicationName, clusterId, property);
-
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/dd8d3d64/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/DataStore.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/DataStore.java b/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/DataStore.java
index f9f42bb..3e678ee 100644
--- a/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/DataStore.java
+++ b/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/DataStore.java
@@ -29,10 +29,17 @@ import java.util.List;
*/
public interface DataStore {
+ public void addPropertyToApplication(String applicationId, NewProperty property) throws RegistryException;
+
+ public void addPropertiesToApplication(String applicationName, NewProperty[] properties)
+ throws RegistryException;
+
public void addPropertiesToCluster(String applicationName, String clusterId, NewProperty[] properties)
throws RegistryException;
- public List<NewProperty> getPropertiesOfCluster(String applicationName, String clusterId)
+ public List<NewProperty> getApplicationProperties(String applicationName) throws RegistryException;
+
+ public List<NewProperty> getClusterProperties(String applicationName, String clusterId)
throws RegistryException;
public void addPropertyToCluster(String applicationId, String clusterId, NewProperty property) throws RegistryException;
http://git-wip-us.apache.org/repos/asf/stratos/blob/dd8d3d64/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
index 6b43d95..72bddd4 100644
--- 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
@@ -55,6 +55,38 @@ public class MetaDataAdmin {
}
@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)
+ throws RestAPIException {
+
+ List<NewProperty> properties;
+ NewProperty[] propertiesArr = null;
+ try {
+ properties = registry
+ .getApplicationProperties(applicationId);
+ if (properties != null) {
+ propertiesArr = new NewProperty[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("/application/{application_id}/cluster/{cluster_id}/properties")
@Produces("application/json")
@Consumes("application/json")
@@ -65,7 +97,7 @@ public class MetaDataAdmin {
NewProperty[] propertiesArr = null;
try {
properties = registry
- .getPropertiesOfCluster(applicationId, clusterId);
+ .getClusterProperties(applicationId, clusterId);
if (properties != null) {
propertiesArr = new NewProperty[properties.size()];
propertiesArr = properties.toArray(propertiesArr);
@@ -86,6 +118,44 @@ public class MetaDataAdmin {
}
@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)
+ throws RestAPIException {
+ List<NewProperty> properties;
+
+
+ NewProperty property = null;
+ try {
+ properties = registry.getApplicationProperties(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 (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("/application/{application_id}/cluster/{cluster_id}/property/{property_name}")
@Produces("application/json")
@Consumes("application/json")
@@ -95,10 +165,8 @@ public class MetaDataAdmin {
NewProperty property = null;
-
try {
- properties = registry
- .getPropertiesOfCluster(applicationId, clusterId);
+ properties = registry.getClusterProperties(applicationId, clusterId);
if (properties == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
@@ -124,11 +192,36 @@ public class MetaDataAdmin {
}
@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 + "/" + property.getKey()).build();
+ if (StringUtils.isEmpty(property.getKey())) {
+ throw new RestAPIException("Property key can not be empty");
+ }
+
+ try {
+ registry.addPropertyToApplication(applicationId, property);
+ } catch (RegistryException e) {
+ String msg = "Error occurred while adding property";
+ log.error(msg, e);
+ throw new RestAPIException(msg, e);
+ }
+ return Response.created(url).build();
+ }
+
+ @POST
@Path("application/{application_id}/cluster/{cluster_id}/property")
@Produces("application/json")
@Consumes("application/json")
@AuthorizationAction("/permission/protected/manage/monitor/tenants")
- public Response addPropertyToACluster(@PathParam("application_id") String applicationId, @PathParam("cluster_id") String clusterId, NewProperty property)
+ public Response addPropertyToCluster(@PathParam("application_id") String applicationId,
+ @PathParam("cluster_id") String clusterId, NewProperty property)
throws RestAPIException {
URI url = uriInfo.getAbsolutePathBuilder().path(applicationId + "/" + clusterId + "/" + property.getKey()).build();
@@ -148,11 +241,32 @@ public class MetaDataAdmin {
}
@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();
+
+ try {
+ registry.addPropertiesToApplication(applicationId, properties);
+ } 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("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)
+ public Response addPropertiesToCluster(@PathParam("application_id") String applicationId,
+ @PathParam("cluster_id") String clusterId, NewProperty[] properties)
throws RestAPIException {
URI url = uriInfo.getAbsolutePathBuilder().path(applicationId + "/" + clusterId).build();