diff options
author | 2020-02-01 21:35:09 +0800 | |
---|---|---|
committer | 2020-02-12 20:08:19 +0000 | |
commit | b0577ce19923aad530dde0363bd8cfe819f75970 (patch) | |
tree | d007a390c44eb806488ac9b749b0e5ce0679746a /appc-provider/appc-provider-bundle/src/main | |
parent | 4828efc8a51ed70ea4813038bd9535f3b1764a51 (diff) |
Add new LCM actions DownloadNESw and ActivateNESw, etc
1. Add LCM actions DownloadNESw and ActivateNESw;
2. Add payload field in the output of Rollback action.
Issue-ID: APPC-1811
Change-Id: I2e05522909a45d03927035fe35e9168751b5de0d
Signed-off-by: Enbo Wang <wangenbo@huawei.com>
Diffstat (limited to 'appc-provider/appc-provider-bundle/src/main')
4 files changed, 260 insertions, 2 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 dc81f7e71..4aad66899 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 @@ -62,6 +62,8 @@ import org.onap.appc.provider.lcm.service.StartTraffic; import org.onap.appc.provider.lcm.service.StatusTraffic; import org.onap.appc.provider.lcm.service.StopTraffic; import org.onap.appc.provider.lcm.service.ConfigScaleInService; +import org.onap.appc.provider.lcm.service.DownloadNESw; +import org.onap.appc.provider.lcm.service.ActivateNESw; import org.onap.appc.provider.lcm.util.RequestInputBuilder; import org.onap.appc.provider.lcm.util.ValidationService; import org.onap.appc.requesthandler.objects.RequestHandlerInput; @@ -660,6 +662,24 @@ public class AppcProviderLcm extends AbstractBaseUtils implements AutoCloseable, } @Override + public ListenableFuture<RpcResult<DownloadNESwOutput>> downloadNESw(DownloadNESwInput input) { + logger.debug(String.format("LCM DownloadNESw received input: %s", input.toString())); + DownloadNESwOutputBuilder outputBuilder = new DownloadNESw().process(input); + RpcResult<DownloadNESwOutput> result = + RpcResultBuilder.<DownloadNESwOutput>status(true).withResult(outputBuilder.build()).build(); + return Futures.immediateFuture(result); + } + + @Override + public ListenableFuture<RpcResult<ActivateNESwOutput>> activateNESw(ActivateNESwInput input) { + logger.debug(String.format("LCM ActivateNESw received input: %s", input.toString())); + ActivateNESwOutputBuilder outputBuilder = new ActivateNESw().process(input); + RpcResult<ActivateNESwOutput> result = + RpcResultBuilder.<ActivateNESwOutput>status(true).withResult(outputBuilder.build()).build(); + return Futures.immediateFuture(result); + } + + @Override public ListenableFuture<RpcResult<TerminateOutput>> terminate(TerminateInput input) { logger.debug("Input received : " + input.toString()); TerminateOutputBuilder outputBuilder = new TerminateOutputBuilder(); 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 index b951bd966..eeeeb9341 100644 --- 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 @@ -149,8 +149,8 @@ public class AbstractBaseUtils { * @return RPC name of the Action */ protected String getRpcName(Action action) { - String regex = "([a-z])([A-Z]+)"; - String replacement = "$1-$2"; + String regex = "([a-zA-Z])(?=[A-Z])"; + String replacement = "$1-"; return action.name().replaceAll(regex, replacement).toLowerCase(); } } diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/ActivateNESw.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/ActivateNESw.java new file mode 100644 index 000000000..6125c1d27 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/ActivateNESw.java @@ -0,0 +1,119 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ================================================================================ + * Copyright (C) 2020 Huawei + * ================================================================================ + * 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.ActivateNESwInput; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ActivateNESwOutputBuilder; +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 activating NE software + */ +public class ActivateNESw extends AbstractBaseService { + public ActivateNESw() { + super(Action.ActivateNESw); + logger.debug("ActivateNESw starts"); + } + + /** + * Process the ActivateNESw request. + * @param input of ActivateNESwInput from the REST API input + * @return ActivateNESwOutputBuilder which has the process results + */ + public ActivateNESwOutputBuilder process(ActivateNESwInput 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); + } + + ActivateNESwOutputBuilder outputBuilder = new ActivateNESwOutputBuilder(); + outputBuilder.setStatus(status); + outputBuilder.setCommonHeader(input.getCommonHeader()); + return outputBuilder; + } + + /** + * Validate the input. + * Set Status if any error occurs. + * + * @param input of ActivateNESwInput 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("ActivateNESw (%s) got IOException when converting payload", rpcName), e); + status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, e.getMessage()); + } + } + + /** + * Proceed to action for the ActivateNESw. + * + * @param input of ActivateNESwInput 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/DownloadNESw.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/DownloadNESw.java new file mode 100644 index 000000000..a21c51001 --- /dev/null +++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/DownloadNESw.java @@ -0,0 +1,119 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ================================================================================ + * Copyright (C) 2020 Huawei + * ================================================================================ + * 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.DownloadNESwInput; +import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.DownloadNESwOutputBuilder; +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 downloading NE software + */ +public class DownloadNESw extends AbstractBaseService { + public DownloadNESw() { + super(Action.DownloadNESw); + logger.debug("DownloadNESw starts"); + } + + /** + * Process the DownloadNESw request. + * @param input of DownloadNESwInput from the REST API input + * @return DownloadNESwOutputBuilder which has the process results + */ + public DownloadNESwOutputBuilder process(DownloadNESwInput 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); + } + + DownloadNESwOutputBuilder outputBuilder = new DownloadNESwOutputBuilder(); + outputBuilder.setStatus(status); + outputBuilder.setCommonHeader(input.getCommonHeader()); + return outputBuilder; + } + + /** + * Validate the input. + * Set Status if any error occurs. + * + * @param input of DownloadNESwInput 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("DownloadNESw (%s) got IOException when converting payload", rpcName), e); + status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, e.getMessage()); + } + } + + /** + * Proceed to action for the DownloadNESw. + * + * @param input of DownloadNESwInput 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); + } + } +} + |