diff options
author | vidhyasree <sn141y@att.com> | 2018-02-21 11:19:33 -0500 |
---|---|---|
committer | Patrick Brady <pb071s@att.com> | 2018-02-22 18:04:35 +0000 |
commit | 6cf060d13e4a06894db3050ed23e4e7667fb021f (patch) | |
tree | 078a7e8980cf73c23402f0637a93ab6ae2d90c1c /appc-provider/appc-provider-bundle | |
parent | 446bae37c2f6dabe842cb2b6585a17bcec327a17 (diff) |
Task to add ConfigScaleOut to LCM API, Yang Model.
A new action ConfigScaleOut is added to LCM API and Yang model.
Removed old action item configscaleout supporting VM action level
which is no longer needed.
Issue-ID: APPC-479
Change-Id: Ie5452f4d5625fc3be6b66c0f403d12baa64fa096
Signed-off-by: vidhyasree <sn141y@att.com>
Diffstat (limited to 'appc-provider/appc-provider-bundle')
3 files changed, 112 insertions, 65 deletions
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 7901c6d83..a66aaaa7c 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ============================================================================= @@ -43,6 +43,7 @@ import org.onap.appc.provider.lcm.service.RequestExecutor; import org.onap.appc.provider.lcm.service.ResumeTrafficService; 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.util.RequestInputBuilder; import org.onap.appc.provider.lcm.util.ValidationService; import org.onap.appc.requesthandler.objects.RequestHandlerInput; @@ -643,35 +644,10 @@ public class AppcProviderLcm extends AbstractBaseUtils implements AutoCloseable, } @Override - public Future<RpcResult<ConfigScaleoutOutput>> configScaleout(ConfigScaleoutInput input) { + public Future<RpcResult<ConfigScaleOutOutput>> configScaleOut(ConfigScaleOutInput input) { logger.debug("Input received : " + input.toString()); - ConfigScaleoutOutputBuilder outputBuilder = new ConfigScaleoutOutputBuilder(); - 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(); - 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<ConfigScaleoutOutput> result = - RpcResultBuilder.<ConfigScaleoutOutput>status(true).withResult(outputBuilder.build()).build(); + ConfigScaleOutOutputBuilder outputBuilder = new ConfigScaleOutService().process(input); + RpcResult<ConfigScaleOutOutput> result = RpcResultBuilder.<ConfigScaleOutOutput> status(true).withResult(outputBuilder.build()).build(); return Futures.immediateFuture(result); } diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/ConfigScaleOutService.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/ConfigScaleOutService.java new file mode 100644 index 000000000..a61abf326 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/ConfigScaleOutService.java @@ -0,0 +1,106 @@ + +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ============================================================================= + * 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.ConfigScaleOutInput; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigScaleOutOutputBuilder; +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; + +public class ConfigScaleOutService extends AbstractBaseService { + /** + * Constructor + * + */ + public ConfigScaleOutService() { + super(Action.ConfigScaleOut); + logger.debug("ConfigScaleOutService starts"); + } + public ConfigScaleOutOutputBuilder process(ConfigScaleOutInput 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); + } + + ConfigScaleOutOutputBuilder outputBuilder = new ConfigScaleOutOutputBuilder(); + 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("ConfigScaleOutService (%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/test/java/org/onap/appc/provider/AppcProviderLcmTest.java b/appc-provider/appc-provider-bundle/src/test/java/org/onap/appc/provider/AppcProviderLcmTest.java index 064f5679f..1d0594837 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ============================================================================= @@ -53,8 +53,6 @@ import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigModifyInpu import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigModifyOutput; import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigRestoreInput; import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigRestoreOutput; -import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigScaleoutInput; -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; @@ -596,39 +594,6 @@ public class AppcProviderLcmTest extends AbstractDataBrokerTest { } @Test - public void testConfigScaleout() throws Exception { - // Validation success - doReturn("Success").when(successlcmStatus).getMessage(); - doReturn(responseContext).when(requestHandlerOutput).getResponseContext(); - doReturn(requestHandlerOutput).when(appcProviderLcm).executeRequest(any()); - doReturn(null).when(validationService).validateInput(any(), any(), any()); - - ConfigScaleoutInput configScaleoutInput = mock(ConfigScaleoutInput.class); - doReturn(newCommonHeader("request-id-test")).when(configScaleoutInput).getCommonHeader(); - doReturn(newActionIdentifier("vnf-id", "vnfc-id", "vserver-id")) - .when(configScaleoutInput).getActionIdentifiers(); - - Future<RpcResult<ConfigScaleoutOutput>> results = appcProviderLcm.configScaleout(configScaleoutInput); - Assert.assertTrue(400 == results.get().getResult().getStatus().getCode()); - Assert.assertEquals("Success", results.get().getResult().getStatus().getMessage()); - verify(appcProviderLcm, times(1)).executeRequest(any()); - - // Validation failed - doReturn(failStatus).when(validationService).validateInput(any(), any(), any()); - results = appcProviderLcm.configScaleout(configScaleoutInput); - Assert.assertEquals(failStatus, results.get().getResult().getStatus()); - verify(appcProviderLcm, times(1)).executeRequest(any()); - - // parse exception - doReturn(null).when(validationService).validateInput(any(), any(), any()); - doReturn(null).when(configScaleoutInput).getActionIdentifiers(); - results = appcProviderLcm.configScaleout(configScaleoutInput); - Assert.assertTrue(LCMCommandStatus.REQUEST_PARSING_FAILED.getResponseCode() - == results.get().getResult().getStatus().getCode()); - verify(appcProviderLcm, times(1)).executeRequest(any()); - } - - @Test public void testConfigRestore() throws Exception { // Validation success doReturn("Success").when(successlcmStatus).getMessage(); |