summaryrefslogtreecommitdiffstats
path: root/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core
diff options
context:
space:
mode:
Diffstat (limited to 'nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core')
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/GenericExternalSystemInfoProvider.java16
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/SelfRegistrationManager.java80
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/SelfRegistrationManagerForSo.java33
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/SelfRegistrationManagerForVfc.java33
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/VnfmCredentials.java79
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/VnfmUrls.java67
6 files changed, 292 insertions, 16 deletions
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 38665877..4ec6717a 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
@@ -15,8 +15,11 @@
*/
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core;
+import com.google.common.base.Splitter;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
+import com.google.common.collect.Lists;
+import java.util.ArrayList;
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;
@@ -28,6 +31,7 @@ import org.springframework.core.env.Environment;
import static java.lang.Long.valueOf;
import static com.google.common.cache.CacheBuilder.newBuilder;
+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.slf4j.LoggerFactory.getLogger;
@@ -52,6 +56,17 @@ public abstract class GenericExternalSystemInfoProvider extends IpMappingProvide
this.environment = environment;
}
+ public static VnfmUrls convert(VnfmInfo vnfmInfo) {
+ ArrayList<String> urls = Lists.newArrayList(Splitter.on(SEPARATOR).split(vnfmInfo.getUrl()));
+ return new VnfmUrls(urls.get(0), urls.get(1), urls.get(2), urls.get(3));
+ }
+
+ public static VnfmCredentials convertToCredentials(VnfmInfo vnfmInfo) {
+ ArrayList<String> userNames = Lists.newArrayList(Splitter.on(SEPARATOR).split(vnfmInfo.getUserName()));
+ ArrayList<String> passwords = Lists.newArrayList(Splitter.on(SEPARATOR).split(vnfmInfo.getPassword()));
+ return new VnfmCredentials(userNames.get(0), passwords.get(0), userNames.get(1), passwords.get(1));
+ }
+
/**
* After the Bean has been initialized the IP mapping and the VMFM cache is initialized
* It is done in this phase because the logic requires the the @Value anoted fields to
@@ -88,4 +103,5 @@ public abstract class GenericExternalSystemInfoProvider extends IpMappingProvide
* @return the description of the VNFM
*/
public abstract VnfmInfo queryVnfmInfoFromSource(String vnfmId);
+
}
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 1dc32209..17060d67 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
@@ -16,18 +16,23 @@
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core;
+import com.google.common.collect.BiMap;
+import com.google.common.collect.HashBiMap;
import com.nokia.cbam.lcn.v32.api.SubscriptionsApi;
import com.nokia.cbam.lcn.v32.model.*;
import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Set;
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.api.VnfmInfoProvider;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.MultiException;
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.Constants;
+import org.onap.vnfmdriver.model.VnfmInfo;
import org.slf4j.Logger;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Component;
import static com.nokia.cbam.lcn.v32.model.SubscriptionAuthentication.TypeEnum.NONE;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.buildFatalFailure;
@@ -38,15 +43,15 @@ import static org.slf4j.LoggerFactory.getLogger;
/**
* Responsible for registering the driver in the core systems.
*/
-@Component
public class SelfRegistrationManager {
public static final String DRIVER_VERSION = "v1";
public static final String SERVICE_NAME = "NokiaSVNFM";
public static final String SWAGGER_API_DEFINITION = "self.swagger.json";
private static Logger logger = getLogger(SelfRegistrationManager.class);
- private final DriverProperties driverProperties;
private final MsbApiProvider msbApiProvider;
private final CbamRestApiProvider cbamRestApiProvider;
+ private final VnfmInfoProvider vnfmInfoProvider;
+ private final BiMap<String, String> vnfmIdToSubscriptionId = HashBiMap.create();
@Value("${driverMsbExternalIp}")
private String driverMsbExternalIp;
@Value("${driverVnfmExternalIp}")
@@ -55,11 +60,10 @@ public class SelfRegistrationManager {
private String driverPort;
private volatile boolean ready = false;
- @Autowired
- SelfRegistrationManager(DriverProperties driverProperties, MsbApiProvider msbApiProvider, CbamRestApiProvider cbamRestApiProvider) {
+ SelfRegistrationManager(VnfmInfoProvider vnfmInfoProvider, MsbApiProvider msbApiProvider, CbamRestApiProvider cbamRestApiProvider) {
this.cbamRestApiProvider = cbamRestApiProvider;
this.msbApiProvider = msbApiProvider;
- this.driverProperties = driverProperties;
+ this.vnfmInfoProvider = vnfmInfoProvider;
}
/**
@@ -67,11 +71,11 @@ public class SelfRegistrationManager {
*/
public void register() {
//the order is important (only publish it's existence after the subscription has been created)
- subscribeToLcn(driverProperties.getVnfmId());
+ subscribeToLcns();
try {
registerMicroService();
} catch (RuntimeException e) {
- deleteSubscription(driverProperties.getVnfmId());
+ deleteSubscriptions();
throw e;
}
ready = true;
@@ -98,7 +102,18 @@ public class SelfRegistrationManager {
throw buildFatalFailure(logger, "Unable to deRegister Nokia VNFM driver", e);
}
}
- deleteSubscription(driverProperties.getVnfmId());
+ deleteSubscriptions();
+ }
+
+ /**
+ * Subscribes to LCN if not yet subscribed
+ *
+ * @param vnfmId the identifier of the VNFM
+ */
+ public void assureSubscription(String vnfmId) {
+ if (!vnfmIdToSubscriptionId.containsKey(vnfmId)) {
+ subscribeToLcn(vnfmId);
+ }
}
/**
@@ -108,15 +123,38 @@ public class SelfRegistrationManager {
return systemFunctions().loadFile(SWAGGER_API_DEFINITION);
}
+ /**
+ * @param subscriptionId the identifier of the subscription
+ * @return the identifier of the VNFM for the subscription
+ */
+ public String getVnfmId(String subscriptionId) {
+ return vnfmIdToSubscriptionId.inverse().get(subscriptionId);
+ }
+
private String getDriverVnfmUrl() {
- return "http://" + driverVnfmExternalIp + ":" + driverPort + DriverProperties.BASE_URL;
+ return "http://" + driverVnfmExternalIp + ":" + driverPort + Constants.BASE_URL;
+ }
+
+ private void deleteSubscriptions() {
+ Set<Exception> exceptions = new HashSet<>();
+ for (String vnfmId : vnfmIdToSubscriptionId.keySet()) {
+ try {
+ deleteSubscription(vnfmId);
+ } catch (Exception e) {
+ exceptions.add(e);
+ logger.warn("Unable to delete subscription for the " + vnfmId);
+ }
+ }
+ if (!exceptions.isEmpty()) {
+ throw new MultiException("Unable to delete some of the subscriptions", exceptions);
+ }
}
private void deleteSubscription(String vnfmId) {
logger.info("Deleting CBAM LCN subscription");
SubscriptionsApi lcnApi = cbamRestApiProvider.getCbamLcnApi(vnfmId);
try {
- String callbackUrl = getDriverVnfmUrl() + DriverProperties.LCN_URL;
+ String callbackUrl = getDriverVnfmUrl() + Constants.LCN_URL;
for (Subscription subscription : lcnApi.subscriptionsGet(NOKIA_LCN_API_VERSION).blockingFirst()) {
if (subscription.getCallbackUrl().equals(callbackUrl)) {
logger.info("Deleting subscription with {} identifier", subscription.getId());
@@ -131,7 +169,7 @@ public class SelfRegistrationManager {
private MicroServiceFullInfo registerMicroService() {
logger.info("Registering micro service");
MicroServiceInfo microServiceInfo = new MicroServiceInfo();
- microServiceInfo.setUrl(DriverProperties.BASE_URL);
+ microServiceInfo.setUrl(Constants.BASE_URL);
//the PATH should not be set
microServiceInfo.setProtocol(MicroServiceInfo.ProtocolEnum.REST);
microServiceInfo.setVisualRange(MicroServiceInfo.VisualRangeEnum._1);
@@ -151,14 +189,23 @@ public class SelfRegistrationManager {
}
}
+ private void subscribeToLcns() {
+ for (String vnfmId : vnfmInfoProvider.getVnfms()) {
+ subscribeToLcn(vnfmId);
+ }
+ }
+
private void subscribeToLcn(String vnfmId) {
- String callbackUrl = getDriverVnfmUrl() + DriverProperties.LCN_URL;
- logger.info("Subscribing to CBAM LCN {} with callback to {}", driverProperties.getCbamLcnUrl(), callbackUrl);
+ String callbackUrl = getDriverVnfmUrl() + Constants.LCN_URL;
+ VnfmInfo vnfmInfo = vnfmInfoProvider.getVnfmInfo(vnfmId);
+ VnfmUrls vnfmUrls = GenericExternalSystemInfoProvider.convert(vnfmInfo);
+ logger.info("Subscribing to CBAM LCN {} with callback to {}", vnfmUrls.getLcnUrl(), callbackUrl);
SubscriptionsApi lcnApi = cbamRestApiProvider.getCbamLcnApi(vnfmId);
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());
+ vnfmIdToSubscriptionId.put(vnfmId, subscription.getId());
return;
}
}
@@ -176,6 +223,7 @@ public class SelfRegistrationManager {
request.setAuthentication(subscriptionAuthentication);
Subscription createdSubscription = lcnApi.subscriptionsPost(request, NOKIA_LCN_API_VERSION).blockingFirst();
logger.info("Subscribed to LCN with {} identifier", createdSubscription.getId());
+ vnfmIdToSubscriptionId.put(vnfmId, 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/core/SelfRegistrationManagerForSo.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/SelfRegistrationManagerForSo.java
new file mode 100644
index 00000000..bffd444d
--- /dev/null
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/SelfRegistrationManagerForSo.java
@@ -0,0 +1,33 @@
+/*
+ * 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.core;
+
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIExternalSystemInfoProvider;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProviderForSo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * Responsible for registering the driver in the core systems.
+ */
+@Component
+public class SelfRegistrationManagerForSo extends SelfRegistrationManager {
+ @Autowired
+ SelfRegistrationManagerForSo(AAIExternalSystemInfoProvider vnfmInfoProvider, MsbApiProvider msbApiProvider, CbamRestApiProviderForSo cbamRestApiProvider) {
+ super(vnfmInfoProvider, msbApiProvider, cbamRestApiProvider);
+ }
+}
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/SelfRegistrationManagerForVfc.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/SelfRegistrationManagerForVfc.java
new file mode 100644
index 00000000..c550e887
--- /dev/null
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/SelfRegistrationManagerForVfc.java
@@ -0,0 +1,33 @@
+/*
+ * 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.core;
+
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.vfc.VfcExternalSystemInfoProvider;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProviderForVfc;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * Responsible for registering the driver in the core systems.
+ */
+@Component
+public class SelfRegistrationManagerForVfc extends SelfRegistrationManager {
+ @Autowired
+ SelfRegistrationManagerForVfc(VfcExternalSystemInfoProvider vnfmInfoProvider, MsbApiProvider msbApiProvider, CbamRestApiProviderForVfc cbamRestApiProvider) {
+ super(vnfmInfoProvider, msbApiProvider, cbamRestApiProvider);
+ }
+}
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/VnfmCredentials.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/VnfmCredentials.java
new file mode 100644
index 00000000..270d004c
--- /dev/null
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/VnfmCredentials.java
@@ -0,0 +1,79 @@
+/*
+ * 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.core;
+
+import static com.google.common.hash.Hashing.sha512;
+
+/**
+ * Describes the VNFM credentials
+ */
+public class VnfmCredentials {
+ private final String username;
+ private final String password;
+ private final String clientId;
+ private final String clientSecret;
+
+ /**
+ * @param username the username for the VNFM
+ * @param password the password for the VNFM
+ * @param clientId the client identifier
+ * @param clientSecret the client secret
+ */
+ VnfmCredentials(String username, String password, String clientId, String clientSecret) {
+ this.username = username;
+ this.password = password;
+ this.clientId = clientId;
+ this.clientSecret = clientSecret;
+ }
+
+ /**
+ * @return the username for the VNFM
+ */
+ public String getUsername() {
+ return username;
+ }
+
+ /**
+ * @return the password for the VNFM
+ */
+ public String getPassword() {
+ return password;
+ }
+
+ /**
+ * @return the client identifier
+ */
+ public String getClientId() {
+ return clientId;
+ }
+
+ /**
+ * @return the client secret
+ */
+ public String getClientSecret() {
+ return clientSecret;
+ }
+
+ @Override
+ public String toString() {
+ return "VnfmCredentials{" +
+ "username='" + username + '\'' +
+ ", password='" + sha512().hashBytes(password.getBytes()).toString() + '\'' +
+ ", clientId='" + clientId + '\'' +
+ ", clientSecret='" + sha512().hashBytes(clientSecret.getBytes()).toString() + '\'' +
+ '}';
+ }
+}
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/VnfmUrls.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/VnfmUrls.java
new file mode 100644
index 00000000..04088459
--- /dev/null
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/VnfmUrls.java
@@ -0,0 +1,67 @@
+/*
+ * 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.core;
+
+/**
+ * Describes the VNFM URLs
+ */
+public class VnfmUrls {
+ private final String lcmUrl;
+ private final String lcnUrl;
+ private final String authUrl;
+ private final String catalogUrl;
+
+ /**
+ * @param authUrl the authentication server URL of the VNFM
+ * @param lcmUrl the LCM URL of the VNFM
+ * @param lcnUrl the LCN URL of the VNFM
+ * @param catalogUrl the catalog URL of the VNFM
+ */
+ VnfmUrls(String authUrl, String lcmUrl, String lcnUrl, String catalogUrl) {
+ this.lcmUrl = lcmUrl;
+ this.lcnUrl = lcnUrl;
+ this.authUrl = authUrl;
+ this.catalogUrl = catalogUrl;
+ }
+
+ /**
+ * @return the LCM URL of the VNFM
+ */
+ public String getLcmUrl() {
+ return lcmUrl;
+ }
+
+ /**
+ * @return the LCN URL of the VNFM
+ */
+ public String getLcnUrl() {
+ return lcnUrl;
+ }
+
+ /**
+ * @return the authentication server URL of the VNFM
+ */
+ public String getAuthUrl() {
+ return authUrl;
+ }
+
+ /**
+ * @return the catalog URL of the VNFM
+ */
+ public String getCatalogUrl() {
+ return catalogUrl;
+ }
+}