Commit 74ab4472 authored by Francesco Chicchiriccò's avatar Francesco Chicchiriccò
Browse files

Review according to REST best-practices

parent 5330b8f6
......@@ -19,6 +19,7 @@ import java.io.InputStream;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.DELETE;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
......@@ -30,110 +31,103 @@ import javax.ws.rs.core.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
@Path("/v1/choreography")
@Api("Choreography")
public interface ChoreographyApi {
@GET
@Path("/start/{choreographyId}")
@POST
@Path("/{choreographyId}/start")
@ApiOperation(
value = "Start a running choreography."
)
Response start(
@ApiParam(name = "choreographyId", value = "The ID of the choregraphy to start", required = true)
@PathParam("choreographyId")
String choreographyId);
@PathParam("choreographyId") String choreographyId);
@GET
@Path("/stop/{choreographyId}")
@POST
@Path("/{choreographyId}/stop")
@ApiOperation(
value = "Stop a running choreography."
)
Response stop(
@ApiParam(name = "choreographyId", value = "The ID of the choregraphy to stop", required = true)
@PathParam("choreographyId")
String choreographyId);
@PathParam("choreographyId") String choreographyId);
@GET
@Path("/pause/{choreographyId}")
@POST
@Path("/{choreographyId}/pause")
@ApiOperation(
value = "Pause a running choreography."
)
Response pause(
@ApiParam(name = "choreographyId", value = "The ID of the choregraphy to pause", required = true)
@PathParam("choreographyId")
String choreographyId);
@PathParam("choreographyId") String choreographyId);
/*
@ApiOperation(
value = "Check the status of a choreography deployment process."
)
@ApiErrors(value = {
@ApiError(code = 404, reason = "Choreography not existing")
})*/
@GET
@Path("/check_status/{choreographyId}")
Response check_status(
@Path("/{choreographyId}/check_status")
Response checkStatus(
@ApiParam(name = "choreographyId", value = "The ID of the choregraphy to check", required = true)
@PathParam("choreographyId")
String choreographyId);
@PathParam("choreographyId") String choreographyId);
@POST
@Path("/deploy/{choreographyName}")
@Consumes(MediaType.APPLICATION_JSON)
@Path("/")
@Consumes(MediaType.APPLICATION_XML)
@ApiOperation(
value = "Deploy a choreography onto a cloud environment.",
response = org.apache.brooklyn.rest.domain.TaskSummary.class
)
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Undefined entity or location"),
@ApiResponse(code = 412, message = "Choreography already registered")
})
Response deploy(
@ApiParam(name = "choreographyName", value = "Choreography name", required = true)
@PathParam("choreographyName") String choreographyName,
@ApiParam(name = "chorSpec", value = "Choreography specifications", required = true)
InputStream chorSpec);
@QueryParam("choreographyName") String choreographyName,
@ApiParam(name = "chorSpec", value = "Choreography specifications", required = true) InputStream chorSpec);
@PUT
@Path("/update/{choreographyId}")
@Consumes(MediaType.APPLICATION_JSON)
@Path("/{choreographyId}")
@Consumes(MediaType.APPLICATION_XML)
@ApiOperation(
value = "Deploy a choreography onto a cloud environment.",
value = "Update an existing choreography onto a cloud environment.",
response = org.apache.brooklyn.rest.domain.TaskSummary.class
)
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Undefined entity or location"),
@ApiResponse(code = 412, message = "Choreography already registered")
})
Response update(
@ApiParam(name = "choreographyId", value = "Choreography ID", required = true)
@PathParam("choreographyId") String choreographyId,
@ApiParam(name = "choreographyName", value = "Choreography name", required = true)
@QueryParam("choreographyName") String choreographyName,
@ApiParam(name = "chorSpec", value = "Choreography specifications", required = true)
InputStream chorSpec);
@ApiParam(name = "chorSpec", value = "Choreography specifications", required = true) InputStream chorSpec);
@DELETE
@Path("/{choreographyId}")
@ApiOperation(
value = "Undeploy a choreography."
)
Response undeploy(
@ApiParam(name = "choreographyId", value = "The ID of the choregraphy to undeploy", required = true)
@PathParam("choreographyId") String choreographyId);
@PUT
@Path("/{choreographyId}/replaceService/{serviceRole}/{serviceName}")
@ApiOperation(
value = "Replace the given service endpoint",
response = org.apache.brooklyn.rest.domain.TaskSummary.class
)
Response replaceService(
@ApiParam(name = "choreographyId", value = "Choreography ID", required = true)
@PathParam("choreographyId") String choreographyId,
@ApiParam(name = "serviceRole", value = "Service name", required = true)
@PathParam("serviceRole") String serviceRole,
@ApiParam(name = "serviceName", value = "Service name", required = true)
@PathParam("serviceRole") String serviceName,
@QueryParam("serviceEndpoint") String serviceEndpoint);
@POST
@Path("/resize/{choreographyId}")
@Consumes(MediaType.APPLICATION_JSON)
@Path("/{choreographyId}/resize")
@ApiOperation(
value = "Resize VM pool running a running choreography.",
response = org.apache.brooklyn.rest.domain.TaskSummary.class
)
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Undefined entity or location"),
@ApiResponse(code = 412, message = "Choreography already registered")
})
Response resize(
@ApiParam(name = "choreographyId", value = "Choreography ID", required = true)
@PathParam("choreographyId") String choreographyId,
@ApiParam(name = "desired_pool_size", value = "Desired size of the VMs pool", required = true)
int desired_size);
@QueryParam("newSize") Integer newSize);
}
......@@ -94,9 +94,21 @@ public class ChoreographyResource extends AbstractBrooklynRestResource implement
return null;
}
@Override
public Response update(String choreographyId, String choreographyName, InputStream chorSpec) {
// TODO Auto-generated method stub
return Response.accepted().build();
}
@Override
public Response undeploy(String choreography_id) {
// TODO Auto-generated method stub
return Response.accepted().build();
}
@Override
public Response check_status(String choreography_id) {
public Response checkStatus(String choreography_id) {
// TODO Auto-generated method stub
for (Application a:mgmt().getApplications()) {
if (a.getApplicationId().equals(choreography_id)) {
......@@ -170,7 +182,7 @@ public class ChoreographyResource extends AbstractBrooklynRestResource implement
}
@Override
public Response resize(String choreography_name, int desired_size) {
public Response resize(String choreography_name, Integer desired_size) {
String symbolicName=choreography_name;
// TODO Auto-generated method stub
......@@ -190,18 +202,21 @@ public class ChoreographyResource extends AbstractBrooklynRestResource implement
return null;
}
@Override
public Response replaceService(
String choreographyId, String serviceRole, String serviceName, String serviceEndpoint) {
// TODO Auto-generated method stub
return null;
}
private ServiceGroup create_new(String xml) throws JAXBException{
JAXBContext context = JAXBContext.newInstance(ServiceGroup.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
ServiceGroup c = (ServiceGroup) unmarshaller.unmarshal(new StringReader(xml));
return c;
}
@Override
public Response update(String choreographyId, String choreographyName, InputStream chorSpec) {
return Response.accepted().build();
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment