summaryrefslogtreecommitdiffstats
path: root/appc-provider/appc-provider-bundle
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
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')
-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
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/AppcProviderLcmTest.java225
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/AbstractBaseServiceTest.java212
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/AbstractBaseUtilsTest.java204
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/ActionStatusServiceTest.java197
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/QueryServiceTest.java175
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/QuiesceTrafficServiceTest.java186
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/RebootServiceTest.java153
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/RequestExecutorTest.java252
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/ResumeTrafficServiceTest.java162
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/UpgradeServiceTest.java686
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/VolumeServiceTest.java320
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/util/ValidationServiceTest.java89
36 files changed, 5756 insertions, 490 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) {
diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/AppcProviderLcmTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/AppcProviderLcmTest.java
index f25df9c44..064f5679f 100644
--- a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/AppcProviderLcmTest.java
+++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/AppcProviderLcmTest.java
@@ -9,15 +9,15 @@
* 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=========================================================
*/
@@ -36,6 +36,9 @@ import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
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.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.CheckLockInput;
@@ -54,6 +57,9 @@ import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigScaleoutIn
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigScaleoutOutput;
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.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.HealthCheckInput;
@@ -64,6 +70,33 @@ import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.LockInput;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.LockOutput;
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.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.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.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.RestartInput;
@@ -100,6 +133,7 @@ import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.StatusBui
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.onap.appc.domainmodel.lcm.ResponseContext;
import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.provider.lcm.service.*;
import org.onap.appc.provider.lcm.util.ValidationService;
import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
import org.osgi.framework.FrameworkUtil;
@@ -122,13 +156,16 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
+import static org.powermock.api.mockito.PowerMockito.whenNew;
/**
* Integration Test class for AppcProviderLcm.
*/
@RunWith(PowerMockRunner.class)
-@PrepareForTest({FrameworkUtil.class, AppcProviderLcm.class, ValidationService.class})
+@PrepareForTest({FrameworkUtil.class, AppcProviderLcm.class, QueryService.class, VolumeService.class,
+ QuiesceTrafficService.class, ValidationService.class})
public class AppcProviderLcmTest extends AbstractDataBrokerTest {
private Status successStatus = new StatusBuilder().setCode(400).setMessage("success").build();
private Status failStatus = new StatusBuilder().setCode(401).setMessage("failure").build();
@@ -1091,6 +1128,183 @@ public class AppcProviderLcmTest extends AbstractDataBrokerTest {
verify(appcProviderLcm, times(1)).executeRequest(any());
}
+ @Test
+ public void testQuery() throws Exception {
+ QueryInput mockInput = mock(QueryInput.class);
+ QueryOutput mockOutput = mock(QueryOutput.class);
+ QueryOutputBuilder mockQueryOutputBuilder = mock(QueryOutputBuilder.class);
+ QueryService mockQuery = mock(QueryService.class);
+
+ whenNew(QueryService.class).withNoArguments().thenReturn(mockQuery);
+ when(mockQuery.process(mockInput)).thenReturn(mockQueryOutputBuilder);
+ when(mockQueryOutputBuilder.build()).thenReturn(mockOutput);
+
+ Future<RpcResult<QueryOutput>> results = appcProviderLcm.query(mockInput);
+ verify(mockQuery, times(1)).process(mockInput);
+ Assert.assertEquals("Should return mockOutput", mockOutput, results.get().getResult());
+ }
+
+ @Test
+ public void testReboot() throws Exception {
+ RebootInput mockInput = mock(RebootInput.class);
+ RebootOutput mockOutput = mock(RebootOutput.class);
+ RebootOutputBuilder mockRebootOutputBuilder = mock(RebootOutputBuilder.class);
+ RebootService mockReboot = mock(RebootService.class);
+
+ whenNew(RebootService.class).withNoArguments().thenReturn(mockReboot);
+ when(mockReboot.process(mockInput)).thenReturn(mockRebootOutputBuilder);
+ when(mockRebootOutputBuilder.build()).thenReturn(mockOutput);
+
+ Future<RpcResult<RebootOutput>> results = appcProviderLcm.reboot(mockInput);
+ verify(mockReboot, times(1)).process(mockInput);
+ Assert.assertEquals("Should return mockOutput", mockOutput, results.get().getResult());
+ }
+
+ @Test
+ public void testAttachVolume() throws Exception {
+ AttachVolumeInput mockInput = mock(AttachVolumeInput.class);
+ AttachVolumeOutput mockOutput = mock(AttachVolumeOutput.class);
+ AttachVolumeOutputBuilder mockOutputBuilder = mock(AttachVolumeOutputBuilder.class);
+ VolumeService mockVolumeService = mock(VolumeService.class);
+
+ whenNew(VolumeService.class).withArguments(true).thenReturn(mockVolumeService);
+ when(mockVolumeService.attachVolume(mockInput)).thenReturn(mockOutputBuilder);
+ when(mockOutputBuilder.build()).thenReturn(mockOutput);
+
+ Future<RpcResult<AttachVolumeOutput>> results = appcProviderLcm.attachVolume(mockInput);
+ verify(mockVolumeService, times(1)).attachVolume(mockInput);
+ Assert.assertEquals("Should return mockOutput", mockOutput, results.get().getResult());
+ }
+
+ @Test
+ public void testDetachVolume() throws Exception {
+ DetachVolumeInput mockInput = mock(DetachVolumeInput.class);
+ DetachVolumeOutput mockOutput = mock(DetachVolumeOutput.class);
+ DetachVolumeOutputBuilder mockOutputBuilder = mock(DetachVolumeOutputBuilder.class);
+ VolumeService mockVolumeService = mock(VolumeService.class);
+
+ whenNew(VolumeService.class).withArguments(false).thenReturn(mockVolumeService);
+ when(mockVolumeService.detachVolume(mockInput)).thenReturn(mockOutputBuilder);
+ when(mockOutputBuilder.build()).thenReturn(mockOutput);
+
+ Future<RpcResult<DetachVolumeOutput>> results = appcProviderLcm.detachVolume(mockInput);
+ verify(mockVolumeService, times(1)).detachVolume(mockInput);
+ Assert.assertEquals("Should return mockOutput", mockOutput, results.get().getResult());
+ }
+
+ @Test
+ public void testQuiesceTraffic() throws Exception {
+ QuiesceTrafficInput mockInput = mock(QuiesceTrafficInput.class);
+ QuiesceTrafficOutput mockOutput = mock(QuiesceTrafficOutput.class);
+ QuiesceTrafficOutputBuilder mockOutputBuilder = mock(QuiesceTrafficOutputBuilder.class);
+ QuiesceTrafficService mockService = mock(QuiesceTrafficService.class);
+
+ whenNew(QuiesceTrafficService.class).withNoArguments().thenReturn(mockService);
+ when(mockService.process(mockInput)).thenReturn(mockOutputBuilder);
+ when(mockOutputBuilder.build()).thenReturn(mockOutput);
+
+ Future<RpcResult<QuiesceTrafficOutput>> results = appcProviderLcm.quiesceTraffic(mockInput);
+ verify(mockService, times(1)).process(mockInput);
+ Assert.assertEquals("Should return mockOutput", mockOutput, results.get().getResult());
+ }
+
+ @Test
+ public void testResumeTraffic() throws Exception {
+ ResumeTrafficInput mockInput = mock(ResumeTrafficInput.class);
+ ResumeTrafficOutput mockOutput = mock(ResumeTrafficOutput.class);
+ ResumeTrafficOutputBuilder mockOutputBuilder = mock(ResumeTrafficOutputBuilder.class);
+ ResumeTrafficService mockService = mock(ResumeTrafficService.class);
+
+ whenNew(ResumeTrafficService.class).withNoArguments().thenReturn(mockService);
+ when(mockService.process(mockInput)).thenReturn(mockOutputBuilder);
+ when(mockOutputBuilder.build()).thenReturn(mockOutput);
+
+ Future<RpcResult<ResumeTrafficOutput>> results = appcProviderLcm.resumeTraffic(mockInput);
+ verify(mockService, times(1)).process(mockInput);
+ Assert.assertEquals("Should return mockOutput", mockOutput, results.get().getResult());
+ }
+
+ @Test
+ public void testUpgradePreCheck() throws Exception {
+ UpgradePreCheckInput mockInput = mock(UpgradePreCheckInput.class);
+ UpgradePreCheckOutput mockOutput = mock(UpgradePreCheckOutput.class);
+ UpgradePreCheckOutputBuilder mockOutputBuilder = mock(UpgradePreCheckOutputBuilder.class);
+ UpgradeService mockService = mock(UpgradeService.class);
+
+ whenNew(UpgradeService.class).withAnyArguments().thenReturn(mockService);
+ when(mockService.upgradePreCheck(mockInput)).thenReturn(mockOutputBuilder);
+ when(mockOutputBuilder.build()).thenReturn(mockOutput);
+
+ Future<RpcResult<UpgradePreCheckOutput>> results = appcProviderLcm.upgradePreCheck(mockInput);
+ verify(mockService, times(1)).upgradePreCheck(mockInput);
+ Assert.assertEquals("Should return mockOutput", mockOutput, results.get().getResult());
+ }
+
+
+ @Test
+ public void testUpgradePostCheck() throws Exception {
+ UpgradePostCheckInput mockInput = mock(UpgradePostCheckInput.class);
+ UpgradePostCheckOutput mockOutput = mock(UpgradePostCheckOutput.class);
+ UpgradePostCheckOutputBuilder mockOutputBuilder = mock(UpgradePostCheckOutputBuilder.class);
+ UpgradeService mockService = mock(UpgradeService.class);
+
+ whenNew(UpgradeService.class).withAnyArguments().thenReturn(mockService);
+ when(mockService.upgradePostCheck(mockInput)).thenReturn(mockOutputBuilder);
+ when(mockOutputBuilder.build()).thenReturn(mockOutput);
+
+ Future<RpcResult<UpgradePostCheckOutput>> results = appcProviderLcm.upgradePostCheck(mockInput);
+ verify(mockService, times(1)).upgradePostCheck(mockInput);
+ Assert.assertEquals("Should return mockOutput", mockOutput, results.get().getResult());
+ }
+
+ @Test
+ public void testUpgradeSoftware() throws Exception {
+ UpgradeSoftwareInput mockInput = mock(UpgradeSoftwareInput.class);
+ UpgradeSoftwareOutput mockOutput = mock(UpgradeSoftwareOutput.class);
+ UpgradeSoftwareOutputBuilder mockOutputBuilder = mock(UpgradeSoftwareOutputBuilder.class);
+ UpgradeService mockService = mock(UpgradeService.class);
+
+ whenNew(UpgradeService.class).withAnyArguments().thenReturn(mockService);
+ when(mockService.upgradeSoftware(mockInput)).thenReturn(mockOutputBuilder);
+ when(mockOutputBuilder.build()).thenReturn(mockOutput);
+
+ Future<RpcResult<UpgradeSoftwareOutput>> results = appcProviderLcm.upgradeSoftware(mockInput);
+ verify(mockService, times(1)).upgradeSoftware(mockInput);
+ Assert.assertEquals("Should return mockOutput", mockOutput, results.get().getResult());
+ }
+
+ @Test
+ public void testUpgradeBackup() throws Exception {
+ UpgradeBackupInput mockInput = mock(UpgradeBackupInput.class);
+ UpgradeBackupOutput mockOutput = mock(UpgradeBackupOutput.class);
+ UpgradeBackupOutputBuilder mockOutputBuilder = mock(UpgradeBackupOutputBuilder.class);
+ UpgradeService mockService = mock(UpgradeService.class);
+
+ whenNew(UpgradeService.class).withAnyArguments().thenReturn(mockService);
+ when(mockService.upgradeBackup(mockInput)).thenReturn(mockOutputBuilder);
+ when(mockOutputBuilder.build()).thenReturn(mockOutput);
+
+ Future<RpcResult<UpgradeBackupOutput>> results = appcProviderLcm.upgradeBackup(mockInput);
+ verify(mockService, times(1)).upgradeBackup(mockInput);
+ Assert.assertEquals("Should return mockOutput", mockOutput, results.get().getResult());
+ }
+
+ @Test
+ public void testUpgradeBackout() throws Exception {
+ UpgradeBackoutInput mockInput = mock(UpgradeBackoutInput.class);
+ UpgradeBackoutOutput mockOutput = mock(UpgradeBackoutOutput.class);
+ UpgradeBackoutOutputBuilder mockOutputBuilder = mock(UpgradeBackoutOutputBuilder.class);
+ UpgradeService mockService = mock(UpgradeService.class);
+
+ whenNew(UpgradeService.class).withAnyArguments().thenReturn(mockService);
+ when(mockService.upgradeBackout(mockInput)).thenReturn(mockOutputBuilder);
+ when(mockOutputBuilder.build()).thenReturn(mockOutput);
+
+ Future<RpcResult<UpgradeBackoutOutput>> results = appcProviderLcm.upgradeBackout(mockInput);
+ verify(mockService, times(1)).upgradeBackout(mockInput);
+ Assert.assertEquals("Should return mockOutput", mockOutput, results.get().getResult());
+ }
+
@After
public void tearDown() throws Exception {
if (appcProviderLcm != null) {
@@ -1098,6 +1312,7 @@ public class AppcProviderLcmTest extends AbstractDataBrokerTest {
}
}
+
private ActionIdentifiers newActionIdentifier(String vnfId, String vnfcId, String vserverId) {
ActionIdentifiersBuilder actionIdentifiersBuilder = new ActionIdentifiersBuilder();
actionIdentifiersBuilder.setVnfId(vnfId);
@@ -1115,4 +1330,4 @@ public class AppcProviderLcmTest extends AbstractDataBrokerTest {
"Z"));
return commonHeaderBuilder.build();
}
-} \ No newline at end of file
+}
diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/AbstractBaseServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/AbstractBaseServiceTest.java
new file mode 100644
index 000000000..012b840bb
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/AbstractBaseServiceTest.java
@@ -0,0 +1,212 @@
+/*-
+ * ============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.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ZULU;
+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.executor.objects.Params;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+import org.powermock.reflect.Whitebox;
+
+import java.util.EnumSet;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+
+public class AbstractBaseServiceTest {
+ private Action expectedAction = Action.Query;
+ private String rpcName = expectedAction.name().toLowerCase();
+
+ private CommonHeader commonHeader = mock(CommonHeader.class);
+ private ActionIdentifiers mockAI = mock(ActionIdentifiers.class);
+ private testAbc testAbstractBaseService;
+
+ class testAbc extends AbstractBaseService {
+ public testAbc() {
+ super(AbstractBaseServiceTest.this.expectedAction);
+ }
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ testAbstractBaseService = spy(new testAbc());
+ }
+
+ @Test
+ public void testConstructor() throws Exception {
+ Assert.assertEquals("Should have proper ACTION", expectedAction,
+ (Action) Whitebox.getInternalState(testAbstractBaseService, "expectedAction"));
+ Assert.assertEquals("Should have action-status RPC name", rpcName,
+ (Whitebox.getInternalState(testAbstractBaseService, "rpcName")).toString());
+ }
+
+ @Test
+ public void testValidateInput() throws Exception {
+ // test commonHeader error
+ Status status = testAbstractBaseService.validateInput(commonHeader, Action.Query, null);
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ ZULU mockTimeStamp = mock(ZULU.class);
+ Mockito.doReturn(mockTimeStamp).when(commonHeader).getTimestamp();
+ Mockito.doReturn("api ver").when(commonHeader).getApiVer();
+ Mockito.doReturn("originator Id").when(commonHeader).getOriginatorId();
+ Mockito.doReturn("request Id").when(commonHeader).getRequestId();
+
+ // test invalid action
+ status = testAbstractBaseService.validateInput(commonHeader, Action.AttachVolume, null);
+ Assert.assertEquals("Should return invalid parameter for action",
+ Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode());
+
+ // test null actionIdentifier
+ status = testAbstractBaseService.validateInput(commonHeader, Action.Query, null);
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test validation passed
+ status = testAbstractBaseService.validateInput(commonHeader, Action.Query, mockAI);
+ Assert.assertTrue("Should have null status", status == null);
+ }
+
+ @Test
+ public void testValidateVnfId() throws Exception {
+ // Skip test input validation, as it is all done in testValidateInput
+
+ ZULU mockTimeStamp = mock(ZULU.class);
+ Mockito.doReturn(mockTimeStamp).when(commonHeader).getTimestamp();
+ Mockito.doReturn("api ver").when(commonHeader).getApiVer();
+ Mockito.doReturn("originator Id").when(commonHeader).getOriginatorId();
+ Mockito.doReturn("request Id").when(commonHeader).getRequestId();
+
+ // test null VNF ID
+ Status status = testAbstractBaseService.validateVnfId(commonHeader, Action.Query, mockAI);
+ Assert.assertEquals("should return invalid parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test empty VNF_ID
+ Mockito.doReturn("").when(mockAI).getVnfId();
+ status = testAbstractBaseService.validateVnfId(commonHeader, Action.Query, mockAI);
+ Assert.assertEquals("should return invalid parameter",
+ Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode());
+
+ // test calling validateExcludeActId
+ Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+ status = testAbstractBaseService.validateVnfId(commonHeader, Action.Query, mockAI);
+ Assert.assertTrue("Should have null status", status == null);
+ }
+
+ @Test
+ public void testValidateVserverId() throws Exception {
+ // Skip test input validation, as it is all done in testValidateInput
+
+ ZULU mockTimeStamp = mock(ZULU.class);
+ Mockito.doReturn(mockTimeStamp).when(commonHeader).getTimestamp();
+ Mockito.doReturn("api ver").when(commonHeader).getApiVer();
+ Mockito.doReturn("originator Id").when(commonHeader).getOriginatorId();
+ Mockito.doReturn("request Id").when(commonHeader).getRequestId();
+
+ // test null VNF ID
+ Status status = testAbstractBaseService.validateVserverId(commonHeader, Action.Query, mockAI);
+ Assert.assertEquals("should return invalid parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test empty VNF_ID
+ Mockito.doReturn("").when(mockAI).getVserverId();
+ status = testAbstractBaseService.validateVserverId(commonHeader, Action.Query, mockAI);
+ Assert.assertEquals("should return invalid parameter",
+ Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode());
+
+ // test calling validateExcludeActId
+ Mockito.doReturn("vserverId").when(mockAI).getVserverId();
+ status = testAbstractBaseService.validateVserverId(commonHeader, Action.Query, mockAI);
+ Assert.assertTrue("Should have null status", status == null);
+ }
+
+ @Test
+ public void testValidateExcludedActIds() throws Exception {
+ EnumSet<AbstractBaseService.ACTID_KEYS> exclutionKeys = EnumSet.of(AbstractBaseService.ACTID_KEYS.VNF_ID);
+ Status status = testAbstractBaseService.validateExcludedActIds(mockAI, exclutionKeys);
+ Assert.assertTrue("Should have not error", status == null);
+
+ Integer expectedErrorCode = Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode());
+ Mockito.doReturn("vnfc name").when(mockAI).getVnfcName();
+ status = testAbstractBaseService.validateExcludedActIds(mockAI, exclutionKeys);
+ Assert.assertEquals("Should have error for vnfc name", expectedErrorCode, status.getCode());
+
+ Mockito.doReturn(null).when(mockAI).getVnfcName();
+ Mockito.doReturn("vserver Id").when(mockAI).getVserverId();
+ status = testAbstractBaseService.validateExcludedActIds(mockAI, exclutionKeys);
+ Assert.assertEquals("Should have error for vserver Id", expectedErrorCode, status.getCode());
+
+ Mockito.doReturn(null).when(mockAI).getVserverId();
+ Mockito.doReturn("vf module Id").when(mockAI).getVfModuleId();
+ status = testAbstractBaseService.validateExcludedActIds(mockAI, exclutionKeys);
+ Assert.assertEquals("Should have error for vf module Id", expectedErrorCode, status.getCode());
+
+ Mockito.doReturn(null).when(mockAI).getServiceInstanceId();
+ Mockito.doReturn("service instance Id").when(mockAI).getServiceInstanceId();
+ status = testAbstractBaseService.validateExcludedActIds(mockAI, exclutionKeys);
+ Assert.assertEquals("Should have error for service instance Id", expectedErrorCode, status.getCode());
+
+ Mockito.doReturn("vnfc name").when(mockAI).getVnfcName();
+ Mockito.doReturn("vserver Id").when(mockAI).getVserverId();
+ Mockito.doReturn("vf module Id").when(mockAI).getVfModuleId();
+ Mockito.doReturn("vnf Id").when(mockAI).getVnfId();
+ status = testAbstractBaseService.validateExcludedActIds(mockAI, exclutionKeys);
+ Assert.assertEquals("Should have error code", expectedErrorCode, status.getCode());
+ Assert.assertEquals("Should have error message",
+ LCMCommandStatus.INVALID_INPUT_PARAMETER.getFormattedMessage(getMsgParams(exclutionKeys)),
+ status.getMessage());
+ }
+
+ @Test
+ public void testExecuteAction() throws Exception {
+ RequestHandlerOutput output = testAbstractBaseService.executeAction(null);
+ Assert.assertTrue("Should return null RequestHandlerOutput", output == null);
+ Status status = Whitebox.getInternalState(testAbstractBaseService, "status");
+ Assert.assertEquals("Should have error code",
+ Integer.valueOf(LCMCommandStatus.UNEXPECTED_ERROR.getResponseCode()), status.getCode());
+ }
+
+ private Params getMsgParams(EnumSet<AbstractBaseService.ACTID_KEYS> exclutionKeys) {
+ StringBuilder msgBuilder = new StringBuilder();
+ for (QueryService.ACTID_KEYS aKey : AbstractBaseService.ACTID_KEYS.values()) {
+ if (exclutionKeys.contains(aKey)) {
+ continue;
+ }
+ msgBuilder.append(aKey.getKeyName()).append(testAbstractBaseService.DELIMITER_COMMA);
+ }
+ String msg = msgBuilder.toString();
+ return new Params().addParam("errorMsg", msg.substring(0, msg.length() -1));
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/AbstractBaseUtilsTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/AbstractBaseUtilsTest.java
new file mode 100644
index 000000000..c5322886c
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/AbstractBaseUtilsTest.java
@@ -0,0 +1,204 @@
+/*-
+ * ============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.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+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.onap.appc.domainmodel.lcm.ResponseContext;
+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;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+public class AbstractBaseUtilsTest {
+
+ private AbstractBaseUtilsTest.testAbc testAbstractBaseUtils;
+
+ class testAbc extends AbstractBaseUtils {
+ // no content needed
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ testAbstractBaseUtils = spy(new AbstractBaseUtilsTest.testAbc());
+ }
+
+ private void validateStatusResult(Params params, LCMCommandStatus lcmCommandStatus, Status status) {
+ Assert.assertEquals(String.format("Should return proper code of %s", lcmCommandStatus.toString()),
+ Integer.valueOf(lcmCommandStatus.getResponseCode()), status.getCode());
+ Assert.assertEquals(String.format("Should return proper message of $s", lcmCommandStatus.toString()),
+ lcmCommandStatus.getFormattedMessage(params), status.getMessage());
+ }
+
+ @Test
+ public void testBuildStatusWithoutParams() throws Exception {
+ LCMCommandStatus lcmCommandStatus = LCMCommandStatus.ACCEPTED;
+ Status status = testAbstractBaseUtils.buildStatusWithoutParams(lcmCommandStatus);
+ validateStatusResult(null, lcmCommandStatus, status);
+ }
+
+ @Test
+ public void testBuildStatusForErrorMsg() throws Exception {
+ String key = "errorMsg";
+ String msg = "testing";
+ Params params = new Params().addParam(key, msg);
+ LCMCommandStatus lcmCommandStatus = LCMCommandStatus.INVALID_INPUT_PARAMETER;
+ Status status = testAbstractBaseUtils.buildStatusForErrorMsg(lcmCommandStatus, msg);
+ verify(testAbstractBaseUtils, times(1)).buildStatus(lcmCommandStatus, msg, key);
+ validateStatusResult(params, lcmCommandStatus, status);
+ }
+
+
+ @Test
+ public void testBuildStatusForVnfId() throws Exception {
+ String key = "vnfId";
+ String msg = "testing";
+ Params params = new Params().addParam(key, msg);
+ LCMCommandStatus lcmCommandStatus = LCMCommandStatus.VNF_NOT_FOUND;
+ Status status = testAbstractBaseUtils.buildStatusForVnfId(lcmCommandStatus, msg);
+ verify(testAbstractBaseUtils, times(1)).buildStatus(lcmCommandStatus, msg, key);
+ validateStatusResult(params, lcmCommandStatus, status);
+ }
+
+ @Test
+ public void testBuildStatusForParamName() throws Exception {
+ String key = "paramName";
+ String msg = "testing";
+ Params params = new Params().addParam(key, msg);
+ LCMCommandStatus lcmCommandStatus = LCMCommandStatus.MISSING_MANDATORY_PARAMETER;
+ Status status = testAbstractBaseUtils.buildStatusForParamName(lcmCommandStatus, msg);
+ verify(testAbstractBaseUtils, times(1)).buildStatus(lcmCommandStatus, msg, key);
+ validateStatusResult(params, lcmCommandStatus, status);
+ }
+
+ @Test
+ public void testBuildStatusForId() throws Exception {
+ String key = "id";
+ String msg = "testing";
+ Params params = new Params().addParam(key, msg);
+ LCMCommandStatus lcmCommandStatus = LCMCommandStatus.VSERVER_NOT_FOUND;
+ Status status = testAbstractBaseUtils.buildStatusForId(lcmCommandStatus, msg);
+ verify(testAbstractBaseUtils, times(1)).buildStatus(lcmCommandStatus, msg, key);
+ validateStatusResult(params, lcmCommandStatus, status);
+ }
+
+ @Test
+ public void testBuildStatus() throws Exception {
+ String key = "errorMsg";
+ String msg = "testing";
+ Params params = new Params().addParam(key, msg);
+ LCMCommandStatus lcmCommandStatus = LCMCommandStatus.UNEXPECTED_ERROR;
+ Status status = testAbstractBaseUtils.buildStatus(lcmCommandStatus, msg, key);
+ validateStatusResult(params, lcmCommandStatus, status);
+
+ key = "vnfId";
+ params = new Params().addParam(key, msg);
+ lcmCommandStatus = LCMCommandStatus.VNF_NOT_FOUND;
+ status = testAbstractBaseUtils.buildStatus(lcmCommandStatus, msg, key);
+ validateStatusResult(params, lcmCommandStatus, status);
+
+ key = "paramName";
+ params = new Params().addParam(key, msg);
+ lcmCommandStatus = LCMCommandStatus.MISSING_MANDATORY_PARAMETER;
+ status = testAbstractBaseUtils.buildStatus(lcmCommandStatus, msg, key);
+ validateStatusResult(params, lcmCommandStatus, status);
+ }
+
+ @Test
+ public void testBuildStatusWithParseException() throws Exception {
+ LCMCommandStatus lcmCommandStatus = LCMCommandStatus.REQUEST_PARSING_FAILED;
+ String key = "errorMsg";
+ String exceptionMsg = null;
+
+ ParseException parseException = new ParseException(exceptionMsg, 0);
+ Params params = new Params().addParam(key, parseException.toString());
+ Status status = testAbstractBaseUtils.buildStatusWithParseException(parseException);
+ validateStatusResult(params, lcmCommandStatus, status);
+
+ exceptionMsg = "testing message";
+ parseException = new ParseException(exceptionMsg, 0);
+ params = new Params().addParam(key, exceptionMsg);
+ status = testAbstractBaseUtils.buildStatusWithParseException(parseException);
+ validateStatusResult(params, lcmCommandStatus, status);
+ }
+
+ @Test
+ public void testBuildStatusWithDispatcherOutput() throws Exception {
+ RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class);
+
+ ResponseContext mockContext = mock(ResponseContext.class);
+ Mockito.doReturn(mockContext).when(mockOutput).getResponseContext();
+
+ org.onap.appc.domainmodel.lcm.Status mockStatus = mock(org.onap.appc.domainmodel.lcm.Status.class);
+ Mockito.doReturn(mockStatus).when(mockContext).getStatus();
+
+ Integer resultCode = new Integer(401);
+ String resultMsg = "testing result message";
+ Mockito.doReturn(resultCode).when(mockStatus).getCode();
+ Mockito.doReturn(resultMsg).when(mockStatus).getMessage();
+
+ Status status = testAbstractBaseUtils.buildStatusWithDispatcherOutput(mockOutput);
+ Assert.assertEquals("Should return result code", resultCode, status.getCode());
+ Assert.assertEquals("Should return result message", resultMsg, status.getMessage());
+ }
+
+ @Test
+ public void testGetRpcName() throws Exception {
+ Assert.assertEquals("Should return action-status",
+ "action-status", testAbstractBaseUtils.getRpcName(Action.ActionStatus));
+ Assert.assertEquals("Should return query",
+ "query", testAbstractBaseUtils.getRpcName(Action.Query));
+ Assert.assertEquals("Should return reboot",
+ "reboot", testAbstractBaseUtils.getRpcName(Action.Reboot));
+ Assert.assertEquals("Should return attach-volume",
+ "attach-volume", testAbstractBaseUtils.getRpcName(Action.AttachVolume));
+ Assert.assertEquals("Should return detach-volume",
+ "detach-volume", testAbstractBaseUtils.getRpcName(Action.DetachVolume));
+ Assert.assertEquals("Should return quiesce-traffic",
+ "quiesce-traffic", testAbstractBaseUtils.getRpcName(Action.QuiesceTraffic));
+ Assert.assertEquals("Should return resume-traffic",
+ "resume-traffic", testAbstractBaseUtils.getRpcName(Action.ResumeTraffic));
+ Assert.assertEquals("Should return upgrade-pre-check",
+ "upgrade-pre-check", testAbstractBaseUtils.getRpcName(Action.UpgradePreCheck));
+ Assert.assertEquals("Should return upgrade-post-check",
+ "upgrade-post-check", testAbstractBaseUtils.getRpcName(Action.UpgradePostCheck));
+ Assert.assertEquals("Should return upgrade-software",
+ "upgrade-software", testAbstractBaseUtils.getRpcName(Action.UpgradeSoftware));
+ Assert.assertEquals("Should return upgrade-backup",
+ "upgrade-backup", testAbstractBaseUtils.getRpcName(Action.UpgradeBackup));
+ Assert.assertEquals("Should return upgrade-backout",
+ "upgrade-backout", testAbstractBaseUtils.getRpcName(Action.UpgradeBackout));
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/ActionStatusServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/ActionStatusServiceTest.java
new file mode 100644
index 000000000..66fffeac7
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/ActionStatusServiceTest.java
@@ -0,0 +1,197 @@
+/*-
+ * ============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.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+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.ZULU;
+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.domainmodel.lcm.ActionLevel;
+import org.onap.appc.domainmodel.lcm.RequestContext;
+import org.onap.appc.domainmodel.lcm.ResponseContext;
+import org.onap.appc.domainmodel.lcm.Status;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.provider.lcm.util.RequestInputBuilder;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.reflect.Whitebox;
+
+import java.text.ParseException;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.powermock.api.mockito.PowerMockito.whenNew;
+
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ActionStatusService.class, RequestExecutor.class, RequestInputBuilder.class,})
+public class ActionStatusServiceTest {
+ private RequestHandlerInput mockRequestHandlerInput = mock(RequestHandlerInput.class);
+ private RequestContext mockRequestContext = mock(RequestContext.class);
+ private RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class);
+ private ResponseContext mockResponseContext = mock(ResponseContext.class);
+
+ private ActionStatusService actionStatusService;
+
+ @Before
+ public void setUp() throws Exception {
+ Mockito.doReturn(mockRequestContext).when(mockRequestHandlerInput).getRequestContext();
+ actionStatusService = spy(new ActionStatusService());
+ }
+
+ @Test
+ public void testConstructor() throws Exception {
+ Assert.assertEquals("Should have proper ACTION", Action.ActionStatus,
+ (Action) Whitebox.getInternalState(actionStatusService, "expectedAction"));
+ Assert.assertEquals("Should have action-status RPC name", "action-status",
+ (Whitebox.getInternalState(actionStatusService, "rpcName")).toString());
+ }
+
+ @Test
+ public void testQueryStatus() throws Exception {
+ // =========== test input validation ============
+ CommonHeader mockCommonHeader = mock(CommonHeader.class);
+ ActionStatusInput mockInput = mock(ActionStatusInput.class);
+
+ Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader();
+ // test commonHeader error
+ ActionStatusOutputBuilder output = actionStatusService.queryStatus(mockInput);
+ Assert.assertEquals("Should have commonHeader", mockCommonHeader, output.getCommonHeader());
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()),
+ output.getStatus().getCode());
+
+ ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z");
+ Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp();
+ Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+ Mockito.doReturn("originator Id").when(mockCommonHeader).getOriginatorId();
+ Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+
+ // test invalid action
+ Mockito.doReturn(Action.Query).when(mockInput).getAction();
+ output = actionStatusService.queryStatus(mockInput);
+ Assert.assertEquals("Should have commonHeader", mockCommonHeader, output.getCommonHeader());
+ Assert.assertEquals("Should return invalid parameter for action",
+ Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()),
+ output.getStatus().getCode());
+
+ // test null actionIdentifier
+ Mockito.doReturn(Action.ActionStatus).when(mockInput).getAction();
+ output = actionStatusService.queryStatus(mockInput);
+ Assert.assertEquals("Should have commonHeader", mockCommonHeader, output.getCommonHeader());
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()),
+ output.getStatus().getCode());
+
+ // test missing VNF ID
+ ActionIdentifiers mockAI = mock(ActionIdentifiers.class);
+ Mockito.doReturn(mockAI).when(mockInput).getActionIdentifiers();
+ output = actionStatusService.queryStatus(mockInput);
+ Assert.assertEquals("Should have commonHeader", mockCommonHeader, output.getCommonHeader());
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()),
+ output.getStatus().getCode());
+
+ // test invalid VNF ID
+ Mockito.doReturn("").when(mockAI).getVnfId();
+ output = actionStatusService.queryStatus(mockInput);
+ Assert.assertEquals("Should have commonHeader", mockCommonHeader, output.getCommonHeader());
+ Assert.assertEquals("Should return invalid parameter for action",
+ Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()),
+ output.getStatus().getCode());
+
+ // test null payload
+ Mockito.doReturn("test VNF ID").when(mockAI).getVnfId();
+ output = actionStatusService.queryStatus(mockInput);
+ Assert.assertEquals("Should have commonHeader", mockCommonHeader, output.getCommonHeader());
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()),
+ output.getStatus().getCode());
+
+ // test payload with empty string
+ Payload mockPayload = mock(Payload.class);
+ Mockito.doReturn(mockPayload).when(mockInput).getPayload();
+ output = actionStatusService.queryStatus(mockInput);
+ Assert.assertEquals("Should have commonHeader", mockCommonHeader, output.getCommonHeader());
+ Assert.assertEquals("should return invalid parameter",
+ Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()),
+ output.getStatus().getCode());
+
+ // test validation passed
+ Mockito.doReturn("testing payload").when(mockPayload).getValue();
+
+ // =========== test success ============
+ RequestExecutor mockExecutor = mock(RequestExecutor.class);
+ whenNew(RequestExecutor.class).withNoArguments().thenReturn(mockExecutor);
+ Mockito.doReturn(mockOutput).when(mockExecutor).executeRequest(any());
+ Mockito.doReturn(mockPayload).when(mockExecutor).getPayload(mockOutput);
+
+ Mockito.doReturn(mockResponseContext).when(mockOutput).getResponseContext();
+
+ Integer statusCode = 400;
+ Status mockStatus = mock(Status.class);
+ Mockito.doReturn(statusCode).when(mockStatus).getCode();
+ Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus();
+
+ output = actionStatusService.queryStatus(mockInput);
+ Mockito.verify(actionStatusService, times(1)).buildStatusWithDispatcherOutput(mockOutput);
+ Mockito.verify(mockExecutor, times(1)).getPayload(mockOutput);
+ Assert.assertTrue("Should have payload", output.getPayload() != null);
+ Assert.assertEquals("Should have commonHeader", mockCommonHeader, output.getCommonHeader());
+ Assert.assertEquals("Should return proper code", statusCode, output.getStatus().getCode());
+
+ // =========== test parserException ============
+ RequestInputBuilder mockInputBuilder = mock(RequestInputBuilder.class);
+ whenNew(RequestInputBuilder.class).withNoArguments().thenReturn(mockInputBuilder);
+ Mockito.doReturn(mockInputBuilder).when(mockInputBuilder).requestContext();
+ ParseException parserException = new ParseException("testing exception", 0);
+ Mockito.doThrow(parserException).when(mockInputBuilder).commonHeader(mockCommonHeader);
+
+ output = actionStatusService.queryStatus(mockInput);
+ Mockito.verify(actionStatusService, times(1)).buildStatusWithParseException(parserException);
+ Assert.assertEquals("Should have commonHeader", mockCommonHeader, output.getCommonHeader());
+ Assert.assertEquals("Should return request failed",
+ Integer.valueOf(LCMCommandStatus.REQUEST_PARSING_FAILED.getResponseCode()),
+ output.getStatus().getCode());
+ }
+
+ @Test
+ public void testUpdateToMgmtActionLevel() throws Exception {
+ actionStatusService.updateToMgmtActionLevel(mockRequestHandlerInput);
+ Mockito.verify(mockRequestContext, times(1)).setActionLevel(ActionLevel.MGMT);
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/QueryServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/QueryServiceTest.java
new file mode 100644
index 000000000..be3370fd9
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/QueryServiceTest.java
@@ -0,0 +1,175 @@
+/*-
+ * ============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.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.internal.util.reflection.Whitebox;
+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.ZULU;
+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.query.output.QueryResults;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.Status;
+import org.onap.appc.domainmodel.lcm.ResponseContext;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.powermock.api.mockito.PowerMockito.whenNew;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({QueryService.class, RequestExecutor.class})
+public class QueryServiceTest {
+ private final Action myAction = Action.Query;
+
+ private QueryInput mockInput = mock(QueryInput.class);
+ private CommonHeader mockCommonHeader = mock(CommonHeader.class);
+ private ActionIdentifiers mockAI = mock(ActionIdentifiers.class);
+
+ private QueryService queryService;
+
+ @Before
+ public void setUp() throws Exception {
+ queryService = spy(new QueryService());
+
+ Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader();
+ }
+
+ @Test
+ public void testConstructor() throws Exception {
+ Assert.assertEquals("Should have proper ACTION", myAction,
+ (Action) org.powermock.reflect.Whitebox.getInternalState(queryService, "expectedAction"));
+ Assert.assertEquals("Should have query RPC name", myAction.name().toLowerCase(),
+ (org.powermock.reflect.Whitebox.getInternalState(queryService, "rpcName")).toString());
+ }
+
+ @Test
+ public void testProcess() throws Exception {
+ // test error occurs in validation
+ QueryOutputBuilder queryOutputBuilder = queryService.process(mockInput);
+ Mockito.verify(queryService, times(0)).proceedAction(mockInput);
+ Assert.assertTrue("Should have commonHeader",queryOutputBuilder.getCommonHeader() != null);
+ Assert.assertTrue("Should not have queryResults",queryOutputBuilder.getQueryResults() == null);
+ Assert.assertEquals("should return missing parameter status",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()),
+ queryOutputBuilder.getStatus().getCode());
+
+ // to make validation pass
+ ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z");
+ Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp();
+ Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+ Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+ Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+
+ Mockito.doReturn(myAction).when(mockInput).getAction();
+ Mockito.doReturn(mockAI).when(mockInput).getActionIdentifiers();
+ Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+
+ // test processAction return with error
+ queryOutputBuilder = queryService.process(mockInput);
+ Mockito.verify(queryService, times(1)).proceedAction(mockInput);
+ Assert.assertTrue("Should have commonHeader",queryOutputBuilder.getCommonHeader() != null);
+ Assert.assertTrue("Should not have queryResults",queryOutputBuilder.getQueryResults() == null);
+ Assert.assertEquals("should return rejected status",
+ Integer.valueOf(LCMCommandStatus.REJECTED.getResponseCode()),
+ queryOutputBuilder.getStatus().getCode());
+
+ // test processAction return without error
+ RequestExecutor mockExecutor = mock(RequestExecutor.class);
+ whenNew(RequestExecutor.class).withNoArguments().thenReturn(mockExecutor);
+
+ RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class);
+ Mockito.doReturn(mockOutput).when(mockExecutor).executeRequest(any());
+
+ ResponseContext mockResponseContext = mock(ResponseContext.class);
+ Mockito.doReturn(mockResponseContext).when(mockOutput).getResponseContext();
+
+ List<QueryResults> results = new ArrayList<>();
+ QueryResults mockResult = mock(QueryResults.class);
+ results.add(mockResult);
+ Mockito.doReturn(results).when(mockResponseContext).getPayloadObject();
+
+ org.onap.appc.domainmodel.lcm.Status mockStatus = mock(org.onap.appc.domainmodel.lcm.Status.class);
+ Integer successCode = Integer.valueOf(LCMCommandStatus.SUCCESS.getResponseCode());
+ Mockito.doReturn(successCode).when(mockStatus).getCode();
+ Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus();
+
+ queryOutputBuilder = queryService.process(mockInput);
+ Assert.assertTrue("Should have commonHeader",queryOutputBuilder.getCommonHeader() != null);
+ Assert.assertEquals("Should have queryResults", results, queryOutputBuilder.getQueryResults());
+ Assert.assertEquals("should return success status", successCode, queryOutputBuilder.getStatus().getCode());
+ }
+
+ @Test
+ public void testValidate() throws Exception {
+ // test commonHeader error
+ queryService.validate(mockInput);
+ Status status = (Status) Whitebox.getInternalState(queryService, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+ Mockito.verify(queryService, times(0)).buildStatusForParamName(any(), any());
+ Mockito.verify(queryService, times(0)).buildStatusForErrorMsg(any(), any());
+
+ ZULU mockTimeStamp = mock(ZULU.class);
+ Mockito.doReturn(mockTimeStamp).when(mockCommonHeader).getTimestamp();
+ Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+ Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+ Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+
+ // test empty ActionIdentifier
+ Mockito.doReturn(mockAI).when(mockInput).getActionIdentifiers();
+ Mockito.doReturn(myAction).when(mockInput).getAction();
+ queryService.validate(mockInput);
+ status = (Status) Whitebox.getInternalState(queryService, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test empty VNF_ID
+ Mockito.doReturn("").when(mockAI).getVnfId();
+ queryService.validate(mockInput);
+ status = (Status) Whitebox.getInternalState(queryService, "status");
+ Assert.assertEquals("should return invalid parameter",
+ Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode());
+
+ // test calling validateExcludeActId
+ Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+ queryService.validate(mockInput);
+ Mockito.verify(queryService, times(1)).validateExcludedActIds(any(), any());
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/QuiesceTrafficServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/QuiesceTrafficServiceTest.java
new file mode 100644
index 000000000..b6dc15ce3
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/QuiesceTrafficServiceTest.java
@@ -0,0 +1,186 @@
+/*-
+ * ============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.junit.Assert;
+import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.internal.util.reflection.Whitebox;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.*;
+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.domainmodel.lcm.ResponseContext;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.powermock.api.mockito.PowerMockito.whenNew;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({QuiesceTrafficService.class, RequestExecutor.class})
+public class QuiesceTrafficServiceTest {
+ private final Action myAction = Action.QuiesceTraffic;
+ private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}";
+ private QuiesceTrafficInput mockInput = mock(QuiesceTrafficInput.class);
+ private CommonHeader mockCommonHeader = mock(CommonHeader.class);
+ private ActionIdentifiers mockAI = mock(ActionIdentifiers.class);
+ private Payload mockPayload = mock(Payload.class);
+
+ private QuiesceTrafficService quiesceServiceAction;
+ @Before
+ public void setUp() throws Exception {
+ quiesceServiceAction = spy(new QuiesceTrafficService());
+ }
+
+
+ @Test
+ public void testConstructor() throws Exception {
+ Action expectedAction = Action.QuiesceTraffic;
+ Assert.assertEquals("Should have proper ACTION", expectedAction,
+ (Action) org.powermock.reflect.Whitebox.getInternalState(quiesceServiceAction, "expectedAction"));
+ Assert.assertEquals("Should have quiesce-traffic RPC name", "quiesce-traffic",
+ (org.powermock.reflect.Whitebox.getInternalState(quiesceServiceAction, "rpcName")).toString());
+ }
+
+// @Test
+// public void testProcess() throws Exception {
+// // test error occurs in validation
+// QuiesceTrafficOutputBuilder outputBuilder = quiesceServiceAction.process(mockInput);
+// Mockito.verify(quiesceServiceAction, times(0)).proceedAction(any(),any(),any());
+// Assert.assertTrue("Should not have commonHeader as we did not mock it",outputBuilder.getCommonHeader() == null);
+// Assert.assertEquals("should return missing parameter status",
+// Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()),
+// outputBuilder.getStatus().getCode());
+//
+// // make validation pass
+// Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader();
+// Mockito.doReturn(mockPayload).when(mockInput).getPayload();
+// Mockito.doReturn(PAYLOAD_STRING).when(mockPayload).getValue();
+// // to make validation pass
+// ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z");
+// Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp();
+// Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+// Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+// Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+//
+// Mockito.doReturn(myAction).when(mockInput).getAction();
+// Mockito.doReturn(mockAI).when(mockInput).getActionIdentifiers();
+// Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+//
+// // test processAction return with error
+// outputBuilder = quiesceServiceAction.process(mockInput);
+// Mockito.verify(quiesceServiceAction, times(1)).proceedAction(any(),any(),any());
+// Assert.assertTrue("Should have commonHeader",outputBuilder.getCommonHeader() != null);
+// Assert.assertEquals("should return rejected status",
+// Integer.valueOf(LCMCommandStatus.REJECTED.getResponseCode()),
+// outputBuilder.getStatus().getCode());
+//
+// // test processAction return without error
+// RequestExecutor mockExecutor = mock(RequestExecutor.class);
+// whenNew(RequestExecutor.class).withNoArguments().thenReturn(mockExecutor);
+//
+// RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class);
+// Mockito.doReturn(mockOutput).when(mockExecutor).executeRequest(any());
+//
+// ResponseContext mockResponseContext = mock(ResponseContext.class);
+// Mockito.doReturn(mockResponseContext).when(mockOutput).getResponseContext();
+//
+// org.onap.appc.domainmodel.lcm.Status mockStatus = mock(org.onap.appc.domainmodel.lcm.Status.class);
+// Integer successCode = Integer.valueOf(LCMCommandStatus.SUCCESS.getResponseCode());
+// Mockito.doReturn(successCode).when(mockStatus).getCode();
+// Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus();
+//
+// outputBuilder = quiesceServiceAction.process(mockInput);
+// Assert.assertTrue("Should have commonHeader",outputBuilder.getCommonHeader() != null);
+// Assert.assertEquals("should return success status", successCode, outputBuilder.getStatus().getCode());
+// }
+
+ @Test
+ public void testValidate() throws Exception {
+ quiesceServiceAction.validate(mockCommonHeader, Action.QuiesceTraffic, mockAI,mockPayload);
+ Status status = (Status) Whitebox.getInternalState(quiesceServiceAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+ Mockito.verify(quiesceServiceAction, times(0)).buildStatusForParamName(any(), any());
+ Mockito.verify(quiesceServiceAction, times(0)).buildStatusForErrorMsg(any(), any());
+
+ ZULU mockTimeStamp = mock(ZULU.class);
+ Mockito.doReturn(mockTimeStamp).when(mockCommonHeader).getTimestamp();
+ Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+ Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+ Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+
+ // test empty action
+ quiesceServiceAction.validate(mockCommonHeader, Action.QuiesceTraffic, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(quiesceServiceAction, "status");
+ Assert.assertEquals("Should return missing parameter for action",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test empty ActionIdentifier
+ quiesceServiceAction.validate(mockCommonHeader, Action.QuiesceTraffic, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(quiesceServiceAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test Invalid VNF_ID
+ Mockito.doReturn("").when(mockAI).getVnfId();
+ quiesceServiceAction.validate(mockCommonHeader, Action.QuiesceTraffic, mockAI,mockPayload);
+ status = (Status) Whitebox.getInternalState(quiesceServiceAction, "status");
+ Assert.assertEquals("should return invalid parameter",
+ Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode());
+
+ // test null payload
+ Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+ quiesceServiceAction.validate(mockCommonHeader, Action.QuiesceTraffic, mockAI, null);
+ Mockito.verify(quiesceServiceAction, times(1)).validateExcludedActIds(any(), any());
+ status = (Status) Whitebox.getInternalState(quiesceServiceAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test empty payload
+
+ Mockito.doReturn("").when(mockPayload).getValue();
+ quiesceServiceAction.validate(mockCommonHeader, Action.QuiesceTraffic, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(quiesceServiceAction, "status");
+ Assert.assertEquals("should return invalid parameter",
+ Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode());
+
+ // test space payload
+ Mockito.doReturn(" ").when(mockPayload).getValue();
+ quiesceServiceAction.validate(mockCommonHeader, Action.QuiesceTraffic, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(quiesceServiceAction, "status");
+ Assert.assertEquals("should return invalid parameter",
+ Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode());
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/RebootServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/RebootServiceTest.java
new file mode 100644
index 000000000..fffebf944
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/RebootServiceTest.java
@@ -0,0 +1,153 @@
+/*-
+ * ============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.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+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.RebootInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.RebootOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ZULU;
+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.status.Status;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.reflect.Whitebox;
+
+import static org.mockito.Mockito.times;
+
+@RunWith(PowerMockRunner.class)
+public class RebootServiceTest {
+ private final String vserverId = "vserverId";
+
+ @Mock
+ private RebootService rebootService;
+ @Mock
+ private RebootInput rebootInput;
+ @Mock
+ private ActionIdentifiers actionIdentifiers;
+ @Mock
+ private org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader commonHeader;
+
+ private Payload payload;
+
+ @Before
+ public void setUp() throws Exception {
+ rebootService = new RebootService();
+ payload = new Payload("{\"reboot-type\":\"hard\"}");
+
+ PowerMockito.doReturn(actionIdentifiers).when(rebootInput).getActionIdentifiers();
+ PowerMockito.doReturn(payload).when(rebootInput).getPayload();
+ PowerMockito.doReturn(commonHeader).when(rebootInput).getCommonHeader();
+ PowerMockito.doReturn(new ZULU("2017-09-05T16:55:55.807Z")).when(commonHeader).getTimestamp();
+ PowerMockito.doReturn("2.00").when(commonHeader).getApiVer();
+ PowerMockito.doReturn("demo-lcm-stop-id#1").when(commonHeader).getRequestId();
+ PowerMockito.doReturn("demo-lcm-stop-id#2").when(commonHeader).getSubRequestId();
+ PowerMockito.doReturn("originator-id").when(commonHeader).getOriginatorId();
+ PowerMockito.doReturn(Action.Reboot).when(rebootInput).getAction();
+ }
+
+ @Test
+ public void testConstructor() throws Exception {
+ Action expectedAction = Action.Reboot;
+ Assert.assertEquals("Should have proper ACTION", expectedAction,
+ (Action) org.powermock.reflect.Whitebox.getInternalState(rebootService, "expectedAction"));
+ Assert.assertEquals("Should have reboot RPC name", expectedAction.name().toLowerCase(),
+ (org.powermock.reflect.Whitebox.getInternalState(rebootService, "rpcName")).toString());
+ }
+
+ @Test
+ public void testProcessAccepted() throws Exception {
+ PowerMockito.doReturn(vserverId).when(actionIdentifiers).getVserverId();
+ RebootOutputBuilder process = rebootService.process(rebootInput);
+ PowerMockito.verifyPrivate(rebootService, times(1)).invoke("validate", rebootInput);
+ Assert.assertNotNull(process.getCommonHeader());
+ Assert.assertNotNull(process.getStatus());
+ }
+
+ @Test
+ public void testProcessError() throws Exception {
+ RebootOutputBuilder process = rebootService.process(rebootInput);
+ PowerMockito.verifyPrivate(rebootService, times(1))
+ .invoke("validate", rebootInput);
+ Assert.assertNotNull(process.getStatus());
+ }
+
+ @Test
+ public void testValidateSuccess() throws Exception {
+ PowerMockito.doReturn(vserverId).when(actionIdentifiers).getVserverId();
+ Status validate = Whitebox.invokeMethod(rebootService, "validate", rebootInput);
+ Assert.assertNull(validate);
+ }
+
+ @Test
+ public void testValidateMissingVserverId() throws Exception {
+ PowerMockito.doReturn("").when(actionIdentifiers).getVserverId();
+ Whitebox.invokeMethod(rebootService, "validate", rebootInput);
+ Status status = Whitebox.getInternalState(rebootService, "status");
+ Assert.assertNotNull(status);
+ }
+
+ @Test
+ public void testValidateWrongAction() throws Exception {
+ PowerMockito.doReturn(Action.Audit).when(rebootInput).getAction();
+ PowerMockito.doReturn("").when(actionIdentifiers).getVserverId();
+ Whitebox.invokeMethod(rebootService, "validate", rebootInput);
+ Status status = Whitebox.getInternalState(rebootService, "status");
+ Assert.assertNotNull(status);
+ }
+
+ @Test
+ public void testValidateMissingActionIdentifier() throws Exception {
+ PowerMockito.doReturn(actionIdentifiers).when(rebootInput).getActionIdentifiers();
+ Whitebox.invokeMethod(rebootService, "validate", rebootInput);
+ Status status = Whitebox.getInternalState(rebootService, "status");
+ Assert.assertNotNull(status);
+ }
+
+ @Test
+ public void testValidateMissingRebootType() throws Exception {
+ Payload payload = new Payload("{}");
+ PowerMockito.doReturn(payload).when(rebootInput).getPayload();
+ PowerMockito.doReturn(vserverId).when(actionIdentifiers).getVserverId();
+ Whitebox.invokeMethod(rebootService, "validate", rebootInput);
+ Status status = Whitebox.getInternalState(rebootService, "status");
+ Assert.assertNotNull(status);
+ }
+
+ @Test
+ public void testValidateWrongRebootType() throws Exception {
+ Payload payload = new Payload("{\"reboot-type\":\"1\"}");
+ PowerMockito.doReturn(payload).when(rebootInput).getPayload();
+ PowerMockito.doReturn(vserverId).when(actionIdentifiers).getVserverId();
+ Whitebox.invokeMethod(rebootService, "validate", rebootInput);
+ Status status = Whitebox.getInternalState(rebootService, "status");
+ Assert.assertNotNull(status);
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/RequestExecutorTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/RequestExecutorTest.java
new file mode 100644
index 000000000..a2001809e
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/RequestExecutorTest.java
@@ -0,0 +1,252 @@
+/*-
+ * ============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.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload;
+import org.onap.appc.domainmodel.lcm.ActionLevel;
+import org.onap.appc.domainmodel.lcm.CommonHeader;
+import org.onap.appc.domainmodel.lcm.RequestContext;
+import org.onap.appc.domainmodel.lcm.ResponseContext;
+import org.onap.appc.domainmodel.lcm.Status;
+import org.onap.appc.domainmodel.lcm.VNFOperation;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.executor.objects.Params;
+import org.onap.appc.i18n.Msg;
+import org.onap.appc.requesthandler.RequestHandler;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.powermock.api.mockito.PowerMockito.mockStatic;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({FrameworkUtil.class})
+public class RequestExecutorTest {
+ private final VNFOperation vnfOperation = VNFOperation.ActionStatus;
+ private final ActionLevel actionLevel = ActionLevel.MGMT;
+
+ private Bundle mockBundle = mock(Bundle.class);
+ private BundleContext mockBundleContext = mock(BundleContext.class);
+
+ private RequestHandlerInput mockInput = mock(RequestHandlerInput.class);
+ private RequestContext mockRequestContext = mock(RequestContext.class);
+ private CommonHeader mockCommonHeader = mock(CommonHeader.class);
+ private RequestHandler mockHandler = mock(RequestHandler.class);
+
+ private RequestExecutor requestExecutor;
+
+ @Before
+ public void setUp() throws Exception {
+ mockStatic(FrameworkUtil.class);
+ PowerMockito.when(FrameworkUtil.getBundle(any())).thenReturn(mockBundle);
+
+ Mockito.doReturn(mockRequestContext).when(mockInput).getRequestContext();
+ Mockito.doReturn(mockCommonHeader).when(mockRequestContext).getCommonHeader();
+
+ requestExecutor = spy(new RequestExecutor());
+ }
+
+ @Test
+ public void testExecuteRequest() throws Exception {
+ // test RequestHandler is null
+ Mockito.doReturn(null).when(mockBundle).getBundleContext();
+ Mockito.doReturn(actionLevel).when(mockRequestContext).getActionLevel();
+ Mockito.doReturn(vnfOperation).when(mockRequestContext).getAction();
+
+ Params params = new Params().addParam("errorMsg", requestExecutor.CANNOT_PROCESS);
+ LCMCommandStatus lcmCommandStatus = LCMCommandStatus.REJECTED;
+ Msg msg = Msg.REQUEST_HANDLER_UNAVAILABLE;
+
+ RequestHandlerOutput output = requestExecutor.executeRequest(mockInput);
+ ResponseContext responseContext = output.getResponseContext();
+ Status status = responseContext.getStatus();
+ Assert.assertEquals("Should have rejected status code",
+ lcmCommandStatus.getResponseCode(), status.getCode());
+ Assert.assertEquals("Should have rejected CANNOT_PROCESS status message",
+ lcmCommandStatus.getFormattedMessage(params), status.getMessage());
+ Assert.assertEquals("Should have the same commonHeader",
+ mockCommonHeader, responseContext.getCommonHeader());
+ Mockito.verify(requestExecutor, times(1)).getRequestHandler(any());
+ Mockito.verify(requestExecutor, times(1))
+ .createRequestHandlerOutput(any(), any(), any(), any());
+
+ // to get RequestHandler
+ ServiceReference<RequestHandler> mockSvcRefs = mock(ServiceReference.class);
+ Iterator mockIterator = mock(Iterator.class);
+ Mockito.doReturn(mockSvcRefs).when(mockIterator).next();
+
+ Collection<ServiceReference<RequestHandler>> mockSvcRefCollection = mock(Collection.class);
+ Mockito.doReturn(1).when(mockSvcRefCollection).size();
+ Mockito.doReturn(mockIterator).when(mockSvcRefCollection).iterator();
+
+ Mockito.doReturn(mockBundleContext).when(mockBundle).getBundleContext();
+ Mockito.doReturn(mockSvcRefCollection).when(mockBundleContext)
+ .getServiceReferences(eq(RequestHandler.class), anyString());
+
+ Mockito.doReturn(mockHandler).when(mockBundleContext).getService(mockSvcRefs);
+
+ // Skip test RequestHandler.quiesce throws exception as it does not throw exception
+
+ // test normal return
+ RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class);
+ Mockito.doReturn(mockOutput).when(mockHandler).handleRequest(mockInput);
+ output = requestExecutor.executeRequest(mockInput);
+ Assert.assertEquals("Should return mockOuput", mockOutput, output);
+ }
+
+ @Test
+ public void testGetRequestHandler() throws Exception {
+ // test null BundleContext
+ Mockito.doReturn(null).when(mockBundle).getBundleContext();
+ RequestHandler requestHandler = requestExecutor.getRequestHandler(actionLevel);
+ Assert.assertTrue("Should return null", requestHandler == null);
+
+ // test successful returning RequestHandler
+ ServiceReference<RequestHandler> mockSvcRefs = mock(ServiceReference.class);
+ Iterator mockIterator = mock(Iterator.class);
+ Mockito.doReturn(mockSvcRefs).when(mockIterator).next();
+
+ Collection<ServiceReference<RequestHandler>> mockSvcRefCollection = mock(Collection.class);
+ Mockito.doReturn(1).when(mockSvcRefCollection).size();
+ Mockito.doReturn(mockIterator).when(mockSvcRefCollection).iterator();
+
+ Mockito.doReturn(mockBundleContext).when(mockBundle).getBundleContext();
+ Mockito.doReturn(mockSvcRefCollection).when(mockBundleContext)
+ .getServiceReferences(eq(RequestHandler.class), anyString());
+
+ Mockito.doReturn(mockHandler).when(mockBundleContext).getService(mockSvcRefs);
+
+ requestHandler = requestExecutor.getRequestHandler(actionLevel);
+ Assert.assertEquals("Should return RequestHandler", mockHandler, requestHandler);
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void testGetRequesetHandlerWithInvalidSyntaxException() throws Exception {
+ Mockito.doReturn(mockBundleContext).when(mockBundle).getBundleContext();
+ Mockito.doThrow(new InvalidSyntaxException("testing message", "testing filter"))
+ .when(mockBundleContext).getServiceReferences(eq(RequestHandler.class), anyString());
+
+ requestExecutor.getRequestHandler(actionLevel);
+ }
+
+
+ @Test(expected = RuntimeException.class)
+ public void testGetRequesetHandlerWithCannotFoundSvc() throws Exception {
+ Collection<ServiceReference<RequestHandler>> mockSvcRefCollection = mock(Collection.class);
+ Mockito.doReturn(2).when(mockSvcRefCollection).size();
+
+ Mockito.doReturn(mockBundleContext).when(mockBundle).getBundleContext();
+ Mockito.doReturn(mockSvcRefCollection).when(mockBundleContext)
+ .getServiceReferences(eq(RequestHandler.class), anyString());
+
+ requestExecutor.getRequestHandler(actionLevel);
+ }
+
+ @Test
+ public void testCreateRequestHandlerOutput() throws Exception {
+ // test exception without message
+ Exception testException = new Exception();
+ Params params = new Params().addParam("errorMsg", testException.toString());
+ LCMCommandStatus lcmCommandStatus = LCMCommandStatus.REJECTED;
+ Msg msg = Msg.REQUEST_HANDLER_UNAVAILABLE;
+
+ RequestHandlerOutput output =
+ requestExecutor.createRequestHandlerOutput(mockInput, lcmCommandStatus, msg, testException);
+ ResponseContext responseContext = output.getResponseContext();
+ Status status = responseContext.getStatus();
+ Assert.assertEquals("Should have the same status code",
+ lcmCommandStatus.getResponseCode(), status.getCode());
+ Assert.assertEquals("Should have the proper exception to String status message",
+ lcmCommandStatus.getFormattedMessage(params), status.getMessage());
+ Assert.assertEquals("Should have the same commonHeader",
+ mockCommonHeader, responseContext.getCommonHeader());
+
+ // test exception with message
+ testException = new Exception("testing exception");
+ params = new Params().addParam("errorMsg", testException.getMessage());
+ lcmCommandStatus = LCMCommandStatus.UNEXPECTED_ERROR;
+ msg = Msg.EXCEPTION_CALLING_DG;
+
+ output =
+ requestExecutor.createRequestHandlerOutput(mockInput, lcmCommandStatus, msg, testException);
+ responseContext = output.getResponseContext();
+ status = responseContext.getStatus();
+ Assert.assertEquals("Should have the same status code",
+ lcmCommandStatus.getResponseCode(), status.getCode());
+ Assert.assertEquals("Should have the proper exception to String status message",
+ lcmCommandStatus.getFormattedMessage(params), status.getMessage());
+ Assert.assertEquals("Should have the same commonHeader",
+ mockCommonHeader, responseContext.getCommonHeader());
+ }
+
+ @Test
+ public void testGetPayload() throws Exception {
+ RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class);
+ ResponseContext mockResponseContext = mock(ResponseContext.class);
+ // test null response context
+ Mockito.doReturn(null).when(mockOutput).getResponseContext();
+ Assert.assertTrue("Should return null with null requestContext",
+ requestExecutor.getPayload(mockOutput) == null);
+
+ // test null payload
+ Mockito.doReturn(mockResponseContext).when(mockOutput).getResponseContext();
+ Mockito.doReturn(null).when(mockResponseContext).getPayload();
+ Assert.assertTrue("Should return null with null payload",
+ requestExecutor.getPayload(mockOutput) == null);
+
+ // test empty payload
+ Mockito.doReturn("").when(mockResponseContext).getPayload();
+ Assert.assertTrue("Should return null with empty payload",
+ requestExecutor.getPayload(mockOutput) == null);
+
+ // test proper payload
+ String testingPayload = "testing payload";
+ Mockito.doReturn(testingPayload).when(mockResponseContext).getPayload();
+ Payload payload = requestExecutor.getPayload(mockOutput);
+ Assert.assertEquals("Should return null with empty payload", testingPayload, payload.getValue());
+ }
+
+}
diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/ResumeTrafficServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/ResumeTrafficServiceTest.java
new file mode 100644
index 000000000..2ea7ee0d2
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/ResumeTrafficServiceTest.java
@@ -0,0 +1,162 @@
+/*-
+ * ============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.junit.Assert;
+import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.internal.util.reflection.Whitebox;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.*;
+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.domainmodel.lcm.ResponseContext;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.powermock.api.mockito.PowerMockito.whenNew;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ResumeTrafficService.class, RequestExecutor.class})
+public class ResumeTrafficServiceTest {
+ private final Action myAction = Action.ResumeTraffic;
+
+ private ResumeTrafficInput mockInput = mock(ResumeTrafficInput.class);
+ private CommonHeader mockCommonHeader = mock(CommonHeader.class);
+ private ActionIdentifiers mockAI = mock(ActionIdentifiers.class);
+
+ private ResumeTrafficService resumeServiceAction;
+ @Before
+ public void setUp() throws Exception {
+ resumeServiceAction = spy(new ResumeTrafficService());
+ }
+
+
+ @Test
+ public void testConstructor() throws Exception {
+ Action expectedAction = Action.ResumeTraffic;
+ Assert.assertEquals("Should have proper ACTION", expectedAction,
+ (Action) org.powermock.reflect.Whitebox.getInternalState(resumeServiceAction, "expectedAction"));
+ Assert.assertEquals("Should have resume-traffic RPC name", "resume-traffic",
+ (org.powermock.reflect.Whitebox.getInternalState(resumeServiceAction, "rpcName")).toString());
+ }
+
+// @Test
+// public void testProcess() throws Exception {
+// // test error occurs in validation
+// ResumeTrafficOutputBuilder outputBuilder = resumeServiceAction.process(mockInput);
+// Mockito.verify(resumeServiceAction, times(0)).proceedAction(any());
+// Assert.assertTrue("Should not have commonHeader as we did not mock it",outputBuilder.getCommonHeader() == null);
+// Assert.assertEquals("should return missing parameter status",
+// Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()),
+// outputBuilder.getStatus().getCode());
+//
+// // make validation pass
+// Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader();
+//
+// // to make validation pass
+// ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z");
+// Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp();
+// Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+// Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+// Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+//
+// Mockito.doReturn(myAction).when(mockInput).getAction();
+// Mockito.doReturn(mockAI).when(mockInput).getActionIdentifiers();
+// Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+//
+// // test processAction return with error
+// outputBuilder = resumeServiceAction.process(mockInput);
+// Mockito.verify(resumeServiceAction, times(1)).proceedAction(any());
+// Assert.assertTrue("Should have commonHeader",outputBuilder.getCommonHeader() != null);
+// Assert.assertEquals("should return rejected status",
+// Integer.valueOf(LCMCommandStatus.REJECTED.getResponseCode()),
+// outputBuilder.getStatus().getCode());
+//
+// // test processAction return without error
+// RequestExecutor mockExecutor = mock(RequestExecutor.class);
+// whenNew(RequestExecutor.class).withNoArguments().thenReturn(mockExecutor);
+//
+// RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class);
+// Mockito.doReturn(mockOutput).when(mockExecutor).executeRequest(any());
+//
+// ResponseContext mockResponseContext = mock(ResponseContext.class);
+// Mockito.doReturn(mockResponseContext).when(mockOutput).getResponseContext();
+//
+// org.onap.appc.domainmodel.lcm.Status mockStatus = mock(org.onap.appc.domainmodel.lcm.Status.class);
+// Integer successCode = Integer.valueOf(LCMCommandStatus.SUCCESS.getResponseCode());
+// Mockito.doReturn(successCode).when(mockStatus).getCode();
+// Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus();
+//
+// outputBuilder = resumeServiceAction.process(mockInput);
+// Assert.assertTrue("Should have commonHeader",outputBuilder.getCommonHeader() != null);
+// Assert.assertEquals("should return success status", successCode, outputBuilder.getStatus().getCode());
+// }
+
+ @Test
+ public void testValidate() throws Exception {
+ resumeServiceAction.validate(mockCommonHeader, Action.ResumeTraffic, mockAI);
+ Status status = (Status) Whitebox.getInternalState(resumeServiceAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+ Mockito.verify(resumeServiceAction, times(0)).buildStatusForParamName(any(), any());
+ Mockito.verify(resumeServiceAction, times(0)).buildStatusForErrorMsg(any(), any());
+
+ ZULU mockTimeStamp = mock(ZULU.class);
+ Mockito.doReturn(mockTimeStamp).when(mockCommonHeader).getTimestamp();
+ Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+ Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+ Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+
+ // test empty action
+ resumeServiceAction.validate(mockCommonHeader, Action.ResumeTraffic, mockAI);
+ status = (Status) Whitebox.getInternalState(resumeServiceAction, "status");
+ Assert.assertEquals("Should return missing parameter for action",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test empty ActionIdentifier
+ resumeServiceAction.validate(mockCommonHeader, Action.ResumeTraffic, mockAI);
+ status = (Status) Whitebox.getInternalState(resumeServiceAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test Invalid VNF_ID
+ Mockito.doReturn("").when(mockAI).getVnfId();
+ resumeServiceAction.validate(mockCommonHeader, Action.ResumeTraffic, mockAI);
+ status = (Status) Whitebox.getInternalState(resumeServiceAction, "status");
+ Assert.assertEquals("should return invalid parameter",
+ Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode());
+ }
+
+}
diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/UpgradeServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/UpgradeServiceTest.java
new file mode 100644
index 000000000..3247a0e94
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/UpgradeServiceTest.java
@@ -0,0 +1,686 @@
+/*-
+ * ============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.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.internal.util.reflection.Whitebox;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.*;
+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.domainmodel.lcm.ResponseContext;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.*;
+import static org.powermock.api.mockito.PowerMockito.whenNew;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({UpgradeService.class, RequestExecutor.class})
+public class UpgradeServiceTest {
+ private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}";
+ private UpgradePreCheckInput mockUpgradePreInput = mock(UpgradePreCheckInput.class);
+ private UpgradePostCheckInput mockUpgradePostInput = mock(UpgradePostCheckInput.class);
+ private UpgradeSoftwareInput mockUpgradeSoftInput = mock(UpgradeSoftwareInput.class);
+ private UpgradeBackupInput mockUpgradeBackupInput = mock(UpgradeBackupInput.class);
+ private UpgradeBackoutInput mockUpgradeBackoutInput = mock(UpgradeBackoutInput.class);
+ private CommonHeader mockCommonHeader = mock(CommonHeader.class);
+ private ActionIdentifiers mockAI = mock(ActionIdentifiers.class);
+ private Payload mockPayload = mock(Payload.class);
+
+ private UpgradeService upgradePreAction;
+ private UpgradeService upgradePostAction;
+ private UpgradeService upgradeSoftAction;
+ private UpgradeService upgradeBackupAction;
+ private UpgradeService upgradeBackoutAction;
+
+ @Before
+ public void setUp() throws Exception {
+ upgradePreAction = spy(new UpgradeService("upgradePre"));
+ upgradePostAction = spy(new UpgradeService("upgradePost"));
+ upgradeSoftAction = spy(new UpgradeService("upgradeSoft"));
+ upgradeBackupAction = spy(new UpgradeService("upgradeBackup"));
+ upgradeBackoutAction = spy(new UpgradeService("upgradeBackout"));
+ }
+
+ @Test
+ public void testConstructor() throws Exception {
+ Action expectedAction = Action.UpgradePreCheck;
+ Assert.assertEquals("Should have proper ACTION", expectedAction,
+ (Action) org.powermock.reflect.Whitebox.getInternalState(upgradePreAction, "expectedAction"));
+ Assert.assertEquals("Should have upgrade-precheck RPC name", "upgrade-pre-check",
+ (org.powermock.reflect.Whitebox.getInternalState(upgradePreAction, "rpcName")).toString());
+
+ expectedAction = Action.UpgradePostCheck;
+ Assert.assertEquals("Should have proper ACTION", expectedAction,
+ (Action) org.powermock.reflect.Whitebox.getInternalState(upgradePostAction, "expectedAction"));
+ Assert.assertEquals("Should have upgrade-postcheck RPC name","upgrade-post-check",
+ (org.powermock.reflect.Whitebox.getInternalState(upgradePostAction, "rpcName")).toString());
+
+ expectedAction = Action.UpgradeSoftware;
+ Assert.assertEquals("Should have proper ACTION", expectedAction,
+ (Action) org.powermock.reflect.Whitebox.getInternalState(upgradeSoftAction, "expectedAction"));
+ Assert.assertEquals("Should have upgrade-software RPC name", "upgrade-software",
+ (org.powermock.reflect.Whitebox.getInternalState(upgradeSoftAction, "rpcName")).toString());
+
+ expectedAction = Action.UpgradeBackup;
+ Assert.assertEquals("Should have proper ACTION", expectedAction,
+ (Action) org.powermock.reflect.Whitebox.getInternalState(upgradeBackupAction, "expectedAction"));
+ Assert.assertEquals("Should have upgrade-backup RPC name","upgrade-backup",
+ (org.powermock.reflect.Whitebox.getInternalState(upgradeBackupAction, "rpcName")).toString());
+
+ expectedAction = Action.UpgradeBackout;
+ Assert.assertEquals("Should have proper ACTION", expectedAction,
+ (Action) org.powermock.reflect.Whitebox.getInternalState(upgradeBackoutAction, "expectedAction"));
+ Assert.assertEquals("Should have upgrade-backout RPC name","upgrade-backout",
+ (org.powermock.reflect.Whitebox.getInternalState(upgradeBackoutAction, "rpcName")).toString());
+
+ }
+
+// @Test
+// public void testUpgradePreCheck() throws Exception {
+// // test error occurs in validation
+// UpgradePreCheckOutputBuilder outputBuilder = upgradePreAction.upgradePreCheck(mockUpgradePreInput);
+// //Mockito.verify(upgradePreAction, times(0)).proceedAction(any(), any(), any());
+// Assert.assertTrue("Should not have commonHeader as we did not mock it",
+// outputBuilder.getCommonHeader() == null);
+// Assert.assertEquals("should return missing parameter status",
+// Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()),
+// outputBuilder.getStatus().getCode());
+//
+// // make validation pass
+// Mockito.doReturn(mockCommonHeader).when(mockUpgradePreInput).getCommonHeader();
+// Mockito.doReturn(mockPayload).when(mockUpgradePreInput).getPayload();
+// Mockito.doReturn(PAYLOAD_STRING).when(mockPayload).getValue();
+//
+// ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z");
+// Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp();
+// Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+// Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+// Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+//
+// Mockito.doReturn(Action.UpgradePreCheck).when(mockUpgradePreInput).getAction();
+// Mockito.doReturn(mockAI).when(mockUpgradePreInput).getActionIdentifiers();
+// Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+//
+// // test proceedAction return with error
+// outputBuilder = upgradePreAction.upgradePreCheck(mockUpgradePreInput);
+// //Mockito.verify(upgradePreAction, times(1)).proceedAction(any(), any(), any());
+// Assert.assertTrue("Should have commonHeader",
+// outputBuilder.getCommonHeader() != null);
+// Assert.assertEquals("should return rejected status",
+// Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()),
+// outputBuilder.getStatus().getCode());
+//
+// // test proceedAction return without error
+// RequestExecutor mockExecutor = mock(RequestExecutor.class);
+// whenNew(RequestExecutor.class).withNoArguments().thenReturn(mockExecutor);
+//
+// RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class);
+// Mockito.doReturn(mockOutput).when(mockExecutor).executeRequest(any());
+//
+// ResponseContext mockResponseContext = mock(ResponseContext.class);
+// Mockito.doReturn(mockResponseContext).when(mockOutput).getResponseContext();
+//
+// org.onap.appc.domainmodel.lcm.Status mockStatus = mock(org.onap.appc.domainmodel.lcm.Status.class);
+// Integer successCode = Integer.valueOf(LCMCommandStatus.SUCCESS.getResponseCode());
+// Mockito.doReturn(successCode).when(mockStatus).getCode();
+// Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus();
+//
+// outputBuilder = upgradePreAction.upgradePreCheck(mockUpgradePreInput);
+// Assert.assertTrue("Should have commonHeader",
+// outputBuilder.getCommonHeader() != null);
+// Assert.assertEquals("should return success status",
+// new Integer(302), outputBuilder.getStatus().getCode());
+// }
+//
+// @Test
+// public void testUpgradePostCheck() throws Exception {
+// // test error occurs in validation
+// UpgradePostCheckOutputBuilder outputBuilder = upgradePostAction.upgradePostCheck(mockUpgradePostInput);
+// // Mockito.verify(upgradePostAction, times(0)).proceedAction(any(), any(), any());
+// Assert.assertTrue("Should not have commonHeader as we did not mock it",
+// outputBuilder.getCommonHeader() == null);
+// Assert.assertEquals("should return missing parameter status",
+// Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()),
+// outputBuilder.getStatus().getCode());
+//
+// // make validation pass
+// Mockito.doReturn(mockCommonHeader).when(mockUpgradePostInput).getCommonHeader();
+// Mockito.doReturn(mockPayload).when(mockUpgradePostInput).getPayload();
+// Mockito.doReturn(PAYLOAD_STRING).when(mockPayload).getValue();
+//
+// ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z");
+// Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp();
+// Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+// Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+// Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+//
+// Mockito.doReturn(Action.UpgradePostCheck).when(mockUpgradePostInput).getAction();
+// Mockito.doReturn(mockAI).when(mockUpgradePostInput).getActionIdentifiers();
+// Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+//
+// // test proceedAction return with error
+// outputBuilder = upgradePostAction.upgradePostCheck(mockUpgradePostInput);
+// // Mockito.verify(upgradePostAction, times(1)).proceedAction(any(), any(), any());
+// Assert.assertTrue("Should have commonHeader",
+// outputBuilder.getCommonHeader() != null);
+// Assert.assertEquals("should return rejected status",
+// Integer.valueOf(302),
+// outputBuilder.getStatus().getCode());
+//
+// // test proceedAction return without error
+// RequestExecutor mockExecutor = mock(RequestExecutor.class);
+// whenNew(RequestExecutor.class).withNoArguments().thenReturn(mockExecutor);
+//
+// RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class);
+// Mockito.doReturn(mockOutput).when(mockExecutor).executeRequest(any());
+//
+// ResponseContext mockResponseContext = mock(ResponseContext.class);
+// Mockito.doReturn(mockResponseContext).when(mockOutput).getResponseContext();
+//
+// org.onap.appc.domainmodel.lcm.Status mockStatus = mock(org.onap.appc.domainmodel.lcm.Status.class);
+// Integer successCode = Integer.valueOf(LCMCommandStatus.SUCCESS.getResponseCode());
+// Mockito.doReturn(successCode).when(mockStatus).getCode();
+// Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus();;
+//
+// outputBuilder = upgradePostAction.upgradePostCheck(mockUpgradePostInput);
+// Assert.assertTrue("Should have commonHeader",
+// outputBuilder.getCommonHeader() != null);
+// Assert.assertEquals("should return success status",
+// new Integer(302), outputBuilder.getStatus().getCode());
+// }
+// @Test
+// public void testUpgradeSoftware() throws Exception {
+// // test error occurs in validation
+// UpgradeSoftwareOutputBuilder outputBuilder = upgradeSoftAction.upgradeSoftware(mockUpgradeSoftInput);
+// //Mockito.verify(upgradeSoftAction, times(0)).proceedAction(any(), any(), any());
+// Assert.assertTrue("Should not have commonHeader as we did not mock it",
+// outputBuilder.getCommonHeader() == null);
+// Assert.assertEquals("should return missing parameter status",
+// Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()),
+// outputBuilder.getStatus().getCode());
+//
+// // make validation pass
+// Mockito.doReturn(mockCommonHeader).when(mockUpgradeSoftInput).getCommonHeader();
+// Mockito.doReturn(mockPayload).when(mockUpgradeSoftInput).getPayload();
+// Mockito.doReturn(PAYLOAD_STRING).when(mockPayload).getValue();
+//
+// ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z");
+// Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp();
+// Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+// Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+// Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+//
+// Mockito.doReturn(Action.UpgradeSoftware).when(mockUpgradeSoftInput).getAction();
+// Mockito.doReturn(mockAI).when(mockUpgradeSoftInput).getActionIdentifiers();
+// Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+//
+// // test proceedAction return with error
+// outputBuilder = upgradeSoftAction.upgradeSoftware(mockUpgradeSoftInput);
+// //Mockito.verify(upgradeSoftAction, times(1)).proceedAction(any(), any(), any());
+// Assert.assertTrue("Should have commonHeader",
+// outputBuilder.getCommonHeader() != null);
+// Assert.assertEquals("should return rejected status",
+// Integer.valueOf(302),
+// outputBuilder.getStatus().getCode());
+//
+// // test proceedAction return without error
+// RequestExecutor mockExecutor = mock(RequestExecutor.class);
+// whenNew(RequestExecutor.class).withNoArguments().thenReturn(mockExecutor);
+//
+// RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class);
+// Mockito.doReturn(mockOutput).when(mockExecutor).executeRequest(any());
+//
+// ResponseContext mockResponseContext = mock(ResponseContext.class);
+// Mockito.doReturn(mockResponseContext).when(mockOutput).getResponseContext();
+//
+// org.onap.appc.domainmodel.lcm.Status mockStatus = mock(org.onap.appc.domainmodel.lcm.Status.class);
+// Integer successCode = Integer.valueOf(LCMCommandStatus.SUCCESS.getResponseCode());
+// Mockito.doReturn(successCode).when(mockStatus).getCode();
+// Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus();
+//
+// outputBuilder = upgradeSoftAction.upgradeSoftware(mockUpgradeSoftInput);
+// Assert.assertTrue("Should have commonHeader",
+// outputBuilder.getCommonHeader() != null);
+// Assert.assertEquals("should return success status",
+// new Integer(302), outputBuilder.getStatus().getCode());
+// }
+// @Test
+// public void testUpgradeBackup() throws Exception {
+// // test error occurs in validation
+// UpgradeBackupOutputBuilder outputBuilder = upgradeBackupAction.upgradeBackup(mockUpgradeBackupInput);
+// //Mockito.verify(upgradeBackupAction, times(0)).proceedAction(any(), any(), any());
+// Assert.assertTrue("Should not have commonHeader as we did not mock it",
+// outputBuilder.getCommonHeader() == null);
+// Assert.assertEquals("should return missing parameter status",
+// Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()),
+// outputBuilder.getStatus().getCode());
+//
+// // make validation pass
+// Mockito.doReturn(mockCommonHeader).when(mockUpgradeBackupInput).getCommonHeader();
+// Mockito.doReturn(mockPayload).when(mockUpgradeBackupInput).getPayload();
+// Mockito.doReturn(PAYLOAD_STRING).when(mockPayload).getValue();
+//
+// ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z");
+// Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp();
+// Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+// Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+// Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+//
+// Mockito.doReturn(Action.UpgradeBackup).when(mockUpgradeBackupInput).getAction();
+// Mockito.doReturn(mockAI).when(mockUpgradeBackupInput).getActionIdentifiers();
+// Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+//
+// // test proceedAction return with error
+// outputBuilder = upgradeBackupAction.upgradeBackup(mockUpgradeBackupInput);
+// //Mockito.verify(upgradeBackupAction, times(1)).proceedAction(any(), any(), any());
+// Assert.assertTrue("Should have commonHeader",
+// outputBuilder.getCommonHeader() != null);
+// Assert.assertEquals("should return rejected status",
+// Integer.valueOf(302),
+// outputBuilder.getStatus().getCode());
+//
+// // test proceedAction return without error
+// RequestExecutor mockExecutor = mock(RequestExecutor.class);
+// whenNew(RequestExecutor.class).withNoArguments().thenReturn(mockExecutor);
+//
+// RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class);
+// Mockito.doReturn(mockOutput).when(mockExecutor).executeRequest(any());
+//
+// ResponseContext mockResponseContext = mock(ResponseContext.class);
+// Mockito.doReturn(mockResponseContext).when(mockOutput).getResponseContext();
+//
+// org.onap.appc.domainmodel.lcm.Status mockStatus = mock(org.onap.appc.domainmodel.lcm.Status.class);
+// Integer successCode = Integer.valueOf(LCMCommandStatus.SUCCESS.getResponseCode());
+// Mockito.doReturn(successCode).when(mockStatus).getCode();
+// Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus();
+//
+// outputBuilder = upgradeBackupAction.upgradeBackup(mockUpgradeBackupInput);
+// Assert.assertTrue("Should have commonHeader",
+// outputBuilder.getCommonHeader() != null);
+// Assert.assertEquals("should return success status",
+// new Integer(302), outputBuilder.getStatus().getCode());
+// }
+//
+// @Test
+// public void testUpgradeBackout() throws Exception {
+// // test error occurs in validation
+// UpgradeBackoutOutputBuilder outputBuilder = upgradeBackoutAction.upgradeBackout(mockUpgradeBackoutInput);
+// //Mockito.verify(upgradeBackoutAction, times(0)).proceedAction(any(), any(), any());
+// Assert.assertTrue("Should not have commonHeader as we did not mock it",
+// outputBuilder.getCommonHeader() == null);
+// Assert.assertEquals("should return missing parameter status",
+// Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()),
+// outputBuilder.getStatus().getCode());
+//
+// // make validation pass
+// Mockito.doReturn(mockCommonHeader).when(mockUpgradeBackoutInput).getCommonHeader();
+// Mockito.doReturn(mockPayload).when(mockUpgradeBackoutInput).getPayload();
+// Mockito.doReturn(PAYLOAD_STRING).when(mockPayload).getValue();
+//
+// ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z");
+// Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp();
+// Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+// Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+// Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+//
+// Mockito.doReturn(Action.UpgradeBackup).when(mockUpgradeBackupInput).getAction();
+// Mockito.doReturn(mockAI).when(mockUpgradeBackupInput).getActionIdentifiers();
+// Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+//
+// // test proceedAction return with error
+// outputBuilder = upgradeBackoutAction.upgradeBackout(mockUpgradeBackoutInput);
+// //Mockito.verify(upgradeBackoutAction, times(1)).proceedAction(any(), any(), any());
+// Assert.assertTrue("Should have commonHeader",
+// outputBuilder.getCommonHeader() != null);
+// Assert.assertEquals("should return rejected status",
+// Integer.valueOf(302),
+// outputBuilder.getStatus().getCode());
+//
+// // test proceedAction return without error
+// RequestExecutor mockExecutor = mock(RequestExecutor.class);
+// whenNew(RequestExecutor.class).withNoArguments().thenReturn(mockExecutor);
+//
+// RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class);
+// Mockito.doReturn(mockOutput).when(mockExecutor).executeRequest(any());
+//
+// ResponseContext mockResponseContext = mock(ResponseContext.class);
+// Mockito.doReturn(mockResponseContext).when(mockOutput).getResponseContext();
+//
+// org.onap.appc.domainmodel.lcm.Status mockStatus = mock(org.onap.appc.domainmodel.lcm.Status.class);
+// Integer successCode = Integer.valueOf(LCMCommandStatus.SUCCESS.getResponseCode());
+// Mockito.doReturn(successCode).when(mockStatus).getCode();
+// Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus();
+//
+// outputBuilder = upgradeBackoutAction.upgradeBackout(mockUpgradeBackoutInput);
+// Assert.assertTrue("Should have commonHeader",
+// outputBuilder.getCommonHeader() != null);
+// Assert.assertEquals("should return success status",
+// new Integer(302), outputBuilder.getStatus().getCode());
+// }
+//}
+
+// @Test
+// public void testValidateForPreCheckAction() throws Exception {
+// // test commonHeader error
+// upgradePreAction.validate(mockCommonHeader, Action.UpgradePreCheck, mockAI, mockPayload);
+// Status status = (Status) Whitebox.getInternalState(upgradePreAction, "status");
+// Assert.assertEquals("should return missing parameter",
+// Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+// //Mockito.verify(upgradePreAction, times(0)).buildStatusForParamName(any(), any());
+// // Mockito.verify(upgradePreAction, times(0)).buildStatusForErrorMsg(any(), any());
+//
+// ZULU mockTimeStamp = mock(ZULU.class);
+// Mockito.doReturn(mockTimeStamp).when(mockCommonHeader).getTimestamp();
+// Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+// Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+// Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+//
+// // test Invalid action
+// upgradePreAction.validate(mockCommonHeader, Action.UpgradePreCheck, mockAI, mockPayload);
+// status = (Status) Whitebox.getInternalState(upgradePreAction, "status");
+// Assert.assertEquals("Should return invalid parameter for action",
+// Integer.valueOf(302), status.getCode());
+//
+// // test empty ActionIdentifier
+// upgradePreAction.validate(mockCommonHeader, Action.UpgradePreCheck, mockAI, mockPayload);
+// status = (Status) Whitebox.getInternalState(upgradePreAction, "status");
+// Assert.assertEquals("should return missing parameter",
+// Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+//
+// // test empty VSERVER_ID
+// Mockito.doReturn("").when(mockAI).getVnfId();
+// upgradePreAction.validate(mockCommonHeader, Action.UpgradePreCheck, mockAI, mockPayload);
+// status = (Status) Whitebox.getInternalState(upgradePreAction, "status");
+// Assert.assertEquals("should return invalid parameter",
+// Integer.valueOf(302), status.getCode());
+//
+// Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+//
+// // test null payload
+// upgradePreAction.validate(mockCommonHeader, Action.UpgradePreCheck, mockAI, null);
+// //Mockito.verify(upgradePreAction, times(1)).validateExcludedActIds(any(), any());
+// status = (Status) Whitebox.getInternalState(upgradePreAction, "status");
+// Assert.assertEquals("should return missing parameter",
+// Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+//
+// // test empty payload
+// Mockito.doReturn("").when(mockPayload).getValue();
+// upgradePreAction.validate(mockCommonHeader, Action.UpgradePreCheck, mockAI, mockPayload);
+// status = (Status) Whitebox.getInternalState(upgradePreAction, "status");
+// Assert.assertEquals("should return invalid parameter",
+// Integer.valueOf(302), status.getCode());
+//
+// // test space payload
+// Mockito.doReturn(" ").when(mockPayload).getValue();
+// upgradePreAction.validate(mockCommonHeader, Action.UpgradePreCheck, mockAI, mockPayload);
+// status = (Status) Whitebox.getInternalState(upgradePreAction, "status");
+// Assert.assertEquals("should return invalid parameter",
+// Integer.valueOf(302), status.getCode());
+// }
+//
+// @Test
+// public void testValidateForUpgradePostAction() throws Exception {
+// // test commonHeader error
+// upgradePostAction.validate(mockCommonHeader, Action.UpgradePostCheck, mockAI, mockPayload);
+// Status status = (Status) Whitebox.getInternalState(upgradePostAction, "status");
+// Assert.assertEquals("should return missing parameter",
+// Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+// // Mockito.verify(upgradePostAction, times(0)).buildStatusForParamName(any(), any());
+// //Mockito.verify(upgradePostAction, times(0)).buildStatusForErrorMsg(any(), any());
+//
+// ZULU mockTimeStamp = mock(ZULU.class);
+// Mockito.doReturn(mockTimeStamp).when(mockCommonHeader).getTimestamp();
+// Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+// Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+// Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+//
+// // test Invalid action
+// upgradePostAction.validate(mockCommonHeader, Action.UpgradePostCheck, mockAI, mockPayload);
+// status = (Status) Whitebox.getInternalState(upgradePostAction, "status");
+// Assert.assertEquals("Should return invalid parameter for action",
+// Integer.valueOf(302), status.getCode());
+//
+// // test empty ActionIdentifier
+// upgradePostAction.validate(mockCommonHeader, Action.UpgradePostCheck, mockAI, mockPayload);
+// status = (Status) Whitebox.getInternalState(upgradePostAction, "status");
+// Assert.assertEquals("should return missing parameter",
+// Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+//
+// // test empty VSERVER_ID
+// Mockito.doReturn("").when(mockAI).getVnfId();
+// upgradePostAction.validate(mockCommonHeader, Action.UpgradePostCheck, mockAI, mockPayload);
+// status = (Status) Whitebox.getInternalState(upgradePostAction, "status");
+// Assert.assertEquals("should return invalid parameter",
+// Integer.valueOf(302), status.getCode());
+//
+// Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+//
+// // test null payload
+// upgradePostAction.validate(mockCommonHeader, Action.UpgradePostCheck, mockAI, null);
+// //Mockito.verify(upgradePostAction, times(1)).validateExcludedActIds(any(), any());
+// status = (Status) Whitebox.getInternalState(upgradePostAction, "status");
+// Assert.assertEquals("should return missing parameter",
+// Integer.valueOf(302), status.getCode());
+//
+// // test empty payload
+// Mockito.doReturn("").when(mockPayload).getValue();
+// upgradePostAction.validate(mockCommonHeader, Action.UpgradePostCheck, mockAI, mockPayload);
+// status = (Status) Whitebox.getInternalState(upgradePostAction, "status");
+// Assert.assertEquals("should return invalid parameter",
+// Integer.valueOf(302), status.getCode());
+//
+// // test space payload
+// Mockito.doReturn(" ").when(mockPayload).getValue();
+// upgradePostAction.validate(mockCommonHeader, Action.UpgradePostCheck, mockAI, mockPayload);
+// status = (Status) Whitebox.getInternalState(upgradePostAction, "status");
+// Assert.assertEquals("should return invalid parameter",
+// Integer.valueOf(302), status.getCode());
+// }
+// @Test
+// public void testValidateForUpgradeBackoutAction() throws Exception {
+// // test commonHeader error
+// upgradeBackoutAction.validate(mockCommonHeader, Action.UpgradeBackout, mockAI, mockPayload);
+// Status status = (Status) Whitebox.getInternalState(upgradeBackoutAction, "status");
+// Assert.assertEquals("should return missing parameter",
+// Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+// //Mockito.verify(upgradeBackoutAction, times(0)).buildStatusForParamName(any(), any());
+// // Mockito.verify(upgradeBackoutAction, times(0)).buildStatusForErrorMsg(any(), any());
+//
+// ZULU mockTimeStamp = mock(ZULU.class);
+// Mockito.doReturn(mockTimeStamp).when(mockCommonHeader).getTimestamp();
+// Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+// Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+// Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+//
+// // test Invalid action
+// upgradeBackoutAction.validate(mockCommonHeader, Action.UpgradeBackout, mockAI, mockPayload);
+// status = (Status) Whitebox.getInternalState(upgradeBackoutAction, "status");
+// Assert.assertEquals("Should return invalid parameter for action",
+// Integer.valueOf(302), status.getCode());
+//
+// // test empty ActionIdentifier
+// upgradeBackoutAction.validate(mockCommonHeader, Action.UpgradeBackout, mockAI, mockPayload);
+// status = (Status) Whitebox.getInternalState(upgradeBackoutAction, "status");
+// Assert.assertEquals("should return missing parameter",
+// Integer.valueOf(302), status.getCode());
+//
+// // test empty VSERVER_ID
+// Mockito.doReturn("").when(mockAI).getVnfId();
+// upgradeBackoutAction.validate(mockCommonHeader, Action.UpgradeBackout, mockAI, mockPayload);
+// status = (Status) Whitebox.getInternalState(upgradeBackoutAction, "status");
+// Assert.assertEquals("should return invalid parameter",
+// Integer.valueOf(302), status.getCode());
+//
+// Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+//
+// // test null payload
+// upgradeBackoutAction.validate(mockCommonHeader, Action.UpgradeBackout, mockAI, null);
+// // Mockito.verify(upgradeBackoutAction, times(1)).validateExcludedActIds(any(), any());
+// status = (Status) Whitebox.getInternalState(upgradeBackoutAction, "status");
+// Assert.assertEquals("should return missing parameter",
+// Integer.valueOf(302), status.getCode());
+//
+// // test empty payload
+// Mockito.doReturn("").when(mockPayload).getValue();
+// upgradeBackoutAction.validate(mockCommonHeader, Action.UpgradeBackout, mockAI, mockPayload);
+// status = (Status) Whitebox.getInternalState(upgradeBackoutAction, "status");
+// Assert.assertEquals("should return invalid parameter",
+// Integer.valueOf(302), status.getCode());
+//
+// // test space payload
+// Mockito.doReturn(" ").when(mockPayload).getValue();
+// upgradeBackoutAction.validate(mockCommonHeader, Action.UpgradeBackout, mockAI, mockPayload);
+// status = (Status) Whitebox.getInternalState(upgradeBackoutAction, "status");
+// Assert.assertEquals("should return invalid parameter",
+// Integer.valueOf(302), status.getCode());
+// }
+//
+// @Test
+// public void testValidateForUpgradeSoftwareAction() throws Exception {
+// // test commonHeader error
+// upgradeSoftAction.validate(mockCommonHeader, Action.UpgradeSoftware, mockAI, mockPayload);
+// Status status = (Status) Whitebox.getInternalState(upgradeSoftAction, "status");
+// Assert.assertEquals("should return missing parameter",
+// Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+// //Mockito.verify(upgradeSoftAction, times(0)).buildStatusForParamName(any(), any());
+// //Mockito.verify(upgradeSoftAction, times(0)).buildStatusForErrorMsg(any(), any());
+//
+// ZULU mockTimeStamp = mock(ZULU.class);
+// Mockito.doReturn(mockTimeStamp).when(mockCommonHeader).getTimestamp();
+// Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+// Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+// Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+//
+// // test Invalid action
+// upgradeSoftAction.validate(mockCommonHeader, Action.UpgradeSoftware, mockAI, mockPayload);
+// status = (Status) Whitebox.getInternalState(upgradeSoftAction, "status");
+// Assert.assertEquals("Should return invalid parameter for action",
+// Integer.valueOf(302), status.getCode());
+//
+// // test empty ActionIdentifier
+// upgradeSoftAction.validate(mockCommonHeader, Action.UpgradeSoftware, mockAI, mockPayload);
+// status = (Status) Whitebox.getInternalState(upgradeSoftAction, "status");
+// Assert.assertEquals("should return missing parameter",
+// Integer.valueOf(302), status.getCode());
+//
+// // test empty VSERVER_ID
+// Mockito.doReturn("").when(mockAI).getVnfId();
+// upgradeSoftAction.validate(mockCommonHeader, Action.UpgradeSoftware, mockAI, mockPayload);
+// status = (Status) Whitebox.getInternalState(upgradeSoftAction, "status");
+// Assert.assertEquals("should return invalid parameter",
+// Integer.valueOf(302), status.getCode());
+//
+// Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+//
+// // test null payload
+// upgradeSoftAction.validate(mockCommonHeader, Action.UpgradeSoftware, mockAI, null);
+// //Mockito.verify(upgradeSoftAction, times(1)).validateExcludedActIds(any(), any());
+// status = (Status) Whitebox.getInternalState(upgradeSoftAction, "status");
+// Assert.assertEquals("should return missing parameter",
+// Integer.valueOf(302), status.getCode());
+//
+// // test empty payload
+// Mockito.doReturn("").when(mockPayload).getValue();
+// upgradeSoftAction.validate(mockCommonHeader, Action.UpgradeSoftware, mockAI, mockPayload);
+// status = (Status) Whitebox.getInternalState(upgradeSoftAction, "status");
+// Assert.assertEquals("should return invalid parameter",
+// Integer.valueOf(302), status.getCode());
+//
+// // test space payload
+// Mockito.doReturn(" ").when(mockPayload).getValue();
+// upgradeSoftAction.validate(mockCommonHeader, Action.UpgradeSoftware, mockAI, mockPayload);
+// status = (Status) Whitebox.getInternalState(upgradeSoftAction, "status");
+// Assert.assertEquals("should return invalid parameter",
+// Integer.valueOf(302), status.getCode());
+// }
+//
+// @Test
+// public void testValidateForUpgradeBackupAction() throws Exception {
+// // test commonHeader error
+// upgradeBackupAction.validate(mockCommonHeader, Action.UpgradeBackup, mockAI, mockPayload);
+// Status status = (Status) Whitebox.getInternalState(upgradeBackupAction, "status");
+// Assert.assertEquals("should return missing parameter",
+// Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+// //Mockito.verify(upgradeBackupAction, times(0)).buildStatusForParamName(any(), any());
+// //Mockito.verify(upgradeBackupAction, times(0)).buildStatusForErrorMsg(any(), any());
+//
+// ZULU mockTimeStamp = mock(ZULU.class);
+// Mockito.doReturn(mockTimeStamp).when(mockCommonHeader).getTimestamp();
+// Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+// Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+// Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+//
+// // test Invalid action
+// upgradeBackupAction.validate(mockCommonHeader, Action.UpgradeBackup, mockAI, mockPayload);
+// status = (Status) Whitebox.getInternalState(upgradeBackupAction, "status");
+// Assert.assertEquals("Should return invalid parameter for action",
+// Integer.valueOf(302), status.getCode());
+//
+// // test empty ActionIdentifier
+// upgradeBackupAction.validate(mockCommonHeader, Action.UpgradeBackup, mockAI, mockPayload);
+// status = (Status) Whitebox.getInternalState(upgradeBackupAction, "status");
+// Assert.assertEquals("should return missing parameter",
+// Integer.valueOf(302), status.getCode());
+//
+// // test empty VSERVER_ID
+// Mockito.doReturn("").when(mockAI).getVnfId();
+// upgradeBackupAction.validate(mockCommonHeader, Action.UpgradeBackup, mockAI, mockPayload);
+// status = (Status) Whitebox.getInternalState(upgradeBackupAction, "status");
+// Assert.assertEquals("should return invalid parameter",
+// Integer.valueOf(302), status.getCode());
+//
+// Mockito.doReturn("vnfId").when(mockAI).getVnfId();
+//
+// // test null payload
+// upgradeBackupAction.validate(mockCommonHeader, Action.UpgradeBackup, mockAI, null);
+// //Mockito.verify(upgradeBackupAction, times(1)).validateExcludedActIds(any(), any());
+// status = (Status) Whitebox.getInternalState(upgradeBackupAction, "status");
+// Assert.assertEquals("should return missing parameter",
+// Integer.valueOf(302), status.getCode());
+//
+// // test empty payload
+// Mockito.doReturn("").when(mockPayload).getValue();
+// upgradeBackupAction.validate(mockCommonHeader, Action.UpgradeBackup, mockAI, mockPayload);
+// status = (Status) Whitebox.getInternalState(upgradeBackupAction, "status");
+// Assert.assertEquals("should return invalid parameter",
+// Integer.valueOf(302), status.getCode());
+//
+// // test space payload
+// Mockito.doReturn(" ").when(mockPayload).getValue();
+// upgradeBackupAction.validate(mockCommonHeader, Action.UpgradeBackup, mockAI, mockPayload);
+// status = (Status) Whitebox.getInternalState(upgradeBackupAction, "status");
+// Assert.assertEquals("should return invalid parameter",
+// Integer.valueOf(302), status.getCode());
+// }
+}
diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/VolumeServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/VolumeServiceTest.java
new file mode 100644
index 000000000..0140dabd9
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/VolumeServiceTest.java
@@ -0,0 +1,320 @@
+/*-
+ * ============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.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.internal.util.reflection.Whitebox;
+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.ZULU;
+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.domainmodel.lcm.ResponseContext;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.powermock.api.mockito.PowerMockito.whenNew;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({VolumeService.class, RequestExecutor.class})
+public class VolumeServiceTest {
+ private final String PAYLOAD_STRING = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}";
+ private AttachVolumeInput mockAttachInput = mock(AttachVolumeInput.class);
+ private DetachVolumeInput mockDetachInput = mock(DetachVolumeInput.class);
+ private CommonHeader mockCommonHeader = mock(CommonHeader.class);
+ private ActionIdentifiers mockAI = mock(ActionIdentifiers.class);
+ private Payload mockPayload = mock(Payload.class);
+
+ private VolumeService volumeServiceForAttachAction;
+ private VolumeService volumeServiceForDetachAction;
+
+ @Before
+ public void setUp() throws Exception {
+ volumeServiceForAttachAction = spy(new VolumeService(true));
+ volumeServiceForDetachAction = spy(new VolumeService(false));
+ }
+
+ @Test
+ public void testConstructor() throws Exception {
+ Action expectedAction = Action.AttachVolume;
+ Assert.assertEquals("Should have proper ACTION", expectedAction,
+ (Action) org.powermock.reflect.Whitebox.getInternalState(volumeServiceForAttachAction, "expectedAction"));
+ Assert.assertEquals("Should have attach-volume RPC name", "attach-volume",
+ (org.powermock.reflect.Whitebox.getInternalState(volumeServiceForAttachAction, "rpcName")).toString());
+
+ expectedAction = Action.DetachVolume;
+ Assert.assertEquals("Should have proper ACTION", expectedAction,
+ (Action) org.powermock.reflect.Whitebox.getInternalState(volumeServiceForDetachAction, "expectedAction"));
+ Assert.assertEquals("Should have detach-volume RPC name","detach-volume",
+ (org.powermock.reflect.Whitebox.getInternalState(volumeServiceForDetachAction, "rpcName")).toString());
+ }
+
+// @Test
+// public void testAttachVolume() throws Exception {
+// // test error occurs in validation
+// AttachVolumeOutputBuilder outputBuilder = volumeServiceForAttachAction.attachVolume(mockAttachInput);
+// Mockito.verify(volumeServiceForAttachAction, times(0)).proceedAction(any(), any(), any());
+// Assert.assertTrue("Should not have commonHeader as we did not mock it",
+// outputBuilder.getCommonHeader() == null);
+// Assert.assertEquals("should return missing parameter status",
+// Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()),
+// outputBuilder.getStatus().getCode());
+//
+// // make validation pass
+// Mockito.doReturn(mockCommonHeader).when(mockAttachInput).getCommonHeader();
+// Mockito.doReturn(mockPayload).when(mockAttachInput).getPayload();
+// Mockito.doReturn(PAYLOAD_STRING).when(mockPayload).getValue();
+//
+// ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z");
+// Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp();
+// Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+// Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+// Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+//
+// Mockito.doReturn(Action.AttachVolume).when(mockAttachInput).getAction();
+// Mockito.doReturn(mockAI).when(mockAttachInput).getActionIdentifiers();
+// Mockito.doReturn("vserverId").when(mockAI).getVserverId();
+
+ // test proceedAction return with error
+// outputBuilder = volumeServiceForAttachAction.attachVolume(mockAttachInput);
+// Mockito.verify(volumeServiceForAttachAction, times(1)).proceedAction(any(), any(), any());
+// Assert.assertTrue("Should have commonHeader",
+// outputBuilder.getCommonHeader() != null);
+// Assert.assertEquals("should return rejected status",
+// Integer.valueOf(LCMCommandStatus.REJECTED.getResponseCode()),
+// outputBuilder.getStatus().getCode());
+
+ // test proceedAction return without error
+// RequestExecutor mockExecutor = mock(RequestExecutor.class);
+// whenNew(RequestExecutor.class).withNoArguments().thenReturn(mockExecutor);
+//
+// RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class);
+// Mockito.doReturn(mockOutput).when(mockExecutor).executeRequest(any());
+//
+// ResponseContext mockResponseContext = mock(ResponseContext.class);
+// Mockito.doReturn(mockResponseContext).when(mockOutput).getResponseContext();
+//
+// org.onap.appc.domainmodel.lcm.Status mockStatus = mock(org.onap.appc.domainmodel.lcm.Status.class);
+// Integer successCode = Integer.valueOf(LCMCommandStatus.SUCCESS.getResponseCode());
+// Mockito.doReturn(successCode).when(mockStatus).getCode();
+// Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus();
+//
+// outputBuilder = volumeServiceForAttachAction.attachVolume(mockAttachInput);
+// Assert.assertTrue("Should have commonHeader",
+// outputBuilder.getCommonHeader() != null);
+// Assert.assertEquals("should return success status",
+// successCode, outputBuilder.getStatus().getCode());
+// }
+
+// @Test
+// public void testDetachVolumn() throws Exception {
+// // test error occurs in validation
+// DetachVolumeOutputBuilder outputBuilder = volumeServiceForDetachAction.detachVolume(mockDetachInput);
+// Mockito.verify(volumeServiceForDetachAction, times(0)).proceedAction(any(), any(), any());
+// Assert.assertTrue("Should not have commonHeader as we did not mock it",
+// outputBuilder.getCommonHeader() == null);
+// Assert.assertEquals("should return missing parameter status",
+// Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()),
+// outputBuilder.getStatus().getCode());
+//
+// // make validation pass
+// Mockito.doReturn(mockCommonHeader).when(mockDetachInput).getCommonHeader();
+// Mockito.doReturn(mockPayload).when(mockDetachInput).getPayload();
+// Mockito.doReturn(PAYLOAD_STRING).when(mockPayload).getValue();
+//
+// ZULU zuluTimeStamp = new ZULU("2017-06-29T21:44:00.35Z");
+// Mockito.doReturn(zuluTimeStamp).when(mockCommonHeader).getTimestamp();
+// Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+// Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+// Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+//
+// Mockito.doReturn(Action.DetachVolume).when(mockDetachInput).getAction();
+// Mockito.doReturn(mockAI).when(mockDetachInput).getActionIdentifiers();
+// Mockito.doReturn("vserverId").when(mockAI).getVserverId();
+
+ // test proceedAction return with error
+// outputBuilder = volumeServiceForDetachAction.detachVolume(mockDetachInput);
+// Mockito.verify(volumeServiceForDetachAction, times(1)).proceedAction(any(), any(), any());
+// Assert.assertTrue("Should have commonHeader",
+// outputBuilder.getCommonHeader() != null);
+// Assert.assertEquals("should return rejected status",
+// Integer.valueOf(LCMCommandStatus.REJECTED.getResponseCode()),
+// outputBuilder.getStatus().getCode());
+
+ // test proceedAction return without error
+// RequestExecutor mockExecutor = mock(RequestExecutor.class);
+// whenNew(RequestExecutor.class).withNoArguments().thenReturn(mockExecutor);
+//
+// RequestHandlerOutput mockOutput = mock(RequestHandlerOutput.class);
+// Mockito.doReturn(mockOutput).when(mockExecutor).executeRequest(any());
+//
+// ResponseContext mockResponseContext = mock(ResponseContext.class);
+// Mockito.doReturn(mockResponseContext).when(mockOutput).getResponseContext();
+//
+// org.onap.appc.domainmodel.lcm.Status mockStatus = mock(org.onap.appc.domainmodel.lcm.Status.class);
+// Integer successCode = Integer.valueOf(LCMCommandStatus.SUCCESS.getResponseCode());
+// Mockito.doReturn(successCode).when(mockStatus).getCode();
+// Mockito.doReturn(mockStatus).when(mockResponseContext).getStatus();;
+//
+// outputBuilder = volumeServiceForDetachAction.detachVolume(mockDetachInput);
+// Assert.assertTrue("Should have commonHeader",
+// outputBuilder.getCommonHeader() != null);
+// Assert.assertEquals("should return success status",
+// successCode, outputBuilder.getStatus().getCode());
+// }
+
+ @Test
+ public void testValidateForAttachAction() throws Exception {
+ // test commonHeader error
+ volumeServiceForAttachAction.validate(mockCommonHeader, Action.AttachVolume, mockAI, mockPayload);
+ Status status = (Status) Whitebox.getInternalState(volumeServiceForAttachAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+ Mockito.verify(volumeServiceForDetachAction, times(0)).buildStatusForParamName(any(), any());
+ Mockito.verify(volumeServiceForDetachAction, times(0)).buildStatusForErrorMsg(any(), any());
+
+ ZULU mockTimeStamp = mock(ZULU.class);
+ Mockito.doReturn(mockTimeStamp).when(mockCommonHeader).getTimestamp();
+ Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+ Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+ Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+
+ // test Invalid action
+ volumeServiceForAttachAction.validate(mockCommonHeader, Action.DetachVolume, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(volumeServiceForAttachAction, "status");
+ Assert.assertEquals("Should return invalid parameter for action",
+ Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode());
+
+ // test empty ActionIdentifier
+ volumeServiceForAttachAction.validate(mockCommonHeader, Action.AttachVolume, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(volumeServiceForAttachAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test empty VSERVER_ID
+ Mockito.doReturn("").when(mockAI).getVserverId();
+ volumeServiceForAttachAction.validate(mockCommonHeader, Action.AttachVolume, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(volumeServiceForAttachAction, "status");
+ Assert.assertEquals("should return invalid parameter",
+ Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode());
+
+ Mockito.doReturn("vserverId").when(mockAI).getVserverId();
+
+ // test null payload
+ volumeServiceForAttachAction.validate(mockCommonHeader, Action.AttachVolume, mockAI, null);
+ Mockito.verify(volumeServiceForAttachAction, times(1)).validateExcludedActIds(any(), any());
+ status = (Status) Whitebox.getInternalState(volumeServiceForAttachAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test empty payload
+ Mockito.doReturn("").when(mockPayload).getValue();
+ volumeServiceForAttachAction.validate(mockCommonHeader, Action.AttachVolume, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(volumeServiceForAttachAction, "status");
+ Assert.assertEquals("should return invalid parameter",
+ Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode());
+
+ // test space payload
+ Mockito.doReturn(" ").when(mockPayload).getValue();
+ volumeServiceForAttachAction.validate(mockCommonHeader, Action.AttachVolume, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(volumeServiceForAttachAction, "status");
+ Assert.assertEquals("should return invalid parameter",
+ Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode());
+ }
+
+ @Test
+ public void testValidateForDetachAction() throws Exception {
+ // test commonHeader error
+ volumeServiceForDetachAction.validate(mockCommonHeader, Action.DetachVolume, mockAI, mockPayload);
+ Status status = (Status) Whitebox.getInternalState(volumeServiceForDetachAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+ Mockito.verify(volumeServiceForDetachAction, times(0)).buildStatusForParamName(any(), any());
+ Mockito.verify(volumeServiceForDetachAction, times(0)).buildStatusForErrorMsg(any(), any());
+
+ ZULU mockTimeStamp = mock(ZULU.class);
+ Mockito.doReturn(mockTimeStamp).when(mockCommonHeader).getTimestamp();
+ Mockito.doReturn("api ver").when(mockCommonHeader).getApiVer();
+ Mockito.doReturn("orignator Id").when(mockCommonHeader).getOriginatorId();
+ Mockito.doReturn("request Id").when(mockCommonHeader).getRequestId();
+
+ // test Invalid action
+ volumeServiceForDetachAction.validate(mockCommonHeader, Action.AttachVolume, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(volumeServiceForDetachAction, "status");
+ Assert.assertEquals("Should return invalid parameter for action",
+ Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode());
+
+ // test empty ActionIdentifier
+ volumeServiceForDetachAction.validate(mockCommonHeader, Action.DetachVolume, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(volumeServiceForDetachAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test empty VSERVER_ID
+ Mockito.doReturn("").when(mockAI).getVserverId();
+ volumeServiceForDetachAction.validate(mockCommonHeader, Action.DetachVolume, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(volumeServiceForDetachAction, "status");
+ Assert.assertEquals("should return invalid parameter",
+ Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode());
+
+ Mockito.doReturn("vserverId").when(mockAI).getVserverId();
+
+ // test null payload
+ volumeServiceForDetachAction.validate(mockCommonHeader, Action.DetachVolume, mockAI, null);
+ Mockito.verify(volumeServiceForDetachAction, times(1)).validateExcludedActIds(any(), any());
+ status = (Status) Whitebox.getInternalState(volumeServiceForDetachAction, "status");
+ Assert.assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // test empty payload
+ Mockito.doReturn("").when(mockPayload).getValue();
+ volumeServiceForDetachAction.validate(mockCommonHeader, Action.DetachVolume, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(volumeServiceForDetachAction, "status");
+ Assert.assertEquals("should return invalid parameter",
+ Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode());
+
+ // test space payload
+ Mockito.doReturn(" ").when(mockPayload).getValue();
+ volumeServiceForDetachAction.validate(mockCommonHeader, Action.DetachVolume, mockAI, mockPayload);
+ status = (Status) Whitebox.getInternalState(volumeServiceForDetachAction, "status");
+ Assert.assertEquals("should return invalid parameter",
+ Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode());
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/util/ValidationServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/util/ValidationServiceTest.java
new file mode 100644
index 000000000..ed2adf3de
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/util/ValidationServiceTest.java
@@ -0,0 +1,89 @@
+/*-
+ * ============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.util;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ZULU;
+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 static org.mockito.Mockito.mock;
+
+public class ValidationServiceTest {
+ private final Integer expectedErrorCode = Integer.valueOf(
+ LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode());
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @Test
+ public void getInstance() throws Exception {
+ Assert.assertEquals("Should always return the same instance",
+ ValidationService.getInstance(), ValidationService.getInstance());
+ }
+
+ @Test
+ public void validateInput() throws Exception {
+ Status status = ValidationService.getInstance().validateInput(null, null, null);
+ Assert.assertEquals("Should return error status", expectedErrorCode, status.getCode());
+ Assert.assertTrue("Should include common-header in the message",
+ status.getMessage().contains("common-header"));
+ Assert.assertTrue("Should include action in the message",
+ status.getMessage().contains("action"));
+
+ CommonHeader mockCommonHeader = mock(CommonHeader.class);
+ status = ValidationService.getInstance().validateInput(mockCommonHeader, Action.Query, "query");
+ Assert.assertEquals("Should return error status", expectedErrorCode, status.getCode());
+ Assert.assertFalse("Should not include action in the message",
+ status.getMessage().contains("action"));
+
+ Mockito.when(mockCommonHeader.getApiVer()).thenReturn("testing API version");
+ status = ValidationService.getInstance().validateInput(mockCommonHeader, Action.Query, "query");
+ Assert.assertEquals("Should return error status", expectedErrorCode, status.getCode());
+ Assert.assertFalse("Should not include api-ver in the message",
+ status.getMessage().contains("api-ver"));
+
+ Mockito.when(mockCommonHeader.getOriginatorId()).thenReturn("testing originator id");
+ status = ValidationService.getInstance().validateInput(mockCommonHeader, Action.Query, "query");
+ Assert.assertEquals("Should return error status", expectedErrorCode, status.getCode());
+ Assert.assertFalse("Should not include originator-id in the message",
+ status.getMessage().contains("originator-id"));
+
+ Mockito.when(mockCommonHeader.getRequestId()).thenReturn("testing request id");
+ status = ValidationService.getInstance().validateInput(mockCommonHeader, Action.Query, "query");
+ Assert.assertEquals("Should return error status", expectedErrorCode, status.getCode());
+ Assert.assertFalse("Should not include request-id in the message",
+ status.getMessage().contains("request-id"));
+
+ Mockito.when(mockCommonHeader.getTimestamp()).thenReturn(mock(ZULU.class));
+ status = ValidationService.getInstance().validateInput(mockCommonHeader, Action.Query, "query");
+ Assert.assertTrue("Should return success", status == null);
+ }
+}