AMBARI-21035. Integrate ClusterService with Swagger (adoroszlai)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/275525b2 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/275525b2 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/275525b2 Branch: refs/heads/trunk Commit: 275525b212d8f9ae306d83417b8f94d035a67474 Parents: 228b928 Author: Attila Doroszlai <adorosz...@hortonworks.com> Authored: Tue May 16 11:14:24 2017 +0200 Committer: Attila Doroszlai <adorosz...@hortonworks.com> Committed: Wed May 17 10:17:12 2017 +0200 ---------------------------------------------------------------------- .../server/api/services/ClusterService.java | 305 ++++++++++++++----- .../ambari/server/api/services/HostService.java | 22 +- .../server/api/services/ServiceService.java | 18 +- .../AmbariManagementControllerImpl.java | 2 +- .../controller/ClusterArtifactRequest.java | 46 +++ .../controller/ClusterArtifactResponse.java | 49 +++ .../server/controller/ClusterRequest.java | 111 ++----- .../server/controller/ClusterResponse.java | 106 +++---- .../ClusterServiceArtifactRequest.java | 34 ++- .../ClusterServiceArtifactResponse.java | 27 +- .../internal/ArtifactResourceProvider.java | 33 +- .../internal/ClusterResourceProvider.java | 90 +++--- .../internal/ProvisionClusterRequest.java | 4 +- .../server/api/services/ClusterServiceTest.java | 30 +- .../AmbariManagementControllerTest.java | 80 ++--- .../server/controller/ClusterRequestTest.java | 16 - .../server/controller/ClusterResponseTest.java | 11 +- .../internal/ClusterResourceProviderTest.java | 20 +- .../internal/ProvisionClusterRequestTest.java | 6 +- .../server/state/cluster/ClusterTest.java | 6 +- 20 files changed, 591 insertions(+), 425 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/275525b2/ambari-server/src/main/java/org/apache/ambari/server/api/services/ClusterService.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ClusterService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ClusterService.java index 5577633..80fcd2e 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ClusterService.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ClusterService.java @@ -1,4 +1,4 @@ -/** +/* * 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 @@ -31,21 +31,37 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; import org.apache.ambari.server.api.resources.ResourceInstance; import org.apache.ambari.server.controller.AmbariServer; +import org.apache.ambari.server.controller.ClusterArtifactResponse; +import org.apache.ambari.server.controller.ClusterResponse.ClusterResponseWrapper; +import org.apache.ambari.server.controller.internal.ClusterResourceProvider; import org.apache.ambari.server.controller.spi.Resource; import org.apache.ambari.server.state.Clusters; +import org.apache.http.HttpStatus; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; /** * Service responsible for cluster resource requests. */ -@Path("/clusters/") +@Path("/clusters") +@Api(value = "/clusters", description = "Endpoint for cluster-specific operations") public class ClusterService extends BaseService { + private static final String CLUSTER_REQUEST_TYPE = "org.apache.ambari.server.controller.ClusterRequest"; + private static final String ARTIFACT_REQUEST_TYPE = "org.apache.ambari.server.controller.ClusterArtifactRequest"; + /** * The clusters utilities. */ @@ -85,10 +101,24 @@ public class ClusterService extends BaseService { */ @GET @Path("{clusterName}") - @Produces("text/plain") + @Produces(MediaType.TEXT_PLAIN) + @ApiOperation(value = "Returns information about a specific cluster", response = ClusterResponseWrapper.class) + @ApiImplicitParams({ + @ApiImplicitParam(name = QUERY_FIELDS, value = QUERY_FILTER_DESCRIPTION, dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY, + defaultValue = ClusterResourceProvider.ALL_PROPERTIES), + }) + @ApiResponses({ + @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION), + @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = MSG_RESOURCE_NOT_FOUND), + @ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = MSG_NOT_AUTHENTICATED), + @ApiResponse(code = HttpStatus.SC_FORBIDDEN, message = MSG_PERMISSION_DENIED), + @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR), + }) public Response getCluster(String body, @Context HttpHeaders headers, @Context UriInfo ui, - @PathParam("clusterName") String clusterName) { - return handleRequest(headers, body, ui, Request.Type.GET, createClusterResource(clusterName)); + @ApiParam(required = true) @PathParam("clusterName") String clusterName + ) { + ResourceInstance resource = createClusterResource(clusterName); + return handleRequest(headers, body, ui, Request.Type.GET, resource); } /** @@ -101,9 +131,27 @@ public class ClusterService extends BaseService { * @return cluster collection resource representation */ @GET - @Produces("text/plain") + @Produces(MediaType.TEXT_PLAIN) + @ApiOperation(value = "Returns all clusters", + response = ClusterResponseWrapper.class, responseContainer = RESPONSE_CONTAINER_LIST) + @ApiImplicitParams({ + @ApiImplicitParam(name = QUERY_FIELDS, value = QUERY_FILTER_DESCRIPTION, dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY, + defaultValue = ClusterResourceProvider.CLUSTER_NAME), + @ApiImplicitParam(name = QUERY_SORT, value = QUERY_SORT_DESCRIPTION, dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY), + @ApiImplicitParam(name = QUERY_PAGE_SIZE, value = QUERY_PAGE_SIZE_DESCRIPTION, defaultValue = DEFAULT_PAGE_SIZE, dataType = DATA_TYPE_INT, paramType = PARAM_TYPE_QUERY), + @ApiImplicitParam(name = QUERY_FROM, value = QUERY_FROM_DESCRIPTION, allowableValues = QUERY_FROM_VALUES, defaultValue = DEFAULT_FROM, dataType = DATA_TYPE_INT, paramType = PARAM_TYPE_QUERY), + @ApiImplicitParam(name = QUERY_TO, value = QUERY_TO_DESCRIPTION, allowableValues = QUERY_TO_VALUES, dataType = DATA_TYPE_INT, paramType = PARAM_TYPE_QUERY), + }) + @ApiResponses({ + @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION), + @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = MSG_RESOURCE_NOT_FOUND), + @ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = MSG_NOT_AUTHENTICATED), + @ApiResponse(code = HttpStatus.SC_FORBIDDEN, message = MSG_PERMISSION_DENIED), + @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR), + }) public Response getClusters(String body, @Context HttpHeaders headers, @Context UriInfo ui) { - return handleRequest(headers, body, ui, Request.Type.GET, createClusterResource(null)); + ResourceInstance resource = createClusterResource(null); + return handleRequest(headers, body, ui, Request.Type.GET, resource); } /** @@ -118,10 +166,25 @@ public class ClusterService extends BaseService { */ @POST @Path("{clusterName}") - @Produces("text/plain") + @Produces(MediaType.TEXT_PLAIN) + @ApiOperation(value = "Creates a cluster") + @ApiImplicitParams({ + @ApiImplicitParam(dataType = CLUSTER_REQUEST_TYPE, paramType = PARAM_TYPE_BODY) + }) + @ApiResponses({ + @ApiResponse(code = HttpStatus.SC_CREATED, message = MSG_SUCCESSFUL_OPERATION), + @ApiResponse(code = HttpStatus.SC_ACCEPTED, message = MSG_REQUEST_ACCEPTED), + @ApiResponse(code = HttpStatus.SC_BAD_REQUEST, message = MSG_INVALID_ARGUMENTS), + @ApiResponse(code = HttpStatus.SC_CONFLICT, message = MSG_RESOURCE_ALREADY_EXISTS), + @ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = MSG_NOT_AUTHENTICATED), + @ApiResponse(code = HttpStatus.SC_FORBIDDEN, message = MSG_PERMISSION_DENIED), + @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR), + }) public Response createCluster(String body, @Context HttpHeaders headers, @Context UriInfo ui, - @PathParam("clusterName") String clusterName) { - return handleRequest(headers, body, ui, Request.Type.POST, createClusterResource(clusterName)); + @ApiParam(required = true) @PathParam("clusterName") String clusterName + ) { + ResourceInstance resource = createClusterResource(clusterName); + return handleRequest(headers, body, ui, Request.Type.POST, resource); } /** @@ -136,10 +199,25 @@ public class ClusterService extends BaseService { */ @PUT @Path("{clusterName}") - @Produces("text/plain") + @Produces(MediaType.TEXT_PLAIN) + @ApiOperation(value = "Updates a cluster") + @ApiImplicitParams({ + @ApiImplicitParam(dataType = CLUSTER_REQUEST_TYPE, paramType = PARAM_TYPE_BODY) + }) + @ApiResponses({ + @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION), + @ApiResponse(code = HttpStatus.SC_ACCEPTED, message = MSG_REQUEST_ACCEPTED), + @ApiResponse(code = HttpStatus.SC_BAD_REQUEST, message = MSG_INVALID_ARGUMENTS), + @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = MSG_RESOURCE_NOT_FOUND), + @ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = MSG_NOT_AUTHENTICATED), + @ApiResponse(code = HttpStatus.SC_FORBIDDEN, message = MSG_PERMISSION_DENIED), + @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR), + }) public Response updateCluster(String body, @Context HttpHeaders headers, @Context UriInfo ui, - @PathParam("clusterName") String clusterName) { - return handleRequest(headers, body, ui, Request.Type.PUT, createClusterResource(clusterName)); + @ApiParam(required = true) @PathParam("clusterName") String clusterName + ) { + ResourceInstance resource = createClusterResource(clusterName); + return handleRequest(headers, body, ui, Request.Type.PUT, resource); } /** @@ -154,10 +232,20 @@ public class ClusterService extends BaseService { */ @DELETE @Path("{clusterName}") - @Produces("text/plain") + @Produces(MediaType.TEXT_PLAIN) + @ApiOperation(value = "Deletes a cluster") + @ApiResponses({ + @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION), + @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = MSG_RESOURCE_NOT_FOUND), + @ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = MSG_NOT_AUTHENTICATED), + @ApiResponse(code = HttpStatus.SC_FORBIDDEN, message = MSG_PERMISSION_DENIED), + @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR), + }) public Response deleteCluster(@Context HttpHeaders headers, @Context UriInfo ui, - @PathParam("clusterName") String clusterName) { - return handleRequest(headers, null, ui, Request.Type.DELETE, createClusterResource(clusterName)); + @ApiParam(required = true) @PathParam("clusterName") String clusterName + ) { + ResourceInstance resource = createClusterResource(clusterName); + return handleRequest(headers, null, ui, Request.Type.DELETE, resource); } /** @@ -173,13 +261,28 @@ public class ClusterService extends BaseService { */ @GET @Path("{clusterName}/artifacts") - @Produces("text/plain") - public Response getArtifacts(String body, - @Context HttpHeaders headers, - @Context UriInfo ui, - @PathParam("clusterName") String clusterName) { - return handleRequest(headers, body, ui, Request.Type.GET, - createArtifactResource(clusterName, null)); + @Produces(MediaType.TEXT_PLAIN) + @ApiOperation(value = "Returns all artifacts associated with the cluster", + response = ClusterArtifactResponse.class, responseContainer = RESPONSE_CONTAINER_LIST) + @ApiImplicitParams({ + @ApiImplicitParam(name = QUERY_FIELDS, value = QUERY_FILTER_DESCRIPTION, dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY), + @ApiImplicitParam(name = QUERY_SORT, value = QUERY_SORT_DESCRIPTION, dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY), + @ApiImplicitParam(name = QUERY_PAGE_SIZE, value = QUERY_PAGE_SIZE_DESCRIPTION, defaultValue = DEFAULT_PAGE_SIZE, dataType = DATA_TYPE_INT, paramType = PARAM_TYPE_QUERY), + @ApiImplicitParam(name = QUERY_FROM, value = QUERY_FROM_DESCRIPTION, allowableValues = QUERY_FROM_VALUES, defaultValue = DEFAULT_FROM, dataType = DATA_TYPE_INT, paramType = PARAM_TYPE_QUERY), + @ApiImplicitParam(name = QUERY_TO, value = QUERY_TO_DESCRIPTION, allowableValues = QUERY_TO_VALUES, dataType = DATA_TYPE_INT, paramType = PARAM_TYPE_QUERY), + }) + @ApiResponses({ + @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION), + @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = MSG_RESOURCE_NOT_FOUND), + @ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = MSG_NOT_AUTHENTICATED), + @ApiResponse(code = HttpStatus.SC_FORBIDDEN, message = MSG_PERMISSION_DENIED), + @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR), + }) + public Response getClusterArtifacts(String body, @Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(required = true) @PathParam("clusterName") String clusterName + ) { + ResourceInstance resource = createArtifactResource(clusterName, null); + return handleRequest(headers, body, ui, Request.Type.GET, resource); } /** @@ -196,13 +299,27 @@ public class ClusterService extends BaseService { */ @GET @Path("{clusterName}/artifacts/{artifactName}") - @Produces("text/plain") - public Response getArtifact(String body, - @Context HttpHeaders headers, - @Context UriInfo ui, - @PathParam("clusterName") String clusterName, - @PathParam("artifactName") String artifactName) { - return handleRequest(headers, body, ui, Request.Type.GET, createArtifactResource(clusterName, artifactName)); + @Produces(MediaType.TEXT_PLAIN) + @ApiOperation(value = "Get the details of a cluster artifact", + response = ClusterArtifactResponse.class) + @ApiImplicitParams({ + @ApiImplicitParam(name = QUERY_FIELDS, value = QUERY_FILTER_DESCRIPTION, dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY), + @ApiImplicitParam(name = QUERY_SORT, value = QUERY_SORT_DESCRIPTION, dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY), + @ApiImplicitParam(name = QUERY_PAGE_SIZE, value = QUERY_PAGE_SIZE_DESCRIPTION, defaultValue = DEFAULT_PAGE_SIZE, dataType = DATA_TYPE_INT, paramType = PARAM_TYPE_QUERY), + @ApiImplicitParam(name = QUERY_FROM, value = QUERY_FROM_DESCRIPTION, defaultValue = DEFAULT_FROM, dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY), + @ApiImplicitParam(name = QUERY_TO, value = QUERY_TO_DESCRIPTION, dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY) + }) + @ApiResponses(value = { + @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION), + @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = MSG_RESOURCE_NOT_FOUND), + @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR) + }) + public Response getClusterArtifact(String body, @Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(required = true) @PathParam("clusterName") String clusterName, + @ApiParam(required = true) @PathParam("artifactName") String artifactName + ) { + ResourceInstance resource = createArtifactResource(clusterName, artifactName); + return handleRequest(headers, body, ui, Request.Type.GET, resource); } /** @@ -214,18 +331,30 @@ public class ClusterService extends BaseService { * @param ui uri info * @param clusterName cluster name * @param artifactName artifact name - * @return */ @POST @Path("{clusterName}/artifacts/{artifactName}") - @Produces("text/plain") - public Response createArtifact(String body, - @Context HttpHeaders headers, - @Context UriInfo ui, - @PathParam("clusterName") String clusterName, - @PathParam("artifactName") String artifactName) { - return handleRequest(headers, body, ui, Request.Type.POST, - createArtifactResource(clusterName, artifactName)); + @Produces(MediaType.TEXT_PLAIN) + @ApiOperation(value = "Creates a cluster artifact") + @ApiImplicitParams({ + @ApiImplicitParam(dataType = ARTIFACT_REQUEST_TYPE, paramType = PARAM_TYPE_BODY) + }) + @ApiResponses({ + @ApiResponse(code = HttpStatus.SC_CREATED, message = MSG_SUCCESSFUL_OPERATION), + @ApiResponse(code = HttpStatus.SC_ACCEPTED, message = MSG_REQUEST_ACCEPTED), + @ApiResponse(code = HttpStatus.SC_BAD_REQUEST, message = MSG_INVALID_ARGUMENTS), + @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = MSG_RESOURCE_NOT_FOUND), + @ApiResponse(code = HttpStatus.SC_CONFLICT, message = MSG_RESOURCE_ALREADY_EXISTS), + @ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = MSG_NOT_AUTHENTICATED), + @ApiResponse(code = HttpStatus.SC_FORBIDDEN, message = MSG_PERMISSION_DENIED), + @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR), + }) + public Response createClusterArtifact(String body, @Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(required = true) @PathParam("clusterName") String clusterName, + @ApiParam(required = true) @PathParam("artifactName") String artifactName + ) { + ResourceInstance resource = createArtifactResource(clusterName, artifactName); + return handleRequest(headers, body, ui, Request.Type.POST, resource); } /** @@ -240,13 +369,25 @@ public class ClusterService extends BaseService { */ @PUT @Path("{clusterName}/artifacts") - @Produces("text/plain") - public Response updateArtifacts(String body, - @Context HttpHeaders headers, - @Context UriInfo ui, - @PathParam("clusterName") String clusterName) { - return handleRequest(headers, body, ui, Request.Type.PUT, - createArtifactResource(clusterName, null)); + @Produces(MediaType.TEXT_PLAIN) + @ApiOperation(value = "Updates multiple artifacts") + @ApiImplicitParams({ + @ApiImplicitParam(dataType = ARTIFACT_REQUEST_TYPE, paramType = PARAM_TYPE_BODY, allowMultiple = true) + }) + @ApiResponses({ + @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION), + @ApiResponse(code = HttpStatus.SC_ACCEPTED, message = MSG_REQUEST_ACCEPTED), + @ApiResponse(code = HttpStatus.SC_BAD_REQUEST, message = MSG_INVALID_ARGUMENTS), + @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = MSG_RESOURCE_NOT_FOUND), + @ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = MSG_NOT_AUTHENTICATED), + @ApiResponse(code = HttpStatus.SC_FORBIDDEN, message = MSG_PERMISSION_DENIED), + @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR), + }) + public Response updateClusterArtifacts(String body, @Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(required = true) @PathParam("clusterName") String clusterName + ) { + ResourceInstance resource = createArtifactResource(clusterName, null); + return handleRequest(headers, body, ui, Request.Type.PUT, resource); } /** @@ -262,14 +403,26 @@ public class ClusterService extends BaseService { */ @PUT @Path("{clusterName}/artifacts/{artifactName}") - @Produces("text/plain") - public Response updateArtifact(String body, - @Context HttpHeaders headers, - @Context UriInfo ui, - @PathParam("clusterName") String clusterName, - @PathParam("artifactName") String artifactName) { - return handleRequest(headers, body, ui, Request.Type.PUT, - createArtifactResource(clusterName, artifactName)); + @Produces(MediaType.TEXT_PLAIN) + @ApiOperation(value = "Updates a single artifact") + @ApiImplicitParams({ + @ApiImplicitParam(dataType = ARTIFACT_REQUEST_TYPE, paramType = PARAM_TYPE_BODY) + }) + @ApiResponses({ + @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION), + @ApiResponse(code = HttpStatus.SC_ACCEPTED, message = MSG_REQUEST_ACCEPTED), + @ApiResponse(code = HttpStatus.SC_BAD_REQUEST, message = MSG_INVALID_ARGUMENTS), + @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = MSG_RESOURCE_NOT_FOUND), + @ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = MSG_NOT_AUTHENTICATED), + @ApiResponse(code = HttpStatus.SC_FORBIDDEN, message = MSG_PERMISSION_DENIED), + @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR), + }) + public Response updateClusterArtifact(String body, @Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(required = true) @PathParam("clusterName") String clusterName, + @ApiParam(required = true) @PathParam("artifactName") String artifactName + ) { + ResourceInstance resource = createArtifactResource(clusterName, artifactName); + return handleRequest(headers, body, ui, Request.Type.PUT, resource); } /** @@ -285,14 +438,21 @@ public class ClusterService extends BaseService { */ @DELETE @Path("{clusterName}/artifacts/{artifactName}") - @Produces("text/plain") - public Response deleteArtifact(String body, - @Context HttpHeaders headers, - @Context UriInfo ui, - @PathParam("clusterName") String clusterName, - @PathParam("artifactName") String artifactName) { - return handleRequest(headers, body, ui, Request.Type.DELETE, - createArtifactResource(clusterName, artifactName)); + @Produces(MediaType.TEXT_PLAIN) + @ApiOperation(value = "Deletes a single artifact") + @ApiResponses({ + @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION), + @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = MSG_RESOURCE_NOT_FOUND), + @ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = MSG_NOT_AUTHENTICATED), + @ApiResponse(code = HttpStatus.SC_FORBIDDEN, message = MSG_PERMISSION_DENIED), + @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR), + }) + public Response deleteClusterArtifact(String body, @Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(required = true) @PathParam("clusterName") String clusterName, + @ApiParam(required = true) @PathParam("artifactName") String artifactName + ) { + ResourceInstance resource = createArtifactResource(clusterName, artifactName); + return handleRequest(headers, body, ui, Request.Type.DELETE, resource); } /** @@ -307,13 +467,20 @@ public class ClusterService extends BaseService { */ @DELETE @Path("{clusterName}/artifacts") - @Produces("text/plain") - public Response deleteArtifacts(String body, - @Context HttpHeaders headers, - @Context UriInfo ui, - @PathParam("clusterName") String clusterName) { - return handleRequest(headers, body, ui, Request.Type.DELETE, - createArtifactResource(clusterName, null)); + @Produces(MediaType.TEXT_PLAIN) + @ApiOperation(value = "Deletes all artifacts of a cluster that match the provided predicate") + @ApiResponses({ + @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION), + @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = MSG_RESOURCE_NOT_FOUND), + @ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = MSG_NOT_AUTHENTICATED), + @ApiResponse(code = HttpStatus.SC_FORBIDDEN, message = MSG_PERMISSION_DENIED), + @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR), + }) + public Response deleteClusterArtifacts(String body, @Context HttpHeaders headers, @Context UriInfo ui, + @ApiParam(required = true) @PathParam("clusterName") String clusterName + ) { + ResourceInstance resource = createArtifactResource(clusterName, null); + return handleRequest(headers, body, ui, Request.Type.DELETE, resource); } /** http://git-wip-us.apache.org/repos/asf/ambari/blob/275525b2/ambari-server/src/main/java/org/apache/ambari/server/api/services/HostService.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/HostService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/HostService.java index e50d70f..0e07ca5 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/HostService.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/HostService.java @@ -92,7 +92,7 @@ public class HostService extends BaseService { @Produces("text/plain") @ApiOperation(value = "Returns information about a single host", response = HostResponse.Wrapper.class) @ApiImplicitParams({ - @ApiImplicitParam(name = QUERY_FIELDS, value = QUERY_FILTER_DESCRIPTION, dataType = "string", paramType = "query"), + @ApiImplicitParam(name = QUERY_FIELDS, value = QUERY_FILTER_DESCRIPTION, dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY), }) @ApiResponses({ @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION), @@ -120,11 +120,11 @@ public class HostService extends BaseService { @Produces("text/plain") @ApiOperation(value = "Returns a collection of all hosts", response = HostResponse.Wrapper.class, responseContainer = "List") @ApiImplicitParams({ - @ApiImplicitParam(name = QUERY_FIELDS, value = QUERY_FILTER_DESCRIPTION, defaultValue = "Hosts/*", dataType = "string", paramType = "query"), - @ApiImplicitParam(name = QUERY_SORT, value = QUERY_SORT_DESCRIPTION, defaultValue = "Hosts/host_name.asc", dataType = "string", paramType = "query"), - @ApiImplicitParam(name = QUERY_PAGE_SIZE, value = QUERY_PAGE_SIZE_DESCRIPTION, defaultValue = DEFAULT_PAGE_SIZE, dataType = "integer", paramType = "query"), - @ApiImplicitParam(name = QUERY_FROM, value = QUERY_FROM_DESCRIPTION, allowableValues = QUERY_FROM_VALUES, defaultValue = DEFAULT_FROM, dataType = DATA_TYPE_INT, paramType = "query"), - @ApiImplicitParam(name = QUERY_TO, value = QUERY_TO_DESCRIPTION, allowableValues = QUERY_TO_VALUES, dataType = QUERY_TO_TYPE, paramType = "query"), + @ApiImplicitParam(name = QUERY_FIELDS, value = QUERY_FILTER_DESCRIPTION, defaultValue = "Hosts/*", dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY), + @ApiImplicitParam(name = QUERY_SORT, value = QUERY_SORT_DESCRIPTION, defaultValue = "Hosts/host_name.asc", dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY), + @ApiImplicitParam(name = QUERY_PAGE_SIZE, value = QUERY_PAGE_SIZE_DESCRIPTION, defaultValue = DEFAULT_PAGE_SIZE, dataType = DATA_TYPE_INT, paramType = PARAM_TYPE_QUERY), + @ApiImplicitParam(name = QUERY_FROM, value = QUERY_FROM_DESCRIPTION, allowableValues = QUERY_FROM_VALUES, defaultValue = DEFAULT_FROM, dataType = DATA_TYPE_INT, paramType = PARAM_TYPE_QUERY), + @ApiImplicitParam(name = QUERY_TO, value = QUERY_TO_DESCRIPTION, allowableValues = QUERY_TO_VALUES, dataType = DATA_TYPE_INT, paramType = PARAM_TYPE_QUERY), }) @ApiResponses({ @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION), @@ -153,7 +153,7 @@ public class HostService extends BaseService { @Produces("text/plain") @ApiOperation(value = "Creates multiple hosts in a single request") @ApiImplicitParams({ - @ApiImplicitParam(dataType = HOST_REQUEST_TYPE, paramType = "body", allowMultiple = true) + @ApiImplicitParam(dataType = HOST_REQUEST_TYPE, paramType = PARAM_TYPE_BODY, allowMultiple = true) }) @ApiResponses({ @ApiResponse(code = HttpStatus.SC_CREATED, message = MSG_SUCCESSFUL_OPERATION), @@ -186,7 +186,7 @@ public class HostService extends BaseService { @Produces("text/plain") @ApiOperation(value = "Creates a host") @ApiImplicitParams({ - @ApiImplicitParam(dataType = HOST_REQUEST_TYPE, paramType = "body") + @ApiImplicitParam(dataType = HOST_REQUEST_TYPE, paramType = PARAM_TYPE_BODY) }) @ApiResponses({ @ApiResponse(code = HttpStatus.SC_CREATED, message = MSG_SUCCESSFUL_OPERATION), @@ -221,7 +221,7 @@ public class HostService extends BaseService { @Produces("text/plain") @ApiOperation(value = "Updates a host") @ApiImplicitParams({ - @ApiImplicitParam(dataType = HOST_REQUEST_TYPE, paramType = "body") + @ApiImplicitParam(dataType = HOST_REQUEST_TYPE, paramType = PARAM_TYPE_BODY) }) @ApiResponses({ @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION), @@ -253,7 +253,7 @@ public class HostService extends BaseService { @Produces("text/plain") @ApiOperation(value = "Updates multiple hosts in a single request") @ApiImplicitParams({ - @ApiImplicitParam(dataType = HOST_REQUEST_TYPE, paramType = "body", allowMultiple = true) + @ApiImplicitParam(dataType = HOST_REQUEST_TYPE, paramType = PARAM_TYPE_BODY, allowMultiple = true) }) @ApiResponses({ @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION), @@ -301,7 +301,7 @@ public class HostService extends BaseService { @Produces("text/plain") @ApiOperation(value = "Deletes multiple hosts in a single request") @ApiImplicitParams({ - @ApiImplicitParam(dataType = HOST_REQUEST_TYPE, paramType = "body", allowMultiple = true) + @ApiImplicitParam(dataType = HOST_REQUEST_TYPE, paramType = PARAM_TYPE_BODY, allowMultiple = true) }) @ApiResponses({ @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION), http://git-wip-us.apache.org/repos/asf/ambari/blob/275525b2/ambari-server/src/main/java/org/apache/ambari/server/api/services/ServiceService.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ServiceService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ServiceService.java index 27de0b4..a28c4aa 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ServiceService.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ServiceService.java @@ -1,4 +1,4 @@ -/** +/* * 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 @@ -155,7 +155,7 @@ public class ServiceService extends BaseService { nickname = "ServiceService#createServices" ) @ApiImplicitParams({ - @ApiImplicitParam(dataType = SERVICE_REQUEST_TYPE, paramType = "body", allowMultiple = false) + @ApiImplicitParam(dataType = SERVICE_REQUEST_TYPE, paramType = PARAM_TYPE_BODY) }) @ApiResponses({ @ApiResponse(code = HttpStatus.SC_CREATED, message = MSG_SUCCESSFUL_OPERATION), @@ -188,7 +188,7 @@ public class ServiceService extends BaseService { nickname = "ServiceService#createService" ) @ApiImplicitParams({ - @ApiImplicitParam(dataType = SERVICE_REQUEST_TYPE, paramType = "body", allowMultiple = true) + @ApiImplicitParam(dataType = SERVICE_REQUEST_TYPE, paramType = PARAM_TYPE_BODY, allowMultiple = true) }) @ApiResponses({ @ApiResponse(code = HttpStatus.SC_CREATED, message = MSG_SUCCESSFUL_OPERATION), @@ -223,7 +223,7 @@ public class ServiceService extends BaseService { nickname = "ServiceService#updateService" ) @ApiImplicitParams({ - @ApiImplicitParam(dataType = SERVICE_REQUEST_TYPE, paramType = "body") + @ApiImplicitParam(dataType = SERVICE_REQUEST_TYPE, paramType = PARAM_TYPE_BODY) }) @ApiResponses({ @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION), @@ -254,7 +254,7 @@ public class ServiceService extends BaseService { nickname = "ServiceService#updateServices" ) @ApiImplicitParams({ - @ApiImplicitParam(dataType = SERVICE_REQUEST_TYPE, paramType = "body") + @ApiImplicitParam(dataType = SERVICE_REQUEST_TYPE, paramType = PARAM_TYPE_BODY) }) @ApiResponses({ @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION), @@ -339,7 +339,7 @@ public class ServiceService extends BaseService { nickname = "ServiceService#createArtifact" ) @ApiImplicitParams({ - @ApiImplicitParam(dataType = ARTIFACT_REQUEST_TYPE, paramType = "body", allowMultiple = false) + @ApiImplicitParam(dataType = ARTIFACT_REQUEST_TYPE, paramType = PARAM_TYPE_BODY) }) @ApiResponses({ @ApiResponse(code = HttpStatus.SC_CREATED, message = MSG_SUCCESSFUL_OPERATION), @@ -419,7 +419,7 @@ public class ServiceService extends BaseService { @GET @Path("{serviceName}/artifacts/{artifactName}") @Produces(MediaType.TEXT_PLAIN) - @ApiOperation(value = "Get the detais of a service artifact", + @ApiOperation(value = "Get the details of a service artifact", nickname = "ServiceService#getArtifact", response = ClusterServiceArtifactResponse.class, responseContainer = RESPONSE_CONTAINER_LIST) @@ -465,7 +465,7 @@ public class ServiceService extends BaseService { nickname = "ServiceService#updateArtifacts" ) @ApiImplicitParams({ - @ApiImplicitParam(dataType = ARTIFACT_REQUEST_TYPE, paramType = "body") + @ApiImplicitParam(dataType = ARTIFACT_REQUEST_TYPE, paramType = PARAM_TYPE_BODY) }) @ApiResponses({ @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION), @@ -503,7 +503,7 @@ public class ServiceService extends BaseService { nickname = "ServiceService#updateArtifact" ) @ApiImplicitParams({ - @ApiImplicitParam(dataType = ARTIFACT_REQUEST_TYPE, paramType = "body") + @ApiImplicitParam(dataType = ARTIFACT_REQUEST_TYPE, paramType = PARAM_TYPE_BODY) }) @ApiResponses({ @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION), http://git-wip-us.apache.org/repos/asf/ambari/blob/275525b2/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java index 4c8154e..27bbd6c 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java @@ -1794,7 +1794,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle } ClusterResponse clusterResponse = - new ClusterResponse(cluster.getClusterId(), cluster.getClusterName(), null, null, null, null, null, null); + new ClusterResponse(cluster.getClusterId(), cluster.getClusterName(), null, null, null, 0, null, null); Map<String, Collection<ServiceConfigVersionResponse>> map = new HashMap<>(); http://git-wip-us.apache.org/repos/asf/ambari/blob/275525b2/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterArtifactRequest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterArtifactRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterArtifactRequest.java new file mode 100644 index 0000000..a821615 --- /dev/null +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterArtifactRequest.java @@ -0,0 +1,46 @@ +/* + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.ambari.server.controller; + +import java.util.Map; + +import org.apache.ambari.server.controller.internal.ArtifactResourceProvider; + +import io.swagger.annotations.ApiModelProperty; + +/** + * Request schema for endpoint {@link org.apache.ambari.server.api.services.ClusterService#createClusterArtifact(String, + * javax.ws.rs.core.HttpHeaders, javax.ws.rs.core.UriInfo, String, String)} + * + * The interface is not actually implemented, it only carries swagger annotations. + */ +@SuppressWarnings("unused") +public interface ClusterArtifactRequest extends ApiModel { + + @ApiModelProperty(name = ArtifactResourceProvider.RESPONSE_KEY) + ClusterArtifactRequestInfo getClusterArtifactRequestInfo(); + + @ApiModelProperty(name = ArtifactResourceProvider.ARTIFACT_DATA_PROPERTY) + Map<String, Object> getArtifactData(); + + interface ClusterArtifactRequestInfo { + @ApiModelProperty(name = ArtifactResourceProvider.ARTIFACT_NAME) + String getArtifactName(); + } + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/275525b2/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterArtifactResponse.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterArtifactResponse.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterArtifactResponse.java new file mode 100644 index 0000000..c0dab20 --- /dev/null +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterArtifactResponse.java @@ -0,0 +1,49 @@ +/* + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.ambari.server.controller; + +import java.util.Map; + +import org.apache.ambari.server.controller.internal.ArtifactResourceProvider; + +import io.swagger.annotations.ApiModelProperty; + +/** + * Response schema for endpoint {@link org.apache.ambari.server.api.services.ClusterService#getClusterArtifact} + * + * The interface is not actually implemented, it only carries swagger annotations. + */ +public interface ClusterArtifactResponse { + + @ApiModelProperty(name = ArtifactResourceProvider.RESPONSE_KEY) + @SuppressWarnings("unused") + ClusterArtifactResponseInfo getClusterArtifactResponseInfo(); + + @ApiModelProperty(name = ArtifactResourceProvider.ARTIFACT_DATA_PROPERTY) + Map<String, Object> getArtifactData(); + + interface ClusterArtifactResponseInfo { + @ApiModelProperty(name = ArtifactResourceProvider.ARTIFACT_NAME) + String getArtifactName(); + + @ApiModelProperty(name = ArtifactResourceProvider.CLUSTER_NAME) + String getClusterName(); + } + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/275525b2/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterRequest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterRequest.java index 4d4fd59..56d0b1c 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterRequest.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterRequest.java @@ -22,40 +22,26 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.apache.ambari.server.controller.internal.ClusterResourceProvider; import org.apache.ambari.server.state.SecurityType; +import io.swagger.annotations.ApiModelProperty; + /** * Used for create Cluster */ public class ClusterRequest { - private Long clusterId; // for GET - - private String clusterName; // for GET/CREATE/UPDATE - - private String stackVersion; // for CREATE/UPDATE - - private String provisioningState; // for GET/CREATE/UPDATE - - /** - * The cluster's security type - * <p/> - * See {@link org.apache.ambari.server.state.SecurityType} for relevant values. - */ + private final Long clusterId; // for GET + private final String clusterName; // for GET/CREATE/UPDATE + private final String stackVersion; // for CREATE/UPDATE + private final String provisioningState; // for GET/CREATE/UPDATE private SecurityType securityType; // for GET/CREATE/UPDATE - - Set<String> hostNames; // CREATE/UPDATE - - private List<ConfigurationRequest> configs = null; - - private ServiceConfigVersionRequest serviceConfigVersionRequest = null; - - /** - * The cluster session attributes. - */ + private Set<String> hostNames; // CREATE/UPDATE + private List<ConfigurationRequest> configs; + private ServiceConfigVersionRequest serviceConfigVersionRequest; private final Map<String, Object> sessionAttributes; - - private String repositoryVersion = null; + private String repositoryVersion; // ----- Constructors ------------------------------------------------------ @@ -70,10 +56,13 @@ public class ClusterRequest { this(clusterId, clusterName, provisioningState, securityType, stackVersion, hostNames, null); } + /** + * @param provisioningState whether the cluster is still initializing or has finished with its deployment requests: + * either {@code INIT} or {@code INSTALLED}, or {@code null} if not set on the request. + */ public ClusterRequest(Long clusterId, String clusterName, String provisioningState, SecurityType securityType, String stackVersion, Set<String> hostNames, Map<String, Object> sessionAttributes) { - super(); this.clusterId = clusterId; this.clusterName = clusterName; this.provisioningState = provisioningState; @@ -86,16 +75,12 @@ public class ClusterRequest { // ----- ClusterRequest ---------------------------------------------------- - /** - * @return the clusterId - */ + @ApiModelProperty(name = ClusterResourceProvider.CLUSTER_ID) public Long getClusterId() { return clusterId; } - /** - * @return the clusterName - */ + @ApiModelProperty(name = ClusterResourceProvider.CLUSTER_NAME) public String getClusterName() { return clusterName; } @@ -107,81 +92,31 @@ public class ClusterRequest { * @return either {@code INIT} or {@code INSTALLED} or {@code null} if not set * on the request. */ + @ApiModelProperty(name = ClusterResourceProvider.PROVISIONING_STATE) public String getProvisioningState(){ return provisioningState; } /** - * Sets whether the cluster is still initializing or has finished with its - * deployment requests. - * - * @param provisioningState - * either {@code INIT} or {@code INSTALLED}, or {@code null} if not - * set on the request. - */ - public void setProvisioningState(String provisioningState) { - this.provisioningState = provisioningState; - } - - /** * Gets the cluster's security type. - * <p/> - * See {@link org.apache.ambari.server.state.SecurityType} for relevant values. * * @return a SecurityType declaring the security type; or {@code null} if not set set on the request */ + @ApiModelProperty(name = ClusterResourceProvider.SECURITY_TYPE) public SecurityType getSecurityType() { return securityType; } - /** - * Sets the cluster's security type. - * <p/> - * See {@link org.apache.ambari.server.state.SecurityType} for relevant values. - * - * @param securityType a SecurityType declaring the cluster's security type; or {@code null} if not - * set on the request - */ - public void setSecurityType(SecurityType securityType) { - this.securityType = securityType; - } - - /** - * @return the stackVersion - */ + @ApiModelProperty(name = ClusterResourceProvider.VERSION) public String getStackVersion() { return stackVersion; } - /** - * @param clusterId the clusterId to set - */ - public void setClusterId(Long clusterId) { - this.clusterId = clusterId; - } - - /** - * @param clusterName the clusterName to set - */ - public void setClusterName(String clusterName) { - this.clusterName = clusterName; - } - - /** - * @param stackVersion the stackVersion to set - */ - public void setStackVersion(String stackVersion) { - this.stackVersion = stackVersion; - } - + @ApiModelProperty(hidden = true) public Set<String> getHostNames() { return hostNames; } - public void setHostNames(Set<String> hostNames) { - this.hostNames = hostNames; - } - /** * Sets the configs requests (if any). * @@ -196,6 +131,7 @@ public class ClusterRequest { * @return the list of configuration requests, * or <code>null</code> if none is set. */ + @ApiModelProperty(name = ClusterResourceProvider.DESIRED_CONFIGS) public List<ConfigurationRequest> getDesiredConfig() { return configs; } @@ -224,6 +160,7 @@ public class ClusterRequest { return sb.toString(); } + @ApiModelProperty(name = ClusterResourceProvider.DESIRED_SERVICE_CONFIG_VERSIONS) public ServiceConfigVersionRequest getServiceConfigVersionRequest() { return serviceConfigVersionRequest; } @@ -233,6 +170,7 @@ public class ClusterRequest { * * @return the session attributes; may be null */ + @ApiModelProperty(hidden = true) public Map<String, Object> getSessionAttributes() { return sessionAttributes; } @@ -251,6 +189,7 @@ public class ClusterRequest { /** * @return the repo version to use */ + @ApiModelProperty(name = ClusterResourceProvider.REPO_VERSION) public String getRepositoryVersion() { return repositoryVersion; } http://git-wip-us.apache.org/repos/asf/ambari/blob/275525b2/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterResponse.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterResponse.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterResponse.java index b89bd45..3f75971 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterResponse.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterResponse.java @@ -1,4 +1,4 @@ -/** +/* * 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 @@ -20,47 +20,36 @@ package org.apache.ambari.server.controller; import java.util.Collection; import java.util.Map; +import java.util.Objects; import java.util.Set; +import org.apache.ambari.server.controller.internal.ClusterResourceProvider; import org.apache.ambari.server.state.ClusterHealthReport; import org.apache.ambari.server.state.DesiredConfig; import org.apache.ambari.server.state.SecurityType; import org.apache.ambari.server.state.State; -public class ClusterResponse { +import io.swagger.annotations.ApiModelProperty; - private final Long clusterId; +public class ClusterResponse { + private final long clusterId; private final String clusterName; - private final Set<String> hostNames; - private final String desiredStackVersion; + private final State provisioningState; + private final SecurityType securityType; + private final int totalHosts; private Map<String, DesiredConfig> desiredConfigs; - private Map<String, Collection<ServiceConfigVersionResponse>> desiredServiceConfigVersions; - - private String provisioningState; - - /** - * The cluster's security. - * <p/> - * See {@link org.apache.ambari.server.state.SecurityType} for relevant values. - */ - private String securityType; - - private Integer totalHosts; - private ClusterHealthReport clusterHealthReport; + private Map<String, String> credentialStoreServiceProperties; - private Map<String, String> credentialStoreServiceProperties = null; - - public ClusterResponse(Long clusterId, String clusterName, - State provisioningState, SecurityType securityType, Set<String> hostNames, Integer totalHosts, + public ClusterResponse(long clusterId, String clusterName, + State provisioningState, SecurityType securityType, Set<String> hostNames, int totalHosts, String desiredStackVersion, ClusterHealthReport clusterHealthReport) { - super(); this.clusterId = clusterId; this.clusterName = clusterName; this.hostNames = hostNames; @@ -69,44 +58,42 @@ public class ClusterResponse { this.clusterHealthReport = clusterHealthReport; if (null != provisioningState) { - this.provisioningState = provisioningState.name(); + this.provisioningState = provisioningState; + } else { + this.provisioningState = State.UNKNOWN; } if (null == securityType) { - this.securityType = SecurityType.NONE.name(); + this.securityType = SecurityType.NONE; } else { - this.securityType = securityType.name(); + this.securityType = securityType; } } /** * @return the clusterId */ - public Long getClusterId() { + @ApiModelProperty(name = ClusterResourceProvider.CLUSTER_ID) + public long getClusterId() { return clusterId; } /** * @return the clusterName */ + @ApiModelProperty(name = ClusterResourceProvider.CLUSTER_NAME) public String getClusterName() { return clusterName; } /** - * @return the host names - */ - public Set<String> getHostNames() { - return hostNames; - } - - /** * Gets whether the cluster is still initializing or has finished with its * deployment requests. * * @return either {@code INIT} or {@code INSTALLED}, never {@code null}. */ - public String getProvisioningState() { + @ApiModelProperty(name = ClusterResourceProvider.PROVISIONING_STATE) + public State getProvisioningState() { return provisioningState; } @@ -117,21 +104,11 @@ public class ClusterResponse { * * @return the cluster's security type */ - public String getSecurityType() { + @ApiModelProperty(name = ClusterResourceProvider.SECURITY_TYPE) + public SecurityType getSecurityType() { return securityType; } - /** - * Sets the cluster's security type. - * <p/> - * See {@link org.apache.ambari.server.state.SecurityType} for relevant values. - * - * @param securityType a String declaring the cluster's security type - */ - public void setSecurityType(String securityType) { - this.securityType = securityType; - } - @Override public String toString() { StringBuilder sb = new StringBuilder(); @@ -165,37 +142,25 @@ public class ClusterResponse { return false; } - ClusterResponse that = (ClusterResponse) o; + ClusterResponse other = (ClusterResponse) o; - if (clusterId != null ? - !clusterId.equals(that.clusterId) : that.clusterId != null) { - return false; - } - if (clusterName != null ? - !clusterName.equals(that.clusterName) : that.clusterName != null) { - return false; - } - - return true; + return Objects.equals(clusterId, other.clusterId) && + Objects.equals(clusterName, other.clusterName); } @Override public int hashCode() { - int result = clusterId != null ? clusterId.intValue() : 0; - result = 71 * result + (clusterName != null ? clusterName.hashCode() : 0); - return result; + return Objects.hash(clusterId, clusterName); } /** * @return the desiredStackVersion */ + @ApiModelProperty(name = ClusterResourceProvider.VERSION) public String getDesiredStackVersion() { return desiredStackVersion; } - /** - * @param configs - */ public void setDesiredConfigs(Map<String, DesiredConfig> configs) { desiredConfigs = configs; } @@ -203,6 +168,7 @@ public class ClusterResponse { /** * @return the desired configs */ + @ApiModelProperty(name = ClusterResourceProvider.DESIRED_CONFIGS) public Map<String, DesiredConfig> getDesiredConfigs() { return desiredConfigs; } @@ -210,17 +176,20 @@ public class ClusterResponse { /** * @return total number of hosts in the cluster */ - public Integer getTotalHosts() { + @ApiModelProperty(name = ClusterResourceProvider.TOTAL_HOSTS) + public int getTotalHosts() { return totalHosts; } /** * @return cluster health report */ + @ApiModelProperty(name = ClusterResourceProvider.HEALTH_REPORT) public ClusterHealthReport getClusterHealthReport() { return clusterHealthReport; } + @ApiModelProperty(name = ClusterResourceProvider.DESIRED_SERVICE_CONFIG_VERSIONS) public Map<String, Collection<ServiceConfigVersionResponse>> getDesiredServiceConfigVersions() { return desiredServiceConfigVersions; } @@ -233,7 +202,14 @@ public class ClusterResponse { this.credentialStoreServiceProperties = credentialServiceProperties; } + @ApiModelProperty(name = ClusterResourceProvider.CREDENTIAL_STORE_PROPERTIES) public Map<String, String> getCredentialStoreServiceProperties() { return credentialStoreServiceProperties; } + + public interface ClusterResponseWrapper extends ApiModel { + @ApiModelProperty(name = ClusterResourceProvider.RESPONSE_KEY) + @SuppressWarnings("unused") + ClusterResponse getClusterResponse(); + } } http://git-wip-us.apache.org/repos/asf/ambari/blob/275525b2/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterServiceArtifactRequest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterServiceArtifactRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterServiceArtifactRequest.java index ac37c0f..bc88469 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterServiceArtifactRequest.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterServiceArtifactRequest.java @@ -1,7 +1,26 @@ +/* + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.ambari.server.controller; import java.util.Map; +import org.apache.ambari.server.controller.internal.ArtifactResourceProvider; + import io.swagger.annotations.ApiModelProperty; /** @@ -10,17 +29,18 @@ import io.swagger.annotations.ApiModelProperty; * * The interface is not actually implemented, it only carries swagger annotations. */ +@SuppressWarnings("unused") public interface ClusterServiceArtifactRequest extends ApiModel { - @ApiModelProperty(name = "Artifacts") - public ClusterServiceArtifactRequestInfo getClusterServiceArtifactRequestInfo(); + @ApiModelProperty(name = ArtifactResourceProvider.RESPONSE_KEY) + ClusterServiceArtifactRequestInfo getClusterServiceArtifactRequestInfo(); - @ApiModelProperty(name = "artifact_data") - public Map<String, Object> getArtifactData(); + @ApiModelProperty(name = ArtifactResourceProvider.ARTIFACT_DATA_PROPERTY) + Map<String, Object> getArtifactData(); - public interface ClusterServiceArtifactRequestInfo { - @ApiModelProperty(name = "artifact_name") - public String getArtifactName(); + interface ClusterServiceArtifactRequestInfo { + @ApiModelProperty(name = ArtifactResourceProvider.ARTIFACT_NAME) + String getArtifactName(); } } http://git-wip-us.apache.org/repos/asf/ambari/blob/275525b2/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterServiceArtifactResponse.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterServiceArtifactResponse.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterServiceArtifactResponse.java index 29b8c94..de967f2 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterServiceArtifactResponse.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterServiceArtifactResponse.java @@ -1,4 +1,4 @@ -/** +/* * 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 @@ -20,6 +20,8 @@ package org.apache.ambari.server.controller; import java.util.Map; +import org.apache.ambari.server.controller.internal.ArtifactResourceProvider; + import io.swagger.annotations.ApiModelProperty; /** @@ -29,21 +31,22 @@ import io.swagger.annotations.ApiModelProperty; */ public interface ClusterServiceArtifactResponse { - @ApiModelProperty(name = "Artifacts") - public ClusterServiceArtifactResponseInfo getClusterServiceArtifactResponseInfo(); + @ApiModelProperty(name = ArtifactResourceProvider.RESPONSE_KEY) + @SuppressWarnings("unused") + ClusterServiceArtifactResponseInfo getClusterServiceArtifactResponseInfo(); - @ApiModelProperty(name = "artifact_data") - public Map<String, Object> getArtifactData(); + @ApiModelProperty(name = ArtifactResourceProvider.ARTIFACT_DATA_PROPERTY) + Map<String, Object> getArtifactData(); - public interface ClusterServiceArtifactResponseInfo { - @ApiModelProperty(name = "artifact_name") - public String getArtifactName(); + interface ClusterServiceArtifactResponseInfo { + @ApiModelProperty(name = ArtifactResourceProvider.ARTIFACT_NAME) + String getArtifactName(); - @ApiModelProperty(name = "cluster_name") - public String getClusterName(); + @ApiModelProperty(name = ArtifactResourceProvider.CLUSTER_NAME) + String getClusterName(); - @ApiModelProperty(name = "service_name") - public String getServiceName(); + @ApiModelProperty(name = ArtifactResourceProvider.SERVICE_NAME) + String getServiceName(); } } http://git-wip-us.apache.org/repos/asf/ambari/blob/275525b2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ArtifactResourceProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ArtifactResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ArtifactResourceProvider.java index a6a731c..cb8c7bb 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ArtifactResourceProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ArtifactResourceProvider.java @@ -1,4 +1,4 @@ -/** +/* * 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 @@ -61,16 +61,15 @@ import com.google.inject.Inject; //todo: implement ExtendedResourceProvider??? @StaticallyInject public class ArtifactResourceProvider extends AbstractResourceProvider { - /** - * artifact name - */ - public static final String ARTIFACT_NAME_PROPERTY = - PropertyHelper.getPropertyId("Artifacts", "artifact_name"); - /** - * artifact data - */ + public static final String RESPONSE_KEY = "Artifacts"; + public static final String ARTIFACT_NAME = "artifact_name"; + public static final String CLUSTER_NAME = "cluster_name"; + public static final String SERVICE_NAME = "service_name"; public static final String ARTIFACT_DATA_PROPERTY = "artifact_data"; + public static final String ARTIFACT_NAME_PROPERTY = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + ARTIFACT_NAME; + public static final String CLUSTER_NAME_PROPERTY = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + CLUSTER_NAME; + public static final String SERVICE_NAME_PROPERTY = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + SERVICE_NAME; /** * primary key fields @@ -118,7 +117,7 @@ public class ArtifactResourceProvider extends AbstractResourceProvider { private static ArtifactDAO artifactDAO; - /** + /* * set resource properties, pk and fk's */ static { @@ -368,7 +367,7 @@ public class ArtifactResourceProvider extends AbstractResourceProvider { public Void invoke() throws AmbariException { // flatten out key properties as is expected by createForeignKeyMap() Map<String, Object> keyProperties = new HashMap<>(); - for (Map.Entry<String, Object> entry : resource.getPropertiesMap().get("Artifacts").entrySet()) { + for (Map.Entry<String, Object> entry : resource.getPropertiesMap().get(RESPONSE_KEY).entrySet()) { keyProperties.put(String.format("Artifacts/%s", entry.getKey()), entry.getValue()); } @@ -667,7 +666,6 @@ public class ArtifactResourceProvider extends AbstractResourceProvider { /** * cluster name property name */ - private static final String CLUSTER_NAME = PropertyHelper.getPropertyId("Artifacts", "cluster_name"); @Override public void setManagementController(AmbariManagementController controller) { @@ -681,7 +679,7 @@ public class ArtifactResourceProvider extends AbstractResourceProvider { @Override public String getFKPropertyName() { - return CLUSTER_NAME; + return CLUSTER_NAME_PROPERTY; } @Override @@ -708,7 +706,7 @@ public class ArtifactResourceProvider extends AbstractResourceProvider { public boolean instanceExists(Map<Resource.Type, String> keyMap, Map<String, Object> properties) throws AmbariException { try { - String clusterName = String.valueOf(properties.get(CLUSTER_NAME)); + String clusterName = String.valueOf(properties.get(CLUSTER_NAME_PROPERTY)); controller.getClusters().getCluster(clusterName); return true; } catch (ObjectNotFoundException e) { @@ -730,7 +728,6 @@ public class ArtifactResourceProvider extends AbstractResourceProvider { /** * service name property name */ - private static final String SERVICE_NAME = PropertyHelper.getPropertyId("Artifacts", "service_name"); @Override public void setManagementController(AmbariManagementController controller) { @@ -744,7 +741,7 @@ public class ArtifactResourceProvider extends AbstractResourceProvider { @Override public String getFKPropertyName() { - return SERVICE_NAME; + return SERVICE_NAME_PROPERTY; } @Override @@ -764,7 +761,7 @@ public class ArtifactResourceProvider extends AbstractResourceProvider { @Override public Map<Resource.Type, String> getForeignKeyInfo() { - return Collections.singletonMap(Resource.Type.Cluster, "Artifacts/cluster_name"); + return Collections.singletonMap(Resource.Type.Cluster, CLUSTER_NAME_PROPERTY); } @Override @@ -774,7 +771,7 @@ public class ArtifactResourceProvider extends AbstractResourceProvider { String clusterName = String.valueOf(properties.get(keyMap.get(Resource.Type.Cluster))); try { Cluster cluster = controller.getClusters().getCluster(clusterName); - cluster.getService(String.valueOf(properties.get(SERVICE_NAME))); + cluster.getService(String.valueOf(properties.get(SERVICE_NAME_PROPERTY))); return true; } catch (ObjectNotFoundException e) { // doesn't exist http://git-wip-us.apache.org/repos/asf/ambari/blob/275525b2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java index ae17de4..cc3234b 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java @@ -1,4 +1,4 @@ -/** +/* * 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 @@ -69,28 +69,41 @@ public class ClusterResourceProvider extends AbstractControllerResourceProvider // ----- Property ID constants --------------------------------------------- // Clusters - public static final String CLUSTER_ID_PROPERTY_ID = PropertyHelper.getPropertyId("Clusters", "cluster_id"); - public static final String CLUSTER_NAME_PROPERTY_ID = PropertyHelper.getPropertyId("Clusters", "cluster_name"); - public static final String CLUSTER_VERSION_PROPERTY_ID = PropertyHelper.getPropertyId("Clusters", "version"); - public static final String CLUSTER_PROVISIONING_STATE_PROPERTY_ID = PropertyHelper.getPropertyId("Clusters", "provisioning_state"); - public static final String CLUSTER_SECURITY_TYPE_PROPERTY_ID = PropertyHelper.getPropertyId("Clusters", "security_type"); - public static final String CLUSTER_DESIRED_CONFIGS_PROPERTY_ID = PropertyHelper.getPropertyId("Clusters", "desired_configs"); - public static final String CLUSTER_DESIRED_SERVICE_CONFIG_VERSIONS_PROPERTY_ID = PropertyHelper.getPropertyId("Clusters", "desired_service_config_versions"); - public static final String CLUSTER_TOTAL_HOSTS_PROPERTY_ID = PropertyHelper.getPropertyId("Clusters", "total_hosts"); - public static final String CLUSTER_HEALTH_REPORT_PROPERTY_ID = PropertyHelper.getPropertyId("Clusters", "health_report"); - public static final String CLUSTER_CREDENTIAL_STORE_PROPERTIES_PROPERTY_ID = PropertyHelper.getPropertyId("Clusters", "credential_store_properties"); - public static final String BLUEPRINT_PROPERTY_ID = PropertyHelper.getPropertyId(null, "blueprint"); - public static final String SECURITY_PROPERTY_ID = PropertyHelper.getPropertyId(null, "security"); - public static final String CREDENTIALS_PROPERTY_ID = PropertyHelper.getPropertyId(null, "credentials"); - public static final String QUICKLINKS_PROFILE_PROPERTY_ID = PropertyHelper.getPropertyId(null, "quicklinks_profile"); - public static final String SESSION_ATTRIBUTES_PROPERTY_ID = "session_attributes"; - - public static final String CLUSTER_REPO_VERSION = "Clusters/repository_version"; + public static final String RESPONSE_KEY = "Clusters"; + public static final String ALL_PROPERTIES = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "*"; + public static final String CLUSTER_ID = "cluster_id"; + public static final String CLUSTER_NAME = "cluster_name"; + public static final String VERSION = "version"; + public static final String PROVISIONING_STATE = "provisioning_state"; + public static final String SECURITY_TYPE = "security_type"; + public static final String DESIRED_CONFIGS = "desired_configs"; + public static final String DESIRED_SERVICE_CONFIG_VERSIONS = "desired_service_config_versions"; + public static final String TOTAL_HOSTS = "total_hosts"; + public static final String HEALTH_REPORT = "health_report"; + public static final String CREDENTIAL_STORE_PROPERTIES = "credential_store_properties"; + public static final String REPO_VERSION = "repository_version"; + public static final String CLUSTER_ID_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + CLUSTER_ID; + public static final String CLUSTER_NAME_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + CLUSTER_NAME; + public static final String CLUSTER_VERSION_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + VERSION; + public static final String CLUSTER_PROVISIONING_STATE_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + PROVISIONING_STATE; + public static final String CLUSTER_SECURITY_TYPE_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + SECURITY_TYPE; + public static final String CLUSTER_DESIRED_CONFIGS_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + DESIRED_CONFIGS; + public static final String CLUSTER_DESIRED_SERVICE_CONFIG_VERSIONS_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + DESIRED_SERVICE_CONFIG_VERSIONS; + public static final String CLUSTER_TOTAL_HOSTS_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + TOTAL_HOSTS; + public static final String CLUSTER_HEALTH_REPORT_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + HEALTH_REPORT; + public static final String CLUSTER_CREDENTIAL_STORE_PROPERTIES_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + CREDENTIAL_STORE_PROPERTIES; + public static final String CLUSTER_REPO_VERSION = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + REPO_VERSION; + + static final String BLUEPRINT = "blueprint"; + private static final String SECURITY = "security"; + static final String CREDENTIALS = "credentials"; + private static final String QUICKLINKS_PROFILE = "quicklinks_profile"; + private static final String SESSION_ATTRIBUTES = "session_attributes"; /** * The session attributes property prefix. */ - private static final String SESSION_ATTRIBUTES_PROPERTY_PREFIX = SESSION_ATTRIBUTES_PROPERTY_ID + "/"; + private static final String SESSION_ATTRIBUTES_PROPERTY_PREFIX = SESSION_ATTRIBUTES + "/"; /** * Request info property ID. Allow internal getResources call to bypass permissions check. @@ -148,12 +161,12 @@ public class ClusterResourceProvider extends AbstractControllerResourceProvider propertyIds.add(CLUSTER_TOTAL_HOSTS_PROPERTY_ID); propertyIds.add(CLUSTER_HEALTH_REPORT_PROPERTY_ID); propertyIds.add(CLUSTER_CREDENTIAL_STORE_PROPERTIES_PROPERTY_ID); - propertyIds.add(BLUEPRINT_PROPERTY_ID); - propertyIds.add(SESSION_ATTRIBUTES_PROPERTY_ID); - propertyIds.add(SECURITY_PROPERTY_ID); - propertyIds.add(CREDENTIALS_PROPERTY_ID); + propertyIds.add(BLUEPRINT); + propertyIds.add(SESSION_ATTRIBUTES); + propertyIds.add(SECURITY); + propertyIds.add(CREDENTIALS); propertyIds.add(CLUSTER_REPO_VERSION); - propertyIds.add(QUICKLINKS_PROFILE_PROPERTY_ID); + propertyIds.add(QUICKLINKS_PROFILE); } @@ -265,23 +278,17 @@ public class ClusterResourceProvider extends AbstractControllerResourceProvider // Allow internal call to bypass permissions check. for (ClusterResponse response : responses) { - - String clusterName = response.getClusterName(); - Resource resource = new ResourceImpl(Resource.Type.Cluster); setResourceProperty(resource, CLUSTER_ID_PROPERTY_ID, response.getClusterId(), requestedIds); - setResourceProperty(resource, CLUSTER_NAME_PROPERTY_ID, clusterName, requestedIds); - setResourceProperty(resource, CLUSTER_PROVISIONING_STATE_PROPERTY_ID, response.getProvisioningState(), requestedIds); - setResourceProperty(resource, CLUSTER_SECURITY_TYPE_PROPERTY_ID, response.getSecurityType(), requestedIds); + setResourceProperty(resource, CLUSTER_NAME_PROPERTY_ID, response.getClusterName(), requestedIds); + setResourceProperty(resource, CLUSTER_PROVISIONING_STATE_PROPERTY_ID, response.getProvisioningState().name(), requestedIds); + setResourceProperty(resource, CLUSTER_SECURITY_TYPE_PROPERTY_ID, response.getSecurityType().name(), requestedIds); setResourceProperty(resource, CLUSTER_DESIRED_CONFIGS_PROPERTY_ID, response.getDesiredConfigs(), requestedIds); - setResourceProperty(resource, CLUSTER_DESIRED_SERVICE_CONFIG_VERSIONS_PROPERTY_ID, - response.getDesiredServiceConfigVersions(), requestedIds); + setResourceProperty(resource, CLUSTER_DESIRED_SERVICE_CONFIG_VERSIONS_PROPERTY_ID, response.getDesiredServiceConfigVersions(), requestedIds); setResourceProperty(resource, CLUSTER_TOTAL_HOSTS_PROPERTY_ID, response.getTotalHosts(), requestedIds); setResourceProperty(resource, CLUSTER_HEALTH_REPORT_PROPERTY_ID, response.getClusterHealthReport(), requestedIds); setResourceProperty(resource, CLUSTER_CREDENTIAL_STORE_PROPERTIES_PROPERTY_ID, response.getCredentialStoreServiceProperties(), requestedIds); - - resource.setProperty(CLUSTER_VERSION_PROPERTY_ID, - response.getDesiredStackVersion()); + setResourceProperty(resource, CLUSTER_VERSION_PROPERTY_ID, response.getDesiredStackVersion(), requestedIds); if (LOG.isDebugEnabled()) { LOG.debug("Adding ClusterResponse to resource" @@ -424,13 +431,12 @@ public class ClusterResourceProvider extends AbstractControllerResourceProvider cr.setRepositoryVersion(properties.get(CLUSTER_REPO_VERSION).toString()); } - List<ConfigurationRequest> configRequests = getConfigurationRequests("Clusters", properties); - - ServiceConfigVersionRequest serviceConfigVersionRequest = getServiceConfigVersionRequest("Clusters", properties); - - if (!configRequests.isEmpty()) + List<ConfigurationRequest> configRequests = getConfigurationRequests(RESPONSE_KEY, properties); + if (!configRequests.isEmpty()) { cr.setDesiredConfig(configRequests); + } + ServiceConfigVersionRequest serviceConfigVersionRequest = getServiceConfigVersionRequest(RESPONSE_KEY, properties); if (serviceConfigVersionRequest != null) { cr.setServiceConfigVersionRequest(serviceConfigVersionRequest); } @@ -464,7 +470,7 @@ public class ClusterResourceProvider extends AbstractControllerResourceProvider /** * Helper method for creating rollback request */ - protected ServiceConfigVersionRequest getServiceConfigVersionRequest(String parentCategory, Map<String, Object> properties) { + protected static ServiceConfigVersionRequest getServiceConfigVersionRequest(String parentCategory, Map<String, Object> properties) { ServiceConfigVersionRequest serviceConfigVersionRequest = null; for (Map.Entry<String, Object> entry : properties.entrySet()) { @@ -519,7 +525,7 @@ public class ClusterResourceProvider extends AbstractControllerResourceProvider NoSuchParentResourceException { LOG.info("Creating Cluster '" + properties.get(CLUSTER_NAME_PROPERTY_ID) + - "' based on blueprint '" + String.valueOf(properties.get(BLUEPRINT_PROPERTY_ID)) + "'."); + "' based on blueprint '" + String.valueOf(properties.get(BLUEPRINT)) + "'."); String rawRequestBody = requestInfoProperties.get(Request.REQUEST_INFO_BODY_PROPERTY); Map<String, Object> rawBodyMap = jsonSerializer.<Map<String, Object>>fromJson(rawRequestBody, Map.class); http://git-wip-us.apache.org/repos/asf/ambari/blob/275525b2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ProvisionClusterRequest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ProvisionClusterRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ProvisionClusterRequest.java index 1a14b01..eb02637 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ProvisionClusterRequest.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ProvisionClusterRequest.java @@ -213,7 +213,7 @@ public class ProvisionClusterRequest extends BaseClusterRequest { private Map<String, Credential> parseCredentials(Map<String, Object> properties) throws InvalidTopologyTemplateException { HashMap<String, Credential> credentialHashMap = new HashMap<>(); - Set<Map<String, String>> credentialsSet = (Set<Map<String, String>>) properties.get(ClusterResourceProvider.CREDENTIALS_PROPERTY_ID); + Set<Map<String, String>> credentialsSet = (Set<Map<String, String>>) properties.get(ClusterResourceProvider.CREDENTIALS); if (credentialsSet != null) { for (Map<String, String> credentialMap : credentialsSet) { String alias = Strings.emptyToNull(credentialMap.get("alias")); @@ -291,7 +291,7 @@ public class ProvisionClusterRequest extends BaseClusterRequest { * @throws NoSuchBlueprintException if specified blueprint doesn't exist */ private void parseBlueprint(Map<String, Object> properties) throws NoSuchStackException, NoSuchBlueprintException { - String blueprintName = String.valueOf(properties.get(ClusterResourceProvider.BLUEPRINT_PROPERTY_ID)); + String blueprintName = String.valueOf(properties.get(ClusterResourceProvider.BLUEPRINT)); // set blueprint field setBlueprint(getBlueprintFactory().getBlueprint(blueprintName)); http://git-wip-us.apache.org/repos/asf/ambari/blob/275525b2/ambari-server/src/test/java/org/apache/ambari/server/api/services/ClusterServiceTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/services/ClusterServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/services/ClusterServiceTest.java index cfc43f5..47b6e98 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/api/services/ClusterServiceTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/api/services/ClusterServiceTest.java @@ -1,4 +1,4 @@ -/** +/* * 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 @@ -95,45 +95,45 @@ public class ClusterServiceTest extends BaseServiceTest { args = new Object[] {getHttpHeaders(), getUriInfo(), "clusterName"}; listInvocations.add(new ServiceTestInvocation(Request.Type.DELETE, clusterService, m, args, null)); - //createArtifact + //createClusterArtifact clusterService = new TestClusterService(clusters, "clusterName"); - m = clusterService.getClass().getMethod("createArtifact", String.class, HttpHeaders.class, UriInfo.class, String.class, String.class); + m = clusterService.getClass().getMethod("createClusterArtifact", String.class, HttpHeaders.class, UriInfo.class, String.class, String.class); args = new Object[] {"body", getHttpHeaders(), getUriInfo(), "clusterName", "artifactName"}; listInvocations.add(new ServiceTestInvocation(Request.Type.POST, clusterService, m, args, "body")); - //getArtifact + //getClusterArtifact clusterService = new TestClusterService(clusters, "clusterName"); - m = clusterService.getClass().getMethod("getArtifact", String.class, HttpHeaders.class, UriInfo.class, String.class, String.class); + m = clusterService.getClass().getMethod("getClusterArtifact", String.class, HttpHeaders.class, UriInfo.class, String.class, String.class); args = new Object[] {"body", getHttpHeaders(), getUriInfo(), "clusterName", "artifact_name"}; listInvocations.add(new ServiceTestInvocation(Request.Type.GET, clusterService, m, args, "body")); - //getArtifacts + //getClusterArtifacts clusterService = new TestClusterService(clusters, "clusterName"); - m = clusterService.getClass().getMethod("getArtifacts", String.class, HttpHeaders.class, UriInfo.class, String.class); + m = clusterService.getClass().getMethod("getClusterArtifacts", String.class, HttpHeaders.class, UriInfo.class, String.class); args = new Object[] {"body", getHttpHeaders(), getUriInfo(), "clusterName"}; listInvocations.add(new ServiceTestInvocation(Request.Type.GET, clusterService, m, args, "body")); - //updateArtifact + //updateClusterArtifact clusterService = new TestClusterService(clusters, "clusterName"); - m = clusterService.getClass().getMethod("updateArtifact", String.class, HttpHeaders.class, UriInfo.class, String.class, String.class); + m = clusterService.getClass().getMethod("updateClusterArtifact", String.class, HttpHeaders.class, UriInfo.class, String.class, String.class); args = new Object[] {"body", getHttpHeaders(), getUriInfo(), "clusterName", "artifactName"}; listInvocations.add(new ServiceTestInvocation(Request.Type.PUT, clusterService, m, args, "body")); - //updateArtifacts + //updateClusterArtifacts clusterService = new TestClusterService(clusters, "clusterName"); - m = clusterService.getClass().getMethod("updateArtifacts", String.class, HttpHeaders.class, UriInfo.class, String.class); + m = clusterService.getClass().getMethod("updateClusterArtifacts", String.class, HttpHeaders.class, UriInfo.class, String.class); args = new Object[] {"body", getHttpHeaders(), getUriInfo(), "clusterName"}; listInvocations.add(new ServiceTestInvocation(Request.Type.PUT, clusterService, m, args, "body")); - //deleteArtifact + //deleteClusterArtifact clusterService = new TestClusterService(clusters, "clusterName"); - m = clusterService.getClass().getMethod("deleteArtifact", String.class, HttpHeaders.class, UriInfo.class, String.class, String.class); + m = clusterService.getClass().getMethod("deleteClusterArtifact", String.class, HttpHeaders.class, UriInfo.class, String.class, String.class); args = new Object[] {"body", getHttpHeaders(), getUriInfo(), "clusterName", "artifactName"}; listInvocations.add(new ServiceTestInvocation(Request.Type.DELETE, clusterService, m, args, "body")); - //deleteArtifacts + //deleteClusterArtifacts clusterService = new TestClusterService(clusters, "clusterName"); - m = clusterService.getClass().getMethod("deleteArtifacts", String.class, HttpHeaders.class, UriInfo.class, String.class); + m = clusterService.getClass().getMethod("deleteClusterArtifacts", String.class, HttpHeaders.class, UriInfo.class, String.class); args = new Object[] {"body", getHttpHeaders(), getUriInfo(), "clusterName"}; listInvocations.add(new ServiceTestInvocation(Request.Type.DELETE, clusterService, m, args, "body"));