2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Orange
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 * ============LICENSE_END=========================================================
22 package org.onap.appc.provider.lcm.service;
25 import org.onap.appc.executor.objects.LCMCommandStatus;
26 import org.onap.appc.requesthandler.objects.RequestHandlerInput;
27 import org.onap.appc.util.JsonUtil;
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.DistributeTrafficInput;
30 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.DistributeTrafficOutputBuilder;
32 import java.io.IOException;
36 * Provide LCM command service for Distribute Traffic between VNFs.
38 public class DistributeTrafficService extends AbstractBaseService {
41 private static final String CONFIG_FILE_NAME_PARAMETER = "ConfigFileName";
42 private static final String PAYLOAD = "payload";
47 public DistributeTrafficService() {
48 super(Action.DistributeTraffic);
49 logger.debug("DistributeTrafficService starts");
53 * Process a DistributeTraffic request
54 * @param input of DistributeTrafficInput from the REST API input
55 * @return DistributeTrafficOutputBuilder which has the process results
57 public DistributeTrafficOutputBuilder process(DistributeTrafficInput input) {
64 DistributeTrafficOutputBuilder outputBuilder = new DistributeTrafficOutputBuilder();
65 outputBuilder.setStatus(status);
66 outputBuilder.setCommonHeader(input.getCommonHeader());
72 * Set Status if any error detected.
74 * @param input of DistributeTrafficInput from the REST API input
76 void validate(DistributeTrafficInput input) {
77 status = validateVnfId(input.getCommonHeader(), input.getAction(), input.getActionIdentifiers());
82 if (input.getPayload() == null) {
83 status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, PAYLOAD);
86 String payloadString = input.getPayload().getValue();
87 status = validateMustHaveParamValue(payloadString == null ? payloadString : payloadString.trim(), PAYLOAD);
93 Map<String, String> payloadMap = JsonUtil.convertJsonStringToFlatMap(payloadString);
94 // ConfigFileName validation
95 final String configFileName = payloadMap.get(CONFIG_FILE_NAME_PARAMETER);
96 if (configFileName == null) {
97 status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, CONFIG_FILE_NAME_PARAMETER);
100 } catch(IOException e) {
101 logger.error(String.format("DistributeTrafficService (%s) got IOException when converting payload", rpcName), e);
102 status = buildStatusForErrorMsg(LCMCommandStatus.UNEXPECTED_ERROR, e.getMessage());
106 void proceedAction(DistributeTrafficInput input) {
107 RequestHandlerInput requestHandlerInput = getRequestHandlerInput(
108 input.getCommonHeader(), input.getActionIdentifiers(), input.getPayload(), this.getClass().getName());
109 if (requestHandlerInput != null) {
110 executeAction(requestHandlerInput);