summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorosinstom <osinstom@gmail.com>2019-03-08 13:30:28 +0100
committerTakamune Cho <takamune.cho@att.com>2019-03-13 21:02:03 +0000
commit2b284f1d97a2c97a92e7d32f47b46fcb50bae06b (patch)
tree29560dd9e87ea30218dc8f30739f055e059292dd
parent651430451d2134d14daab15ebae29eccc878b52b (diff)
Adding DistributeTrafficCheck LCM API
Issue-ID: APPC-1444 Change-Id: I26163c216184eb49daeea01cbb54f0b9803e1f95 Signed-off-by: Tomek Osinski <tomasz.osinski2@orange.com>
-rw-r--r--appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/main/java/org/onap/appc/domainmodel/lcm/VNFOperation.java3
-rw-r--r--appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/conv/Converter.java7
-rw-r--r--appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/ConverterTest.java18
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderLcm.java12
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/DistributeTrafficCheckService.java104
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/AppcProviderLcmTest.java10
-rw-r--r--appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/DistributeTrafficCheckServiceTest.java169
-rw-r--r--appc-provider/appc-provider-model/src/main/yang/appc-provider-lcm.yang26
8 files changed, 341 insertions, 8 deletions
diff --git a/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/main/java/org/onap/appc/domainmodel/lcm/VNFOperation.java b/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/main/java/org/onap/appc/domainmodel/lcm/VNFOperation.java
index edf9a4541..e08e49630 100644
--- a/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/main/java/org/onap/appc/domainmodel/lcm/VNFOperation.java
+++ b/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/main/java/org/onap/appc/domainmodel/lcm/VNFOperation.java
@@ -6,7 +6,7 @@
* ================================================================================
* Copyright (C) 2017 Amdocs
* ================================================================================
- * Modifications Copyright (C) 2018 Orange
+ * Modifications Copyright (C) 2018-2019 Orange
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,6 +48,7 @@ public enum VNFOperation {
QuiesceTraffic,
ResumeTraffic,
DistributeTraffic,
+ DistributeTrafficCheck,
Reboot,
Rebuild,
Restart,
diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/conv/Converter.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/conv/Converter.java
index 2bfc912f1..260f8695f 100644
--- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/conv/Converter.java
+++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/conv/Converter.java
@@ -6,7 +6,7 @@
* ================================================================================
* Copyright (C) 2017 Amdocs
* ================================================================================
- * Modifications Copyright (C) 2018 Orange
+ * Modifications Copyright (C) 2018-2019 Orange
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -285,6 +285,11 @@ public class Converter {
((DistributeTrafficOutputBuilder)outObj).setCommonHeader(commonHeader);
((DistributeTrafficOutputBuilder)outObj).setStatus(status);
return outObj;
+ case DistributeTrafficCheck:
+ outObj = new DistributeTrafficCheckOutputBuilder();
+ ((DistributeTrafficCheckOutputBuilder) outObj).setCommonHeader(commonHeader);
+ ((DistributeTrafficCheckOutputBuilder)outObj).setStatus(status);
+ return outObj;
default:
throw new IllegalArgumentException(action+" action is not supported");
}
diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/ConverterTest.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/ConverterTest.java
index 46a367a88..0bfd4d6ad 100644
--- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/ConverterTest.java
+++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/test/java/org/onap/appc/requesthandler/ConverterTest.java
@@ -6,7 +6,7 @@
* ================================================================================
* Copyright (C) 2017 Amdocs
* ================================================================================
- * Modifications Copyright (C) 2018 Orange
+ * Modifications Copyright (C) 2018-2019 Orange
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -60,7 +60,9 @@ public class ConverterTest {
private String expectedJsonBodyStrwithPayload ="{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"payload\":\"{}\",\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}}";
private String expectedDmaapOutgoingMessageJsonStringReboot ="{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"reboot\",\"type\":\"response\"}";
- private String expectedDmaapOutgoingMessageJsonStringDistributeTraffc = "{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"distribute-traffic\",\"type\":\"response\"}";
+ private String expectedDmaapOutgoingMessageJsonStringDistributeTraffic = "{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"distribute-traffic\",\"type\":\"response\"}";
+ private String expectedDmaapOutgoingMessageJsonStringDistributeTrafficCheck = "{\"body\":{\"output\":{\"common-header\":{\"api-ver\":\"2.0.0\",\"flags\":{},\"originator-id\":\"oid\",\"request-id\":\"reqid\",\"timestamp\":\"1970-01-01T00:00:01.000Z\"},\"status\":{\"code\":400,\"message\":\"SUCCESS - request has been processed successfully\"}}},\"cambria.partition\":\"MSO\",\"correlation-id\":\"reqid\",\"rpc-name\":\"distribute-traffic-check\",\"type\":\"response\"}";
+
@Test
public void convDateToZuluStringTest(){
@@ -392,6 +394,7 @@ public class ConverterTest {
System.out.println("jsonStr = " + jsonStr);
Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringUpgradeSoftware,jsonStr);
}
+
@Test
public void convAsyncResponseToBuilderUpgradeBackoutTest() throws JsonProcessingException {
ResponseContext asyncResponse = buildAsyncResponse();
@@ -445,7 +448,16 @@ public class ConverterTest {
String rpcName = convertActionNameToUrl(action.name());
String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
System.out.println("jsonStr = " + jsonStr);
- Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringDistributeTraffc,jsonStr);
+ Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringDistributeTraffic,jsonStr);
+ }
+
+ @Test
+ public void convAsyncResponseToDmaapOutgoingMessageJsonStringDistributeTrafficCheckTest() throws JsonProcessingException {
+ ResponseContext asyncResponse = buildAsyncResponse();
+ VNFOperation action = VNFOperation.DistributeTrafficCheck;
+ String rpcName = convertActionNameToUrl(action.name());
+ String jsonStr = Converter.convAsyncResponseToDmaapOutgoingMessageJsonString(action, rpcName, asyncResponse);
+ Assert.assertEquals(expectedDmaapOutgoingMessageJsonStringDistributeTrafficCheck,jsonStr);
}
/*@Test
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 b6641953c..f486dcc61 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
@@ -6,7 +6,7 @@
* ================================================================================
* Copyright (C) 2017 Amdocs
* ================================================================================
- * Modifications Copyright (C) 2018 Orange
+ * Modifications Copyright (C) 2018-2019 Orange
* ================================================================================
* Modifications Copyright (C) 2019 Ericsson
* =============================================================================
@@ -47,6 +47,7 @@ import org.onap.appc.provider.lcm.service.UpgradeService;
import org.onap.appc.provider.lcm.service.VolumeService;
import org.onap.appc.provider.lcm.service.ConfigScaleOutService;
import org.onap.appc.provider.lcm.service.DistributeTrafficService;
+import org.onap.appc.provider.lcm.service.DistributeTrafficCheckService;
import org.onap.appc.provider.lcm.util.RequestInputBuilder;
import org.onap.appc.provider.lcm.util.ValidationService;
import org.onap.appc.requesthandler.objects.RequestHandlerInput;
@@ -501,6 +502,15 @@ public class AppcProviderLcm extends AbstractBaseUtils implements AutoCloseable,
}
@Override
+ public ListenableFuture<RpcResult<DistributeTrafficCheckOutput>> distributeTrafficCheck(DistributeTrafficCheckInput input) {
+ logger.debug(String.format("LCM DistributeTrafficCheck, received input: %s", input.toString()));
+ DistributeTrafficCheckOutputBuilder outputBuilder = new DistributeTrafficCheckService().process(input);
+ RpcResult<DistributeTrafficCheckOutput> result =
+ RpcResultBuilder.<DistributeTrafficCheckOutput>status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+ @Override
public ListenableFuture<RpcResult<UpgradePreCheckOutput>> upgradePreCheck(UpgradePreCheckInput input) {
logger.debug(String.format("LCM upgradeprecheck received input: %s", input.toString()));
UpgradePreCheckOutputBuilder outputBuilder = new UpgradeService("upgradePre").upgradePreCheck(input);
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/DistributeTrafficCheckService.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/DistributeTrafficCheckService.java
new file mode 100644
index 000000000..893c058ae
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/DistributeTrafficCheckService.java
@@ -0,0 +1,104 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 Orange
+ * =============================================================================
+ * 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.
+ *
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.service;
+
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+import org.onap.appc.util.JsonUtil;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.DistributeTrafficCheckInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.DistributeTrafficCheckOutputBuilder;
+
+import java.io.IOException;
+import java.util.Map;
+
+
+/**
+ * Provide LCM command service to check conditions and the result of DistributeTraffic.
+ */
+public class DistributeTrafficCheckService extends AbstractBaseService {
+
+ private static final String PAYLOAD = "payload";
+
+ /**
+ * Constructor.
+ */
+ public DistributeTrafficCheckService() {
+ super(Action.DistributeTrafficCheck);
+ logger.debug("DistributeTrafficCheckService starts");
+ }
+
+ /**
+ * Process the DistributeTrafficCheck request
+ * @param input of DistributeTrafficCheckInput from the REST API input
+ * @return DistributeTrafficCheckOutputBuilder which has the process results
+ */
+ public DistributeTrafficCheckOutputBuilder process(DistributeTrafficCheckInput input) {
+
+ validate(input);
+ if (status == null) {
+ proceedAction(input);
+ }
+
+ DistributeTrafficCheckOutputBuilder outputBuilder = new DistributeTrafficCheckOutputBuilder();
+ outputBuilder.setStatus(status);
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ return outputBuilder;
+
+ }
+
+ /**
+ * Validate input.
+ * Set status if any error detected. Otherwise, status == null.
+ * @param input of DistributeTrafficCheckInput from the REST API input
+ */
+ void validate(DistributeTrafficCheckInput input) {
+ status = validateVnfId(input.getCommonHeader(), input.getAction(), input.getActionIdentifiers());
+ if (status != null) {
+ return;
+ }
+
+ if (input.getPayload() == null) {
+ status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, PAYLOAD);
+ return;
+ }
+ String payloadString = input.getPayload().getValue();
+ status = validateMustHaveParamValue(payloadString == null ? payloadString : payloadString.trim(), PAYLOAD);
+ if (status != null) {
+ return;
+ }
+ }
+
+ /**
+ * Execute the distribute-traffic-check action.
+ * @param input of DistributeTrafficCheckInput from the REST API input
+ */
+ void proceedAction(DistributeTrafficCheckInput input) {
+ RequestHandlerInput requestHandlerInput = getRequestHandlerInput(
+ input.getCommonHeader(), input.getActionIdentifiers(), input.getPayload(), this.getClass().getName());
+ if (requestHandlerInput != null) {
+ executeAction(requestHandlerInput);
+ }
+ }
+
+
+}
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 f59c9e09e..c68503136 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
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2018-2019 Ericsson
* ================================================================================
+ * Modifications Copyright (C) 2019 Orange
+ * ================================================================================
* 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
@@ -52,6 +54,7 @@ import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigScaleOutIn
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigureInput;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.DetachVolumeInput;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.DistributeTrafficInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.DistributeTrafficCheckInput;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.EvacuateInput;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.HealthCheckInput;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.LiveUpgradeInput;
@@ -315,6 +318,13 @@ public class AppcProviderLcmTest {
}
@Test
+ public void distributeTrafficCheckTest() {
+ DistributeTrafficCheckInput distributeTrafficCheckInput = mock(DistributeTrafficCheckInput.class);
+ Mockito.doReturn(Action.DistributeTrafficCheck).when(distributeTrafficCheckInput).getAction();
+ assertTrue(underTest.distributeTrafficCheck(distributeTrafficCheckInput).isDone());
+ }
+
+ @Test
public void upgradePreCheckInputTest() {
UpgradePreCheckInput upgradePreCheckInput = mock(UpgradePreCheckInput.class);
Mockito.doReturn(Action.UpgradePreCheck).when(upgradePreCheckInput).getAction();
diff --git a/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/DistributeTrafficCheckServiceTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/DistributeTrafficCheckServiceTest.java
new file mode 100644
index 000000000..6fd71720f
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/lcm/service/DistributeTrafficCheckServiceTest.java
@@ -0,0 +1,169 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 Orange
+ * =============================================================================
+ * 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.
+ *
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.service;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.appc.domainmodel.lcm.ResponseContext;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+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.powermock.reflect.Whitebox;
+
+import static org.junit.Assert.*;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.*;
+import static org.powermock.api.mockito.PowerMockito.whenNew;
+
+@RunWith(MockitoJUnitRunner.class)
+public class DistributeTrafficCheckServiceTest {
+
+ private static final Action myAction = Action.DistributeTrafficCheck;
+ private static final String rpcName = "distribute-traffic-check";
+ private static final String PAYLOAD_STRING = "{\"test\":\"test\"}";
+
+ private final DistributeTrafficCheckInput mockInput = mock(DistributeTrafficCheckInput.class);
+ private final CommonHeader mockCommonHeader = mock(CommonHeader.class);
+ private final ActionIdentifiers mockActionIdentifiers = mock(ActionIdentifiers.class);
+ private final Payload mockPayload = mock(Payload.class);
+
+ private DistributeTrafficCheckService distributeTrafficCheckService;
+
+ @Before
+ public void setUp() throws Exception {
+ distributeTrafficCheckService = spy(new DistributeTrafficCheckService());
+ }
+
+ @Test
+ public void testConstructor() throws Exception {
+ assertEquals("Should have proper ACTION", myAction,
+ (Action) Whitebox.getInternalState(distributeTrafficCheckService, "expectedAction"));
+ assertEquals("Should have action-status RPC name", rpcName,
+ Whitebox.getInternalState(distributeTrafficCheckService, "rpcName").toString());
+ }
+
+ private void helpInitializeRequestParameters() {
+ Mockito.doReturn(mockCommonHeader).when(mockInput).getCommonHeader();
+ Mockito.doReturn(mockPayload).when(mockInput).getPayload();
+ Mockito.doReturn(myAction).when(mockInput).getAction();
+ Mockito.doReturn(mockActionIdentifiers).when(mockInput).getActionIdentifiers();
+ 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("vnfId").when(mockActionIdentifiers).getVnfId();
+ }
+
+ @Test
+ public void testProcess() throws Exception {
+ helpInitializeRequestParameters();
+
+ // 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();
+
+ Mockito.when(distributeTrafficCheckService.executeAction(any())).thenReturn(mockOutput);
+
+ DistributeTrafficCheckOutputBuilder outputBuilder = distributeTrafficCheckService.process(mockInput);
+
+ Mockito.verify(distributeTrafficCheckService, times(1)).proceedAction(mockInput);
+
+ assertNotNull("Should have commonHeader", outputBuilder.getCommonHeader());
+ }
+
+ @Test
+ public void testValidateMissingParameters() throws Exception {
+ DistributeTrafficCheckOutputBuilder outputBuilder = distributeTrafficCheckService.process(mockInput);
+ Mockito.verify(distributeTrafficCheckService, times(0)).proceedAction(any());
+ assertNull("Should not have commonHeader as we did not mock it", outputBuilder.getCommonHeader());
+ assertEquals("should return missing parameter status",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()),
+ outputBuilder.getStatus().getCode());
+ }
+
+ @Test
+ public void testValidateForMissingOrInvalidAction() throws Exception {
+ helpInitializeRequestParameters();
+
+ // check missing Action
+ Mockito.doReturn(null).when(mockInput).getAction();
+
+ distributeTrafficCheckService.validate(mockInput);
+ Status status = (Status) Whitebox.getInternalState(distributeTrafficCheckService, "status");
+ assertEquals("Should return missing parameter for action",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ // check invalid Action
+ Mockito.doReturn(Action.Migrate).when(mockInput).getAction();
+ distributeTrafficCheckService.validate(mockInput);
+ status = (Status) Whitebox.getInternalState(distributeTrafficCheckService, "status");
+ assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode());
+ }
+
+ @Test
+ public void testValidateForMissingActionIdentifiers() throws Exception {
+ helpInitializeRequestParameters();
+ Mockito.doReturn(null).when(mockInput).getActionIdentifiers();
+
+ // test missing ActionIdentifiers
+ distributeTrafficCheckService.validate(mockInput);
+ Status status = (Status) Whitebox.getInternalState(distributeTrafficCheckService, "status");
+ assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+ }
+
+ @Test
+ public void testValidateEmptyOrMissingPayload() throws Exception {
+ helpInitializeRequestParameters();
+
+ // validate empty payload
+ Mockito.doReturn("").when(mockPayload).getValue();
+ distributeTrafficCheckService.validate(mockInput);
+ Status status = (Status) Whitebox.getInternalState(distributeTrafficCheckService, "status");
+ assertEquals("should return invalid parameter",
+ Integer.valueOf(LCMCommandStatus.INVALID_INPUT_PARAMETER.getResponseCode()), status.getCode());
+
+ // validate missing payload
+ Mockito.doReturn(null).when(mockInput).getPayload();
+ distributeTrafficCheckService.validate(mockInput);
+ status = (Status) Whitebox.getInternalState(distributeTrafficCheckService, "status");
+ assertEquals("should return missing parameter",
+ Integer.valueOf(LCMCommandStatus.MISSING_MANDATORY_PARAMETER.getResponseCode()), status.getCode());
+
+ }
+
+}
diff --git a/appc-provider/appc-provider-model/src/main/yang/appc-provider-lcm.yang b/appc-provider/appc-provider-model/src/main/yang/appc-provider-lcm.yang
index 2e369fae3..2b8521a61 100644
--- a/appc-provider/appc-provider-model/src/main/yang/appc-provider-lcm.yang
+++ b/appc-provider/appc-provider-model/src/main/yang/appc-provider-lcm.yang
@@ -6,7 +6,7 @@
* ================================================================================
* Copyright (C) 2017 Amdocs
* ================================================================================
- * Modifications Copyright (C) 2018 Orange
+ * Modifications Copyright (C) 2018-2019 Orange
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -124,7 +124,7 @@ module appc-provider-lcm {
enum "AttachVolume";
enum "DetachVolume";
enum "DistributeTraffic";
-
+ enum "DistributeTrafficCheck";
}
description "The action to be taken by APP-C, e.g. Restart, Rebuild, Migrate";
}
@@ -1340,6 +1340,28 @@ module appc-provider-lcm {
}
}
+ /**********************************************************************************
+ * Define the distribute traffic check service
+ **********************************************************************************/
+ rpc distribute-traffic-check {
+ description "An operation to check conditions and the result of DistributeTraffic.";
+ input {
+ uses common-header;
+ leaf action {
+ type action;
+ mandatory true;
+ }
+ uses action-identifiers;
+ leaf payload {
+ type payload;
+ mandatory true;
+ }
+ }
+ output {
+ uses common-header;
+ uses status;
+ }
+ }
/**********************************************************************************