Fix sonar issues
[vfc/nfvo/driver/vnfm/svnfm.git] / nokiav2 / driver / src / main / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / nokia / onap / direct / notification / GenericVnfManager.java
index 959177c..52e9151 100644 (file)
  */
 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
 
-import com.nokia.cbam.lcm.v32.ApiException;
 import com.nokia.cbam.lcm.v32.model.VnfInfo;
-import org.onap.aai.domain.yang.v11.GenericVnf;
-import org.onap.aai.domain.yang.v11.Relationship;
+import java.util.ArrayList;
+import java.util.NoSuchElementException;
+import org.onap.aai.model.GenericVnf;
+import org.onap.aai.model.Relationship;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring.Conditions;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider;
@@ -28,10 +29,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Conditional;
 import org.springframework.stereotype.Component;
 
-import java.util.NoSuchElementException;
-
-import static java.lang.String.format;
-import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider.AAIService.NETWORK;
 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.buildFatalFailure;
 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions;
 
@@ -41,7 +38,6 @@ import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.sys
 @Component
 @Conditional(value = Conditions.UseForDirect.class)
 class GenericVnfManager extends AbstractManager {
-    private static final String VNF_URL = "/generic-vnfs/generic-vnf/%s";
     private static final long MAX_MS_TO_WAIT_FOR_VNF_TO_APPEAR = 30 * 1000L;
     private static Logger logger = org.slf4j.LoggerFactory.getLogger(GenericVnfManager.class);
 
@@ -53,6 +49,7 @@ class GenericVnfManager extends AbstractManager {
     static Relationship linkTo(String vnfId) {
         Relationship relationship = new Relationship();
         relationship.setRelatedTo("generic-vnf");
+        relationship.setRelationshipData(new ArrayList<>());
         relationship.getRelationshipData().add(buildRelationshipData("generic-vnf.vnf-id", vnfId));
         return relationship;
     }
@@ -69,7 +66,7 @@ class GenericVnfManager extends AbstractManager {
         } catch (NoSuchElementException e) {
             try {
                 logger.warn("The VNF with " + vnfId + " identifier did not appear in time", e);
-                updateFields(OBJECT_FACTORY.createGenericVnf(), vnfId, inMaintenance);
+                updateFields(new GenericVnf(), vnfId, inMaintenance);
             } catch (Exception e2) {
                 logger.warn("The VNF with " + vnfId + " identifier has been created since after the maximal wait for VNF to appear timeout", e2);
                 //the VNF might have been created since the last poll
@@ -78,31 +75,30 @@ class GenericVnfManager extends AbstractManager {
         }
     }
 
-    GenericVnf getExistingVnf(String vnfId) {
-        return aaiRestApiProvider.get(logger, NETWORK, format(VNF_URL, vnfId), GenericVnf.class);
+    private GenericVnf getExistingVnf(String vnfId) {
+        return aaiRestApiProvider.getNetworkApi().getNetworkGenericVnfsGenericVnf(vnfId, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null).blockingFirst();
     }
 
     private void updateFields(GenericVnf vnf, String vnfId, boolean inMaintenance) {
         try {
-            VnfInfo vnfInfo = cbamRestApiProvider.getCbamLcmApi(driverProperties.getVnfmId()).vnfsVnfInstanceIdGet(vnfId, CbamRestApiProvider.NOKIA_LCM_API_VERSION);
+            VnfInfo vnfInfo = cbamRestApiProvider.getCbamLcmApi(driverProperties.getVnfmId()).vnfsVnfInstanceIdGet(vnfId, CbamRestApiProvider.NOKIA_LCM_API_VERSION).blockingFirst();
             vnf.setVnfName(vnfInfo.getName());
-        } catch (ApiException e) {
+        } catch (RuntimeException e) {
             throw buildFatalFailure(logger, "Unable to query VNF with " + vnfId + " identifier from CBAM", e);
         }
         vnf.setVnfId(vnfId);
         vnf.setInMaint(inMaintenance);
-        vnf.setVnfInstanceId(vnfId);
         //FIXME whould be good to know if this parameter is relevant or not? (mandatory)
         vnf.setVnfType("NokiaVNF");
         vnf.setIsClosedLoopDisabled(inMaintenance);
-        aaiRestApiProvider.put(logger, NETWORK, format(VNF_URL, vnf.getVnfId()), vnf, Void.class);
+        aaiRestApiProvider.getNetworkApi().createOrUpdateNetworkGenericVnfsGenericVnf(vnf.getVnfId(), vnf).blockingFirst();
     }
 
     private GenericVnf waitForVnfToAppearInAai(String vnfId) {
         long timeoutInMs = systemFunctions().currentTimeMillis() + MAX_MS_TO_WAIT_FOR_VNF_TO_APPEAR;
         while (timeoutInMs - systemFunctions().currentTimeMillis() > 0) {
             try {
-                return aaiRestApiProvider.get(logger, NETWORK, format(VNF_URL, vnfId), GenericVnf.class);
+                return getExistingVnf(vnfId);
             } catch (NoSuchElementException e) {
                 logger.debug("Unable to get VNF with " + vnfId + " identifier", e);
             }