aboutsummaryrefslogtreecommitdiffstats
path: root/appc-provider/appc-provider-bundle/src/main/java
diff options
context:
space:
mode:
authorAnand <ac204h@att.com>2018-01-04 19:35:51 -0500
committerSkip Wonnell <skip@att.com>2018-01-08 22:09:50 +0000
commit36bcd566167f2f91c0e8e7a304fce5f6bc150776 (patch)
tree7ba7acfee7e520da83a2b6286ea464285bc8cf67 /appc-provider/appc-provider-bundle/src/main/java
parent38d293d605b42f88c9c82319ba848b4b81e45b64 (diff)
Include impacted changes for APPC-346,APPC-348
Issue-ID: APPC-347 Change-Id: I399bc2a1e0dfd481e103032a373bb80fce5baf41 Signed-off-by: Anand <ac204h@att.com>
Diffstat (limited to 'appc-provider/appc-provider-bundle/src/main/java')
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderClient.java42
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderLcm.java644
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/AbstractMockHelper.java66
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/MockQuiesceHelper.java103
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/MockRebootHelper.java70
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/MockRequestExecutor.java61
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/MockResumeHelper.java84
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/MockUpgradeHelper.java229
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/MockVolumeHelper.java140
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/query/MockQueryHelper.java165
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/query/query47
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/AbstractBaseService.java280
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/AbstractBaseUtils.java157
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/ActionStatusService.java114
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/QueryService.java91
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/QuiesceTrafficService.java124
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/RebootService.java110
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/RequestExecutor.java178
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/ResumeTrafficService.java99
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/UpgradeService.java200
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/VolumeService.java165
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/util/RequestInputBuilder.java38
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/util/ValidationService.java62
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/topology/TopologyService.java116
24 files changed, 2900 insertions, 485 deletions
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderClient.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderClient.java
index d4d18d8b9..965961ca4 100644
--- a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderClient.java
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderClient.java
@@ -24,9 +24,9 @@
package org.onap.appc.provider;
-import org.onap.appc.util.StringHelper;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
+import org.onap.appc.util.StringHelper;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
import org.osgi.framework.BundleContext;
@@ -34,37 +34,34 @@ import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
import org.slf4j.MDC;
-import static com.att.eelf.configuration.Configuration.*;
-
-import java.util.Properties;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.Properties;
import java.util.TimeZone;
public class AppcProviderClient {
- private static EELFLogger LOG = EELFManager.getInstance().getApplicationLogger();
- private static EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
+ private final EELFLogger LOG = EELFManager.getInstance().getApplicationLogger();
+ private final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
private SvcLogicService svcLogic = null;
public AppcProviderClient() {
BundleContext bctx = FrameworkUtil.getBundle(SvcLogicService.class).getBundleContext();
- //Handle BundleContext returning null
+ // Handle BundleContext returning null
if (bctx == null){
- LOG.warn("Cannot find bundle context for " + SvcLogicService.NAME);
- }
- else{
- // Get SvcLogicService reference
- ServiceReference sref = bctx.getServiceReference(SvcLogicService.NAME);
- if (sref != null) {
- svcLogic = (SvcLogicService) bctx.getService(sref);
-
- } else {
- LOG.warn("Cannot find service reference for " + SvcLogicService.NAME);
-
- }
+ LOG.warn("Cannot find bundle context for " + SvcLogicService.NAME);
+ } else {
+ // Get SvcLogicService reference
+ ServiceReference sref = bctx.getServiceReference(SvcLogicService.NAME);
+ if (sref != null) {
+ svcLogic = (SvcLogicService) bctx.getService(sref);
+
+ } else {
+ LOG.warn("Cannot find service reference for " + SvcLogicService.NAME);
+
+ }
}
}
@@ -83,29 +80,26 @@ public class AppcProviderClient {
TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
df.setTimeZone(tz);
- String startTimeStr = df.format(new Date());
long endTime = System.currentTimeMillis();
long duration = endTime - startTime;
- String endTimeStr = String.valueOf(endTime);
String durationStr = String.valueOf(duration);
String endTimeStrUTC = df.format(new Date());
MDC.put("EndTimestamp", endTimeStrUTC);
MDC.put("ElapsedTime", durationStr);
MDC.put("TargetEntity", "sli");
MDC.put("TargetServiceName", "execute");
- MDC.put("ClassName", "org.onap.appc.provider.AppcProviderClient");
+ MDC.put("ClassName", "org.onap.appc.provider.AppcProviderClient");
LOG.debug("Parameters passed to SLI: " + StringHelper.propertiesToString(parms));
metricsLogger.info("Parameters passed to SLI: " + StringHelper.propertiesToString(parms));
Properties respProps = svcLogic.execute(module, rpc, version, mode, parms);
-
+
/*
* Set End time for Metrics Logger
*/
endTime = System.currentTimeMillis();
duration = endTime - startTime;
- endTimeStr = String.valueOf(endTime);
durationStr = String.valueOf(duration);
endTimeStrUTC = df.format(new Date());
MDC.put("EndTimestamp", endTimeStrUTC);
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderLcm.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderLcm.java
index 66e8909bd..7d755cd81 100644
--- a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderLcm.java
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderLcm.java
@@ -26,13 +26,19 @@ package org.onap.appc.provider;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
-import com.att.eelf.i18n.EELFResourceManager;
import com.google.common.util.concurrent.Futures;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ActionStatusInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ActionStatusOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ActionStatusOutputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.AppcProviderLcmService;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.AttachVolumeInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.AttachVolumeOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.AttachVolumeOutputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.AuditInput;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.AuditOutput;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.AuditOutputBuilder;
@@ -60,6 +66,9 @@ import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigScaleoutOu
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigureInput;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigureOutput;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigureOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.DetachVolumeInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.DetachVolumeOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.DetachVolumeOutputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.EvacuateInput;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.EvacuateOutput;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.EvacuateOutputBuilder;
@@ -75,6 +84,18 @@ import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.LockOutputBuilde
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.MigrateInput;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.MigrateOutput;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.MigrateOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.QueryInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.QueryOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.QueryOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.QuiesceTrafficInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.QuiesceTrafficOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.QuiesceTrafficOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ResumeTrafficInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ResumeTrafficOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ResumeTrafficOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.RebootInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.RebootOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.RebootOutputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.RebuildInput;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.RebuildOutput;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.RebuildOutputBuilder;
@@ -90,9 +111,15 @@ import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.SnapshotOutputBu
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.SoftwareUploadInput;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.SoftwareUploadOutput;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.SoftwareUploadOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StartApplicationInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StartApplicationOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StartApplicationOutputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StartInput;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StartOutput;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StartOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StopApplicationInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StopApplicationOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StopApplicationOutputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StopInput;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StopOutput;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StopOutputBuilder;
@@ -108,53 +135,59 @@ import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.TestOutputBuilde
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UnlockInput;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UnlockOutput;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UnlockOutputBuilder;
-import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StartApplicationOutput;
-import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StartApplicationOutputBuilder;
-import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StartApplicationInput;
-import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StopApplicationOutput;
-import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StopApplicationOutputBuilder;
-import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StopApplicationInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UpgradePreCheckInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UpgradePreCheckOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UpgradePreCheckOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UpgradeSoftwareInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UpgradeSoftwareOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UpgradeSoftwareOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UpgradePostCheckInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UpgradePostCheckOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UpgradePostCheckOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UpgradeBackupInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UpgradeBackupOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UpgradeBackupOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UpgradeBackoutInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UpgradeBackoutOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UpgradeBackoutOutputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.Status;
-import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.StatusBuilder;
-import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.onap.appc.Constants;
import org.onap.appc.configuration.Configuration;
import org.onap.appc.configuration.ConfigurationFactory;
-import org.onap.appc.domainmodel.lcm.ActionLevel;
-import org.onap.appc.domainmodel.lcm.ResponseContext;
-import org.onap.appc.exceptions.APPCException;
-import org.onap.appc.executor.objects.LCMCommandStatus;
-import org.onap.appc.executor.objects.Params;
import org.onap.appc.i18n.Msg;
import org.onap.appc.logging.LoggingConstants;
import org.onap.appc.logging.LoggingUtils;
+import org.onap.appc.provider.lcm.service.AbstractBaseUtils;
+import org.onap.appc.provider.lcm.service.ActionStatusService;
+import org.onap.appc.provider.lcm.service.QueryService;
+import org.onap.appc.provider.lcm.service.QuiesceTrafficService;
+import org.onap.appc.provider.lcm.service.ResumeTrafficService;
+import org.onap.appc.provider.lcm.service.UpgradeService;
+import org.onap.appc.provider.lcm.service.RebootService;
+import org.onap.appc.provider.lcm.service.RequestExecutor;
+import org.onap.appc.provider.lcm.service.VolumeService;
import org.onap.appc.provider.lcm.util.RequestInputBuilder;
import org.onap.appc.provider.lcm.util.ValidationService;
-import org.onap.appc.requesthandler.RequestHandler;
import org.onap.appc.requesthandler.objects.RequestHandlerInput;
import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
import java.text.ParseException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
-import java.util.Collection;
-public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
+
+public class AppcProviderLcm
+ extends AbstractBaseUtils
+ implements AutoCloseable, AppcProviderLcmService {
private Configuration configuration = ConfigurationFactory.getConfiguration();
private final EELFLogger logger = EELFManager.getInstance().getLogger(AppcProviderLcm.class);
private final ExecutorService executor;
- private final String COMMON_ERROR_MESSAGE_TEMPLATE = "Error processing %s input : %s";
-
/**
* The ODL data store broker. Provides access to a conceptual data tree store and also provides the ability to
* subscribe for changes to data under a given branch of the tree.
@@ -224,7 +257,7 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
/**
* Rebuilds a specific VNF
*
- * @see AppcProviderLcmService#rebuild(RebuildInput)
+ * @see org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.AppcProviderLcmService#rebuild(RebuildInput)
*/
@Override
public Future<RpcResult<RebuildOutput>> rebuild(RebuildInput input) {
@@ -233,19 +266,14 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
RebuildOutputBuilder outputBuilder = new RebuildOutputBuilder();
String action = Action.Rebuild.toString() ;
String rpcName = Action.Rebuild.name().toLowerCase();
- Status status =
- ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
if(null == status) {
try {
- RequestHandlerInput request = new RequestInputBuilder().requestContext()
- .commonHeader(input.getCommonHeader())
- .actionIdentifiers(input.getActionIdentifiers())
- .payload(input.getPayload()).action(action).rpcName(rpcName).build();
+ RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).payload(input.getPayload()).action(action).rpcName(rpcName).build();
status = buildStatusWithDispatcherOutput(executeRequest(request));
- logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s",
- input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
} catch (ParseException e) {
- status = buildParsingErrorStatus(e);
+ status = buildStatusWithParseException(e);
LoggingUtils.logErrorMessage(
LoggingConstants.TargetNames.APPC_PROVIDER,
@@ -258,8 +286,10 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
outputBuilder.setStatus(status);
RpcResult<RebuildOutput> result = RpcResultBuilder.<RebuildOutput> status(true).withResult(outputBuilder.build()).build();
return Futures.immediateFuture(result);
+
}
+
/**
* Restarts a specific VNF
*
@@ -272,8 +302,7 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
RestartOutputBuilder outputBuilder = new RestartOutputBuilder();
String action = Action.Restart.toString() ;
String rpcName = Action.Restart.name().toLowerCase();
- Status status =
- ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
if(null == status) {
try {
RequestHandlerInput request = new RequestInputBuilder().requestContext()
@@ -285,10 +314,9 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
.build();
status = buildStatusWithDispatcherOutput(executeRequest(request));
- logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s",
- input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
} catch (ParseException e) {
- status = buildParsingErrorStatus(e);
+ status = buildStatusWithParseException(e);
LoggingUtils.logErrorMessage(
LoggingConstants.TargetNames.APPC_PROVIDER,
@@ -304,9 +332,50 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
}
/**
+ * Start Application
+ *
+ * @see org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.AppcProviderLcmService#startApplication(StartApplicationInput)
+ */
+ @Override
+ public Future<RpcResult<StartApplicationOutput>> startApplication(StartApplicationInput input) {
+ logger.debug("Input received : " + input.toString());
+
+ StartApplicationOutputBuilder outputBuilder = new StartApplicationOutputBuilder();
+ String action = Action.StartApplication.toString() ;
+ String rpcName = Action.StartApplication.name().toLowerCase();
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ if(null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().requestContext()
+ .commonHeader(input.getCommonHeader())
+ .actionIdentifiers(input.getActionIdentifiers())
+ .payload(input.getPayload())
+ .action(action)
+ .rpcName(rpcName)
+ .build();
+
+ status = buildStatusWithDispatcherOutput(executeRequest(request));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+ status = buildStatusWithParseException(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
+
+ }
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ RpcResult<StartApplicationOutput> result = RpcResultBuilder.<StartApplicationOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+ /**
* Migrates a specific VNF
*
- * @see AppcProviderLcmService#migrate(MigrateInput)
+ * @see org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.AppcProviderLcmService#migrate(MigrateInput)
*/
@Override
public Future<RpcResult<MigrateOutput>> migrate(MigrateInput input) {
@@ -315,19 +384,14 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
MigrateOutputBuilder outputBuilder = new MigrateOutputBuilder();
String action = Action.Migrate.toString() ;
String rpcName = Action.Migrate.name().toLowerCase();
- Status status =
- ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
if(null == status) {
try {
- RequestHandlerInput request = new RequestInputBuilder().requestContext()
- .commonHeader(input.getCommonHeader())
- .actionIdentifiers(input.getActionIdentifiers())
- .payload(input.getPayload()).action(action).rpcName(rpcName).build();
+ RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).payload(input.getPayload()).action(action).rpcName(rpcName).build();
status = buildStatusWithDispatcherOutput(executeRequest(request));
- logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s",
- input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
} catch (ParseException e) {
- status = buildParsingErrorStatus(e);
+ status = buildStatusWithParseException(e);
LoggingUtils.logErrorMessage(
LoggingConstants.TargetNames.APPC_PROVIDER,
@@ -342,10 +406,11 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
return Futures.immediateFuture(result);
}
+
/**
* Evacuates a specific VNF
*
- * @see AppcProviderLcmService#evacuate(EvacuateInput)
+ * @see org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.AppcProviderLcmService#evacuate(EvacuateInput)
*/
@Override
public Future<RpcResult<EvacuateOutput>> evacuate(EvacuateInput input) {
@@ -361,7 +426,7 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
status = buildStatusWithDispatcherOutput(executeRequest(request));
logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
} catch (ParseException e) {
- status = buildParsingErrorStatus(e);
+ status = buildStatusWithParseException(e);
LoggingUtils.logErrorMessage(
LoggingConstants.TargetNames.APPC_PROVIDER,
@@ -380,7 +445,7 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
/**
* Evacuates a specific VNF
*
- * @see AppcProviderLcmService#snapshot(SnapshotInput)
+ * @see org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.AppcProviderLcmService#snapshot(SnapshotInput)
*/
@Override
public Future<RpcResult<SnapshotOutput>> snapshot(SnapshotInput input) {
@@ -389,21 +454,15 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
SnapshotOutputBuilder outputBuilder = new SnapshotOutputBuilder();
String action = Action.Snapshot.toString() ;
String rpcName = Action.Snapshot.name().toLowerCase();
- Status status =
- ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
String identityUrl = input.getIdentityUrl();
if(null == status) {
try {
- RequestHandlerInput request = new RequestInputBuilder().requestContext()
- .commonHeader(input.getCommonHeader())
- .actionIdentifiers(input.getActionIdentifiers())
- .payload(input.getPayload()).action(action).rpcName(rpcName)
- .additionalContext("identity-url", identityUrl).build();
+ RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).payload(input.getPayload()).action(action).rpcName(rpcName).additionalContext("identity-url", identityUrl).build();
status = buildStatusWithDispatcherOutput(executeRequest(request));
- logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s",
- input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
} catch (ParseException e) {
- status = buildParsingErrorStatus(e);
+ status = buildStatusWithParseException(e);
LoggingUtils.logErrorMessage(
LoggingConstants.TargetNames.APPC_PROVIDER,
@@ -423,22 +482,16 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
RollbackOutputBuilder outputBuilder = new RollbackOutputBuilder();
String rpcName = Action.Rollback.toString() ;
- Status status =
- ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), rpcName);
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), rpcName);
String identityUrl = input.getIdentityUrl();
String snapshotId = input.getSnapshotId();
if(null == status) {
try {
- RequestHandlerInput request = new RequestInputBuilder().requestContext()
- .commonHeader(input.getCommonHeader())
- .actionIdentifiers(input.getActionIdentifiers())
- .payload(input.getPayload()).additionalContext("identity-url", identityUrl)
- .additionalContext("snapshot-id", snapshotId).action(rpcName).build();
+ RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).payload(input.getPayload()).additionalContext("identity-url", identityUrl).additionalContext("snapshot-id", snapshotId).action(rpcName).build();
status = buildStatusWithDispatcherOutput(executeRequest(request));
- logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s",
- input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
} catch (ParseException e) {
- status = buildParsingErrorStatus(e);
+ status = buildStatusWithParseException(e);
LoggingUtils.logErrorMessage(
LoggingConstants.TargetNames.APPC_PROVIDER,
@@ -459,19 +512,14 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
SyncOutputBuilder outputBuilder = new SyncOutputBuilder();
String action = Action.Sync.toString() ;
String rpcName = Action.Sync.name().toLowerCase();
- Status status =
- ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
if(null == status) {
try {
- RequestHandlerInput request = new RequestInputBuilder().requestContext()
- .commonHeader(input.getCommonHeader())
- .actionIdentifiers(input.getActionIdentifiers())
- .payload(input.getPayload()).action(action).rpcName(rpcName).build();
+ RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).payload(input.getPayload()).action(action).rpcName(rpcName).build();
status = buildStatusWithDispatcherOutput(executeRequest(request));
- logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s",
- input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
} catch (ParseException e) {
- status = buildParsingErrorStatus(e);
+ status = buildStatusWithParseException(e);
LoggingUtils.logErrorMessage(
LoggingConstants.TargetNames.APPC_PROVIDER,
@@ -486,92 +534,120 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
return Futures.immediateFuture(result);
}
- private Status buildParsingErrorStatus(ParseException e){
- LCMCommandStatus requestParsingFailure = LCMCommandStatus.REQUEST_PARSING_FAILED;
- String errorMessage = e.getMessage() != null ? e.getMessage() : e.toString();
- Params params = new Params().addParam("errorMsg", errorMessage);
- return buildStatus(requestParsingFailure.getResponseCode(), requestParsingFailure.getFormattedMessage(params));
+ @Override
+ public Future<RpcResult<QueryOutput>> query(QueryInput input) {
+ logger.debug(String.format("LCM query received input: %s", input.toString()));
+ QueryOutputBuilder outputBuilder = new QueryService().process(input);
+ RpcResult<QueryOutput> result =
+ RpcResultBuilder.<QueryOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
}
- private Status buildStatus(Integer code,String message){
- StatusBuilder status = new StatusBuilder();
- status.setCode(code);
- status.setMessage(message);
- return status.build();
+ @Override
+ public Future<RpcResult<RebootOutput>> reboot(RebootInput input) {
+ logger.debug(String.format("LCM reboot received input: %s", input.toString()));
+ RebootOutputBuilder outputBuilder = new RebootService().process(input);
+ RpcResult<RebootOutput> result =
+ RpcResultBuilder.<RebootOutput>status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
}
- private Status buildStatusWithDispatcherOutput(RequestHandlerOutput requestHandlerOutput){
- Integer statusCode = requestHandlerOutput.getResponseContext().getStatus().getCode();
- String statusMessage = requestHandlerOutput.getResponseContext().getStatus().getMessage();
- return buildStatus(statusCode, statusMessage);
+ @Override
+ public Future<RpcResult<AttachVolumeOutput>> attachVolume(AttachVolumeInput input) {
+ logger.debug(String.format("LCM attachVolume received input: %s", input.toString()));
+ AttachVolumeOutputBuilder outputBuilder = new VolumeService(true).attachVolume(input);
+ RpcResult<AttachVolumeOutput> result =
+ RpcResultBuilder.<AttachVolumeOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
}
- private RequestHandlerOutput createErrorRequestHandlerObj(RequestHandlerInput request,
- LCMCommandStatus cmdStatus,
- Msg msg,
- Exception e) {
- final String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
- final String reason = EELFResourceManager.format(msg, e,
- appName, e.getClass().getSimpleName(), "", e.getMessage());
-
- RequestHandlerOutput requestHandlerOutput = new RequestHandlerOutput();
- final ResponseContext responseContext = new ResponseContext();
- requestHandlerOutput.setResponseContext(responseContext);
- responseContext.setCommonHeader(request.getRequestContext().getCommonHeader());
-
- String errorMessage = e.getMessage() != null ? e.getMessage() : e.toString();
- Params params = new Params().addParam("errorMsg", errorMessage);
- responseContext.setStatus(cmdStatus.toStatus(params));
-
- LoggingUtils.logErrorMessage(
- LoggingConstants.TargetNames.APPC_PROVIDER,
- reason,
- this.getClass().getName());
-
- return requestHandlerOutput;
+ @Override
+ public Future<RpcResult<DetachVolumeOutput>> detachVolume(DetachVolumeInput input) {
+ logger.debug(String.format("LCM detachVolume received input: %s", input.toString()));
+ DetachVolumeOutputBuilder outputBuilder = new VolumeService(false).detachVolume(input);
+ RpcResult<DetachVolumeOutput> result =
+ RpcResultBuilder.<DetachVolumeOutput>status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
}
- private RequestHandler getRequestHandler(ActionLevel actionLevel){
- final BundleContext context = FrameworkUtil.getBundle(RequestHandler.class).getBundleContext();
- if (context != null) {
- String filter = null;
- try {
- filter = "(level=" + actionLevel.name() + ")";
- Collection<ServiceReference<RequestHandler>> serviceReferences = context.getServiceReferences(RequestHandler.class, filter);
- if (serviceReferences.size() != 1) {
- logger.error("Cannot find service reference for " + RequestHandler.class.getName());
- throw new RuntimeException();
- }
- ServiceReference<RequestHandler> serviceReference = serviceReferences.iterator().next();
- return context.getService(serviceReference);
- } catch (InvalidSyntaxException e) {
- logger.error("Cannot find service reference for " + RequestHandler.class.getName() + ": Invalid Syntax " + filter, e);
- throw new RuntimeException(e);
- }
- }
- return null;
+ @Override
+ public Future<RpcResult<QuiesceTrafficOutput>> quiesceTraffic(QuiesceTrafficInput input) {
+ logger.debug(String.format("LCM quiesce received input: %s", input.toString()));
+ QuiesceTrafficOutputBuilder outputBuilder = new QuiesceTrafficService().process(input);
+ RpcResult<QuiesceTrafficOutput> result =
+ RpcResultBuilder.<QuiesceTrafficOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
}
@Override
+ public Future<RpcResult<ResumeTrafficOutput>> resumeTraffic(ResumeTrafficInput input) {
+ logger.debug(String.format("LCM resume received input: %s", input.toString()));
+ ResumeTrafficOutputBuilder outputBuilder = new ResumeTrafficService().process(input);
+ RpcResult<ResumeTrafficOutput> result =
+ RpcResultBuilder.<ResumeTrafficOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+ @Override
+ public Future<RpcResult<UpgradePreCheckOutput>> upgradePreCheck(UpgradePreCheckInput input) {
+ logger.debug(String.format("LCM upgradeprecheck received input: %s", input.toString()));
+ UpgradePreCheckOutputBuilder outputBuilder = new UpgradeService("upgradePre").upgradePreCheck(input);
+ RpcResult<UpgradePreCheckOutput> result =
+ RpcResultBuilder.<UpgradePreCheckOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+ @Override
+ public Future<RpcResult<UpgradeSoftwareOutput>> upgradeSoftware(UpgradeSoftwareInput input) {
+ logger.debug(String.format("LCM upgradesoftware received input: %s", input.toString()));
+ UpgradeSoftwareOutputBuilder outputBuilder = new UpgradeService("upgradeSoft").upgradeSoftware(input);
+ RpcResult<UpgradeSoftwareOutput> result =
+ RpcResultBuilder.<UpgradeSoftwareOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+ @Override
+ public Future<RpcResult<UpgradePostCheckOutput>> upgradePostCheck(UpgradePostCheckInput input) {
+ logger.debug(String.format("LCM upgradepostcheck received input: %s", input.toString()));
+ UpgradePostCheckOutputBuilder outputBuilder = new UpgradeService("upgradePost").upgradePostCheck(input);
+ RpcResult<UpgradePostCheckOutput> result =
+ RpcResultBuilder.<UpgradePostCheckOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+ @Override
+ public Future<RpcResult<UpgradeBackupOutput>> upgradeBackup(UpgradeBackupInput input) {
+ logger.debug(String.format("LCM backup received input: %s", input.toString()));
+ UpgradeBackupOutputBuilder outputBuilder = new UpgradeService("upgradeBackup").upgradeBackup(input);
+ RpcResult<UpgradeBackupOutput> result =
+ RpcResultBuilder.<UpgradeBackupOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+ @Override
+ public Future<RpcResult<UpgradeBackoutOutput>> upgradeBackout(UpgradeBackoutInput input) {
+ logger.debug(String.format("LCM backout received input: %s", input.toString()));
+ UpgradeBackoutOutputBuilder outputBuilder = new UpgradeService("upgradeBackout").upgradeBackout(input);
+ RpcResult<UpgradeBackoutOutput> result =
+ RpcResultBuilder.<UpgradeBackoutOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+ @Override
public Future<RpcResult<TerminateOutput>> terminate(TerminateInput input) {
logger.debug("Input received : " + input.toString());
TerminateOutputBuilder outputBuilder = new TerminateOutputBuilder();
- String action = Action.Terminate.toString() ;
- String rpcName = Action.Terminate.name().toLowerCase();
- Status status =
- ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ Action myAction = Action.Terminate;
+ String action = myAction.toString() ;
+ String rpcName = getRpcName(myAction);
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
if(null == status) {
try {
- RequestHandlerInput request = new RequestInputBuilder().requestContext()
- .commonHeader(input.getCommonHeader())
- .actionIdentifiers(input.getActionIdentifiers())
- .payload(input.getPayload()).action(action).rpcName(rpcName).build();
+ RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).payload(input.getPayload()).action(action).rpcName(rpcName).build();
status = buildStatusWithDispatcherOutput(executeRequest(request));
- logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s",
- input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
} catch (ParseException e) {
- status = buildParsingErrorStatus(e);
+ status = buildStatusWithParseException(e);
LoggingUtils.logErrorMessage(
LoggingConstants.TargetNames.APPC_PROVIDER,
@@ -583,8 +659,7 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
}
outputBuilder.setCommonHeader(input.getCommonHeader());
outputBuilder.setStatus(status);
- RpcResult<TerminateOutput> result =
- RpcResultBuilder.<TerminateOutput> status(true).withResult(outputBuilder.build()).build();
+ RpcResult<TerminateOutput> result = RpcResultBuilder.<TerminateOutput> status(true).withResult(outputBuilder.build()).build();
return Futures.immediateFuture(result);
}
@@ -592,21 +667,17 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
public Future<RpcResult<ConfigureOutput>> configure(ConfigureInput input) {
logger.debug("Input received : " + input.toString());
ConfigureOutputBuilder outputBuilder = new ConfigureOutputBuilder();
- String action = Action.Configure.toString() ;
- String rpcName = "configure";
- Status status =
- ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ Action myAction = Action.Configure;
+ String action = myAction.toString() ;
+ String rpcName = getRpcName(myAction);
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
if(null == status) {
try {
- RequestHandlerInput request = new RequestInputBuilder().requestContext()
- .commonHeader(input.getCommonHeader())
- .actionIdentifiers(input.getActionIdentifiers())
- .payload(input.getPayload()).action(action).rpcName(rpcName).build();
+ RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).payload(input.getPayload()).action(action).rpcName(rpcName).build();
status = buildStatusWithDispatcherOutput(executeRequest(request));
- logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s",
- input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
} catch (ParseException e) {
- status = buildParsingErrorStatus(e);
+ status = buildStatusWithParseException(e);
LoggingUtils.logErrorMessage(
LoggingConstants.TargetNames.APPC_PROVIDER,
@@ -617,8 +688,15 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
}
outputBuilder.setCommonHeader(input.getCommonHeader());
outputBuilder.setStatus(status);
- RpcResult<ConfigureOutput> result =
- RpcResultBuilder.<ConfigureOutput> status(true).withResult(outputBuilder.build()).build();
+ RpcResult<ConfigureOutput> result = RpcResultBuilder.<ConfigureOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+ @Override
+ public Future<RpcResult<ActionStatusOutput>> actionStatus(ActionStatusInput input) {
+ logger.debug(String.format("Input received : %s", input.toString()));
+ ActionStatusOutputBuilder outputBuilder = (new ActionStatusService()).queryStatus(input);
+ RpcResult<ActionStatusOutput> result = RpcResultBuilder.<ActionStatusOutput> status(true).withResult(outputBuilder.build()).build();
return Futures.immediateFuture(result);
}
@@ -626,21 +704,17 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
public Future<RpcResult<ConfigModifyOutput>> configModify(ConfigModifyInput input) {
logger.debug("Input received : " + input.toString());
ConfigModifyOutputBuilder outputBuilder = new ConfigModifyOutputBuilder();
- String action = Action.ConfigModify.toString() ;
- String rpcName = "config-modify";
- Status status =
- ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ Action myAction = Action.ConfigModify;
+ String action = myAction.toString() ;
+ String rpcName = getRpcName(myAction);
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
if(null == status) {
try {
- RequestHandlerInput request = new RequestInputBuilder().requestContext()
- .commonHeader(input.getCommonHeader())
- .actionIdentifiers(input.getActionIdentifiers())
- .payload(input.getPayload()).action(action).rpcName(rpcName).build();
+ RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).payload(input.getPayload()).action(action).rpcName(rpcName).build();
status = buildStatusWithDispatcherOutput(executeRequest(request));
- logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s",
- input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
} catch (ParseException e) {
- status = buildParsingErrorStatus(e);
+ status = buildStatusWithParseException(e);
LoggingUtils.logErrorMessage(
LoggingConstants.TargetNames.APPC_PROVIDER,
@@ -651,8 +725,7 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
}
outputBuilder.setCommonHeader(input.getCommonHeader());
outputBuilder.setStatus(status);
- RpcResult<ConfigModifyOutput> result =
- RpcResultBuilder.<ConfigModifyOutput> status(true).withResult(outputBuilder.build()).build();
+ RpcResult<ConfigModifyOutput> result = RpcResultBuilder.<ConfigModifyOutput> status(true).withResult(outputBuilder.build()).build();
return Futures.immediateFuture(result);
}
@@ -660,21 +733,17 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
public Future<RpcResult<ConfigScaleoutOutput>> configScaleout(ConfigScaleoutInput input) {
logger.debug("Input received : " + input.toString());
ConfigScaleoutOutputBuilder outputBuilder = new ConfigScaleoutOutputBuilder();
- String action = Action.ConfigScaleOut.toString() ;
- String rpcName = "config-scaleout";
- Status status =
- ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ Action myAction = Action.ConfigScaleOut;
+ String action = myAction.toString() ;
+ String rpcName = getRpcName(myAction);
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
if(null == status) {
try {
- RequestHandlerInput request = new RequestInputBuilder().requestContext()
- .commonHeader(input.getCommonHeader())
- .actionIdentifiers(input.getActionIdentifiers())
- .payload(input.getPayload()).action(action).rpcName(rpcName).build();
+ RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).payload(input.getPayload()).action(action).rpcName(rpcName).build();
status = buildStatusWithDispatcherOutput(executeRequest(request));
- logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s",
- input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
} catch (ParseException e) {
- status = buildParsingErrorStatus(e);
+ status = buildStatusWithParseException(e);
LoggingUtils.logErrorMessage(
LoggingConstants.TargetNames.APPC_PROVIDER,
@@ -685,8 +754,7 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
}
outputBuilder.setCommonHeader(input.getCommonHeader());
outputBuilder.setStatus(status);
- RpcResult<ConfigScaleoutOutput> result =
- RpcResultBuilder.<ConfigScaleoutOutput> status(true).withResult(outputBuilder.build()).build();
+ RpcResult<ConfigScaleoutOutput> result = RpcResultBuilder.<ConfigScaleoutOutput> status(true).withResult(outputBuilder.build()).build();
return Futures.immediateFuture(result);
}
@@ -694,21 +762,17 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
public Future<RpcResult<ConfigRestoreOutput>> configRestore(ConfigRestoreInput input) {
logger.debug("Input received : " + input.toString());
ConfigRestoreOutputBuilder outputBuilder = new ConfigRestoreOutputBuilder();
- String action = Action.ConfigRestore.toString() ;
- String rpcName = "config-restore";
- Status status =
- ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ Action myAction = Action.ConfigRestore;
+ String action = myAction.toString() ;
+ String rpcName = getRpcName(myAction);
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
if(null == status) {
try {
- RequestHandlerInput request = new RequestInputBuilder().requestContext()
- .commonHeader(input.getCommonHeader())
- .actionIdentifiers(input.getActionIdentifiers())
- .payload(input.getPayload()).action(action).rpcName(rpcName).build();
+ RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).payload(input.getPayload()).action(action).rpcName(rpcName).build();
status = buildStatusWithDispatcherOutput(executeRequest(request));
- logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s",
- input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
} catch (ParseException e) {
- status = buildParsingErrorStatus(e);
+ status = buildStatusWithParseException(e);
LoggingUtils.logErrorMessage(
LoggingConstants.TargetNames.APPC_PROVIDER,
@@ -719,8 +783,7 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
}
outputBuilder.setCommonHeader(input.getCommonHeader());
outputBuilder.setStatus(status);
- RpcResult<ConfigRestoreOutput> result =
- RpcResultBuilder.<ConfigRestoreOutput> status(true).withResult(outputBuilder.build()).build();
+ RpcResult<ConfigRestoreOutput> result = RpcResultBuilder.<ConfigRestoreOutput> status(true).withResult(outputBuilder.build()).build();
return Futures.immediateFuture(result);
}
@@ -728,8 +791,9 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
public Future<RpcResult<TestOutput>> test(TestInput input) {
logger.debug("Input received : " + input.toString());
TestOutputBuilder outputBuilder = new TestOutputBuilder();
- String action = Action.Test.toString() ;
- String rpcName = Action.Test.name().toLowerCase();
+ Action myAction = Action.Test;
+ String action = myAction.toString() ;
+ String rpcName = getRpcName(myAction);
Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
if(null == status) {
try {
@@ -737,7 +801,7 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
status = buildStatusWithDispatcherOutput(executeRequest(request));
logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
} catch (ParseException e) {
- status = buildParsingErrorStatus(e);
+ status = buildStatusWithParseException(e);
LoggingUtils.logErrorMessage(
LoggingConstants.TargetNames.APPC_PROVIDER,
@@ -757,8 +821,9 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
public Future<RpcResult<StopOutput>> stop(StopInput input) {
logger.debug("Input received : " + input.toString());
StopOutputBuilder outputBuilder = new StopOutputBuilder();
- String action = Action.Stop.toString() ;
- String rpcName = Action.Stop.name().toLowerCase();
+ Action myAction = Action.Stop;
+ String action = myAction.toString() ;
+ String rpcName = getRpcName(myAction);
Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
if(null == status) {
try {
@@ -766,7 +831,7 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
status = buildStatusWithDispatcherOutput(executeRequest(request));
logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
} catch (ParseException e) {
- status = buildParsingErrorStatus(e);
+ status = buildStatusWithParseException(e);
LoggingUtils.logErrorMessage(
LoggingConstants.TargetNames.APPC_PROVIDER,
@@ -784,15 +849,16 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
/**
* Starts a specific VNF
*
- * @see AppcProviderLcmService#start(StartInput)
+ * @see org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.AppcProviderLcmService#start(StartInput)
*/
@Override
public Future<RpcResult<StartOutput>> start(StartInput input) {
logger.debug("Input received : " + input.toString());
StartOutputBuilder outputBuilder = new StartOutputBuilder();
- String action = Action.Start.toString() ;
- String rpcName = Action.Start.name().toLowerCase();
+ Action myAction = Action.Start;
+ String action = myAction.toString() ;
+ String rpcName = getRpcName(myAction);
Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
if(null == status) {
try {
@@ -805,7 +871,7 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
status = buildStatusWithDispatcherOutput(executeRequest(request));
logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
} catch (ParseException e) {
- status = buildParsingErrorStatus(e);
+ status = buildStatusWithParseException(e);
LoggingUtils.logErrorMessage(
LoggingConstants.TargetNames.APPC_PROVIDER,
@@ -825,8 +891,9 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
public Future<RpcResult<AuditOutput>> audit(AuditInput input) {
logger.debug("Input received : " + input.toString());
AuditOutputBuilder outputBuilder = new AuditOutputBuilder();
- String action = Action.Audit.toString();
- String rpcName = Action.Audit.name().toLowerCase();
+ Action myAction = Action.Audit;
+ String action = myAction.toString() ;
+ String rpcName = getRpcName(myAction);
Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
if(null == status) {
try {
@@ -834,7 +901,7 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
status = buildStatusWithDispatcherOutput(executeRequest(request));
logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
} catch (ParseException e) {
- status = buildParsingErrorStatus(e);
+ status = buildStatusWithParseException(e);
LoggingUtils.logErrorMessage(
LoggingConstants.TargetNames.APPC_PROVIDER,
@@ -853,8 +920,9 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
public Future<RpcResult<SoftwareUploadOutput>> softwareUpload(SoftwareUploadInput input) {
logger.debug("Input received : " + input.toString());
SoftwareUploadOutputBuilder outputBuilder = new SoftwareUploadOutputBuilder();
- String action = Action.SoftwareUpload.toString() ;
- String rpcName = convertActionNameToUrl(action);
+ Action myAction = Action.SoftwareUpload;
+ String action = myAction.toString() ;
+ String rpcName = getRpcName(myAction);
Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
if(null == status) {
try {
@@ -863,7 +931,7 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
status = buildStatusWithDispatcherOutput(executeRequest(request));
logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
} catch (ParseException e) {
- status = buildParsingErrorStatus(e);
+ status = buildStatusWithParseException(e);
LoggingUtils.logErrorMessage(
LoggingConstants.TargetNames.APPC_PROVIDER,
@@ -882,8 +950,9 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
public Future<RpcResult<HealthCheckOutput>> healthCheck(HealthCheckInput input) {
logger.debug("Input received : " + input.toString());
HealthCheckOutputBuilder outputBuilder = new HealthCheckOutputBuilder();
- String action = Action.HealthCheck.toString() ;
- String rpcName = convertActionNameToUrl(action);
+ Action myAction = Action.HealthCheck;
+ String action = myAction.toString() ;
+ String rpcName = getRpcName(myAction);
Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
if(null == status) {
try {
@@ -891,7 +960,7 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
status = buildStatusWithDispatcherOutput(executeRequest(request));
logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
} catch (ParseException e) {
- status = buildParsingErrorStatus(e);
+ status = buildStatusWithParseException(e);
LoggingUtils.logErrorMessage(
LoggingConstants.TargetNames.APPC_PROVIDER,
@@ -910,8 +979,9 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
public Future<RpcResult<LiveUpgradeOutput>> liveUpgrade(LiveUpgradeInput input) {
logger.debug("Input received : " + input.toString());
LiveUpgradeOutputBuilder outputBuilder = new LiveUpgradeOutputBuilder();
- String action = Action.LiveUpgrade.toString() ;
- String rpcName = convertActionNameToUrl(action);
+ Action myAction = Action.LiveUpgrade;
+ String action = myAction.toString() ;
+ String rpcName = getRpcName(myAction);
Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
if(null == status) {
try {
@@ -919,7 +989,7 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
status = buildStatusWithDispatcherOutput(executeRequest(request));
logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
} catch (ParseException e) {
- status = buildParsingErrorStatus(e);
+ status = buildStatusWithParseException(e);
LoggingUtils.logErrorMessage(
LoggingConstants.TargetNames.APPC_PROVIDER,
@@ -939,8 +1009,9 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
public Future<RpcResult<LockOutput>> lock(LockInput input) {
logger.debug("Input received : " + input.toString());
LockOutputBuilder outputBuilder = new LockOutputBuilder();
- String action = Action.Lock.toString() ;
- String rpcName = Action.Lock.name().toLowerCase();
+ Action myAction = Action.Lock;
+ String action = myAction.toString() ;
+ String rpcName = getRpcName(myAction);
Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
if(null == status) {
try {
@@ -948,7 +1019,7 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
status = buildStatusWithDispatcherOutput(executeRequest(request));
logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
} catch (ParseException e) {
- status = buildParsingErrorStatus(e);
+ status = buildStatusWithParseException(e);
LoggingUtils.logErrorMessage(
LoggingConstants.TargetNames.APPC_PROVIDER,
@@ -968,8 +1039,9 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
public Future<RpcResult<UnlockOutput>> unlock(UnlockInput input) {
logger.debug("Input received : " + input.toString());
UnlockOutputBuilder outputBuilder = new UnlockOutputBuilder();
- String action = Action.Unlock.toString() ;
- String rpcName = Action.Unlock.name().toLowerCase();
+ Action myAction = Action.Unlock;
+ String action = myAction.toString() ;
+ String rpcName = getRpcName(myAction);
Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
if(null == status) {
try {
@@ -977,7 +1049,7 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
status = buildStatusWithDispatcherOutput(executeRequest(request));
logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
} catch (ParseException e) {
- status = buildParsingErrorStatus(e);
+ status = buildStatusWithParseException(e);
LoggingUtils.logErrorMessage(
LoggingConstants.TargetNames.APPC_PROVIDER,
@@ -996,23 +1068,24 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
public Future<RpcResult<CheckLockOutput>> checkLock(CheckLockInput input) {
logger.debug("Input received : " + input.toString());
CheckLockOutputBuilder outputBuilder = new CheckLockOutputBuilder();
- String action = Action.CheckLock.toString();
- String rpcName = Action.CheckLock.name().toLowerCase();
+ Action myAction = Action.CheckLock;
+ String action = myAction.toString();
+ String rpcName = getRpcName(myAction);
RequestHandlerOutput requestHandlerOutput = null;
- Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(),
- input.getAction(), action);
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(),
+ action);
if (null == status) {
try {
RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input
- .getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).action(action)
- .rpcName(rpcName).build();
+ .getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).action(action).rpcName
+ (rpcName).build();
requestHandlerOutput = executeRequest(request);
status = buildStatusWithDispatcherOutput(requestHandlerOutput);
- logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s",
- input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input
+ .getActionIdentifiers(), status.getCode(), status.getMessage()));
} catch (ParseException e) {
- status = buildParsingErrorStatus(e);
+ status = buildStatusWithParseException(e);
LoggingUtils.logErrorMessage(
LoggingConstants.TargetNames.APPC_PROVIDER,
@@ -1021,14 +1094,15 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
}
}
+
outputBuilder.setCommonHeader(input.getCommonHeader());
outputBuilder.setStatus(status);
if (requestHandlerOutput != null && requestHandlerOutput.getResponseContext().getStatus().getCode() == 400) {
outputBuilder.setLocked(CheckLockOutput.Locked.valueOf(requestHandlerOutput.getResponseContext()
.getAdditionalContext().get("locked").toUpperCase()));
}
- RpcResult<CheckLockOutput> result = RpcResultBuilder.<CheckLockOutput>status(true)
- .withResult(outputBuilder.build()).build();
+ RpcResult<CheckLockOutput> result = RpcResultBuilder.<CheckLockOutput>status(true).withResult(outputBuilder
+ .build()).build();
return Futures.immediateFuture(result);
}
@@ -1036,16 +1110,17 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
public Future<RpcResult<ConfigBackupOutput>> configBackup(ConfigBackupInput input) {
logger.debug("Input received : " + input.toString());
ConfigBackupOutputBuilder outputBuilder = new ConfigBackupOutputBuilder();
- String action = Action.ConfigBackup.toString() ;
- String rpcName = Action.ConfigBackup.name().toLowerCase();
+ Action myAction = Action.ConfigBackup;
+ String action = myAction.toString() ;
+ String rpcName = getRpcName(myAction);
Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
if(null == status) {
try {
- RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).action(action).rpcName(rpcName).build();
+ RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).payload(input.getPayload()).action(action).rpcName(rpcName).build();
status = buildStatusWithDispatcherOutput(executeRequest(request));
logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
} catch (ParseException e) {
- status = buildParsingErrorStatus(e);
+ status = buildStatusWithParseException(e);
LoggingUtils.logErrorMessage(
LoggingConstants.TargetNames.APPC_PROVIDER,
@@ -1065,8 +1140,9 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
public Future<RpcResult<ConfigBackupDeleteOutput>> configBackupDelete(ConfigBackupDeleteInput input) {
logger.debug("Input received : " + input.toString());
ConfigBackupDeleteOutputBuilder outputBuilder = new ConfigBackupDeleteOutputBuilder();
- String action = Action.ConfigBackupDelete.toString() ;
- String rpcName = Action.ConfigBackupDelete.name().toLowerCase();
+ Action myAction = Action.ConfigBackupDelete;
+ String action = myAction.toString() ;
+ String rpcName = getRpcName(myAction);
Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
if(null == status) {
try {
@@ -1074,7 +1150,7 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
status = buildStatusWithDispatcherOutput(executeRequest(request));
logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
} catch (ParseException e) {
- status = buildParsingErrorStatus(e);
+ status = buildStatusWithParseException(e);
LoggingUtils.logErrorMessage(
LoggingConstants.TargetNames.APPC_PROVIDER,
@@ -1094,8 +1170,9 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
public Future<RpcResult<ConfigExportOutput>> configExport(ConfigExportInput input) {
logger.debug("Input received : " + input.toString());
ConfigExportOutputBuilder outputBuilder = new ConfigExportOutputBuilder();
- String action = Action.ConfigExport.toString() ;
- String rpcName = Action.ConfigExport.name().toLowerCase();
+ Action myAction = Action.ConfigExport;
+ String action = myAction.toString() ;
+ String rpcName = getRpcName(myAction);
Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
if(null == status) {
try {
@@ -1103,7 +1180,7 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
status = buildStatusWithDispatcherOutput(executeRequest(request));
logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
} catch (ParseException e) {
- status = buildParsingErrorStatus(e);
+ status = buildStatusWithParseException(e);
LoggingUtils.logErrorMessage(
LoggingConstants.TargetNames.APPC_PROVIDER,
@@ -1117,55 +1194,22 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
RpcResult<ConfigExportOutput> result = RpcResultBuilder.<ConfigExportOutput> status(true).withResult(outputBuilder.build()).build();
return Futures.immediateFuture(result);
}
- @Override
- public Future<RpcResult<StartApplicationOutput>> startApplication(StartApplicationInput input) {
- logger.debug("Input received : " + input.toString());
- StartApplicationOutputBuilder outputBuilder = new StartApplicationOutputBuilder();
- String action = Action.StartApplication.toString() ;
- String rpcName = Action.StartApplication.name().toLowerCase();
- Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
- if(null == status) {
- try {
- RequestHandlerInput request = new RequestInputBuilder().requestContext()
- .commonHeader(input.getCommonHeader())
- .actionIdentifiers(input.getActionIdentifiers())
- .payload(input.getPayload())
- .action(action)
- .rpcName(rpcName)
- .build();
- status = buildStatusWithDispatcherOutput(executeRequest(request));
- logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
- } catch (ParseException e) {
- status = buildParsingErrorStatus(e);
-
- LoggingUtils.logErrorMessage(
- LoggingConstants.TargetNames.APPC_PROVIDER,
- String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
- this.getClass().getName());
-
- }
- }
- outputBuilder.setCommonHeader(input.getCommonHeader());
- outputBuilder.setStatus(status);
- RpcResult<StartApplicationOutput> result = RpcResultBuilder.<StartApplicationOutput> status(true).withResult(outputBuilder.build()).build();
- return Futures.immediateFuture(result);
- }
- @Override
public Future<RpcResult<StopApplicationOutput>> stopApplication(StopApplicationInput input){
logger.debug("Input received : " + input.toString());
StopApplicationOutputBuilder outputBuilder = new StopApplicationOutputBuilder();
- String action = Action.StopApplication.toString() ;
- String rpcName = Action.StopApplication.name().toLowerCase();
+ Action myAction = Action.StopApplication;
+ String action = myAction.toString() ;
+ String rpcName = getRpcName(myAction);
Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
if(null == status) {
try {
- RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).payload(input.getPayload()).action(action).rpcName(rpcName).build();
+ RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).action(action).rpcName(rpcName).build();
status = buildStatusWithDispatcherOutput(executeRequest(request));
logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
} catch (ParseException e) {
- status = buildParsingErrorStatus(e);
+ status = buildStatusWithParseException(e);
LoggingUtils.logErrorMessage(
LoggingConstants.TargetNames.APPC_PROVIDER,
@@ -1180,29 +1224,7 @@ public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
return Futures.immediateFuture(result);
}
- private String convertActionNameToUrl(String action) {
- String regex = "([a-z])([A-Z]+)";
- String replacement = "$1-$2";
- return action.replaceAll(regex, replacement)
- .toLowerCase();
- }
-
RequestHandlerOutput executeRequest(RequestHandlerInput request){
- RequestHandler handler = getRequestHandler(request.getRequestContext().getActionLevel());
- RequestHandlerOutput requestHandlerOutput;
- if (handler != null) {
- try {
- requestHandlerOutput = handler.handleRequest(request);
- } catch (Exception e) {
- logger.info("UNEXPECTED FAILURE while executing " + request.getRequestContext().getAction().name());
- requestHandlerOutput = createErrorRequestHandlerObj(request,
- LCMCommandStatus.UNEXPECTED_ERROR, Msg.EXCEPTION_CALLING_DG, e);
- }
- } else {
- String errorMsg = "LCM request cannot be processed at the moment because APPC isn't running";
- requestHandlerOutput = createErrorRequestHandlerObj(request,
- LCMCommandStatus.REJECTED, Msg.REQUEST_HANDLER_UNAVAILABLE, new APPCException(errorMsg));
- }
- return requestHandlerOutput;
+ return new RequestExecutor().executeRequest(request);
}
}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/AbstractMockHelper.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/AbstractMockHelper.java
new file mode 100644
index 000000000..7c3f96022
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/AbstractMockHelper.java
@@ -0,0 +1,66 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.mock;
+
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.Status;
+import org.onap.appc.domainmodel.lcm.ResponseContext;
+import org.onap.appc.provider.lcm.service.AbstractBaseUtils;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+
+import java.util.Properties;
+
+/**
+ * Mock Helper abstract class
+ * provide common methods for all mock services
+ */
+public class AbstractMockHelper extends AbstractBaseUtils {
+ protected RequestHandlerOutput requestHandlerOutput = new RequestHandlerOutput();
+ protected Properties properties = new Properties();
+ protected Status status;
+
+ public AbstractMockHelper() {
+ requestHandlerOutput.setResponseContext(new ResponseContext());
+ }
+
+ /**
+ * Get request handling status
+ * @return Status of this class
+ */
+ public Status getStatus() {
+ return status;
+ }
+
+ /**
+ * Set output Status to RequestHandlerOutput and return requestHandlerOutput.
+ * @return RequestHandlerOutput
+ */
+ protected RequestHandlerOutput setOutputStatus() {
+ org.onap.appc.domainmodel.lcm.Status outputStatus = new org.onap.appc.domainmodel.lcm.Status();
+ outputStatus.setCode(status.getCode());
+ outputStatus.setMessage(status.getMessage());
+ requestHandlerOutput.getResponseContext().setStatus(outputStatus);
+ return requestHandlerOutput;
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/MockQuiesceHelper.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/MockQuiesceHelper.java
new file mode 100644
index 000000000..205249b13
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/MockQuiesceHelper.java
@@ -0,0 +1,103 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.mock;
+
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import org.onap.appc.util.JsonUtil;
+import java.io.IOException;
+
+import java.util.Map;
+
+
+/**
+ * This class is here because LCM quiesce backend is not implemented.
+ * Hence this class is here to mock the handling response of LCM quiesce REST API.
+ *
+ * When backend is implemented, this file should be removed.
+ */
+public class MockQuiesceHelper extends AbstractMockHelper {
+ private final String MOCK_QUIESCE_DIR = "/tmp/lcm/quiescetraffic";
+ private final String PAUSE = "pause";
+
+ public RequestHandlerOutput quiesceTraffic(RequestHandlerInput input) {
+ if (!mockConditionExists()) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ "The quiesce-traffic command is not supported");
+ return setOutputStatus();
+ }
+
+ String vnfId = input.getRequestContext().getActionIdentifiers().getVnfId();
+ String vnfPath = String.format("%s/%s", MOCK_QUIESCE_DIR, vnfId);
+ if (!isDirectoryExist(vnfPath)) {
+ status = buildStatusForVnfId(LCMCommandStatus.VNF_NOT_FOUND, vnfId);
+ return setOutputStatus();
+ }
+
+ Map<String, String> jsonMap = getJsonMap(input.getRequestContext().getPayload());
+ if (jsonMap == null) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, "payload reading failed");
+ return setOutputStatus();
+ }
+
+ String pausePath = String.format("%s/%s", vnfPath, PAUSE);
+ if (isDirectoryExist(pausePath)) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ String.format("VNF %s is already quiesced", vnfId));
+ return setOutputStatus();
+ }
+
+ File pauseDir = new File(pausePath);
+ boolean success = pauseDir.mkdir();
+ status = success ?
+ buildStatusWithoutParams(LCMCommandStatus.ACCEPTED) :
+ buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ String.format("Failed to quiesce traffic VNF %s", vnfId));
+
+ return setOutputStatus();
+ }
+
+ private boolean mockConditionExists() {
+ return isDirectoryExist(MOCK_QUIESCE_DIR);
+ }
+
+ private boolean isDirectoryExist(String path) {
+ return Files.isDirectory(Paths.get(path));
+ }
+
+ private Map<String, String> getJsonMap(String jsonString) {
+ try {
+ return JsonUtil.convertJsonStringToFlatMap(jsonString);
+ } catch (IOException e) {
+ logger.error(String.format("MockQuiesceHelper got exception when convert json map for (%s)", jsonString), e);
+ }
+ return null;
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/MockRebootHelper.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/MockRebootHelper.java
new file mode 100644
index 000000000..1f2fb593c
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/MockRebootHelper.java
@@ -0,0 +1,70 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.mock;
+
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+/**
+ * This class is here because LCM reboot backend is not implemented.
+ * Hence this class is here to mock the handling response of LCM reboot REST API.
+ * <p>
+ * When backend is implemented, this file should be removed.
+ */
+public class MockRebootHelper extends AbstractMockHelper {
+ private final String MOCK_REBOOT_FILENAME = "/tmp/lcm/reboot";
+
+ /**
+ * Process service request through reading the mockFile.
+ * If the file doesn't exist, it will return "The reboot command is not supported"
+ * Otherwise, it will build an accepted result.
+ *
+ * @param requestHandlerInput of the input
+ * @return RequestHandlerOutput
+ */
+ public RequestHandlerOutput reboot(RequestHandlerInput requestHandlerInput) {
+ File file = new File(MOCK_REBOOT_FILENAME);
+ if (!file.exists()) {
+ // when mock file does not exist, return generic service not supported
+ status = buildStatusForErrorMsg(LCMCommandStatus.REJECTED, "The reboot command is not supported");
+ } else {
+ try {
+ properties.load(new FileInputStream(MOCK_REBOOT_FILENAME));
+ status = buildStatusWithoutParams(LCMCommandStatus.ACCEPTED);
+ } catch (IOException e) {
+ // when loading propertes from mock file failed, return with associated message
+ status = buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ String.format("cannot load properties from %s", MOCK_REBOOT_FILENAME));
+ }
+ }
+
+ return setOutputStatus();
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/MockRequestExecutor.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/MockRequestExecutor.java
new file mode 100644
index 000000000..9763e098d
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/MockRequestExecutor.java
@@ -0,0 +1,61 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.mock;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import org.onap.appc.domainmodel.lcm.VNFOperation;
+import org.onap.appc.provider.lcm.mock.query.MockQueryHelper;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+
+/**
+ * Mock Request executor which mocks backend implementation
+ * for the set of LCM commands which do not have backend support.
+ */
+public class MockRequestExecutor {
+
+ private final EELFLogger logger = EELFManager.getInstance().getLogger(MockRequestExecutor.class);
+
+ /**
+ * Execute the request.
+ * @param request of the RequestHandlerInput
+ * @return RequestHandlerOutput if mock is supported, otherwise return null.
+ */
+ public RequestHandlerOutput executeRequest(RequestHandlerInput requestHandlerInput) {
+ VNFOperation vnfOperation = requestHandlerInput.getRequestContext().getAction();
+ switch (vnfOperation) {
+ case Query:
+ logger.debug("Proceed with mock helper for query VNF");
+ return new MockQueryHelper().query(requestHandlerInput);
+ case Reboot:
+ logger.debug("Proceed with mock helper for reboot VM");
+ return new MockRebootHelper().reboot(requestHandlerInput);
+ default:
+ // do nothing
+ }
+ return null;
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/MockResumeHelper.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/MockResumeHelper.java
new file mode 100644
index 000000000..49364fb3d
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/MockResumeHelper.java
@@ -0,0 +1,84 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.mock;
+
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Map;
+
+/**
+ * This class is here because LCM resume backend is not implemented.
+ * Hence this class is here to mock the handling response of LCM resume REST API.
+ *
+ * When backend is implemented, this file should be removed.
+ */
+public class MockResumeHelper extends AbstractMockHelper {
+ private final String MOCK_RESUME_DIR = "/tmp/lcm/resumetraffic";
+ private final String RESUME = "resume";
+
+ public RequestHandlerOutput resumeTraffic(RequestHandlerInput input) {
+ if (!mockConditionExists()) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ "The resume-traffic command is not supported");
+ return setOutputStatus();
+ }
+
+ String vnfId = input.getRequestContext().getActionIdentifiers().getVnfId();
+ String vnfPath = String.format("%s/%s", MOCK_RESUME_DIR, vnfId);
+ if (!isDirectoryExist(vnfPath)) {
+ status = buildStatusForVnfId(LCMCommandStatus.VNF_NOT_FOUND, vnfId);
+ return setOutputStatus();
+ }
+
+ String resumePath = String.format("%s/%s", vnfPath, RESUME);
+ if (isDirectoryExist(resumePath)) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ String.format("VNF %s is already resumed", vnfId));
+ return setOutputStatus();
+ }
+
+ File resumeDir = new File(resumePath);
+ boolean success = resumeDir.mkdir();
+ status = success ?
+ buildStatusWithoutParams(LCMCommandStatus.ACCEPTED) :
+ buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ String.format("Failed to resume traffic VNF %s", vnfId));
+
+ return setOutputStatus();
+ }
+
+ private boolean mockConditionExists() {
+ return isDirectoryExist(MOCK_RESUME_DIR);
+ }
+
+ private boolean isDirectoryExist(String path) {
+ return Files.isDirectory(Paths.get(path));
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/MockUpgradeHelper.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/MockUpgradeHelper.java
new file mode 100644
index 000000000..c04de54bc
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/MockUpgradeHelper.java
@@ -0,0 +1,229 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.mock;
+
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+import org.onap.appc.util.JsonUtil;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Map;
+
+/**
+ * This class is here because LCM upgrade actions are not implemented.
+ * Hence this class is here to mock the handling response of LCM upgrade actions REST API.
+ *
+ * When backend is implemented, this file should be removed.
+ */
+public class MockUpgradeHelper extends AbstractMockHelper {
+ private final String MOCK_UPGRADE_DIR = "/tmp/lcm/upgrade";
+ private final String UPGRADE = "upgrade";
+
+ public RequestHandlerOutput upgradePreCheck(RequestHandlerInput input) {
+
+ if (!mockConditionExists()) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ "The upgrade-pre-check command is not supported");
+ return setOutputStatus();
+ }
+
+ String vnfId = input.getRequestContext().getActionIdentifiers().getVnfId();
+ Map<String, String> jsonMap = getJsonMap(input.getRequestContext().getPayload());
+ if (jsonMap == null) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, "payload reading failed");
+ return setOutputStatus();
+ }
+
+ String upgradePath = String.format(MOCK_UPGRADE_DIR+"/%s-%s", jsonMap.get("existing-software-version"),jsonMap.get("new-software-version"));
+
+ if (isDirectoryExist(upgradePath)) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ String.format("UpgradeCheck from %s to %s is already happened to VNF %s", jsonMap.get("existing-software-version"),jsonMap.get("new-software-version"), vnfId));
+ return setOutputStatus();
+ }
+
+ File upgradeDir = new File(upgradePath);
+ boolean success = upgradeDir.mkdir();
+ status = success ?
+ buildStatusWithoutParams(LCMCommandStatus.SUCCESS) :
+ buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ String.format("Failed to upgradePreCheck for VNF %s", vnfId));
+
+ return setOutputStatus();
+ }
+
+ public RequestHandlerOutput upgradePostCheck(RequestHandlerInput input) {
+
+ if (!mockConditionExists()) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ "The upgrade-post-check command is not supported");
+ return setOutputStatus();
+ }
+
+ String vnfId = input.getRequestContext().getActionIdentifiers().getVnfId();
+ Map<String, String> jsonMap = getJsonMap(input.getRequestContext().getPayload());
+ if (jsonMap == null) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, "payload reading failed");
+ return setOutputStatus();
+ }
+
+ String upgradePath = String.format(MOCK_UPGRADE_DIR+"/%s/%s", jsonMap.get("existing-software-version"),jsonMap.get("new-software-version"));
+
+ if (isDirectoryExist(upgradePath)) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ String.format("UpgradePostcheck from %s to %s is already happened to VNF %s", jsonMap.get("existing-software-version"),jsonMap.get("new-software-version"), vnfId));
+ return setOutputStatus();
+ }
+
+ File upgradeDir = new File(upgradePath);
+ boolean success = upgradeDir.mkdir();
+ status = success ?
+ buildStatusWithoutParams(LCMCommandStatus.SUCCESS) :
+ buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ String.format("Failed to upgradePostCheck for %s ", vnfId));
+
+ return setOutputStatus();
+ }
+
+ public RequestHandlerOutput upgradeSoftware(RequestHandlerInput input) {
+
+ if (!mockConditionExists()) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ "The upgrade-software command is not supported");
+ return setOutputStatus();
+ }
+
+ String vnfId = input.getRequestContext().getActionIdentifiers().getVnfId();
+ Map<String, String> jsonMap = getJsonMap(input.getRequestContext().getPayload());
+ if (jsonMap == null) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, "payload reading failed");
+ return setOutputStatus();
+ }
+
+ String upgradePath = String.format(MOCK_UPGRADE_DIR+"/%s/%s", jsonMap.get("existing-software-version"),jsonMap.get("new-software-version"));
+
+ if (isDirectoryExist(upgradePath)) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ String.format("UpgradeSoftware from %s to %s is already happened to VNF %s", jsonMap.get("existing-software-version"),jsonMap.get("new-software-version"), vnfId));
+ return setOutputStatus();
+ }
+
+ File upgradeDir = new File(upgradePath);
+ boolean success = upgradeDir.mkdir();
+ status = success ?
+ buildStatusWithoutParams(LCMCommandStatus.SUCCESS) :
+ buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ String.format("Failed to upgradeSoftware for VNF %s", vnfId));
+
+ return setOutputStatus();
+ }
+
+ public RequestHandlerOutput upgradeBackup(RequestHandlerInput input) {
+
+ if (!mockConditionExists()) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ "The upgrade-backup command is not supported");
+ return setOutputStatus();
+ }
+
+ String vnfId = input.getRequestContext().getActionIdentifiers().getVnfId();
+ Map<String, String> jsonMap = getJsonMap(input.getRequestContext().getPayload());
+ if (jsonMap == null) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, "payload reading failed");
+ return setOutputStatus();
+ }
+
+ String upgradePath = String.format(MOCK_UPGRADE_DIR+"/%s/%s", jsonMap.get("existing-software-version"),jsonMap.get("new-software-version"));
+
+ if (isDirectoryExist(upgradePath)) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ String.format("UpgradeBackup from %s to %s is already happened to VNF %s", jsonMap.get("existing-software-version"),jsonMap.get("new-software-version"), vnfId));
+ return setOutputStatus();
+ }
+
+ File upgradeDir = new File(upgradePath);
+ boolean success = upgradeDir.mkdir();
+ status = success ?
+ buildStatusWithoutParams(LCMCommandStatus.SUCCESS) :
+ buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ String.format("Failed to upgradeBackup for VNF %s", vnfId));
+
+ return setOutputStatus();
+ }
+
+ public RequestHandlerOutput upgradeBackout(RequestHandlerInput input) {
+
+ if (!mockConditionExists()) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ "The upgrade-backout command is not supported");
+ return setOutputStatus();
+ }
+
+ String vnfId = input.getRequestContext().getActionIdentifiers().getVnfId();
+ Map<String, String> jsonMap = getJsonMap(input.getRequestContext().getPayload());
+ if (jsonMap == null) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, "payload reading failed");
+ return setOutputStatus();
+ }
+
+ String upgradePath = String.format(MOCK_UPGRADE_DIR+"/%s/%s", jsonMap.get("existing-software-version"),jsonMap.get("new-software-version"));
+
+ if (isDirectoryExist(upgradePath)) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ String.format("UpgradeBackout from %s to %s is already happened to VNF %s", jsonMap.get("existing-software-version"),jsonMap.get("new-software-version"), vnfId));
+ return setOutputStatus();
+ }
+
+ File upgradeDir = new File(upgradePath);
+ boolean success = upgradeDir.mkdir();
+ status = success ?
+ buildStatusWithoutParams(LCMCommandStatus.SUCCESS) :
+ buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ String.format("Failed to upgradebackout for VNF %s", vnfId));
+
+ return setOutputStatus();
+ }
+
+ private boolean mockConditionExists() {
+ return isDirectoryExist(MOCK_UPGRADE_DIR);
+ }
+
+ private boolean isDirectoryExist(String path) {
+ return Files.isDirectory(Paths.get(path));
+ }
+
+ private Map<String, String> getJsonMap(String jsonString) {
+ try {
+ return JsonUtil.convertJsonStringToFlatMap(jsonString);
+ } catch (IOException e) {
+ logger.error(String.format("MockUpgradeHelper got exception when convert json map for (%s)", jsonString), e);
+ }
+ return null;
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/MockVolumeHelper.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/MockVolumeHelper.java
new file mode 100644
index 000000000..562d376b0
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/MockVolumeHelper.java
@@ -0,0 +1,140 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.mock;
+
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+import org.onap.appc.util.JsonUtil;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Map;
+
+/**
+ * This class is here because LCM attachVolume and detachVolume backends are not implemented.
+ * Hence this class is here to mock the handling response of LCM attachVolume and detachVolume REST API.
+ *
+ * When backend is implemented, this file should be removed.
+ */
+public class MockVolumeHelper extends AbstractMockHelper {
+ private final String MOCK_VOLUME_DIR = "/tmp/lcm/volume";
+ private final String VOLUME_ID_KEY = "volumeAttachment.volumeId";
+
+ public RequestHandlerOutput attachVolume(RequestHandlerInput input) {
+ if (!mockConditionExists()) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ "The attach-volume command is not supported");
+ return setOutputStatus();
+ }
+
+ String vserverId = input.getRequestContext().getActionIdentifiers().getVserverId();
+ String vserverPath = String.format("%s/%s", MOCK_VOLUME_DIR, vserverId);
+ if (!isDirectoryExist(vserverPath)) {
+ status = buildStatusForId(LCMCommandStatus.VSERVER_NOT_FOUND, vserverId);
+ return setOutputStatus();
+ }
+
+ Map<String, String> jsonMap = getJsonMap(input.getRequestContext().getPayload());
+ if (jsonMap == null) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, "payload reading failed");
+ return setOutputStatus();
+ }
+
+ String volumeId = jsonMap.get(VOLUME_ID_KEY);
+ String volumeIdPath = String.format("%s/%s", vserverPath, volumeId);
+ if (isDirectoryExist(volumeIdPath)) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ String.format("Volume %s is already attached to VM %s", volumeId, vserverId));
+ return setOutputStatus();
+ }
+
+ File volumeDir = new File(volumeIdPath);
+ boolean success = volumeDir.mkdir();
+ status = success ?
+ buildStatusWithoutParams(LCMCommandStatus.SUCCESS) :
+ buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ String.format("Failed to attach volume %s to VM %s", volumeId, vserverId));
+
+ return setOutputStatus();
+ }
+
+ public RequestHandlerOutput detachVolume(RequestHandlerInput input) {
+ if (!mockConditionExists()) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ "The detach-volume command is not supported");
+ return setOutputStatus();
+ }
+
+ String vserverId = input.getRequestContext().getActionIdentifiers().getVserverId();
+ String vserverPath = String.format("%s/%s", MOCK_VOLUME_DIR, vserverId);
+ if (!isDirectoryExist(vserverPath)) {
+ status = buildStatusForId(LCMCommandStatus.VSERVER_NOT_FOUND, vserverId);
+ return setOutputStatus();
+ }
+
+ Map<String, String> jsonMap = getJsonMap(input.getRequestContext().getPayload());
+ if (jsonMap == null) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, "payload reading failed");
+ return setOutputStatus();
+ }
+
+ String volumeId = jsonMap.get(VOLUME_ID_KEY);
+ String volumeIdPath = String.format("%s/%s", vserverPath, volumeId);
+ if (!isDirectoryExist(volumeIdPath)) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ String.format("Volume %s is not attached to VM %s", volumeId, vserverId));
+ return setOutputStatus();
+ }
+
+ File volumeDir = new File(volumeIdPath);
+ boolean success = volumeDir.delete();
+ status = success ?
+ buildStatusWithoutParams(LCMCommandStatus.SUCCESS) :
+ buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
+ String.format("Failed to attach volume %s to VM %s", volumeId, vserverId));
+
+ return setOutputStatus();
+ }
+
+ private boolean mockConditionExists() {
+ return isDirectoryExist(MOCK_VOLUME_DIR);
+ }
+
+ private boolean isDirectoryExist(String path) {
+ return Files.isDirectory(Paths.get(path));
+ }
+
+ private Map<String, String> getJsonMap(String jsonString) {
+ try {
+ return JsonUtil.convertJsonStringToFlatMap(jsonString);
+ } catch (IOException e) {
+ logger.error(String.format("MockVolumeHelper got exception when convert json map for (%s)", jsonString), e);
+ }
+ return null;
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/query/MockQueryHelper.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/query/MockQueryHelper.java
new file mode 100644
index 000000000..7e6f84e03
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/query/MockQueryHelper.java
@@ -0,0 +1,165 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.mock.query;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.VmState;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.VmStatus;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.query.output.QueryResults;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.query.output.QueryResultsBuilder;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.provider.lcm.mock.AbstractMockHelper;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * This class is here because LCM query backend is not implemented.
+ * Hence this class is here to mock the handling response of LCM query REST API.
+ *
+ * When backend is implemented, this file should be removed.
+ */
+public class MockQueryHelper extends AbstractMockHelper {
+ private final String MOCK_QUERY_FILENAME = "/tmp/lcm/query";
+
+ /** VF_STATE value are listed at https://wiki.openstack.org/wiki/VMState#vm_state */
+ private final Map<VmState, List<String>> VF_STATE_MAP = new HashMap<VmState, List<String>>() {
+ {
+ put(VmState.Inactive, Arrays.asList(
+ "INITIALIZED",
+ "PAUSED",
+ "SUSPENDED",
+ "STOPPED",
+ "SOFT_DELETED",
+ "HARD_DELETED",
+ "ERROR"));
+ put(VmState.Active, Arrays.asList(
+ "ACTIVE",
+ "RESCUED",
+ "RESIZED"));
+ put(VmState.Standby, Arrays.asList(
+ "STANDBY"
+ ));
+ }
+ };
+
+ private final EELFLogger logger = EELFManager.getInstance().getLogger(MockQueryHelper.class);
+
+ /**
+ * Process service request through reading the mockFile. File should contain:
+ * - VNF_IDS: the list of VNF IDs, separated by comma
+ * - VMS_<a VNF id>: the list of VMs of the VNF ID, separated by comma
+ * - STATE_<a VM id>: the state of the VM
+ * - STATUS_<a VM id>: the status of the VMl
+ * @param input of RequestHandleInput which contains the VNF ID
+ * @return RequestHandlerOutput
+ */
+ public RequestHandlerOutput query(RequestHandlerInput input) {
+ File file = new File(MOCK_QUERY_FILENAME);
+ if (!file.exists()) {
+ // when mock file does not exist, return generic service not supported
+ status = buildStatusForErrorMsg(LCMCommandStatus.REJECTED, "The query command is not supported");
+ return setOutputStatus();
+ }
+
+ logger.debug(String.format("MockQueryHelper loading property from file %s", MOCK_QUERY_FILENAME));
+ try {
+ properties.load(new FileInputStream(MOCK_QUERY_FILENAME));
+ } catch (IOException e) {
+ // when loading propertes from mock file failed, return with associated message
+ status = buildStatusForErrorMsg(
+ LCMCommandStatus.REJECTED, "cannot load properties from " + MOCK_QUERY_FILENAME);
+ return setOutputStatus();
+ }
+
+ String key = "VNF_IDS";
+ List<String> vnfIds =
+ Arrays.asList(properties.getProperty(key, "").split(DELIMITER_COMMA));
+ logger.debug(String.format("MockQueryHelper got vnfId %s", vnfIds.toString()));
+
+ String vnfId = input.getRequestContext().getActionIdentifiers().getVnfId();
+ if (!vnfIds.contains(vnfId)) {
+ status = buildStatusForVnfId(LCMCommandStatus.VNF_NOT_FOUND, vnfId);
+ return setOutputStatus();
+ }
+
+ key = "VMS_" + vnfId;
+ List<String> vmIds =
+ Arrays.asList(properties.getProperty(key, "").split(DELIMITER_COMMA));
+ logger.debug(String.format("MockQueryHelper got vmId %s", vmIds.toString()));
+
+ List<QueryResults> queryResultList = new ArrayList<>();
+ VmState vfState;
+ VmStatus vfStatus;
+ boolean found = false;
+ for (String vmId : vmIds) {
+ // state
+ vfState = VmState.Unknown;
+ key = "STATE_" + vmId;
+ String stateProp = properties.getProperty(key, "").toUpperCase();
+ for (Map.Entry<VmState, List<String>> aEntry: VF_STATE_MAP.entrySet()) {
+ if (aEntry.getValue().contains(stateProp)) {
+ vfState = aEntry.getKey();
+ break;
+ }
+ }
+
+ // status
+ vfStatus = VmStatus.Unknown;
+ key = "STATUS_" + vmId;
+ String statusProp = properties.getProperty(key, "unknown").toLowerCase();
+ for (VmStatus otherVfStatus : VmStatus.values()) {
+ if (statusProp.equalsIgnoreCase(otherVfStatus.name())) {
+ vfStatus = otherVfStatus;
+ }
+ }
+
+ QueryResultsBuilder queryResultBuilder = new QueryResultsBuilder();
+ queryResultBuilder.setVserverId(vmId);
+ queryResultBuilder.setVmState(vfState);
+ queryResultBuilder.setVmStatus(vfStatus);
+ queryResultList.add(queryResultBuilder.build());
+ found = true;
+ }
+
+ if (found) {
+ status = buildStatusWithoutParams(LCMCommandStatus.SUCCESS);
+ requestHandlerOutput.getResponseContext().setPayloadObject(queryResultList);
+ } else {
+ status = buildStatusForErrorMsg(LCMCommandStatus.VNF_NOT_FOUND, "no detailss for vnfId");
+ }
+
+ return setOutputStatus();
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/query/query b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/query/query
new file mode 100644
index 000000000..671e77cd0
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/mock/query/query
@@ -0,0 +1,47 @@
+##################################################################################################
+#
+# Mock data file for LCM command Query
+#
+# To use me when the backend implementation is not available,
+# copy me to /tmp/lcm directory on the APPC server
+#
+# Mock data structure:
+# VNF_IDS: stores all the mocked vnfIds, separated by comma.
+# for per vnfId:
+# VMS_<vnfId>: stores all the mocked vmIds of the specific vnfId, spearated by comma.
+# for each vmId:
+# STATE_<vmId>: stores VM state of the specific vmId.
+# VM state found at https://wiki.openstack.org/wiki/VMState#vm_state
+# STATUS_<vmId>: stores VM sattus of the specific vmId.
+#
+##################################################################################################
+VNF_IDS=vSCP,vSBG
+
+VMS_vSCP=smp001,smp002,fex001,fex002,bex001,bex002,bex003,bex004,bex005,nee001
+STATE_smp001=ACTIVE
+STATE_smp002=RESCUED
+STATE_fex001=PAUSED
+STATE_fex002=SUSPENDED
+STATE_bex001=STOPPED
+STATE_bex002=HARD_DELETED
+STATE_bex003=RESIZED
+STATE_bex004=ERROR
+STATE_bex005=SOFT_DELETED
+# left out for UNKNOWN value
+#STATE_nee001
+
+STATUS_smp001=healthy
+STATUS_smp002=unhealthy
+STATUS_fex001=healthy
+STATUS_fex002=healthy
+STATUS_bex001=unhealthy
+STATUS_bex002=unhealthy
+STATUS_bex003=unhealthy
+STATUS_bex004=unhealthy
+STATUS_bex005=unhealthy
+# left out for UNKNOWN value
+#STATUS_nee001
+
+VMS_vSBG=vm001
+STATE_vm001=STANDBY
+STATUS_vm001=healthy \ No newline at end of file
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/AbstractBaseService.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/AbstractBaseService.java
new file mode 100644
index 000000000..ccf244532
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/AbstractBaseService.java
@@ -0,0 +1,280 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.service;
+
+import org.apache.commons.lang.StringUtils;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.Status;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.logging.LoggingConstants;
+import org.onap.appc.logging.LoggingUtils;
+import org.onap.appc.provider.lcm.util.RequestInputBuilder;
+import org.onap.appc.provider.lcm.util.ValidationService;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+
+import java.text.ParseException;
+import java.util.EnumSet;
+
+public abstract class AbstractBaseService extends AbstractBaseUtils {
+ /**
+ * The list of ActionIdentifier keys.<br>
+ * The extra space in the front of the keyName is for better REST API response output.
+ */
+ enum ACTID_KEYS {
+ SERVICE_INSTANCE_ID(" service-instance-id"),
+ VF_MODULE_ID(" vf-module-id"),
+ VNF_ID(" vnf-id"),
+ VNFC_NAME(" vnfc-name"),
+ VSERVER_ID(" vserver-id");
+
+ String keyName;
+
+ ACTID_KEYS(String keyName) {
+ this.keyName = keyName;
+ }
+
+ String getKeyName() {
+ return keyName;
+ }
+ }
+
+ String rpcName;
+ Action expectedAction;
+
+ Status status;
+
+ protected AbstractBaseService(){};
+ /**
+ * Constructor
+ *
+ * @param theAction of the expected Action for this service
+ */
+ protected AbstractBaseService(Action theAction) {
+ expectedAction = theAction;
+ rpcName = getRpcName(theAction);
+ }
+
+
+ /**
+ * Validate Input: <br>
+ * - using ValidationService to do common validation <br>
+ * - validate Action matches the expected Action <br>
+ * - validate existence of ActionIdentifier <br>
+ *
+ * @param commonHeader of the input
+ * @param action of the input
+ * @param actionIdentifiers of the input
+ * @return null if validation passed, otherwise, return Status with validation failure details.
+ */
+ Status validateInput(CommonHeader commonHeader, Action action, ActionIdentifiers actionIdentifiers) {
+ // common validation
+ Status validatedStatus = ValidationService.getInstance().validateInput(commonHeader, action, rpcName);
+ if (validatedStatus != null) {
+ return validatedStatus;
+ }
+
+ // action validation
+ if (action != expectedAction) {
+ validatedStatus = buildStatusForErrorMsg(LCMCommandStatus.INVALID_INPUT_PARAMETER, "action");
+ return validatedStatus;
+ }
+
+ // action identifier
+ if (actionIdentifiers == null) {
+ validatedStatus = buildStatusForParamName(
+ LCMCommandStatus.MISSING_MANDATORY_PARAMETER, "action-identifiers");
+ }
+
+ return validatedStatus;
+ }
+
+ /**
+ * Validate input as well as VNF ID in actionIdentifier
+ *
+ * @param commonHeader of the input
+ * @param action of the input
+ * @param actionIdentifiers of the input
+ * @return null if validation passed, otherwise, return Status with validation failure details.
+ */
+ Status validateVnfId(CommonHeader commonHeader, Action action, ActionIdentifiers actionIdentifiers) {
+ Status validatedStatus = validateInput(commonHeader, action, actionIdentifiers);
+ if (validatedStatus != null) {
+ return validatedStatus;
+ }
+
+ validatedStatus = validateMustHaveParamValue(actionIdentifiers.getVnfId(), "vnf-id");
+ if (validatedStatus == null) {
+ validatedStatus = validateExcludedActIds(actionIdentifiers, EnumSet.of(ACTID_KEYS.VNF_ID));
+ }
+
+ return validatedStatus;
+ }
+
+ /**
+ * Validate input as well as VSERVER ID in actionIdentifier
+ *
+ * @param commonHeader of the input
+ * @param action of the input
+ * @param actionIdentifiers of the input
+ * @return null if validation passed, otherwise, return Status with validation failure details.
+ */
+ Status validateVserverId(CommonHeader commonHeader, Action action, ActionIdentifiers actionIdentifiers) {
+ Status validatedStatus = validateInput(commonHeader, action, actionIdentifiers);
+ if (validatedStatus != null) {
+ return validatedStatus;
+ }
+
+ validatedStatus = validateMustHaveParamValue(actionIdentifiers.getVserverId(), "vserver-id");
+ if (validatedStatus == null) {
+ validatedStatus = validateExcludedActIds(actionIdentifiers, EnumSet.of(ACTID_KEYS.VSERVER_ID));
+ }
+
+ return validatedStatus;
+ }
+
+ /**
+ * Validate a value of the must have parameter
+ * @param value the value of the parameter
+ * @param keyName the key name of the parameter
+ * @return null if validation passed, otherwise, return Status with validation failure details.
+ */
+ Status validateMustHaveParamValue(String value, String keyName) {
+ Status validatedStatus = null;
+ if (StringUtils.isEmpty(value)) {
+ if (value == null) {
+ validatedStatus = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, keyName);
+ } else {
+ validatedStatus = buildStatusForErrorMsg(LCMCommandStatus.INVALID_INPUT_PARAMETER, keyName);
+ }
+ }
+ return validatedStatus;
+ }
+
+ /**
+ * Validate the excluded Action Identifier to ensure they do not exist.
+ * Set Status if any error occurs.
+ *
+ * @param actionIdentifiers of the to be validated object
+ * @param exclusionKeys of a list of ACTID_KEYS should be ignored in this validation
+ * @return null if validation passed, otherwise, return Status with validation failure details.
+ */
+ Status validateExcludedActIds(ActionIdentifiers actionIdentifiers, EnumSet<ACTID_KEYS> exclusionKeys) {
+ StringBuilder names = new StringBuilder();
+ boolean append = false;
+ for (ACTID_KEYS key : ACTID_KEYS.values()) {
+ if (exclusionKeys.contains(key)) {
+ continue;
+ }
+
+ switch (key) {
+ case SERVICE_INSTANCE_ID:
+ append = actionIdentifiers.getServiceInstanceId() != null;
+ break;
+ case VF_MODULE_ID:
+ append = actionIdentifiers.getVfModuleId() != null;
+ break;
+ case VSERVER_ID:
+ append = actionIdentifiers.getVserverId() != null;
+ break;
+ case VNFC_NAME:
+ append = actionIdentifiers.getVnfcName() != null;
+ break;
+ case VNF_ID:
+ append = actionIdentifiers.getVnfId() != null;
+ break;
+ default:
+ append = false;
+ }
+
+ if (append) {
+ names.append(key.getKeyName()).append(DELIMITER_COMMA);
+ }
+ }
+
+ Status validatedStatus = null;
+ int namesLength = names.length();
+ if (namesLength != 0) {
+ names.setLength(namesLength - 1);
+ validatedStatus = buildStatusForErrorMsg(LCMCommandStatus.INVALID_INPUT_PARAMETER, names.toString());
+ }
+
+ return validatedStatus;
+ }
+
+ /**
+ * Get RequestHandlerInput
+ * @param commonHeader of the input
+ * @param actionIdentifiers of the input
+ * @param payload of the input
+ * @param callerClassName String of this.getClass().getName() of the call class
+ * @return the newly built RequestHandlerInput if no error occured, otherwise, return null.
+ */
+ RequestHandlerInput getRequestHandlerInput(CommonHeader commonHeader,
+ ActionIdentifiers actionIdentifiers,
+ Payload payload,
+ String callerClassName) {
+
+ try {
+ RequestInputBuilder requestInputBuilder = new RequestInputBuilder().requestContext()
+ .commonHeader(commonHeader)
+ .actionIdentifiers(actionIdentifiers)
+ .action(expectedAction.name())
+ .rpcName(rpcName);
+ if (payload != null) {
+ requestInputBuilder = requestInputBuilder.payload(payload);
+ }
+ return requestInputBuilder.build();
+ } catch (ParseException e) {
+ status = buildStatusWithParseException(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, expectedAction, e.getMessage()),
+ callerClassName);
+ }
+ return null;
+ }
+
+ /**
+ * Execute the action through RequestExecutor
+ * @param requestHandlerInput contains everything about the action
+ */
+ RequestHandlerOutput executeAction(RequestHandlerInput requestHandlerInput) {
+ RequestHandlerOutput requestHandlerOutput = null;
+ if (requestHandlerInput == null) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR,
+ "executeAction with null RequestHandlerInput");
+ } else {
+ RequestExecutor requestExecutor = new RequestExecutor();
+ requestHandlerOutput = requestExecutor.executeRequest(requestHandlerInput);
+ status = buildStatusWithDispatcherOutput(requestHandlerOutput);
+ }
+ return requestHandlerOutput;
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/AbstractBaseUtils.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/AbstractBaseUtils.java
new file mode 100644
index 000000000..d41c80805
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/AbstractBaseUtils.java
@@ -0,0 +1,157 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.service;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.Status;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.StatusBuilder;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.executor.objects.Params;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+
+import java.text.ParseException;
+
+public class AbstractBaseUtils {
+ protected final String COMMON_ERROR_MESSAGE_TEMPLATE = "Error processing %s input : %s";
+ protected final String DELIMITER_COMMA = ",";
+
+ protected final EELFLogger logger = EELFManager.getInstance().getLogger(AbstractBaseService.class);
+
+ /**
+ * Build a Status without parameter
+ *
+ * @param lcmCommandStatus for the Status code and message format
+ * @return the newly built Status
+ */
+ protected Status buildStatusWithoutParams(LCMCommandStatus lcmCommandStatus) {
+ return buildStatus(lcmCommandStatus, null, null);
+ }
+
+ /**
+ * Build a Status with "errorMsg" param key.
+ *
+ * @param lcmCommandStatus for the Status code and message format
+ * @param message String for the Status message variable
+ * @return the newly built Status
+ */
+ protected Status buildStatusForErrorMsg(LCMCommandStatus lcmCommandStatus, String message) {
+ return buildStatus(lcmCommandStatus, message, "errorMsg");
+ }
+
+ /**
+ * Build a Status with "vnfId" param key.
+ *
+ * @param lcmCommandStatus for the Status code and message format
+ * @param message String for the Status message variable
+ * @return the newly build Status
+ */
+ protected Status buildStatusForVnfId(LCMCommandStatus lcmCommandStatus, String message) {
+ return buildStatus(lcmCommandStatus, message, "vnfId");
+ }
+
+ /**
+ * Build a Status with "paramName" param key.
+ *
+ * @param lcmCommandStatus for the Status code and message format
+ * @param message String for the Status message variable
+ * @return the newly built Status
+ */
+ protected Status buildStatusForParamName(LCMCommandStatus lcmCommandStatus, String message) {
+ return buildStatus(lcmCommandStatus, message, "paramName");
+ }
+
+ /**
+ * Build a Status with "id" param key.
+ *
+ * @param lcmCommandStatus for the Status code and message format
+ * @param message String for the Status message variable
+ * @return the newly build Status
+ */
+ protected Status buildStatusForId(LCMCommandStatus lcmCommandStatus, String message) {
+ return buildStatus(lcmCommandStatus, message, "id");
+ }
+
+ /**
+ * Build a Status.
+ *
+ * @param lcmCommandStatus for the Status code and message format
+ * @param message String for the Status message variable
+ * @param key String for the LCMcommandStatus format
+ * @return the newly built Status
+ */
+ Status buildStatus(LCMCommandStatus lcmCommandStatus, String message, String key) {
+ Params params = new Params().addParam(key, message);
+ String statusMsg = lcmCommandStatus.getFormattedMessage(params);
+
+ return buildStatusWithCode(lcmCommandStatus.getResponseCode(), statusMsg);
+ }
+
+ /**
+ * Build a Status with passed in code
+ * @param statusCode Integer of the status code
+ * @param statusMsg String of the status description
+ * @return the newly build Status
+ */
+ private Status buildStatusWithCode(Integer statusCode, String statusMsg) {
+ StatusBuilder status = new StatusBuilder();
+ status.setCode(statusCode);
+ status.setMessage(statusMsg);
+ return status.build();
+ }
+
+ /**
+ * Build a Status using ParseException
+ * @param e of the ParseException
+ * @return the newly built Status
+ */
+ protected Status buildStatusWithParseException(ParseException e) {
+ String errorMessage = e.getMessage() != null ? e.getMessage() : e.toString();
+ return buildStatusForErrorMsg(LCMCommandStatus.REQUEST_PARSING_FAILED, errorMessage);
+ }
+
+ /**
+ * Build a Status using RequestHandlerOutput
+ * @param requestHandlerOutput object which contains the status code and message for building the new status
+ * @return the newly built Status
+ */
+ protected Status buildStatusWithDispatcherOutput(RequestHandlerOutput requestHandlerOutput){
+ Integer statusCode = requestHandlerOutput.getResponseContext().getStatus().getCode();
+ String statusMessage = requestHandlerOutput.getResponseContext().getStatus().getMessage();
+ return buildStatusWithCode(statusCode, statusMessage);
+ }
+
+ /**
+ * Get RPC name from Action. When there 2 words in the Action, RPC name will be dash separated string.
+ * @param action of Action object
+ * @return RPC name of the Action
+ */
+ protected String getRpcName(Action action) {
+ String regex = "([a-z])([A-Z]+)";
+ String replacement = "$1-$2";
+ return action.name().replaceAll(regex, replacement).toLowerCase();
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/ActionStatusService.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/ActionStatusService.java
new file mode 100644
index 000000000..ede2b2837
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/ActionStatusService.java
@@ -0,0 +1,114 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.service;
+
+import org.apache.commons.lang.StringUtils;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ActionStatusInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ActionStatusOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers;
+import org.onap.appc.domainmodel.lcm.ActionLevel;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+
+/**
+ * Provide LCM command service for Query action status of a previously issue LCM command
+ */
+public class ActionStatusService extends AbstractBaseService {
+
+ /**
+ * Constructor
+ */
+ public ActionStatusService() {
+ super(Action.ActionStatus);
+ logger.debug("ActionStatusService starts");
+ }
+
+ /**
+ * Query action status
+ * @param input of the ActionStatusInput which contains the information about the previous LCM command
+ * @return ActionStatusOuputBuilder containing query results
+ */
+ public ActionStatusOutputBuilder queryStatus(ActionStatusInput input) {
+ Payload outputPayload = null;
+
+ validate(input);
+ ActionIdentifiers actionIdentifiers = input.getActionIdentifiers();
+ if (null == status) {
+ RequestHandlerInput requestHandlerInput = getRequestHandlerInput(
+ input.getCommonHeader(), actionIdentifiers, input.getPayload(), this.getClass().getName());
+ if (requestHandlerInput != null) {
+ updateToMgmtActionLevel(requestHandlerInput);
+
+ RequestHandlerOutput reqHandlerOutput = executeAction(requestHandlerInput);
+
+ outputPayload = new RequestExecutor().getPayload(reqHandlerOutput);
+ }
+ }
+
+ logger.info(String.format("ActionStatus execute of '%s' finished with status %s. Reason: %s",
+ actionIdentifiers, status == null ? "null" : status.getCode().toString(),
+ status == null ? "null" : status.getMessage()));
+
+ ActionStatusOutputBuilder outputBuilder = new ActionStatusOutputBuilder();
+ outputBuilder.setPayload(outputPayload);
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ return outputBuilder;
+ }
+
+ /**
+ * Validate input for
+ * - commonHeader
+ * - Action in the input
+ * - ActionIdentifier and only has VNF ID
+ * - and payload exists and is not empty string
+ * @param input of the ActionStatusInput from the REST API
+ */
+ void validate(ActionStatusInput input) {
+ status = validateVnfId(input.getCommonHeader(), input.getAction(), input.getActionIdentifiers());
+ if (status != null) {
+ return;
+ }
+
+ Payload payload = input.getPayload();
+ if (payload == null) {
+ status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, "payload");
+ } else if (StringUtils.isEmpty(payload.getValue())) {
+ status = buildStatusForParamName(LCMCommandStatus.INVALID_INPUT_PARAMETER, "payload");
+ }
+ }
+
+ /**
+ * Update request to MGMT action level
+ * @param request of the RequestHandlerInput
+ */
+ void updateToMgmtActionLevel(RequestHandlerInput request) {
+ request.getRequestContext().setActionLevel(ActionLevel.MGMT);
+ }
+
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/QueryService.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/QueryService.java
new file mode 100644
index 000000000..2ff6fcb1d
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/QueryService.java
@@ -0,0 +1,91 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.service;
+
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.QueryInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.QueryOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.query.output.QueryResults;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+
+import java.util.List;
+
+/**
+ * Provide LCM command service for Query of VNF state/status
+ */
+public class QueryService extends AbstractBaseService {
+ private List<QueryResults> queryResultList;
+
+ /**
+ * Constructor
+ */
+ public QueryService() {
+ super(Action.Query);
+ logger.debug("QueryService starts");
+ }
+
+ /**
+ * Process the input for the query service
+ * @param input of QueryInput from the REST API input
+ * @return QueryOutputBuilder which has the query results
+ */
+ public QueryOutputBuilder process(QueryInput input) {
+ validate(input);
+ if (status == null) {
+ proceedAction(input);
+ }
+
+ QueryOutputBuilder outputBuilder = new QueryOutputBuilder();
+ outputBuilder.setStatus(status);
+ outputBuilder.setQueryResults(queryResultList);
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ return outputBuilder;
+ }
+
+ /**
+ * Validate the input.
+ * Set Status if any error occurs.
+ *
+ * @param input of QueryInput from the REST API input
+ */
+ void validate(QueryInput input) {
+ status = validateVnfId(input.getCommonHeader(), input.getAction(), input.getActionIdentifiers());
+ }
+
+ /**
+ * Proceed to action for the query service.
+ *
+ * @param input of QueryInput from the REST API input
+ */
+ void proceedAction(QueryInput input) {
+ RequestHandlerInput requestHandlerInput = getRequestHandlerInput(
+ input.getCommonHeader(), input.getActionIdentifiers(), null, this.getClass().getName());
+ if (requestHandlerInput != null) {
+ RequestHandlerOutput requestHandlerOutput = executeAction(requestHandlerInput);
+ queryResultList = (List<QueryResults>) requestHandlerOutput.getResponseContext().getPayloadObject();
+ }
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/QuiesceTrafficService.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/QuiesceTrafficService.java
new file mode 100644
index 000000000..ee6bf8517
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/QuiesceTrafficService.java
@@ -0,0 +1,124 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.service;
+
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.QuiesceTrafficInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.QuiesceTrafficOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.QuiesceTrafficOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.util.JsonUtil;
+
+import java.io.IOException;
+import java.util.Map;
+/**
+ * Provide LCM command service for Quiesce VNF traffic
+ */
+public class QuiesceTrafficService extends AbstractBaseService {
+
+ /**
+ * Constructor
+ */
+ public QuiesceTrafficService() {
+ super(Action.QuiesceTraffic);
+ logger.debug("QuiesceTrafficService starts");
+ }
+
+ /**
+ * Process the quiesce request
+ * @param input of QuiesceTrafficInput from the REST API input
+ * @return QuiesceTrafficOutputBuilder which has the process results
+ */
+ public QuiesceTrafficOutputBuilder process(QuiesceTrafficInput input) {
+ CommonHeader commonHeader = input.getCommonHeader();
+ ActionIdentifiers actionIdentifiers = input.getActionIdentifiers();
+ Payload payload = input.getPayload();
+
+ validate(commonHeader, input.getAction(), actionIdentifiers, payload);
+ if (status == null) {
+ proceedAction(commonHeader,actionIdentifiers,payload);
+ }
+
+ QuiesceTrafficOutputBuilder outputBuilder = new QuiesceTrafficOutputBuilder();
+ outputBuilder.setStatus(status);
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ return outputBuilder;
+ }
+
+ /**
+ * Validate the input.
+ * Set Status if any error occurs.
+ *
+ * @param input of QuiesceTrafficInput from the REST API input
+ */
+ void validate(CommonHeader commonHeader,
+ Action action,
+ ActionIdentifiers actionIdentifiers,
+ Payload payload) {
+ status = validateVnfId(commonHeader, action, actionIdentifiers);
+ if (status != null) {
+ return;
+ }
+
+ // validate payload
+ String keyName = "payload";
+ if (payload == null) {
+ status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, keyName);
+ return;
+ }
+ String payloadString = payload.getValue();
+ status = validateMustHaveParamValue(payloadString == null ? payloadString : payloadString.trim(), "payload");
+ if (status != null) {
+ return;
+ }
+
+ try {
+ Map<String, String> payloadMap = JsonUtil.convertJsonStringToFlatMap(payloadString);
+ validateMustHaveParamValue(payloadMap.get(keyName), keyName);
+ } catch (IOException e) {
+ logger.error(String.format("QuiesceTrafficService (%s) got IOException when converting payload", rpcName), e);
+ status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, e.getMessage());
+ }
+ }
+
+ /**
+ * Proceed to action for the quiesce VNF traffic.
+ *
+ * @param input of QuiesceTrafficInput from the REST API input
+ */
+ void proceedAction(CommonHeader commonHeader,
+ ActionIdentifiers actionIdentifiers,
+ Payload payload) {
+ RequestHandlerInput requestHandlerInput = getRequestHandlerInput(commonHeader, actionIdentifiers, payload,
+ this.getClass().getName());
+ if (requestHandlerInput != null) {
+ executeAction(requestHandlerInput);
+ }
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/RebootService.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/RebootService.java
new file mode 100644
index 000000000..f1c2354d3
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/RebootService.java
@@ -0,0 +1,110 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.service;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.RebootInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.RebootOutputBuilder;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+import org.onap.appc.util.JsonUtil;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Provide LCM command service for rebooting virtual machine (VM)
+ */
+public class RebootService extends AbstractBaseService {
+ private final EELFLogger myLogger = EELFManager.getInstance().getLogger(RebootService.class);
+ private static final String REBOOT_TYPE_PARAMETER = "reboot-type";
+ private final List<String> rebootTypeList = Arrays.asList("hard", "soft");
+
+ /**
+ * Constructor
+ */
+ public RebootService() {
+ super(Action.Reboot);
+ }
+
+ public RebootOutputBuilder process(RebootInput input) {
+ validate(input);
+ if (status == null) {
+ proceedAction(input);
+ }
+
+ final RebootOutputBuilder outputBuilder = new RebootOutputBuilder();
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ return outputBuilder;
+ }
+
+ private void proceedAction(RebootInput input) {
+ RequestHandlerInput requestHandlerInput = getRequestHandlerInput(
+ input.getCommonHeader(), input.getActionIdentifiers(), input.getPayload(), this.getClass().getName());
+ if (requestHandlerInput != null) {
+ executeAction(requestHandlerInput);
+ }
+ }
+
+ private String getRebootType(RebootInput input) {
+ String rebootType = null;
+ if (input.getPayload() != null) {
+ Map<String, String> payloadMap;
+ try {
+ payloadMap = JsonUtil.convertJsonStringToFlatMap(input.getPayload().getValue());
+ rebootType = payloadMap.get(REBOOT_TYPE_PARAMETER);
+ } catch (IOException e) {
+ myLogger.error("Error in converting payload of RebootInput", e.getMessage());
+ }
+ }
+
+ return rebootType;
+ }
+
+ /**
+ * Validate the input.
+ *
+ * @param input of RebootInput from the REST API input
+ */
+ private void validate(RebootInput input) {
+ status = validateVserverId(input.getCommonHeader(), input.getAction(), input.getActionIdentifiers());
+ if (status != null) {
+ return;
+ }
+
+ //reboot-type validation
+ final String rebootType = getRebootType(input);
+ if (null == rebootType) {
+ status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, REBOOT_TYPE_PARAMETER);
+ } else if (!rebootTypeList.contains(rebootType)) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.INVALID_INPUT_PARAMETER, REBOOT_TYPE_PARAMETER);
+ }
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/RequestExecutor.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/RequestExecutor.java
new file mode 100644
index 000000000..66872588f
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/RequestExecutor.java
@@ -0,0 +1,178 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.service;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.att.eelf.i18n.EELFResourceManager;
+import com.google.common.base.Strings;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload;
+import org.onap.appc.Constants;
+import org.onap.appc.configuration.Configuration;
+import org.onap.appc.configuration.ConfigurationFactory;
+import org.onap.appc.domainmodel.lcm.ActionLevel;
+import org.onap.appc.domainmodel.lcm.ResponseContext;
+import org.onap.appc.exceptions.APPCException;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.executor.objects.Params;
+import org.onap.appc.i18n.Msg;
+import org.onap.appc.logging.LoggingConstants;
+import org.onap.appc.logging.LoggingUtils;
+import org.onap.appc.provider.AppcProviderLcm;
+import org.onap.appc.provider.lcm.mock.MockRequestExecutor;
+import org.onap.appc.requesthandler.RequestHandler;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Collection;
+
+/**
+ * Provider LCM request executor
+ */
+public class RequestExecutor {
+ final String CANNOT_PROCESS = "LCM request cannot be processed at the moment because APPC isn't running";
+
+ private final Configuration configuration = ConfigurationFactory.getConfiguration();
+ private final EELFLogger logger = EELFManager.getInstance().getLogger(AppcProviderLcm.class);
+
+ /**
+ * Execute the request.
+ * @param requestHandlerInput of the RequestHandlerInput
+ * @return RequestHandlerOutput
+ */
+ public RequestHandlerOutput executeRequest(RequestHandlerInput requestHandlerInput) {
+ // TODO mock backend should be removed when backend implementation is done
+ RequestHandlerOutput requestHandlerOutput = new MockRequestExecutor().executeRequest(requestHandlerInput);
+ if (requestHandlerOutput != null) {
+ // mock support, return mock results
+ return requestHandlerOutput;
+ }
+
+ RequestHandler handler = getRequestHandler(requestHandlerInput.getRequestContext().getActionLevel());
+ if (handler == null) {
+ logger.debug("execute while requesthandler is null");
+ requestHandlerOutput = createRequestHandlerOutput(requestHandlerInput,
+ LCMCommandStatus.REJECTED, Msg.REQUEST_HANDLER_UNAVAILABLE, new APPCException(CANNOT_PROCESS));
+ } else {
+ try {
+ logger.debug("execute while requesthandler is not null");
+ requestHandlerOutput = handler.handleRequest(requestHandlerInput);
+ } catch (Exception e) {
+ logger.info(String.format("UNEXPECTED FAILURE while executing %s action",
+ requestHandlerInput.getRequestContext().getAction().name()));
+ requestHandlerOutput = createRequestHandlerOutput(requestHandlerInput,
+ LCMCommandStatus.UNEXPECTED_ERROR, Msg.EXCEPTION_CALLING_DG, e);
+ }
+ }
+ return requestHandlerOutput;
+ }
+
+ /**
+ * Get Request handler by ActionLevel
+ * @param actionLevel the ActionLevel
+ * @return RequestHandler if found, otherwise return null or throw RuntimeException
+ */
+ RequestHandler getRequestHandler(ActionLevel actionLevel) {
+ final BundleContext context = FrameworkUtil.getBundle(RequestHandler.class).getBundleContext();
+ if (context == null) {
+ return null;
+ }
+
+ String filter = null;
+ try {
+ filter = "(level=" + actionLevel.name() + ")";
+ Collection<ServiceReference<RequestHandler>> serviceReferences =
+ context.getServiceReferences(RequestHandler.class, filter);
+ if (serviceReferences.size() == 1) {
+ ServiceReference<RequestHandler> serviceReference = serviceReferences.iterator().next();
+ return context.getService(serviceReference);
+ }
+
+ logger.error(String.format("Cannot find service reference for %s", RequestHandler.class.getName()));
+ throw new RuntimeException();
+
+ } catch (InvalidSyntaxException e) {
+ logger.error(String.format("Cannot find service reference for %s: Invalid Syntax %s",
+ RequestHandler.class.getName(), filter), e);
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Create request handler output
+ * @param request of RequestHandlerInput
+ * @param cmdStatus of LCMCommandStatus
+ * @param msg of Msg for audit log
+ * @param e of the Exception
+ * @return generated RequestHandlerOutput based on the input
+ */
+ RequestHandlerOutput createRequestHandlerOutput(RequestHandlerInput request,
+ LCMCommandStatus cmdStatus,
+ Msg msg,
+ Exception e) {
+ String errorMsg = e.getMessage() != null ? e.getMessage() : e.toString();
+ Params params = new Params().addParam("errorMsg", errorMsg);
+
+ final org.onap.appc.domainmodel.lcm.Status status = new org.onap.appc.domainmodel.lcm.Status();
+ status.setMessage(cmdStatus.getFormattedMessage(params));
+ status.setCode(cmdStatus.getResponseCode());
+
+ final ResponseContext responseContext = new ResponseContext();
+ responseContext.setCommonHeader(request.getRequestContext().getCommonHeader());
+ responseContext.setStatus(status);
+
+ RequestHandlerOutput requestHandlerOutput = new RequestHandlerOutput();
+ requestHandlerOutput.setResponseContext(responseContext);
+
+ final String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
+ final String reason = EELFResourceManager.format(
+ msg, e, appName, e.getClass().getSimpleName(), "", e.getMessage());
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ reason,
+ this.getClass().getName());
+
+ return requestHandlerOutput;
+ }
+
+ /**
+ * Get payload from passed in RequestHandlerOutput
+ * @param output of the RequestHandlerOutput
+ * @return If the passed in RequestHandlerOutput contains payload, return a Payload object of the payload.
+ * Otherwise, return null.
+ */
+ public Payload getPayload(RequestHandlerOutput output) {
+ if (output.getResponseContext() == null
+ || Strings.isNullOrEmpty(output.getResponseContext().getPayload())) {
+ return null;
+ }
+
+ return new Payload(output.getResponseContext().getPayload());
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/ResumeTrafficService.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/ResumeTrafficService.java
new file mode 100644
index 000000000..53d038141
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/ResumeTrafficService.java
@@ -0,0 +1,99 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.service;
+
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ResumeTrafficInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ResumeTrafficOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ResumeTrafficOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.util.JsonUtil;
+
+import java.io.IOException;
+import java.util.Map;
+/**
+ * Provide LCM command service for Resume VNF traffic
+ */
+public class ResumeTrafficService extends AbstractBaseService {
+
+ /**
+ * Constructor
+ */
+ public ResumeTrafficService() {
+ super(Action.ResumeTraffic);
+ logger.debug("ResumeTrafficService starts");
+ }
+
+ /**
+ * Process the Resume request
+ * @param input of ResumeTrafficInput from the REST API input
+ * @return ResumeTrafficOutputBuilder which has the process results
+ */
+ public ResumeTrafficOutputBuilder process(ResumeTrafficInput input) {
+ CommonHeader commonHeader = input.getCommonHeader();
+ ActionIdentifiers actionIdentifiers = input.getActionIdentifiers();
+
+ validate(commonHeader, input.getAction(), actionIdentifiers);
+ if (status == null) {
+ proceedAction(input);
+ }
+
+ ResumeTrafficOutputBuilder outputBuilder = new ResumeTrafficOutputBuilder();
+ outputBuilder.setStatus(status);
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ return outputBuilder;
+ }
+
+ /**
+ * Validate the input.
+ * Set Status if any error occurs.
+ *
+ * @param input of ResumeTrafficInput from the REST API input
+ */
+ void validate(CommonHeader commonHeader,
+ Action action,
+ ActionIdentifiers actionIdentifiers) {
+ status = validateVnfId(commonHeader, action, actionIdentifiers);
+ if (status != null) {
+ return;
+ }
+ }
+
+ /**
+ * Proceed to action for the Resume VNF traffic.
+ *
+ * @param input of ResumeTrafficInput from the REST API input
+ */
+ void proceedAction(ResumeTrafficInput input) {
+ RequestHandlerInput requestHandlerInput = getRequestHandlerInput(
+ input.getCommonHeader(), input.getActionIdentifiers(), null, this.getClass().getName());
+ if (requestHandlerInput != null) {
+ executeAction(requestHandlerInput);
+ }
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/UpgradeService.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/UpgradeService.java
new file mode 100644
index 000000000..04f3954c5
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/UpgradeService.java
@@ -0,0 +1,200 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.service;
+
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UpgradePreCheckInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UpgradePreCheckOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UpgradeSoftwareInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UpgradeSoftwareOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UpgradePostCheckInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UpgradePostCheckOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UpgradeBackupInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UpgradeBackupOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UpgradeBackoutInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UpgradeBackoutOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+import org.onap.appc.util.JsonUtil;
+
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * Provide LCM command service for attach/detach a cinder to a VM
+ */
+public class UpgradeService extends AbstractBaseService {
+ /**
+ * Constructor
+ *
+ */
+ public UpgradeService(String upgrade) {
+ switch(upgrade){
+ case "upgradePre":
+ rpcName = getRpcName(Action.UpgradePreCheck);
+ expectedAction = Action.UpgradePreCheck;
+ break;
+ case "upgradePost":
+ rpcName = getRpcName(Action.UpgradePostCheck);
+ expectedAction = Action.UpgradePostCheck;
+ break;
+ case "upgradeSoft":
+ rpcName = getRpcName(Action.UpgradeSoftware);
+ expectedAction = Action.UpgradeSoftware;
+ break;
+ case "upgradeBackup":
+ rpcName = getRpcName(Action.UpgradeBackup);
+ expectedAction = Action.UpgradeBackup;
+ break;
+ case "upgradeBackout":
+ rpcName = getRpcName(Action.UpgradeBackout);
+ expectedAction = Action.UpgradeBackout;
+ break;
+ }
+ logger.debug("UpgradeService starts ", upgrade);
+ }
+
+ public UpgradePreCheckOutputBuilder upgradePreCheck(UpgradePreCheckInput input) {
+ CommonHeader commonHeader = input.getCommonHeader();
+ ActionIdentifiers actionIdentifiers = input.getActionIdentifiers();
+ Payload payload = input.getPayload();
+
+ validate(commonHeader, input.getAction(), actionIdentifiers, payload);
+ if (status == null) {
+ proceedAction(commonHeader, actionIdentifiers, payload);
+ }
+
+ UpgradePreCheckOutputBuilder outputBuilder = new UpgradePreCheckOutputBuilder();
+ outputBuilder.setStatus(status);
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ return outputBuilder;
+ }
+
+
+ public UpgradeSoftwareOutputBuilder upgradeSoftware(UpgradeSoftwareInput input) {
+ CommonHeader commonHeader = input.getCommonHeader();
+ ActionIdentifiers actionIdentifiers = input.getActionIdentifiers();
+ Payload payload = input.getPayload();
+
+ validate(commonHeader, input.getAction(), actionIdentifiers, payload);
+ if (status == null) {
+ proceedAction(commonHeader, actionIdentifiers, payload);
+ }
+
+ UpgradeSoftwareOutputBuilder outputBuilder = new UpgradeSoftwareOutputBuilder();
+ outputBuilder.setStatus(status);
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ return outputBuilder;
+ }
+ public UpgradePostCheckOutputBuilder upgradePostCheck(UpgradePostCheckInput input) {
+ CommonHeader commonHeader = input.getCommonHeader();
+ ActionIdentifiers actionIdentifiers = input.getActionIdentifiers();
+ Payload payload = input.getPayload();
+
+ validate(commonHeader, input.getAction(), actionIdentifiers, payload);
+ if (status == null) {
+ proceedAction(commonHeader, actionIdentifiers, payload);
+ }
+
+ UpgradePostCheckOutputBuilder outputBuilder = new UpgradePostCheckOutputBuilder();
+ outputBuilder.setStatus(status);
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ return outputBuilder;
+ }
+
+ public UpgradeBackupOutputBuilder upgradeBackup(UpgradeBackupInput input) {
+ CommonHeader commonHeader = input.getCommonHeader();
+ ActionIdentifiers actionIdentifiers = input.getActionIdentifiers();
+ Payload payload = input.getPayload();
+
+ validate(commonHeader, input.getAction(), actionIdentifiers, payload);
+ if (status == null) {
+ proceedAction(commonHeader, actionIdentifiers, payload);
+ }
+
+ UpgradeBackupOutputBuilder outputBuilder = new UpgradeBackupOutputBuilder();
+ outputBuilder.setStatus(status);
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ return outputBuilder;
+ }
+ public UpgradeBackoutOutputBuilder upgradeBackout(UpgradeBackoutInput input) {
+ CommonHeader commonHeader = input.getCommonHeader();
+ ActionIdentifiers actionIdentifiers = input.getActionIdentifiers();
+ Payload payload = input.getPayload();
+
+ validate(commonHeader, input.getAction(), actionIdentifiers, payload);
+ if (status == null) {
+ proceedAction(commonHeader, actionIdentifiers, payload);
+ }
+
+ UpgradeBackoutOutputBuilder outputBuilder = new UpgradeBackoutOutputBuilder();
+ outputBuilder.setStatus(status);
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ return outputBuilder;
+ }
+ void validate(CommonHeader commonHeader,
+ Action action,
+ ActionIdentifiers actionIdentifiers,
+ Payload payload) {
+ status = validateVnfId(commonHeader, action, actionIdentifiers);
+ if (status != null) {
+ return;
+ }
+
+ // validate payload
+ String keyName = "payload";
+ if (payload == null) {
+ status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, keyName);
+ return;
+ }
+ String payloadString = payload.getValue();
+ status = validateMustHaveParamValue(
+ payloadString == null ? payloadString : payloadString.trim(), "payload");
+ if (status != null) {
+ return;
+ }
+
+ try {
+ Map<String, String> payloadMap = JsonUtil.convertJsonStringToFlatMap(payloadString);
+ validateMustHaveParamValue(payloadMap.get(keyName), keyName);
+ } catch (IOException e) {
+ logger.error(String.format("UpgradeService (%s) got IOException when converting payload", rpcName), e);
+ status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, e.getMessage());
+ }
+ }
+
+ void proceedAction(CommonHeader commonHeader,
+ ActionIdentifiers actionIdentifiers,
+ Payload payload) {
+ RequestHandlerInput requestHandlerInput =
+ getRequestHandlerInput(commonHeader, actionIdentifiers, payload, this.getClass().getName());
+ if (requestHandlerInput != null) {
+ executeAction(requestHandlerInput);
+ }
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/VolumeService.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/VolumeService.java
new file mode 100644
index 000000000..74524a79e
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/VolumeService.java
@@ -0,0 +1,165 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.service;
+
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.AttachVolumeInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.AttachVolumeOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.DetachVolumeInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.DetachVolumeOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.Status;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+import org.onap.appc.util.JsonUtil;
+import java.util.EnumSet;
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * Provide LCM command service for attach/detach a cinder to a VM
+ */
+public class VolumeService extends AbstractBaseService {
+ /**
+ * Constructor
+ *
+ * @param isAttachVolume boolean to indicate if this VolumeSerivce is created for attaching or detaching cinder
+ */
+ public VolumeService(boolean isAttachVolume) {
+ super(isAttachVolume ? Action.AttachVolume : Action.DetachVolume);
+ logger.debug("VolumeService starts ", isAttachVolume);
+ }
+
+ /**
+ * Attach a cinder to the VM volume
+ *
+ * @param input of AttachVolumeInput from the REST API input
+ * @return AttachVolumeOutputBuilder which has the details of the request results
+ */
+ public AttachVolumeOutputBuilder attachVolume(AttachVolumeInput input) {
+ CommonHeader commonHeader = input.getCommonHeader();
+ ActionIdentifiers actionIdentifiers = input.getActionIdentifiers();
+ Payload payload = input.getPayload();
+
+ validate(commonHeader, input.getAction(), actionIdentifiers,payload);
+ if (status == null) {
+ proceedAction(commonHeader, actionIdentifiers, payload);
+ }
+
+ AttachVolumeOutputBuilder outputBuilder = new AttachVolumeOutputBuilder();
+ outputBuilder.setStatus(status);
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ return outputBuilder;
+ }
+
+ /**
+ * Detach a cinder to the VM volume
+ *
+ * @param input of DetachVolumeInput from the REST API input
+ * @return DetachVolumeOutputBuilder which has the details of the request results
+ */
+ public DetachVolumeOutputBuilder detachVolume(DetachVolumeInput input) {
+ CommonHeader commonHeader = input.getCommonHeader();
+ ActionIdentifiers actionIdentifiers = input.getActionIdentifiers();
+ Payload payload = input.getPayload();
+
+ validate(commonHeader, input.getAction(), actionIdentifiers,payload);
+ if (status == null) {
+ proceedAction(commonHeader, actionIdentifiers, payload);
+ }
+
+ DetachVolumeOutputBuilder outputBuilder = new DetachVolumeOutputBuilder();
+ outputBuilder.setStatus(status);
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ return outputBuilder;
+ }
+
+ void validate(CommonHeader commonHeader,
+ Action action,
+ ActionIdentifiers actionIdentifiers,
+ Payload payload) {
+ status = validateVserverIdVnfId(commonHeader, action, actionIdentifiers);
+ if (status != null) {
+ return;
+ }
+
+ // validate payload
+ String keyName = "payload";
+ if (payload == null) {
+ status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, keyName);
+ return;
+ }
+ String payloadString = payload.getValue();
+ status = validateMustHaveParamValue(
+ payloadString == null ? payloadString : payloadString.trim(), "payload");
+ if (status != null) {
+ return;
+ }
+
+ try {
+ Map<String, String> payloadMap = JsonUtil.convertJsonStringToFlatMap(payloadString);
+ validateMustHaveParamValue(payloadMap.get(keyName), keyName);
+ } catch (IOException e) {
+ logger.error(String.format("VolumeService (%s) got IOException when converting payload", rpcName), e);
+ status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, e.getMessage());
+ }
+ }
+
+ Status validateVserverIdVnfId(CommonHeader commonHeader, Action action, ActionIdentifiers actionIdentifiers ) {
+ Status validatedStatus = validateInput(commonHeader, action, actionIdentifiers);
+
+ if (validatedStatus != null) {
+ return validatedStatus;
+ }
+
+ validatedStatus = validateMustHaveParamValue(actionIdentifiers.getVserverId(), "vserver-id");
+ if (validatedStatus == null) {
+ validatedStatus = validateMustHaveParamValue(actionIdentifiers.getVserverId(), "vnf-id");
+ logger.debug("check for vnf-id");
+ }
+ if (validatedStatus == null) {
+ validatedStatus = validateExcludedActIds(actionIdentifiers, EnumSet.of(ACTID_KEYS.VSERVER_ID, ACTID_KEYS.VNF_ID));
+ }
+ logger.debug("check for ActIds");
+ return validatedStatus;
+ }
+ /**
+ * Proceed to action for the attach or detach volume.
+ * @param commonHeader of the input
+ * @param actionIdentifiers of the input
+ * @param payload of the input
+ */
+ void proceedAction(CommonHeader commonHeader,
+ ActionIdentifiers actionIdentifiers,
+ Payload payload) {
+ RequestHandlerInput requestHandlerInput =
+ getRequestHandlerInput(commonHeader, actionIdentifiers, payload, this.getClass().getName());
+ if (requestHandlerInput != null) {
+ executeAction(requestHandlerInput);
+ }
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/util/RequestInputBuilder.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/util/RequestInputBuilder.java
index 979c834de..56f094565 100644
--- a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/util/RequestInputBuilder.java
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/util/RequestInputBuilder.java
@@ -28,12 +28,11 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.common.header.Flags;
-import org.onap.appc.domainmodel.lcm.Flags.Mode;
import org.onap.appc.domainmodel.lcm.ActionLevel;
import org.onap.appc.domainmodel.lcm.RequestContext;
import org.onap.appc.domainmodel.lcm.VNFOperation;
@@ -44,16 +43,13 @@ import com.att.eelf.configuration.EELFManager;
public class RequestInputBuilder {
- private static EELFLogger logger = EELFManager.getInstance().getApplicationLogger();
+ private final EELFLogger logger = EELFManager.getInstance().getApplicationLogger();
private static final String FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
private RequestContext requestContext;
private String rpcName;
- public RequestInputBuilder() {
- }
-
public RequestInputBuilder requestContext() {
this.requestContext = new RequestContext();
@@ -99,7 +95,7 @@ public class RequestInputBuilder {
SimpleDateFormat format = new SimpleDateFormat(FORMAT);
format.setLenient(false);
format.setTimeZone(TimeZone.getTimeZone("UTC"));
- header.setTimestamp(format.parse(commonHeader.getTimestamp().getValue()).toInstant());
+ header.setTimestamp(format.parse(commonHeader.getTimestamp().getValue()));
}else{
throw new ParseException("Missing mandatory parameter : timestamp " , 0);
}
@@ -113,23 +109,21 @@ public class RequestInputBuilder {
header.setSubRequestId(commonHeader.getSubRequestId());
Flags inFlags = commonHeader.getFlags();
- boolean force = false;
- Mode mode = null;
- int ttl = 0;
+ org.onap.appc.domainmodel.lcm.Flags flags = new org.onap.appc.domainmodel.lcm.Flags();
if (inFlags != null) {
- if (null != inFlags.getForce()) {
- force = Boolean.parseBoolean(inFlags.getForce().toString().toLowerCase());
+ if(null != inFlags.getForce()) {
+ flags.setForce(Boolean.parseBoolean(inFlags.getForce().toString().toLowerCase()));
}
- if (null != inFlags.getMode()) {
- mode = Mode.valueOf(inFlags.getMode().name());
+ if(null!=inFlags.getMode()) {
+ flags.setMode(inFlags.getMode().name());
}
- if (null != inFlags.getTtl()) {
- ttl = inFlags.getTtl();
+ if(null!= inFlags.getTtl()) {
+ flags.setTtl(inFlags.getTtl());
}
}
- this.requestContext.getCommonHeader().setFlags(new org.onap.appc.domainmodel.lcm.Flags(mode, force, ttl));
+ this.requestContext.getCommonHeader().setFlags(flags);
return this;
}
@@ -143,7 +137,7 @@ public class RequestInputBuilder {
actionIds.setVfModuleId(actionIdentifiers.getVfModuleId());
this.requestContext.setActionIdentifiers(actionIds);
- ActionLevel actionLevel = readActionLevel(actionIds);
+ ActionLevel actionLevel=ActionLevel.VNF;
this.requestContext.setActionLevel(actionLevel);
return this;
}else{
@@ -151,12 +145,4 @@ public class RequestInputBuilder {
}
}
- private ActionLevel readActionLevel(org.onap.appc.domainmodel.lcm.ActionIdentifiers actionIds) {
- if(!StringUtils.isEmpty(actionIds.getVserverId())){
- return ActionLevel.VM;
- }
- return ActionLevel.VNF;
- }
-
-
}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/util/ValidationService.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/util/ValidationService.java
index 69e100b57..fc53e8ebd 100644
--- a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/util/ValidationService.java
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/util/ValidationService.java
@@ -38,10 +38,6 @@ import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.att.eelf.i18n.EELFResourceManager;
-import javax.swing.*;
-
-
-
public class ValidationService {
private static class ValidationServiceHolder {
@@ -49,46 +45,62 @@ public class ValidationService {
}
private final EELFLogger logger = EELFManager.getInstance().getLogger(ValidationService.class);
-
private Configuration configuration = ConfigurationFactory.getConfiguration();
public static ValidationService getInstance(){
return ValidationServiceHolder.INSTANCE;
}
- public Status validateInput (CommonHeader commonHeader, Action action , String rpcName) {
- String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
- String reason ;
- StringBuilder paramName = new StringBuilder("");
- if (!isEmpty(commonHeader) && !isEmpty(commonHeader.getApiVer())&& !isEmpty(commonHeader.getTimestamp()) && !isEmpty(commonHeader.getRequestId()) && !isEmpty(action) && !isEmpty(commonHeader.getOriginatorId())){
- if(!action.toString().equalsIgnoreCase(rpcName)) logger.warn("action in input request '" + action.toString() + "' is different from endpoint '" + rpcName + "'");
+ public Status validateInput(CommonHeader commonHeader, Action action , String rpcName) {
+ if (!isEmpty(commonHeader)
+ && !isEmpty(commonHeader.getApiVer())
+ && !isEmpty(commonHeader.getTimestamp())
+ && !isEmpty(commonHeader.getRequestId())
+ && !isEmpty(commonHeader.getOriginatorId())
+ && !isEmpty(action)) {
return null;
- } else{
- if(isEmpty(commonHeader)){
- paramName.append("common-header");
- }else{
- if (isEmpty(commonHeader.getApiVer())) paramName.append("api-ver");
- if (isEmpty(commonHeader.getTimestamp())) paramName.append(isEmpty(paramName) ? "timestamp" : " , timestamp" );
- if (isEmpty(commonHeader.getRequestId())) paramName.append(isEmpty(paramName) ? "request-id" : " , request-id" );
- if (isEmpty(commonHeader.getOriginatorId())) paramName.append(isEmpty(paramName) ? "originator-id" : " , originator-id" );
- }
- if (isEmpty(action)) paramName.append(isEmpty(paramName) ? "action" : " , action" );
}
+ StringBuilder paramName = new StringBuilder();
+ if(isEmpty(commonHeader)){
+ paramName.append("common-header");
+ } else {
+ if (isEmpty(commonHeader.getApiVer())) {
+ paramName.append("api-ver");
+ }
+ if (isEmpty(commonHeader.getTimestamp())) {
+ paramName.append(isEmpty(paramName) ? "timestamp" : " , timestamp");
+ }
+ if (isEmpty(commonHeader.getRequestId())) {
+ paramName.append(isEmpty(paramName) ? "request-id" : " , request-id");
+ }
+ if (isEmpty(commonHeader.getOriginatorId())) {
+ paramName.append(isEmpty(paramName) ? "originator-id" : " , originator-id");
+ }
+ }
+ if (isEmpty(action)) {
+ paramName.append(isEmpty(paramName) ? "action" : " , action");
+ }
-
- reason = EELFResourceManager.format(Msg.NULL_OR_INVALID_ARGUMENT, appName, rpcName, paramName.toString() , "");
logger.info("Mandatory parameter/s" + paramName.toString() + " is/are missing");
+ String reason = EELFResourceManager.format(
+ Msg.NULL_OR_INVALID_ARGUMENT,
+ configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME),
+ rpcName,
+ paramName.toString(),
+ "");
logger.error(reason);
+
LCMCommandStatus lcmCommandStatus = LCMCommandStatus.MISSING_MANDATORY_PARAMETER;
Params params = new Params().addParam("paramName", paramName.toString());
+
StatusBuilder status = new StatusBuilder();
status.setCode(lcmCommandStatus.getResponseCode());
status.setMessage(lcmCommandStatus.getFormattedMessage(params));
return status.build();
}
- private boolean isEmpty (Object object){
- return (null == object || "".equalsIgnoreCase(object.toString()));
+ private boolean isEmpty(Object object) {
+ return null == object || "".equalsIgnoreCase(object.toString());
}
}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/topology/TopologyService.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/topology/TopologyService.java
index ea1d3f1ee..35258ed49 100644
--- a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/topology/TopologyService.java
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/topology/TopologyService.java
@@ -80,12 +80,10 @@ public class TopologyService {
/**
* The loggers we are using
*/
- // private static EELFLogger logger = LoggerFactory.getLogger(TopologyService.class);
- private static EELFLogger logger = EELFManager.getInstance().getApplicationLogger();
- private static EELFLogger securityLogger = EELFManager.getInstance().getSecurityLogger();
- private static EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
- private static EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
- private static EELFLogger performanceLogger = EELFManager.getInstance().getPerformanceLogger();
+ private final EELFLogger logger = EELFManager.getInstance().getApplicationLogger();
+ private final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
+ private final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
+ private final EELFLogger performanceLogger = EELFManager.getInstance().getPerformanceLogger();
/**
* The provider we are servicing
@@ -112,80 +110,20 @@ public class TopologyService {
this.provider = provider;
}
- // /**
- // * Processes the topology request
- // *
- // * @param input
- // * The request to be processed
- // * @return The result of processing
- // */
- // public RpcResult<TopologyOperationOutput> process(TopologyOperationInput input) {
- // RpcResult<TopologyOperationOutput> response;
- //
- // String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
- // logger.info(String.format("%s:topology operations called...", appName));
- //
- // /*
- // * Properties used to pass information to the DG
- // */
- // Properties properties = new Properties();
- //
- // if (input == null || input.getTopologyRequest().getVmId() == null) {
- // String msg =
- // String.format("%s: topology operation failed, invalid input. Null or empty argument '%s'", appName,
- // "vm_id");
- // logger.debug(msg);
- // response = generateTopologyOperationResponse(Boolean.FALSE, "UNKNOWN", msg, "UNDEFINED");
- // } else {
- // // CommonRequestHeader crh = input.getCommonRequestHeader();
- // TopologyHeader hdr = input.getTopologyHeader();
- // TopologyRequest req = input.getTopologyRequest();
- //
- // // String requestId = crh.getServiceRequestId();
- // String requestId = hdr.getSvcRequestId();
- // properties.put(Constants.CONTEXT_REQID, requestId);
- //
- // String infomsg = String.format("Topology request '%s' (%s) received.", requestId, hdr.getSvcAction());
- //
- // // switch (req.getSvcAction()) {
- // switch (hdr.getSvcAction()) {
- // case Restart:
- // properties.put(Constants.CONTEXT_SERVICE, Constants.SERVICE_RESTART);
- // response = restart(input, properties);
- // logger.info(infomsg);
- // break;
- //
- // case Rebuild:
- // properties.put(Constants.CONTEXT_SERVICE, Constants.SERVICE_REBUILD);
- // response = rebuild(input, properties);
- // logger.info(infomsg);
- // break;
- //
- // default:
- // String msg = String.format("Invalid request type [%s] for request id [%s]", req, requestId);
- // response = generateTopologyOperationResponse(Boolean.FALSE, requestId, msg, "N/A");
- // }
- // }
- //
- // return response;
- // }
-
/**
- * Restart a VM
- *
+ * Modify configuration
+ *
* @param hdr
* The common request header
- * @param vnf
- * The identification of the VNF resource to be operated upon
- * @return The rpc result of the restart operation
+ * @param data
+ * The payload of the configuration
+ * @return The rpc result of the operation
*/
public RpcResult<ModifyConfigOutput> modifyConfig(CommonRequestHeader hdr, ConfigPayload data) {
long startTime = System.currentTimeMillis();
TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
df.setTimeZone(tz);
- // String startTimeStr = String.valueOf(startTime);
- String startTimeStr = df.format(new Date());
String requestId = hdr.getServiceRequestId();
//MDC.clear();
@@ -227,10 +165,6 @@ public class TopologyService {
properties.put("org.onap.appc.configURL", url);
properties.put("org.onap.appc.configJson", data.getConfigJson());
- //UUID identityUrl = vnf.getIdentityUrl();
- //if (identityUrl != null) {
- // properties.put(Constants.CONTEXT_IDENTITY_URL, identityUrl.getValue());
- //}
/*
* Attempt to call the DG with the appropriate properties
*/
@@ -261,9 +195,7 @@ public class TopologyService {
requestId, statusStr, startTime, endTime, duration, requestId, reason));
// Status must be set to true to indicate that our return is expected
- RpcResult<ModifyConfigOutput> rpcResult =
- RpcResultBuilder.<ModifyConfigOutput> status(true).withResult(rob.build()).build();
- return rpcResult;
+ return RpcResultBuilder.<ModifyConfigOutput> status(true).withResult(rob.build()).build();
}
@@ -354,9 +286,7 @@ public class TopologyService {
requestId, statusStr, startTime, endTime, duration, requestId, reason));
// Status must be set to true to indicate that our return is expected
- RpcResult<MigrateOutput> rpcResult =
- RpcResultBuilder.<MigrateOutput> status(true).withResult(mob.build()).build();
- return rpcResult;
+ return RpcResultBuilder.<MigrateOutput> status(true).withResult(mob.build()).build();
}
/**
@@ -373,8 +303,6 @@ public class TopologyService {
TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
df.setTimeZone(tz);
- // String startTimeStr = String.valueOf(startTime);
- String startTimeStr = df.format(new Date());
String requestId = hdr.getServiceRequestId();
//MDC.clear();
@@ -441,9 +369,7 @@ public class TopologyService {
requestId, statusStr, startTime, endTime, duration, requestId, reason));
// Status must be set to true to indicate that our return is expected
- RpcResult<RestartOutput> rpcResult =
- RpcResultBuilder.<RestartOutput> status(true).withResult(rob.build()).build();
- return rpcResult;
+ return RpcResultBuilder.<RestartOutput> status(true).withResult(rob.build()).build();
}
/**
@@ -530,9 +456,7 @@ public class TopologyService {
requestId, statusStr, startTime, endTime, duration, requestId, reason));
// Status must be set to true to indicate that our return is expected
- RpcResult<RebuildOutput> rpcResult =
- RpcResultBuilder.<RebuildOutput> status(true).withResult(rob.build()).build();
- return rpcResult;
+ return RpcResultBuilder.<RebuildOutput> status(true).withResult(rob.build()).build();
}
/**
@@ -549,8 +473,6 @@ public class TopologyService {
TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
df.setTimeZone(tz);
- // String startTimeStr = String.valueOf(startTime);
- String startTimeStr = df.format(new Date());
String requestId = hdr.getServiceRequestId();
//MDC.clear();
@@ -617,9 +539,7 @@ public class TopologyService {
requestId, statusStr, startTime, endTime, duration, requestId, reason));
// Status must be set to true to indicate that our return is expected
- RpcResult<SnapshotOutput> rpcResult =
- RpcResultBuilder.<SnapshotOutput> status(true).withResult(sob.build()).build();
- return rpcResult;
+ return RpcResultBuilder.<SnapshotOutput> status(true).withResult(sob.build()).build();
}
/**************************************************/
@@ -690,9 +610,7 @@ public class TopologyService {
vob.setStatMsg(tempstring2);
// Status must be set to true to indicate that our return is expected
- RpcResult<VmstatuscheckOutput> rpcResult =
- RpcResultBuilder.<VmstatuscheckOutput> status(true).withResult(vob.build()).build();
- return rpcResult;
+ return RpcResultBuilder.<VmstatuscheckOutput> status(true).withResult(vob.build()).build();
}
/*************************************************/
@@ -726,7 +644,7 @@ public class TopologyService {
logger.debug(String.format("Calling Graph %s", graphName));
metricsLogger.info(String.format("Calling Graph %s", graphName));
- boolean success = false;
+ boolean success;
String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
AppcProviderClient svcLogicClient = new AppcProviderClient();
try {
@@ -748,7 +666,7 @@ public class TopologyService {
if (respProps.containsKey(Constants.ATTRIBUTE_ERROR_CODE)) {
// || respProps.containsKey(Constants.ATTRIBUTE_ERROR_MESSAGE)) {
String errorCodeProperty = respProps.getProperty(Constants.ATTRIBUTE_ERROR_CODE).trim();
- int errorCode = 200;
+ int errorCode;
try {
errorCode = Integer.parseInt(errorCodeProperty);
if (errorCode >= 300) {