Commit ae37ce55 authored by Alessio Carenini's avatar Alessio Carenini
Browse files

Added update method

parent f6beefaf
......@@ -30,6 +30,10 @@ import java.io.StringReader;
import java.util.Collection;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
......@@ -40,12 +44,16 @@ import javax.xml.transform.stream.StreamSource;
import org.apache.brooklyn.api.entity.Application;
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.entity.EntitySpec;
import org.apache.brooklyn.api.location.Location;
import org.apache.brooklyn.api.typereg.RegisteredType;
import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic;
import org.apache.brooklyn.core.mgmt.entitlement.Entitlements;
import org.apache.brooklyn.core.mgmt.entitlement.Entitlements.StringAndArgument;
import org.apache.brooklyn.core.typereg.RegisteredTypeLoadingContexts;
import org.apache.brooklyn.core.typereg.RegisteredTypePredicates;
import org.apache.brooklyn.entity.webapp.ControlledDynamicWebAppCluster;
import org.apache.brooklyn.entity.webapp.chorevolution.Choreography;
import org.apache.brooklyn.entity.webapp.chorevolution.ControlledDynamicChoreographyCluster;
import org.apache.brooklyn.rest.api.ChoreographyApi;
import org.apache.brooklyn.rest.util.WebResourceUtils;
......@@ -54,6 +62,8 @@ import org.slf4j.LoggerFactory;
import com.google.common.collect.Lists;
import eu.chorevolution.datamodel.ServiceGroup;
public class ChoreographyResource extends AbstractBrooklynRestResource implements ChoreographyApi {
private static final Logger log = LoggerFactory.getLogger(ChoreographyResource.class);
......@@ -61,6 +71,7 @@ public class ChoreographyResource extends AbstractBrooklynRestResource implement
@Override
public Response deploy(String choreography_name, String specifications) {
String brooklyn_def = null;
EntitySpec chor=null;
ApplicationResource ar=new ApplicationResource();
log.info("Deploying choreography "+choreography_name+" | specifications: "+specifications);
ByteArrayOutputStream out = new ByteArrayOutputStream();
......@@ -70,8 +81,12 @@ public class ChoreographyResource extends AbstractBrooklynRestResource implement
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"," ");
log.info("Created YAML specs: "+brooklyn_def);
return ar.createFromYaml(brooklyn_def);
ar.createFromYaml(brooklyn_def);
chor = mgmt().getTypeRegistry().createSpecFromPlan(null, brooklyn_def, RegisteredTypeLoadingContexts.spec(Choreography.class), EntitySpec.class);
return ar.launch(brooklyn_def, chor);
} catch (TransformerConfigurationException ie) {
// TODO Auto-generated catch block
......@@ -91,6 +106,12 @@ public class ChoreographyResource extends AbstractBrooklynRestResource implement
@Override
public Response check_status(String choreography_id) {
// TODO Auto-generated method stub
for (Application a:mgmt().getApplications()) {
if (a.getApplicationId().equals(choreography_id)) {
ServiceStateLogic.getExpectedState(a);
}
}
return null;
}
......@@ -177,5 +198,20 @@ public class ChoreographyResource extends AbstractBrooklynRestResource implement
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 choreography_name, String choreography) {
// TODO Auto-generated method stub
return null;
}
}
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