2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.provider.lcm.service;
27 import com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
29 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
30 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.RebootInput;
31 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.RebootOutputBuilder;
32 import org.onap.appc.executor.objects.LCMCommandStatus;
33 import org.onap.appc.requesthandler.objects.RequestHandlerInput;
34 import org.onap.appc.util.JsonUtil;
36 import java.io.IOException;
37 import java.util.Arrays;
38 import java.util.List;
42 * Provide LCM command service for rebooting virtual machine (VM)
44 public class RebootService extends AbstractBaseService {
45 private final EELFLogger myLogger = EELFManager.getInstance().getLogger(RebootService.class);
46 private static final String REBOOT_TYPE_PARAMETER = "reboot-type";
47 private final List<String> rebootTypeList = Arrays.asList("hard", "soft");
52 public RebootService() {
56 public RebootOutputBuilder process(RebootInput input) {
62 final RebootOutputBuilder outputBuilder = new RebootOutputBuilder();
63 outputBuilder.setCommonHeader(input.getCommonHeader());
64 outputBuilder.setStatus(status);
68 private void proceedAction(RebootInput input) {
69 RequestHandlerInput requestHandlerInput = getRequestHandlerInput(
70 input.getCommonHeader(), input.getActionIdentifiers(), input.getPayload(), this.getClass().getName());
71 if (requestHandlerInput != null) {
72 executeAction(requestHandlerInput);
76 private String getRebootType(RebootInput input) {
77 String rebootType = null;
78 if (input.getPayload() != null) {
79 Map<String, String> payloadMap;
81 payloadMap = JsonUtil.convertJsonStringToFlatMap(input.getPayload().getValue());
82 rebootType = payloadMap.get(REBOOT_TYPE_PARAMETER);
83 } catch (IOException e) {
84 myLogger.error("Error in converting payload of RebootInput", e.getMessage());
94 * @param input of RebootInput from the REST API input
96 private void validate(RebootInput input) {
97 status = validateVserverId(input.getCommonHeader(), input.getAction(), input.getActionIdentifiers());
102 //reboot-type validation
103 final String rebootType = getRebootType(input);
104 if (null == rebootType) {
105 status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, REBOOT_TYPE_PARAMETER);
106 } else if (!rebootTypeList.contains(rebootType)) {
107 status = buildStatusForErrorMsg(LCMCommandStatus.INVALID_INPUT_PARAMETER, REBOOT_TYPE_PARAMETER);