Commit 31d1bef7 authored by Francesco Chicchiricco's avatar Francesco Chicchiricco
Browse files

[CRV-278] Now ChoreographyService's create() and update() modify only the...

[CRV-278] Now ChoreographyService's create() and update() modify only the internal storage; a new enact() method is provide to actually involve the configured EE instance
parent 28116e80
/*
* Copyright 2017 The CHOReVOLUTION project.
* Copyright 2017 The CHOReVOLUTION project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -21,171 +21,167 @@ import javax.ws.rs.core.Response;
public class MonitoringResource implements MonitoringApi {
@Override
public Response getEngineStatus() {
EnactmentEngineStatusTO enactmentEngineStatusTO = new EnactmentEngineStatusTO();
enactmentEngineStatusTO.setKey("dummyKey");
enactmentEngineStatusTO.setRamUsage(4880);
enactmentEngineStatusTO.setRamTotal(13336);
enactmentEngineStatusTO.setStorageTotal(3024);
enactmentEngineStatusTO.setStorageUsage(628);
enactmentEngineStatusTO.setCpuUsageRatio(36.0);
enactmentEngineStatusTO.setVirtualMachinesCount(4);
return Response.ok(enactmentEngineStatusTO).build();
}
@Override
public Response getEngineVirtualMachines() {
VirtualMachineInfoTO info1 = new VirtualMachineInfoTO();
info1.setKey("vm001");
info1.setChorId("xx45671");
info1.setChorDisplay("In-store Marketing and Sales");
info1.setSysOp("Ubuntu 16.10");
info1.setIp("192.168.0.11");
info1.setHostname("localhost");
info1.setCpuCount(4);
info1.setCpuUsageRatio(30.5);
info1.setRamUsage(1500);
info1.setRamTotal(4096);
info1.setStorageUsage(100);
info1.setStorageTotal(1000);
info1.setIsChoreography(true);
info1.setIsLoadBalancer(false);
VirtualMachineInfoTO info2 = new VirtualMachineInfoTO();
info2.setKey("vm002");
info2.setChorId("xx45671");
info2.setChorDisplay("In-store Marketing and Sales");
info2.setSysOp("Ubuntu 16.10");
info2.setIp("192.168.0.12");
info2.setHostname("localhost");
info2.setCpuCount(2);
info2.setCpuUsageRatio(51);
info2.setRamUsage(400);
info2.setRamTotal(1048);
info2.setStorageUsage(100);
info2.setStorageTotal(512);
info2.setIsChoreography(false);
info2.setIsLoadBalancer(true);
VirtualMachineInfoTO info3 = new VirtualMachineInfoTO();
info3.setKey("vm003");
info3.setChorId("ww45672");
info3.setChorDisplay("Smart Mobility and Tourism");
info3.setSysOp("Ubuntu 16.10");
info3.setIp("192.168.0.13");
info3.setHostname("localhost");
info3.setCpuCount(4);
info3.setCpuUsageRatio(26.5);
info3.setRamUsage(2230);
info3.setRamTotal(4096);
info3.setStorageUsage(88);
info3.setStorageTotal(512);
info3.setIsChoreography(false);
info3.setIsLoadBalancer(true);
VirtualMachineInfoTO info4 = new VirtualMachineInfoTO();
info4.setKey("vm004");
info4.setChorId("ww45672");
info4.setChorDisplay("Smart Mobility and Tourism");
info4.setSysOp("Ubuntu 16.10");
info4.setIp("192.168.0.14");
info4.setHostname("localhost");
info4.setCpuCount(4);
info4.setCpuUsageRatio(44);
info4.setRamUsage(750);
info4.setRamTotal(4096);
info4.setStorageUsage(340);
info4.setStorageTotal(1000);
info4.setIsChoreography(true);
info4.setIsLoadBalancer(false);
VirtualMachineInfoTO[] result = new VirtualMachineInfoTO[4];
result[0] = info1;
result[1] = info2;
result[2] = info3;
result[3] = info4;
if(result == null) {
return Response.status(Response.Status.NOT_FOUND)
.entity("Error while acting on EE").build();
}
return Response.ok(result).build();
}
@Override
public Response getChorStatus(final String choreographyId) {
if (choreographyId == null || choreographyId.isEmpty()) {
return Response.serverError().entity("chorID cannot be blank").build();
}
EnactmentEngineStatusTO enactmentEngineStatusTO = new EnactmentEngineStatusTO();
enactmentEngineStatusTO.setKey("dummyKey");
enactmentEngineStatusTO.setRamUsage(1900);
enactmentEngineStatusTO.setRamTotal(5144);
enactmentEngineStatusTO.setStorageTotal(1512);
enactmentEngineStatusTO.setStorageUsage(200);
enactmentEngineStatusTO.setCpuUsageRatio(37.0);
enactmentEngineStatusTO.setVirtualMachinesCount(2);
return Response.ok(enactmentEngineStatusTO).build();
}
@Override
public Response getChorVirtualMachines(final String choreographyId) {
if (choreographyId == null || choreographyId.isEmpty()) {
return Response.serverError().entity("chorID cannot be blank").build();
}
VirtualMachineInfoTO info1 = new VirtualMachineInfoTO();
info1.setKey("vm001");
info1.setChorId(choreographyId);
info1.setChorDisplay("In-store Marketing and Sales");
info1.setSysOp("Ubuntu 16.10");
info1.setIp("192.168.0.11");
info1.setHostname("localhost");
info1.setCpuCount(4);
info1.setCpuUsageRatio(30.5);
info1.setRamUsage(1500);
info1.setRamTotal(4096);
info1.setStorageUsage(100);
info1.setStorageTotal(1000);
info1.setIsChoreography(true);
info1.setIsLoadBalancer(false);
VirtualMachineInfoTO info2 = new VirtualMachineInfoTO();
info2.setKey("vm002");
info2.setChorId(choreographyId);
info2.setChorDisplay("In-store Marketing and Sales");
info2.setSysOp("Ubuntu 16.10");
info2.setIp("192.168.0.12");
info2.setHostname("localhost");
info2.setCpuCount(2);
info2.setCpuUsageRatio(51);
info2.setRamUsage(400);
info2.setRamTotal(1048);
info2.setStorageUsage(100);
info2.setStorageTotal(512);
info2.setIsChoreography(false);
info2.setIsLoadBalancer(true);
VirtualMachineInfoTO[] result = new VirtualMachineInfoTO[2];
result[0] = info1;
result[1] = info2;
if(result == null) {
return Response.status(Response.Status.NOT_FOUND)
.entity("Choreografy not found for choreographyId: " + choreographyId).build();
}
return Response.ok(result).build();
}
@Override
public Response getEngineStatus() {
EnactmentEngineStatusTO enactmentEngineStatusTO = new EnactmentEngineStatusTO();
enactmentEngineStatusTO.setKey("dummyKey");
enactmentEngineStatusTO.setRamUsage(4880);
enactmentEngineStatusTO.setRamTotal(13336);
enactmentEngineStatusTO.setStorageTotal(3024);
enactmentEngineStatusTO.setStorageUsage(628);
enactmentEngineStatusTO.setCpuUsageRatio(36.0);
enactmentEngineStatusTO.setVirtualMachinesCount(4);
return Response.ok(enactmentEngineStatusTO).build();
}
@Override
public Response getEngineVirtualMachines() {
VirtualMachineInfoTO info1 = new VirtualMachineInfoTO();
info1.setKey("vm001");
info1.setChorId("xx45671");
info1.setChorDisplay("In-store Marketing and Sales");
info1.setSysOp("Ubuntu 16.10");
info1.setIp("192.168.0.11");
info1.setHostname("localhost");
info1.setCpuCount(4);
info1.setCpuUsageRatio(30.5);
info1.setRamUsage(1500);
info1.setRamTotal(4096);
info1.setStorageUsage(100);
info1.setStorageTotal(1000);
info1.setIsChoreography(true);
info1.setIsLoadBalancer(false);
VirtualMachineInfoTO info2 = new VirtualMachineInfoTO();
info2.setKey("vm002");
info2.setChorId("xx45671");
info2.setChorDisplay("In-store Marketing and Sales");
info2.setSysOp("Ubuntu 16.10");
info2.setIp("192.168.0.12");
info2.setHostname("localhost");
info2.setCpuCount(2);
info2.setCpuUsageRatio(51);
info2.setRamUsage(400);
info2.setRamTotal(1048);
info2.setStorageUsage(100);
info2.setStorageTotal(512);
info2.setIsChoreography(false);
info2.setIsLoadBalancer(true);
VirtualMachineInfoTO info3 = new VirtualMachineInfoTO();
info3.setKey("vm003");
info3.setChorId("ww45672");
info3.setChorDisplay("Smart Mobility and Tourism");
info3.setSysOp("Ubuntu 16.10");
info3.setIp("192.168.0.13");
info3.setHostname("localhost");
info3.setCpuCount(4);
info3.setCpuUsageRatio(26.5);
info3.setRamUsage(2230);
info3.setRamTotal(4096);
info3.setStorageUsage(88);
info3.setStorageTotal(512);
info3.setIsChoreography(false);
info3.setIsLoadBalancer(true);
VirtualMachineInfoTO info4 = new VirtualMachineInfoTO();
info4.setKey("vm004");
info4.setChorId("ww45672");
info4.setChorDisplay("Smart Mobility and Tourism");
info4.setSysOp("Ubuntu 16.10");
info4.setIp("192.168.0.14");
info4.setHostname("localhost");
info4.setCpuCount(4);
info4.setCpuUsageRatio(44);
info4.setRamUsage(750);
info4.setRamTotal(4096);
info4.setStorageUsage(340);
info4.setStorageTotal(1000);
info4.setIsChoreography(true);
info4.setIsLoadBalancer(false);
VirtualMachineInfoTO[] result = new VirtualMachineInfoTO[4];
result[0] = info1;
result[1] = info2;
result[2] = info3;
result[3] = info4;
if (result == null) {
return Response.status(Response.Status.NOT_FOUND)
.entity("Error while acting on EE").build();
}
return Response.ok(result).build();
}
@Override
public Response getChorStatus(final String choreographyId) {
if (choreographyId == null || choreographyId.isEmpty()) {
return Response.serverError().entity("chorID cannot be blank").build();
}
EnactmentEngineStatusTO enactmentEngineStatusTO = new EnactmentEngineStatusTO();
enactmentEngineStatusTO.setKey("dummyKey");
enactmentEngineStatusTO.setRamUsage(1900);
enactmentEngineStatusTO.setRamTotal(5144);
enactmentEngineStatusTO.setStorageTotal(1512);
enactmentEngineStatusTO.setStorageUsage(200);
enactmentEngineStatusTO.setCpuUsageRatio(37.0);
enactmentEngineStatusTO.setVirtualMachinesCount(2);
return Response.ok(enactmentEngineStatusTO).build();
}
@Override
public Response getChorVirtualMachines(final String choreographyId) {
if (choreographyId == null || choreographyId.isEmpty()) {
return Response.serverError().entity("chorID cannot be blank").build();
}
VirtualMachineInfoTO info1 = new VirtualMachineInfoTO();
info1.setKey("vm001");
info1.setChorId(choreographyId);
info1.setChorDisplay("In-store Marketing and Sales");
info1.setSysOp("Ubuntu 16.10");
info1.setIp("192.168.0.11");
info1.setHostname("localhost");
info1.setCpuCount(4);
info1.setCpuUsageRatio(30.5);
info1.setRamUsage(1500);
info1.setRamTotal(4096);
info1.setStorageUsage(100);
info1.setStorageTotal(1000);
info1.setIsChoreography(true);
info1.setIsLoadBalancer(false);
VirtualMachineInfoTO info2 = new VirtualMachineInfoTO();
info2.setKey("vm002");
info2.setChorId(choreographyId);
info2.setChorDisplay("In-store Marketing and Sales");
info2.setSysOp("Ubuntu 16.10");
info2.setIp("192.168.0.12");
info2.setHostname("localhost");
info2.setCpuCount(2);
info2.setCpuUsageRatio(51);
info2.setRamUsage(400);
info2.setRamTotal(1048);
info2.setStorageUsage(100);
info2.setStorageTotal(512);
info2.setIsChoreography(false);
info2.setIsLoadBalancer(true);
VirtualMachineInfoTO[] result = new VirtualMachineInfoTO[2];
result[0] = info1;
result[1] = info2;
if (result == null) {
return Response.status(Response.Status.NOT_FOUND)
.entity("Choreografy not found for choreographyId: " + choreographyId).build();
}
return Response.ok(result).build();
}
}
......@@ -31,6 +31,8 @@ public final class ChorevolutionEntitlement {
public static final String CHOREOGRAPHY_DELETE = "CHOREOGRAPHY_DELETE";
public static final String CHOREOGRAPHY_ENACT = "CHOREOGRAPHY_ENACT";
public static final String NOTIFY_COMPLETION = "NOTIFY_COMPLETION";
public static final String ON_CHOREOGRAPHY = "ON_CHOREOGRAPHY";
......
/*
/*
* Copyright 2015 The CHOReVOLUTION project
*
* Licensed under the Apache License, Version 2.0 (the "License");
......@@ -18,23 +18,23 @@ package eu.chorevolution.idm.common.types;
public enum ChoreographyAction {
/**
* User requests start to be accepted.
* Only available after given choreography was subjected to {@link STOP}..
* Only available after given choreography was subjected to {@link #STOP}..
*/
START,
/**
* No more user requests are accepted.
* Only available after given choreography was subjected to {@link START}..
* Only available after given choreography was subjected to {@link #START}..
*/
STOP,
/**
* Freezes all choreography resources.
* Each node is put in a frozen state.
* Only available after given choreography was subjected to {@link START}..
* Only available after given choreography was subjected to {@link #START}..
*/
FREEZE,
/**
* Unfreezes all choreography resources.
* Only available after given choreography was subjected to {@link FREEZE}..
* Unfreezes all choreography resources.
* Only available after given choreography was subjected to {@link #FREEZE}..
* Each node is back available again.
*/
UNFREEZE,
......@@ -42,4 +42,5 @@ public enum ChoreographyAction {
* Sets the minimum number of nodes running each service group of the given choreography.
*/
RESIZE;
}
......@@ -568,12 +568,12 @@ we are happy to inform you that the password request was execute successfully fo
multivalue="0" readonly="0" type="String" uniqueConstraint="0" anyTypeClass_id="Service Role"/>
<SyncopeSchema id="id"/>
<PlainSchema id="id" mandatoryCondition="true"
<PlainSchema id="id" mandatoryCondition="false"
multivalue="0" readonly="0" type="String" uniqueConstraint="1" anyTypeClass_id="Choreography"/>
<SyncopeSchema id="status"/>
<PlainSchema id="status" mandatoryCondition="true"
multivalue="0" readonly="0" type="Enum" uniqueConstraint="0" enumerationValues="STARTED;FROZEN;STOPPED;PENDING DELETE"
multivalue="0" readonly="0" type="Enum" uniqueConstraint="0" enumerationValues="PENDING CREATE;PENDING UPDATE;STARTED;FROZEN;STOPPED;PENDING DELETE"
anyTypeClass_id="Choreography"/>
<SyncopeSchema id="description"/>
......
......@@ -573,12 +573,12 @@ we are happy to inform you that the password request was execute successfully fo
multivalue="0" readonly="0" type="String" uniqueConstraint="0" anyTypeClass_id="Service Role"/>
 
<SyncopeSchema id="id"/>
<PlainSchema id="id" mandatoryCondition="true"
<PlainSchema id="id" mandatoryCondition="false"
multivalue="0" readonly="0" type="String" uniqueConstraint="1" anyTypeClass_id="Choreography"/>
 
<SyncopeSchema id="status"/>
<PlainSchema id="status" mandatoryCondition="true"
multivalue="0" readonly="0" type="Enum" uniqueConstraint="0" enumerationValues="STARTED;FROZEN;STOPPED;PENDING DELETE"
multivalue="0" readonly="0" type="Enum" uniqueConstraint="0" enumerationValues="PENDING CREATE;PENDING UPDATE;STARTED;FROZEN;STOPPED;PENDING DELETE"
anyTypeClass_id="Choreography"/>
 
<SyncopeSchema id="chorSpec"/>
......@@ -26,7 +26,6 @@ import org.apache.syncope.client.console.commons.Constants;
import org.apache.syncope.client.console.pages.BasePage;
import org.apache.syncope.client.console.pages.ChoreographyPage;
import org.apache.syncope.client.console.pages.ChoreographyDetailPage;
import static org.apache.syncope.client.console.panels.DirectoryPanel.LOG;
import org.apache.syncope.client.console.rest.AnyTypeClassRestClient;
import org.apache.syncope.client.console.rest.AnyTypeRestClient;
import org.apache.syncope.client.console.rest.ChoreographyRestClient;
......@@ -86,14 +85,16 @@ public class ChoreographyDirectoryPanel extends GroupDirectoryPanel {
columns.add(new AttrColumn<>("description", SchemaType.PLAIN));
columns.add(new AbstractColumn<GroupTO, String>(new ResourceModel("", "Enactment Engine")) {
private static final long serialVersionUID = 2054811145491901166L;
@Override
public void populateItem(
final Item<ICellPopulator<GroupTO>> item, final String componentId, final IModel<GroupTO> model) {
String eeName = "";
String eeName = StringUtils.EMPTY;
try {
eeName = choreographyRestClient.getChoreographyEE(
model.getObject().getPlainAttrMap().get("id").getValues().iterator().next())
.getName();
eeName = choreographyRestClient.getChoreographyEE(model.getObject().getKey()).getName();
} catch (Exception e) {
eeName = "Not assigned";
} finally {
......
......@@ -124,8 +124,8 @@ public class ChoreographyRestClient extends BaseRestClient {
.onChoreography(choreographyId, ChoreographyAction.RESIZE, size);
}
public AnyObjectTO getChoreographyEE(final String choreographyId) {
return getService(ChoreographyService.class).getEnactmentEngine(choreographyId);
public AnyObjectTO getChoreographyEE(final String choreographyKey) {
return getService(ChoreographyService.class).getEnactmentEngine(choreographyKey);
}
public EnactmentEngineStatusTO getChoreographyEEStatus(
......
......@@ -42,12 +42,12 @@ import org.apache.syncope.common.lib.to.AnyObjectTO;
public interface ChoreographyService extends JAXRSService {
/**
* Enact a new choreography.
* Creates a choreography.
*
* @param name choreography name
* @param enactmentEngineKey target enactment engine instance
* @param chorSpec ChorSpec XML representation
* @return the choreography deployment id as generated by the enactment engine
* @return Response object featuring Location header of created choreography
*/
@POST
@Consumes({ MediaType.APPLICATION_XML })
......@@ -57,7 +57,7 @@ public interface ChoreographyService extends JAXRSService {
InputStream chorSpec);
/**
* Enact an existing choreography, with updated specification.
* Updates an existing choreography, with updated specification.
*
* @param id choreography id
* @param name choreography name
......@@ -72,7 +72,7 @@ public interface ChoreographyService extends JAXRSService {
InputStream chorSpec);
/**
* Retire the given choreography.
* Deletes the given choreography.
*
* @param id choreography id
*/
......@@ -80,6 +80,15 @@ public interface ChoreographyService extends JAXRSService {
@Path("{id}")
void delete(@NotNull @PathParam("id") String id);
/**
* Request to enact the choreography matching the provided name, onto the associated Enactment Engine.
*
* @param name choreography name
*/
@POST
@Path("{name}/enact")
void enact(@NotNull @PathParam("name") String name);
/**
* This operation will used to notify that an enactment operation was completed, providing the
* related concrete ChorSpec.
......@@ -166,14 +175,14 @@ public interface ChoreographyService extends JAXRSService {
URL federationServerURL);
/**
* Returns the enactment engine associated to the choreography
*
* @param id choreography id
* Returns the enactment engine associated with the choreography.
*
* @param key choreography key
* @return Enactment engine associated to the choreography
*/
@GET
@Path("{id}/enactmentEngine")
@Path("{key}/enactmentEngine")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
AnyObjectTO getEnactmentEngine(@NotNull @PathParam("id") String id);
AnyObjectTO getEnactmentEngine(@NotNull @PathParam("key") String key);
}
......@@ -24,6 +24,7 @@ import java.io.InputStream;
import java.net.URL;
import javax.ws.rs.core.Response;
import org.apache.syncope.common.lib.to.AnyObjectTO;
import org.apache.syncope.common.rest.api.RESTHeaders;
import org.apache.syncope.common.rest.api.service.ChoreographyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -36,8 +37,10 @@ public class ChoreographyServiceImpl extends AbstractServiceImpl implements Chor
@Override
public Response create(final String name, final String enactmentEngineKey, final InputStream chorSpec) {
return Response.status(Response.Status.CREATED).
header("X-CHOReVOLUTION-ChoreographyId", logic.create(name, enactmentEngineKey, chorSpec)).
String key = logic.create(name, enactmentEngineKey, chorSpec);
return Response.
created(uriInfo.getAbsolutePathBuilder().path(key).build()).
header(RESTHeaders.RESOURCE_KEY, key).
build();
}
......@@ -51,6 +54,11 @@ public class ChoreographyServiceImpl extends AbstractServiceImpl implements Chor
logic.delete(id);
}
@Override
public void enact(final String name) {
logic.enact(name);
}
@Override
public void notifyCompletion(
final String id,
......@@ -92,8 +100,8 @@ public class ChoreographyServiceImpl extends AbstractServiceImpl implements Chor
}