a00c1664eafca99caf2751690165ecc797d68a04
[dcaegen2/services/son-handler.git] / src / main / java / org / onap / dcaegen2 / services / sonhms / child / StateOof.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  son-handler
4  *  ================================================================================
5  *   Copyright (C) 2019 Wipro Limited.
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  *     ============LICENSE_END=========================================================
19  *  
20  *******************************************************************************/
21
22 package org.onap.dcaegen2.services.sonhms.child;
23
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.UUID;
27 import java.util.concurrent.BlockingQueue;
28
29 import org.onap.dcaegen2.services.sonhms.Configuration;
30 import org.onap.dcaegen2.services.sonhms.exceptions.OofNotFoundException;
31 import org.onap.dcaegen2.services.sonhms.model.AnrInput;
32 import org.onap.dcaegen2.services.sonhms.restclient.OofRestClient;
33 import org.slf4j.Logger;
34
35 public class StateOof {
36     private static final Logger log = org.slf4j.LoggerFactory.getLogger(StateOof.class);
37     private BlockingQueue<List<String>> childStatusUpdate;
38
39     public StateOof() {
40
41     }
42
43     /**
44      * Parameterized Constructor.
45      *
46      */
47     public StateOof(BlockingQueue<List<String>> childStatusUpdate) {
48         super();
49         this.childStatusUpdate = childStatusUpdate;
50     }
51
52     /**
53      * Triggers OOF for pci.
54      * 
55      * @throws OofNotFoundException
56      *             when trigger oof fails
57      */
58     public UUID triggerOof(List<String> cellidList, String networkId, List<AnrInput> anrInputList)
59             throws OofNotFoundException, InterruptedException {
60
61         log.info("Triggering oof");
62
63         log.debug("the cells triggering the oof are {}", cellidList);
64
65         UUID transactionId = UUID.randomUUID();
66
67         Configuration config = Configuration.getInstance();
68         int numSolutions = config.getNumSolutions();
69         List<String> pciOptimizerList = new ArrayList<>();
70         List<String> pciAnrOptimizerList = new ArrayList<>();
71
72         pciOptimizerList.add(config.getPciOptimizer());
73         pciAnrOptimizerList.add(config.getPciAnrOptimizer());
74
75         String oofResponse = null;
76         if (!anrInputList.isEmpty()) {
77             oofResponse = OofRestClient.queryOof(numSolutions, transactionId.toString(), "create", cellidList,
78                     networkId, pciAnrOptimizerList, anrInputList);
79         } else {
80             oofResponse = OofRestClient.queryOof(numSolutions, transactionId.toString(), "create", cellidList,
81                     networkId, pciOptimizerList, anrInputList);
82         }
83         log.info("Synchronous Response {}", oofResponse);
84
85         List<String> childStatus = new ArrayList<>();
86         childStatus.add(Long.toString(Thread.currentThread().getId()));
87         childStatus.add("triggeredOof");
88         try {
89             childStatusUpdate.put(childStatus);
90         } catch (InterruptedException e1) {
91             log.debug("Interrupted execption {}", e1);
92             Thread.currentThread().interrupt();
93
94         }
95
96         return transactionId;
97     }
98
99 }