diff options
author | Tomek Osinski <tomasz.osinski2@orange.com> | 2018-09-12 15:10:08 +0200 |
---|---|---|
committer | Takamune Cho <tc012c@att.com> | 2018-09-17 20:16:32 +0000 |
commit | 3c0def26b386b2bc48ec7b6c0f53064bd270ce63 (patch) | |
tree | 6adbae9ba6fd9771991ffc30a5d6b040b88e312a /appc-provider/appc-provider-bundle/src/main | |
parent | d90ba5c3b7237131a47ad835ab19f42110166a73 (diff) |
Adding DistributeTraffic LCM API
This commit contains code modifications for APPC to support DistributeTraffic LCM API. Tests has been implemented for new service.
Change-Id: I853120eced93928268074cf89dd62fb89fea9ff8
Issue-ID: APPC-1169
Signed-off-by: Tomek Osinski <tomasz.osinski2@orange.com>
Diffstat (limited to 'appc-provider/appc-provider-bundle/src/main')
2 files changed, 126 insertions, 0 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 410a9ea1c..ff1195127 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 @@ -5,6 +5,8 @@ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications Copyright (C) 2018 Orange * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,6 +45,7 @@ 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.service.DistributeTrafficService; import org.onap.appc.provider.lcm.util.RequestInputBuilder; import org.onap.appc.provider.lcm.util.ValidationService; import org.onap.appc.requesthandler.objects.RequestHandlerInput; @@ -488,6 +491,15 @@ public class AppcProviderLcm extends AbstractBaseUtils implements AutoCloseable, } @Override + public Future<RpcResult<DistributeTrafficOutput>> distributeTraffic(DistributeTrafficInput input) { + logger.debug(String.format("LCM DistributeTraffic, received input: %s", input.toString())); + DistributeTrafficOutputBuilder outputBuilder = new DistributeTrafficService().process(input); + RpcResult<DistributeTrafficOutput> result = + RpcResultBuilder.<DistributeTrafficOutput>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); diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/DistributeTrafficService.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/DistributeTrafficService.java new file mode 100644 index 000000000..367135265 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/DistributeTrafficService.java @@ -0,0 +1,114 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2018 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.DistributeTrafficInput; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.DistributeTrafficOutputBuilder; + +import java.io.IOException; +import java.util.Map; + +/** + * Provide LCM command service for Distribute Traffic between VNFs. + */ +public class DistributeTrafficService extends AbstractBaseService { + + + private static final String CONFIG_FILE_NAME_PARAMETER = "ConfigFileName"; + private static final String PAYLOAD = "payload"; + + /** + * Constructor + */ + public DistributeTrafficService() { + super(Action.DistributeTraffic); + logger.debug("DistributeTrafficService starts"); + } + + /** + * Process a DistributeTraffic request + * @param input of DistributeTrafficInput from the REST API input + * @return DistributeTrafficOutputBuilder which has the process results + */ + public DistributeTrafficOutputBuilder process(DistributeTrafficInput input) { + + validate(input); + if (status == null) { + proceedAction(input); + } + + DistributeTrafficOutputBuilder outputBuilder = new DistributeTrafficOutputBuilder(); + outputBuilder.setStatus(status); + outputBuilder.setCommonHeader(input.getCommonHeader()); + return outputBuilder; + } + + /** + * Validate input. + * Set Status if any error detected. + * + * @param input of DistributeTrafficInput from the REST API input + */ + void validate(DistributeTrafficInput 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; + } + + try { + Map<String, String> payloadMap = JsonUtil.convertJsonStringToFlatMap(payloadString); + // ConfigFileName validation + final String configFileName = payloadMap.get(CONFIG_FILE_NAME_PARAMETER); + if (configFileName == null) { + status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, CONFIG_FILE_NAME_PARAMETER); + } + + } catch(IOException e) { + logger.error(String.format("DistributeTrafficService (%s) got IOException when converting payload", rpcName), e); + status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, e.getMessage()); + } + } + + void proceedAction(DistributeTrafficInput input) { + RequestHandlerInput requestHandlerInput = getRequestHandlerInput( + input.getCommonHeader(), input.getActionIdentifiers(), input.getPayload(), this.getClass().getName()); + if (requestHandlerInput != null) { + executeAction(requestHandlerInput); + } + } + +} |