From 2b284f1d97a2c97a92e7d32f47b46fcb50bae06b Mon Sep 17 00:00:00 2001 From: osinstom Date: Fri, 8 Mar 2019 13:30:28 +0100 Subject: Adding DistributeTrafficCheck LCM API Issue-ID: APPC-1444 Change-Id: I26163c216184eb49daeea01cbb54f0b9803e1f95 Signed-off-by: Tomek Osinski --- .../org/onap/appc/provider/AppcProviderLcm.java | 12 ++- .../lcm/service/DistributeTrafficCheckService.java | 104 +++++++++++++++++++++ 2 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/DistributeTrafficCheckService.java (limited to 'appc-provider/appc-provider-bundle/src/main/java/org') 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; @@ -500,6 +501,15 @@ public class AppcProviderLcm extends AbstractBaseUtils implements AutoCloseable, return Futures.immediateFuture(result); } + @Override + public ListenableFuture> distributeTrafficCheck(DistributeTrafficCheckInput input) { + logger.debug(String.format("LCM DistributeTrafficCheck, received input: %s", input.toString())); + DistributeTrafficCheckOutputBuilder outputBuilder = new DistributeTrafficCheckService().process(input); + RpcResult result = + RpcResultBuilder.status(true).withResult(outputBuilder.build()).build(); + return Futures.immediateFuture(result); + } + @Override public ListenableFuture> upgradePreCheck(UpgradePreCheckInput input) { logger.debug(String.format("LCM upgradeprecheck received input: %s", input.toString())); 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); + } + } + + +} -- cgit 1.2.3-korg