Commit 3d4e2bcf authored by Gianluca Filippone's avatar Gianluca Filippone
Browse files

[CRV-280] Adapted ChoreographyService methods to use choreography key as input parameter

parent 9cdd8d38
......@@ -86,7 +86,7 @@ public class ChoreographyDetailPage extends BaseExtPage {
});
try {
AnyObjectTO ee = restClient.getChoreographyEE(choreography.getGroupKey());
AnyObjectTO ee = restClient.getChoreographyEE(choreography.getKey());
tabs.add(new AbstractTab(new ResourceModel("eeResources")) {
private static final long serialVersionUID = -5861786415855103549L;
@Override
......
......@@ -185,7 +185,7 @@ public class ChoreographyDirectoryPanel extends GroupDirectoryPanel {
public void onClick(final AjaxRequestTarget target) {
try {
choreographyRestClient.stopChoreography(
model.getObject().getPlainAttrMap().get("id").getValues().iterator().next());
model.getObject().getKey());
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
target.add(container);
} catch (SyncopeClientException e) {
......@@ -204,7 +204,7 @@ public class ChoreographyDirectoryPanel extends GroupDirectoryPanel {
public void onClick(final AjaxRequestTarget target) {
try {
choreographyRestClient.freezeChoreography(
model.getObject().getPlainAttrMap().get("id").getValues().iterator().next());
model.getObject().getKey());
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
target.add(container);
} catch (SyncopeClientException e) {
......@@ -226,7 +226,7 @@ public class ChoreographyDirectoryPanel extends GroupDirectoryPanel {
public void onClick(final AjaxRequestTarget target) {
try {
choreographyRestClient.startChoreography(
model.getObject().getPlainAttrMap().get("id").getValues().iterator().next());
model.getObject().getKey());
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
target.add(container);
} catch (SyncopeClientException e) {
......@@ -248,7 +248,7 @@ public class ChoreographyDirectoryPanel extends GroupDirectoryPanel {
public void onClick(final AjaxRequestTarget target) {
try {
choreographyRestClient.unfreezeChoreography(
model.getObject().getPlainAttrMap().get("id").getValues().iterator().next());
model.getObject().getKey());
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
target.add(container);
} catch (SyncopeClientException e) {
......@@ -270,7 +270,7 @@ public class ChoreographyDirectoryPanel extends GroupDirectoryPanel {
public void onClick(final AjaxRequestTarget target) {
try {
choreographyRestClient.deleteChoreography(
model.getObject().getPlainAttrMap().get("id").getValues().iterator().next());
model.getObject().getKey());
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
target.add(container);
} catch (SyncopeClientException e) {
......
......@@ -69,7 +69,7 @@ public class ChoreographyEEResourcesPanel extends Panel {
this.content = new WebMarkupContainer("eeDetails");
content.add(buildResorucesOverviewPanel());
content.add(new ChoreographyVMDirectoryPanel(
"virtualMachinesList", pageRef, enactmentEngine.getKey(), choreography.getId()));
"virtualMachinesList", pageRef, enactmentEngine.getKey(), choreography.getKey()));
content.add(buildActionsPanel());
content.setOutputMarkupId(true);
......@@ -80,6 +80,7 @@ public class ChoreographyEEResourcesPanel extends Panel {
}
private ChoreographyActionsPanel buildActionsPanel() {
String currentChoreographyStatus = restClient.getChoreography(choreography.getChoreographyId()).getStatus();
ChoreographyActionsPanel actionsPanel = new ChoreographyActionsPanel("actionsPanel");
actionsPanel.addAction(new IndicatingAjaxLink<Void>("link") {
......@@ -90,12 +91,13 @@ public class ChoreographyEEResourcesPanel extends Panel {
utilityModal.size(Modal.Size.Small);
utilityModal.addSubmitButton();
utilityModal.header(Model.of("Resize"));
utilityModal.setContent(new ResizeModalPanel(utilityModal, choreography.getId(), pageRef));
utilityModal.setContent(new ResizeModalPanel(
utilityModal, choreography.getChoreographyId(), pageRef));
utilityModal.show(true);
target.add(utilityModal);
}
}, ChoreographyActionsPanel.ChoreographyActionType.RESIZE);
if (choreography.getStatus().equals("STARTED")) {
if (currentChoreographyStatus.equals("STARTED")) {
actionsPanel.addAction(new IndicatingAjaxLink<Void>("link") {
private static final long serialVersionUID = 3104631231085231035L;
......@@ -103,10 +105,10 @@ public class ChoreographyEEResourcesPanel extends Panel {
@Override
public void onClick(final AjaxRequestTarget target) {
try {
restClient.stopChoreography(choreography.getId());
restClient.stopChoreography(choreography.getKey());
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
} catch (SyncopeClientException e) {
LOG.error("While stopping choreography {}", choreography.getGroupKey(), e);
LOG.error("While stopping choreography {}", choreography.getName(), e);
SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage())
? e.getClass().getName() : e.getMessage());
}
......@@ -122,10 +124,10 @@ public class ChoreographyEEResourcesPanel extends Panel {
@Override
public void onClick(final AjaxRequestTarget target) {
try {
restClient.freezeChoreography(choreography.getId());
restClient.freezeChoreography(choreography.getKey());
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
} catch (SyncopeClientException e) {
LOG.error("While freezing choreography {}", choreography.getGroupKey(), e);
LOG.error("While freezing choreography {}", choreography.getName(), e);
SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage())
? e.getClass().getName() : e.getMessage());
}
......@@ -136,7 +138,7 @@ public class ChoreographyEEResourcesPanel extends Panel {
}, ChoreographyActionsPanel.ChoreographyActionType.FREEZE);
}
if (choreography.getStatus().equals("STOPPED")) {
if (currentChoreographyStatus.equals("STOPPED")) {
actionsPanel.addAction(new IndicatingAjaxLink<Void>("link") {
private static final long serialVersionUID = 3104631231085231035L;
......@@ -144,10 +146,10 @@ public class ChoreographyEEResourcesPanel extends Panel {
@Override
public void onClick(final AjaxRequestTarget target) {
try {
restClient.startChoreography(choreography.getId());
restClient.startChoreography(choreography.getKey());
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
} catch (SyncopeClientException e) {
LOG.error("While starting choreography {}", choreography.getGroupKey(), e);
LOG.error("While starting choreography {}", choreography.getName(), e);
SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage())
? e.getClass().getName() : e.getMessage());
}
......@@ -158,7 +160,7 @@ public class ChoreographyEEResourcesPanel extends Panel {
}, ChoreographyActionsPanel.ChoreographyActionType.START);
}
if (choreography.getStatus().equals("FROZEN")) {
if (currentChoreographyStatus.equals("FROZEN")) {
actionsPanel.addAction(new IndicatingAjaxLink<Void>("link") {
private static final long serialVersionUID = 3104631231085231035L;
......@@ -166,10 +168,10 @@ public class ChoreographyEEResourcesPanel extends Panel {
@Override
public void onClick(final AjaxRequestTarget target) {
try {
restClient.unfreezeChoreography(choreography.getId());
restClient.unfreezeChoreography(choreography.getKey());
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
} catch (SyncopeClientException e) {
LOG.error("While unfreezing choreography {}", choreography.getGroupKey(), e);
LOG.error("While unfreezing choreography {}", choreography.getName(), e);
SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage())
? e.getClass().getName() : e.getMessage());
}
......@@ -184,7 +186,8 @@ public class ChoreographyEEResourcesPanel extends Panel {
private RepeatingView buildResorucesOverviewPanel() {
EnactmentEngineStatusTO ee = restClient.getChoreographyEEStatus(enactmentEngine.getKey(), choreography.getId());
EnactmentEngineStatusTO ee = restClient.getChoreographyEEStatus(
enactmentEngine.getKey(), choreography.getKey());
double ramPercentage = (ee.getRamUsage() / Float.valueOf(ee.getRamTotal())) * 100;
double storagePercentage = (ee.getStorageUsage() / Float.valueOf(ee.getStorageTotal())) * 100;
......
......@@ -44,7 +44,7 @@ public class ChoreographyServiceDirectoryPanel extends AnyObjectDirectoryPanel {
final ChoreographyTO choreography) {
super(id, new Builder(AnyTypeKind.ANY_OBJECT.name(), pageRef), false);
this.fiql = new AnyObjectFiqlSearchConditionBuilder("SERVICE")
.inGroups(choreography.getGroupKey()).query();
.inGroups(choreography.getKey()).query();
dataProvider.setFIQL(fiql);
}
......
......@@ -75,11 +75,11 @@ public class ResizeModalPanel extends AbstractModalPanel<Serializable> {
@Override
public void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
try {
choreographyRestClient.resizeChoreography(choreography.getId(), sizeInput.getModelObject());
choreographyRestClient.resizeChoreography(choreography.getKey(), sizeInput.getModelObject());
resizeModal.close(target);
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
} catch (SyncopeClientException e) {
LOG.error("While deleting object {}", choreography.getGroupKey(), e);
LOG.error("While resizing {}", choreography.getName(), e);
SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage())
? e.getClass().getName() : e.getMessage());
}
......
......@@ -91,8 +91,8 @@ public class ChoreographyRestClient extends BaseRestClient {
return getService(MonitorInterfaceService.class).averageOperationList(choreographyId, cdName);
}
public void deleteChoreography(final String choreographyId) {
getService(ChoreographyService.class).delete(choreographyId);
public void deleteChoreography(final String choreographyKey) {
getService(ChoreographyService.class).delete(choreographyKey);
}
public void deleteInstance(final String choreographyInstancePK) {
......@@ -103,29 +103,29 @@ public class ChoreographyRestClient extends BaseRestClient {
getService(ChoreographyService.class).enact(choregographyName);
}
public void startChoreography(final String choreographyId) {
public void startChoreography(final String choreographyKey) {
getService(ChoreographyService.class)
.onChoreography(choreographyId, ChoreographyAction.START, null);
.onChoreography(choreographyKey, ChoreographyAction.START, null);
}
public void stopChoreography(final String choreographyId) {
public void stopChoreography(final String choreographyKey) {
getService(ChoreographyService.class)
.onChoreography(choreographyId, ChoreographyAction.STOP, null);
.onChoreography(choreographyKey, ChoreographyAction.STOP, null);
}
public void freezeChoreography(final String choreographyId) {
public void freezeChoreography(final String choreographyKey) {
getService(ChoreographyService.class)
.onChoreography(choreographyId, ChoreographyAction.FREEZE, null);
.onChoreography(choreographyKey, ChoreographyAction.FREEZE, null);
}
public void unfreezeChoreography(final String choreographyId) {
public void unfreezeChoreography(final String choreographyKey) {
getService(ChoreographyService.class)
.onChoreography(choreographyId, ChoreographyAction.UNFREEZE, null);
.onChoreography(choreographyKey, ChoreographyAction.UNFREEZE, null);
}
public void resizeChoreography(final String choreographyId, final Integer size) {
public void resizeChoreography(final String choreographyKey, final Integer size) {
getService(ChoreographyService.class)
.onChoreography(choreographyId, ChoreographyAction.RESIZE, size);
.onChoreography(choreographyKey, ChoreographyAction.RESIZE, size);
}
public AnyObjectTO getChoreographyEE(final String choreographyKey) {
......
......@@ -25,9 +25,9 @@ public class ChoreographyTO extends AbstractBaseBean {
private static final long serialVersionUID = 4518569389223742217L;
private String id;
private String key;
private String groupKey;
private String choreographyId;
private String name;
......@@ -41,20 +41,20 @@ public class ChoreographyTO extends AbstractBaseBean {
private String status;
public String getId() {
return id;
public String getKey() {
return key;
}
public void setId(final String id) {
this.id = id;
public void setKey(final String key) {
this.key = key;
}
public String getGroupKey() {
return groupKey;
public String getChoreographyId() {
return choreographyId;
}
public void setGroupKey(final String groupKey) {
this.groupKey = groupKey;
public void setChoreographyId(final String choreographyId) {
this.choreographyId = choreographyId;
}
public String getName() {
......
......@@ -324,8 +324,8 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
}
@PreAuthorize("hasRole('" + ChorevolutionEntitlement.CHOREOGRAPHY_UPDATE + "')")
public void update(final String id, final String name, final InputStream chorSpec) {
GroupTO choreography = choreographyExists(id);
public void update(final String key, final String name, final InputStream chorSpec) {
GroupTO choreography = groupLogic.read(key);
GroupPatch choreographyPatch = new GroupPatch();
choreographyPatch.setKey(choreography.getKey());
......@@ -349,18 +349,19 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
}
@PreAuthorize("hasRole('" + ChorevolutionEntitlement.CHOREOGRAPHY_DELETE + "')")
public void delete(final String id) {
GroupTO choreography = choreographyExists(id);
public void delete(final String key) {
GroupTO choreography = groupLogic.read(key);
AnyObjectTO enactmentEngine = enactmentEngineForChoreography(choreography.getKey());
try {
WebClient webClient = getEEWebClient(enactmentEngine, "/" + id);
WebClient webClient = getEEWebClient(enactmentEngine,
"/" + choreography.getPlainAttrMap().get("id").getValues().iterator().next());
Response response = webClient.delete();
if (response.getStatus() != Response.Status.ACCEPTED.getStatusCode()) {
throw new WebApplicationException(response);
}
} catch (Exception e) {
throw new RuntimeException("While deleting " + id, e);
throw new RuntimeException("While deleting " + choreography.getName(), e);
}
// finally update the choreograpy status
......@@ -670,12 +671,12 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
@PreAuthorize("hasRole('" + ChorevolutionEntitlement.ON_CHOREOGRAPHY + "')")
public void onChoreography(
final String id,
final String key,
final ChoreographyAction action,
final Integer newSize) {
GroupTO choreography = choreographyExists(id);
AnyObjectTO enactmentEngine = enactmentEngineForChoreography(choreography.getKey());
GroupTO choreography = groupLogic.read(key);
AnyObjectTO enactmentEngine = enactmentEngineForChoreography(key);
String newStatus = null;
try {
......@@ -683,22 +684,27 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
switch (action) {
case START:
case UNFREEZE:
webClient = getEEWebClient(enactmentEngine, "/" + id + "/start");
webClient = getEEWebClient(enactmentEngine,
"/" + choreography.getPlainAttrMap().get("id").getValues().iterator().next() + "/start");
newStatus = "STARTED";
break;
case STOP:
webClient = getEEWebClient(enactmentEngine, "/" + id + "/stop");
webClient = getEEWebClient(enactmentEngine,
"/" + choreography.getPlainAttrMap().get("id").getValues().iterator().next() + "/stop");
newStatus = "STOPPED";
break;
case FREEZE:
webClient = getEEWebClient(enactmentEngine, "/" + id + "/pause");
webClient = getEEWebClient(enactmentEngine,
"/" + choreography.getPlainAttrMap().get("id").getValues().iterator().next() + "/pause");
newStatus = "FROZEN";
break;
case RESIZE:
webClient = getEEWebClient(enactmentEngine, "/" + id + "/resize?newSize=" + newSize);
webClient = getEEWebClient(enactmentEngine,
"/" + choreography.getPlainAttrMap().get("id").getValues().iterator().next()
+ "/resize?newSize=" + newSize);
break;
default:
......@@ -715,18 +721,19 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
updateChoreographyStatus(choreography, newStatus);
}
} catch (Exception e) {
throw new RuntimeException("While acting on " + id, e);
throw new RuntimeException(
"While acting on " + choreography.getName(), e);
}
}
@PreAuthorize("hasRole('" + ChorevolutionEntitlement.ON_CHOREOGRAPHY_SERVICE + "')")
public void onChoreographyService(
final String id,
final String key,
final String serviceId,
final ServiceAction action,
final String argument) {
GroupTO choreography = choreographyExists(id);
GroupTO choreography = groupLogic.read(key);
AnyObjectTO enactmentEngine = enactmentEngineForChoreography(choreography.getKey());
AnyObjectTO service = serviceExists(serviceId);
......@@ -753,7 +760,8 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
try {
WebClient webClient = getEEWebClient(enactmentEngine,
"/" + id + "/replaceService/" + newServiceRole.getName() + "/" + newService.getName()
"/" + choreography.getPlainAttrMap().get("id").getValues().iterator().next()
+ "/replaceService/" + newServiceRole.getName() + "/" + newService.getName()
+ "?serviceEndPoint=" + serviceLocation);
Response response = webClient.post(null);
if (response.getStatus() != Response.Status.ACCEPTED.getStatusCode()) {
......@@ -800,8 +808,8 @@ 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);
public SecurityFilterInfo readSecurityFilterInfo(final String key, final String serviceId) {
GroupTO choreography = groupLogic.read(key);
AnyObjectTO service = serviceExists(serviceId);
try {
......@@ -813,13 +821,16 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
return response.readEntity(SecurityFilterInfo.class);
} catch (WebApplicationException e) {
throw new RuntimeException("While reading security filter information for " + service.getName()
+ " in choreography " + id, e);
+ " in choreography " + choreography.getName(), e);
}
}
@PreAuthorize("hasRole('" + ChorevolutionEntitlement.ON_CHOREOGRAPHY_SERVICE + "')")
public void configureSecurityFilter(final String id, final String serviceId, final URL federationServerURL) {
GroupTO choreography = choreographyExists(id);
public void configureSecurityFilter(
final String key,
final String serviceId,
final URL federationServerURL) {
GroupTO choreography = groupLogic.read(key);
AnyObjectTO service = serviceExists(serviceId);
try {
......@@ -832,7 +843,7 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
}
} catch (WebApplicationException e) {
throw new RuntimeException("While setting the Federation Server UTL into the Security Filter instance for "
+ service.getName() + " in choreography " + id, e);
+ service.getName() + " in choreography " + choreography.getName(), e);
}
}
......
......@@ -143,12 +143,12 @@ public class MonitorLogic extends AbstractTransactionalLogic<AbstractBaseBean> {
private ChoreographyTO getChoreographyTO(final Group choreography, final boolean details) {
ChoreographyTO choreographyTO = new ChoreographyTO();
choreographyTO.setGroupKey(choreography.getKey());
choreographyTO.setKey(choreography.getKey());
choreographyTO.setName(choreography.getName());
GPlainAttr id = choreography.getPlainAttr("id");
if (id != null && id.getUniqueValue() != null) {
choreographyTO.setId(id.getUniqueValue().getStringValue());
choreographyTO.setChoreographyId(id.getUniqueValue().getStringValue());
}
GPlainAttr description = choreography.getPlainAttr("description");
......
......@@ -59,26 +59,26 @@ public interface ChoreographyService extends JAXRSService {
/**
* Updates an existing choreography, with updated specification.
*
* @param id choreography id
* @param key choreography key
* @param name choreography name
* @param chorSpec ChorSpec XML representation
*/
@PUT
@Path("{id}")
@Path("{key}")
@Consumes({ MediaType.APPLICATION_XML })
void update(
@NotNull @PathParam("id") String id,
@NotNull @PathParam("id") String key,
@NotNull @QueryParam("name") String name,
InputStream chorSpec);
/**
* Deletes the given choreography.
*
* @param id choreography id
* @param key choreography key
*/
@DELETE
@Path("{id}")
void delete(@NotNull @PathParam("id") String id);
@Path("{key}")
void delete(@NotNull @PathParam("key") String key);
/**
* Request to enact the choreography matching the provided name, onto the associated Enactment Engine.
......@@ -112,22 +112,22 @@ public interface ChoreographyService extends JAXRSService {
/**
* Performs the given action on the given choreography.
*
* @param id choreography id
* @param key choreography key
* @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
*/
@POST
@Path("{id}")
@Path("{key}")
void onChoreography(
@NotNull @PathParam("id") String id,
@NotNull @PathParam("key") String key,
@NotNull @QueryParam("action") ChoreographyAction action,
@QueryParam("newSize") Integer newSize);
/**
* Performs the given action on the given choreography's service.
*
* @param id choreography id
* @param key choreography key
* @param serviceId choreography service id
* @param action action to be performed
* @param argument Security context name if {@link ServiceAction#ENFORCE_SECURITY_CONTEXT};
......@@ -136,9 +136,9 @@ public interface ChoreographyService extends JAXRSService {
* service URL to replace the current set for the given service id
*/
@POST
@Path("{id}/{serviceId}")
@Path("{key}/{serviceId}")
void onChoreographyService(
@NotNull @PathParam("id") String id,
@NotNull @PathParam("key") String key,
@NotNull @PathParam("serviceId") String serviceId,
@NotNull @QueryParam("action") ServiceAction action,
@QueryParam("argument") String argument);
......@@ -147,30 +147,30 @@ public interface ChoreographyService extends JAXRSService {
* Returns information about the current status of the security filter instance associated to the given service,
* in the given choreography (if available).
*
* @param id choreography id
* @param key choreography key
* @param serviceId choreography service id
* @return information about the current status of the security filter instance associated to the given service,
* in the given choreography (if available)
*/
@GET
@Path("{id}/{serviceId}/securityFilterInfo")
@Path("{key}/{serviceId}/securityFilterInfo")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
SecurityFilterInfo readSecurityFilterInfo(
@NotNull @PathParam("id") String id,
@NotNull @PathParam("key") String key,
@NotNull @PathParam("serviceId") String serviceId);
/**
* Configure the Federation Server URL into the security filter instance associated to the given service,
* in the given choreography (if available).
*
* @param id choreography id
<