summaryrefslogtreecommitdiffstats
path: root/nokiav2/driver/src
diff options
context:
space:
mode:
authorDenes Nemeth <denes.nemeth@nokia.com>2018-03-24 14:00:54 +0100
committerDenes Nemeth <denes.nemeth@nokia.com>2018-03-25 21:32:03 +0200
commitc82c886215ed34953a51dff0710c6bd15cb80ee4 (patch)
tree783f928ba8e033bbf55b6cffa343c7ea47c40b59 /nokiav2/driver/src
parent1489e4215e075ab3ffe8f7158559a38778cd0b34 (diff)
Removing jackson to mitigate cve-2017-4995
Signed-off-by: Denes Nemeth <denes.nemeth@nokia.com> Issue-ID: VFC-728 Change-Id: Ib495d4706361cc39527dfe86463aa505d9564afa
Diffstat (limited to 'nokiav2/driver/src')
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/api/INotificationSender.java3
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/GenericExternalSystemInfoProvider.java4
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/IpMappingProvider.java7
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/MsbApiProvider.java27
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/SelfRegistrationManager.java49
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/AAIExternalSystemInfoProvider.java33
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/AAIRestApiProvider.java141
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/AaiSecurityProvider.java48
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/SdcPackageProvider.java6
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/AAINotificationProcessor.java9
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/AbstractManager.java41
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/GenericVnfManager.java24
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/L3NetworkManager.java26
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/LInterfaceManager.java54
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/VnfcManager.java37
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/VserverManager.java51
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcGrantManager.java3
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcNotificationSender.java6
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcPackageProvider.java7
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/CbamVnfPackageBuilder.java1
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/CbamVnfdBuilder.java10
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/OnapVnfPackageBuilder.java1
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/OnapVnfdBuilder.java5
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/ConverterApi.java15
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/LcmApi.java6
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/LcnApi.java10
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/SwaggerApi.java5
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/Conditions.java5
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/RealConfig.java10
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/StoreLoader.java4
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/SystemFunctions.java20
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/AdditionalParameters.java1
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CatalogManager.java13
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamSecurityProvider.java92
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamTokenProvider.java7
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/DriverProperties.java3
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/GenericSecurityProvider.java111
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/JobManager.java16
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/LifecycleManager.java17
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/LifecycleChangeNotificationManager.java14
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/ProcessedNotification.java1
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/ReportedAffectedConnectionPoints.java1
-rw-r--r--nokiav2/driver/src/test/java/okhttp3/OakExtractor.java28
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/FullUnitTestSuite.java2
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/ct/CTDirectReal.java3
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestGenericExternalSystemInfoProvider.java1
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestMsbApiProvider.java61
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIExternalSystemInfoProvider.java51
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIRestApiProvider.java310
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAaiSecurityProvider.java42
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestSdcPackageProvider.java7
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAAINotificationProcessor.java8
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAbstractManager.java146
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestGenericVnfManager.java94
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestL3NetworkManager.java32
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestLInterfaceManager.java84
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVnfcManager.java25
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVserverManager.java74
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcGrantManager.java10
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcNotificationSender.java6
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcPackageProvider.java5
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfPackageBuilder.java7
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java3
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java15
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcmApi.java1
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcnApi.java2
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerApi.java3
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerDefinitionConsistency.java11
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestRealConfig.java29
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestSecurityConfig.java5
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestStoreLoader.java5
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestSystemFunctions.java3
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestUtil.java1
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/HttpTestServer.java15
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestAdditionalParams.java7
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestBase.java32
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamCatalogManager.java11
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamRestApiProvider.java26
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamSecurityProvider.java306
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamTokenProvider.java5
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestGenericSecurityProvider.java326
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestJobManager.java19
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManager.java12
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestSelfRegistrationManager.java73
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/TestLifecycleChangeNotificationManager.java46
-rw-r--r--nokiav2/driver/src/test/resources/unittests/packageconverter/cbam.full.modified.vnfd.yaml93
-rw-r--r--nokiav2/driver/src/test/resources/unittests/packageconverter/cbam.minimal.modified.vnfd.yaml45
87 files changed, 1598 insertions, 1436 deletions
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/api/INotificationSender.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/api/INotificationSender.java
index 55e9cca2..87f56db2 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/api/INotificationSender.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/api/INotificationSender.java
@@ -17,9 +17,8 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api;
import com.nokia.cbam.lcm.v32.model.OperationExecution;
import com.nokia.cbam.lcm.v32.model.VnfLifecycleChangeNotification;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.ReportedAffectedConnectionPoints;
-
import java.util.Optional;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.ReportedAffectedConnectionPoints;
/**
* Responsible for processing the preprocessed notification from CBAM and making the changes
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/GenericExternalSystemInfoProvider.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/GenericExternalSystemInfoProvider.java
index 13b070a7..38665877 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/GenericExternalSystemInfoProvider.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/GenericExternalSystemInfoProvider.java
@@ -17,6 +17,7 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
+import java.util.concurrent.TimeUnit;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.VimInfoProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.VnfmInfoProvider;
import org.onap.vnfmdriver.model.VnfmInfo;
@@ -24,10 +25,9 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.env.Environment;
-import java.util.concurrent.TimeUnit;
+import static java.lang.Long.valueOf;
import static com.google.common.cache.CacheBuilder.newBuilder;
-import static java.lang.Long.valueOf;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.buildFatalFailure;
import static org.slf4j.LoggerFactory.getLogger;
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/IpMappingProvider.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/IpMappingProvider.java
index ec6db5e4..99fe615d 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/IpMappingProvider.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/IpMappingProvider.java
@@ -15,15 +15,14 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-
import static com.google.common.base.Splitter.on;
import static com.google.common.collect.Lists.newArrayList;
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/MsbApiProvider.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/MsbApiProvider.java
index 64a418de..c9edf895 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/MsbApiProvider.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/MsbApiProvider.java
@@ -15,17 +15,17 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core;
-import org.onap.msb.sdk.discovery.common.RouteException;
-import org.onap.msb.sdk.discovery.entity.MicroServiceFullInfo;
-import org.onap.msb.sdk.discovery.entity.NodeInfo;
-import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
+import com.google.common.annotations.VisibleForTesting;
+import org.onap.msb.ApiClient;
+import org.onap.msb.api.ServiceResourceApi;
+import org.onap.msb.model.MicroServiceFullInfo;
+import org.onap.msb.model.NodeInfo;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
-import static java.lang.Integer.valueOf;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.buildFatalFailure;
import static org.slf4j.LoggerFactory.getLogger;
@@ -48,8 +48,15 @@ public class MsbApiProvider extends IpMappingProvider {
/**
* @return API to access ONAP MSB
*/
- public MSBServiceClient getMsbClient() {
- return new MSBServiceClient(messageBusIp, valueOf(messageBusPort));
+ public ServiceResourceApi getMsbApi() {
+ return buildApiClient().createService(ServiceResourceApi.class);
+ }
+
+ @VisibleForTesting
+ ApiClient buildApiClient() {
+ ApiClient apiClient = new ApiClient();
+ apiClient.setAdapterBuilder(apiClient.getAdapterBuilder().baseUrl("http://" + messageBusIp + ":" + messageBusPort + "/api/msdiscover/v1/"));
+ return apiClient;
}
/**
@@ -60,15 +67,15 @@ public class MsbApiProvider extends IpMappingProvider {
public String getMicroServiceUrl(String name, String version) {
MicroServiceFullInfo microServiceFullInfo = getMicroServiceInfo(name, version);
String ipAnPort = getNodeIpAnPort(microServiceFullInfo);
- String protocol = microServiceFullInfo.isEnable_ssl() ? "https://" : "http://";
+ String protocol = microServiceFullInfo.isEnableSsl() ? "https://" : "http://";
//the field name in A&AI is misleading the URL is relative path postfixed to http(s)://ip:port
return protocol + ipAnPort + microServiceFullInfo.getUrl();
}
private MicroServiceFullInfo getMicroServiceInfo(String name, String version) {
try {
- return getMsbClient().queryMicroServiceInfo(name, version);
- } catch (RouteException e) {
+ return getMsbApi().getMicroService_0(name, version, null, null, null, null, null).blockingFirst();
+ } catch (Exception e) {
throw buildFatalFailure(logger, "Unable to get micro service URL for " + name + " with version " + version, e);
}
}
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/SelfRegistrationManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/SelfRegistrationManager.java
index 92064b16..0c57c376 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/SelfRegistrationManager.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/SelfRegistrationManager.java
@@ -18,11 +18,10 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core;
import com.nokia.cbam.lcn.v32.api.SubscriptionsApi;
import com.nokia.cbam.lcn.v32.model.*;
-import org.onap.msb.sdk.discovery.common.RouteException;
-import org.onap.msb.sdk.discovery.entity.MicroServiceFullInfo;
-import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;
-import org.onap.msb.sdk.discovery.entity.Node;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions;
+import java.util.ArrayList;
+import org.onap.msb.model.MicroServiceFullInfo;
+import org.onap.msb.model.MicroServiceInfo;
+import org.onap.msb.model.Node;
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;
@@ -30,11 +29,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
-import java.util.ArrayList;
-import java.util.HashSet;
-
import static com.nokia.cbam.lcn.v32.model.SubscriptionAuthentication.TypeEnum.NONE;
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;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider.NOKIA_LCN_API_VERSION;
import static org.slf4j.LoggerFactory.getLogger;
@@ -89,17 +86,20 @@ public class SelfRegistrationManager {
public void deRegister() {
try {
logger.info("Cancelling micro service registration");
- msbApiProvider.getMsbClient().cancelMicroServiceInfo(SERVICE_NAME, DRIVER_VERSION);
- } catch (RouteException e) {
+ systemFunctions().blockingFirst(msbApiProvider.getMsbApi().deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null));
+ } catch (Exception e) {
//ONAP throws 500 internal server error, but deletes the micro service
+ boolean serviceFoundAfterDelete = false;
try {
- msbApiProvider.getMsbClient().queryMicroServiceInfo(SERVICE_NAME, DRIVER_VERSION);
- //the micro service still exists
- throw buildFatalFailure(logger, "Unable to deRegister Nokia VNFM driver", e);
- } catch (RouteException e1) {
+ msbApiProvider.getMsbApi().getMicroService_0(SERVICE_NAME, DRIVER_VERSION, null, null, null, null, null);
+ serviceFoundAfterDelete = true;
+ } catch (Exception e1) {
logger.info("Unable to query " + SERVICE_NAME + " from MSB (so the service was successfully deleted)", e1);
// the micro service was deleted (even though 500 HTTP code was reported)
}
+ if (serviceFoundAfterDelete) {
+ throw buildFatalFailure(logger, "Unable to deRegister Nokia VNFM driver", e);
+ }
}
deleteSubscription(driverProperties.getVnfmId());
}
@@ -108,7 +108,7 @@ public class SelfRegistrationManager {
* @return the swagger API definition
*/
public byte[] getSwaggerApiDefinition() {
- return SystemFunctions.systemFunctions().loadFile(SWAGGER_API_DEFINITION);
+ return systemFunctions().loadFile(SWAGGER_API_DEFINITION);
}
private String getDriverVnfmUrl() {
@@ -122,7 +122,8 @@ public class SelfRegistrationManager {
String callbackUrl = getDriverVnfmUrl() + DriverProperties.LCN_URL;
for (Subscription subscription : lcnApi.subscriptionsGet(NOKIA_LCN_API_VERSION).blockingFirst()) {
if (subscription.getCallbackUrl().equals(callbackUrl)) {
- lcnApi.subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION);
+ logger.info("Deleting subscription with {} identifier", subscription.getId());
+ systemFunctions().blockingFirst(lcnApi.subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION));
}
}
} catch (Exception e) {
@@ -135,20 +136,20 @@ public class SelfRegistrationManager {
MicroServiceInfo microServiceInfo = new MicroServiceInfo();
microServiceInfo.setUrl(DriverProperties.BASE_URL);
//the PATH should not be set
- microServiceInfo.setProtocol("REST");
- microServiceInfo.setVisualRange(INTERNAL_SERVICE);
+ microServiceInfo.setProtocol(MicroServiceInfo.ProtocolEnum.REST);
+ microServiceInfo.setVisualRange(MicroServiceInfo.VisualRangeEnum._1);
microServiceInfo.setServiceName(SERVICE_NAME);
microServiceInfo.setVersion(DRIVER_VERSION);
- microServiceInfo.setEnable_ssl(false);
+ microServiceInfo.setEnableSsl(false);
Node node = new Node();
- microServiceInfo.setNodes(new HashSet<>());
+ microServiceInfo.setNodes(new ArrayList<>());
microServiceInfo.getNodes().add(node);
node.setIp(driverMsbExternalIp);
node.setPort(driverPort);
node.setTtl("0");
try {
- return msbApiProvider.getMsbClient().registerMicroServiceInfo(microServiceInfo);
- } catch (RouteException e) {
+ return msbApiProvider.getMsbApi().addMicroService(microServiceInfo, true, false).blockingFirst();
+ } catch (Exception e) {
throw buildFatalFailure(logger, "Unable to register Nokia VNFM driver", e);
}
}
@@ -160,6 +161,7 @@ public class SelfRegistrationManager {
try {
for (Subscription subscription : lcnApi.subscriptionsGet(NOKIA_LCN_API_VERSION).blockingFirst()) {
if (subscription.getCallbackUrl().equals(callbackUrl)) {
+ logger.warn("The subscription with {} identifier has the same callback URL", subscription.getId());
return;
}
}
@@ -175,7 +177,8 @@ public class SelfRegistrationManager {
SubscriptionAuthentication subscriptionAuthentication = new SubscriptionAuthentication();
subscriptionAuthentication.setType(NONE);
request.setAuthentication(subscriptionAuthentication);
- lcnApi.subscriptionsPost(request, NOKIA_LCN_API_VERSION);
+ Subscription createdSubscription = lcnApi.subscriptionsPost(request, NOKIA_LCN_API_VERSION).blockingFirst();
+ logger.info("Subscribed to LCN with {} identifier", createdSubscription.getId());
} catch (Exception e) {
throw buildFatalFailure(logger, "Unable to subscribe to CBAM LCN", e);
}
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/AAIExternalSystemInfoProvider.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/AAIExternalSystemInfoProvider.java
index f5656f75..81834bcb 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/AAIExternalSystemInfoProvider.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/AAIExternalSystemInfoProvider.java
@@ -15,9 +15,8 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct;
-import org.onap.aai.domain.yang.v11.EsrSystemInfo;
-import org.onap.aai.domain.yang.v11.EsrSystemInfoList;
-import org.onap.aai.domain.yang.v11.EsrVnfm;
+import org.onap.aai.model.EsrSystemInfo;
+import org.onap.aai.model.EsrVnfm;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.GenericExternalSystemInfoProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring.Conditions;
import org.onap.vnfmdriver.model.VimInfo;
@@ -28,9 +27,6 @@ import org.springframework.context.annotation.Conditional;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
-import static java.lang.String.format;
-import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider.AAIService.CLOUD;
-import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider.AAIService.ESR;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.buildFatalFailure;
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;
@@ -42,8 +38,6 @@ import static org.slf4j.LoggerFactory.getLogger;
@Component
@Conditional(value = Conditions.UseForDirect.class)
public class AAIExternalSystemInfoProvider extends GenericExternalSystemInfoProvider {
- private static final String VNFM_URL = "/esr-vnfm-list/esr-vnfm/%s?depth=all";
- private static final String VIM_URL = "/cloud-regions/cloud-region/%s/%s/esr-system-info-list";
private static Logger logger = getLogger(AAIExternalSystemInfoProvider.class);
private final AAIRestApiProvider aaiRestApiProvider;
@@ -55,20 +49,20 @@ public class AAIExternalSystemInfoProvider extends GenericExternalSystemInfoProv
@Override
public VnfmInfo queryVnfmInfoFromSource(String vnfmId) {
+ return convertEsrToVnfmInfo(getEsrVnfm(vnfmId));
+ }
+
+ private EsrVnfm getEsrVnfm(String vnfmId) {
try {
- return convertEsrToVnfmInfo(aaiRestApiProvider.get(logger, ESR, format(VNFM_URL, vnfmId), EsrVnfm.class));
- } catch (RuntimeException e) {
+ return aaiRestApiProvider.getExternalSystemApi().getExternalSystemEsrVnfmListEsrVnfm(vnfmId).blockingFirst();
+ } catch (Exception e) {
throw buildFatalFailure(logger, "Unable to query VNFM with " + vnfmId + " identifier from AAI", e);
}
}
@Override
public VimInfo getVimInfo(String vimId) {
- try {
- return convertEsrToVim(getEsrSystemInfo(vimId), vimId);
- } catch (RuntimeException e) {
- throw buildFatalFailure(logger, "Unable to query VIM with " + vimId + " identifier from AAI", e);
- }
+ return convertEsrToVim(getEsrSystemInfo(vimId), vimId);
}
/**
@@ -76,8 +70,11 @@ public class AAIExternalSystemInfoProvider extends GenericExternalSystemInfoProv
* @return the VIM details
*/
public EsrSystemInfo getEsrSystemInfo(String vimId) {
- String url = format(VIM_URL, getCloudOwner(vimId), getRegionName(vimId));
- return aaiRestApiProvider.get(logger, CLOUD, url, EsrSystemInfoList.class).getEsrSystemInfo().get(0);
+ try {
+ return aaiRestApiProvider.getCloudInfrastructureApi().getCloudInfrastructureCloudRegionsCloudRegion(getCloudOwner(vimId), getRegionName(vimId), null, null).blockingFirst().getEsrSystemInfoList().get(0);
+ } catch (Exception e) {
+ throw buildFatalFailure(logger, "Unable to query VIM with " + vimId + " identifier from AAI", e);
+ }
}
private VimInfo convertEsrToVim(EsrSystemInfo esrSystemInfo, String vimId) {
@@ -103,7 +100,7 @@ public class AAIExternalSystemInfoProvider extends GenericExternalSystemInfoProv
private VnfmInfo convertEsrToVnfmInfo(EsrVnfm vnfmInAai) {
- EsrSystemInfo esrSystemInfo = vnfmInAai.getEsrSystemInfoList().getEsrSystemInfo().get(0);
+ EsrSystemInfo esrSystemInfo = vnfmInAai.getEsrSystemInfoList().get(0);
VnfmInfo vnfmInfo = new VnfmInfo();
vnfmInfo.setPassword(esrSystemInfo.getPassword());
vnfmInfo.setDescription(esrSystemInfo.getEsrSystemInfoId());
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/AAIRestApiProvider.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/AAIRestApiProvider.java
index 141ba847..14bdea11 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/AAIRestApiProvider.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/AAIRestApiProvider.java
@@ -16,32 +16,20 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct;
import com.google.common.annotations.VisibleForTesting;
-import org.onap.aai.restclient.client.Headers;
-import org.onap.aai.restclient.client.OperationResult;
-import org.onap.aai.restclient.client.RestClient;
-import org.onap.aai.restclient.enums.RestAuthenticationMode;
+import okhttp3.Credentials;
+import okhttp3.Request;
+import org.onap.aai.ApiClient;
+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.MsbApiProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring.Conditions;
-import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Conditional;
-import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
-import javax.xml.bind.JAXBContext;
-import java.io.ByteArrayOutputStream;
-import java.io.StringReader;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.NoSuchElementException;
-
-import static com.google.common.collect.Lists.newArrayList;
-import static javax.ws.rs.core.MediaType.APPLICATION_XML_TYPE;
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.util.CbamUtils.buildFatalFailure;
-import static org.slf4j.LoggerFactory.getLogger;
/**
* Responsible for providing access to AAI APIs.
@@ -50,118 +38,63 @@ import static org.slf4j.LoggerFactory.getLogger;
@Component
@Conditional(value = Conditions.UseForDirect.class)
public class AAIRestApiProvider {
- private static final String AAI_VERSION = "v11";
- private static Logger logger = getLogger(AAIRestApiProvider.class);
private final MsbApiProvider msbApiProvider;
+ private final AaiSecurityProvider aaiSecurityProvider;
@Value("${aaiUsername}")
private String aaiUsername;
@Value("${aaiPassword}")
private String aaiPassword;
@Autowired
- AAIRestApiProvider(MsbApiProvider msbApiProvider) {
+ AAIRestApiProvider(MsbApiProvider msbApiProvider, AaiSecurityProvider aaiSecurityProvider) {
this.msbApiProvider = msbApiProvider;
+ this.aaiSecurityProvider = aaiSecurityProvider;
}
/**
- * @param logger the logger of the class that requests unmarshalling
- * @param service the AAI service of the request
- * @param url the URL of the request after the base URL (ex. /cloud-infrastructure/...)
- * @param clazz the class of the result
- * @param <T> the type of the result
- * @return the result of the GET request
- */
- public <T> T get(Logger logger, AAIService service, String url, Class<T> clazz) {
- return expectSuccess(logger, buildClient().get(getBaseUrl(service.getServiceName()) + url, buildCommonHeaders(), APPLICATION_XML_TYPE), clazz, url);
- }
-
- /**
- * @param logger the logger of the class that requests unmarshalling
- * @param service the AAI service of the request
- * @param url the URL of the request after the base URL (ex. /cloud-infrastructure/...)
- * @param payload the payload of the request (non serialized)
- * @param clazz the class of the result
- * @param <T> the type of the result
- * @return the result of the PUT request
+ * @return API to access the cloud infrastructure
*/
- public <T, S> T put(Logger logger, AAIService service, String url, S payload, Class<T> clazz) {
- String marshalledContent = marshall(payload);
- OperationResult result = buildClient().put(getBaseUrl(service.getServiceName()) + url, marshalledContent, buildCommonHeaders(), APPLICATION_XML_TYPE, APPLICATION_XML_TYPE);
- return expectSuccess(logger, result, clazz, url);
+ public CloudInfrastructureApi getCloudInfrastructureApi() {
+ return buildApiClient(AAIService.CLOUD).createService(CloudInfrastructureApi.class);
}
/**
- * Execute a delete request on the given URL
- *
- * @param logger the logger of the class that requests unmarshalling
- * @param service the AAI service of the request
- * @param url the URL of the request after the base URL (ex. /cloud-infrastructure/...)
+ * @return API to access the external systems
*/
- public void delete(Logger logger, AAIService service, String url) {
- buildClient().delete(getBaseUrl(service.getServiceName()) + url, buildCommonHeaders(), APPLICATION_XML_TYPE);
+ public ExternalSystemApi getExternalSystemApi() {
+ return buildApiClient(AAIService.ESR).createService(ExternalSystemApi.class);
}
/**
- * @param serviceName the name of the AAI service on MSB
- * @return the base URL of the service
+ * @return API to access the networking
*/
- private String getBaseUrl(String serviceName) {
- return msbApiProvider.getMicroServiceUrl(serviceName, AAI_VERSION);
- }
+ public NetworkApi getNetworkApi() {
+ return buildApiClient(AAIService.NETWORK).createService(NetworkApi.class);
- private <T> T expectSuccess(Logger logger, OperationResult result, Class<T> clazz, String url) {
- if (!result.wasSuccessful()) {
- if (result.getResultCode() == 404) {
- logger.debug("The resource at " + url + " does not exists");
- throw new NoSuchElementException("The resource at " + url + " does not exists");
- }
- throw buildFatalFailure(logger, "Bad response. Code: " + result.getResultCode() + " cause: " + result.getFailureCause());
- }
- if (clazz.isAssignableFrom(Void.class)) {
- return null;
- }
- return unmarshal(result.getResult(), clazz);
- }
-
- private <T> T unmarshal(String content, Class<T> clazz) {
- try {
- return (T) JAXBContext.newInstance(clazz).createUnmarshaller().unmarshal(new StringReader(content));
- } catch (Exception e) {
- throw buildFatalFailure(logger, "Unable to unmarshal content", e);
- }
- }
-
- private String marshall(Object object) {
- try {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- JAXBContext.newInstance(object.getClass()).createMarshaller().marshal(object, bos);
- return bos.toString();
- } catch (Exception e) {
- throw buildFatalFailure(logger, "Unable to marshal content", e);
- }
- }
-
- /**
- * @return the common mandatory headers for AAI requests
- */
- private Map<String, List<String>> buildCommonHeaders() {
- Map<String, List<String>> headers = new HashMap<>();
- headers.put(Headers.ACCEPT, newArrayList(MediaType.APPLICATION_XML_VALUE));
- headers.put(Headers.FROM_APP_ID, newArrayList(SERVICE_NAME));
- return headers;
- }
-
-
- private RestClient buildClient() {
- return buildRawClient().basicAuthUsername(aaiUsername).basicAuthPassword(aaiPassword).authenticationMode(RestAuthenticationMode.SSL_BASIC);
}
@VisibleForTesting
- RestClient buildRawClient() {
- return new RestClient();
+ ApiClient buildApiClient(AAIService service) {
+ ApiClient apiClient = new ApiClient();
+ apiClient.getOkBuilder().sslSocketFactory(aaiSecurityProvider.buildSSLSocketFactory(), aaiSecurityProvider.buildTrustManager());
+ apiClient.getOkBuilder().hostnameVerifier(aaiSecurityProvider.buildHostnameVerifier());
+ apiClient.getOkBuilder().addInterceptor(chain -> {
+ Request request = chain.request().newBuilder().addHeader("X-FromAppId", SERVICE_NAME).build();
+ return chain.proceed(request);
+ });
+ apiClient.getOkBuilder().authenticator((route, response) -> {
+ String credential = Credentials.basic(aaiUsername, aaiPassword);
+ return response.request().newBuilder().header("Authorization", credential).build();
+ });
+ String url = msbApiProvider.getMicroServiceUrl(service.getServiceName(), "v11");
+ if (!url.endsWith("/")) {
+ url = url + "/";
+ }
+ apiClient.getAdapterBuilder().baseUrl(url);
+ return apiClient;
}
- public enum AAIService {
+ enum AAIService {
NETWORK {
String getServiceName() {
return "aai-network";
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/AaiSecurityProvider.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/AaiSecurityProvider.java
new file mode 100644
index 00000000..688a82fd
--- /dev/null
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/AaiSecurityProvider.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2016-2017, Nokia Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct;
+
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.GenericSecurityProvider;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+/**
+ * Responsible for providing SSL factories for AAI
+ */
+@Component
+public class AaiSecurityProvider extends GenericSecurityProvider {
+ @Value("${trustedCertificatesForAai}")
+ private String trustedCertificates;
+ @Value("${skipCertificateVerificationForAai}")
+ private boolean skipCertificateVerification;
+ @Value("${skipHostnameVerificationForAai}")
+ private boolean skipHostnameVerification;
+
+ @Override
+ protected boolean skipHostnameVerification() {
+ return skipHostnameVerification;
+ }
+
+ @Override
+ protected boolean skipCertificateVerification() {
+ return skipCertificateVerification;
+ }
+
+ @Override
+ protected String trustedCertificates() {
+ return trustedCertificates;
+ }
+}
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/SdcPackageProvider.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/SdcPackageProvider.java
index 8a165478..a7e6e404 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/SdcPackageProvider.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/SdcPackageProvider.java
@@ -17,6 +17,8 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
@@ -32,11 +34,9 @@ import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Component;
import org.yaml.snakeyaml.Yaml;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
+import static java.lang.String.format;
import static com.google.common.io.ByteStreams.toByteArray;
-import static java.lang.String.format;
import static org.apache.http.HttpHeaders.ACCEPT;
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.util.CbamUtils.*;
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/AAINotificationProcessor.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/AAINotificationProcessor.java
index aad90eac..86517435 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/AAINotificationProcessor.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/AAINotificationProcessor.java
@@ -18,6 +18,10 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
import com.nokia.cbam.lcm.v32.model.AffectedVirtualLink;
import com.nokia.cbam.lcm.v32.model.OperationExecution;
import com.nokia.cbam.lcm.v32.model.VnfLifecycleChangeNotification;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Optional;
+import java.util.Set;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.INotificationSender;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring.Conditions;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.ReportedAffectedConnectionPoints;
@@ -27,11 +31,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Component;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Optional;
-import java.util.Set;
-
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.tryFind;
import static com.nokia.cbam.lcm.v32.model.ChangeType.*;
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/AbstractManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/AbstractManager.java
index c8008f38..ee7a3feb 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/AbstractManager.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/AbstractManager.java
@@ -16,20 +16,17 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
import com.google.gson.Gson;
-import org.onap.aai.domain.yang.v11.ObjectFactory;
-import org.onap.aai.domain.yang.v11.Relationship;
-import org.onap.aai.domain.yang.v11.RelationshipData;
-import org.onap.aai.domain.yang.v11.RelationshipList;
+import io.reactivex.Observable;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import org.onap.aai.model.Relationship;
+import org.onap.aai.model.RelationshipData;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider;
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 java.util.HashSet;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.Set;
-
import static com.google.common.collect.Iterables.find;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.SEPARATOR;
@@ -37,7 +34,6 @@ import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.SEPARATOR
* Handles the common management of changing entities in AAI
*/
abstract class AbstractManager {
- protected static final ObjectFactory OBJECT_FACTORY = new ObjectFactory();
protected final AAIRestApiProvider aaiRestApiProvider;
protected final CbamRestApiProvider cbamRestApiProvider;
protected final DriverProperties driverProperties;
@@ -78,17 +74,17 @@ abstract class AbstractManager {
* @param relationships the list of relationships
* @param relationship the expected relationship
*/
- protected static void addSingletonRelation(RelationshipList relationships, Relationship relationship) {
+ protected static void addSingletonRelation(List<Relationship> relationships, Relationship relationship) {
boolean found = false;
- for (Relationship currentRelationShip : relationships.getRelationship()) {
+ for (Relationship currentRelationShip : relationships) {
if (relationship.getRelatedTo().equals(currentRelationShip.getRelatedTo())) {
found = true;
}
}
if (!found) {
- relationships.getRelationship().add(relationship);
+ relationships.add(relationship);
} else {
- Relationship existingRelationShip = find(relationships.getRelationship(), currentRelationShip -> currentRelationShip.getRelatedTo().equals(relationship.getRelatedTo()));
+ Relationship existingRelationShip = find(relationships, currentRelationShip -> currentRelationShip.getRelatedTo().equals(relationship.getRelatedTo()));
existingRelationShip.getRelationshipData().clear();
existingRelationShip.getRelationshipData().addAll(relationship.getRelationshipData());
}
@@ -100,14 +96,14 @@ abstract class AbstractManager {
* @param relationships the relationships
* @param relationship the relationship to be added
*/
- protected static void addMissingRelation(RelationshipList relationships, Relationship relationship) {
- for (Relationship currentRelationShip : relationships.getRelationship()) {
+ protected static void addMissingRelation(List<Relationship> relationships, Relationship relationship) {
+ for (Relationship currentRelationShip : relationships) {
if (currentRelationShip.getRelatedTo().equals(relationship.getRelatedTo())
&& compositeKeys(currentRelationShip.getRelationshipData()).equals(compositeKeys(relationship.getRelationshipData()))) {
return;
}
}
- relationships.getRelationship().add(relationship);
+ relationships.add(relationship);
}
private static Set<String> compositeKeys(List<RelationshipData> data) {
@@ -126,17 +122,16 @@ abstract class AbstractManager {
/**
* Creates or returns a REST resource instance
*
- * @param service the type of the service
- * @param url the URL of the resource without the service prefix
+ * @param get provides an existing instance
* @param newInstance the empty instance if the resource does not exists
* @param <T> the type of the resource
* @return the created or queried resource
*/
- protected <T> T createOrGet(AAIRestApiProvider.AAIService service, String url, T newInstance) {
+ protected <T> T createOrGet(Observable<T> get, T newInstance) {
try {
- return (T) aaiRestApiProvider.get(getLogger(), service, url, newInstance.getClass());
- } catch (NoSuchElementException e) {
- getLogger().debug("The resource on " + url + " URL was not found in AAI", e);
+ return get.blockingFirst();
+ } catch (Exception e) {
+ getLogger().debug("The resource was not found in AAI", e);
return newInstance;
}
}
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/GenericVnfManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/GenericVnfManager.java
index 2b9b3882..130004e4 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/GenericVnfManager.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/GenericVnfManager.java
@@ -16,10 +16,13 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
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.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;
@@ -27,10 +30,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;
@@ -40,7 +39,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);
@@ -52,6 +50,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;
}
@@ -68,7 +67,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
@@ -77,8 +76,8 @@ 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) {
@@ -90,18 +89,17 @@ class GenericVnfManager extends AbstractManager {
}
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);
+ SystemFunctions.systemFunctions().blockingFirst(aaiRestApiProvider.getNetworkApi().createOrUpdateNetworkGenericVnfsGenericVnf(vnf.getVnfId(), vnf));
}
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);
}
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/L3NetworkManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/L3NetworkManager.java
index 6d2b42bc..1d641cff 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/L3NetworkManager.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/L3NetworkManager.java
@@ -16,9 +16,10 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
import com.nokia.cbam.lcm.v32.model.AffectedVirtualLink;
-import org.onap.aai.domain.yang.v11.L3Network;
-import org.onap.aai.domain.yang.v11.Relationship;
-import org.onap.aai.domain.yang.v11.RelationshipList;
+import io.reactivex.Observable;
+import java.util.ArrayList;
+import org.onap.aai.model.L3Network;
+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,9 +29,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Component;
-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.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;
@@ -40,7 +40,6 @@ import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.ge
@Component
@Conditional(value = Conditions.UseForDirect.class)
class L3NetworkManager extends AbstractManager {
- private static final String NETWORK_URL = "/l3-networks/l3-network/%s";
private static Logger logger = org.slf4j.LoggerFactory.getLogger(L3NetworkManager.class);
@Autowired
@@ -54,12 +53,17 @@ class L3NetworkManager extends AbstractManager {
}
void update(String vimId, String vnfId, AffectedVirtualLink affectedVirtualLink) {
- L3Network l3Network = createOrGet(NETWORK, format(NETWORK_URL, buildNetworkId(vnfId, affectedVirtualLink)), OBJECT_FACTORY.createL3Network());
+ L3Network l3Network = createOrGet(getNetwork(vnfId, affectedVirtualLink), new L3Network());
updateNetworkFields(vimId, vnfId, affectedVirtualLink, l3Network);
}
+ private Observable<L3Network> getNetwork(String vnfId, AffectedVirtualLink affectedVirtualLink) {
+ return aaiRestApiProvider.getNetworkApi().getNetworkL3NetworksL3Network(buildNetworkId(vnfId, affectedVirtualLink), null, null, null, null, null, null, null, null, null);
+ }
+
void delete(String vnfId, AffectedVirtualLink removedVl) {
- aaiRestApiProvider.delete(logger, NETWORK, format(NETWORK_URL, buildNetworkId(vnfId, removedVl)));
+ L3Network l3Network = getNetwork(vnfId, removedVl).blockingFirst();
+ systemFunctions().blockingFirst(aaiRestApiProvider.getNetworkApi().deleteNetworkL3NetworksL3Network(l3Network.getNetworkId(), l3Network.getResourceVersion()));
}
private void updateNetworkFields(String vimId, String vnfId, AffectedVirtualLink affectedVirtualLink, L3Network network) {
@@ -73,12 +77,12 @@ class L3NetworkManager extends AbstractManager {
network.setOperationalStatus("active");
network.setOrchestrationStatus("active");
if (network.getRelationshipList() == null) {
- network.setRelationshipList(new RelationshipList());
+ network.setRelationshipList(new ArrayList<>());
}
addMissingRelation(network.getRelationshipList(), GenericVnfManager.linkTo(vnfId));
addSingletonRelation(network.getRelationshipList(), getRegionLink(vimId));
addSingletonRelation(network.getRelationshipList(), getTenantLink(vimId, extractMandatoryValue(affectedVirtualLink.getResource().getAdditionalData(), "tenantId")));
- aaiRestApiProvider.put(logger, NETWORK, format(NETWORK_URL, network.getNetworkId()), network, Void.class);
+ systemFunctions().blockingFirst(aaiRestApiProvider.getNetworkApi().createOrUpdateNetworkL3NetworksL3Network(network.getNetworkId(), network));
}
private String buildNetworkId(String vnfId, AffectedVirtualLink affectedVirtualLink) {
@@ -88,6 +92,7 @@ class L3NetworkManager extends AbstractManager {
private Relationship getRegionLink(String vimId) {
Relationship relationship = new Relationship();
relationship.setRelatedTo("cloud-region");
+ relationship.setRelationshipData(new ArrayList<>());
relationship.getRelationshipData().add(buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(vimId)));
relationship.getRelationshipData().add(buildRelationshipData("cloud-region.cloud-region-id", getRegionName(vimId)));
return relationship;
@@ -96,6 +101,7 @@ class L3NetworkManager extends AbstractManager {
private Relationship getTenantLink(String vimId, String tenantId) {
Relationship relationship = new Relationship();
relationship.setRelatedTo("tenant");
+ relationship.setRelationshipData(new ArrayList<>());
relationship.getRelationshipData().add(buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(vimId)));
relationship.getRelationshipData().add(buildRelationshipData("cloud-region.cloud-region-id", getRegionName(vimId)));
relationship.getRelationshipData().add(buildRelationshipData("tenant.tenant-id", tenantId));
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/LInterfaceManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/LInterfaceManager.java
index 229fe679..78da503e 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/LInterfaceManager.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/LInterfaceManager.java
@@ -15,10 +15,11 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
-import org.onap.aai.domain.yang.v11.L3InterfaceIpv4AddressList;
-import org.onap.aai.domain.yang.v11.L3InterfaceIpv6AddressList;
-import org.onap.aai.domain.yang.v11.LInterface;
-import org.onap.aai.domain.yang.v11.RelationshipList;
+import io.reactivex.Observable;
+import java.util.ArrayList;
+import org.onap.aai.model.L3InterfaceIpv4AddressList;
+import org.onap.aai.model.L3InterfaceIpv6AddressList;
+import org.onap.aai.model.LInterface;
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;
@@ -30,7 +31,8 @@ import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Component;
import static java.lang.String.format;
-import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider.AAIService.CLOUD;
+
+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;
@@ -62,15 +64,30 @@ class LInterfaceManager extends AbstractManager {
}
void update(String vnfId, String vimId, ReportedAffectedCp affectedCp, boolean inMaintenance) {
- LInterface lInterface = createOrGet(CLOUD, buildUrl(vimId, affectedCp), OBJECT_FACTORY.createLInterface());
- updateFields(lInterface, affectedCp, vnfId, buildUrl(vimId, affectedCp), inMaintenance);
+ LInterface lInterface = createOrGet(getLinterface(vimId, affectedCp), new LInterface());
+ updateFields(vimId, lInterface, affectedCp, vnfId, inMaintenance);
}
void delete(String vimId, ReportedAffectedCp removedCp) {
- aaiRestApiProvider.delete(logger, AAIRestApiProvider.AAIService.CLOUD, buildUrl(vimId, removedCp));
+ LInterface linterface = getLinterface(vimId, removedCp).blockingFirst();
+ String cloudOwner = getCloudOwner(vimId);
+ String regionName = getRegionName(vimId);
+ String tenantId = removedCp.getTenantId();
+ String vServerId = removedCp.getServerProviderId();
+ String cpId = removedCp.getCpId();
+ aaiRestApiProvider.getCloudInfrastructureApi().deleteCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(cloudOwner, regionName, tenantId, vServerId, cpId, linterface.getResourceVersion());
+ }
+
+ private Observable<LInterface> getLinterface(String vimId, ReportedAffectedCp cp) {
+ String cloudOwner = getCloudOwner(vimId);
+ String regionName = getRegionName(vimId);
+ String tenantId = cp.getTenantId();
+ String vServerId = cp.getServerProviderId();
+ String cpId = cp.getCpId();
+ return aaiRestApiProvider.getCloudInfrastructureApi().getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(cloudOwner, regionName, tenantId, vServerId, cpId, null, null, null, null, null, null, null, null, null, null, null, null);
}
- private void updateFields(LInterface logicalInterface, ReportedAffectedCp affectedCp, String vnfId, String url, boolean inMaintenance) {
+ private void updateFields(String vimId, LInterface logicalInterface, ReportedAffectedCp affectedCp, String vnfId, boolean inMaintenance) {
logicalInterface.setInMaint(inMaintenance);
logicalInterface.setIsIpUnnumbered(false);
logicalInterface.setIsPortMirrored(false);
@@ -81,21 +98,32 @@ class LInterfaceManager extends AbstractManager {
logicalInterface.setProvStatus("active");
if (affectedCp.getIpAddress() != null) {
if (affectedCp.getIpAddress().contains(":")) {
- L3InterfaceIpv6AddressList ipv6Address = OBJECT_FACTORY.createL3InterfaceIpv6AddressList();
+ L3InterfaceIpv6AddressList ipv6Address = new L3InterfaceIpv6AddressList();
ipv6Address.setL3InterfaceIpv6Address(affectedCp.getIpAddress());
ipv6Address.setNeutronNetworkId(affectedCp.getNetworkProviderId());
+ if (logicalInterface.getL3InterfaceIpv6AddressList() == null) {
+ logicalInterface.setL3InterfaceIpv6AddressList(new ArrayList<>());
+ }
logicalInterface.getL3InterfaceIpv6AddressList().add(ipv6Address);
} else {
- L3InterfaceIpv4AddressList ipv4Address = OBJECT_FACTORY.createL3InterfaceIpv4AddressList();
+ L3InterfaceIpv4AddressList ipv4Address = new L3InterfaceIpv4AddressList();
ipv4Address.setL3InterfaceIpv4Address(affectedCp.getIpAddress());
ipv4Address.setNeutronNetworkId(affectedCp.getNetworkProviderId());
+ if (logicalInterface.getL3InterfaceIpv4AddressList() == null) {
+ logicalInterface.setL3InterfaceIpv4AddressList(new ArrayList<>());
+ }
logicalInterface.getL3InterfaceIpv4AddressList().add(ipv4Address);
}
}
if (logicalInterface.getRelationshipList() == null) {
- logicalInterface.setRelationshipList(new RelationshipList());
+ logicalInterface.setRelationshipList(new ArrayList<>());
}
addSingletonRelation(logicalInterface.getRelationshipList(), GenericVnfManager.linkTo(vnfId));
- aaiRestApiProvider.put(logger, CLOUD, url, logicalInterface, Void.class);
+ String cloudOwner = getCloudOwner(vimId);
+ String regionName = getRegionName(vimId);
+ String tenantId = affectedCp.getTenantId();
+ String vServerId = affectedCp.getServerProviderId();
+ String cpId = affectedCp.getCpId();
+ systemFunctions().blockingFirst(aaiRestApiProvider.getCloudInfrastructureApi().createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(cloudOwner, regionName, tenantId, vServerId, cpId, logicalInterface));
}
}
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/VnfcManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/VnfcManager.java
index e1d1197b..9528e1a7 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/VnfcManager.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/VnfcManager.java
@@ -15,8 +15,9 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
-import org.onap.aai.domain.yang.v11.RelationshipList;
-import org.onap.aai.domain.yang.v11.Vnfc;
+import io.reactivex.Observable;
+import java.util.ArrayList;
+import org.onap.aai.model.Vnfc;
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;
@@ -26,9 +27,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Component;
-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.SEPARATOR;
+import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions;
/**
* Responsible for managing {@link Vnfc} in AAI
@@ -43,15 +43,6 @@ public class VnfcManager extends AbstractManager {
super(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
}
- /**
- * @param vnfId the identifier of the VNF
- * @param cbamVnfcId the identifier of the VNFC in CBAM
- * @return the URL of the VNFC
- */
- public static String buildUrl(String vnfId, String cbamVnfcId) {
- return format("/vnfcs/vnfc/%s", buildId(vnfId, cbamVnfcId));
- }
-
private static String buildId(String vnfId, String cbamVnfcId) {
return vnfId + SEPARATOR + cbamVnfcId;
}
@@ -62,16 +53,20 @@ public class VnfcManager extends AbstractManager {
}
void delete(String vnfId, com.nokia.cbam.lcm.v32.model.AffectedVnfc cbamVnfc) {
- aaiRestApiProvider.delete(logger, NETWORK, buildUrl(vnfId, cbamVnfc.getId()));
+ Vnfc vnfc = getVnfc(buildId(vnfId, cbamVnfc.getId())).blockingFirst();
+ systemFunctions().blockingFirst(aaiRestApiProvider.getNetworkApi().deleteNetworkVnfcsVnfc(vnfc.getVnfcName(), vnfc.getResourceVersion()));
+ }
+
+ private Observable<Vnfc> getVnfc(String vnfcId) {
+ return aaiRestApiProvider.getNetworkApi().getNetworkVnfcsVnfc(vnfcId, null, null, null, null, null, null, null, null, null);
}
void update(String vimId, String tenantId, String vnfId, com.nokia.cbam.lcm.v32.model.AffectedVnfc cbamVnfc, boolean inMaintenance) {
- String url = buildUrl(vnfId, cbamVnfc.getId());
- Vnfc vnfc = createOrGet(NETWORK, url, OBJECT_FACTORY.createVnfc());
- updateFields(vimId, tenantId, vnfc, cbamVnfc, vnfId, url, inMaintenance);
+ Vnfc vnfc = createOrGet(getVnfc(buildId(vnfId, cbamVnfc.getId())), new Vnfc());
+ updateFields(vimId, tenantId, vnfc, cbamVnfc, vnfId, inMaintenance);
}
- private void updateFields(String vimId, String tenantId, Vnfc aaiVnfc, com.nokia.cbam.lcm.v32.model.AffectedVnfc cbamVnfc, String vnfId, String url, boolean inMaintenance) {
+ private void updateFields(String vimId, String tenantId, Vnfc aaiVnfc, com.nokia.cbam.lcm.v32.model.AffectedVnfc cbamVnfc, String vnfId, boolean inMaintenance) {
aaiVnfc.setInMaint(inMaintenance);
aaiVnfc.setIsClosedLoopDisabled(inMaintenance);
//FIXME would be good to know what is this mandatory parameter
@@ -79,9 +74,11 @@ public class VnfcManager extends AbstractManager {
//FIXME would be good to know what is this mandatory parameter
aaiVnfc.setNfcNamingCode(cbamVnfc.getId());
aaiVnfc.setVnfcName(buildId(vnfId, cbamVnfc.getId()));
- aaiVnfc.setRelationshipList(new RelationshipList());
+ if (aaiVnfc.getRelationshipList() == null) {
+ aaiVnfc.setRelationshipList(new ArrayList<>());
+ }
addSingletonRelation(aaiVnfc.getRelationshipList(), VserverManager.linkTo(vimId, tenantId, cbamVnfc.getComputeResource().getResourceId()));
addSingletonRelation(aaiVnfc.getRelationshipList(), GenericVnfManager.linkTo(vnfId));
- aaiRestApiProvider.put(logger, NETWORK, url, aaiVnfc, Void.class);
+ systemFunctions().blockingFirst(aaiRestApiProvider.getNetworkApi().createOrUpdateNetworkVnfcsVnfc(aaiVnfc.getVnfcName(), aaiVnfc));
}
} \ No newline at end of file
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/VserverManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/VserverManager.java
index cec779a4..3eba8b21 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/VserverManager.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/VserverManager.java
@@ -20,7 +20,12 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.nokia.cbam.lcm.v32.model.AffectedVirtualStorage;
import com.nokia.cbam.lcm.v32.model.AffectedVnfc;
-import org.onap.aai.domain.yang.v11.*;
+import io.reactivex.Observable;
+import java.util.ArrayList;
+import java.util.List;
+import org.onap.aai.model.Relationship;
+import org.onap.aai.model.Volume;
+import org.onap.aai.model.Vserver;
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;
@@ -30,12 +35,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Component;
-import java.util.List;
-
import static com.google.common.collect.Iterables.find;
-import static java.lang.String.format;
-import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider.AAIService.CLOUD;
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;
@@ -45,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(VserverManager.class);
+ private static Logger logger = org.slf4j.LoggerFactory.getLogger(AbstractManager.class);
@Autowired
VserverManager(AAIRestApiProvider aaiRestApiProvider, CbamRestApiProvider cbamRestApiProvider, DriverProperties driverProperties) {
@@ -55,6 +57,7 @@ class VserverManager extends AbstractManager {
static Relationship linkTo(String vimId, String tenantId, String serverProviderId) {
Relationship relationship = new Relationship();
relationship.setRelatedTo("vserver");
+ relationship.setRelationshipData(new ArrayList<>());
relationship.getRelationshipData().add(buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(vimId)));
relationship.getRelationshipData().add(buildRelationshipData("cloud-region.cloud-region-id", getRegionName(vimId)));
relationship.getRelationshipData().add(buildRelationshipData("tenant.tenant-id", tenantId));
@@ -72,47 +75,53 @@ class VserverManager extends AbstractManager {
}
void update(String vimId, String vnfId, AffectedVnfc cbamVnfc, List<AffectedVirtualStorage> affectedVirtualStorages, boolean inMaintenance) {
- String url = buildUrl(vimId, cbamVnfc);
- Vserver vserver = createOrGet(CLOUD, url, OBJECT_FACTORY.createVserver());
- updateFields(vserver, cbamVnfc, vnfId, affectedVirtualStorages, url, inMaintenance);
+ Vserver vserver = createOrGet(getVserver(vimId, cbamVnfc), new Vserver());
+ updateFields(vimId, vserver, cbamVnfc, vnfId, affectedVirtualStorages, inMaintenance);
}
- void delete(String vimId, com.nokia.cbam.lcm.v32.model.AffectedVnfc deletedVnfc) {
- aaiRestApiProvider.delete(logger, CLOUD, buildUrl(vimId, deletedVnfc));
+ void delete(String vimId, AffectedVnfc deletedVnfc) {
+ String tenantId = getTenantId(deletedVnfc);
+ String cloudOwner = getCloudOwner(vimId);
+ String regionName = getRegionName(vimId);
+ Vserver vserver = getVserver(vimId, deletedVnfc).blockingFirst();
+ aaiRestApiProvider.getCloudInfrastructureApi().deleteCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(cloudOwner, regionName, tenantId, vserver.getVserverId(), vserver.getResourceVersion());
}
- private String buildUrl(String vimId, AffectedVnfc cbamVnfc) {
+ private Observable<Vserver> getVserver(String vimId, AffectedVnfc cbamVnfc) {
String tenantId = getTenantId(cbamVnfc);
String cloudOwner = getCloudOwner(vimId);
String regionName = getRegionName(vimId);
- return format("/cloud-regions/cloud-region/%s/%s/tenants/tenant/%s/vservers/vserver/%s", cloudOwner, regionName, tenantId, cbamVnfc.getComputeResource().getResourceId());
+ return aaiRestApiProvider.getCloudInfrastructureApi().getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(cloudOwner, regionName, tenantId, cbamVnfc.getComputeResource().getResourceId(), null, null, null, null, null, null, null, null, null);
}
- private void updateFields(Vserver server, AffectedVnfc cbamVnfc, String vnfId, List<AffectedVirtualStorage> affectedVirtualStorages, String url, boolean inMaintenance) {
+ private void updateFields(String vimId, Vserver server, AffectedVnfc cbamVnfc, String vnfId, List<AffectedVirtualStorage> affectedVirtualStorages, boolean inMaintenance) {
server.setInMaint(inMaintenance);
server.setIsClosedLoopDisabled(inMaintenance);
JsonElement additionalData = new Gson().toJsonTree(cbamVnfc.getComputeResource().getAdditionalData());
server.setVserverName(additionalData.getAsJsonObject().get("name").getAsString());
server.setVserverId(cbamVnfc.getComputeResource().getResourceId());
server.setProvStatus("active");
- server.setRelationshipList(new RelationshipList());
+ server.setRelationshipList(new ArrayList<>());
server.setVserverId(cbamVnfc.getComputeResource().getResourceId());
server.setVserverSelflink(extractSelfLink(cbamVnfc.getComputeResource().getAdditionalData()));
addSingletonRelation(server.getRelationshipList(), GenericVnfManager.linkTo(vnfId));
- if (server.getVolumes() == null) {
- server.setVolumes(new Volumes());
- }
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().getVolume().add(volume);
+ server.getVolumes().add(volume);
}
} else {
- server.setVolumes(OBJECT_FACTORY.createVolumes());
+ server.setVolumes(new ArrayList<>());
}
- aaiRestApiProvider.put(logger, CLOUD, url, server, Void.class);
+ String tenantId = getTenantId(cbamVnfc);
+ String cloudOwner = getCloudOwner(vimId);
+ String regionName = getRegionName(vimId);
+ systemFunctions().blockingFirst(aaiRestApiProvider.getCloudInfrastructureApi().createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(cloudOwner, regionName, tenantId, server.getVserverId(), server));
}
private String extractSelfLink(Object additionalData) {
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcGrantManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcGrantManager.java
index 03169612..01b75027 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcGrantManager.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcGrantManager.java
@@ -23,6 +23,7 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.nokia.cbam.lcm.v32.model.VnfInfo;
import com.nokia.cbam.lcm.v32.model.VnfcResourceInfo;
+import java.util.*;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.IGrantManager;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring.Conditions;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CatalogManager;
@@ -34,8 +35,6 @@ import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Component;
import org.yaml.snakeyaml.Yaml;
-import java.util.*;
-
import static com.nokia.cbam.lcm.v32.model.InstantiationState.INSTANTIATED;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.buildFatalFailure;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.child;
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcNotificationSender.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcNotificationSender.java
index 50f6221b..65cef408 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcNotificationSender.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcNotificationSender.java
@@ -19,6 +19,8 @@ import com.google.gson.Gson;
import com.nokia.cbam.lcm.v32.model.OperationExecution;
import com.nokia.cbam.lcm.v32.model.ScaleVnfRequest;
import com.nokia.cbam.lcm.v32.model.VnfLifecycleChangeNotification;
+import java.util.ArrayList;
+import java.util.Optional;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.INotificationSender;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring.Conditions;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties;
@@ -31,12 +33,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Component;
-import java.util.ArrayList;
-import java.util.Optional;
+import static java.util.Optional.of;
import static com.google.common.collect.Iterables.tryFind;
import static com.nokia.cbam.lcm.v32.model.ScaleDirection.IN;
-import static java.util.Optional.of;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.SEPARATOR;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.buildFatalFailure;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.JobManager.extractOnapJobId;
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcPackageProvider.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcPackageProvider.java
index 5a3e960f..9ade5f4a 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcPackageProvider.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcPackageProvider.java
@@ -18,6 +18,9 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.vfc;
import com.google.common.io.ByteStreams;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHeaders;
import org.apache.http.client.methods.CloseableHttpResponse;
@@ -33,10 +36,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Component;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-
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;
import static org.slf4j.LoggerFactory.getLogger;
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/CbamVnfPackageBuilder.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/CbamVnfPackageBuilder.java
index 5f9f6341..6503177e 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/CbamVnfPackageBuilder.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/CbamVnfPackageBuilder.java
@@ -17,7 +17,6 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer;
import com.google.common.io.ByteStreams;
-
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/CbamVnfdBuilder.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/CbamVnfdBuilder.java
index 83b93518..07cd8032 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/CbamVnfdBuilder.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/CbamVnfdBuilder.java
@@ -16,13 +16,10 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import com.google.gson.*;
-import org.yaml.snakeyaml.Yaml;
-
import java.io.IOException;
+import java.io.StringReader;
+import org.yaml.snakeyaml.Yaml;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.child;
@@ -53,8 +50,7 @@ public class CbamVnfdBuilder {
if (interfaces.has("Healable")) {
addOperationParams(addChild(child(interfaces, "Healable"), "heal"));
}
- JsonNode jsonNodeTree = new ObjectMapper().readTree(new GsonBuilder().setPrettyPrinting().create().toJson(root));
- return new YAMLMapper().writeValueAsString(jsonNodeTree);
+ return new Yaml().dump(new Yaml().load(new StringReader(new Gson().toJson(root))));
}
private void addOperationParams(JsonObject operation) {
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/OnapVnfPackageBuilder.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/OnapVnfPackageBuilder.java
index 9fe4a298..00977e4a 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/OnapVnfPackageBuilder.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/OnapVnfPackageBuilder.java
@@ -17,7 +17,6 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer;
import com.google.common.io.ByteStreams;
-
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/OnapVnfdBuilder.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/OnapVnfdBuilder.java
index 701b42eb..dcac5cdf 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/OnapVnfdBuilder.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/OnapVnfdBuilder.java
@@ -21,13 +21,12 @@ import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
-import org.slf4j.Logger;
-import org.yaml.snakeyaml.Yaml;
-
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.regex.Pattern;
+import org.slf4j.Logger;
+import org.yaml.snakeyaml.Yaml;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.child;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.childElement;
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/ConverterApi.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/ConverterApi.java
index 790ac054..7ae05f5e 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/ConverterApi.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/ConverterApi.java
@@ -16,25 +16,24 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.restapi;
import com.google.common.io.ByteStreams;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.Part;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer.OnapVnfPackageBuilder;
import org.slf4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.Part;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-
-import static org.apache.http.entity.ContentType.APPLICATION_OCTET_STREAM;
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;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties.BASE_URL;
import static org.slf4j.LoggerFactory.getLogger;
import static org.springframework.http.HttpHeaders.*;
import static org.springframework.http.HttpStatus.OK;
+import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM;
import static org.springframework.http.MediaType.TEXT_HTML_VALUE;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;
@@ -71,7 +70,7 @@ public class ConverterApi {
} catch (Exception e) {
throw buildFatalFailure(logger, "Unable to convert VNF package", e);
}
- httpResponse.addHeader(CONTENT_TYPE, APPLICATION_OCTET_STREAM.getMimeType());
+ httpResponse.addHeader(CONTENT_TYPE, APPLICATION_OCTET_STREAM.toString());
httpResponse.setStatus(OK.value());
httpResponse.addHeader(CONTENT_LENGTH, Integer.toString(convertedPackage.length));
httpResponse.addHeader(CONTENT_DISPOSITION, "attachment; filename=\"" + "core.csar" + "\"");
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/LcmApi.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/LcmApi.java
index be78aa0a..c3405201 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/LcmApi.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/LcmApi.java
@@ -15,6 +15,7 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.restapi;
+import javax.servlet.http.HttpServletResponse;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.JobManager;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager;
import org.onap.vnfmdriver.model.*;
@@ -26,10 +27,9 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
-import javax.servlet.http.HttpServletResponse;
-
+import static javax.servlet.http.HttpServletResponse.SC_CREATED;
import static java.util.Optional.empty;
-import static org.apache.http.HttpStatus.SC_CREATED;
+
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties.BASE_URL;
import static org.slf4j.LoggerFactory.getLogger;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/LcnApi.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/LcnApi.java
index df871b09..d11226b0 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/LcnApi.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/LcnApi.java
@@ -16,17 +16,15 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.restapi;
import com.nokia.cbam.lcm.v32.model.VnfLifecycleChangeNotification;
+import javax.servlet.http.HttpServletResponse;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.LifecycleChangeNotificationManager;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
-import javax.servlet.http.HttpServletResponse;
-
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties.BASE_URL;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties.LCN_URL;
import static org.slf4j.LoggerFactory.getLogger;
@@ -62,13 +60,11 @@ public class LcnApi {
/**
* Handle the LCN sent by CBAM
*
- * @param lcn the LCN notification
- * @param httpResponse the HTTP response
+ * @param lcn the LCN notification
*/
@RequestMapping(value = LCN_URL, method = POST, consumes = APPLICATION_JSON_VALUE)
- @ResponseBody
@ResponseStatus(code = NO_CONTENT)
- public void handleLcn(@RequestBody VnfLifecycleChangeNotification lcn, HttpServletResponse httpResponse) {
+ public void handleLcn(@RequestBody VnfLifecycleChangeNotification lcn) {
logger.info("REST: handle LCN");
lcnManager.handleLcn(lcn);
}
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/SwaggerApi.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/SwaggerApi.java
index 15c8dc36..51423ae8 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/SwaggerApi.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/SwaggerApi.java
@@ -15,6 +15,8 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.restapi;
+import java.io.IOException;
+import javax.servlet.http.HttpServletResponse;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
@@ -22,9 +24,6 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties.BASE_URL;
import static org.slf4j.LoggerFactory.getLogger;
import static org.springframework.http.HttpHeaders.CONTENT_LENGTH;
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/Conditions.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/Conditions.java
index defa340a..d27f4be1 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/Conditions.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/Conditions.java
@@ -16,13 +16,12 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring;
import com.google.common.collect.Sets;
+import java.util.HashSet;
+import java.util.Set;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
-import java.util.HashSet;
-import java.util.Set;
-
import static com.google.common.collect.Sets.newHashSet;
/**
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/RealConfig.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/RealConfig.java
index f9b2e394..7ab14e8b 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/RealConfig.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/RealConfig.java
@@ -15,15 +15,16 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring;
+import com.google.gson.Gson;
+import com.nokia.cbam.lcn.v32.JSON;
+import java.util.ArrayList;
+import java.util.Collection;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.GsonHttpMessageConverter;
-import java.util.ArrayList;
-import java.util.Collection;
-
/**
* Responsible for configuring the raw REST input conversion
*/
@@ -40,7 +41,8 @@ public class RealConfig {
@Bean
public HttpMessageConverters customConverters() {
Collection<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
- GsonHttpMessageConverter gsonHttpMessageConverter = new GsonHttpMessageConverter();
+ Gson gson = new JSON().getGson();
+ GsonHttpMessageConverter gsonHttpMessageConverter = new GsonHttpMessageConverter(gson);
messageConverters.add(gsonHttpMessageConverter);
return new HttpMessageConverters(true, messageConverters);
}
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/StoreLoader.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/StoreLoader.java
index 643d0286..7ff44ea5 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/StoreLoader.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/StoreLoader.java
@@ -16,8 +16,6 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util;
-import org.apache.commons.codec.binary.Base64;
-
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.security.KeyFactory;
@@ -31,9 +29,11 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
+import org.apache.commons.codec.binary.Base64;
import static java.util.Optional.empty;
import static java.util.Optional.of;
+
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.buildFatalFailure;
import static org.slf4j.LoggerFactory.getLogger;
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/SystemFunctions.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/SystemFunctions.java
index 0bb63039..c7fac86a 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/SystemFunctions.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/SystemFunctions.java
@@ -16,11 +16,12 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util;
import com.google.common.io.ByteStreams;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-
+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;
/**
* Wrapper class for static method calls to core or core libraries.
@@ -162,4 +163,17 @@ public class SystemFunctions {
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
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/AdditionalParameters.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/AdditionalParameters.java
index dfb7adaf..f585a6a2 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/AdditionalParameters.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/AdditionalParameters.java
@@ -17,7 +17,6 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm;
import com.nokia.cbam.lcm.v32.model.*;
import com.nokia.cbam.lcm.v32.model.VimInfo.VimInfoTypeEnum;
-
import java.util.*;
/**
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CatalogManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CatalogManager.java
index a7cabd52..5b99bad1 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CatalogManager.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CatalogManager.java
@@ -19,11 +19,6 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm;
import com.google.common.io.ByteStreams;
import com.nokia.cbam.catalog.v1.api.DefaultApi;
import com.nokia.cbam.catalog.v1.model.CatalogAdapterVnfpackage;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.IPackageProvider;
-import org.slf4j.Logger;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -33,14 +28,18 @@ import java.util.NoSuchElementException;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.IPackageProvider;
+import org.slf4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
import static com.google.common.base.Splitter.on;
import static com.google.common.collect.Iterables.filter;
-import static javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM;
import static okhttp3.MediaType.parse;
import static okhttp3.RequestBody.create;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.buildFatalFailure;
import static org.slf4j.LoggerFactory.getLogger;
+import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM;
/**
@@ -116,7 +115,7 @@ public class CatalogManager {
if (!isPackageReplicated(cbamVnfdId, cbamCatalogApi)) {
try {
ByteArrayOutputStream cbamPackage = getFileInZip(new ByteArrayInputStream(packageProvider.getPackage(csarId)), CBAM_PACKAGE_NAME_IN_ZIP);
- return cbamCatalogApi.create(create(parse(APPLICATION_OCTET_STREAM), cbamPackage.toByteArray())).execute().body();
+ return cbamCatalogApi.create(create(parse(APPLICATION_OCTET_STREAM.toString()), cbamPackage.toByteArray())).execute().body();
} catch (Exception e) {
logger.debug("Probably concurrent package uploads", e);
//retest if the VNF package exists in CBAM. It might happen that an other operation
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamSecurityProvider.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamSecurityProvider.java
index 6c70c26d..3a334361 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamSecurityProvider.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamSecurityProvider.java
@@ -15,33 +15,14 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm;
-import com.google.common.base.Joiner;
-import com.google.common.io.BaseEncoding;
-import org.apache.http.conn.ssl.DefaultHostnameVerifier;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.StoreLoader;
-import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
-import org.springframework.util.StringUtils;
-
-import javax.net.ssl.*;
-import java.nio.charset.StandardCharsets;
-import java.security.KeyStore;
-import java.security.SecureRandom;
-import java.security.cert.CertificateException;
-import java.security.cert.X509Certificate;
-import java.util.Set;
-
-import static java.util.UUID.randomUUID;
-import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.buildFatalFailure;
-import static org.slf4j.LoggerFactory.getLogger;
/**
- * Responsible for providing a token to access CBAM APIs
+ * Responsible for providing SSL factories for AAI
*/
@Component
-public class CbamSecurityProvider {
- private static Logger logger = getLogger(CbamSecurityProvider.class);
+public class CbamSecurityProvider extends GenericSecurityProvider {
@Value("${trustedCertificates}")
private String trustedCertificates;
@Value("${skipCertificateVerification}")
@@ -49,69 +30,18 @@ public class CbamSecurityProvider {
@Value("${skipHostnameVerification}")
private boolean skipHostnameVerification;
- protected HostnameVerifier buildHostnameVerifier() {
- if (skipHostnameVerification) {
- return (hostname, session) -> true;
- } else {
- return new DefaultHostnameVerifier();
- }
+ @Override
+ protected boolean skipHostnameVerification() {
+ return skipHostnameVerification;
}
- protected SSLSocketFactory buildSSLSocketFactory() {
- try {
- TrustManager[] trustManagers = new X509TrustManager[]{buildTrustManager()};
- SSLContext sslContext = SSLContext.getInstance("TLS");
- sslContext.init(null, trustManagers, new SecureRandom());
- return sslContext.getSocketFactory();
- } catch (Exception e) {
- throw buildFatalFailure(logger, "Unable to create SSL socket factory", e);
- }
+ @Override
+ protected boolean skipCertificateVerification() {
+ return skipCertificateVerification;
}
- protected X509TrustManager buildTrustManager() {
- if (skipCertificateVerification) {
- return new AllTrustedTrustManager();
- } else {
- if (StringUtils.isEmpty(trustedCertificates)) {
- throw buildFatalFailure(logger, "If the skipCertificateVerification is set to false (default) the trustedCertificates can not be empty");
- }
- Set<String> trustedPems;
- String content;
- try {
- content = new String(BaseEncoding.base64().decode(trustedCertificates), StandardCharsets.UTF_8);
- trustedPems = StoreLoader.getCertifacates(content);
- } catch (Exception e) {
- throw buildFatalFailure(logger, "The trustedCertificates must be a base64 encoded collection of PEM certificates", e);
- }
- if (trustedPems.isEmpty()) {
- throw buildFatalFailure(logger, "No certificate can be extracted from " + content);
- }
- try {
- KeyStore keyStore = StoreLoader.loadStore(Joiner.on("\n").join(trustedPems), randomUUID().toString(), randomUUID().toString());
- TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
- trustManagerFactory.init(keyStore);
- return (X509TrustManager) trustManagerFactory.getTrustManagers()[0];
- } catch (Exception e) {
- throw buildFatalFailure(logger, "Unable to create keystore", e);
- }
- }
+ @Override
+ protected String trustedCertificates() {
+ return trustedCertificates;
}
-
- private static class AllTrustedTrustManager implements X509TrustManager {
- @Override
- public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
- //no need to check certificates if everything is trusted
- }
-
- @Override
- public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
- //no need to check certificates if everything is trusted
- }
-
- @Override
- public X509Certificate[] getAcceptedIssuers() {
- return new X509Certificate[0];
- }
- }
-
}
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamTokenProvider.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamTokenProvider.java
index 837a25e5..df21e52d 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamTokenProvider.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CbamTokenProvider.java
@@ -18,6 +18,9 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm;
import com.google.common.annotations.VisibleForTesting;
import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
+import java.io.IOException;
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.SSLSocketFactory;
import okhttp3.*;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.VnfmInfoProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions;
@@ -27,10 +30,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.SSLSocketFactory;
-import java.io.IOException;
-
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.buildFatalFailure;
import static org.slf4j.LoggerFactory.getLogger;
import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/DriverProperties.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/DriverProperties.java
index d510ba25..b15d2850 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/DriverProperties.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/DriverProperties.java
@@ -16,12 +16,11 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm;
+import java.util.Objects;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
-import java.util.Objects;
-
/**
* Wraps the properties supplied to the servlet
*/
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/GenericSecurityProvider.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/GenericSecurityProvider.java
new file mode 100644
index 00000000..55440f56
--- /dev/null
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/GenericSecurityProvider.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2016-2017, Nokia Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm;
+
+import com.google.common.base.Joiner;
+import com.google.common.io.BaseEncoding;
+import java.nio.charset.StandardCharsets;
+import java.security.KeyStore;
+import java.security.SecureRandom;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import java.util.Set;
+import javax.net.ssl.*;
+import org.apache.http.conn.ssl.DefaultHostnameVerifier;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.StoreLoader;
+import org.slf4j.Logger;
+import org.springframework.util.StringUtils;
+
+import static java.util.UUID.randomUUID;
+
+import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.buildFatalFailure;
+import static org.slf4j.LoggerFactory.getLogger;
+
+public abstract class GenericSecurityProvider {
+ private static Logger logger = getLogger(GenericSecurityProvider.class);
+
+ protected abstract boolean skipHostnameVerification();
+
+ protected abstract boolean skipCertificateVerification();
+
+ protected abstract String trustedCertificates();
+
+ public HostnameVerifier buildHostnameVerifier() {
+ if (skipHostnameVerification()) {
+ return (hostname, session) -> true;
+ } else {
+ return new DefaultHostnameVerifier();
+ }
+ }
+
+ public SSLSocketFactory buildSSLSocketFactory() {
+ try {
+ TrustManager[] trustManagers = new X509TrustManager[]{buildTrustManager()};
+ SSLContext sslContext = SSLContext.getInstance("TLS");
+ sslContext.init(null, trustManagers, new SecureRandom());
+ return sslContext.getSocketFactory();
+ } catch (Exception e) {
+ throw buildFatalFailure(logger, "Unable to create SSL socket factory", e);
+ }
+ }
+
+ public X509TrustManager buildTrustManager() {
+ if (skipCertificateVerification()) {
+ return new AllTrustedTrustManager();
+ } else {
+ if (StringUtils.isEmpty(trustedCertificates())) {
+ throw buildFatalFailure(logger, "If the skipCertificateVerification is set to false (default) the trustedCertificates can not be empty");
+ }
+ Set<String> trustedPems;
+ String content;
+ try {
+ content = new String(BaseEncoding.base64().decode(trustedCertificates()), StandardCharsets.UTF_8);
+ trustedPems = StoreLoader.getCertifacates(content);
+ } catch (Exception e) {
+ throw buildFatalFailure(logger, "The trustedCertificates must be a base64 encoded collection of PEM certificates", e);
+ }
+ if (trustedPems.isEmpty()) {
+ throw buildFatalFailure(logger, "No certificate can be extracted from " + content);
+ }
+ try {
+ KeyStore keyStore = StoreLoader.loadStore(Joiner.on("\n").join(trustedPems), randomUUID().toString(), randomUUID().toString());
+ TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+ trustManagerFactory.init(keyStore);
+ return (X509TrustManager) trustManagerFactory.getTrustManagers()[0];
+ } catch (Exception e) {
+ throw buildFatalFailure(logger, "Unable to create keystore", e);
+ }
+ }
+ }
+
+ private static class AllTrustedTrustManager implements X509TrustManager {
+ @Override
+ public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+ //no need to check certificates if everything is trusted
+ }
+
+ @Override
+ public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+ //no need to check certificates if everything is trusted
+ }
+
+ @Override
+ public X509Certificate[] getAcceptedIssuers() {
+ return new X509Certificate[0];
+ }
+ }
+}
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/JobManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/JobManager.java
index 0d078d0b..277be9c4 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/JobManager.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/JobManager.java
@@ -24,7 +24,8 @@ import com.nokia.cbam.lcm.v32.api.VnfsApi;
import com.nokia.cbam.lcm.v32.model.OperationExecution;
import com.nokia.cbam.lcm.v32.model.OperationType;
import com.nokia.cbam.lcm.v32.model.VnfInfo;
-import org.apache.http.HttpStatus;
+import java.util.*;
+import javax.servlet.http.HttpServletResponse;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager;
import org.onap.vnfmdriver.model.JobDetailInfo;
import org.onap.vnfmdriver.model.JobDetailInfoResponseDescriptor;
@@ -34,8 +35,9 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import javax.servlet.http.HttpServletResponse;
-import java.util.*;
+import static javax.servlet.http.HttpServletResponse.SC_SERVICE_UNAVAILABLE;
+import static java.util.Optional.empty;
+import static java.util.Optional.of;
import static com.google.common.base.Splitter.on;
import static com.google.common.collect.Iterables.find;
@@ -43,8 +45,6 @@ import static com.google.common.collect.Iterables.tryFind;
import static com.google.common.collect.Lists.newArrayList;
import static com.nokia.cbam.lcm.v32.model.OperationStatus.FAILED;
import static com.nokia.cbam.lcm.v32.model.OperationStatus.STARTED;
-import static java.util.Optional.empty;
-import static java.util.Optional.of;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.SEPARATOR;
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;
@@ -109,11 +109,11 @@ public class JobManager {
String jobId = vnfId + SEPARATOR + UUID.randomUUID().toString();
synchronized (this) {
if (preparingForShutDown) {
- response.setStatus(HttpStatus.SC_SERVICE_UNAVAILABLE);
+ response.setStatus(SC_SERVICE_UNAVAILABLE);
throw buildFatalFailure(logger, "The service is preparing to shut down");
}
if (!selfRegistrationManager.isReady()) {
- response.setStatus(HttpStatus.SC_SERVICE_UNAVAILABLE);
+ response.setStatus(SC_SERVICE_UNAVAILABLE);
throw buildFatalFailure(logger, "The service is not yet ready");
}
}
@@ -285,7 +285,7 @@ public class JobManager {
}
private boolean isCurrentOperationTriggeredByJob(String jobId, OperationExecutionsApi cbamOperationExecutionApi, OperationExecution operationExecution) {
- if(OperationType.MODIFY_INFO.equals(operationExecution.getOperationType())){
+ if (OperationType.MODIFY_INFO.equals(operationExecution.getOperationType())) {
//the modify info is never triggered by an external job
return false;
}
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/LifecycleManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/LifecycleManager.java
index 36df12a6..1b813a39 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/LifecycleManager.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/LifecycleManager.java
@@ -23,6 +23,10 @@ import com.google.gson.JsonObject;
import com.nokia.cbam.catalog.v1.model.CatalogAdapterVnfpackage;
import com.nokia.cbam.lcm.v32.model.*;
import com.nokia.cbam.lcm.v32.model.ScaleDirection;
+import java.util.*;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import javax.servlet.http.HttpServletResponse;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.IGrantManager;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.VimInfoProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.StoreLoader;
@@ -36,10 +40,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.yaml.snakeyaml.Yaml;
-import javax.servlet.http.HttpServletResponse;
-import java.util.*;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
+import static java.lang.Integer.parseInt;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static com.google.common.base.Splitter.on;
import static com.google.common.collect.Iterables.find;
@@ -49,8 +51,6 @@ import static com.nokia.cbam.lcm.v32.model.InstantiationState.INSTANTIATED;
import static com.nokia.cbam.lcm.v32.model.OperationStatus.FINISHED;
import static com.nokia.cbam.lcm.v32.model.OperationType.INSTANTIATE;
import static com.nokia.cbam.lcm.v32.model.VimInfo.VimInfoTypeEnum.*;
-import static java.lang.Integer.parseInt;
-import static java.nio.charset.StandardCharsets.UTF_8;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.*;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider.NOKIA_LCM_API_VERSION;
@@ -437,11 +437,12 @@ public class LifecycleManager {
cbamRequest.setTerminationType(TerminationType.FORCEFUL);
}
}
+ cbamRequest.setAdditionalParams(new Gson().toJsonTree(jobInfo).getAsJsonObject());
com.nokia.cbam.lcm.v32.model.VnfInfo vnf = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdGet(vnfId, NOKIA_LCM_API_VERSION).blockingFirst();
if (vnf.getInstantiationState() == INSTANTIATED) {
terminateVnf(vnfmId, vnfId, jobInfo, cbamRequest, vnf);
} else {
- cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdDelete(vnfId, NOKIA_LCM_API_VERSION);
+ systemFunctions().blockingFirst(cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdDelete(vnfId, NOKIA_LCM_API_VERSION));
}
});
}
@@ -454,7 +455,7 @@ public class LifecycleManager {
if (finishedOperation.getStatus() == FINISHED) {
notificationManager.waitForTerminationToBeProcessed(finishedOperation.getId());
logger.info("Deleting VNF with {}", vnfId);
- cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdDelete(vnfId, NOKIA_LCM_API_VERSION);
+ systemFunctions().blockingFirst(cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdDelete(vnfId, NOKIA_LCM_API_VERSION));
logger.info("VNF with {} has been deleted", vnfId);
} else {
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/LifecycleChangeNotificationManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/LifecycleChangeNotificationManager.java
index d6fbd33f..1485ef59 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/LifecycleChangeNotificationManager.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/LifecycleChangeNotificationManager.java
@@ -23,6 +23,9 @@ import com.google.gson.JsonObject;
import com.nokia.cbam.lcm.v32.api.OperationExecutionsApi;
import com.nokia.cbam.lcm.v32.api.VnfsApi;
import com.nokia.cbam.lcm.v32.model.*;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.INotificationSender;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider;
@@ -33,17 +36,14 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import java.util.List;
-import java.util.Optional;
-import java.util.Set;
+import static java.util.Optional.empty;
+import static java.util.Optional.of;
import static com.google.common.collect.Iterables.find;
import static com.google.common.collect.Iterables.tryFind;
import static com.google.common.collect.Sets.newConcurrentHashSet;
import static com.google.common.collect.Sets.newHashSet;
import static com.nokia.cbam.lcm.v32.model.OperationType.INSTANTIATE;
-import static java.util.Optional.empty;
-import static java.util.Optional.of;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.buildFatalFailure;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.childElement;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider.NOKIA_LCM_API_VERSION;
@@ -192,6 +192,10 @@ public class LifecycleChangeNotificationManager implements ILifecycleChangeNotif
}
private Optional<ReportedAffectedConnectionPoints> buildAffectedCps(OperationExecution operationExecution) {
+ if (!isTerminal(operationExecution.getStatus())) {
+ //connection points can only be calculated after the operation has finished
+ return Optional.empty();
+ }
if (operationExecution.getOperationType() == OperationType.TERMINATE) {
String terminationType = childElement(new Gson().toJsonTree(operationExecution.getOperationParams()).getAsJsonObject(), "terminationType").getAsString();
if (TerminationType.FORCEFUL.name().equals(terminationType)) {
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/ProcessedNotification.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/ProcessedNotification.java
index 8f91604e..27007413 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/ProcessedNotification.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/ProcessedNotification.java
@@ -16,7 +16,6 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification;
import com.nokia.cbam.lcm.v32.model.OperationStatus;
-
import java.util.Objects;
/**
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/ReportedAffectedConnectionPoints.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/ReportedAffectedConnectionPoints.java
index 7bd79435..115685a4 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/ReportedAffectedConnectionPoints.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/ReportedAffectedConnectionPoints.java
@@ -16,7 +16,6 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification;
import com.google.gson.annotations.SerializedName;
-
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
diff --git a/nokiav2/driver/src/test/java/okhttp3/OakExtractor.java b/nokiav2/driver/src/test/java/okhttp3/OakExtractor.java
deleted file mode 100644
index ffeb88f4..00000000
--- a/nokiav2/driver/src/test/java/okhttp3/OakExtractor.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright 2016-2017, Nokia Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package okhttp3;
-
-import javax.net.ssl.HostnameVerifier;
-
-public class OakExtractor {
- /**
- * Cheat access control durting tests
- */
- public static HostnameVerifier extract(OkHttpClient.Builder okBuilder) {
- return okBuilder.hostnameVerifier;
- }
-}
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/FullUnitTestSuite.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/FullUnitTestSuite.java
index f0b24762..640097f3 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/FullUnitTestSuite.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/FullUnitTestSuite.java
@@ -41,8 +41,6 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.TestProcessed
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.TestReportedAffectedConnectionPoints;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.TestReportedAffectedCp;
-//import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.TestCbamRestApiProvider;
-
@RunWith(Suite.class)
@Suite.SuiteClasses({
TestGenericExternalSystemInfoProvider.class,
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/ct/CTDirectReal.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/ct/CTDirectReal.java
index 78939fdf..2bd0820c 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/ct/CTDirectReal.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/ct/CTDirectReal.java
@@ -18,6 +18,7 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.ct;
import com.google.gson.JsonObject;
import com.nokia.cbam.lcm.v32.model.*;
+import java.util.ArrayList;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.NokiaSvnfmApplication;
@@ -32,8 +33,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
-import java.util.ArrayList;
-
import static java.util.Optional.of;
@RunWith(value = SpringRunner.class)
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestGenericExternalSystemInfoProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestGenericExternalSystemInfoProvider.java
index a0d4ea4d..efa45234 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestGenericExternalSystemInfoProvider.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestGenericExternalSystemInfoProvider.java
@@ -26,6 +26,7 @@ import org.springframework.core.env.Environment;
import org.springframework.test.util.ReflectionTestUtils;
import static java.lang.Long.valueOf;
+
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.fail;
import static org.mockito.Mockito.*;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestMsbApiProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestMsbApiProvider.java
index eb3674c3..a0565206 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestMsbApiProvider.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestMsbApiProvider.java
@@ -16,20 +16,20 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core;
+import io.reactivex.Observable;
+import java.util.ArrayList;
+import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
-import org.onap.msb.sdk.discovery.common.RouteException;
-import org.onap.msb.sdk.discovery.entity.MicroServiceFullInfo;
-import org.onap.msb.sdk.discovery.entity.NodeInfo;
-import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
+import org.onap.msb.ApiClient;
+import org.onap.msb.api.ServiceResourceApi;
+import org.onap.msb.model.MicroServiceFullInfo;
+import org.onap.msb.model.NodeInfo;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamTokenProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
import org.springframework.core.env.Environment;
-import java.util.HashSet;
-import java.util.Set;
-
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.fail;
import static org.mockito.Mockito.verify;
@@ -42,7 +42,7 @@ public class TestMsbApiProvider extends TestBase {
@Mock
private CbamTokenProvider cbamTokenProvider;
private MicroServiceFullInfo microServiceInfo = new MicroServiceFullInfo();
- private Set<NodeInfo> nodes = new HashSet<>();
+ private List<NodeInfo> nodes = new ArrayList<>();
private MsbApiProvider msbApiProvider;
@Before
@@ -60,9 +60,9 @@ public class TestMsbApiProvider extends TestBase {
setFieldWithPropertyAnnotation(msbApiProvider, "${messageBusIp}", "mymessageBusIp");
setFieldWithPropertyAnnotation(msbApiProvider, "${messageBusPort}", "123");
//when
- MSBServiceClient msbClient = msbApiProvider.getMsbClient();
+ ApiClient msbClient = msbApiProvider.buildApiClient();
//verify
- assertEquals("mymessageBusIp:123", msbClient.getMsbSvrAddress());
+ assertEquals("http://mymessagebusip:123/api/msdiscover/v1/", msbClient.getAdapterBuilder().build().baseUrl().toString());
}
/**
@@ -79,18 +79,34 @@ public class TestMsbApiProvider extends TestBase {
nodes.add(dockerAccessPoint);
msbApiProvider = new MsbApiProvider(environment) {
@Override
- public MSBServiceClient getMsbClient() {
+ public ServiceResourceApi getMsbApi() {
return msbClient;
}
};
- when(msbClient.queryMicroServiceInfo("serviceName", "v1")).thenReturn(microServiceInfo);
+ when(msbClient.getMicroService_0("serviceName", "v1", null, null, null, null, null)).thenReturn(buildObservable(microServiceInfo));
//when
try {
msbApiProvider.getMicroServiceUrl("serviceName", "v1");
fail();
} catch (Exception e) {
- assertEquals("The serviceName service with v1 does not have any valid nodes[172.1.2.3:null ttl:]", e.getMessage());
- verify(logger).error("The serviceName service with v1 does not have any valid nodes[172.1.2.3:null ttl:]");
+ String msg = "The serviceName service with v1 does not have any valid nodes[class NodeInfo {\n" +
+ " ip: 172.1.2.3\n" +
+ " port: null\n" +
+ " lbServerParams: null\n" +
+ " checkType: null\n" +
+ " checkUrl: null\n" +
+ " checkInterval: null\n" +
+ " checkTimeOut: null\n" +
+ " ttl: null\n" +
+ " haRole: null\n" +
+ " nodeId: null\n" +
+ " status: null\n" +
+ " expiration: null\n" +
+ " createdAt: null\n" +
+ " updatedAt: null\n" +
+ "}]";
+ assertEquals(msg, e.getMessage());
+ verify(logger).error(msg);
}
}
@@ -109,11 +125,11 @@ public class TestMsbApiProvider extends TestBase {
nodes.add(nonDocker);
msbApiProvider = new MsbApiProvider(environment) {
@Override
- public MSBServiceClient getMsbClient() {
+ public ServiceResourceApi getMsbApi() {
return msbClient;
}
};
- when(msbClient.queryMicroServiceInfo("serviceName", "v1")).thenReturn(microServiceInfo);
+ when(msbClient.getMicroService_0("serviceName", "v1", null, null, null, null, null)).thenReturn(buildObservable(microServiceInfo));
msbApiProvider.afterPropertiesSet();
//when
assertEquals("http://1.2.3.4:234/lead/nslcm/v1", msbApiProvider.getMicroServiceUrl("serviceName", "v1"));
@@ -131,16 +147,16 @@ public class TestMsbApiProvider extends TestBase {
microServiceInfo.setServiceName("serviceName");
microServiceInfo.setVersion("v1");
microServiceInfo.setUrl("/lead/nslcm/v1");
- microServiceInfo.setEnable_ssl(true);
+ microServiceInfo.setEnableSsl(true);
when(environment.getProperty(IpMappingProvider.IP_MAP, String.class, "")).thenReturn("173.1.2.3->1.2.3.4");
nodes.add(nonDocker);
msbApiProvider = new MsbApiProvider(environment) {
@Override
- public MSBServiceClient getMsbClient() {
+ public ServiceResourceApi getMsbApi() {
return msbClient;
}
};
- when(msbClient.queryMicroServiceInfo("serviceName", "v1")).thenReturn(microServiceInfo);
+ when(msbClient.getMicroService_0("serviceName", "v1", null, null, null, null, null)).thenReturn(buildObservable(microServiceInfo));
msbApiProvider.afterPropertiesSet();
//when
assertEquals("https://1.2.3.4:123/lead/nslcm/v1", msbApiProvider.getMicroServiceUrl("serviceName", "v1"));
@@ -153,13 +169,12 @@ public class TestMsbApiProvider extends TestBase {
public void testUnableQueryMicroserviInfo() throws Exception {
msbApiProvider = new MsbApiProvider(environment) {
@Override
- public MSBServiceClient getMsbClient() {
+ public ServiceResourceApi getMsbApi() {
return msbClient;
}
};
- RouteException expectedException = new RouteException();
- when(msbClient.queryMicroServiceInfo("serviceName", "v1")).thenThrow(expectedException);
-
+ RuntimeException expectedException = new RuntimeException();
+ when(msbClient.getMicroService_0("serviceName", "v1", null, null, null, null, null)).thenReturn(Observable.error(expectedException));
//when
try {
msbApiProvider.getMicroServiceUrl("serviceName", "v1");
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIExternalSystemInfoProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIExternalSystemInfoProvider.java
index c1da617e..912a2209 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIExternalSystemInfoProvider.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIExternalSystemInfoProvider.java
@@ -15,13 +15,15 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct;
+import java.util.ArrayList;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
-import org.onap.aai.domain.yang.v11.EsrSystemInfo;
-import org.onap.aai.domain.yang.v11.EsrSystemInfoList;
-import org.onap.aai.domain.yang.v11.EsrVnfm;
-import org.onap.aai.domain.yang.v11.ObjectFactory;
+import org.onap.aai.api.CloudInfrastructureApi;
+import org.onap.aai.api.ExternalSystemApi;
+import org.onap.aai.model.CloudRegion;
+import org.onap.aai.model.EsrSystemInfo;
+import org.onap.aai.model.EsrVnfm;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
import org.onap.vnfmdriver.model.VimInfo;
import org.onap.vnfmdriver.model.VnfmInfo;
@@ -33,15 +35,20 @@ import static org.mockito.Mockito.when;
import static org.springframework.test.util.ReflectionTestUtils.setField;
public class TestAAIExternalSystemInfoProvider extends TestBase {
- private ObjectFactory OBJECT_FACTORY = new ObjectFactory();
private AAIExternalSystemInfoProvider aaiExternalSystemInfoProvider;
@Mock
private AAIRestApiProvider aaiRestApiProvider;
+ @Mock
+ private ExternalSystemApi externalSystemApi;
+ @Mock
+ private CloudInfrastructureApi cloudInfrastructureApi;
@Before
public void init() {
- aaiExternalSystemInfoProvider = new AAIExternalSystemInfoProvider(environment, aaiRestApiProvider);
setField(AAIExternalSystemInfoProvider.class, "logger", logger);
+ aaiExternalSystemInfoProvider = new AAIExternalSystemInfoProvider(environment, aaiRestApiProvider);
+ when(aaiRestApiProvider.getExternalSystemApi()).thenReturn(externalSystemApi);
+ when(aaiRestApiProvider.getCloudInfrastructureApi()).thenReturn(cloudInfrastructureApi);
}
/**
@@ -49,9 +56,10 @@ public class TestAAIExternalSystemInfoProvider extends TestBase {
*/
@Test
public void testVim() throws Exception {
- EsrSystemInfoList vims = OBJECT_FACTORY.createEsrSystemInfoList();
- EsrSystemInfo vim = OBJECT_FACTORY.createEsrSystemInfo();
- vims.getEsrSystemInfo().add(vim);
+ CloudRegion cloudRegion = new CloudRegion();
+ cloudRegion.setEsrSystemInfoList(new ArrayList<>());
+ EsrSystemInfo vim = new EsrSystemInfo();
+ cloudRegion.getEsrSystemInfoList().add(vim);
vim.setPassword("myPassword");
vim.setUserName("myUsername");
vim.setServiceUrl("http://1.2.3.4:1234/a");
@@ -61,7 +69,7 @@ public class TestAAIExternalSystemInfoProvider extends TestBase {
vim.setType("type");
vim.setSslInsecure(true);
vim.setVendor("vendor");
- when(aaiRestApiProvider.get(logger, AAIRestApiProvider.AAIService.CLOUD, "/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/esr-system-info-list", EsrSystemInfoList.class)).thenReturn(vims);
+ when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegion("myCloudOwnerId", "myRegionName", null, null)).thenReturn(buildObservable(cloudRegion));
//when
VimInfo vimInfo = aaiExternalSystemInfoProvider.getVimInfo(VIM_ID);
assertEquals("myPassword", vimInfo.getPassword());
@@ -84,9 +92,10 @@ public class TestAAIExternalSystemInfoProvider extends TestBase {
*/
@Test
public void testVimSsl() throws Exception {
- EsrSystemInfoList vims = OBJECT_FACTORY.createEsrSystemInfoList();
- EsrSystemInfo vim = OBJECT_FACTORY.createEsrSystemInfo();
- vims.getEsrSystemInfo().add(vim);
+ CloudRegion cloudRegion = new CloudRegion();
+ cloudRegion.setEsrSystemInfoList(new ArrayList<>());
+ EsrSystemInfo vim = new EsrSystemInfo();
+ cloudRegion.getEsrSystemInfoList().add(vim);
vim.setPassword("myPassword");
vim.setUserName("myUsername");
vim.setServiceUrl("https://1.2.3.4:1234/a");
@@ -97,7 +106,7 @@ public class TestAAIExternalSystemInfoProvider extends TestBase {
vim.setSslInsecure(false);
vim.setSslCacert("cert");
vim.setVendor("vendor");
- when(aaiRestApiProvider.get(logger, AAIRestApiProvider.AAIService.CLOUD, "/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/esr-system-info-list", EsrSystemInfoList.class)).thenReturn(vims);
+ when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegion("myCloudOwnerId", "myRegionName", null, null)).thenReturn(buildObservable(cloudRegion));
//when
VimInfo vimInfo = aaiExternalSystemInfoProvider.getVimInfo(VIM_ID);
assertEquals("myPassword", vimInfo.getPassword());
@@ -120,7 +129,7 @@ public class TestAAIExternalSystemInfoProvider extends TestBase {
@Test
public void testVimUnableToQuery() throws Exception {
RuntimeException expectedException = new RuntimeException();
- when(aaiRestApiProvider.get(logger, AAIRestApiProvider.AAIService.CLOUD, "/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/esr-system-info-list", EsrSystemInfoList.class)).thenThrow(expectedException);
+ when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegion("myCloudOwnerId", "myRegionName", null, null)).thenThrow(expectedException);
//when
try {
aaiExternalSystemInfoProvider.getVimInfo(VIM_ID);
@@ -136,11 +145,11 @@ public class TestAAIExternalSystemInfoProvider extends TestBase {
*/
@Test
public void testVnfmQuery() throws Exception {
- EsrVnfm vnfm = OBJECT_FACTORY.createEsrVnfm();
+ EsrVnfm vnfm = new EsrVnfm();
vnfm.setVimId(VIM_ID);
- vnfm.setEsrSystemInfoList(OBJECT_FACTORY.createEsrSystemInfoList());
- EsrSystemInfo esrInfo = OBJECT_FACTORY.createEsrSystemInfo();
- vnfm.getEsrSystemInfoList().getEsrSystemInfo().add(esrInfo);
+ vnfm.setEsrSystemInfoList(new ArrayList<>());
+ EsrSystemInfo esrInfo = new EsrSystemInfo();
+ vnfm.getEsrSystemInfoList().add(esrInfo);
esrInfo.setPassword("myPassword");
esrInfo.setUserName("myUsername");
esrInfo.setServiceUrl("https://1.2.3.4:1234/a");
@@ -152,7 +161,7 @@ public class TestAAIExternalSystemInfoProvider extends TestBase {
esrInfo.setSslCacert("cert");
esrInfo.setVendor("vendor");
vnfm.setVnfmId(VNFM_ID);
- when(aaiRestApiProvider.get(logger, AAIRestApiProvider.AAIService.ESR, "/esr-vnfm-list/esr-vnfm/" + VNFM_ID + "?depth=all", EsrVnfm.class)).thenReturn(vnfm);
+ when(externalSystemApi.getExternalSystemEsrVnfmListEsrVnfm(VNFM_ID)).thenReturn(buildObservable(vnfm));
//when
VnfmInfo actualVnfmInfo = aaiExternalSystemInfoProvider.queryVnfmInfoFromSource(VNFM_ID);
@@ -176,7 +185,7 @@ public class TestAAIExternalSystemInfoProvider extends TestBase {
@Test
public void testVnfmUnableToQuery() throws Exception {
RuntimeException expectedException = new RuntimeException();
- when(aaiRestApiProvider.get(logger, AAIRestApiProvider.AAIService.ESR, "/esr-vnfm-list/esr-vnfm/" + VNFM_ID + "?depth=all", EsrVnfm.class)).thenThrow(expectedException);
+ when(externalSystemApi.getExternalSystemEsrVnfmListEsrVnfm(VNFM_ID)).thenThrow(expectedException);
//when
try {
aaiExternalSystemInfoProvider.queryVnfmInfoFromSource(VNFM_ID);
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIRestApiProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIRestApiProvider.java
index 953f7da0..9c53aba1 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIRestApiProvider.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAAIRestApiProvider.java
@@ -15,224 +15,216 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct;
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.SSLSocketFactory;
+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.onap.aai.domain.yang.v11.GenericVnf;
-import org.onap.aai.domain.yang.v11.L3Network;
-import org.onap.aai.domain.yang.v11.ObjectFactory;
-import org.onap.aai.restclient.client.OperationResult;
-import org.onap.aai.restclient.client.RestClient;
-import org.onap.aai.restclient.enums.RestAuthenticationMode;
+import org.mockito.invocation.InvocationOnMock;
+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.vnfm.TestBase;
-import javax.xml.bind.JAXBContext;
-import java.io.ByteArrayOutputStream;
-import java.io.StringReader;
-import java.util.List;
-import java.util.Map;
-import java.util.NoSuchElementException;
-
-import static com.google.common.collect.Lists.newArrayList;
-import static java.util.Base64.getEncoder;
-import static javax.ws.rs.core.MediaType.APPLICATION_XML_TYPE;
-import static junit.framework.TestCase.*;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static junit.framework.TestCase.assertEquals;
+import static org.mockito.Mockito.*;
import static org.springframework.test.util.ReflectionTestUtils.setField;
-public class TestAAIRestApiProvider extends TestBase {
- private ObjectFactory OBJECT_FACTORY = new ObjectFactory();
- @Mock
- private RestClient restClient;
- private AAIRestApiProvider aaiRestApiProvider;
- private ArgumentCaptor<Map> headers = ArgumentCaptor.forClass(Map.class);
- private ArgumentCaptor<String> payload = ArgumentCaptor.forClass(String.class);
-
- private OperationResult result = new OperationResult();
+class ResultCaptor<T> implements Answer {
+ private T result = null;
- public static String marshall(Object object) throws Exception {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- JAXBContext.newInstance(object.getClass()).createMarshaller().marshal(object, bos);
- return bos.toString();
+ public T getResult() {
+ return result;
}
- public static <T> T unmarshal(String content, Class<T> clazz) {
- try {
- return (T) JAXBContext.newInstance(clazz).createUnmarshaller().unmarshal(new StringReader(content));
- } catch (Exception e) {
- throw new RuntimeException();
- }
+ @Override
+ public T answer(InvocationOnMock invocationOnMock) throws Throwable {
+ result = (T) invocationOnMock.callRealMethod();
+ return result;
}
+}
+
+public class TestAAIRestApiProvider extends TestBase {
+ private AAIRestApiProvider aaiRestApiProvider;
+ @Mock
+ private HostnameVerifier hostnameVerifier;
+ private AaiSecurityProvider aaiSecurityProvider = spy(new AaiSecurityProvider());
@Before
public void init() {
- //MockitoAnnotations.initMocks(this);
- AAIRestApiProvider real = new AAIRestApiProvider(msbApiProvider);
- setField(AAIRestApiProvider.class, "logger", logger);
- setFieldWithPropertyAnnotation(real, "${aaiUsername}", "aaiUsername");
- setFieldWithPropertyAnnotation(real, "${aaiPassword}", "aaiPassword");
- aaiRestApiProvider = Mockito.spy(real);
- when(aaiRestApiProvider.buildRawClient()).thenReturn(restClient);
- when(restClient.basicAuthPassword("aaiPassword")).thenReturn(restClient);
- when(restClient.basicAuthUsername("aaiUsername")).thenReturn(restClient);
- when(restClient.authenticationMode(RestAuthenticationMode.SSL_BASIC)).thenReturn(restClient);
- when(msbApiProvider.getMicroServiceUrl(AAIRestApiProvider.AAIService.CLOUD.getServiceName(), "v11")).thenReturn("x://1.2.3.4:4/a");
- result.setResultCode(201);
+ aaiRestApiProvider = new AAIRestApiProvider(msbApiProvider, aaiSecurityProvider);
}
/**
- * test HTTP GET success scenario
+ * test building a client to access AAI API
*/
@Test
- public void testGetSuccess() throws Exception {
- GenericVnf vnf = OBJECT_FACTORY.createGenericVnf();
- vnf.setVnfId("myVnfId");
- when(restClient.get(eq("x://1.2.3.4:4/a/myurl"), headers.capture(), eq(APPLICATION_XML_TYPE))).thenReturn(result);
- result.setResult(marshall(vnf));
+ public void testApiClientBuilder() throws Exception {
+ setField(aaiSecurityProvider, "skipCertificateVerification", true);
+ setField(aaiSecurityProvider, "skipHostnameVerification", true);
+ setFieldWithPropertyAnnotation(aaiRestApiProvider, "${aaiUsername}", "username");
+ setFieldWithPropertyAnnotation(aaiRestApiProvider, "${aaiPassword}", "aaiPassword");
+ ResultCaptor<SSLSocketFactory> sslSocketFactoryResultCaptor = new ResultCaptor<>();
+ doAnswer(sslSocketFactoryResultCaptor).when(aaiSecurityProvider).buildSSLSocketFactory();
+ when(msbApiProvider.getMicroServiceUrl(AAIRestApiProvider.AAIService.NETWORK.getServiceName(), "v11")).thenReturn("http://1.2.3.4/a/");
+ when(aaiSecurityProvider.buildHostnameVerifier()).thenReturn(hostnameVerifier);
//when
- GenericVnf actualVnf = aaiRestApiProvider.get(logger, AAIRestApiProvider.AAIService.CLOUD, "/myurl", GenericVnf.class);
+ org.onap.aai.ApiClient apiClient = aaiRestApiProvider.buildApiClient(AAIRestApiProvider.AAIService.NETWORK);
//verify
- assertEquals(vnf.getVnfId(), actualVnf.getVnfId());
- assertHeaders();
- }
-
- /**
- * HTTP GET on non existing resource results in {@link java.util.NoSuchElementException}
- */
- @Test
- public void testGetMissingResource() throws Exception {
- when(restClient.get(eq("x://1.2.3.4:4/a/myurl"), headers.capture(), eq(APPLICATION_XML_TYPE))).thenReturn(result);
- result.setResultCode(404);
- //when
- try {
- aaiRestApiProvider.get(logger, AAIRestApiProvider.AAIService.CLOUD, "/myurl", GenericVnf.class);
- fail();
- } catch (NoSuchElementException e) {
- verify(logger).debug("The resource at /myurl does not exists");
- assertEquals("The resource at /myurl does not exists", e.getMessage());
- }
- }
-
- /**
- * Non known HTTP response code is propagated
- */
- @Test
- public void testUnknownErroCode() throws Exception {
- when(restClient.get(eq("x://1.2.3.4:4/a/myurl"), headers.capture(), eq(APPLICATION_XML_TYPE))).thenReturn(result);
- result.setResultCode(502);
- result.setFailureCause("myFail");
- //when
- try {
- aaiRestApiProvider.get(logger, AAIRestApiProvider.AAIService.CLOUD, "/myurl", GenericVnf.class);
- fail();
- } catch (RuntimeException e) {
- verify(logger).error("Bad response. Code: 502 cause: myFail");
- assertEquals("Bad response. Code: 502 cause: myFail", e.getMessage());
- }
+ 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());
+ 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();
+ Request authenticate = apiClient.getOkBuilder().build().authenticator().authenticate(null, resp);
+ assertEquals("Basic dXNlcm5hbWU6YWFpUGFzc3dvcmQ=", authenticate.headers().get("Authorization"));
}
/**
- * response content is not used when not requesting result
+ * is slash is missing from micro service URL it is added
*/
@Test
- public void testNoResult() throws Exception {
- when(restClient.get(eq("x://1.2.3.4:4/a/myurl"), headers.capture(), eq(APPLICATION_XML_TYPE))).thenReturn(result);
- result.setResultCode(202);
+ public void testApiClientBuilderMissingSlash() throws Exception {
+ setField(aaiSecurityProvider, "skipCertificateVerification", true);
+ setField(aaiSecurityProvider, "skipHostnameVerification", true);
+ setFieldWithPropertyAnnotation(aaiRestApiProvider, "${aaiUsername}", "username");
+ setFieldWithPropertyAnnotation(aaiRestApiProvider, "${aaiPassword}", "aaiPassword");
+ ResultCaptor<SSLSocketFactory> sslSocketFactoryResultCaptor = new ResultCaptor<>();
+ doAnswer(sslSocketFactoryResultCaptor).when(aaiSecurityProvider).buildSSLSocketFactory();
+ when(msbApiProvider.getMicroServiceUrl(AAIRestApiProvider.AAIService.NETWORK.getServiceName(), "v11")).thenReturn("http://1.2.3.4/a");
+ when(aaiSecurityProvider.buildHostnameVerifier()).thenReturn(hostnameVerifier);
//when
- Void result = aaiRestApiProvider.get(logger, AAIRestApiProvider.AAIService.CLOUD, "/myurl", Void.class);
+ org.onap.aai.ApiClient apiClient = aaiRestApiProvider.buildApiClient(AAIRestApiProvider.AAIService.NETWORK);
//verify
- assertNull(result);
+ 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());
+ 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();
+ Request authenticate = apiClient.getOkBuilder().build().authenticator().authenticate(null, resp);
+ assertEquals("Basic dXNlcm5hbWU6YWFpUGFzc3dvcmQ=", authenticate.headers().get("Authorization"));
}
/**
- * test HTTP PUT success scenario
+ * test building a client to access AAI API
*/
@Test
- public void putSuccess() throws Exception {
- when(restClient.put(eq("x://1.2.3.4:4/a/myurl"), payload.capture(), headers.capture(), eq(APPLICATION_XML_TYPE), eq(APPLICATION_XML_TYPE))).thenReturn(result);
- GenericVnf request = OBJECT_FACTORY.createGenericVnf();
- request.setVnfId("myVnfId");
- L3Network response = OBJECT_FACTORY.createL3Network();
- response.setNetworkId("myNetworkId");
- result.setResult(marshall(response));
+ public void testApiClientBuilderForCloud() throws Exception {
+ setField(aaiSecurityProvider, "skipCertificateVerification", true);
+ setField(aaiSecurityProvider, "skipHostnameVerification", true);
+ setFieldWithPropertyAnnotation(aaiRestApiProvider, "${aaiUsername}", "username");
+ setFieldWithPropertyAnnotation(aaiRestApiProvider, "${aaiPassword}", "aaiPassword");
+ ResultCaptor<SSLSocketFactory> sslSocketFactoryResultCaptor = new ResultCaptor<>();
+ doAnswer(sslSocketFactoryResultCaptor).when(aaiSecurityProvider).buildSSLSocketFactory();
+ when(msbApiProvider.getMicroServiceUrl(AAIRestApiProvider.AAIService.CLOUD.getServiceName(), "v11")).thenReturn("http://1.2.3.4/a/");
+ when(aaiSecurityProvider.buildHostnameVerifier()).thenReturn(hostnameVerifier);
//when
- L3Network actualResponse = aaiRestApiProvider.put(logger, AAIRestApiProvider.AAIService.CLOUD, "/myurl", request, L3Network.class);
+ org.onap.aai.ApiClient apiClient = aaiRestApiProvider.buildApiClient(AAIRestApiProvider.AAIService.CLOUD);
//verify
- GenericVnf actualValue = unmarshal(payload.getValue(), GenericVnf.class);
- assertEquals("myVnfId", actualValue.getVnfId());
- assertEquals("myNetworkId", actualResponse.getNetworkId());
- assertHeaders();
+ 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());
+ 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();
+ Request authenticate = apiClient.getOkBuilder().build().authenticator().authenticate(null, resp);
+ assertEquals("Basic dXNlcm5hbWU6YWFpUGFzc3dvcmQ=", authenticate.headers().get("Authorization"));
}
/**
- * test HTTP delete success scenario
+ * test building a client to access AAI API
*/
@Test
- public void deleteSuccess() throws Exception {
- when(restClient.delete(eq("x://1.2.3.4:4/a/myurl"), headers.capture(), eq(APPLICATION_XML_TYPE))).thenReturn(result);
+ public void testApiClientBuilderForExternalSystems() throws Exception {
+ setField(aaiSecurityProvider, "skipCertificateVerification", true);
+ setField(aaiSecurityProvider, "skipHostnameVerification", true);
+ setFieldWithPropertyAnnotation(aaiRestApiProvider, "${aaiUsername}", "username");
+ setFieldWithPropertyAnnotation(aaiRestApiProvider, "${aaiPassword}", "aaiPassword");
+ ResultCaptor<SSLSocketFactory> sslSocketFactoryResultCaptor = new ResultCaptor<>();
+ doAnswer(sslSocketFactoryResultCaptor).when(aaiSecurityProvider).buildSSLSocketFactory();
+ when(msbApiProvider.getMicroServiceUrl(AAIRestApiProvider.AAIService.ESR.getServiceName(), "v11")).thenReturn("http://1.2.3.4/a/");
+ when(aaiSecurityProvider.buildHostnameVerifier()).thenReturn(hostnameVerifier);
//when
- aaiRestApiProvider.delete(logger, AAIRestApiProvider.AAIService.CLOUD, "/myurl");
+ org.onap.aai.ApiClient apiClient = aaiRestApiProvider.buildApiClient(AAIRestApiProvider.AAIService.ESR);
//verify
- assertHeaders();
- //the when above is the verify
+ 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());
+ 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();
+ Request authenticate = apiClient.getOkBuilder().build().authenticator().authenticate(null, resp);
+ assertEquals("Basic dXNlcm5hbWU6YWFpUGFzc3dvcmQ=", authenticate.headers().get("Authorization"));
}
/**
- * invalid request content results in error
+ * Test API wrapping for NetworkApi
+ * (questionable benefit [ this is more less ensured by Java type safety) ]
*/
@Test
- public void testInvalidInput() throws Exception {
- when(restClient.put(eq("x://1.2.3.4:4/a/myurl"), payload.capture(), headers.capture(), eq(APPLICATION_XML_TYPE), eq(APPLICATION_XML_TYPE))).thenReturn(result);
- //when
- try {
- aaiRestApiProvider.put(logger, AAIRestApiProvider.AAIService.CLOUD, "/myurl", "Invalid content", L3Network.class);
- //verify
- fail();
- } catch (Exception e) {
- assertEquals("Unable to marshal content", e.getMessage());
- verify(logger).error("Unable to marshal content", e.getCause());
+ public void testNetworkApiAPiWrapping() {
+ org.onap.aai.ApiClient c = Mockito.mock(org.onap.aai.ApiClient.class);
+ class TestClasss extends AAIRestApiProvider {
+ public TestClasss() {
+ super(msbApiProvider, aaiSecurityProvider);
+ }
+
+ @Override
+ org.onap.aai.ApiClient buildApiClient(AAIRestApiProvider.AAIService service) {
+ return c;
+ }
}
+ NetworkApi defaultApi = Mockito.mock(NetworkApi.class);
+ when(c.createService(NetworkApi.class)).thenReturn(defaultApi);
+ //verify
+ TestClasss testInstnace = new TestClasss();
+ assertEquals(defaultApi, testInstnace.getNetworkApi());
}
/**
- * invalid response content results in error
+ * Test API wrapping for CloudInfrastructureApi
+ * (questionable benefit [ this is more less ensured by Java type safety) ]
*/
@Test
- public void testInvalidResponse() throws Exception {
- when(restClient.put(eq("x://1.2.3.4:4/a/myurl"), payload.capture(), headers.capture(), eq(APPLICATION_XML_TYPE), eq(APPLICATION_XML_TYPE))).thenReturn(result);
- GenericVnf request = OBJECT_FACTORY.createGenericVnf();
- request.setVnfId("myVnfId");
- result.setResult("invalid");
- //when
- try {
- aaiRestApiProvider.put(logger, AAIRestApiProvider.AAIService.CLOUD, "/myurl", request, L3Network.class);
- //verify
- fail();
- } catch (Exception e) {
- assertEquals("Unable to unmarshal content", e.getMessage());
- verify(logger).error("Unable to unmarshal content", e.getCause());
+ public void testCloudInfrastructureApiWrapping() {
+ org.onap.aai.ApiClient c = Mockito.mock(org.onap.aai.ApiClient.class);
+ class TestClasss extends AAIRestApiProvider {
+ public TestClasss() {
+ super(msbApiProvider, aaiSecurityProvider);
+ }
+
+ @Override
+ org.onap.aai.ApiClient buildApiClient(AAIRestApiProvider.AAIService service) {
+ return c;
+ }
}
+ CloudInfrastructureApi defaultApi = Mockito.mock(CloudInfrastructureApi.class);
+ when(c.createService(CloudInfrastructureApi.class)).thenReturn(defaultApi);
+ //verify
+ TestClasss testInstnace = new TestClasss();
+ assertEquals(defaultApi, testInstnace.getCloudInfrastructureApi());
}
/**
- * test AAI service names in AAI
+ * Test API wrapping for ExternalSystemApi
+ * (questionable benefit [ this is more less ensured by Java type safety) ]
*/
@Test
- public void testServiceNames() {
- //the names have been base64-ed to prevent "smart" IDEs (idea) to refactor the tests too for the otherwise known fix constants in external systems
- assertEquals("YWFpLWNsb3VkSW5mcmFzdHJ1Y3R1cmU=", getEncoder().encodeToString(AAIRestApiProvider.AAIService.CLOUD.getServiceName().getBytes()));
- assertEquals("YWFpLW5ldHdvcms=", getEncoder().encodeToString(AAIRestApiProvider.AAIService.NETWORK.getServiceName().getBytes()));
- assertEquals("YWFpLWV4dGVybmFsU3lzdGVt", getEncoder().encodeToString(AAIRestApiProvider.AAIService.ESR.getServiceName().getBytes()));
- }
-
- private void assertHeaders() {
- Map<String, List<String>> actualHeaders = headers.getValue();
- assertEquals(2, actualHeaders.size());
- assertEquals(newArrayList("NokiaSVNFM"), actualHeaders.get("X-FromAppId"));
- assertEquals(newArrayList("application/xml"), actualHeaders.get("Accept"));
+ public void testExternalSystemApiWrapping() {
+ org.onap.aai.ApiClient c = Mockito.mock(org.onap.aai.ApiClient.class);
+ class TestClasss extends AAIRestApiProvider {
+ public TestClasss() {
+ super(msbApiProvider, aaiSecurityProvider);
+ }
+
+ @Override
+ org.onap.aai.ApiClient buildApiClient(AAIRestApiProvider.AAIService service) {
+ return c;
+ }
+ }
+ ExternalSystemApi defaultApi = Mockito.mock(ExternalSystemApi.class);
+ when(c.createService(ExternalSystemApi.class)).thenReturn(defaultApi);
+ //verify
+ TestClasss testInstnace = new TestClasss();
+ assertEquals(defaultApi, testInstnace.getExternalSystemApi());
}
}
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAaiSecurityProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAaiSecurityProvider.java
new file mode 100644
index 00000000..4fbd0b27
--- /dev/null
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestAaiSecurityProvider.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2016-2017, Nokia Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct;
+
+import org.junit.Test;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
+
+import static junit.framework.TestCase.assertEquals;
+
+
+public class TestAaiSecurityProvider extends TestBase {
+ private AaiSecurityProvider securityProvider = new AaiSecurityProvider();
+
+ /**
+ * test property handling
+ */
+ @Test
+ public void init() throws Exception {
+ setFieldWithPropertyAnnotation(securityProvider, "${skipHostnameVerificationForAai}", true);
+ setFieldWithPropertyAnnotation(securityProvider, "${skipCertificateVerificationForAai}", true);
+ setFieldWithPropertyAnnotation(securityProvider, "${trustedCertificatesForAai}", "cert");
+
+ assertEquals(true, securityProvider.skipCertificateVerification());
+ assertEquals(true, securityProvider.skipHostnameVerification());
+ assertEquals("cert", securityProvider.trustedCertificates());
+ }
+
+}
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestSdcPackageProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestSdcPackageProvider.java
index 199f7255..87b065f0 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestSdcPackageProvider.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/TestSdcPackageProvider.java
@@ -15,16 +15,15 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.NoSuchElementException;
import org.apache.http.client.methods.HttpGet;
import org.junit.Before;
import org.junit.Test;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.util.NoSuchElementException;
-
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.fail;
import static org.apache.http.HttpHeaders.ACCEPT;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAAINotificationProcessor.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAAINotificationProcessor.java
index 7bc7df7a..d183e38e 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAAINotificationProcessor.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAAINotificationProcessor.java
@@ -17,6 +17,8 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
import com.google.gson.JsonObject;
import com.nokia.cbam.lcm.v32.model.*;
+import java.util.ArrayList;
+import java.util.UUID;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InOrder;
@@ -26,12 +28,10 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.ReportedAffectedConnectionPoints;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.ReportedAffectedCp;
-import java.util.ArrayList;
-import java.util.UUID;
-
-import static com.nokia.cbam.lcm.v32.model.ChangeType.*;
import static java.util.Optional.empty;
import static java.util.Optional.of;
+
+import static com.nokia.cbam.lcm.v32.model.ChangeType.*;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.springframework.test.util.ReflectionTestUtils.setField;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAbstractManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAbstractManager.java
index 2495daf1..8991b819 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAbstractManager.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestAbstractManager.java
@@ -16,23 +16,24 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
import com.google.gson.JsonObject;
+import java.util.ArrayList;
+import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
-import org.onap.aai.domain.yang.v11.*;
+import org.onap.aai.model.GenericVnf;
+import org.onap.aai.model.Relationship;
+import org.onap.aai.model.RelationshipData;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
import org.slf4j.Logger;
-import java.util.NoSuchElementException;
-
+import static io.reactivex.Observable.error;
import static junit.framework.TestCase.assertEquals;
-import static org.mockito.Mockito.when;
public class TestAbstractManager extends TestBase {
- private ObjectFactory OBJECT_FACTORY = new ObjectFactory();
@Mock
private AAIRestApiProvider aaiRestApiProvider;
private DummyManager dummyManager;
@@ -47,10 +48,9 @@ public class TestAbstractManager extends TestBase {
*/
@Test
public void testIfResourceDoesNotExists() throws Exception {
- GenericVnf newInstance = OBJECT_FACTORY.createGenericVnf();
- when(aaiRestApiProvider.get(logger, AAIRestApiProvider.AAIService.CLOUD, "url", GenericVnf.class)).thenThrow(new NoSuchElementException());
+ GenericVnf newInstance = new GenericVnf();
//when
- GenericVnf actualInstance = dummyManager.createOrGet(AAIRestApiProvider.AAIService.CLOUD, "url", newInstance);
+ GenericVnf actualInstance = dummyManager.createOrGet(error(new RuntimeException()), newInstance);
//verify
assertEquals(newInstance, actualInstance);
}
@@ -60,16 +60,17 @@ public class TestAbstractManager extends TestBase {
*/
@Test
public void testIfResourceExists() throws Exception {
- GenericVnf newInstance = OBJECT_FACTORY.createGenericVnf();
- GenericVnf existingInstance = OBJECT_FACTORY.createGenericVnf();
- existingInstance.setVnfId("id");
- when(aaiRestApiProvider.get(logger, AAIRestApiProvider.AAIService.CLOUD, "url", GenericVnf.class)).thenReturn(existingInstance);
+ GenericVnf newInstance = new GenericVnf();
+ GenericVnf existingInstance = new GenericVnf();
//when
- GenericVnf actualInstance = dummyManager.createOrGet(AAIRestApiProvider.AAIService.CLOUD, "url", newInstance);
+ GenericVnf actualInstance = dummyManager.createOrGet(buildObservable(existingInstance), newInstance);
//verify
assertEquals(existingInstance, actualInstance);
}
+ /**
+ * Test relationship data builder
+ */
@Test
public void testBuildRelationshipData() {
RelationshipData relationshipData = AbstractManager.buildRelationshipData("key", "value");
@@ -77,6 +78,9 @@ public class TestAbstractManager extends TestBase {
assertEquals("value", relationshipData.getRelationshipValue());
}
+ /**
+ * test mandatory value extraction
+ */
@Test
public void testExtractMandatoryValue() {
JsonObject object = new JsonObject();
@@ -89,33 +93,36 @@ public class TestAbstractManager extends TestBase {
*/
@Test
public void testAddSingletonRelationForExisting() {
- RelationshipList relations = OBJECT_FACTORY.createRelationshipList();
- Relationship relation = OBJECT_FACTORY.createRelationship();
+ List<Relationship> relationships = new ArrayList<>();
+ Relationship relation = new Relationship();
relation.setRelatedTo("unknownRelation");
- relations.getRelationship().add(relation);
- Relationship sameRelation = OBJECT_FACTORY.createRelationship();
+ relation.setRelationshipData(new ArrayList<>());
+ relationships.add(relation);
+ Relationship sameRelation = new Relationship();
sameRelation.setRelatedTo("relatedTo");
- relations.getRelationship().add(sameRelation);
- RelationshipData data = OBJECT_FACTORY.createRelationshipData();
+ relationships.add(sameRelation);
+ RelationshipData data = new RelationshipData();
data.setRelationshipValue("v");
data.setRelationshipKey("k");
+ sameRelation.setRelationshipData(new ArrayList<>());
sameRelation.getRelationshipData().add(data);
- Relationship newRelation = OBJECT_FACTORY.createRelationship();
+ Relationship newRelation = new Relationship();
newRelation.setRelatedTo("relatedTo");
- RelationshipData data2 = OBJECT_FACTORY.createRelationshipData();
+ RelationshipData data2 = new RelationshipData();
data2.setRelationshipValue("v2");
data2.setRelationshipKey("k2");
+ newRelation.setRelationshipData(new ArrayList<>());
newRelation.getRelationshipData().add(data2);
//when
- AbstractManager.addSingletonRelation(relations, newRelation);
+ AbstractManager.addSingletonRelation(relationships, newRelation);
//verify
- assertEquals(2, relations.getRelationship().size());
- assertEquals(1, relations.getRelationship().get(1).getRelationshipData().size());
- assertEquals("k2", relations.getRelationship().get(1).getRelationshipData().get(0).getRelationshipKey());
- assertEquals("v2", relations.getRelationship().get(1).getRelationshipData().get(0).getRelationshipValue());
+ assertEquals(2, relationships.size());
+ assertEquals(1, relationships.get(1).getRelationshipData().size());
+ assertEquals("k2", relationships.get(1).getRelationshipData().get(0).getRelationshipKey());
+ assertEquals("v2", relationships.get(1).getRelationshipData().get(0).getRelationshipValue());
}
/**
@@ -123,25 +130,28 @@ public class TestAbstractManager extends TestBase {
*/
@Test
public void testAddSingletonRelation() {
- RelationshipList relations = OBJECT_FACTORY.createRelationshipList();
- Relationship relation = OBJECT_FACTORY.createRelationship();
+ Relationship relation = new Relationship();
relation.setRelatedTo("unknownRelation");
- relations.getRelationship().add(relation);
+ List<Relationship> relationships = new ArrayList<>();
+
+ relationships.add(relation);
- Relationship newRelation = OBJECT_FACTORY.createRelationship();
+ Relationship newRelation = new Relationship();
newRelation.setRelatedTo("relatedTo");
- RelationshipData data2 = OBJECT_FACTORY.createRelationshipData();
+ RelationshipData data2 = new RelationshipData();
+ ;
data2.setRelationshipValue("v2");
data2.setRelationshipKey("k2");
+ newRelation.setRelationshipData(new ArrayList<>());
newRelation.getRelationshipData().add(data2);
//when
- AbstractManager.addSingletonRelation(relations, newRelation);
+ AbstractManager.addSingletonRelation(relationships, newRelation);
//verify
- assertEquals(2, relations.getRelationship().size());
- assertEquals(1, relations.getRelationship().get(1).getRelationshipData().size());
- assertEquals("k2", relations.getRelationship().get(1).getRelationshipData().get(0).getRelationshipKey());
- assertEquals("v2", relations.getRelationship().get(1).getRelationshipData().get(0).getRelationshipValue());
+ assertEquals(2, relationships.size());
+ assertEquals(1, relationships.get(1).getRelationshipData().size());
+ assertEquals("k2", relationships.get(1).getRelationshipData().get(0).getRelationshipKey());
+ assertEquals("v2", relationships.get(1).getRelationshipData().get(0).getRelationshipValue());
}
/**
@@ -149,35 +159,39 @@ public class TestAbstractManager extends TestBase {
*/
@Test
public void testAddMissingRelationForExisting() {
- RelationshipList relations = OBJECT_FACTORY.createRelationshipList();
- Relationship relation = OBJECT_FACTORY.createRelationship();
+ List<Relationship> relationships = new ArrayList<>();
+ Relationship relation = new Relationship();
relation.setRelatedTo("unknownRelation");
- relations.getRelationship().add(relation);
- Relationship sameRelation = OBJECT_FACTORY.createRelationship();
+ relationships.add(relation);
+ Relationship sameRelation = new Relationship();
sameRelation.setRelatedTo("relatedTo");
- relations.getRelationship().add(sameRelation);
- RelationshipData data = OBJECT_FACTORY.createRelationshipData();
+ relationships.add(sameRelation);
+ RelationshipData data = new RelationshipData();
+ ;
data.setRelationshipValue("v");
data.setRelationshipKey("k");
+ sameRelation.setRelationshipData(new ArrayList<>());
sameRelation.getRelationshipData().add(data);
- Relationship newRelation = OBJECT_FACTORY.createRelationship();
+ Relationship newRelation = new Relationship();
newRelation.setRelatedTo("relatedTo");
- RelationshipData data2 = OBJECT_FACTORY.createRelationshipData();
+ RelationshipData data2 = new RelationshipData();
+ ;
data2.setRelationshipValue("v2");
data2.setRelationshipKey("k2");
+ newRelation.setRelationshipData(new ArrayList<>());
newRelation.getRelationshipData().add(data2);
//when
- AbstractManager.addMissingRelation(relations, newRelation);
+ AbstractManager.addMissingRelation(relationships, newRelation);
//verify
- assertEquals(3, relations.getRelationship().size());
- assertEquals(1, relations.getRelationship().get(1).getRelationshipData().size());
- assertEquals("k", relations.getRelationship().get(1).getRelationshipData().get(0).getRelationshipKey());
- assertEquals("v", relations.getRelationship().get(1).getRelationshipData().get(0).getRelationshipValue());
- assertEquals("k2", relations.getRelationship().get(2).getRelationshipData().get(0).getRelationshipKey());
- assertEquals("v2", relations.getRelationship().get(2).getRelationshipData().get(0).getRelationshipValue());
+ assertEquals(3, relationships.size());
+ assertEquals(1, relationships.get(1).getRelationshipData().size());
+ assertEquals("k", relationships.get(1).getRelationshipData().get(0).getRelationshipKey());
+ assertEquals("v", relationships.get(1).getRelationshipData().get(0).getRelationshipValue());
+ assertEquals("k2", relationships.get(2).getRelationshipData().get(0).getRelationshipKey());
+ assertEquals("v2", relationships.get(2).getRelationshipData().get(0).getRelationshipValue());
}
/**
@@ -185,33 +199,37 @@ public class TestAbstractManager extends TestBase {
*/
@Test
public void testAddMissingRelation() {
- RelationshipList relations = OBJECT_FACTORY.createRelationshipList();
- Relationship relation = OBJECT_FACTORY.createRelationship();
+ Relationship relation = new Relationship();
relation.setRelatedTo("unknownRelation");
- relations.getRelationship().add(relation);
+ List<Relationship> relationships = new ArrayList<>();
+ relationships.add(relation);
- Relationship sameRelation = OBJECT_FACTORY.createRelationship();
+ Relationship sameRelation = new Relationship();
sameRelation.setRelatedTo("relatedTo");
- relations.getRelationship().add(sameRelation);
- RelationshipData data = OBJECT_FACTORY.createRelationshipData();
+ relationships.add(sameRelation);
+ RelationshipData data = new RelationshipData();
+ ;
data.setRelationshipValue("v");
data.setRelationshipKey("k");
+ sameRelation.setRelationshipData(new ArrayList<>());
sameRelation.getRelationshipData().add(data);
- Relationship newRelation = OBJECT_FACTORY.createRelationship();
+ Relationship newRelation = new Relationship();
newRelation.setRelatedTo("relatedTo");
- RelationshipData data2 = OBJECT_FACTORY.createRelationshipData();
+ RelationshipData data2 = new RelationshipData();
+ ;
data2.setRelationshipValue("v");
data2.setRelationshipKey("k");
+ newRelation.setRelationshipData(new ArrayList<>());
newRelation.getRelationshipData().add(data2);
//when
- AbstractManager.addMissingRelation(relations, newRelation);
+ AbstractManager.addMissingRelation(relationships, newRelation);
//verify
- assertEquals(2, relations.getRelationship().size());
- assertEquals(1, relations.getRelationship().get(1).getRelationshipData().size());
- assertEquals("k", relations.getRelationship().get(1).getRelationshipData().get(0).getRelationshipKey());
- assertEquals("v", relations.getRelationship().get(1).getRelationshipData().get(0).getRelationshipValue());
+ assertEquals(2, relationships.size());
+ assertEquals(1, relationships.get(1).getRelationshipData().size());
+ assertEquals("k", relationships.get(1).getRelationshipData().get(0).getRelationshipKey());
+ assertEquals("v", relationships.get(1).getRelationshipData().get(0).getRelationshipValue());
}
class DummyManager extends AbstractManager {
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestGenericVnfManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestGenericVnfManager.java
index 7cddb50e..514098b6 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestGenericVnfManager.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestGenericVnfManager.java
@@ -16,6 +16,12 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
import com.nokia.cbam.lcm.v32.model.VnfInfo;
+import io.reactivex.Observable;
+import java.util.HashSet;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -23,35 +29,35 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
-import org.onap.aai.domain.yang.v11.*;
+import org.onap.aai.api.NetworkApi;
+import org.onap.aai.model.GenericVnf;
+import org.onap.aai.model.Relationship;
+import org.onap.aai.model.RelationshipData;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
-import java.util.HashSet;
-import java.util.NoSuchElementException;
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicLong;
+import static java.lang.Boolean.TRUE;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.fail;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;
-import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider.AAIService.NETWORK;
import static org.springframework.test.util.ReflectionTestUtils.setField;
public class TestGenericVnfManager extends TestBase {
- private ObjectFactory OBJECT_FACTORY = new ObjectFactory();
private ArgumentCaptor<GenericVnf> payload = ArgumentCaptor.forClass(GenericVnf.class);
@Mock
private AAIRestApiProvider aaiRestApiProvider;
+ @Mock
+ private NetworkApi networkApi;
private GenericVnfManager genericVnfManager;
private VnfInfo vnfInfo = new VnfInfo();
- static void assertRelation(RelationshipList relationShips, String relatedTo, RelationshipData... data) {
- for (Relationship relationship : relationShips.getRelationship()) {
+ static void assertRelation(List<Relationship> relationShips, String relatedTo, RelationshipData... data) {
+ for (Relationship relationship : relationShips) {
if (relationship.getRelatedTo().equals(relatedTo)) {
assertEquals(data.length, relationship.getRelationshipData().size());
int i = 0;
@@ -68,6 +74,7 @@ public class TestGenericVnfManager extends TestBase {
@Before
public void init() {
+ when(aaiRestApiProvider.getNetworkApi()).thenReturn(networkApi);
genericVnfManager = new GenericVnfManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
setField(GenericVnfManager.class, "logger", logger);
AtomicLong currentTime = new AtomicLong(0L);
@@ -87,33 +94,20 @@ public class TestGenericVnfManager extends TestBase {
}
/**
- * retrieving an existing VNF
- */
- @Test
- public void testGetExistingVnf() throws Exception {
- GenericVnf aaiVnf = OBJECT_FACTORY.createGenericVnf();
- when(aaiRestApiProvider.get(logger, NETWORK, "/generic-vnfs/generic-vnf/" + VNF_ID, GenericVnf.class)).thenReturn(aaiVnf);
- //when
- GenericVnf vnf = genericVnfManager.getExistingVnf(VNF_ID);
- //verify
- assertEquals(aaiVnf, vnf);
- }
-
- /**
* if the VNF does not exist it is created
*/
@Test
public void createNonExistingVnf() throws Exception {
- GenericVnf vnfInAaai = OBJECT_FACTORY.createGenericVnf();
+ GenericVnf vnfInAaai = new GenericVnf();
Set<GenericVnf> vnfs = new HashSet<>();
- when(aaiRestApiProvider.get(logger, NETWORK, "/generic-vnfs/generic-vnf/" + VNF_ID, GenericVnf.class)).thenAnswer((Answer<GenericVnf>) invocation -> {
+ when(networkApi.getNetworkGenericVnfsGenericVnf(VNF_ID, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null)).thenAnswer((Answer<Observable<GenericVnf>>) invocation -> {
if (vnfs.size() == 0) {
throw new NoSuchElementException();
}
- return vnfs.iterator().next();
+ return buildObservable(vnfs.iterator().next());
});
when(cbamRestApiProvider.getCbamLcmApi(VNFM_ID).vnfsVnfInstanceIdGet(VNF_ID, CbamRestApiProvider.NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo));
- when(aaiRestApiProvider.put(eq(logger), eq(NETWORK), eq("/generic-vnfs/generic-vnf/" + VNF_ID), payload.capture(), eq(Void.class))).thenAnswer(invocation -> {
+ when(networkApi.createOrUpdateNetworkGenericVnfsGenericVnf(eq(VNF_ID), payload.capture())).thenAnswer(invocation -> {
vnfs.add(vnfInAaai);
return null;
});
@@ -123,13 +117,13 @@ public class TestGenericVnfManager extends TestBase {
//verify
GenericVnf vnfSentToAai = payload.getValue();
assertEquals(VNF_ID, vnfSentToAai.getVnfId());
- assertEquals(VNF_ID, vnfSentToAai.getVnfInstanceId());
+ assertEquals(VNF_ID, vnfSentToAai.getVnfId());
assertEquals("NokiaVNF", vnfSentToAai.getVnfType());
- assertEquals(true, vnfSentToAai.isInMaint());
- assertEquals(true, vnfSentToAai.isIsClosedLoopDisabled());
+ assertEquals(TRUE, vnfSentToAai.isInMaint());
+ assertEquals(TRUE, vnfSentToAai.isIsClosedLoopDisabled());
assertEquals("vnfName", vnfSentToAai.getVnfName());
verify(systemFunctions, times(10)).sleep(3000);
- verify(aaiRestApiProvider, times(10)).get(logger, NETWORK, "/generic-vnfs/generic-vnf/" + VNF_ID, GenericVnf.class);
+ verify(networkApi, times(10)).getNetworkGenericVnfsGenericVnf(VNF_ID, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
}
/**
@@ -137,24 +131,24 @@ public class TestGenericVnfManager extends TestBase {
*/
@Test
public void testUpdateExistingVnf() throws Exception {
- GenericVnf vnfInAaai = OBJECT_FACTORY.createGenericVnf();
+ GenericVnf vnfInAaai = new GenericVnf();
vnfInAaai.setResourceVersion("v1");
- when(aaiRestApiProvider.get(logger, NETWORK, "/generic-vnfs/generic-vnf/" + VNF_ID, GenericVnf.class)).thenReturn(vnfInAaai);
+ 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(aaiRestApiProvider.put(eq(logger), eq(NETWORK), eq("/generic-vnfs/generic-vnf/" + VNF_ID), payload.capture(), eq(Void.class))).thenReturn(null);
+ when(networkApi.createOrUpdateNetworkGenericVnfsGenericVnf(eq(VNF_ID), payload.capture())).thenReturn(null);
vnfInfo.setName("vnfName");
//when
genericVnfManager.createOrUpdate(VNF_ID, true);
//verify
GenericVnf vnfSentToAai = payload.getValue();
assertEquals(VNF_ID, vnfSentToAai.getVnfId());
- assertEquals(VNF_ID, vnfSentToAai.getVnfInstanceId());
+ assertEquals(VNF_ID, vnfSentToAai.getVnfId());
assertEquals("NokiaVNF", vnfSentToAai.getVnfType());
- assertEquals(true, vnfSentToAai.isInMaint());
- assertEquals(true, vnfSentToAai.isIsClosedLoopDisabled());
+ assertEquals(TRUE, vnfSentToAai.isInMaint());
+ assertEquals(TRUE, vnfSentToAai.isIsClosedLoopDisabled());
assertEquals("vnfName", vnfSentToAai.getVnfName());
verify(systemFunctions, never()).sleep(anyLong());
- verify(aaiRestApiProvider, times(1)).get(logger, NETWORK, "/generic-vnfs/generic-vnf/" + VNF_ID, GenericVnf.class);
+ verify(networkApi, times(1)).getNetworkGenericVnfsGenericVnf(VNF_ID, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
}
/**
@@ -162,12 +156,12 @@ public class TestGenericVnfManager extends TestBase {
*/
@Test
public void testUnableToQueryVnfFromCBAM() throws Exception {
- GenericVnf vnfInAaai = OBJECT_FACTORY.createGenericVnf();
+ GenericVnf vnfInAaai = new GenericVnf();
vnfInAaai.setResourceVersion("v1");
- when(aaiRestApiProvider.get(logger, NETWORK, "/generic-vnfs/generic-vnf/" + VNF_ID, GenericVnf.class)).thenReturn(vnfInAaai);
+ 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));
RuntimeException expectedException = new RuntimeException();
when(cbamRestApiProvider.getCbamLcmApi(VNFM_ID).vnfsVnfInstanceIdGet(VNF_ID, CbamRestApiProvider.NOKIA_LCM_API_VERSION)).thenThrow(expectedException);
- when(aaiRestApiProvider.put(eq(logger), eq(NETWORK), eq("/generic-vnfs/generic-vnf/" + VNF_ID), payload.capture(), eq(Void.class))).thenAnswer(invocation -> {
+ when(networkApi.createOrUpdateNetworkGenericVnfsGenericVnf(eq(VNF_ID), payload.capture())).thenAnswer(invocation -> {
vnfInAaai.setResourceVersion("v2");
return null;
});
@@ -187,20 +181,20 @@ public class TestGenericVnfManager extends TestBase {
*/
@Test
public void testConcurency1() throws Exception {
- GenericVnf vnfInAaai = OBJECT_FACTORY.createGenericVnf();
+ GenericVnf vnfInAaai = new GenericVnf();
vnfInAaai.setResourceVersion("v3");
Set<Integer> queryCount = new HashSet<>();
- when(aaiRestApiProvider.get(logger, NETWORK, "/generic-vnfs/generic-vnf/" + VNF_ID, GenericVnf.class)).thenAnswer((Answer<GenericVnf>) invocation -> {
+ when(networkApi.getNetworkGenericVnfsGenericVnf(VNF_ID, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null)).thenAnswer((Answer<Observable>) invocationOnMock -> {
queryCount.add(queryCount.size());
if (queryCount.size() >= 11) {
- return vnfInAaai;
+ return buildObservable(vnfInAaai);
}
throw new NoSuchElementException();
});
when(cbamRestApiProvider.getCbamLcmApi(VNFM_ID).vnfsVnfInstanceIdGet(VNF_ID, CbamRestApiProvider.NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo));
RuntimeException runtimeException = new RuntimeException();
- when(aaiRestApiProvider.put(eq(logger), eq(NETWORK), eq("/generic-vnfs/generic-vnf/" + VNF_ID), payload.capture(), eq(Void.class))).thenAnswer(invocation -> {
- GenericVnf vnfSentToAAi = (GenericVnf) invocation.getArguments()[3];
+ when(networkApi.createOrUpdateNetworkGenericVnfsGenericVnf(eq(VNF_ID), payload.capture())).thenAnswer(invocation -> {
+ GenericVnf vnfSentToAAi = (GenericVnf) invocation.getArguments()[1];
if (vnfSentToAAi.getResourceVersion() == null) {
throw runtimeException;
}
@@ -212,15 +206,15 @@ public class TestGenericVnfManager extends TestBase {
//verify
GenericVnf vnfSentToAai = payload.getValue();
assertEquals(VNF_ID, vnfSentToAai.getVnfId());
- assertEquals(VNF_ID, vnfSentToAai.getVnfInstanceId());
+ assertEquals(VNF_ID, vnfSentToAai.getVnfId());
assertEquals("NokiaVNF", vnfSentToAai.getVnfType());
- assertEquals(true, vnfSentToAai.isInMaint());
- assertEquals(true, vnfSentToAai.isIsClosedLoopDisabled());
+ assertEquals(TRUE, vnfSentToAai.isInMaint());
+ assertEquals(TRUE, vnfSentToAai.isIsClosedLoopDisabled());
assertEquals("vnfName", vnfSentToAai.getVnfName());
assertEquals("v3", vnfSentToAai.getResourceVersion());
verify(systemFunctions, times(10)).sleep(3000);
- verify(aaiRestApiProvider, times(11)).get(logger, NETWORK, "/generic-vnfs/generic-vnf/" + VNF_ID, GenericVnf.class);
- verify(aaiRestApiProvider, times(2)).put(eq(logger), eq(NETWORK), eq("/generic-vnfs/generic-vnf/" + VNF_ID), any(), eq(Void.class));
+ verify(networkApi, times(11)).getNetworkGenericVnfsGenericVnf(VNF_ID, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
+ 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);
}
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestL3NetworkManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestL3NetworkManager.java
index 373c5dd0..47dbb95d 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestL3NetworkManager.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestL3NetworkManager.java
@@ -18,24 +18,20 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
import com.google.gson.JsonObject;
import com.nokia.cbam.lcm.v32.model.AffectedVirtualLink;
import com.nokia.cbam.lcm.v32.model.ResourceHandle;
+import java.util.ArrayList;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.onap.aai.domain.yang.v11.L3Network;
-import org.onap.aai.domain.yang.v11.ObjectFactory;
-import org.onap.aai.domain.yang.v11.RelationshipList;
+import org.onap.aai.api.NetworkApi;
+import org.onap.aai.model.L3Network;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
-import java.util.NoSuchElementException;
-
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-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.onap.direct.notification.AbstractManager.buildRelationshipData;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.TestGenericVnfManager.assertRelation;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getCloudOwner;
@@ -43,17 +39,19 @@ import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.ge
import static org.springframework.test.util.ReflectionTestUtils.setField;
public class TestL3NetworkManager extends TestBase {
- private ObjectFactory OBJECT_FACTORY = new ObjectFactory();
private ArgumentCaptor<L3Network> payload = ArgumentCaptor.forClass(L3Network.class);
private AffectedVirtualLink affectedVirtualLink = new AffectedVirtualLink();
@Mock
private AAIRestApiProvider aaiRestApiProvider;
private L3NetworkManager l3NetworkManager;
+ @Mock
+ private NetworkApi networkApi;
@Before
public void init() {
l3NetworkManager = new L3NetworkManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
setField(L3NetworkManager.class, "logger", logger);
+ when(aaiRestApiProvider.getNetworkApi()).thenReturn(networkApi);
}
/**
@@ -68,8 +66,9 @@ public class TestL3NetworkManager extends TestBase {
affectedVirtualLink.setResource(new ResourceHandle());
affectedVirtualLink.getResource().setAdditionalData(additionalData);
affectedVirtualLink.getResource().setResourceId("netProviderId");
- when(aaiRestApiProvider.get(logger, NETWORK, "/l3-networks/l3-network/myVnfId_vlId", L3Network.class)).thenThrow(new NoSuchElementException());
- when(aaiRestApiProvider.put(eq(logger), eq(NETWORK), eq("/l3-networks/l3-network/myVnfId_vlId"), payload.capture(), eq(Void.class))).thenReturn(null);
+ 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
l3NetworkManager.update(VIM_ID, VNF_ID, affectedVirtualLink);
//verify
@@ -98,11 +97,11 @@ public class TestL3NetworkManager extends TestBase {
affectedVirtualLink.setResource(new ResourceHandle());
affectedVirtualLink.getResource().setAdditionalData(additionalData);
affectedVirtualLink.getResource().setResourceId("netProviderId");
- L3Network l3Network = OBJECT_FACTORY.createL3Network();
+ L3Network l3Network = new L3Network();
l3Network.setResourceVersion("v3");
- l3Network.setRelationshipList(new RelationshipList());
- when(aaiRestApiProvider.get(logger, NETWORK, "/l3-networks/l3-network/myVnfId_vlId", L3Network.class)).thenReturn(l3Network);
- when(aaiRestApiProvider.put(eq(logger), eq(NETWORK), eq("/l3-networks/l3-network/myVnfId_vlId"), payload.capture(), eq(Void.class))).thenReturn(null);
+ 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
l3NetworkManager.update(VIM_ID, VNF_ID, affectedVirtualLink);
//verify
@@ -126,10 +125,13 @@ public class TestL3NetworkManager extends TestBase {
@Test
public void testDelete() throws Exception {
affectedVirtualLink.setId("vlId");
+ L3Network l3Network = new L3Network();
+ l3Network.setResourceVersion("v3");
+ when(networkApi.getNetworkL3NetworksL3Network("myVnfId_vlId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(l3Network));
//when
l3NetworkManager.delete(VNF_ID, affectedVirtualLink);
//verify
- verify(aaiRestApiProvider).delete(logger, NETWORK, "/l3-networks/l3-network/myVnfId_vlId");
+ networkApi.deleteNetworkL3NetworksL3Network("myVnfId_vlId", "v3");
}
/**
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestLInterfaceManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestLInterfaceManager.java
index ef9f569e..3728bdb2 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestLInterfaceManager.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestLInterfaceManager.java
@@ -15,40 +15,41 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
+import java.util.ArrayList;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.onap.aai.domain.yang.v11.LInterface;
-import org.onap.aai.domain.yang.v11.ObjectFactory;
-import org.onap.aai.domain.yang.v11.RelationshipList;
+import org.onap.aai.api.CloudInfrastructureApi;
+import org.onap.aai.model.LInterface;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.ReportedAffectedCp;
-import java.util.NoSuchElementException;
+import static java.lang.Boolean.FALSE;
+import static java.lang.Boolean.TRUE;
import static junit.framework.TestCase.assertEquals;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider.AAIService.CLOUD;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.AbstractManager.buildRelationshipData;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.TestGenericVnfManager.assertRelation;
import static org.springframework.test.util.ReflectionTestUtils.setField;
public class TestLInterfaceManager extends TestBase {
- private ObjectFactory OBJECT_FACTORY = new ObjectFactory();
private ArgumentCaptor<LInterface> payload = ArgumentCaptor.forClass(LInterface.class);
@Mock
private AAIRestApiProvider aaiRestApiProvider;
private LInterfaceManager lInterfaceManager;
+ @Mock
+ private CloudInfrastructureApi cloudInfrastructureApi;
@Before
public void init() {
lInterfaceManager = new LInterfaceManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
setField(LInterfaceManager.class, "logger", logger);
+ when(aaiRestApiProvider.getCloudInfrastructureApi()).thenReturn(cloudInfrastructureApi);
}
/**
@@ -67,22 +68,25 @@ public class TestLInterfaceManager extends TestBase {
affectedCp.setEcpdId("ecpdId");
affectedCp.setName("name");
affectedCp.setCpId("cpId");
- when(aaiRestApiProvider.get(eq(logger), eq(CLOUD), eq("/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId/l-interfaces/l-interface/cpId"), eq(LInterface.class))).thenThrow(new NoSuchElementException());
- when(aaiRestApiProvider.put(eq(logger), eq(CLOUD), eq("/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId/l-interfaces/l-interface/cpId"), payload.capture(), eq(Void.class))).thenReturn(null);
+ 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
lInterfaceManager.update(VNF_ID, VIM_ID, affectedCp, true);
//verify
LInterface actualInterface = payload.getValue();
- assertEquals(true, actualInterface.isInMaint());
- assertEquals(false, actualInterface.isIsIpUnnumbered());
- assertEquals(false, actualInterface.isIsPortMirrored());
+ assertEquals(TRUE, actualInterface.isInMaint());
+ assertEquals(FALSE, actualInterface.isIsIpUnnumbered());
+ assertEquals(FALSE, actualInterface.isIsPortMirrored());
assertEquals("name", actualInterface.getInterfaceName());
assertEquals("cpId", actualInterface.getInterfaceId());
assertEquals("cpdId", actualInterface.getInterfaceRole());
assertEquals("mac", actualInterface.getMacaddr());
assertEquals("active", actualInterface.getProvStatus());
assertEquals(1, actualInterface.getL3InterfaceIpv4AddressList().size());
- assertEquals(0, actualInterface.getL3InterfaceIpv6AddressList().size());
+ assertEquals(null, actualInterface.getL3InterfaceIpv6AddressList());
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));
@@ -103,22 +107,25 @@ public class TestLInterfaceManager extends TestBase {
affectedCp.setEcpdId("ecpdId");
affectedCp.setName("name");
affectedCp.setCpId("cpId");
- when(aaiRestApiProvider.get(eq(logger), eq(CLOUD), eq("/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId/l-interfaces/l-interface/cpId"), eq(LInterface.class))).thenThrow(new NoSuchElementException());
- when(aaiRestApiProvider.put(eq(logger), eq(CLOUD), eq("/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId/l-interfaces/l-interface/cpId"), payload.capture(), eq(Void.class))).thenReturn(null);
+ 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
lInterfaceManager.update(VNF_ID, VIM_ID, affectedCp, true);
//verify
LInterface actualInterface = payload.getValue();
- assertEquals(true, actualInterface.isInMaint());
- assertEquals(false, actualInterface.isIsIpUnnumbered());
- assertEquals(false, actualInterface.isIsPortMirrored());
+ assertEquals(TRUE, actualInterface.isInMaint());
+ assertEquals(FALSE, actualInterface.isIsIpUnnumbered());
+ assertEquals(FALSE, actualInterface.isIsPortMirrored());
assertEquals("name", actualInterface.getInterfaceName());
assertEquals("cpId", actualInterface.getInterfaceId());
assertEquals("cpdId", actualInterface.getInterfaceRole());
assertEquals("mac", actualInterface.getMacaddr());
assertEquals("active", actualInterface.getProvStatus());
- assertEquals(0, actualInterface.getL3InterfaceIpv6AddressList().size());
- assertEquals(0, actualInterface.getL3InterfaceIpv4AddressList().size());
+ assertEquals(null, actualInterface.getL3InterfaceIpv6AddressList());
+ assertEquals(null, actualInterface.getL3InterfaceIpv4AddressList());
assertRelation(actualInterface.getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
}
@@ -138,25 +145,25 @@ public class TestLInterfaceManager extends TestBase {
affectedCp.setEcpdId("ecpdId");
affectedCp.setName("name");
affectedCp.setCpId("cpId");
- LInterface lInterface = OBJECT_FACTORY.createLInterface();
+ LInterface lInterface = new LInterface();
lInterface.setResourceVersion("v3");
- lInterface.setRelationshipList(new RelationshipList());
- when(aaiRestApiProvider.get(eq(logger), eq(CLOUD), eq("/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId/l-interfaces/l-interface/cpId"), eq(LInterface.class))).thenReturn(lInterface);
- when(aaiRestApiProvider.put(eq(logger), eq(CLOUD), eq("/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId/l-interfaces/l-interface/cpId"), payload.capture(), eq(Void.class))).thenReturn(null);
+ 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
lInterfaceManager.update(VNF_ID, VIM_ID, affectedCp, true);
//verify
LInterface actualInterface = payload.getValue();
- assertEquals(true, actualInterface.isInMaint());
- assertEquals(false, actualInterface.isIsIpUnnumbered());
- assertEquals(false, actualInterface.isIsPortMirrored());
+ assertEquals(TRUE, actualInterface.isInMaint());
+ assertEquals(FALSE, actualInterface.isIsIpUnnumbered());
+ assertEquals(FALSE, actualInterface.isIsPortMirrored());
assertEquals("name", actualInterface.getInterfaceName());
assertEquals("cpId", actualInterface.getInterfaceId());
assertEquals("cpdId", actualInterface.getInterfaceRole());
assertEquals("mac", actualInterface.getMacaddr());
assertEquals("active", actualInterface.getProvStatus());
assertEquals(1, actualInterface.getL3InterfaceIpv4AddressList().size());
- assertEquals(0, actualInterface.getL3InterfaceIpv6AddressList().size());
+ assertEquals(null, actualInterface.getL3InterfaceIpv6AddressList());
assertEquals("networkProviderId", actualInterface.getL3InterfaceIpv4AddressList().get(0).getNeutronNetworkId());
assertEquals("1.2.3.4", actualInterface.getL3InterfaceIpv4AddressList().get(0).getL3InterfaceIpv4Address());
assertEquals("v3", lInterface.getResourceVersion());
@@ -179,21 +186,24 @@ public class TestLInterfaceManager extends TestBase {
affectedCp.setEcpdId("ecpdId");
affectedCp.setName("name");
affectedCp.setCpId("cpId");
- when(aaiRestApiProvider.get(eq(logger), eq(CLOUD), eq("/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId/l-interfaces/l-interface/cpId"), eq(LInterface.class))).thenThrow(new NoSuchElementException());
- when(aaiRestApiProvider.put(eq(logger), eq(CLOUD), eq("/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId/l-interfaces/l-interface/cpId"), payload.capture(), eq(Void.class))).thenReturn(null);
+ 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
lInterfaceManager.update(VNF_ID, VIM_ID, affectedCp, false);
//verify
LInterface actualInterface = payload.getValue();
- assertEquals(false, actualInterface.isInMaint());
- assertEquals(false, actualInterface.isIsIpUnnumbered());
- assertEquals(false, actualInterface.isIsPortMirrored());
+ assertEquals(FALSE, actualInterface.isInMaint());
+ assertEquals(FALSE, actualInterface.isIsIpUnnumbered());
+ assertEquals(FALSE, actualInterface.isIsPortMirrored());
assertEquals("name", actualInterface.getInterfaceName());
assertEquals("cpId", actualInterface.getInterfaceId());
assertEquals("cpdId", actualInterface.getInterfaceRole());
assertEquals("mac", actualInterface.getMacaddr());
assertEquals("active", actualInterface.getProvStatus());
- assertEquals(0, actualInterface.getL3InterfaceIpv4AddressList().size());
+ assertEquals(null, actualInterface.getL3InterfaceIpv4AddressList());
assertEquals(1, actualInterface.getL3InterfaceIpv6AddressList().size());
assertEquals("networkProviderId", actualInterface.getL3InterfaceIpv6AddressList().get(0).getNeutronNetworkId());
assertEquals("::", actualInterface.getL3InterfaceIpv6AddressList().get(0).getL3InterfaceIpv6Address());
@@ -212,10 +222,14 @@ public class TestLInterfaceManager extends TestBase {
affectedCp.setProviderId("portProviderId");
affectedCp.setServerProviderId("serverProviderId");
affectedCp.setNetworkProviderId("networkProviderId");
+ 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
lInterfaceManager.delete(VIM_ID, affectedCp);
//verify
- verify(aaiRestApiProvider).delete(logger, CLOUD, "/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId/l-interfaces/l-interface/cpId");
+ cloudInfrastructureApi.deleteCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", "cpId", "v3");
}
/**
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVnfcManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVnfcManager.java
index 87a1149b..8b41c3f8 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVnfcManager.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVnfcManager.java
@@ -21,17 +21,15 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.onap.aai.domain.yang.v11.ObjectFactory;
-import org.onap.aai.domain.yang.v11.Vnfc;
+import org.onap.aai.api.NetworkApi;
+import org.onap.aai.model.Vnfc;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
-import java.util.NoSuchElementException;
-
import static junit.framework.TestCase.assertEquals;
import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-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.onap.direct.notification.AbstractManager.buildRelationshipData;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.TestGenericVnfManager.assertRelation;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getCloudOwner;
@@ -39,17 +37,19 @@ import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.ge
import static org.springframework.test.util.ReflectionTestUtils.setField;
public class TestVnfcManager extends TestBase {
- private ObjectFactory OBJECT_FACTORY = new ObjectFactory();
private ArgumentCaptor<Vnfc> payload = ArgumentCaptor.forClass(Vnfc.class);
@Mock
private AAIRestApiProvider aaiRestApiProvider;
private VnfcManager vnfcManager;
+ @Mock
+ private NetworkApi networkApi;
@Before
public void init() {
vnfcManager = new VnfcManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
setField(VnfcManager.class, "logger", logger);
+ when(aaiRestApiProvider.getNetworkApi()).thenReturn(networkApi);
}
/**
@@ -61,8 +61,9 @@ public class TestVnfcManager extends TestBase {
affectedVnfc.setComputeResource(new ResourceHandle());
affectedVnfc.getComputeResource().setResourceId("serverProviderId");
affectedVnfc.setId("vnfcId");
- when(aaiRestApiProvider.get(eq(logger), eq(NETWORK), eq("/vnfcs/vnfc/myVnfId_vnfcId"), eq(Vnfc.class))).thenThrow(new NoSuchElementException());
- when(aaiRestApiProvider.put(eq(logger), eq(NETWORK), eq("/vnfcs/vnfc/myVnfId_vnfcId"), payload.capture(), eq(Void.class))).thenReturn(null);
+ Vnfc existingVnfc = new Vnfc();
+ 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
vnfcManager.update(VIM_ID, "myTenantPrivderId", VNF_ID, affectedVnfc, true);
//verify
@@ -88,12 +89,14 @@ public class TestVnfcManager extends TestBase {
affectedVnfc.setComputeResource(new ResourceHandle());
affectedVnfc.getComputeResource().setResourceId("serverProviderId");
affectedVnfc.setId("vnfcId");
- when(aaiRestApiProvider.get(eq(logger), eq(NETWORK), eq("/vnfcs/vnfc/myVnfId_vnfcId"), eq(Vnfc.class))).thenThrow(new NoSuchElementException());
- when(aaiRestApiProvider.put(eq(logger), eq(NETWORK), eq("/vnfcs/vnfc/myVnfId_vnfcId"), payload.capture(), eq(Void.class))).thenReturn(null);
+ Vnfc existingVnfc = new Vnfc();
+ 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
vnfcManager.delete(VNF_ID, affectedVnfc);
//verify
- aaiRestApiProvider.delete(logger, NETWORK, "/vnfcs/vnfc/myVnfId_vnfcId");
+ verify(networkApi).deleteNetworkVnfcsVnfc("myVnfId_vnfcId", "v3");
}
/**
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVserverManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVserverManager.java
index bb5d1d3d..68f5ab5f 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVserverManager.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/TestVserverManager.java
@@ -20,22 +20,22 @@ import com.google.gson.JsonObject;
import com.nokia.cbam.lcm.v32.model.AffectedVirtualStorage;
import com.nokia.cbam.lcm.v32.model.AffectedVnfc;
import com.nokia.cbam.lcm.v32.model.ResourceHandle;
+import java.util.ArrayList;
+import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.onap.aai.domain.yang.v11.*;
+import org.onap.aai.api.CloudInfrastructureApi;
+import org.onap.aai.model.Relationship;
+import org.onap.aai.model.Vserver;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.NoSuchElementException;
-
import static junit.framework.TestCase.assertEquals;
import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider.AAIService.CLOUD;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.AbstractManager.buildRelationshipData;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.TestGenericVnfManager.assertRelation;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getCloudOwner;
@@ -43,17 +43,19 @@ import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.ge
import static org.springframework.test.util.ReflectionTestUtils.setField;
public class TestVserverManager extends TestBase {
- private ObjectFactory OBJECT_FACTORY = new ObjectFactory();
private ArgumentCaptor<Vserver> payload = ArgumentCaptor.forClass(Vserver.class);
@Mock
private AAIRestApiProvider aaiRestApiProvider;
private VserverManager vserverManager;
+ @Mock
+ private CloudInfrastructureApi cloudInfrastructureApi;
@Before
public void init() {
vserverManager = new VserverManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
setField(VserverManager.class, "logger", logger);
+ when(aaiRestApiProvider.getCloudInfrastructureApi()).thenReturn(cloudInfrastructureApi);
}
/**
@@ -89,12 +91,12 @@ public class TestVserverManager extends TestBase {
affectedVnfc.setStorageResourceIds(new ArrayList<>());
affectedVnfc.getStorageResourceIds().add("sId");
- String url = "/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId";
+ String url = "/cloud-regions/cloud-region///tenants/tenant//vservers/vserver/";
- Vserver existingVserver = OBJECT_FACTORY.createVserver();
- existingVserver.setVolumes(new Volumes());
- when(aaiRestApiProvider.get(eq(logger), eq(CLOUD), eq(url), eq(Vserver.class))).thenReturn(existingVserver);
- when(aaiRestApiProvider.put(eq(logger), eq(CLOUD), eq(url), payload.capture(), eq(Void.class))).thenReturn(null);
+ 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
vserverManager.update(VIM_ID, VNF_ID, affectedVnfc, affectedStorages, true);
//verify
@@ -103,8 +105,8 @@ public class TestVserverManager extends TestBase {
assertEquals("active", vserver.getProvStatus());
assertEquals("serverName", vserver.getVserverName());
assertEquals("url", vserver.getVserverSelflink());
- assertEquals(1, vserver.getVolumes().getVolume().size());
- assertEquals("storageProviderId", vserver.getVolumes().getVolume().get(0).getVolumeId());
+ assertEquals(1, vserver.getVolumes().size());
+ assertEquals("storageProviderId", vserver.getVolumes().get(0).getVolumeId());
}
/**
@@ -130,9 +132,10 @@ public class TestVserverManager extends TestBase {
affectedVnfc.setStorageResourceIds(new ArrayList<>());
affectedVnfc.getStorageResourceIds().add("sId");
- String url = "/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId";
- when(aaiRestApiProvider.get(eq(logger), eq(CLOUD), eq(url), eq(Vserver.class))).thenThrow(new NoSuchElementException());
- when(aaiRestApiProvider.put(eq(logger), eq(CLOUD), eq(url), payload.capture(), eq(Void.class))).thenReturn(null);
+ 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
vserverManager.update(VIM_ID, VNF_ID, affectedVnfc, affectedStorages, true);
//verify
@@ -141,8 +144,8 @@ public class TestVserverManager extends TestBase {
assertEquals("active", vserver.getProvStatus());
assertEquals("serverName", vserver.getVserverName());
assertEquals("unknown", vserver.getVserverSelflink());
- assertEquals(1, vserver.getVolumes().getVolume().size());
- assertEquals("storageProviderId", vserver.getVolumes().getVolume().get(0).getVolumeId());
+ assertEquals(1, vserver.getVolumes().size());
+ assertEquals("storageProviderId", vserver.getVolumes().get(0).getVolumeId());
}
/**
@@ -166,9 +169,10 @@ public class TestVserverManager extends TestBase {
affectedVnfc.setStorageResourceIds(new ArrayList<>());
affectedVnfc.getStorageResourceIds().add("sId");
- String url = "/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId";
- when(aaiRestApiProvider.get(eq(logger), eq(CLOUD), eq(url), eq(Vserver.class))).thenThrow(new NoSuchElementException());
- when(aaiRestApiProvider.put(eq(logger), eq(CLOUD), eq(url), payload.capture(), eq(Void.class))).thenReturn(null);
+ 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
vserverManager.update(VIM_ID, VNF_ID, affectedVnfc, affectedStorages, true);
//verify
@@ -177,8 +181,8 @@ public class TestVserverManager extends TestBase {
assertEquals("active", vserver.getProvStatus());
assertEquals("serverName", vserver.getVserverName());
assertEquals("unknown", vserver.getVserverSelflink());
- assertEquals(1, vserver.getVolumes().getVolume().size());
- assertEquals("storageProviderId", vserver.getVolumes().getVolume().get(0).getVolumeId());
+ assertEquals(1, vserver.getVolumes().size());
+ assertEquals("storageProviderId", vserver.getVolumes().get(0).getVolumeId());
}
/**
@@ -195,9 +199,10 @@ public class TestVserverManager extends TestBase {
affectedVnfc.getComputeResource().setAdditionalData(additionalData);
affectedVnfc.setId("vnfcId");
List<AffectedVirtualStorage> affectedStorages = new ArrayList<>();
- String url = "/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId";
- when(aaiRestApiProvider.get(eq(logger), eq(CLOUD), eq(url), eq(Vserver.class))).thenThrow(new NoSuchElementException());
- when(aaiRestApiProvider.put(eq(logger), eq(CLOUD), eq(url), payload.capture(), eq(Void.class))).thenReturn(null);
+ 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
vserverManager.update(VIM_ID, VNF_ID, affectedVnfc, affectedStorages, true);
//verify
@@ -206,7 +211,7 @@ public class TestVserverManager extends TestBase {
assertEquals("active", vserver.getProvStatus());
assertEquals("serverName", vserver.getVserverName());
assertEquals("unknown", vserver.getVserverSelflink());
- assertEquals(0, vserver.getVolumes().getVolume().size());
+ assertEquals(0, vserver.getVolumes().size());
}
/**
@@ -222,18 +227,23 @@ public class TestVserverManager extends TestBase {
additionalData.addProperty("tenantId", "myTenantId");
affectedVnfc.getComputeResource().setAdditionalData(additionalData);
affectedVnfc.setId("vnfcId");
+ Vserver existingVserver = new Vserver();
+ existingVserver.setResourceVersion("v3");
+ existingVserver.setVserverId("serverProviderId");
+ 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
vserverManager.delete(VIM_ID, affectedVnfc);
//verify
- String url = "/cloud-regions/cloud-region/myCloudOwnerId/myRegionName/tenants/tenant/myTenantId/vservers/vserver/serverProviderId";
- aaiRestApiProvider.delete(logger, CLOUD, url);
+ verify(cloudInfrastructureApi).deleteCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", "v3");
}
@Test
public void testLinks() {
Relationship relationship = VserverManager.linkTo(VIM_ID, "myTenantPrivderId", "serverProviderId");
- RelationshipList relationships = new RelationshipList();
- relationships.getRelationship().add(relationship);
+ List<Relationship> relationships = new ArrayList<>();
+ relationships.add(relationship);
assertRelation(relationships, "vserver",
buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)),
buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)),
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcGrantManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcGrantManager.java
index 53e8f8d7..6fc61981 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcGrantManager.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcGrantManager.java
@@ -21,6 +21,10 @@ import com.google.gson.JsonObject;
import com.nokia.cbam.lcm.v32.model.*;
import com.nokia.cbam.lcm.v32.model.VnfInfo;
import io.reactivex.Observable;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -34,12 +38,8 @@ import org.onap.vnfmdriver.model.*;
import org.onap.vnfmdriver.model.ScaleDirection;
import retrofit2.Call;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
import static java.nio.file.Files.readAllBytes;
+
import static junit.framework.TestCase.*;
import static org.mockito.Mockito.*;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider.NOKIA_LCM_API_VERSION;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcNotificationSender.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcNotificationSender.java
index 4fbae45f..a701a159 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcNotificationSender.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcNotificationSender.java
@@ -27,6 +27,8 @@ import com.nokia.cbam.lcm.v32.model.ChangeType;
import com.nokia.cbam.lcm.v32.model.*;
import com.nokia.cbam.lcm.v32.model.OperationType;
import com.nokia.cbam.lcm.v32.model.ScaleDirection;
+import java.util.ArrayList;
+import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -36,11 +38,9 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.ReportedAffec
import org.onap.vnfmdriver.model.*;
import org.threeten.bp.OffsetDateTime;
-import java.util.ArrayList;
-import java.util.List;
-
import static java.util.Optional.empty;
import static java.util.Optional.of;
+
import static junit.framework.TestCase.*;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcPackageProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcPackageProvider.java
index b09a11b1..8d344c5b 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcPackageProvider.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcPackageProvider.java
@@ -15,6 +15,8 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.vfc;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
import org.apache.http.HttpHeaders;
import org.apache.http.client.methods.HttpGet;
import org.junit.Assert;
@@ -29,9 +31,6 @@ import org.onap.vfccatalog.model.VnfPkgDetailInfo;
import org.onap.vfccatalog.model.VnfPkgInfo;
import retrofit2.Call;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.fail;
import static org.mockito.Mockito.verify;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfPackageBuilder.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfPackageBuilder.java
index 9c9f7958..8ba697d0 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfPackageBuilder.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfPackageBuilder.java
@@ -15,13 +15,12 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer;
-import org.junit.Test;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
-
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
+import org.junit.Test;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
import static junit.framework.TestCase.assertEquals;
import static org.mockito.Mockito.when;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java
index 2cd0aa1e..a97ee4f1 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java
@@ -15,13 +15,12 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer;
+import java.util.NoSuchElementException;
import org.junit.Before;
import org.junit.Test;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
-import java.util.NoSuchElementException;
-
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.fail;
import static org.mockito.Mockito.verify;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java
index 218c478e..8f8cc8c1 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java
@@ -17,6 +17,13 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.restapi;
import com.google.common.collect.Lists;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.Arrays;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.Part;
import org.apache.http.entity.ContentType;
import org.junit.Before;
import org.junit.Test;
@@ -32,14 +39,6 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.mock.web.DelegatingServletOutputStream;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.Part;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.util.Arrays;
-
import static junit.framework.TestCase.*;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcmApi.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcmApi.java
index 6b04d69d..dbbad3f0 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcmApi.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcmApi.java
@@ -29,6 +29,7 @@ import org.onap.vnfmdriver.model.VnfScaleRequest;
import org.onap.vnfmdriver.model.VnfTerminateRequest;
import static java.util.Optional.empty;
+
import static org.apache.http.HttpStatus.SC_CREATED;
import static org.mockito.Mockito.verify;
import static org.springframework.test.util.ReflectionTestUtils.setField;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcnApi.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcnApi.java
index fc6b97b4..67842f61 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcnApi.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestLcnApi.java
@@ -57,7 +57,7 @@ public class TestLcnApi extends TestBase {
@Test
public void testHandleLcn() {
//when
- lcnApi.handleLcn(lcn, httpResponse);
+ lcnApi.handleLcn(lcn);
//verify
verify(lcnManager).handleLcn(lcn);
verify(logger).info("REST: handle LCN");
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerApi.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerApi.java
index 638f7237..f9b6f3ce 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerApi.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerApi.java
@@ -16,6 +16,7 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.restapi;
+import javax.servlet.ServletOutputStream;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
@@ -24,8 +25,6 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
-import javax.servlet.ServletOutputStream;
-
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.springframework.test.util.ReflectionTestUtils.setField;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerDefinitionConsistency.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerDefinitionConsistency.java
index 6096802a..f88305a0 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerDefinitionConsistency.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerDefinitionConsistency.java
@@ -21,17 +21,16 @@ import com.google.common.collect.Sets;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
-import junit.framework.TestCase;
-import org.junit.Test;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
+import junit.framework.TestCase;
+import org.junit.Test;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.child;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil.loadFile;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestRealConfig.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestRealConfig.java
index 6bcce07f..22a9d06c 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestRealConfig.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestRealConfig.java
@@ -17,19 +17,16 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring;
import com.nokia.cbam.lcm.v32.model.*;
-import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
-import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpInputMessage;
import org.springframework.http.MediaType;
-import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.http.converter.json.GsonHttpMessageConverter;
import org.springframework.mock.http.MockHttpInputMessage;
import org.springframework.mock.http.MockHttpOutputMessage;
+import org.threeten.bp.OffsetDateTime;
-import java.io.IOException;
-import java.io.InputStream;
-
+import static com.google.common.collect.Iterables.filter;
import static junit.framework.TestCase.assertEquals;
public class TestRealConfig {
@@ -41,22 +38,26 @@ public class TestRealConfig {
public void test() throws Exception {
HttpMessageConverters converters = new RealConfig().customConverters();
//verify
- converters.getConverters().get(0).canRead(VnfIdentifierCreationNotification.class, MediaType.APPLICATION_JSON);
- converters.getConverters().get(0).canRead(VnfIdentifierDeletionNotification.class, MediaType.APPLICATION_JSON);
- converters.getConverters().get(0).canRead(VnfInfoAttributeValueChangeNotification.class, MediaType.APPLICATION_JSON);
- converters.getConverters().get(0).canRead(VnfLifecycleChangeNotification.class, MediaType.APPLICATION_JSON);
- converters.getConverters().get(0).canRead(String.class, MediaType.APPLICATION_JSON);
+ GsonHttpMessageConverter httpMessageConverter1 = filter(converters.getConverters(), GsonHttpMessageConverter.class).iterator().next();
+ httpMessageConverter1.canRead(VnfIdentifierCreationNotification.class, MediaType.APPLICATION_JSON);
+ httpMessageConverter1.canRead(VnfIdentifierDeletionNotification.class, MediaType.APPLICATION_JSON);
+ httpMessageConverter1.canRead(VnfInfoAttributeValueChangeNotification.class, MediaType.APPLICATION_JSON);
+ httpMessageConverter1.canRead(VnfLifecycleChangeNotification.class, MediaType.APPLICATION_JSON);
+ httpMessageConverter1.canRead(String.class, MediaType.APPLICATION_JSON);
- HttpMessageConverter<VnfLifecycleChangeNotification> httpMessageConverter = (HttpMessageConverter<VnfLifecycleChangeNotification>) converters.getConverters().get(0);
MockHttpOutputMessage out = new MockHttpOutputMessage();
VnfLifecycleChangeNotification not = new VnfLifecycleChangeNotification();
not.setNotificationType(VnfNotificationType.VNFLIFECYCLECHANGENOTIFICATION);
not.setVnfInstanceId("vnfId");
- httpMessageConverter.write(not, MediaType.APPLICATION_JSON, out);
+ OffsetDateTime now = OffsetDateTime.now();
+ not.setTimestamp(now);
+ httpMessageConverter1.write(not, MediaType.APPLICATION_JSON, out);
String write = out.getBodyAsString();
HttpInputMessage x = new MockHttpInputMessage(write.getBytes());
- VnfLifecycleChangeNotification deserialized = (VnfLifecycleChangeNotification) httpMessageConverter.read(VnfLifecycleChangeNotification.class, x);
+ VnfLifecycleChangeNotification deserialized = (VnfLifecycleChangeNotification) httpMessageConverter1.read(VnfLifecycleChangeNotification.class, x);
assertEquals("vnfId", deserialized.getVnfInstanceId());
+ assertEquals(now, deserialized.getTimestamp());
+
}
}
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestSecurityConfig.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestSecurityConfig.java
index 39a8e648..d1cbbb68 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestSecurityConfig.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/spring/TestSecurityConfig.java
@@ -16,6 +16,8 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring;
+import java.util.HashMap;
+import java.util.List;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.security.config.annotation.ObjectPostProcessor;
@@ -27,9 +29,6 @@ import org.springframework.security.web.util.matcher.AnyRequestMatcher;
import org.springframework.security.web.util.matcher.RequestMatcher;
import org.springframework.test.util.ReflectionTestUtils;
-import java.util.HashMap;
-import java.util.List;
-
import static junit.framework.TestCase.assertTrue;
public class TestSecurityConfig {
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestStoreLoader.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestStoreLoader.java
index 2dc33f3b..d995fcd1 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestStoreLoader.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestStoreLoader.java
@@ -16,9 +16,6 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -31,6 +28,8 @@ import java.security.cert.CertificateException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
+import org.junit.BeforeClass;
+import org.junit.Test;
import static com.google.common.collect.Sets.newHashSet;
import static org.junit.Assert.*;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestSystemFunctions.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestSystemFunctions.java
index ec1ebd78..df97d4a4 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestSystemFunctions.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestSystemFunctions.java
@@ -16,11 +16,10 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util;
-import org.junit.Test;
-
import java.util.Base64;
import java.util.HashSet;
import java.util.Set;
+import org.junit.Test;
import static org.junit.Assert.*;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestUtil.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestUtil.java
index f5d9cc41..767505e6 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestUtil.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestUtil.java
@@ -17,7 +17,6 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util;
import com.google.common.io.ByteStreams;
-
import java.io.InputStream;
import java.lang.reflect.Constructor;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/HttpTestServer.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/HttpTestServer.java
index 4109b132..a99e8d8d 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/HttpTestServer.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/HttpTestServer.java
@@ -17,14 +17,6 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm;
import com.google.common.io.ByteStreams;
-import org.eclipse.jetty.server.NetworkTrafficServerConnector;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.handler.AbstractHandler;
-import org.eclipse.jetty.util.ssl.SslContextFactory;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -34,6 +26,13 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.eclipse.jetty.server.NetworkTrafficServerConnector;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.handler.AbstractHandler;
+import org.eclipse.jetty.util.ssl.SslContextFactory;
public class HttpTestServer {
public Server _server;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestAdditionalParams.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestAdditionalParams.java
index d1afeac4..00cb83b8 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestAdditionalParams.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestAdditionalParams.java
@@ -18,15 +18,14 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm;
import com.google.common.collect.Maps;
import com.nokia.cbam.lcm.v32.model.NetworkAddress;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
import org.junit.Test;
import pl.pojo.tester.internal.field.AbstractFieldValueChanger;
import pl.pojo.tester.internal.field.DefaultFieldValueChanger;
import pl.pojo.tester.internal.field.collections.map.AbstractMapFieldValueChanger;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
import static pl.pojo.tester.api.assertion.Assertions.assertPojoMethodsFor;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestBase.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestBase.java
index 2489d3c2..190f78ee 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestBase.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestBase.java
@@ -22,6 +22,16 @@ 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 java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.lang.reflect.Field;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import javax.servlet.http.HttpServletResponse;
import okhttp3.RequestBody;
import okio.Buffer;
import org.apache.commons.lang3.ArrayUtils;
@@ -36,11 +46,12 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
-import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
+import org.onap.msb.api.ServiceResourceApi;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.INotificationSender;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.VnfmInfoProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.MsbApiProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AaiSecurityProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.vfc.VfcRestApiProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions;
import org.onap.vfccatalog.api.VnfpackageApi;
@@ -52,17 +63,6 @@ import org.springframework.test.util.ReflectionTestUtils;
import retrofit2.Call;
import retrofit2.Response;
-import javax.servlet.http.HttpServletResponse;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.lang.reflect.Field;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertTrue;
import static org.mockito.Mockito.when;
@@ -83,6 +83,8 @@ public class TestBase {
@Mock
protected MsbApiProvider msbApiProvider;
@Mock
+ protected AaiSecurityProvider aaiSecurityProvider;
+ @Mock
protected VnfmInfoProvider vnfmInfoProvider;
@Mock
protected VnfsApi vnfApi;
@@ -95,7 +97,7 @@ public class TestBase {
@Mock
protected SubscriptionsApi lcnApi;
@Mock
- protected MSBServiceClient msbClient;
+ protected ServiceResourceApi msbClient;
@Mock
protected DriverProperties driverProperties;
@Mock
@@ -142,7 +144,7 @@ public class TestBase {
when(cbamRestApiProvider.getCbamOperationExecutionApi(VNFM_ID)).thenReturn(operationExecutionApi);
when(cbamRestApiProvider.getCbamLcnApi(VNFM_ID)).thenReturn(lcnApi);
when(cbamRestApiProvider.getCbamCatalogApi(VNFM_ID)).thenReturn(cbamCatalogApi);
- when(msbApiProvider.getMsbClient()).thenReturn(msbClient);
+ when(msbApiProvider.getMsbApi()).thenReturn(msbClient);
when(vfcRestApiProvider.getNsLcmApi()).thenReturn(nsLcmApi);
when(vfcRestApiProvider.getVfcCatalogApi()).thenReturn(vfcCatalogApi);
when(systemFunctions.getHttpClient()).thenReturn(httpClient);
@@ -194,7 +196,7 @@ public class TestBase {
return files;
}
- protected void setFieldWithPropertyAnnotation(Object obj, String key, String value) {
+ protected void setFieldWithPropertyAnnotation(Object obj, String key, Object value) {
for (Field field : obj.getClass().getDeclaredFields()) {
for (Value fieldValue : field.getAnnotationsByType(Value.class)) {
if (fieldValue.value().equals(key)) {
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamCatalogManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamCatalogManager.java
index 1425d97c..90e064a2 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamCatalogManager.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamCatalogManager.java
@@ -16,6 +16,11 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm;
import com.nokia.cbam.catalog.v1.model.CatalogAdapterVnfpackage;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import okhttp3.Headers;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
@@ -33,12 +38,6 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.IPackageProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil;
import retrofit2.Call;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
import static junit.framework.TestCase.*;
import static org.junit.Assert.assertArrayEquals;
import static org.mockito.Mockito.*;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamRestApiProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamRestApiProvider.java
index cb541278..e21e638a 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamRestApiProvider.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamRestApiProvider.java
@@ -21,27 +21,24 @@ import com.nokia.cbam.lcm.v32.ApiClient;
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 java.util.ArrayList;
+import java.util.Map;
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.SSLSocketFactory;
import okhttp3.Interceptor;
-import okhttp3.OakExtractor;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
-import org.onap.msb.sdk.discovery.entity.MicroServiceFullInfo;
-import org.onap.msb.sdk.discovery.entity.NodeInfo;
+import org.onap.msb.model.MicroServiceFullInfo;
+import org.onap.msb.model.NodeInfo;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.GenericExternalSystemInfoProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.IpMappingProvider;
import org.onap.vnfmdriver.model.VnfmInfo;
import org.springframework.core.env.Environment;
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.SSLSocketFactory;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;
import static org.mockito.Mockito.*;
@@ -72,7 +69,7 @@ public class TestCbamRestApiProvider extends TestBase {
private Interceptor interceptor;
@Mock
private HostnameVerifier hostnameVerifier;
- private Set<NodeInfo> nodes = new HashSet<>();
+ private java.util.List<NodeInfo> nodes = new ArrayList<>();
private CbamRestApiProvider cbamRestApiProvider;
private CbamSecurityProvider cbamSecurityProvider = spy(new CbamSecurityProvider());
@@ -102,13 +99,12 @@ public class TestCbamRestApiProvider extends TestBase {
//when
ApiClient cbamLcmApi = cbamRestApiProvider.buildLcmApiClient(VNFM_ID);
//verify
- String actual = cbamLcmApi.getAdapterBuilder().build().baseUrl().toString();
- assertEquals("https://cbamurl:123/d/", actual);
+ assertEquals("https://cbamurl:123/d/", cbamLcmApi.getAdapterBuilder().build().baseUrl().toString());
assertEquals(sslSocketFactoryResultCaptor.getResult(), cbamLcmApi.getOkBuilder().build().sslSocketFactory());
Map<String, Interceptor> apiAuthorizations = cbamLcmApi.getApiAuthorizations();
assertEquals(1, apiAuthorizations.size());
assertEquals(interceptor, apiAuthorizations.values().iterator().next());
- assertEquals(hostnameVerifier, OakExtractor.extract(cbamLcmApi.getOkBuilder()));
+ assertEquals(hostnameVerifier, cbamLcmApi.getOkBuilder().build().hostnameVerifier());
}
/**
@@ -130,7 +126,7 @@ public class TestCbamRestApiProvider extends TestBase {
Map<String, Interceptor> apiAuthorizations = cbamLcmApi.getApiAuthorizations();
assertEquals(1, apiAuthorizations.size());
assertEquals(interceptor, apiAuthorizations.values().iterator().next());
- assertEquals(hostnameVerifier, OakExtractor.extract(cbamLcmApi.getOkBuilder()));
+ assertEquals(hostnameVerifier, cbamLcmApi.getOkBuilder().build().hostnameVerifier());
}
/**
@@ -152,7 +148,7 @@ public class TestCbamRestApiProvider extends TestBase {
Map<String, Interceptor> apiAuthorizations = cbamLcmApi.getApiAuthorizations();
assertEquals(1, apiAuthorizations.size());
assertEquals(interceptor, apiAuthorizations.values().iterator().next());
- assertEquals(hostnameVerifier, OakExtractor.extract(cbamLcmApi.getOkBuilder()));
+ assertEquals(hostnameVerifier, cbamLcmApi.getOkBuilder().build().hostnameVerifier());
}
/**
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamSecurityProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamSecurityProvider.java
index 17c68e41..55d949e3 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamSecurityProvider.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamSecurityProvider.java
@@ -16,312 +16,26 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm;
-import com.google.gson.Gson;
-import com.google.gson.JsonParseException;
-import com.google.gson.annotations.SerializedName;
-import com.nokia.cbam.lcn.v32.JSON;
-import io.reactivex.Observable;
-import okhttp3.OkHttpClient;
-import okhttp3.RequestBody;
-import okhttp3.ResponseBody;
-import org.junit.After;
-import org.junit.Before;
import org.junit.Test;
-import retrofit2.Converter;
-import retrofit2.Retrofit;
-import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
-import retrofit2.converter.gson.GsonConverterFactory;
-import retrofit2.http.GET;
-import retrofit2.http.Headers;
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-import java.io.IOException;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Base64;
+import static junit.framework.TestCase.assertEquals;
-import static junit.framework.TestCase.*;
-import static org.springframework.test.util.ReflectionTestUtils.setField;
-
-interface TestService {
- @Headers({
- "Content-Type:application/json"
- })
- @GET("subscriptions")
- Observable<TestResource> subscriptionsGet();
-}
-
-@XmlRootElement(name = "Subscription")
-@XmlAccessorType(XmlAccessType.FIELD)
-class TestResource {
- @XmlElement(name = "id")
- @SerializedName("id")
- public String id = null;
-}
-
-class GsonCustomConverterFactory extends Converter.Factory {
- private final Gson gson;
- private final GsonConverterFactory gsonConverterFactory;
-
- private GsonCustomConverterFactory(Gson gson) {
- if (gson == null)
- throw new NullPointerException("gson == null");
- this.gson = gson;
- this.gsonConverterFactory = GsonConverterFactory.create(gson);
- }
-
- public static GsonCustomConverterFactory create(Gson gson) {
- return new GsonCustomConverterFactory(gson);
- }
-
- @Override
- public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
- if (type.equals(String.class))
- return new GsonResponseBodyConverterToString<Object>(gson, type);
- else
- return gsonConverterFactory.responseBodyConverter(type, annotations, retrofit);
- }
-
- @Override
- public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
- return gsonConverterFactory.requestBodyConverter(type, parameterAnnotations, methodAnnotations, retrofit);
- }
-}
-
-class GsonResponseBodyConverterToString<T> implements Converter<ResponseBody, T> {
- private final Gson gson;
- private final Type type;
-
- GsonResponseBodyConverterToString(Gson gson, Type type) {
- this.gson = gson;
- this.type = type;
- }
-
- @Override
- public T convert(ResponseBody value) throws IOException {
- String returned = value.string();
- try {
- return gson.fromJson(returned, type);
- } catch (JsonParseException e) {
- return (T) returned;
- }
- }
-}
public class TestCbamSecurityProvider extends TestBase {
- CbamSecurityProvider securityProvider = new CbamSecurityProvider() {
- };
-
- HttpTestServer testServer = new HttpTestServer();
- String url;
-
- @Before
- public void init() throws Exception {
- setField(securityProvider, "skipCertificateVerification", true);
- setField(securityProvider, "skipHostnameVerification", true);
- testServer = new HttpTestServer();
- testServer.start();
- url = testServer._server.getURI().toString();
- }
-
- @After
- public void testServer() throws Exception {
- testServer.stop();
- }
-
- /**
- * test skipping certificate and skipping hostname verification
- */
- @Test
- public void testSkipHostAndSkipCertifiacateVerification() throws Exception {
- setField(securityProvider, "skipCertificateVerification", true);
- setField(securityProvider, "skipHostnameVerification", true);
- //when
- TestResource testResource = fireRequest();
- //verify
- assertEquals("1234", testResource.id);
- //when
- securityProvider.buildTrustManager().checkClientTrusted(null, null);
- //verify
- //no security exception is thrown
- }
-
- /**
- * test skipping certificate and doing hostname verification
- */
- @Test
- public void testHostAndSkipCertifiacateVerification() throws Exception {
- setField(securityProvider, "skipCertificateVerification", true);
- setField(securityProvider, "skipHostnameVerification", false);
- url = url.replace("127.0.0.1", "localhost");
- TestResource testResource = fireRequest();
- assertEquals("1234", testResource.id);
- }
-
- /**
- * test skipping certificate and doing hostname verification
- * (if hostname is invalid exception is propagated)
- */
- @Test
- public void testHostAndSkipCertifiacateVerificationNegativeCase() throws Exception {
- setField(securityProvider, "skipCertificateVerification", true);
- setField(securityProvider, "skipHostnameVerification", false);
- //url = url.replace("127.0.0.1", "localhost");
- try {
- fireRequest();
- fail();
- } catch (Exception e) {
- assertEquals(javax.net.ssl.SSLPeerUnverifiedException.class, e.getCause().getClass());
- assertTrue(e.getCause().getMessage().contains("Hostname 127.0.0.1 not verified"));
- }
- }
-
- /**
- * test certificate and hostname verification
- */
- @Test
- public void testHostAndCertifiacateVerification() throws Exception {
- Path jksPath = Paths.get(TestCbamTokenProvider.class.getResource("/unittests/localhost.cert.pem").toURI());
- String cert = Base64.getEncoder().encodeToString(Files.readAllBytes(jksPath));
- setField(securityProvider, "trustedCertificates", cert);
- setField(securityProvider, "skipCertificateVerification", false);
- setField(securityProvider, "skipHostnameVerification", false);
- url = url.replace("127.0.0.1", "localhost");
- TestResource testResource = fireRequest();
- assertEquals("1234", testResource.id);
- }
-
- /**
- * test certificate and hostname verification
- * (not trusted certificate)
- */
- @Test
- public void testHostAndCertifiacateVerificationNegative() throws Exception {
- Path jksPath = Paths.get(TestCbamTokenProvider.class.getResource("/unittests/sample.cert.pem").toURI());
- String cert = Base64.getEncoder().encodeToString(Files.readAllBytes(jksPath));
- setField(securityProvider, "trustedCertificates", cert);
- setField(securityProvider, "skipCertificateVerification", false);
- setField(securityProvider, "skipHostnameVerification", false);
- url = url.replace("127.0.0.1", "localhost");
- try {
- fireRequest();
- fail();
- } catch (Exception e) {
- assertEquals(javax.net.ssl.SSLHandshakeException.class, e.getCause().getClass());
- assertTrue(e.getCause().getMessage().contains("unable to find valid certification path to requested target"));
- }
- }
-
- /**
- * test certificate and hostname verification
- */
- @Test
- public void testSkipHostAndCertifiacateVerification() throws Exception {
- Path jksPath = Paths.get(TestCbamTokenProvider.class.getResource("/unittests/localhost.cert.pem").toURI());
- String cert = Base64.getEncoder().encodeToString(Files.readAllBytes(jksPath));
- setField(securityProvider, "trustedCertificates", cert);
- setField(securityProvider, "skipCertificateVerification", false);
- setField(securityProvider, "skipHostnameVerification", true);
- //url = url.replace("127.0.0.1", "localhost");
- TestResource testResource = fireRequest();
- assertEquals("1234", testResource.id);
- }
+ private CbamSecurityProvider securityProvider = new CbamSecurityProvider();
/**
- * empty trusted pem results in error if verification is required
+ * test property handling
*/
@Test
- public void testEmptyTrustStoreWhenCheckingIsRequired() throws Exception {
- setField(securityProvider, "trustedCertificates", "");
- setField(securityProvider, "skipCertificateVerification", false);
- try {
- securityProvider.buildTrustManager();
- fail();
- } catch (Exception e) {
- assertEquals("If the skipCertificateVerification is set to false (default) the trustedCertificates can not be empty", e.getMessage());
- }
- }
-
- /**
- * invalid PEM results in fast fail error
- */
- @Test
- public void testInvalidPem() throws Exception {
- setField(securityProvider, "trustedCertificates", "______");
- setField(securityProvider, "skipCertificateVerification", false);
- try {
- securityProvider.buildTrustManager();
- fail();
- } catch (Exception e) {
- assertEquals("The trustedCertificates must be a base64 encoded collection of PEM certificates", e.getMessage());
- }
- }
-
- /**
- * invalid PEM results in fast fail error
- */
- @Test
- public void testEmptyInvalidPem() throws Exception {
- setField(securityProvider, "trustedCertificates", "a3VrdQo=");
- setField(securityProvider, "skipCertificateVerification", false);
- try {
- securityProvider.buildTrustManager();
- fail();
- } catch (Exception e) {
- assertEquals("No certificate can be extracted from kuku\n", e.getMessage());
- }
- }
-
- /**
- * bad certificate content results in fast fail error
- */
- @Test
- public void testEmptyInvalidPemContent() throws Exception {
- String badCert = "-----BEGIN CERTIFICATE-----\nXXXXXX\n-----END CERTIFICATE-----";
- setField(securityProvider, "trustedCertificates", Base64.getEncoder().encodeToString(badCert.getBytes()));
- setField(securityProvider, "skipCertificateVerification", false);
- try {
- securityProvider.buildTrustManager();
- fail();
- } catch (Exception e) {
- assertEquals("Unable to create keystore", e.getMessage());
- }
- }
-
- /**
- * bad certificate content results in fast fail error for SSL socket factory
- */
- @Test
- public void testEmptyInvalidPemContentSSl() throws Exception {
- String badCert = "-----BEGIN CERTIFICATE-----\nXXXXXX\n-----END CERTIFICATE-----";
- setField(securityProvider, "trustedCertificates", Base64.getEncoder().encodeToString(badCert.getBytes()));
- setField(securityProvider, "skipCertificateVerification", false);
- try {
- securityProvider.buildSSLSocketFactory();
- fail();
- } catch (Exception e) {
- assertEquals("Unable to create SSL socket factory", e.getMessage());
- }
- }
+ public void init() throws Exception {
+ setFieldWithPropertyAnnotation(securityProvider, "${skipCertificateVerification}", true);
+ setFieldWithPropertyAnnotation(securityProvider, "${skipHostnameVerification}", true);
+ setFieldWithPropertyAnnotation(securityProvider, "${trustedCertificates}", "cert");
- private TestResource fireRequest() {
- OkHttpClient client =
- new OkHttpClient.Builder()
- .sslSocketFactory(securityProvider.buildSSLSocketFactory(), securityProvider.buildTrustManager())
- .hostnameVerifier(securityProvider.buildHostnameVerifier()).build();
- TestService test1 = new Retrofit.Builder().baseUrl(url).client(client)
- .addConverterFactory(GsonCustomConverterFactory.create(new JSON().getGson()))
- .addCallAdapterFactory(RxJava2CallAdapterFactory.create()).build().create(TestService.class);
- testServer.respones.add("{ \"id\" : \"1234\" } ");
- testServer.codes.add(200);
- TestService test = test1;
- return test.subscriptionsGet().blockingFirst();
+ assertEquals(true, securityProvider.skipCertificateVerification());
+ assertEquals(true, securityProvider.skipHostnameVerification());
+ assertEquals("cert", securityProvider.trustedCertificates());
}
}
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamTokenProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamTokenProvider.java
index 699a5900..7c1b1179 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamTokenProvider.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamTokenProvider.java
@@ -16,6 +16,8 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm;
+import java.io.IOException;
+import java.net.URI;
import okhttp3.Interceptor;
import okhttp3.Request;
import org.junit.After;
@@ -27,9 +29,6 @@ import org.mockito.Mockito;
import org.onap.vnfmdriver.model.VnfmInfo;
import org.springframework.http.HttpStatus;
-import java.io.IOException;
-import java.net.URI;
-
import static junit.framework.TestCase.*;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestGenericSecurityProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestGenericSecurityProvider.java
new file mode 100644
index 00000000..8823b2e0
--- /dev/null
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestGenericSecurityProvider.java
@@ -0,0 +1,326 @@
+/*
+ * Copyright 2016-2017, Nokia Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonParseException;
+import com.google.gson.annotations.SerializedName;
+import com.nokia.cbam.lcn.v32.JSON;
+import io.reactivex.Observable;
+import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Base64;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import okhttp3.OkHttpClient;
+import okhttp3.RequestBody;
+import okhttp3.ResponseBody;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import retrofit2.Converter;
+import retrofit2.Retrofit;
+import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
+import retrofit2.converter.gson.GsonConverterFactory;
+import retrofit2.http.GET;
+import retrofit2.http.Headers;
+
+import static junit.framework.TestCase.*;
+import static org.springframework.test.util.ReflectionTestUtils.setField;
+
+interface TestService {
+ @Headers({
+ "Content-Type:application/json"
+ })
+ @GET("subscriptions")
+ Observable<TestResource> subscriptionsGet();
+}
+
+@XmlRootElement(name = "Subscription")
+@XmlAccessorType(XmlAccessType.FIELD)
+class TestResource {
+ @XmlElement(name = "id")
+ @SerializedName("id")
+ public String id = null;
+}
+
+class GsonCustomConverterFactory extends Converter.Factory {
+ private final Gson gson;
+ private final GsonConverterFactory gsonConverterFactory;
+
+ private GsonCustomConverterFactory(Gson gson) {
+ if (gson == null)
+ throw new NullPointerException("gson == null");
+ this.gson = gson;
+ this.gsonConverterFactory = GsonConverterFactory.create(gson);
+ }
+
+ public static GsonCustomConverterFactory create(Gson gson) {
+ return new GsonCustomConverterFactory(gson);
+ }
+
+ @Override
+ public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
+ if (type.equals(String.class))
+ return new GsonResponseBodyConverterToString<Object>(gson, type);
+ else
+ return gsonConverterFactory.responseBodyConverter(type, annotations, retrofit);
+ }
+
+ @Override
+ public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
+ return gsonConverterFactory.requestBodyConverter(type, parameterAnnotations, methodAnnotations, retrofit);
+ }
+}
+
+class GsonResponseBodyConverterToString<T> implements Converter<ResponseBody, T> {
+ private final Gson gson;
+ private final Type type;
+
+ GsonResponseBodyConverterToString(Gson gson, Type type) {
+ this.gson = gson;
+ this.type = type;
+ }
+
+ @Override
+ public T convert(ResponseBody value) throws IOException {
+ String returned = value.string();
+ try {
+ return gson.fromJson(returned, type);
+ } catch (JsonParseException e) {
+ return (T) returned;
+ }
+ }
+}
+
+public class TestGenericSecurityProvider extends TestBase {
+ GenericSecurityProvider securityProvider = new CbamSecurityProvider() {
+ };
+
+ HttpTestServer testServer = new HttpTestServer();
+ String url;
+
+ @Before
+ public void init() throws Exception {
+ setField(securityProvider, "skipCertificateVerification", true);
+ setField(securityProvider, "skipHostnameVerification", true);
+ testServer = new HttpTestServer();
+ testServer.start();
+ url = testServer._server.getURI().toString();
+ }
+
+ @After
+ public void testServer() throws Exception {
+ testServer.stop();
+ }
+
+ /**
+ * test skipping certificate and skipping hostname verification
+ */
+ @Test
+ public void testSkipHostAndSkipCertifiacateVerification() throws Exception {
+ setField(securityProvider, "skipCertificateVerification", true);
+ setField(securityProvider, "skipHostnameVerification", true);
+ //when
+ TestResource testResource = fireRequest();
+ //verify
+ assertEquals("1234", testResource.id);
+ //when
+ securityProvider.buildTrustManager().checkClientTrusted(null, null);
+ //verify
+ //no security exception is thrown
+ }
+
+ /**
+ * test skipping certificate and doing hostname verification
+ */
+ @Test
+ public void testHostAndSkipCertifiacateVerification() throws Exception {
+ setField(securityProvider, "skipCertificateVerification", true);
+ setField(securityProvider, "skipHostnameVerification", false);
+ url = url.replace("127.0.0.1", "localhost");
+ TestResource testResource = fireRequest();
+ assertEquals("1234", testResource.id);
+ }
+
+ /**
+ * test skipping certificate and doing hostname verification
+ * (if hostname is invalid exception is propagated)
+ */
+ @Test
+ public void testHostAndSkipCertifiacateVerificationNegativeCase() throws Exception {
+ setField(securityProvider, "skipCertificateVerification", true);
+ setField(securityProvider, "skipHostnameVerification", false);
+ //url = url.replace("127.0.0.1", "localhost");
+ try {
+ fireRequest();
+ fail();
+ } catch (Exception e) {
+ assertEquals(javax.net.ssl.SSLPeerUnverifiedException.class, e.getCause().getClass());
+ assertTrue(e.getCause().getMessage().contains("Hostname 127.0.0.1 not verified"));
+ }
+ }
+
+ /**
+ * test certificate and hostname verification
+ */
+ @Test
+ public void testHostAndCertifiacateVerification() throws Exception {
+ Path jksPath = Paths.get(TestCbamTokenProvider.class.getResource("/unittests/localhost.cert.pem").toURI());
+ String cert = Base64.getEncoder().encodeToString(Files.readAllBytes(jksPath));
+ setField(securityProvider, "trustedCertificates", cert);
+ setField(securityProvider, "skipCertificateVerification", false);
+ setField(securityProvider, "skipHostnameVerification", false);
+ url = url.replace("127.0.0.1", "localhost");
+ TestResource testResource = fireRequest();
+ assertEquals("1234", testResource.id);
+ }
+
+ /**
+ * test certificate and hostname verification
+ * (not trusted certificate)
+ */
+ @Test
+ public void testHostAndCertifiacateVerificationNegative() throws Exception {
+ Path jksPath = Paths.get(TestCbamTokenProvider.class.getResource("/unittests/sample.cert.pem").toURI());
+ String cert = Base64.getEncoder().encodeToString(Files.readAllBytes(jksPath));
+ setField(securityProvider, "trustedCertificates", cert);
+ setField(securityProvider, "skipCertificateVerification", false);
+ setField(securityProvider, "skipHostnameVerification", false);
+ url = url.replace("127.0.0.1", "localhost");
+ try {
+ fireRequest();
+ fail();
+ } catch (Exception e) {
+ assertEquals(javax.net.ssl.SSLHandshakeException.class, e.getCause().getClass());
+ assertTrue(e.getCause().getMessage().contains("unable to find valid certification path to requested target"));
+ }
+ }
+
+ /**
+ * test certificate and hostname verification
+ */
+ @Test
+ public void testSkipHostAndCertifiacateVerification() throws Exception {
+ Path jksPath = Paths.get(TestCbamTokenProvider.class.getResource("/unittests/localhost.cert.pem").toURI());
+ String cert = Base64.getEncoder().encodeToString(Files.readAllBytes(jksPath));
+ setField(securityProvider, "trustedCertificates", cert);
+ setField(securityProvider, "skipCertificateVerification", false);
+ setField(securityProvider, "skipHostnameVerification", true);
+ //url = url.replace("127.0.0.1", "localhost");
+ TestResource testResource = fireRequest();
+ assertEquals("1234", testResource.id);
+ }
+
+ /**
+ * empty trusted pem results in error if verification is required
+ */
+ @Test
+ public void testEmptyTrustStoreWhenCheckingIsRequired() throws Exception {
+ setField(securityProvider, "trustedCertificates", "");
+ setField(securityProvider, "skipCertificateVerification", false);
+ try {
+ securityProvider.buildTrustManager();
+ fail();
+ } catch (Exception e) {
+ assertEquals("If the skipCertificateVerification is set to false (default) the trustedCertificates can not be empty", e.getMessage());
+ }
+ }
+
+ /**
+ * invalid PEM results in fast fail error
+ */
+ @Test
+ public void testInvalidPem() throws Exception {
+ setField(securityProvider, "trustedCertificates", "______");
+ setField(securityProvider, "skipCertificateVerification", false);
+ try {
+ securityProvider.buildTrustManager();
+ fail();
+ } catch (Exception e) {
+ assertEquals("The trustedCertificates must be a base64 encoded collection of PEM certificates", e.getMessage());
+ }
+ }
+
+ /**
+ * invalid PEM results in fast fail error
+ */
+ @Test
+ public void testEmptyInvalidPem() throws Exception {
+ setField(securityProvider, "trustedCertificates", "a3VrdQo=");
+ setField(securityProvider, "skipCertificateVerification", false);
+ try {
+ securityProvider.buildTrustManager();
+ fail();
+ } catch (Exception e) {
+ assertEquals("No certificate can be extracted from kuku\n", e.getMessage());
+ }
+ }
+
+ /**
+ * bad certificate content results in fast fail error
+ */
+ @Test
+ public void testEmptyInvalidPemContent() throws Exception {
+ String badCert = "-----BEGIN CERTIFICATE-----\nXXXXXX\n-----END CERTIFICATE-----";
+ setField(securityProvider, "trustedCertificates", Base64.getEncoder().encodeToString(badCert.getBytes()));
+ setField(securityProvider, "skipCertificateVerification", false);
+ try {
+ securityProvider.buildTrustManager();
+ fail();
+ } catch (Exception e) {
+ assertEquals("Unable to create keystore", e.getMessage());
+ }
+ }
+
+ /**
+ * bad certificate content results in fast fail error for SSL socket factory
+ */
+ @Test
+ public void testEmptyInvalidPemContentSSl() throws Exception {
+ String badCert = "-----BEGIN CERTIFICATE-----\nXXXXXX\n-----END CERTIFICATE-----";
+ setField(securityProvider, "trustedCertificates", Base64.getEncoder().encodeToString(badCert.getBytes()));
+ setField(securityProvider, "skipCertificateVerification", false);
+ try {
+ securityProvider.buildSSLSocketFactory();
+ fail();
+ } catch (Exception e) {
+ assertEquals("Unable to create SSL socket factory", e.getMessage());
+ }
+ }
+
+ private TestResource fireRequest() {
+ OkHttpClient client =
+ new OkHttpClient.Builder()
+ .sslSocketFactory(securityProvider.buildSSLSocketFactory(), securityProvider.buildTrustManager())
+ .hostnameVerifier(securityProvider.buildHostnameVerifier()).build();
+ TestService test1 = new Retrofit.Builder().baseUrl(url).client(client)
+ .addConverterFactory(GsonCustomConverterFactory.create(new JSON().getGson()))
+ .addCallAdapterFactory(RxJava2CallAdapterFactory.create()).build().create(TestService.class);
+ testServer.respones.add("{ \"id\" : \"1234\" } ");
+ testServer.codes.add(200);
+ TestService test = test1;
+ return test.subscriptionsGet().blockingFirst();
+ }
+
+}
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestJobManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestJobManager.java
index bed25400..743fb95e 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestJobManager.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestJobManager.java
@@ -20,6 +20,14 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.nokia.cbam.lcm.v32.model.*;
import io.reactivex.Observable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.UUID;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import javax.servlet.http.HttpServletResponse;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -34,15 +42,6 @@ import org.onap.vnfmdriver.model.JobStatus;
import org.springframework.test.util.ReflectionTestUtils;
import org.threeten.bp.OffsetDateTime;
-import javax.servlet.http.HttpServletResponse;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.UUID;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-
import static junit.framework.TestCase.*;
import static org.mockito.Mockito.*;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.SEPARATOR;
@@ -425,7 +424,7 @@ public class TestJobManager extends TestBase {
fail();
} catch (RuntimeException e) {
assertEquals(expectedException, e.getCause());
- verify(logger).error("Unable to retrieve operation parameters of operation with " + operation.getId() +" identifier", expectedException);
+ verify(logger).error("Unable to retrieve operation parameters of operation with " + operation.getId() + " identifier", expectedException);
}
assertTrue(jobManager.hasOngoingJobs());
}
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManager.java
index 9095eea3..b7e30e2c 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManager.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManager.java
@@ -25,6 +25,9 @@ import com.nokia.cbam.lcm.v32.model.OperationType;
import com.nokia.cbam.lcm.v32.model.VimInfo;
import com.nokia.cbam.lcm.v32.model.VnfInfo;
import io.reactivex.Observable;
+import java.nio.file.Paths;
+import java.util.*;
+import javax.servlet.http.HttpServletResponse;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -43,13 +46,10 @@ import org.onap.vnfmdriver.model.*;
import org.onap.vnfmdriver.model.ScaleDirection;
import org.threeten.bp.OffsetDateTime;
-import javax.servlet.http.HttpServletResponse;
-import java.nio.file.Paths;
-import java.util.*;
-
import static java.lang.Boolean.parseBoolean;
import static java.nio.file.Files.readAllBytes;
import static java.util.Optional.empty;
+
import static junit.framework.TestCase.*;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;
@@ -746,6 +746,8 @@ 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);
JsonElement instantiationParameters = new JsonParser().parse("{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] } ");
when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet("operationExecutionId", NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(instantiationParameters));
//when
@@ -754,10 +756,12 @@ public class TestLifecycleManager extends TestBase {
waitForJobToFinishInJobManager(finished);
assertEquals(1, actualTerminationRequest.getAllValues().size());
assertEquals(TerminationType.FORCEFUL, actualTerminationRequest.getValue().getTerminationType());
+ assertEquals(JOB_ID, new Gson().toJsonTree(actualTerminationRequest.getValue().getAdditionalParams()).getAsJsonObject().get("jobId").getAsString());
InOrder notificationIsProcessedBeforeDeletingTheVnf = Mockito.inOrder(vfcGrantManager, notificationManager, vnfApi);
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);
verify(jobManager).spawnJob(VNF_ID, restResponse);
verify(logger).info(eq("Starting {} operation on VNF with {} identifier with {} parameter"), eq("termination"), eq(VNF_ID), anyString());
}
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestSelfRegistrationManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestSelfRegistrationManager.java
index ffbda145..d668262f 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestSelfRegistrationManager.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestSelfRegistrationManager.java
@@ -20,35 +20,34 @@ import com.nokia.cbam.lcn.v32.model.CreateSubscriptionRequest;
import com.nokia.cbam.lcn.v32.model.Subscription;
import com.nokia.cbam.lcn.v32.model.SubscriptionAuthentication;
import com.nokia.cbam.lcn.v32.model.VnfNotificationType;
+import io.reactivex.Observable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.UUID;
import org.junit.Before;
import org.junit.Test;
import org.mockito.*;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
-import org.onap.msb.sdk.discovery.common.RouteException;
-import org.onap.msb.sdk.discovery.entity.MicroServiceFullInfo;
-import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;
-import org.onap.msb.sdk.discovery.entity.Node;
-import org.onap.msb.sdk.discovery.entity.RouteResult;
+import org.onap.msb.model.MicroServiceFullInfo;
+import org.onap.msb.model.MicroServiceInfo;
+import org.onap.msb.model.Node;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.UUID;
-
import static com.nokia.cbam.lcn.v32.model.OperationType.*;
import static junit.framework.TestCase.*;
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.vnfm.CbamRestApiProvider.NOKIA_LCN_API_VERSION;
import static org.springframework.test.util.ReflectionTestUtils.setField;
public class TestSelfRegistrationManager extends TestBase {
@Mock
private JobManager jobManager;
- private List<Subscription> subscriptions = new ArrayList<>();
+ private java.util.List<Subscription> subscriptions = new ArrayList<>();
private ArgumentCaptor<MicroServiceInfo> registeredMicroservice = ArgumentCaptor.forClass(MicroServiceInfo.class);
private ArgumentCaptor<CreateSubscriptionRequest> subscriptionToCreate = ArgumentCaptor.forClass(CreateSubscriptionRequest.class);
@InjectMocks
@@ -79,13 +78,13 @@ public class TestSelfRegistrationManager extends TestBase {
Subscription subscription = new Subscription();
when(lcnApi.subscriptionsPost(subscriptionToCreate.capture(), Mockito.eq(NOKIA_LCN_API_VERSION))).thenReturn(buildObservable(subscription));
MicroServiceFullInfo returnedMicroService = new MicroServiceFullInfo();
- when(msbClient.registerMicroServiceInfo(registeredMicroservice.capture())).thenReturn(returnedMicroService);
+ when(msbClient.addMicroService(registeredMicroservice.capture(), eq(true), eq(false))).thenReturn(buildObservable(returnedMicroService));
//when
selfRegistrationManager.register();
//verify
InOrder registrationOrder = Mockito.inOrder(lcnApi, msbClient);
registrationOrder.verify(lcnApi).subscriptionsPost(any(), any());
- registrationOrder.verify(msbClient).registerMicroServiceInfo(any());
+ registrationOrder.verify(msbClient).addMicroService(any(), any(), any());
assertMicroserviceRegistered();
assertNewLcnSubscription();
@@ -111,6 +110,7 @@ public class TestSelfRegistrationManager extends TestBase {
assertTrue(subscriptionCreation.getFilter().getOperationTypes().contains(TERMINATE));
assertTrue(subscriptionCreation.getFilter().getOperationTypes().contains(INSTANTIATE));
assertEquals(4, subscriptionCreation.getFilter().getOperationTypes().size());
+ verify(logger).info("Subscribing to CBAM LCN {} with callback to {}", driverProperties.getCbamLcnUrl(), "http://5.6.7.8:12345/api/NokiaSVNFM/v1/lcn");
}
private void assertMicroserviceRegistered() {
@@ -120,16 +120,15 @@ public class TestSelfRegistrationManager extends TestBase {
assertEquals("0", node.getTtl());
assertEquals("1.2.3.4", node.getIp());
assertEquals("12345", node.getPort());
- assertEquals("REST", microserviceRequest.getProtocol());
+ assertEquals(REST, microserviceRequest.getProtocol());
assertNull(microserviceRequest.getMetadata());
//very strange, but it should be null for ONAP to work
- assertEquals("", microserviceRequest.getPath());
assertEquals(SelfRegistrationManager.SERVICE_NAME, microserviceRequest.getServiceName());
assertEquals("/api/NokiaSVNFM/v1", microserviceRequest.getUrl());
assertEquals("v1", microserviceRequest.getVersion());
- assertEquals(false, microserviceRequest.isEnable_ssl());
+ assertEquals(Boolean.FALSE, microserviceRequest.isEnableSsl());
//1 means internal service to ONAP
- assertEquals("1", microserviceRequest.getVisualRange());
+ assertEquals(_1, microserviceRequest.getVisualRange());
}
/**
@@ -139,7 +138,7 @@ public class TestSelfRegistrationManager extends TestBase {
public void testResubscription() throws Exception {
//given
MicroServiceFullInfo returnedMicroService = new MicroServiceFullInfo();
- when(msbClient.registerMicroServiceInfo(registeredMicroservice.capture())).thenReturn(returnedMicroService);
+ when(msbClient.addMicroService(registeredMicroservice.capture(), eq(true), eq(false))).thenReturn(buildObservable(returnedMicroService));
Subscription existingSubscription = new Subscription();
existingSubscription.setId(UUID.randomUUID().toString());
existingSubscription.setCallbackUrl("http://5.6.7.8:12345/api/NokiaSVNFM/v1/lcn");
@@ -168,7 +167,7 @@ public class TestSelfRegistrationManager extends TestBase {
assertEquals(expectedException, e.getCause());
}
//verify
- verify(msbClient, never()).registerMicroServiceInfo(any());
+ verify(msbClient, never()).addMicroService(any(), any(), any());
verify(logger).error("Unable to subscribe to CBAM LCN", expectedException);
assertServiceDown();
}
@@ -187,8 +186,8 @@ public class TestSelfRegistrationManager extends TestBase {
return buildObservable(subscription);
});
MicroServiceFullInfo returnedMicroService = new MicroServiceFullInfo();
- RouteException expectedException = new RouteException();
- when(msbClient.registerMicroServiceInfo(registeredMicroservice.capture())).thenThrow(expectedException);
+ RuntimeException expectedException = new RuntimeException();
+ when(msbClient.addMicroService(registeredMicroservice.capture(), eq(true), eq(false))).thenThrow(expectedException);
//when
try {
selfRegistrationManager.register();
@@ -216,14 +215,17 @@ public class TestSelfRegistrationManager extends TestBase {
subscription.setId(UUID.randomUUID().toString());
subscriptions.add(subscription);
when(jobManager.hasOngoingJobs()).thenReturn(false);
- MicroServiceFullInfo returnedMicroService = new MicroServiceFullInfo();
+ Observable delete = Mockito.mock(Observable.class);
+ when(lcnApi.subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION)).thenReturn(delete);
//when
selfRegistrationManager.deRegister();
//verify
InOrder inOrder = Mockito.inOrder(jobManager, msbClient, lcnApi);
- inOrder.verify(msbClient).cancelMicroServiceInfo(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION);
+ inOrder.verify(msbClient).deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null);
inOrder.verify(lcnApi).subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION);
assertServiceDown();
+ verify(systemFunctions).blockingFirst(delete);
+ verify(logger).info("Deleting subscription with {} identifier", subscription.getId());
}
/**
@@ -238,11 +240,11 @@ public class TestSelfRegistrationManager extends TestBase {
subscription.setId(UUID.randomUUID().toString());
subscriptions.add(subscription);
when(jobManager.hasOngoingJobs()).thenReturn(false);
- when(msbClient.cancelMicroServiceInfo(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION)).then(new Answer<RouteResult>() {
+ when(msbClient.deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null)).then(new Answer<Observable<Void>>() {
@Override
- public RouteResult answer(InvocationOnMock invocationOnMock) throws Throwable {
- when(msbClient.queryMicroServiceInfo(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION)).thenThrow(new RouteException());
- throw new RouteException();
+ 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());
+ throw new RuntimeException();
}
});
MicroServiceFullInfo returnedMicroService = new MicroServiceFullInfo();
@@ -250,8 +252,8 @@ public class TestSelfRegistrationManager extends TestBase {
selfRegistrationManager.deRegister();
//verify
InOrder inOrder = Mockito.inOrder(jobManager, msbClient, lcnApi);
- inOrder.verify(msbClient).cancelMicroServiceInfo(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION);
- inOrder.verify(msbClient).queryMicroServiceInfo(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION);
+ 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(lcnApi).subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION);
assertServiceDown();
}
@@ -266,13 +268,12 @@ 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.cancelMicroServiceInfo(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION)).then(new Answer<RouteResult>() {
+ when(msbClient.deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null)).then(new Answer<Observable<Void>>() {
@Override
- public RouteResult answer(InvocationOnMock invocationOnMock) throws Throwable {
- throw new RouteException();
+ public Observable<Void> answer(InvocationOnMock invocationOnMock) throws Throwable {
+ throw new RuntimeException();
}
});
- MicroServiceFullInfo returnedMicroService = new MicroServiceFullInfo();
//when
try {
selfRegistrationManager.deRegister();
@@ -282,8 +283,8 @@ public class TestSelfRegistrationManager extends TestBase {
}
//verify
InOrder inOrder = Mockito.inOrder(jobManager, msbClient, lcnApi);
- inOrder.verify(msbClient).cancelMicroServiceInfo(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION);
- inOrder.verify(msbClient).queryMicroServiceInfo(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION);
+ 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);
verify(lcnApi, Mockito.never()).subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION);
assertServiceDown();
}
@@ -310,7 +311,7 @@ public class TestSelfRegistrationManager extends TestBase {
}
//verify
InOrder inOrder = Mockito.inOrder(jobManager, msbClient, lcnApi);
- inOrder.verify(msbClient).cancelMicroServiceInfo(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION);
+ inOrder.verify(msbClient).deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null);
inOrder.verify(lcnApi).subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION);
assertServiceDown();
}
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/TestLifecycleChangeNotificationManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/TestLifecycleChangeNotificationManager.java
index dc1b8ddf..922e92bb 100644
--- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/TestLifecycleChangeNotificationManager.java
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/TestLifecycleChangeNotificationManager.java
@@ -17,6 +17,11 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification;
import com.google.gson.*;
import com.nokia.cbam.lcm.v32.model.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Optional;
+import java.util.concurrent.*;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -26,11 +31,7 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
import org.threeten.bp.OffsetDateTime;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.Optional;
-import java.util.concurrent.*;
+import static java.util.Optional.empty;
import static com.nokia.cbam.lcm.v32.model.OperationType.*;
import static junit.framework.TestCase.*;
@@ -95,7 +96,6 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
}
private void prepOperation(OperationExecution operationExecution) {
- addEmptyModifiedConnectionPoints(operationExecution);
JsonElement root = new JsonParser().parse("{ \"additionalParams\" : { \"jobId\" : \"" + JOB_ID + "\"}}");
operationExecution.setOperationParams(root);
switch (operationExecution.getOperationType()) {
@@ -349,6 +349,7 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
secondTerminationOperationExecution.setOperationParams(buildTerminationParams());
nonProcessedEvent.setLifecycleOperationOccurrenceId(secondTerminationOperationExecution.getId());
lifecycleChangeNotificationManager.handleLcn(nonProcessedEvent);
+ addEmptyModifiedConnectionPoints(terminationOperation);
//add second termination
recievedLcn.setOperation(OperationType.TERMINATE);
recievedLcn.setStatus(OperationStatus.FINISHED);
@@ -401,6 +402,7 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
lifecycleChangeNotificationManager.handleLcn(recievedLcn);
//verify
assertTrue(waitExitedWithSuccess.get());
+ assertEquals(empty(), affectedConnectionPoints.getValue());
}
/**
@@ -443,6 +445,34 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
verify(logger).warn("The operation failed and the affected connection points were not reported");
}
+
+ /**
+ * affected connection points are passed to the actual notification processor
+ */
+ @Test
+ public void testAffectedConnectionPointProcessing() throws Exception {
+ //given
+ recievedLcn.setOperation(OperationType.INSTANTIATE);
+ recievedLcn.setStatus(OperationStatus.FINISHED);
+ recievedLcn.setLifecycleOperationOccurrenceId(instantiationOperation.getId());
+ instantiationOperation.setStatus(OperationStatus.FAILED);
+ addEmptyModifiedConnectionPoints(instantiationOperation);
+ OperationResult operationResult = new OperationResult();
+ ReportedAffectedConnectionPoints affectedCp = new ReportedAffectedConnectionPoints();
+ ReportedAffectedCp cp = new ReportedAffectedCp();
+ cp.setCpId("cpId");
+ affectedCp.getPost().add(cp);
+ operationResult.operationResult = affectedCp;
+ instantiationOperation.setAdditionalData(new Gson().toJsonTree(operationResult));
+
+ //when
+ lifecycleChangeNotificationManager.handleLcn(recievedLcn);
+ //verify
+ assertTrue(affectedConnectionPoints.getValue().isPresent());
+ ReportedAffectedConnectionPoints actualCps = new Gson().fromJson(new Gson().toJsonTree(affectedConnectionPoints.getValue().get()), ReportedAffectedConnectionPoints.class);
+ assertEquals(1, actualCps.getPost().size());
+ }
+
/**
* Failures in affected connection point processing are tolerated for failed operation
* (because the POST script was not able to run)
@@ -454,6 +484,7 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
recievedLcn.setStatus(OperationStatus.FAILED);
recievedLcn.setLifecycleOperationOccurrenceId(instantiationOperation.getId());
instantiationOperation.setStatus(OperationStatus.FAILED);
+ addEmptyModifiedConnectionPoints(instantiationOperation);
JsonObject additionalData = (JsonObject) instantiationOperation.getAdditionalData();
additionalData.remove("operationResult");
//when
@@ -500,8 +531,10 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
request.setType(ScaleDirection.OUT);
scaleOperation.setOperationParams(request);
scaleOperation.setStatus(OperationStatus.FAILED);
+ addEmptyModifiedConnectionPoints(scaleOperation);
((JsonObject) scaleOperation.getAdditionalData()).get("operationResult").getAsJsonObject().remove("cbam_post");
scaleOperation.setOperationType(OperationType.SCALE);
+
//when
lifecycleChangeNotificationManager.handleLcn(recievedLcn);
assertFalse(affectedConnectionPoints.getValue().isPresent());
@@ -522,6 +555,7 @@ public class TestLifecycleChangeNotificationManager extends TestBase {
request.setType(ScaleDirection.OUT);
scaleOperation.setOperationParams(request);
scaleOperation.setStatus(OperationStatus.FAILED);
+ addEmptyModifiedConnectionPoints(scaleOperation);
JsonObject operationResult = ((JsonObject) scaleOperation.getAdditionalData()).get("operationResult").getAsJsonObject();
operationResult.remove("cbam_post");
operationResult.addProperty("cbam_post", "");
diff --git a/nokiav2/driver/src/test/resources/unittests/packageconverter/cbam.full.modified.vnfd.yaml b/nokiav2/driver/src/test/resources/unittests/packageconverter/cbam.full.modified.vnfd.yaml
index 83f1ea35..ba65e4f2 100644
--- a/nokiav2/driver/src/test/resources/unittests/packageconverter/cbam.full.modified.vnfd.yaml
+++ b/nokiav2/driver/src/test/resources/unittests/packageconverter/cbam.full.modified.vnfd.yaml
@@ -1,87 +1,68 @@
----
-tosca_definitions_version: "tosca_simple_profile_for_nfv_1_0_0_nokia"
+tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0_nokia
topology_template:
substitution_mappings:
- node_type: "tosca.nodes.nfv.VNF"
+ node_type: tosca.nodes.nfv.VNF
capabilities:
vnf:
properties:
modifiable_attributes:
extensions:
- existingAttribute:
- default: "value"
- onapCsarId:
- default: "kuku"
- vimId:
- default: "kuku"
+ existingAttribute: {default: value}
+ onapCsarId: {default: kuku}
+ vimId: {default: kuku}
interfaces:
Basic:
instantiate:
inputs:
extensions:
pre_actions:
- - javascript: "pre"
- include:
- - "javascript/scalable_prepare_cbam_include.js"
- output: "stack_parameters"
- - javascript: "javascript/cbam.pre.collectConnectionPoints.js"
- include:
- - "javascript/cbam.collectConnectionPoints.js"
- output: "operation_result"
+ - javascript: pre
+ include: [javascript/scalable_prepare_cbam_include.js]
+ output: stack_parameters
+ - javascript: javascript/cbam.pre.collectConnectionPoints.js
+ include: [javascript/cbam.collectConnectionPoints.js]
+ output: operation_result
post_actions:
- - javascript: "post"
- output: "ansible_inventory"
- - javascript: "javascript/cbam.post.collectConnectionPoints.js"
- include:
- - "javascript/cbam.collectConnectionPoints.js"
- output: "operation_result"
- additional_parameters:
- kuku: "muku"
- jobId: "kuku"
+ - {javascript: post, output: ansible_inventory}
+ - javascript: javascript/cbam.post.collectConnectionPoints.js
+ include: [javascript/cbam.collectConnectionPoints.js]
+ output: operation_result
+ additional_parameters: {kuku: muku, jobId: kuku}
terminate:
inputs:
extensions:
pre_actions:
- - javascript: "javascript/cbam.pre.collectConnectionPoints.js"
- include:
- - "javascript/cbam.collectConnectionPoints.js"
- output: "operation_result"
+ - javascript: javascript/cbam.pre.collectConnectionPoints.js
+ include: [javascript/cbam.collectConnectionPoints.js]
+ output: operation_result
post_actions:
- - javascript: "javascript/cbam.post.collectConnectionPoints.js"
- include:
- - "javascript/cbam.collectConnectionPoints.js"
- output: "operation_result"
- additional_parameters:
- jobId: "kuku"
+ - javascript: javascript/cbam.post.collectConnectionPoints.js
+ include: [javascript/cbam.collectConnectionPoints.js]
+ output: operation_result
+ additional_parameters: {jobId: kuku}
Scalable:
scale:
inputs:
extensions:
pre_actions:
- - javascript: "javascript/cbam.pre.collectConnectionPoints.js"
- include:
- - "javascript/cbam.collectConnectionPoints.js"
- output: "operation_result"
+ - javascript: javascript/cbam.pre.collectConnectionPoints.js
+ include: [javascript/cbam.collectConnectionPoints.js]
+ output: operation_result
post_actions:
- - javascript: "javascript/cbam.post.collectConnectionPoints.js"
- include:
- - "javascript/cbam.collectConnectionPoints.js"
- output: "operation_result"
- additional_parameters:
- jobId: "kuku"
+ - javascript: javascript/cbam.post.collectConnectionPoints.js
+ include: [javascript/cbam.collectConnectionPoints.js]
+ output: operation_result
+ additional_parameters: {jobId: kuku}
Healable:
heal:
inputs:
extensions:
pre_actions:
- - javascript: "javascript/cbam.pre.collectConnectionPoints.js"
- include:
- - "javascript/cbam.collectConnectionPoints.js"
- output: "operation_result"
+ - javascript: javascript/cbam.pre.collectConnectionPoints.js
+ include: [javascript/cbam.collectConnectionPoints.js]
+ output: operation_result
post_actions:
- - javascript: "javascript/cbam.post.collectConnectionPoints.js"
- include:
- - "javascript/cbam.collectConnectionPoints.js"
- output: "operation_result"
- additional_parameters:
- jobId: "kuku"
+ - javascript: javascript/cbam.post.collectConnectionPoints.js
+ include: [javascript/cbam.collectConnectionPoints.js]
+ output: operation_result
+ additional_parameters: {jobId: kuku}
diff --git a/nokiav2/driver/src/test/resources/unittests/packageconverter/cbam.minimal.modified.vnfd.yaml b/nokiav2/driver/src/test/resources/unittests/packageconverter/cbam.minimal.modified.vnfd.yaml
index 2b05ecf1..ed242473 100644
--- a/nokiav2/driver/src/test/resources/unittests/packageconverter/cbam.minimal.modified.vnfd.yaml
+++ b/nokiav2/driver/src/test/resources/unittests/packageconverter/cbam.minimal.modified.vnfd.yaml
@@ -1,46 +1,37 @@
----
-tosca_definitions_version: "tosca_simple_profile_for_nfv_1_0_0_nokia"
+tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0_nokia
topology_template:
substitution_mappings:
- node_type: "tosca.nodes.nfv.VNF"
+ node_type: tosca.nodes.nfv.VNF
interfaces:
Basic:
instantiate:
inputs:
extensions:
pre_actions:
- - javascript: "javascript/cbam.pre.collectConnectionPoints.js"
- include:
- - "javascript/cbam.collectConnectionPoints.js"
- output: "operation_result"
+ - javascript: javascript/cbam.pre.collectConnectionPoints.js
+ include: [javascript/cbam.collectConnectionPoints.js]
+ output: operation_result
post_actions:
- - javascript: "javascript/cbam.post.collectConnectionPoints.js"
- include:
- - "javascript/cbam.collectConnectionPoints.js"
- output: "operation_result"
- additional_parameters:
- jobId: "kuku"
+ - javascript: javascript/cbam.post.collectConnectionPoints.js
+ include: [javascript/cbam.collectConnectionPoints.js]
+ output: operation_result
+ additional_parameters: {jobId: kuku}
terminate:
inputs:
extensions:
pre_actions:
- - javascript: "javascript/cbam.pre.collectConnectionPoints.js"
- include:
- - "javascript/cbam.collectConnectionPoints.js"
- output: "operation_result"
+ - javascript: javascript/cbam.pre.collectConnectionPoints.js
+ include: [javascript/cbam.collectConnectionPoints.js]
+ output: operation_result
post_actions:
- - javascript: "javascript/cbam.post.collectConnectionPoints.js"
- include:
- - "javascript/cbam.collectConnectionPoints.js"
- output: "operation_result"
- additional_parameters:
- jobId: "kuku"
+ - javascript: javascript/cbam.post.collectConnectionPoints.js
+ include: [javascript/cbam.collectConnectionPoints.js]
+ output: operation_result
+ additional_parameters: {jobId: kuku}
capabilities:
vnf:
properties:
modifiable_attributes:
extensions:
- onapCsarId:
- default: "kuku"
- vimId:
- default: "kuku"
+ onapCsarId: {default: kuku}
+ vimId: {default: kuku}