aboutsummaryrefslogtreecommitdiffstats
path: root/appc-provider/appc-provider-bundle/src/main/java/org
diff options
context:
space:
mode:
authorvidhyasree <sn141y@att.com>2018-06-22 11:30:24 -0400
committerTakamune Cho <tc012c@att.com>2018-06-25 18:37:10 +0000
commita0e26d8b474fa91e6f4ec6bcbb2c53384821bd7a (patch)
tree8cf2461d1ed9c4547931cc4fb689845d5e058fdf /appc-provider/appc-provider-bundle/src/main/java/org
parent057c89a2d1db077fa2238c02f998e4dbe9c47268 (diff)
new action Reboot to the LCM API
Issue-ID: APPC-920 Change-Id: Iba1e40f5bc4319f99f6cdfa3a9409faa191ec649 Signed-off-by: vidhyasree <sn141y@att.com>
Diffstat (limited to 'appc-provider/appc-provider-bundle/src/main/java/org')
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderLcm.java2
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/RebootService.java95
2 files changed, 62 insertions, 35 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 1282afacd..c3606df4f 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
@@ -445,7 +445,7 @@ public class AppcProviderLcm extends AbstractBaseUtils implements AutoCloseable,
@Override
public Future<RpcResult<RebootOutput>> reboot(RebootInput input) {
logger.debug(String.format("LCM reboot received input: %s", input.toString()));
- RebootOutputBuilder outputBuilder = new RebootService().process(input);
+ RebootOutputBuilder outputBuilder = new RebootService().reboot(input);
RpcResult<RebootOutput> result =
RpcResultBuilder.<RebootOutput>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/RebootService.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/RebootService.java
index 77b287017..19f51e39d 100644
--- a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/RebootService.java
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/service/RebootService.java
@@ -4,20 +4,18 @@
* ================================================================================
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
- * Copyright (C) 2017 Amdocs
- * =============================================================================
* 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=========================================================
*/
@@ -26,14 +24,19 @@ package org.onap.appc.provider.lcm.service;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.RebootInput;
import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.RebootOutputBuilder;
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.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 java.io.IOException;
import java.util.Arrays;
+import java.util.EnumSet;
import java.util.List;
import java.util.Map;
@@ -42,8 +45,8 @@ import java.util.Map;
*/
public class RebootService extends AbstractBaseService {
private final EELFLogger myLogger = EELFManager.getInstance().getLogger(RebootService.class);
- private static final String REBOOT_TYPE_PARAMETER = "reboot-type";
- private final List<String> rebootTypeList = Arrays.asList("hard", "soft");
+ private static final String REBOOT_TYPE_PARAMETER = "type";
+ private final List<String> rebootTypeList = Arrays.asList("HARD", "SOFT");
/**
* Constructor
@@ -52,58 +55,82 @@ public class RebootService extends AbstractBaseService {
super(Action.Reboot);
}
- public RebootOutputBuilder process(RebootInput input) {
+ public RebootOutputBuilder reboot(RebootInput input) {
+
validate(input);
if (status == null) {
proceedAction(input);
}
- final RebootOutputBuilder outputBuilder = new RebootOutputBuilder();
+ RebootOutputBuilder outputBuilder = new RebootOutputBuilder();
outputBuilder.setCommonHeader(input.getCommonHeader());
outputBuilder.setStatus(status);
return outputBuilder;
}
- private void proceedAction(RebootInput input) {
+ void proceedAction(RebootInput input) {
RequestHandlerInput requestHandlerInput = getRequestHandlerInput(
- input.getCommonHeader(), input.getActionIdentifiers(), input.getPayload(), this.getClass().getName());
+ input.getCommonHeader(), input.getActionIdentifiers(), input.getPayload(), this.getClass().getName());
if (requestHandlerInput != null) {
executeAction(requestHandlerInput);
}
}
- private String getRebootType(RebootInput input) {
- String rebootType = null;
- if (input.getPayload() != null) {
- Map<String, String> payloadMap;
- try {
- payloadMap = JsonUtil.convertJsonStringToFlatMap(input.getPayload().getValue());
- rebootType = payloadMap.get(REBOOT_TYPE_PARAMETER);
- } catch (IOException e) {
- myLogger.error("Error in converting payload of RebootInput", e.getMessage());
- }
- }
-
- return rebootType;
- }
-
/**
* Validate the input.
*
* @param input of RebootInput from the REST API input
*/
- private void validate(RebootInput input) {
- status = validateVserverId(input.getCommonHeader(), input.getAction(), input.getActionIdentifiers());
+ void validate(RebootInput input) {
+ status = validateVserverIdVnfId(input.getCommonHeader(), input.getAction(), input.getActionIdentifiers());
if (status != null) {
return;
}
+ // validate payload
+ String keyName = "payload";
+ if (input.getPayload() == null) {
+ status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, keyName);
+ 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);
+ //reboot-type validation
+ final String rebootType = payloadMap.get(REBOOT_TYPE_PARAMETER);
+ if (rebootType == null) {
+ return;
+ } else if (!rebootTypeList.contains(rebootType)) {
+ status = buildStatusForErrorMsg(LCMCommandStatus.INVALID_INPUT_PARAMETER, REBOOT_TYPE_PARAMETER);
+ return;
+ }
+ } catch (IOException e) {
+ logger.error(String.format("VolumeService (%s) got IOException when converting payload", rpcName), e);
+ status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, e.getMessage());
+ }
+ }
- //reboot-type validation
- final String rebootType = getRebootType(input);
- if (null == rebootType) {
- status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, REBOOT_TYPE_PARAMETER);
- } else if (!rebootTypeList.contains(rebootType)) {
- status = buildStatusForErrorMsg(LCMCommandStatus.INVALID_INPUT_PARAMETER, REBOOT_TYPE_PARAMETER);
+ Status validateVserverIdVnfId(CommonHeader commonHeader, Action action, ActionIdentifiers actionIdentifiers ) {
+ Status validatedStatus = validateInput(commonHeader, action, actionIdentifiers);
+
+ if (validatedStatus != null) {
+ return validatedStatus;
+ }
+
+ validatedStatus = validateMustHaveParamValue(actionIdentifiers.getVserverId(), "vserver-id");
+ if (validatedStatus == null) {
+ validatedStatus = validateMustHaveParamValue(actionIdentifiers.getVnfId(), "vnf-id");
+ logger.debug("check for vnf-id");
+ }
+ if (validatedStatus == null) {
+ validatedStatus = validateExcludedActIds(actionIdentifiers, EnumSet.of(ACTID_KEYS.VSERVER_ID, ACTID_KEYS.VNF_ID));
}
+ logger.debug("check for ActIds");
+ return validatedStatus;
}
}