Commit a200c8a1 authored by Francesco Chicchiricco's avatar Francesco Chicchiricco
Browse files

[CRV-231] #resolve

parent 160a67a0
......@@ -116,8 +116,7 @@ public class ChoreographyDirectoryPanel extends GroupDirectoryPanel {
public void onClick(final AjaxRequestTarget target) {
try {
choreographyRestClient.stopChoreography(
model.getObject().getPlainAttrMap().get("id").getValues().iterator().next(),
"Default");
model.getObject().getPlainAttrMap().get("id").getValues().iterator().next());
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
target.add(container);
} catch (SyncopeClientException e) {
......@@ -136,8 +135,7 @@ public class ChoreographyDirectoryPanel extends GroupDirectoryPanel {
public void onClick(final AjaxRequestTarget target) {
try {
choreographyRestClient.freezeChoreography(
model.getObject().getPlainAttrMap().get("id").getValues().iterator().next(),
"Default");
model.getObject().getPlainAttrMap().get("id").getValues().iterator().next());
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
target.add(container);
} catch (SyncopeClientException e) {
......@@ -159,8 +157,7 @@ public class ChoreographyDirectoryPanel extends GroupDirectoryPanel {
public void onClick(final AjaxRequestTarget target) {
try {
choreographyRestClient.startChoreography(
model.getObject().getPlainAttrMap().get("id").getValues().iterator().next(),
"Default");
model.getObject().getPlainAttrMap().get("id").getValues().iterator().next());
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
target.add(container);
} catch (SyncopeClientException e) {
......@@ -182,8 +179,7 @@ public class ChoreographyDirectoryPanel extends GroupDirectoryPanel {
public void onClick(final AjaxRequestTarget target) {
try {
choreographyRestClient.unfreezeChoreography(
model.getObject().getPlainAttrMap().get("id").getValues().iterator().next(),
"Default");
model.getObject().getPlainAttrMap().get("id").getValues().iterator().next());
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
target.add(container);
} catch (SyncopeClientException e) {
......@@ -204,8 +200,7 @@ public class ChoreographyDirectoryPanel extends GroupDirectoryPanel {
public void onClick(final AjaxRequestTarget target) {
try {
choreographyRestClient.deleteChoreography(
model.getObject().getPlainAttrMap().get("id").getValues().iterator().next(),
"Default");
model.getObject().getPlainAttrMap().get("id").getValues().iterator().next());
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
target.add(container);
} catch (SyncopeClientException e) {
......
......@@ -88,36 +88,36 @@ public class ChoreographyRestClient extends BaseRestClient {
return getService(ConsoleInterfaceService.class).averageOperationList(choreographyId, cdName);
}
public void deleteChoreography(final String choreographyId, final String enactmentEngine) {
getService(ChoreographyService.class).delete(choreographyId, enactmentEngine);
public void deleteChoreography(final String choreographyId) {
getService(ChoreographyService.class).delete(choreographyId);
}
public void deleteInstance(final String choreographyInstancePK) {
getService(ConsoleInterfaceService.class).deleteInstance(choreographyInstancePK);
}
public void startChoreography(final String choreographyId, final String enactmentEngine) {
public void startChoreography(final String choreographyId) {
getService(ChoreographyService.class)
.onChoreography(choreographyId, enactmentEngine, ChoreographyAction.START, null);
.onChoreography(choreographyId, ChoreographyAction.START, null);
}
public void stopChoreography(final String choreographyId, final String enactmentEngine) {
public void stopChoreography(final String choreographyId) {
getService(ChoreographyService.class)
.onChoreography(choreographyId, enactmentEngine, ChoreographyAction.STOP, null);
.onChoreography(choreographyId, ChoreographyAction.STOP, null);
}
public void freezeChoreography(final String choreographyId, final String enactmentEngine) {
public void freezeChoreography(final String choreographyId) {
getService(ChoreographyService.class)
.onChoreography(choreographyId, enactmentEngine, ChoreographyAction.FREEZE, null);
.onChoreography(choreographyId, ChoreographyAction.FREEZE, null);
}
public void unfreezeChoreography(final String choreographyId, final String enactmentEngine) {
public void unfreezeChoreography(final String choreographyId) {
getService(ChoreographyService.class)
.onChoreography(choreographyId, enactmentEngine, ChoreographyAction.UNFREEZE, null);
.onChoreography(choreographyId, ChoreographyAction.UNFREEZE, null);
}
public void resizeChoreography(final String choreographyId, final String enactmentEngine, final Integer size) {
public void resizeChoreography(final String choreographyId, final Integer size) {
getService(ChoreographyService.class)
.onChoreography(choreographyId, enactmentEngine, ChoreographyAction.RESIZE, size);
.onChoreography(choreographyId, ChoreographyAction.RESIZE, size);
}
}
......@@ -35,6 +35,7 @@ import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
......@@ -84,6 +85,8 @@ import org.springframework.stereotype.Component;
@Component
public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
private static final Map<String, String> CREATE_REQUESTS = Collections.synchronizedMap(new HashMap<>());
private static final int PAGE_SIZE = 100;
private static final String SERVICE_TYPE = "SERVICE";
......@@ -145,6 +148,10 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
throw new NotFoundException("Enactment Engine instance with key " + enactmentEngineKey);
}
return getEEWebClient(enactmentEngine, endpoint);
}
private WebClient getEEWebClient(final AnyObjectTO enactmentEngine, final String endpoint) throws Exception {
Map<String, AttrTO> plainAttrs = enactmentEngine.getPlainAttrMap();
String baseURL = null;
......@@ -156,7 +163,7 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
}
if (baseURL == null) {
throw new IllegalArgumentException(
"Could not find " + ENACTMENT_ENGINE_BASE_URL + " for " + enactmentEngineKey);
"Could not find " + ENACTMENT_ENGINE_BASE_URL + " for " + enactmentEngine.getKey());
}
String username = null;
......@@ -224,7 +231,7 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
return candidates.get(0);
}
private AnyObjectTO anyObjectExists(final String id) {
private AnyObjectTO serviceExists(final String id) {
AnyObjectTO serviceTO = anyObjectLogic.read(id);
if (!SERVICE_TYPE.equals(serviceTO.getType())) {
throw new NotFoundException(SERVICE_TYPE + " " + id);
......@@ -232,8 +239,25 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
return serviceTO;
}
private AnyObjectTO enactmentEngineForChoreography(final String choreographyKey) {
MembershipCond membershipCond = new MembershipCond();
membershipCond.setGroup(choreographyKey);
AnyTypeCond anyTypeCond = new AnyTypeCond();
anyTypeCond.setAnyTypeKey(ENACTMENT_ENGINE_TYPE);
SearchCond serviceCond = SearchCond.getAndCond(
SearchCond.getLeafCond(anyTypeCond), SearchCond.getLeafCond(membershipCond));
List<AnyObjectTO> candidates =
anyObjectLogic.search(serviceCond, 1, 1, Collections.emptyList(), SyncopeConstants.ROOT_REALM, false);
if (candidates.isEmpty()) {
throw new NotFoundException("Enactment Engine for choreography " + choreographyKey);
}
return candidates.get(0);
}
@PreAuthorize("hasRole('" + ChorevolutionEntitlement.CHOREOGRAPHY_CREATE + "')")
public String enact(final String name, final String enactmentEngineKey, final InputStream chorSpec) {
public String create(final String name, final String enactmentEngineKey, final InputStream chorSpec) {
String generatedChoreographyId = null;
Response response;
......@@ -254,36 +278,40 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
}
}
} catch (Exception e) {
throw new RuntimeException("While enacting on " + enactmentEngineKey, e);
throw new RuntimeException("While creating on " + enactmentEngineKey, e);
}
if (StringUtils.isEmpty(generatedChoreographyId)) {
throw new RuntimeException("Could not extract the generated choreography id");
}
CREATE_REQUESTS.put(generatedChoreographyId, enactmentEngineKey);
return generatedChoreographyId;
}
@PreAuthorize("hasRole('" + ChorevolutionEntitlement.CHOREOGRAPHY_UPDATE + "')")
public void enact(final String id, final String name, final String enactmentEngineKey, final InputStream chorSpec) {
choreographyExists(id);
public void update(final String id, final String name, final InputStream chorSpec) {
GroupTO choreography = choreographyExists(id);
AnyObjectTO enactmentEngine = enactmentEngineForChoreography(choreography.getKey());
try {
WebClient webClient = getEEWebClient(enactmentEngineKey, "/" + id + "?choreographyName=" + name);
WebClient webClient = getEEWebClient(enactmentEngine, "/" + id + "?choreographyName=" + name);
Response response = webClient.put(chorSpec);
if (response.getStatus() != Response.Status.ACCEPTED.getStatusCode()) {
throw new WebApplicationException(response);
}
} catch (Exception e) {
throw new RuntimeException("While enacting on " + enactmentEngineKey, e);
throw new RuntimeException("While updating on " + enactmentEngine.getKey(), e);
}
}
@PreAuthorize("hasRole('" + ChorevolutionEntitlement.CHOREOGRAPHY_DELETE + "')")
public void delete(final String id, final String enactmentEngineKey) {
choreographyExists(id);
public void delete(final String id) {
GroupTO choreography = choreographyExists(id);
AnyObjectTO enactmentEngine = enactmentEngineForChoreography(choreography.getKey());
try {
WebClient webClient = getEEWebClient(enactmentEngineKey, "/" + id);
WebClient webClient = getEEWebClient(enactmentEngine, "/" + id);
Response response = webClient.delete();
if (response.getStatus() != Response.Status.ACCEPTED.getStatusCode()) {
throw new WebApplicationException(response);
......@@ -398,6 +426,20 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
AnyTypeClassTO classForUserTE;
switch (operation) {
case CREATE:
String enactmentEngineKey = CREATE_REQUESTS.get(id);
if (enactmentEngineKey == null) {
throw new BadRequestException("Could not find matching Enactment Engine instance for " + id);
} else {
// ensures that enactmentEngine contains effectively the entity key and that
// such object exists and has the expected type
AnyObjectTO enactmentEngine = anyObjectLogic.read(enactmentEngineKey);
if (!ENACTMENT_ENGINE_TYPE.equals(enactmentEngine.getType())) {
throw new BadRequestException("Could not find Enactment Engine with key "
+ enactmentEngine.getKey());
}
enactmentEngineKey = enactmentEngine.getKey();
}
// 1. create the choreography group
choreography = new GroupTO();
choreography.setName(name);
......@@ -420,7 +462,12 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
choreography = groupLogic.create(choreography, false).getEntity();
// 2. process the chroSpec
AnyObjectPatch eePatch = new AnyObjectPatch();
eePatch.setKey(enactmentEngineKey);
eePatch.getMemberships().add(new MembershipPatch.Builder().group(choreography.getKey()).build());
anyObjectLogic.update(eePatch, false);
// 2. process the chorSpec
classForUserTE = new AnyTypeClassTO();
classForUserTE.setKey(getUSERTypeExtensionKey(name));
......@@ -446,7 +493,7 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
choreography = choreographyExists(id);
String oldName = choreography.getName();
// 1. update name and chroSpec
// 1. update name and chorSpec
GroupPatch groupPatch = new GroupPatch();
groupPatch.setKey(choreography.getKey());
if (!oldName.equals(name)) {
......@@ -488,7 +535,7 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
}
}
// 3. process the chroSpec
// 3. process the chorSpec
classForUserTE = anyTypeClassLogic.read(oldName);
processChorSpec(chorSpec, choreography.getKey(), classForUserTE);
......@@ -541,11 +588,11 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
@PreAuthorize("hasRole('" + ChorevolutionEntitlement.ON_CHOREOGRAPHY + "')")
public void onChoreography(
final String id,
final String enactmentEngineKey,
final ChoreographyAction action,
final Integer newSize) {
GroupTO choreography = choreographyExists(id);
AnyObjectTO enactmentEngine = enactmentEngineForChoreography(choreography.getKey());
String newStatus = null;
try {
......@@ -553,22 +600,22 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
switch (action) {
case START:
case UNFREEZE:
webClient = getEEWebClient(enactmentEngineKey, "/" + id + "/start");
webClient = getEEWebClient(enactmentEngine, "/" + id + "/start");
newStatus = "STARTED";
break;
case STOP:
webClient = getEEWebClient(enactmentEngineKey, "/" + id + "/stop");
webClient = getEEWebClient(enactmentEngine, "/" + id + "/stop");
newStatus = "STOPPED";
break;
case FREEZE:
webClient = getEEWebClient(enactmentEngineKey, "/" + id + "/pause");
webClient = getEEWebClient(enactmentEngine, "/" + id + "/pause");
newStatus = "FROZEN";
break;
case RESIZE:
webClient = getEEWebClient(enactmentEngineKey, "/" + id + "/resize?newSize=" + newSize);
webClient = getEEWebClient(enactmentEngine, "/" + id + "/resize?newSize=" + newSize);
break;
default:
......@@ -598,13 +645,13 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
@PreAuthorize("hasRole('" + ChorevolutionEntitlement.ON_CHOREOGRAPHY_SERVICE + "')")
public void onChoreographyService(
final String id,
final String enactmentEngineKey,
final String serviceId,
final ServiceAction action,
final String argument) {
GroupTO choreography = choreographyExists(id);
AnyObjectTO service = anyObjectExists(serviceId);
AnyObjectTO enactmentEngine = enactmentEngineForChoreography(choreography.getKey());
AnyObjectTO service = serviceExists(serviceId);
MembershipTO membership = service.getMembershipMap().get(choreography.getKey());
if (membership == null) {
......@@ -613,7 +660,7 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
}
if (action == ServiceAction.REPLACE) {
AnyObjectTO newService = anyObjectExists(argument);
AnyObjectTO newService = serviceExists(argument);
RelationshipTO relationship = IterableUtils.find(
newService.getRelationships(),
(RelationshipTO object) -> SERVICE_ROLE_TYPE.equals(object.getRightType()));
......@@ -628,7 +675,7 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
}
try {
WebClient webClient = getEEWebClient(enactmentEngineKey,
WebClient webClient = getEEWebClient(enactmentEngine,
"/" + id + "/replaceService/" + newServiceRole.getName() + "/" + newService.getName()
+ "?serviceEndPoint=" + serviceLocation);
Response response = webClient.post(null);
......@@ -678,7 +725,7 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
@PreAuthorize("hasRole('" + ChorevolutionEntitlement.ON_CHOREOGRAPHY_SERVICE + "')")
public SecurityFilterInfo readSecurityFilterInfo(final String id, final String serviceId) {
GroupTO choreography = choreographyExists(id);
AnyObjectTO service = anyObjectExists(serviceId);
AnyObjectTO service = serviceExists(serviceId);
try {
WebClient webClient = getSFWebClient(choreography, service, "info");
......@@ -696,7 +743,7 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
@PreAuthorize("hasRole('" + ChorevolutionEntitlement.ON_CHOREOGRAPHY_SERVICE + "')")
public void configureSecurityFilter(final String id, final String serviceId, final URL federationServerURL) {
GroupTO choreography = choreographyExists(id);
AnyObjectTO service = anyObjectExists(serviceId);
AnyObjectTO service = serviceExists(serviceId);
try {
WebClient webClient = getSFWebClient(choreography, service, "federationServerURL");
......
......@@ -50,7 +50,7 @@ public interface ChoreographyService extends JAXRSService {
*/
@POST
@Consumes({ MediaType.APPLICATION_XML })
Response enact(
Response create(
@NotNull @QueryParam("name") String name,
@NotNull @QueryParam("enactmentEngineKey") String enactmentEngineKey,
InputStream chorSpec);
......@@ -60,29 +60,24 @@ public interface ChoreographyService extends JAXRSService {
*
* @param id choreography id
* @param name choreography name
* @param enactmentEngineKey target enactment engine instance
* @param chorSpec ChorSpec XML representation
*/
@PUT
@Path("{id}")
@Consumes({ MediaType.APPLICATION_XML })
void enact(
void update(
@NotNull @PathParam("id") String id,
@NotNull @QueryParam("name") String name,
@NotNull @QueryParam("enactmentEngineKey") String enactmentEngineKey,
InputStream chorSpec);
/**
* Retire the given choreography.
*
* @param id choreography id
* @param enactmentEngineKey target enactment engine instance
*/
@DELETE
@Path("{id}")
void delete(
@NotNull @PathParam("id") String id,
@NotNull @QueryParam("enactmentEngineKey") String enactmentEngineKey);
void delete(@NotNull @PathParam("id") String id);
/**
* This operation will used to notify that an enactment operation was completed, providing the
......@@ -108,7 +103,6 @@ public interface ChoreographyService extends JAXRSService {
* Performs the given action on the given choreography.
*
* @param id choreography id
* @param enactmentEngineKey target enactment engine instance
* @param action action to be performed
* @param newSize (normally ignored, required if {@code action} is {@link ChoreographyAction#RESIZE}
* minimum number of nodes running each service group of the given choreography
......@@ -117,7 +111,6 @@ public interface ChoreographyService extends JAXRSService {
@Path("{id}")
void onChoreography(
@NotNull @PathParam("id") String id,
@NotNull @QueryParam("enactmentEngineKey") String enactmentEngineKey,
@NotNull @QueryParam("action") ChoreographyAction action,
@QueryParam("newSize") Integer newSize);
......@@ -125,7 +118,6 @@ public interface ChoreographyService extends JAXRSService {
* Performs the given action on the given choreography's service.
*
* @param id choreography id
* @param enactmentEngineKey target enactment engine instance (for service replace)
* @param serviceId choreography service id
* @param action action to be performed
* @param argument Security context name if {@link ServiceAction#ENFORCE_SECURITY_CONTEXT};
......@@ -137,7 +129,6 @@ public interface ChoreographyService extends JAXRSService {
@Path("{id}/{serviceId}")
void onChoreographyService(
@NotNull @PathParam("id") String id,
@QueryParam("enactmentEngineKey") String enactmentEngineKey,
@NotNull @PathParam("serviceId") String serviceId,
@NotNull @QueryParam("action") ServiceAction action,
@QueryParam("argument") String argument);
......
......@@ -34,20 +34,20 @@ public class ChoreographyServiceImpl extends AbstractServiceImpl implements Chor
private ChoreographyLogic logic;
@Override
public Response enact(final String name, final String enactmentEngineKey, final InputStream chorSpec) {
public Response create(final String name, final String enactmentEngineKey, final InputStream chorSpec) {
return Response.status(Response.Status.CREATED).
header("X-CHOReVOLUTION-ChoreographyId", logic.enact(name, enactmentEngineKey, chorSpec)).
header("X-CHOReVOLUTION-ChoreographyId", logic.create(name, enactmentEngineKey, chorSpec)).
build();
}
@Override
public void enact(final String id, final String name, final String enactmentEngineKey, final InputStream chorSpec) {
logic.enact(id, name, enactmentEngineKey, chorSpec);
public void update(final String id, final String name, final InputStream chorSpec) {
logic.update(id, name, chorSpec);
}
@Override
public void delete(final String id, final String enactmentEngineKey) {
logic.delete(id, enactmentEngineKey);
public void delete(final String id) {
logic.delete(id);
}
@Override
......@@ -64,22 +64,20 @@ public class ChoreographyServiceImpl extends AbstractServiceImpl implements Chor
@Override
public void onChoreography(
final String id,
final String enactmentEngineKey,
final ChoreographyAction action,
final Integer newSize) {
logic.onChoreography(id, enactmentEngineKey, action, newSize);
logic.onChoreography(id, action, newSize);
}
@Override
public void onChoreographyService(
final String id,
final String enactmentEngineKey,
final String serviceId,
final ServiceAction action,
final String newServiceURL) {
logic.onChoreographyService(id, enactmentEngineKey, serviceId, action, newServiceURL);
logic.onChoreographyService(id, serviceId, action, newServiceURL);
}
@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