Fix sonar issues 13/38513/1
authorDenes Nemeth <denes.nemeth@nokia.com>
Mon, 26 Mar 2018 12:25:44 +0000 (14:25 +0200)
committerDenes Nemeth <denes.nemeth@nokia.com>
Mon, 26 Mar 2018 12:27:41 +0000 (14:27 +0200)
Change-Id: I24ffa257b614b6dfa9768a54689424989308c9cf
Issue-ID: VFC-728
Signed-off-by: Denes Nemeth <denes.nemeth@nokia.com>
23 files changed:
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/SelfRegistrationManager.java
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/GenericVnfManager.java
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/L3NetworkManager.java
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/LInterfaceManager.java
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/VnfcManager.java
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/VserverManager.java
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/CbamVnfdBuilder.java
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/SystemFunctions.java
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamSecurityProvider.java
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/LifecycleManager.java
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/LifecycleChangeNotificationManager.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestMsbApiProvider.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIRestApiProvider.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestGenericVnfManager.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestL3NetworkManager.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestLInterfaceManager.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVnfcManager.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVserverManager.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestBase.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestJobManager.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManager.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestSelfRegistrationManager.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/TestLifecycleChangeNotificationManager.java

index 0c57c37..172dd33 100644 (file)
@@ -86,7 +86,7 @@ public class SelfRegistrationManager {
     public void deRegister() {
         try {
             logger.info("Cancelling micro service registration");
-            systemFunctions().blockingFirst(msbApiProvider.getMsbApi().deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null));
+            msbApiProvider.getMsbApi().deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null).blockingFirst();
         } catch (Exception e) {
             //ONAP throws 500 internal server error, but deletes the micro service
             boolean serviceFoundAfterDelete = false;
@@ -123,7 +123,7 @@ public class SelfRegistrationManager {
             for (Subscription subscription : lcnApi.subscriptionsGet(NOKIA_LCN_API_VERSION).blockingFirst()) {
                 if (subscription.getCallbackUrl().equals(callbackUrl)) {
                     logger.info("Deleting subscription with {} identifier", subscription.getId());
-                    systemFunctions().blockingFirst(lcnApi.subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION));
+                    lcnApi.subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION).blockingFirst();
                 }
             }
         } catch (Exception e) {
index 130004e..52e9151 100644 (file)
@@ -22,7 +22,6 @@ 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.util.SystemFunctions;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties;
 import org.slf4j.Logger;
@@ -92,7 +91,7 @@ class GenericVnfManager extends AbstractManager {
         //FIXME whould be good to know if this parameter is relevant or not? (mandatory)
         vnf.setVnfType("NokiaVNF");
         vnf.setIsClosedLoopDisabled(inMaintenance);
-        SystemFunctions.systemFunctions().blockingFirst(aaiRestApiProvider.getNetworkApi().createOrUpdateNetworkGenericVnfsGenericVnf(vnf.getVnfId(), vnf));
+        aaiRestApiProvider.getNetworkApi().createOrUpdateNetworkGenericVnfsGenericVnf(vnf.getVnfId(), vnf).blockingFirst();
     }
 
     private GenericVnf waitForVnfToAppearInAai(String vnfId) {
index 1d641cf..f1c47d5 100644 (file)
@@ -30,7 +30,6 @@ import org.springframework.context.annotation.Conditional;
 import org.springframework.stereotype.Component;
 
 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.SEPARATOR;
-import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions;
 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getCloudOwner;
 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getRegionName;
 
@@ -63,7 +62,7 @@ class L3NetworkManager extends AbstractManager {
 
     void delete(String vnfId, AffectedVirtualLink removedVl) {
         L3Network l3Network = getNetwork(vnfId, removedVl).blockingFirst();
-        systemFunctions().blockingFirst(aaiRestApiProvider.getNetworkApi().deleteNetworkL3NetworksL3Network(l3Network.getNetworkId(), l3Network.getResourceVersion()));
+        aaiRestApiProvider.getNetworkApi().deleteNetworkL3NetworksL3Network(l3Network.getNetworkId(), l3Network.getResourceVersion()).blockingFirst();
     }
 
     private void updateNetworkFields(String vimId, String vnfId, AffectedVirtualLink affectedVirtualLink, L3Network network) {
@@ -82,7 +81,7 @@ class L3NetworkManager extends AbstractManager {
         addMissingRelation(network.getRelationshipList(), GenericVnfManager.linkTo(vnfId));
         addSingletonRelation(network.getRelationshipList(), getRegionLink(vimId));
         addSingletonRelation(network.getRelationshipList(), getTenantLink(vimId, extractMandatoryValue(affectedVirtualLink.getResource().getAdditionalData(), "tenantId")));
-        systemFunctions().blockingFirst(aaiRestApiProvider.getNetworkApi().createOrUpdateNetworkL3NetworksL3Network(network.getNetworkId(), network));
+        aaiRestApiProvider.getNetworkApi().createOrUpdateNetworkL3NetworksL3Network(network.getNetworkId(), network).blockingFirst();
     }
 
     private String buildNetworkId(String vnfId, AffectedVirtualLink affectedVirtualLink) {
index 78da503..ab216bd 100644 (file)
@@ -32,7 +32,6 @@ import org.springframework.stereotype.Component;
 
 import static java.lang.String.format;
 
-import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions;
 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getCloudOwner;
 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getRegionName;
 
@@ -124,6 +123,6 @@ class LInterfaceManager extends AbstractManager {
         String tenantId = affectedCp.getTenantId();
         String vServerId = affectedCp.getServerProviderId();
         String cpId = affectedCp.getCpId();
-        systemFunctions().blockingFirst(aaiRestApiProvider.getCloudInfrastructureApi().createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(cloudOwner, regionName, tenantId, vServerId, cpId, logicalInterface));
+        aaiRestApiProvider.getCloudInfrastructureApi().createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(cloudOwner, regionName, tenantId, vServerId, cpId, logicalInterface).blockingFirst();
     }
 }
index 9528e1a..bc31f4f 100644 (file)
@@ -28,7 +28,6 @@ import org.springframework.context.annotation.Conditional;
 import org.springframework.stereotype.Component;
 
 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.SEPARATOR;
-import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions;
 
 /**
  * Responsible for managing {@link Vnfc} in AAI
@@ -54,7 +53,7 @@ public class VnfcManager extends AbstractManager {
 
     void delete(String vnfId, com.nokia.cbam.lcm.v32.model.AffectedVnfc cbamVnfc) {
         Vnfc vnfc = getVnfc(buildId(vnfId, cbamVnfc.getId())).blockingFirst();
-        systemFunctions().blockingFirst(aaiRestApiProvider.getNetworkApi().deleteNetworkVnfcsVnfc(vnfc.getVnfcName(), vnfc.getResourceVersion()));
+        aaiRestApiProvider.getNetworkApi().deleteNetworkVnfcsVnfc(vnfc.getVnfcName(), vnfc.getResourceVersion()).blockingFirst();
     }
 
     private Observable<Vnfc> getVnfc(String vnfcId) {
@@ -79,6 +78,6 @@ public class VnfcManager extends AbstractManager {
         }
         addSingletonRelation(aaiVnfc.getRelationshipList(), VserverManager.linkTo(vimId, tenantId, cbamVnfc.getComputeResource().getResourceId()));
         addSingletonRelation(aaiVnfc.getRelationshipList(), GenericVnfManager.linkTo(vnfId));
-        systemFunctions().blockingFirst(aaiRestApiProvider.getNetworkApi().createOrUpdateNetworkVnfcsVnfc(aaiVnfc.getVnfcName(), aaiVnfc));
+        aaiRestApiProvider.getNetworkApi().createOrUpdateNetworkVnfcsVnfc(aaiVnfc.getVnfcName(), aaiVnfc).blockingFirst();
     }
 }
\ No newline at end of file
index 3eba8b2..6aeefd7 100644 (file)
@@ -31,13 +31,13 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring.Conditions;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties;
 import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Conditional;
 import org.springframework.stereotype.Component;
 
 import static com.google.common.collect.Iterables.find;
 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.childElement;
-import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions;
 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getCloudOwner;
 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getRegionName;
 
@@ -47,7 +47,7 @@ import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.ge
 @Component
 @Conditional(value = Conditions.UseForDirect.class)
 class VserverManager extends AbstractManager {
-    private static Logger logger = org.slf4j.LoggerFactory.getLogger(AbstractManager.class);
+    private static Logger logger = LoggerFactory.getLogger(AbstractManager.class);
 
     @Autowired
     VserverManager(AAIRestApiProvider aaiRestApiProvider, CbamRestApiProvider cbamRestApiProvider, DriverProperties driverProperties) {
@@ -101,27 +101,25 @@ class VserverManager extends AbstractManager {
         server.setVserverName(additionalData.getAsJsonObject().get("name").getAsString());
         server.setVserverId(cbamVnfc.getComputeResource().getResourceId());
         server.setProvStatus("active");
-        server.setRelationshipList(new ArrayList<>());
         server.setVserverId(cbamVnfc.getComputeResource().getResourceId());
         server.setVserverSelflink(extractSelfLink(cbamVnfc.getComputeResource().getAdditionalData()));
+        if (server.getRelationshipList() == null) {
+            server.setRelationshipList(new ArrayList<>());
+        }
         addSingletonRelation(server.getRelationshipList(), GenericVnfManager.linkTo(vnfId));
+        server.setVolumes(new ArrayList<>());
         if (cbamVnfc.getStorageResourceIds() != null) {
-            if (server.getVolumes() == null) {
-                server.setVolumes(new ArrayList<>());
-            }
             for (String virtualStorageId : cbamVnfc.getStorageResourceIds()) {
                 Volume volume = new Volume();
                 AffectedVirtualStorage affectedStorage = find(affectedVirtualStorages, storage -> virtualStorageId.equals(storage.getId()));
                 volume.setVolumeId(affectedStorage.getResource().getResourceId());
                 server.getVolumes().add(volume);
             }
-        } else {
-            server.setVolumes(new ArrayList<>());
         }
         String tenantId = getTenantId(cbamVnfc);
         String cloudOwner = getCloudOwner(vimId);
         String regionName = getRegionName(vimId);
-        systemFunctions().blockingFirst(aaiRestApiProvider.getCloudInfrastructureApi().createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(cloudOwner, regionName, tenantId, server.getVserverId(), server));
+        aaiRestApiProvider.getCloudInfrastructureApi().createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(cloudOwner, regionName, tenantId, server.getVserverId(), server).blockingFirst();
     }
 
     private String extractSelfLink(Object additionalData) {
index 07cd803..1c1e4c7 100644 (file)
@@ -17,7 +17,6 @@
 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer;
 
 import com.google.gson.*;
-import java.io.IOException;
 import java.io.StringReader;
 import org.yaml.snakeyaml.Yaml;
 
@@ -32,7 +31,7 @@ public class CbamVnfdBuilder {
      * @param cbamVnfdContent the original CBAM VNFD
      * @return the modified content CBAM VNFD
      */
-    public String build(String cbamVnfdContent) throws IOException {
+    public String build(String cbamVnfdContent) {
         JsonObject root = new Gson().toJsonTree(new Yaml().load(cbamVnfdContent)).getAsJsonObject();
         JsonObject substitutionMappings = child(child(root, "topology_template"), "substitution_mappings");
         JsonObject extensions = addChild(addChild(addChild(addChild(addChild(substitutionMappings, "capabilities"), "vnf"), "properties"), "modifiable_attributes"), "extensions");
index c7fac86..b67c786 100644 (file)
 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util;
 
 import com.google.common.io.ByteStreams;
-import io.reactivex.Observable;
 import java.io.InputStream;
 import java.io.PrintStream;
-import java.util.NoSuchElementException;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClients;
 
@@ -162,18 +160,4 @@ public class SystemFunctions {
     public CloseableHttpClient getHttpClient() {
         return HttpClients.createDefault();
     }
-
-    /**
-     * Execute blocking first
-     *
-     * @param observable the observable
-     */
-    public void blockingFirst(Observable<Void> observable) {
-        try {
-            observable.blockingFirst();
-        } catch (NoSuchElementException e) {
-            //swallow void returns null :)
-        }
-    }
-
 }
\ No newline at end of file
index 3a33436..6dd6b9d 100644 (file)
@@ -19,7 +19,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
 /**
- * Responsible for providing SSL factories for AAI
+ * Responsible for providing SSL factories for CBAM
  */
 @Component
 public class CbamSecurityProvider extends GenericSecurityProvider {
index 1b813a3..9b69fcf 100644 (file)
@@ -332,22 +332,7 @@ public class LifecycleManager {
         accessInfov3.setProject(vim.getAccessInfo().getTenant());
         accessInfov3.setRegion(getRegionName(vimId));
         accessInfov3.setUsername(vimInfo.getUserName());
-        EndpointInfo interfaceInfoV3 = new EndpointInfo();
-        interfaceInfoV3.setEndpoint(vimInfo.getUrl());
-        if (!isEmpty(vimInfo.getSslInsecure())) {
-            interfaceInfoV3.setSkipCertificateVerification(Boolean.parseBoolean(vimInfo.getSslInsecure()));
-            interfaceInfoV3.setSkipCertificateHostnameCheck(Boolean.parseBoolean(vimInfo.getSslInsecure()));
-        } else {
-            interfaceInfoV3.setSkipCertificateHostnameCheck(true);
-            interfaceInfoV3.setSkipCertificateVerification(true);
-        }
-        if (!interfaceInfoV3.isSkipCertificateVerification()) {
-            interfaceInfoV3.setTrustedCertificates(new ArrayList<>());
-            for (String trustedCertificate : StoreLoader.getCertifacates(vimInfo.getSslCacert())) {
-                interfaceInfoV3.getTrustedCertificates().add(trustedCertificate.getBytes(UTF_8));
-            }
-        }
-        openstackv3INFO.setInterfaceInfo(interfaceInfoV3);
+        openstackv3INFO.setInterfaceInfo(getEndpointInfo(vimInfo));
         openstackv3INFO.setId(vimId);
         return openstackv3INFO;
     }
@@ -361,6 +346,13 @@ public class LifecycleManager {
         accessInfo.setTenant(vim.getAccessInfo().getTenant());
         accessInfo.setUsername(vimInfo.getUserName());
         accessInfo.setRegion(getRegionName(vimId));
+        EndpointInfo interfaceEndpoint = getEndpointInfo(vimInfo);
+        openstackv2INFO.setInterfaceInfo(interfaceEndpoint);
+        openstackv2INFO.setId(vimId);
+        return openstackv2INFO;
+    }
+
+    private EndpointInfo getEndpointInfo(VimInfo vimInfo) {
         EndpointInfo interfaceEndpoint = new EndpointInfo();
         if (!isEmpty(vimInfo.getSslInsecure())) {
             interfaceEndpoint.setSkipCertificateHostnameCheck(Boolean.parseBoolean(vimInfo.getSslInsecure()));
@@ -376,9 +368,7 @@ public class LifecycleManager {
                 interfaceEndpoint.getTrustedCertificates().add(trustedCertificate.getBytes(UTF_8));
             }
         }
-        openstackv2INFO.setInterfaceInfo(interfaceEndpoint);
-        openstackv2INFO.setId(vimId);
-        return openstackv2INFO;
+        return interfaceEndpoint;
     }
 
     private VMWAREVCLOUDINFO buildVcloudInfo(String vimId, org.onap.vnfmdriver.model.VimInfo vimInfo) {
@@ -389,22 +379,7 @@ public class LifecycleManager {
         accessInfo.setPassword(vimInfo.getPassword());
         accessInfo.setUsername(vimInfo.getUserName());
         accessInfo.setOrganization(getRegionName(vimId));
-        EndpointInfo interfaceEndpoint = new EndpointInfo();
-        if (!isEmpty(vimInfo.getSslInsecure())) {
-            interfaceEndpoint.setSkipCertificateHostnameCheck(Boolean.parseBoolean(vimInfo.getSslInsecure()));
-            interfaceEndpoint.setSkipCertificateVerification(Boolean.parseBoolean(vimInfo.getSslInsecure()));
-        } else {
-            interfaceEndpoint.setSkipCertificateHostnameCheck(true);
-            interfaceEndpoint.setSkipCertificateVerification(true);
-        }
-        interfaceEndpoint.setEndpoint(vimInfo.getUrl());
-        if (!interfaceEndpoint.isSkipCertificateVerification()) {
-            interfaceEndpoint.setTrustedCertificates(new ArrayList<>());
-            for (String trustedCertificate : StoreLoader.getCertifacates(vimInfo.getSslCacert())) {
-                interfaceEndpoint.getTrustedCertificates().add(trustedCertificate.getBytes(UTF_8));
-            }
-        }
-        vcloudInfo.setInterfaceInfo(interfaceEndpoint);
+        vcloudInfo.setInterfaceInfo(getEndpointInfo(vimInfo));
         vcloudInfo.setId(vimId);
         return vcloudInfo;
     }
@@ -442,7 +417,7 @@ public class LifecycleManager {
             if (vnf.getInstantiationState() == INSTANTIATED) {
                 terminateVnf(vnfmId, vnfId, jobInfo, cbamRequest, vnf);
             } else {
-                systemFunctions().blockingFirst(cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdDelete(vnfId, NOKIA_LCM_API_VERSION));
+                cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdDelete(vnfId, NOKIA_LCM_API_VERSION).blockingFirst();
             }
         });
     }
@@ -455,7 +430,7 @@ public class LifecycleManager {
         if (finishedOperation.getStatus() == FINISHED) {
             notificationManager.waitForTerminationToBeProcessed(finishedOperation.getId());
             logger.info("Deleting VNF with {}", vnfId);
-            systemFunctions().blockingFirst(cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdDelete(vnfId, NOKIA_LCM_API_VERSION));
+            cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdDelete(vnfId, NOKIA_LCM_API_VERSION).blockingFirst();
             logger.info("VNF with {} has been deleted", vnfId);
 
         } else {
index 1485ef5..3ff0499 100644 (file)
@@ -203,6 +203,8 @@ public class LifecycleChangeNotificationManager implements ILifecycleChangeNotif
                 //calculated from operation execution result
                 logger.warn("Unable to send information related to affected connection points during forceful termination");
                 return empty();
+            } else {
+                //graceful termination should be handled as any other operation
             }
         }
         try {
index a056520..c313e31 100644 (file)
@@ -22,6 +22,7 @@ import java.util.List;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
+import org.mockito.Mockito;
 import org.onap.msb.ApiClient;
 import org.onap.msb.api.ServiceResourceApi;
 import org.onap.msb.model.MicroServiceFullInfo;
@@ -185,4 +186,29 @@ public class TestMsbApiProvider extends TestBase {
         }
     }
 
+    /**
+     * Test API wrapping for LCM
+     * (questionable benefit [ this is more less ensured by Java type safety) ]
+     */
+    @Test
+    public void testOperationExecutionsApiAPiWrapping() {
+        ApiClient c = Mockito.mock(ApiClient.class);
+        class TestClasss extends MsbApiProvider {
+
+            TestClasss(Environment environment) {
+                super(environment);
+            }
+
+            @Override
+            ApiClient buildApiClient() {
+                return c;
+            }
+        }
+        ServiceResourceApi defaultApi = Mockito.mock(ServiceResourceApi.class);
+        when(c.createService(ServiceResourceApi.class)).thenReturn(defaultApi);
+        //verify
+        TestClasss testInstnace = new TestClasss(environment);
+        assertEquals(defaultApi, testInstnace.getMsbApi());
+    }
+
 }
index 9c53aba..fafaf2c 100644 (file)
@@ -17,11 +17,13 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct;
 
 import javax.net.ssl.HostnameVerifier;
 import javax.net.ssl.SSLSocketFactory;
+import okhttp3.Interceptor;
 import okhttp3.Protocol;
 import okhttp3.Request;
 import okhttp3.Response;
 import org.junit.Before;
 import org.junit.Test;
+import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.invocation.InvocationOnMock;
@@ -29,6 +31,7 @@ import org.mockito.stubbing.Answer;
 import org.onap.aai.api.CloudInfrastructureApi;
 import org.onap.aai.api.ExternalSystemApi;
 import org.onap.aai.api.NetworkApi;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
 
 import static junit.framework.TestCase.assertEquals;
@@ -79,9 +82,24 @@ public class TestAAIRestApiProvider extends TestBase {
         assertEquals("http://1.2.3.4/a/", apiClient.getAdapterBuilder().build().baseUrl().toString());
         assertEquals(sslSocketFactoryResultCaptor.getResult(), apiClient.getOkBuilder().build().sslSocketFactory());
         assertEquals(hostnameVerifier, apiClient.getOkBuilder().build().hostnameVerifier());
+
+        //given
         Response resp = new Response.Builder().message("a").code(200).protocol(Protocol.HTTP_1_0).request(new Request.Builder().url("http://1.2.3.4/d").build()).build();
+        //when
         Request authenticate = apiClient.getOkBuilder().build().authenticator().authenticate(null, resp);
+        //verify
         assertEquals("Basic dXNlcm5hbWU6YWFpUGFzc3dvcmQ=", authenticate.headers().get("Authorization"));
+
+        //given
+        Interceptor.Chain chain = Mockito.mock(Interceptor.Chain.class);
+        when(chain.request()).thenReturn(new Request.Builder().url("http://1.2.3.4/d").build());
+        ArgumentCaptor<Request> modifedRequest = ArgumentCaptor.forClass(Request.class);
+        when(chain.proceed(modifedRequest.capture())).thenReturn(resp);
+        //when
+        apiClient.getOkBuilder().interceptors().get(0).intercept(chain);
+        //verify
+        assertEquals(SelfRegistrationManager.SERVICE_NAME, modifedRequest.getValue().header("X-FromAppId"));
+
     }
 
     /**
index 514098b..2b411ca 100644 (file)
@@ -109,7 +109,7 @@ public class TestGenericVnfManager extends TestBase {
         when(cbamRestApiProvider.getCbamLcmApi(VNFM_ID).vnfsVnfInstanceIdGet(VNF_ID, CbamRestApiProvider.NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo));
         when(networkApi.createOrUpdateNetworkGenericVnfsGenericVnf(eq(VNF_ID), payload.capture())).thenAnswer(invocation -> {
             vnfs.add(vnfInAaai);
-            return null;
+            return VOID_OBSERVABLE.value();
         });
         vnfInfo.setName("vnfName");
         //when
@@ -124,6 +124,7 @@ public class TestGenericVnfManager extends TestBase {
         assertEquals("vnfName", vnfSentToAai.getVnfName());
         verify(systemFunctions, times(10)).sleep(3000);
         verify(networkApi, times(10)).getNetworkGenericVnfsGenericVnf(VNF_ID, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
+        VOID_OBSERVABLE.assertCalled();
     }
 
     /**
@@ -135,7 +136,7 @@ public class TestGenericVnfManager extends TestBase {
         vnfInAaai.setResourceVersion("v1");
         when(networkApi.getNetworkGenericVnfsGenericVnf(VNF_ID, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(vnfInAaai));
         when(cbamRestApiProvider.getCbamLcmApi(VNFM_ID).vnfsVnfInstanceIdGet(VNF_ID, CbamRestApiProvider.NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo));
-        when(networkApi.createOrUpdateNetworkGenericVnfsGenericVnf(eq(VNF_ID), payload.capture())).thenReturn(null);
+        when(networkApi.createOrUpdateNetworkGenericVnfsGenericVnf(eq(VNF_ID), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
         vnfInfo.setName("vnfName");
         //when
         genericVnfManager.createOrUpdate(VNF_ID, true);
@@ -148,6 +149,7 @@ public class TestGenericVnfManager extends TestBase {
         assertEquals(TRUE, vnfSentToAai.isIsClosedLoopDisabled());
         assertEquals("vnfName", vnfSentToAai.getVnfName());
         verify(systemFunctions, never()).sleep(anyLong());
+        VOID_OBSERVABLE.assertCalled();
         verify(networkApi, times(1)).getNetworkGenericVnfsGenericVnf(VNF_ID, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
     }
 
@@ -198,7 +200,7 @@ public class TestGenericVnfManager extends TestBase {
             if (vnfSentToAAi.getResourceVersion() == null) {
                 throw runtimeException;
             }
-            return null;
+            return VOID_OBSERVABLE.value();
         });
         vnfInfo.setName("vnfName");
         //when
@@ -217,6 +219,7 @@ public class TestGenericVnfManager extends TestBase {
         verify(networkApi, times(2)).createOrUpdateNetworkGenericVnfsGenericVnf(eq(VNF_ID), any());
         verify(logger).warn(eq("The VNF with myVnfId identifier did not appear in time"), any(NoSuchElementException.class));
         verify(logger).warn("The VNF with myVnfId identifier has been created since after the maximal wait for VNF to appear timeout", runtimeException);
+        VOID_OBSERVABLE.assertCalled();
     }
 
     /**
index 47dbb95..cdedafb 100644 (file)
@@ -68,7 +68,7 @@ public class TestL3NetworkManager extends TestBase {
         affectedVirtualLink.getResource().setResourceId("netProviderId");
         L3Network existingNetwork = new L3Network();
         when(networkApi.getNetworkL3NetworksL3Network("myVnfId_vlId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingNetwork));
-        when(networkApi.createOrUpdateNetworkL3NetworksL3Network(eq("myVnfId_vlId"), payload.capture())).thenReturn(null);
+        when(networkApi.createOrUpdateNetworkL3NetworksL3Network(eq("myVnfId_vlId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
         //when
         l3NetworkManager.update(VIM_ID, VNF_ID, affectedVirtualLink);
         //verify
@@ -83,6 +83,7 @@ public class TestL3NetworkManager extends TestBase {
         assertRelation(payload.getValue().getRelationshipList(), "cloud-region", buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)), buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)));
         assertRelation(payload.getValue().getRelationshipList(), "tenant", buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)), buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)), buildRelationshipData("tenant.tenant-id", "myTenantId"));
         assertRelation(payload.getValue().getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
+        VOID_OBSERVABLE.assertCalled();
     }
 
     /**
@@ -101,7 +102,7 @@ public class TestL3NetworkManager extends TestBase {
         l3Network.setResourceVersion("v3");
         l3Network.setRelationshipList(new ArrayList<>());
         when(networkApi.getNetworkL3NetworksL3Network("myVnfId_vlId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(l3Network));
-        when(networkApi.createOrUpdateNetworkL3NetworksL3Network(eq("myVnfId_vlId"), payload.capture())).thenReturn(null);
+        when(networkApi.createOrUpdateNetworkL3NetworksL3Network(eq("myVnfId_vlId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
         //when
         l3NetworkManager.update(VIM_ID, VNF_ID, affectedVirtualLink);
         //verify
@@ -117,6 +118,7 @@ public class TestL3NetworkManager extends TestBase {
         assertRelation(payload.getValue().getRelationshipList(), "cloud-region", buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)), buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)));
         assertRelation(payload.getValue().getRelationshipList(), "tenant", buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)), buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)), buildRelationshipData("tenant.tenant-id", "myTenantId"));
         assertRelation(payload.getValue().getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
+        VOID_OBSERVABLE.assertCalled();
     }
 
     /**
@@ -127,11 +129,14 @@ public class TestL3NetworkManager extends TestBase {
         affectedVirtualLink.setId("vlId");
         L3Network l3Network = new L3Network();
         l3Network.setResourceVersion("v3");
+        l3Network.setNetworkId("myVnfId_vlId");
         when(networkApi.getNetworkL3NetworksL3Network("myVnfId_vlId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(l3Network));
+        when(networkApi.deleteNetworkL3NetworksL3Network("myVnfId_vlId", "v3")).thenReturn(VOID_OBSERVABLE.value());
         //when
         l3NetworkManager.delete(VNF_ID, affectedVirtualLink);
         //verify
         networkApi.deleteNetworkL3NetworksL3Network("myVnfId_vlId", "v3");
+        VOID_OBSERVABLE.assertCalled();
     }
 
     /**
index 3728bdb..0ac9333 100644 (file)
@@ -72,7 +72,7 @@ public class TestLInterfaceManager extends TestBase {
         lInterface.setResourceVersion("v3");
         lInterface.setRelationshipList(new ArrayList<>());
         when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", "cpId", null, null, null, null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(lInterface));
-        when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(null);
+        when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
         //when
         lInterfaceManager.update(VNF_ID, VIM_ID, affectedCp, true);
         //verify
@@ -90,6 +90,7 @@ public class TestLInterfaceManager extends TestBase {
         assertEquals("networkProviderId", actualInterface.getL3InterfaceIpv4AddressList().get(0).getNeutronNetworkId());
         assertEquals("1.2.3.4", actualInterface.getL3InterfaceIpv4AddressList().get(0).getL3InterfaceIpv4Address());
         assertRelation(actualInterface.getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
+        VOID_OBSERVABLE.assertCalled();
     }
 
     /**
@@ -109,9 +110,8 @@ public class TestLInterfaceManager extends TestBase {
         affectedCp.setCpId("cpId");
         LInterface lInterface = new LInterface();
         lInterface.setResourceVersion("v3");
-        lInterface.setRelationshipList(new ArrayList<>());
         when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", "cpId", null, null, null, null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(lInterface));
-        when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(null);
+        when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
         //when
         lInterfaceManager.update(VNF_ID, VIM_ID, affectedCp, true);
         //verify
@@ -127,6 +127,7 @@ public class TestLInterfaceManager extends TestBase {
         assertEquals(null, actualInterface.getL3InterfaceIpv6AddressList());
         assertEquals(null, actualInterface.getL3InterfaceIpv4AddressList());
         assertRelation(actualInterface.getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
+        VOID_OBSERVABLE.assertCalled();
     }
 
     /**
@@ -148,8 +149,9 @@ public class TestLInterfaceManager extends TestBase {
         LInterface lInterface = new LInterface();
         lInterface.setResourceVersion("v3");
         lInterface.setRelationshipList(new ArrayList<>());
+        lInterface.getRelationshipList().add(VserverManager.linkTo(VIM_ID, "b", "c"));
         when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", "cpId", null, null, null, null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(lInterface));
-        when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(null);
+        when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
         //when
         lInterfaceManager.update(VNF_ID, VIM_ID, affectedCp, true);
         //verify
@@ -168,6 +170,8 @@ public class TestLInterfaceManager extends TestBase {
         assertEquals("1.2.3.4", actualInterface.getL3InterfaceIpv4AddressList().get(0).getL3InterfaceIpv4Address());
         assertEquals("v3", lInterface.getResourceVersion());
         assertRelation(actualInterface.getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
+        assertEquals(2, lInterface.getRelationshipList().size());
+        VOID_OBSERVABLE.assertCalled();
     }
 
     /**
@@ -190,7 +194,7 @@ public class TestLInterfaceManager extends TestBase {
         lInterface.setResourceVersion("v3");
         lInterface.setRelationshipList(new ArrayList<>());
         when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", "cpId", null, null, null, null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(lInterface));
-        when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(null);
+        when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
         //when
         lInterfaceManager.update(VNF_ID, VIM_ID, affectedCp, false);
         //verify
@@ -230,6 +234,7 @@ public class TestLInterfaceManager extends TestBase {
         lInterfaceManager.delete(VIM_ID, affectedCp);
         //verify
         cloudInfrastructureApi.deleteCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", "cpId", "v3");
+        VOID_OBSERVABLE.assertCalled();
     }
 
     /**
index 8b41c3f..efec7b3 100644 (file)
@@ -17,6 +17,7 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
 
 import com.nokia.cbam.lcm.v32.model.AffectedVnfc;
 import com.nokia.cbam.lcm.v32.model.ResourceHandle;
+import java.util.ArrayList;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
@@ -62,8 +63,10 @@ public class TestVnfcManager extends TestBase {
         affectedVnfc.getComputeResource().setResourceId("serverProviderId");
         affectedVnfc.setId("vnfcId");
         Vnfc existingVnfc = new Vnfc();
+        existingVnfc.setRelationshipList(new ArrayList<>());
+        existingVnfc.getRelationshipList().add(GenericVnfManager.linkTo("any"));
         when(networkApi.getNetworkVnfcsVnfc("myVnfId_vnfcId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVnfc));
-        when(networkApi.createOrUpdateNetworkVnfcsVnfc(eq("myVnfId_vnfcId"), payload.capture())).thenReturn(null);
+        when(networkApi.createOrUpdateNetworkVnfcsVnfc(eq("myVnfId_vnfcId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
         //when
         vnfcManager.update(VIM_ID, "myTenantPrivderId", VNF_ID, affectedVnfc, true);
         //verify
@@ -78,6 +81,8 @@ public class TestVnfcManager extends TestBase {
                 buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)),
                 buildRelationshipData("tenant.tenant-id", "myTenantPrivderId"),
                 buildRelationshipData("vserver.vserver-id", "serverProviderId"));
+        assertEquals(2, vnfc.getRelationshipList().size());
+        VOID_OBSERVABLE.assertCalled();
     }
 
     /**
@@ -93,10 +98,12 @@ public class TestVnfcManager extends TestBase {
         existingVnfc.setResourceVersion("v3");
         existingVnfc.setVnfcName("myVnfId_vnfcId");
         when(networkApi.getNetworkVnfcsVnfc("myVnfId_vnfcId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVnfc));
+        when(networkApi.deleteNetworkVnfcsVnfc("myVnfId_vnfcId", "v3")).thenReturn(VOID_OBSERVABLE.value());
         //when
         vnfcManager.delete(VNF_ID, affectedVnfc);
         //verify
         verify(networkApi).deleteNetworkVnfcsVnfc("myVnfId_vnfcId", "v3");
+        VOID_OBSERVABLE.assertCalled();
     }
 
     /**
index 68f5ab5..5140c55 100644 (file)
@@ -91,12 +91,11 @@ public class TestVserverManager extends TestBase {
         affectedVnfc.setStorageResourceIds(new ArrayList<>());
         affectedVnfc.getStorageResourceIds().add("sId");
 
-        String url = "/cloud-regions/cloud-region///tenants/tenant//vservers/vserver/";
-
         Vserver existingVserver = new Vserver();
-        existingVserver.setVolumes(new ArrayList<>());
+        existingVserver.setRelationshipList(new ArrayList<>());
+        existingVserver.getRelationshipList().add(VserverManager.linkTo(VIM_ID, "tenantId", "serverId2"));
         when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVserver));
-        when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(null);
+        when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
         //when
         vserverManager.update(VIM_ID, VNF_ID, affectedVnfc, affectedStorages, true);
         //verify
@@ -107,6 +106,8 @@ public class TestVserverManager extends TestBase {
         assertEquals("url", vserver.getVserverSelflink());
         assertEquals(1, vserver.getVolumes().size());
         assertEquals("storageProviderId", vserver.getVolumes().get(0).getVolumeId());
+        assertEquals(2, vserver.getRelationshipList().size());
+        VOID_OBSERVABLE.assertCalled();
     }
 
     /**
@@ -135,7 +136,7 @@ public class TestVserverManager extends TestBase {
         Vserver existingVserver = new Vserver();
         existingVserver.setVolumes(new ArrayList<>());
         when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVserver));
-        when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(null);
+        when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
         //when
         vserverManager.update(VIM_ID, VNF_ID, affectedVnfc, affectedStorages, true);
         //verify
@@ -146,6 +147,7 @@ public class TestVserverManager extends TestBase {
         assertEquals("unknown", vserver.getVserverSelflink());
         assertEquals(1, vserver.getVolumes().size());
         assertEquals("storageProviderId", vserver.getVolumes().get(0).getVolumeId());
+        VOID_OBSERVABLE.assertCalled();
     }
 
     /**
@@ -172,7 +174,7 @@ public class TestVserverManager extends TestBase {
         Vserver existingVserver = new Vserver();
         existingVserver.setVolumes(new ArrayList<>());
         when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVserver));
-        when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(null);
+        when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
         //when
         vserverManager.update(VIM_ID, VNF_ID, affectedVnfc, affectedStorages, true);
         //verify
@@ -183,6 +185,7 @@ public class TestVserverManager extends TestBase {
         assertEquals("unknown", vserver.getVserverSelflink());
         assertEquals(1, vserver.getVolumes().size());
         assertEquals("storageProviderId", vserver.getVolumes().get(0).getVolumeId());
+        VOID_OBSERVABLE.assertCalled();
     }
 
     /**
@@ -202,7 +205,7 @@ public class TestVserverManager extends TestBase {
         Vserver existingVserver = new Vserver();
         existingVserver.setVolumes(new ArrayList<>());
         when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVserver));
-        when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(null);
+        when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
         //when
         vserverManager.update(VIM_ID, VNF_ID, affectedVnfc, affectedStorages, true);
         //verify
@@ -237,6 +240,7 @@ public class TestVserverManager extends TestBase {
         vserverManager.delete(VIM_ID, affectedVnfc);
         //verify
         verify(cloudInfrastructureApi).deleteCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", "v3");
+        VOID_OBSERVABLE.assertCalled();
     }
 
     @Test
index 190f78e..a699ee9 100644 (file)
@@ -22,6 +22,7 @@ import com.nokia.cbam.lcm.v32.api.OperationExecutionsApi;
 import com.nokia.cbam.lcm.v32.api.VnfsApi;
 import com.nokia.cbam.lcn.v32.api.SubscriptionsApi;
 import io.reactivex.Observable;
+import io.reactivex.internal.operators.observable.ObservableFromCallable;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.lang.reflect.Field;
@@ -29,9 +30,11 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.Callable;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
 import javax.servlet.http.HttpServletResponse;
+import junit.framework.TestCase;
 import okhttp3.RequestBody;
 import okio.Buffer;
 import org.apache.commons.lang3.ArrayUtils;
@@ -68,7 +71,9 @@ import static junit.framework.TestCase.assertTrue;
 import static org.mockito.Mockito.when;
 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CatalogManager.getFileInZip;
 
+
 public class TestBase {
+
     public static final String VNF_ID = "myVnfId";
     public static final String VNFM_ID = "myVnfmId";
     public static final String ONAP_CSAR_ID = "myOnapCsarId";
@@ -76,6 +81,7 @@ public class TestBase {
     public static final String JOB_ID = "myJobId";
     public static final String CBAM_VNFD_ID = "cbamVnfdId";
     protected static Call<Void> VOID_CALL = buildCall(null);
+    protected static VoidObservable VOID_OBSERVABLE = new VoidObservable();
     @Mock
     protected CbamRestApiProvider cbamRestApiProvider;
     @Mock
@@ -210,4 +216,23 @@ public class TestBase {
             }
         }
     }
+
+    protected static class VoidObservable {
+        boolean called = false;
+        ObservableFromCallable<Void> s = new ObservableFromCallable(new Callable() {
+            @Override
+            public Object call() throws Exception {
+                called = true;
+                return "";
+            }
+        });
+
+        public void assertCalled() {
+            TestCase.assertTrue(called);
+        }
+
+        public Observable<Void> value() {
+            return s;
+        }
+    }
 }
index 743fb95..b34bc1d 100644 (file)
@@ -497,6 +497,51 @@ public class TestJobManager extends TestBase {
         assertTrue(jobManager.hasOngoingJobs());
     }
 
+    /**
+     * the modify attribute job is skipped, since it is not explicitly triggered by any external job
+     */
+    @Test
+    public void testModifyAttributesOperationExecutionIsSkipped() throws Exception {
+        String jobId = jobManager.spawnJob(VNF_ID, httpResponse);
+        VnfInfo vnf = new VnfInfo();
+        vnf.setId(VNF_ID);
+        vnfs.add(vnf);
+        VnfInfo detailedVnf = new VnfInfo();
+        detailedVnf.setId(VNF_ID);
+        when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(detailedVnf));
+        OperationExecution olderOperation = new OperationExecution();
+        olderOperation.setId(UUID.randomUUID().toString());
+        olderOperation.setStartTime(OffsetDateTime.now());
+        olderOperation.setStatus(OperationStatus.FINISHED);
+        olderOperation.setOperationType(OperationType.TERMINATE);
+        OperationExecution newerOperation = new OperationExecution();
+        newerOperation.setId(UUID.randomUUID().toString());
+        newerOperation.setStartTime(OffsetDateTime.now().plusDays(1));
+        newerOperation.setStatus(OperationStatus.FINISHED);
+        newerOperation.setOperationType(OperationType.MODIFY_INFO);
+        detailedVnf.setOperationExecutions(new ArrayList<>());
+        detailedVnf.getOperationExecutions().add(olderOperation);
+        detailedVnf.getOperationExecutions().add(newerOperation);
+        JsonElement operationParams = new JsonParser().parse("{ \"additionalParams\" : { \"jobId\" : \"" + jobId + "\"}}");
+        List<String> queriedOperaionsInOrder = new ArrayList<>();
+        when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(Mockito.anyString(), Mockito.eq(NOKIA_LCM_API_VERSION)))
+                .then(new Answer<Observable<Object>>() {
+                    @Override
+                    public Observable<Object> answer(InvocationOnMock invocationOnMock) throws Throwable {
+                        queriedOperaionsInOrder.add(invocationOnMock.getArguments()[0].toString());
+                        if (invocationOnMock.getArguments()[0].equals(olderOperation.getId())) {
+                            return buildObservable(new JsonParser().parse("{ \"additionalParams\" : { \"jobId\" : \"" + jobId + "\"}}"));
+                        } else {
+                            throw new RuntimeException(); //this should be never reached
+                        }
+                    }
+                });
+        JobDetailInfo job = jobManager.getJob(VNFM_ID, jobId);
+        //verify
+        assertEquals(Lists.newArrayList(olderOperation.getId()), queriedOperaionsInOrder);
+        assertTrue(jobManager.hasOngoingJobs());
+    }
+
     /**
      * if the registration process has not finished it is prevented to spawn jobs
      */
index b7e30e2..178f0b5 100644 (file)
@@ -746,8 +746,7 @@ public class TestLifecycleManager extends TestBase {
                 return buildObservable(terminationOperation);
             }
         });
-        Observable<Void> delete = Mockito.mock(Observable.class);
-        when(vnfApi.vnfsVnfInstanceIdDelete(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(delete);
+        when(vnfApi.vnfsVnfInstanceIdDelete(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(VOID_OBSERVABLE.value());
         JsonElement instantiationParameters = new JsonParser().parse("{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] } ");
         when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet("operationExecutionId", NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(instantiationParameters));
         //when
@@ -761,7 +760,7 @@ public class TestLifecycleManager extends TestBase {
         notificationIsProcessedBeforeDeletingTheVnf.verify(vfcGrantManager).requestGrantForTerminate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, vnfInfo, JOB_ID);
         notificationIsProcessedBeforeDeletingTheVnf.verify(notificationManager).waitForTerminationToBeProcessed("terminationId");
         notificationIsProcessedBeforeDeletingTheVnf.verify(vnfApi).vnfsVnfInstanceIdDelete(VNF_ID, NOKIA_LCM_API_VERSION);
-        verify(systemFunctions).blockingFirst(delete);
+        VOID_OBSERVABLE.assertCalled();
         verify(jobManager).spawnJob(VNF_ID, restResponse);
         verify(logger).info(eq("Starting {} operation on VNF with {} identifier with {} parameter"), eq("termination"), eq(VNF_ID), anyString());
     }
index d668262..640d29b 100644 (file)
@@ -41,6 +41,8 @@ import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.*;
 import static org.onap.msb.model.MicroServiceInfo.ProtocolEnum.REST;
 import static org.onap.msb.model.MicroServiceInfo.VisualRangeEnum._1;
+import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager.DRIVER_VERSION;
+import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager.SERVICE_NAME;
 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider.NOKIA_LCN_API_VERSION;
 import static org.springframework.test.util.ReflectionTestUtils.setField;
 
@@ -123,7 +125,7 @@ public class TestSelfRegistrationManager extends TestBase {
         assertEquals(REST, microserviceRequest.getProtocol());
         assertNull(microserviceRequest.getMetadata());
         //very strange, but it should be null for ONAP to work
-        assertEquals(SelfRegistrationManager.SERVICE_NAME, microserviceRequest.getServiceName());
+        assertEquals(SERVICE_NAME, microserviceRequest.getServiceName());
         assertEquals("/api/NokiaSVNFM/v1", microserviceRequest.getUrl());
         assertEquals("v1", microserviceRequest.getVersion());
         assertEquals(Boolean.FALSE, microserviceRequest.isEnableSsl());
@@ -183,6 +185,7 @@ public class TestSelfRegistrationManager extends TestBase {
             subscription.setCallbackUrl("http://5.6.7.8:12345/api/NokiaSVNFM/v1/lcn");
             subscription.setId(UUID.randomUUID().toString());
             subscriptions.add(subscription);
+            when(lcnApi.subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION)).thenReturn(VOID_OBSERVABLE.value());
             return buildObservable(subscription);
         });
         MicroServiceFullInfo returnedMicroService = new MicroServiceFullInfo();
@@ -215,16 +218,18 @@ public class TestSelfRegistrationManager extends TestBase {
         subscription.setId(UUID.randomUUID().toString());
         subscriptions.add(subscription);
         when(jobManager.hasOngoingJobs()).thenReturn(false);
-        Observable delete = Mockito.mock(Observable.class);
-        when(lcnApi.subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION)).thenReturn(delete);
+        when(lcnApi.subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION)).thenReturn(VOID_OBSERVABLE.value());
+        VoidObservable MSB_DELETE = new VoidObservable();
+        when(msbClient.deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null)).thenReturn(MSB_DELETE.value());
         //when
         selfRegistrationManager.deRegister();
         //verify
         InOrder inOrder = Mockito.inOrder(jobManager, msbClient, lcnApi);
-        inOrder.verify(msbClient).deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null);
+        inOrder.verify(msbClient).deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null);
         inOrder.verify(lcnApi).subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION);
         assertServiceDown();
-        verify(systemFunctions).blockingFirst(delete);
+        VOID_OBSERVABLE.assertCalled();
+        MSB_DELETE.assertCalled();
         verify(logger).info("Deleting subscription with {} identifier", subscription.getId());
     }
 
@@ -240,22 +245,23 @@ public class TestSelfRegistrationManager extends TestBase {
         subscription.setId(UUID.randomUUID().toString());
         subscriptions.add(subscription);
         when(jobManager.hasOngoingJobs()).thenReturn(false);
-        when(msbClient.deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null)).then(new Answer<Observable<Void>>() {
+        when(msbClient.deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null)).then(new Answer<Observable<Void>>() {
             @Override
             public Observable<Void> answer(InvocationOnMock invocationOnMock) throws Throwable {
-                when(msbClient.getMicroService_0(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null, null, null, null)).thenThrow(new RuntimeException());
+                when(msbClient.getMicroService_0(SERVICE_NAME, DRIVER_VERSION, null, null, null, null, null)).thenThrow(new RuntimeException());
                 throw new RuntimeException();
             }
         });
-        MicroServiceFullInfo returnedMicroService = new MicroServiceFullInfo();
+        when(lcnApi.subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION)).thenReturn(VOID_OBSERVABLE.value());
         //when
         selfRegistrationManager.deRegister();
         //verify
         InOrder inOrder = Mockito.inOrder(jobManager, msbClient, lcnApi);
-        inOrder.verify(msbClient).deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null);
-        inOrder.verify(msbClient).getMicroService_0(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null, null, null, null);
+        inOrder.verify(msbClient).deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null);
+        inOrder.verify(msbClient).getMicroService_0(SERVICE_NAME, DRIVER_VERSION, null, null, null, null, null);
         inOrder.verify(lcnApi).subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION);
         assertServiceDown();
+        VOID_OBSERVABLE.assertCalled();
     }
 
     /**
@@ -268,7 +274,7 @@ public class TestSelfRegistrationManager extends TestBase {
         subscription.setCallbackUrl("http://5.6.7.8:12345/api/NokiaSVNFM/v1/lcn");
         subscription.setId(UUID.randomUUID().toString());
         subscriptions.add(subscription);
-        when(msbClient.deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null)).then(new Answer<Observable<Void>>() {
+        when(msbClient.deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null)).then(new Answer<Observable<Void>>() {
             @Override
             public Observable<Void> answer(InvocationOnMock invocationOnMock) throws Throwable {
                 throw new RuntimeException();
@@ -283,8 +289,8 @@ public class TestSelfRegistrationManager extends TestBase {
         }
         //verify
         InOrder inOrder = Mockito.inOrder(jobManager, msbClient, lcnApi);
-        inOrder.verify(msbClient).deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null);
-        inOrder.verify(msbClient).getMicroService_0(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null, null, null, null);
+        inOrder.verify(msbClient).deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null);
+        inOrder.verify(msbClient).getMicroService_0(SERVICE_NAME, DRIVER_VERSION, null, null, null, null, null);
         verify(lcnApi, Mockito.never()).subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION);
         assertServiceDown();
     }
@@ -302,6 +308,7 @@ public class TestSelfRegistrationManager extends TestBase {
         when(jobManager.hasOngoingJobs()).thenReturn(false);
         RuntimeException expectedException = new RuntimeException();
         doThrow(expectedException).when(lcnApi).subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION);
+        when(msbClient.deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null)).thenReturn(VOID_OBSERVABLE.value());
         //when
         try {
             selfRegistrationManager.deRegister();
@@ -311,7 +318,7 @@ public class TestSelfRegistrationManager extends TestBase {
         }
         //verify
         InOrder inOrder = Mockito.inOrder(jobManager, msbClient, lcnApi);
-        inOrder.verify(msbClient).deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null);
+        inOrder.verify(msbClient).deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null);
         inOrder.verify(lcnApi).subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION);
         assertServiceDown();
     }
index 922e92b..449217f 100644 (file)
@@ -426,6 +426,24 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
         verify(logger).warn("Unable to send information related to affected connection points during forceful termination");
     }
 
+    /**
+     * Forceful termination results in an empty affected connection points
+     */
+    @Test
+    public void testGracefullTermination() {
+        //given
+        recievedLcn.setOperation(OperationType.INSTANTIATE);
+        recievedLcn.setStatus(OperationStatus.FINISHED);
+        recievedLcn.setLifecycleOperationOccurrenceId(terminationOperation.getId());
+        ((JsonObject) terminationOperation.getOperationParams()).addProperty("terminationType", "GRACEFUL");
+        addEmptyModifiedConnectionPoints(terminationOperation);
+        terminationOperation.setStatus(OperationStatus.FINISHED);
+        terminationOperation.setOperationType(OperationType.TERMINATE);
+        //when
+        lifecycleChangeNotificationManager.handleLcn(recievedLcn);
+        assertTrue(affectedConnectionPoints.getValue().isPresent());
+    }
+
     /**
      * Failures in affected connection point processing are tolerated for failed operation
      * (because the POST script was not able to run)