Commit b5f3eb75 authored by Francesco Chicchiriccò's avatar Francesco Chicchiriccò
Browse files

ChoreographyApi changes: remove choreography_name from resize(), change String...

ChoreographyApi changes: remove choreography_name from resize(), change String to InputStream for chorSpec
parent f0a0e6fd
......@@ -19,6 +19,8 @@
package org.apache.brooklyn.rest.api;
import java.io.InputStream;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
......@@ -40,34 +42,34 @@ import io.swagger.annotations.ApiResponses;
public interface ChoreographyApi {
@GET
@Path("/start/{choreography_id}")
@Path("/start/{choreographyId}")
@ApiOperation(
value = "Start a running choreography."
)
public Response start(
@ApiParam(name = "choreography_id", value = "The ID of the choregraphy to start", required = true)
@PathParam("choreography_id")
String choreography_id);
Response start(
@ApiParam(name = "choreographyId", value = "The ID of the choregraphy to start", required = true)
@PathParam("choreographyId")
String choreographyId);
@GET
@Path("/stop/{choreography_id}")
@Path("/stop/{choreographyId}")
@ApiOperation(
value = "Stop a running choreography."
)
public Response stop(
@ApiParam(name = "choreography_id", value = "The ID of the choregraphy to stop", required = true)
@PathParam("choreography_id")
String choreography_id);
Response stop(
@ApiParam(name = "choreographyId", value = "The ID of the choregraphy to stop", required = true)
@PathParam("choreographyId")
String choreographyId);
@GET
@Path("/pause/{choreography_id}")
@Path("/pause/{choreographyId}")
@ApiOperation(
value = "Pause a running choreography."
)
public Response pause(
@ApiParam(name = "choreography_id", value = "The ID of the choregraphy to pause", required = true)
@PathParam("choreography_id")
String choreography_id);
Response pause(
@ApiParam(name = "choreographyId", value = "The ID of the choregraphy to pause", required = true)
@PathParam("choreographyId")
String choreographyId);
/*
......@@ -78,15 +80,14 @@ public interface ChoreographyApi {
@ApiError(code = 404, reason = "Choreography not existing")
})*/
@GET
@Path("/check_status/{choreography_id}")
public Response check_status(
@ApiParam(name = "choreography_id", value = "The ID of the choregraphy to check", required = true)
@PathParam("choreography_id")
String choreography_id);
@Path("/check_status/{choreographyId}")
Response check_status(
@ApiParam(name = "choreographyId", value = "The ID of the choregraphy to check", required = true)
@PathParam("choreographyId")
String choreographyId);
@POST
@Path("/deploy/{choreography_name}")
@Path("/deploy/{choreographyName}")
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
value = "Deploy a choreography onto a cloud environment.",
......@@ -96,14 +97,14 @@ public interface ChoreographyApi {
@ApiResponse(code = 404, message = "Undefined entity or location"),
@ApiResponse(code = 412, message = "Choreography already registered")
})
public Response deploy(
@ApiParam(name = "choreography_name", value = "Choreography ID or name", required = true)
@PathParam("choreography_name") String choreography_name,
@ApiParam(name = "choreography", value = "Choreography specifications", required = true)
String choreography);
Response deploy(
@ApiParam(name = "choreographyName", value = "Choreography name", required = true)
@PathParam("choreographyName") String choreographyName,
@ApiParam(name = "chorSpec", value = "Choreography specifications", required = true)
InputStream chorSpec);
@POST
@Path("/resize/{choreography_name}")
@Path("/resize/{choreographyId}")
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
value = "Resize VM pool running a running choreography.",
......@@ -113,10 +114,9 @@ public interface ChoreographyApi {
@ApiResponse(code = 404, message = "Undefined entity or location"),
@ApiResponse(code = 412, message = "Choreography already registered")
})
public Response resize(
@ApiParam(name = "choreography_name", value = "Choreography ID or name", required = true)
@PathParam("choreography_name") String choreography_name,
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);
}
......@@ -97,7 +97,7 @@ public class ChorRegistry {
try {
xml_dump = chor.getXML();
} catch (JAXBException e) {
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
......@@ -112,7 +112,7 @@ public class ChorRegistry {
else
try {
connection.set(chor_prefix + chor.getId(), chor.getXML());
} catch (JAXBException e) {
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
......@@ -121,7 +121,7 @@ public class ChorRegistry {
public void updateChoreography(Choreography chor) {
try {
connection.set(chor_prefix + chor.getId(), chor.getXML());
} catch (JAXBException e) {
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
......
......@@ -59,20 +59,19 @@ public class ChoreographyResource extends AbstractBrooklynRestResource implement
private static final Logger log = LoggerFactory.getLogger(ChoreographyResource.class);
@Override
public Response deploy(String choreography_name, String specifications) {
public Response deploy(String choreographName, InputStream chorSpec) {
String brooklyn_def = null;
ApplicationResource ar=new ApplicationResource();
log.info("Deploying choreography "+choreography_name+" | specifications: "+specifications);
log.info("Deploying choreography "+choreographName+" | specifications: {}", chorSpec);
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
InputStream xslt_content = this.getClass().getClassLoader().getSystemResourceAsStream("chor2brooklyn.xslt");
Transformer transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(xslt_content));
transformer.transform(new StreamSource(new StringReader(specifications)), new StreamResult(out));
brooklyn_def = out.toString().replace("CHOREOGRAPHY_NAME", choreography_name).replaceAll("\t"," ");
InputStream xsltContent = ClassLoader.getSystemResourceAsStream("chor2brooklyn.xslt");
Transformer transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(xsltContent));
transformer.transform(new StreamSource(chorSpec), new StreamResult(out));
brooklyn_def = out.toString().replace("CHOREOGRAPHY_NAME", choreographName).replaceAll("\t"," ");
log.info("Created YAML specs: "+brooklyn_def);
return ar.createFromYaml(brooklyn_def);
} catch (TransformerConfigurationException ie) {
// TODO Auto-generated catch block
ie.printStackTrace();
......@@ -85,7 +84,6 @@ public class ChoreographyResource extends AbstractBrooklynRestResource implement
}
return null;
}
@Override
......
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