Implement adaptive SON functionality
[dcaegen2/services/son-handler.git] / src / main / java / org / onap / dcaegen2 / services / sonhms / restclient / OofRestClient.java
index 0f6dd98..ca56e89 100644 (file)
@@ -2,7 +2,7 @@
  *  ============LICENSE_START=======================================================
  *  son-handler
  *  ================================================================================
- *   Copyright (C) 2019 Wipro Limited.
+ *   Copyright (C) 2019-2020 Wipro Limited.
  *   ==============================================================================
  *     Licensed under the Apache License, Version 2.0 (the "License");
  *     you may not use this file except in compliance with the License.
@@ -29,7 +29,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 
-import org.onap.dcaegen2.services.sonhms.ConfigPolicy;
 import org.onap.dcaegen2.services.sonhms.Configuration;
 import org.onap.dcaegen2.services.sonhms.exceptions.OofNotFoundException;
 import org.onap.dcaegen2.services.sonhms.model.AnrInput;
@@ -54,7 +53,7 @@ public class OofRestClient {
      */
 
     public static String queryOof(int numSolutions, String transactionId, String requestType, List<String> cellIdList,
-            String networkId, List<String> optimizers, List<AnrInput> anrInputList) throws OofNotFoundException {
+            String networkId, List<String> optimizers, List<AnrInput> anrInputList, List<String> fixedPciCells) throws OofNotFoundException {
         log.debug("inside queryoof");
 
         Configuration configuration = Configuration.getInstance();
@@ -73,13 +72,7 @@ public class OofRestClient {
         Map<String, String> callbackHeader = new HashMap<>();
         callbackHeader.put("Content-Type", "application/json");
         requestInfo.setCallbackHeader(callbackHeader);
-        ConfigPolicy config = ConfigPolicy.getInstance();
         int timeout = 60;
-        try {
-            timeout = (int) config.getConfig().get("PCI_NEIGHBOR_CHANGE_CLUSTER_TIMEOUT_IN_SECS");
-        } catch (NullPointerException e) {
-            log.debug("No config policy available. Using default timeout 60 sec");
-        }
         requestInfo.setTimeout(timeout);
 
         CellInfo cellInfo = new CellInfo();
@@ -89,6 +82,9 @@ public class OofRestClient {
         if (!anrInputList.isEmpty()) {
             cellInfo.setAnrInputList(anrInputList);
         }
+        if(!fixedPciCells.isEmpty()) {
+        cellInfo.setFixedPCICells(fixedPciCells); 
+        }
         OofRequestBody oofRequestBody = new OofRequestBody();
         oofRequestBody.setRequestInfo(requestInfo);
         oofRequestBody.setCellInfo(cellInfo);
@@ -103,15 +99,19 @@ public class OofRestClient {
         }
         log.info("requestBody{}", requestBody);
 
-        String requestUrl = configuration.getOofService() + "/api/oof/pci/v1";
-        log.debug("requestUrl {}", requestUrl);
-        ResponseEntity<String> response = null;
+        String requestUrl = configuration.getOofService() + configuration.getOofEndpoint();
+        log.info("requestUrl {}", requestUrl);
+        ResponseEntity<String> response = null; 
         response = SonHandlerRestTemplate.sendPostRequestToOof(requestUrl, requestBody,
                 new ParameterizedTypeReference<String>() {
                 });
+        
         if (response == null) {
             throw new OofNotFoundException("Request to oof failed");
         }
+        else if (response.getStatusCodeValue() != 202) {
+            throw new OofNotFoundException("Request to oof failed with status code" + response.getStatusCodeValue());
+        }
         log.info("response {}", response);
 
         return response.getBody();