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

[CRV-19] Completing invocation of all EE methods

parent b4458c0c
......@@ -18,6 +18,7 @@ package eu.chorevolution.idm.choremocks.sf;
import eu.chorevolution.securityfilter.api.RuntimeInfo;
import eu.chorevolution.securityfilter.api.SecurityFilterManagement;
import eu.chorevolution.securityfilter.api.Status;
import eu.chorevolution.securityfilter.api.SecurityContext;
import javax.ws.rs.Path;
import org.springframework.stereotype.Service;
......@@ -30,7 +31,7 @@ public class SecurityFilterManagementImpl implements SecurityFilterManagement {
static {
SHARED_INSTANCE = new RuntimeInfo();
SHARED_INSTANCE.setStatus(Status.ENABLED);
SHARED_INSTANCE.setSecurityContext("A context");
SHARED_INSTANCE.setSecurityContext(null);
}
@Override
......@@ -44,7 +45,7 @@ public class SecurityFilterManagementImpl implements SecurityFilterManagement {
}
@Override
public void securityContext(final String securityContext) {
public void securityContext(final SecurityContext securityContext) {
SHARED_INSTANCE.setSecurityContext(securityContext);
}
......
......@@ -42,6 +42,7 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.xml.bind.JAXBException;
import javax.xml.stream.XMLStreamException;
import org.apache.commons.collections4.IterableUtils;
import org.apache.cxf.helpers.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.cxf.common.util.Base64Utility;
......@@ -59,6 +60,7 @@ import org.apache.syncope.common.lib.to.AttrTO;
import org.apache.syncope.common.lib.to.GroupTO;
import org.apache.syncope.common.lib.to.MembershipTO;
import org.apache.syncope.common.lib.to.PlainSchemaTO;
import org.apache.syncope.common.lib.to.RelationshipTO;
import org.apache.syncope.common.lib.to.TypeExtensionTO;
import org.apache.syncope.common.lib.types.AnyTypeKind;
import org.apache.syncope.common.lib.types.AttrSchemaType;
......@@ -84,6 +86,8 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
private static final String SERVICE_TYPE = "SERVICE";
private static final String SERVICE_ROLE_TYPE = "SERVICE ROLE";
private static final String ENACTMENT_ENGINE_TYPE = "ENACTMENT ENGINE";
private static final String ENACTMENT_ENGINE_BASE_URL = "enactmentEngineBaseURL";
......@@ -94,6 +98,8 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
private static final String CHOREOGRAPHY_ID_SCHEMA = "id";
private static final String SERVICE_LOCATION_SCHEMA = "Service Location";
private static final String GLOBAL_SECURITY_FILTER_ENDPOINT_SCHEMA = "GlobalSecurityFilterEndpoint";
private static final String SECURITY_FILTER_ENDPOINT_SCHEMA = "SecurityFilterEndpoint";
......@@ -268,7 +274,7 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
throw new WebApplicationException(response);
}
} catch (Exception e) {
throw new RuntimeException("While deleting " + enactmentEngineKey, e);
throw new RuntimeException("While deleting " + id, e);
}
}
......@@ -518,36 +524,66 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
}
@PreAuthorize("hasRole('" + ChorevolutionEntitlement.ON_CHOREOGRAPHY + "')")
public void onChoreography(final String id, final ChoreographyAction action, final Integer newSize) {
switch (action) {
case START:
// ChoreographyApi#start()
break;
public void onChoreography(
final String id,
final String enactmentEngineKey,
final ChoreographyAction action,
final Integer newSize) {
case STOP:
// ChoreographyApi#stop()
break;
GroupTO choreography = choreographyExists(id);
case FREEZE:
// ChoreographyApi#pause()
break;
String newStatus = null;
try {
WebClient webClient = null;
switch (action) {
case START:
case UNFREEZE:
webClient = getEEWebClient(enactmentEngineKey, "/" + id + "/start");
newStatus = "STARTED";
break;
case STOP:
webClient = getEEWebClient(enactmentEngineKey, "/" + id + "/stop");
newStatus = "STOPPED";
break;
case FREEZE:
webClient = getEEWebClient(enactmentEngineKey, "/" + id + "/pause");
newStatus = "FROZEN";
break;
case RESIZE:
webClient = getEEWebClient(enactmentEngineKey, "/" + id + "/resize?newSize=" + newSize);
break;
default:
}
case UNFREEZE:
// ChoreographyApi#start()
break;
if (webClient != null) {
Response response = webClient.post(null);
if (response.getStatus() != Response.Status.ACCEPTED.getStatusCode()) {
throw new WebApplicationException(response);
}
}
case RESIZE:
// ChoreographyApi#resize()
break;
if (newStatus != null) {
GroupPatch patch = new GroupPatch();
patch.setKey(choreography.getKey());
patch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(
new AttrTO.Builder().schema("status").value("newStatus").build()
).build());
default:
groupLogic.update(patch, false);
}
} catch (Exception e) {
throw new RuntimeException("While acting on " + id, e);
}
}
@PreAuthorize("hasRole('" + ChorevolutionEntitlement.ON_CHOREOGRAPHY_SERVICE + "')")
public void onChoreographyService(
final String id,
final String enactmentEngineKey,
final String serviceId,
final ServiceAction action,
final String argument) {
......@@ -562,7 +598,31 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
}
if (action == ServiceAction.REPLACE) {
// ChoreographyApi#replaceService()
AnyObjectTO newService = anyObjectExists(argument);
RelationshipTO relationship = IterableUtils.find(
newService.getRelationships(),
(RelationshipTO object) -> SERVICE_ROLE_TYPE.equals(object.getRightType()));
if (relationship == null) {
throw new NotFoundException(SERVICE_ROLE_TYPE + " for service " + newService.getName());
}
AnyObjectTO newServiceRole = anyObjectLogic.read(relationship.getRightKey());
AttrTO serviceLocation = newService.getPlainAttrMap().get(SERVICE_LOCATION_SCHEMA);
if (serviceLocation == null || serviceLocation.getValues().isEmpty()) {
throw new NotFoundException(SERVICE_LOCATION_SCHEMA + " for service " + newService.getName());
}
try {
WebClient webClient = getEEWebClient(enactmentEngineKey,
"/" + id + "/replaceService/" + newServiceRole.getName() + "/" + newService.getName()
+ "?serviceEndPoint=" + serviceLocation);
Response response = webClient.post(null);
if (response.getStatus() != Response.Status.ACCEPTED.getStatusCode()) {
throw new WebApplicationException(response);
}
} catch (Exception e) {
throw new RuntimeException("While replacing service", e);
}
} else {
AttrTO securityFilterEndpoint = membership.getPlainAttrMap().get(SECURITY_FILTER_ENDPOINT_SCHEMA);
if (securityFilterEndpoint == null || securityFilterEndpoint.getValues().isEmpty()) {
......
......@@ -107,6 +107,7 @@ 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
......@@ -115,6 +116,7 @@ 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);
......@@ -122,6 +124,7 @@ 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};
......@@ -133,6 +136,7 @@ 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);
......
......@@ -61,18 +61,24 @@ public class ChoreographyServiceImpl extends AbstractServiceImpl implements Chor
}
@Override
public void onChoreography(final String id, final ChoreographyAction action, final Integer newSize) {
logic.onChoreography(id, action, newSize);
public void onChoreography(
final String id,
final String enactmentEngineKey,
final ChoreographyAction action,
final Integer newSize) {
logic.onChoreography(id, enactmentEngineKey, action, newSize);
}
@Override
public void onChoreographyService(
final String id,
final String enactmentEngineKey,
final String serviceId,
final ServiceAction action,
final String newServiceURL) {
logic.onChoreographyService(id, serviceId, action, newServiceURL);
logic.onChoreographyService(id, enactmentEngineKey, 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