Adding DistributeTrafficCheck LCM API
[appc.git] / appc-provider / appc-provider-bundle / src / main / java / org / onap / appc / provider / lcm / service / DistributeTrafficCheckService.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2019 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.appc.provider.lcm.service;
23
24 import org.onap.appc.executor.objects.LCMCommandStatus;
25 import org.onap.appc.requesthandler.objects.RequestHandlerInput;
26 import org.onap.appc.util.JsonUtil;
27 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
28 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.DistributeTrafficCheckInput;
29 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.DistributeTrafficCheckOutputBuilder;
30
31 import java.io.IOException;
32 import java.util.Map;
33
34
35 /**
36  * Provide LCM command service to check conditions and the result of DistributeTraffic.
37  */
38 public class DistributeTrafficCheckService extends AbstractBaseService {
39
40     private static final String PAYLOAD = "payload";
41
42     /**
43      * Constructor.
44      */
45     public DistributeTrafficCheckService() {
46         super(Action.DistributeTrafficCheck);
47         logger.debug("DistributeTrafficCheckService starts");
48     }
49
50     /**
51      * Process the DistributeTrafficCheck request
52      * @param input of DistributeTrafficCheckInput from the REST API input
53      * @return DistributeTrafficCheckOutputBuilder which has the process results
54      */
55     public DistributeTrafficCheckOutputBuilder process(DistributeTrafficCheckInput input) {
56
57         validate(input);
58         if (status == null) {
59             proceedAction(input);
60         }
61
62         DistributeTrafficCheckOutputBuilder outputBuilder = new DistributeTrafficCheckOutputBuilder();
63         outputBuilder.setStatus(status);
64         outputBuilder.setCommonHeader(input.getCommonHeader());
65         return outputBuilder;
66
67     }
68
69     /**
70      * Validate input.
71      * Set status if any error detected. Otherwise, status == null.
72      * @param input of DistributeTrafficCheckInput from the REST API input
73      */
74     void validate(DistributeTrafficCheckInput input) {
75         status = validateVnfId(input.getCommonHeader(), input.getAction(), input.getActionIdentifiers());
76         if (status != null) {
77             return;
78         }
79
80         if (input.getPayload() == null) {
81             status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, PAYLOAD);
82             return;
83         }
84         String payloadString = input.getPayload().getValue();
85         status = validateMustHaveParamValue(payloadString == null ? payloadString : payloadString.trim(), PAYLOAD);
86         if (status != null) {
87             return;
88         }
89     }
90
91     /**
92      * Execute the distribute-traffic-check action.
93      * @param input of DistributeTrafficCheckInput from the REST API input
94      */
95     void proceedAction(DistributeTrafficCheckInput input) {
96         RequestHandlerInput requestHandlerInput = getRequestHandlerInput(
97                 input.getCommonHeader(), input.getActionIdentifiers(), input.getPayload(), this.getClass().getName());
98         if (requestHandlerInput != null) {
99             executeAction(requestHandlerInput);
100         }
101     }
102
103
104 }