2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications (C) 2019 Ericsson
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.provider.lcm.service;
28 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
29 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ResumeTrafficInput;
30 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ResumeTrafficOutputBuilder;
31 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers;
32 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload;
33 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;
34 import org.onap.appc.requesthandler.objects.RequestHandlerInput;
35 import org.onap.appc.executor.objects.LCMCommandStatus;
36 import org.onap.appc.util.JsonUtil;
37 import java.io.IOException;
41 * Provide LCM command service for Resume VNF traffic
43 public class ResumeTrafficService extends AbstractBaseService {
48 public ResumeTrafficService() {
49 super(Action.ResumeTraffic);
50 logger.debug("ResumeTrafficService starts");
54 * Process the Resume request
56 * @param input of ResumeTrafficInput from the REST API input
57 * @return ResumeTrafficOutputBuilder which has the process results
59 public ResumeTrafficOutputBuilder process(ResumeTrafficInput input) {
60 CommonHeader commonHeader = input.getCommonHeader();
61 ActionIdentifiers actionIdentifiers = input.getActionIdentifiers();
62 Payload payload = input.getPayload();
64 validate(commonHeader, input.getAction(), actionIdentifiers, payload);
66 proceedAction(commonHeader, actionIdentifiers, payload);
69 ResumeTrafficOutputBuilder outputBuilder = new ResumeTrafficOutputBuilder();
70 outputBuilder.setStatus(status);
71 outputBuilder.setCommonHeader(input.getCommonHeader());
77 * Set Status if any error occurs.
79 * @param input of ResumeTrafficInput from the REST API input
81 void validate(CommonHeader commonHeader, Action action, ActionIdentifiers actionIdentifiers, Payload payload) {
82 status = validateVnfId(commonHeader, action, actionIdentifiers);
87 String keyName = "payload";
88 if (payload == null) {
89 status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, keyName);
92 String payloadString = payload.getValue();
93 status = validateMustHaveParamValue(payloadString == null ? payloadString : payloadString.trim(), "payload");
98 Map<String, String> payloadMap = JsonUtil.convertJsonStringToFlatMap(payloadString);
99 validateMustHaveParamValue(payloadMap.get(keyName), keyName);
100 } catch (IOException e) {
101 logger.error(String.format("ResumeTrafficService (%s) got IOException when converting payload", rpcName),
103 status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, e.getMessage());
108 * Proceed to action for the Resume VNF traffic.
110 * @param input of ResumeTrafficInput from the REST API input
112 void proceedAction(CommonHeader commonHeader, ActionIdentifiers actionIdentifiers, Payload payload) {
113 RequestHandlerInput requestHandlerInput =
114 getRequestHandlerInput(commonHeader, actionIdentifiers, payload, this.getClass().getName());
115 if (requestHandlerInput != null) {
116 executeAction(requestHandlerInput);