2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
20 * ============LICENSE_END=========================================================
23 package org.onap.appc.provider.lcm.service;
25 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
26 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StatusTrafficInput;
27 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StatusTrafficOutput;
28 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StatusTrafficOutputBuilder;
29 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload;
30 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers;
31 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;
32 import org.onap.appc.requesthandler.objects.RequestHandlerInput;
33 import org.onap.appc.executor.objects.LCMCommandStatus;
34 import org.onap.appc.util.JsonUtil;
36 import java.io.IOException;
39 * Provide LCM command service for StatusTraffic VNF
41 public class StatusTraffic extends AbstractBaseService {
46 public StatusTraffic() {
47 super(Action.StatusTraffic);
48 logger.debug("StatusTraffic starts");
52 * Process the StatusTraffic request
53 * @param input of StatusTrafficInput from the REST API input
54 * @return StatusTrafficOutputBuilder which has the process results
56 public StatusTrafficOutputBuilder process(StatusTrafficInput input) {
57 CommonHeader commonHeader = input.getCommonHeader();
58 ActionIdentifiers actionIdentifiers = input.getActionIdentifiers();
59 Payload payload = input.getPayload();
61 validate(commonHeader, input.getAction(), actionIdentifiers, payload);
63 proceedAction(commonHeader,actionIdentifiers,payload);
66 StatusTrafficOutputBuilder outputBuilder = new StatusTrafficOutputBuilder();
67 outputBuilder.setStatus(status);
68 outputBuilder.setCommonHeader(input.getCommonHeader());
74 * Set Status if any error occurs.
76 * @param input of StatusTrafficInput from the REST API input
78 void validate(CommonHeader commonHeader,
80 ActionIdentifiers actionIdentifiers,
82 status = validateVnfId(commonHeader, action, actionIdentifiers);
88 String keyName = "payload";
89 if (payload == null) {
90 status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, keyName);
93 String payloadString = payload.getValue();
94 status = validateMustHaveParamValue(payloadString == null ? payloadString : payloadString.trim(), "payload");
100 Map<String, String> payloadMap = JsonUtil.convertJsonStringToFlatMap(payloadString);
101 validateMustHaveParamValue(payloadMap.get(keyName), keyName);
102 } catch (IOException e) {
103 logger.error(String.format("StatusTraffic (%s) got IOException when converting payload", rpcName), e);
104 status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, e.getMessage());
109 * Proceed to action for the StatusTraffic VNF traffic.
111 * @param input of StatusTrafficInput from the REST API input
113 void proceedAction(CommonHeader commonHeader,
114 ActionIdentifiers actionIdentifiers,
116 RequestHandlerInput requestHandlerInput = getRequestHandlerInput(commonHeader, actionIdentifiers, payload,
117 this.getClass().getName());
118 if (requestHandlerInput != null) {
119 executeAction(requestHandlerInput);