Skip to content
This repository has been archived by the owner on Apr 15, 2021. It is now read-only.

Fix issue 43 - enhance instance operation UI #930

Open
wants to merge 2 commits into
base: v17.3.0-fix-branch
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*******************************************************************************
*
* Copyright FUJITSU LIMITED 2017
* Copyright FUJITSU LIMITED 2018
*
* Sample controller implementation for the
* Asynchronous Provisioning Platform (APP)
Expand All @@ -11,6 +11,7 @@

package org.oscm.app.sample.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Properties;

Expand All @@ -31,6 +32,8 @@
import org.oscm.app.v2_0.data.ProvisioningSettings;
import org.oscm.app.v2_0.data.ServiceUser;
import org.oscm.app.v2_0.exceptions.APPlatformException;
import org.oscm.app.v2_0.exceptions.AbortException;
import org.oscm.app.v2_0.exceptions.SuspendException;
import org.oscm.app.v2_0.intf.APPlatformController;
import org.oscm.app.v2_0.intf.APPlatformService;
import org.slf4j.Logger;
Expand Down Expand Up @@ -63,6 +66,8 @@ public class SampleController implements APPlatformController {
public static final String ID = "ess.sample";

private APPlatformService platformService;

final String REASON = "Reason:";

/**
* Retrieves an <code>APPlatformService</code> instance.
Expand Down Expand Up @@ -181,12 +186,57 @@ public InstanceStatus modifyInstance(String instanceId,
// Set status to store for application instance
paramHandler.setState(Status.MODIFICATION_REQUESTED);

simulateErrorMessage(paramHandler);

InstanceStatus result = new InstanceStatus();
result.setChangedParameters(newSettings.getParameters());
result.setChangedAttributes(newSettings.getAttributes());
return result;
}

private void simulateErrorMessage(PropertyHandler ph)
throws APPlatformException {

String msg = ph.getMessage();

if (!mayContainGivenErrorMessage(msg))
return;

if (msg.startsWith(SuspendException.class.getSimpleName() + ":")) {
String details = msg.substring(msg.indexOf(":") + 1);

throwSuspendException(details);
}

if (msg.startsWith(AbortException.class.getSimpleName() + ":")) {

String details = msg.substring(msg.indexOf(":") + 1);

String adminMsg = details;
String customerMsg = details;

if (msg.contains(REASON)) {
adminMsg = msg.substring(msg.indexOf(REASON) + 1);
customerMsg = details.substring(0, msg.indexOf(REASON));
}

throwAbortException(customerMsg, adminMsg);
}

if (msg.startsWith(APPlatformException.class.getSimpleName() + ":")) {

throwAPPlatformException(msg);
}

}


private boolean mayContainGivenErrorMessage(String msg) {
int minLen = msg.indexOf(":") + 2;

return (minLen >= 2 && msg.length() > minLen);
}

/**
* Returns the current overall status of the application instance.
* <p>
Expand Down Expand Up @@ -431,4 +481,23 @@ public void setControllerSettings(ControllerSettings settings) {
// not applicable
}

private void throwAPPlatformException(String msg)
throws APPlatformException {
throw new APPlatformException(msg.substring(msg.indexOf(":") + 1));
}

protected void throwSuspendException(String details)
throws SuspendException {
LocalizedText lt = new LocalizedText("en", details);
throw new SuspendException(Arrays.asList(new LocalizedText[] { lt }));
}

protected void throwAbortException(String customerMsg, String providerMsg)
throws AbortException {
LocalizedText ltc = new LocalizedText("en", customerMsg);
LocalizedText ltp = new LocalizedText("en", providerMsg);
throw new AbortException(Arrays.asList(new LocalizedText[] { ltc }),
Arrays.asList(new LocalizedText[] { ltp }));
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*******************************************************************************
*
* Copyright FUJITSU LIMITED 2017
* Copyright FUJITSU LIMITED 2019
*
* Creation Date: 2014-2-25
*
Expand Down Expand Up @@ -211,6 +211,8 @@ boolean filterOperation(InstanceOperation operation,
switch (operation) {

case RESUME:
isOperationAllowed = true;
break;
case ABORT_PENDING:
if (!runWithTimer && !controllerReady) {
isOperationAllowed = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void filterOperation_Failed() throws Exception {
serviceInstance);

// then
assertEquals(Boolean.FALSE, Boolean.valueOf(result));
assertEquals(Boolean.TRUE, Boolean.valueOf(result));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*******************************************************************************
*
* Copyright FUJITSU LIMITED 2017
* Copyright FUJITSU LIMITED 2019
*
* Creation Date: 2014-02-25
*
Expand Down Expand Up @@ -405,6 +405,7 @@ void completePendingInstance(ServiceInstance serviceInstance, String locale)
throws ServiceInstanceException {
try {
ServiceInstance dbInstance = dao.find(serviceInstance);
dbInstance.setRunWithTimer(true);
if (dbInstance.isControllerReady()) {
switch (dbInstance.getProvisioningStatus()) {
case WAITING_FOR_SYSTEM_CREATION:
Expand Down