Changed to unmaintained
[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.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
27 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.DistributeTrafficCheckInput;
28 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.DistributeTrafficCheckOutputBuilder;
29
30
31 /**
32  * Provide LCM command service to check conditions and the result of DistributeTraffic.
33  */
34 public class DistributeTrafficCheckService extends AbstractBaseService {
35
36     private static final String PAYLOAD = "payload";
37
38     /**
39      * Constructor.
40      */
41     public DistributeTrafficCheckService() {
42         super(Action.DistributeTrafficCheck);
43         logger.debug("DistributeTrafficCheckService starts");
44     }
45
46     /**
47      * Process the DistributeTrafficCheck request
48      * @param input of DistributeTrafficCheckInput from the REST API input
49      * @return DistributeTrafficCheckOutputBuilder which has the process results
50      */
51     public DistributeTrafficCheckOutputBuilder process(DistributeTrafficCheckInput input) {
52
53         validate(input);
54         if (status == null) {
55             proceedAction(input);
56         }
57
58         DistributeTrafficCheckOutputBuilder outputBuilder = new DistributeTrafficCheckOutputBuilder();
59         outputBuilder.setStatus(status);
60         outputBuilder.setCommonHeader(input.getCommonHeader());
61         return outputBuilder;
62
63     }
64
65     /**
66      * Validate input.
67      * Set status if any error detected. Otherwise, status == null.
68      * @param input of DistributeTrafficCheckInput from the REST API input
69      */
70     void validate(DistributeTrafficCheckInput input) {
71         status = validateVnfId(input.getCommonHeader(), input.getAction(), input.getActionIdentifiers());
72         if (status != null) {
73             return;
74         }
75
76         if (input.getPayload() == null) {
77             status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, PAYLOAD);
78             return;
79         }
80         String payloadString = input.getPayload().getValue();
81         status = validateMustHaveParamValue(payloadString == null ? payloadString : payloadString.trim(), PAYLOAD);
82         if (status != null) {
83             return;
84         }
85     }
86
87     /**
88      * Execute the distribute-traffic-check action.
89      * @param input of DistributeTrafficCheckInput from the REST API input
90      */
91     void proceedAction(DistributeTrafficCheckInput input) {
92         RequestHandlerInput requestHandlerInput = getRequestHandlerInput(
93                 input.getCommonHeader(), input.getActionIdentifiers(), input.getPayload(), this.getClass().getName());
94         if (requestHandlerInput != null) {
95             executeAction(requestHandlerInput);
96         }
97     }
98
99
100 }