package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core;
-import com.nokia.cbam.lcn.v32.ApiException;
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;
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;
public class SelfRegistrationManager {
public static final String DRIVER_VERSION = "v1";
public static final String SERVICE_NAME = "NokiaSVNFM";
- // 1 means internal 0 means core :)
- public static final String INTERNAL_SERVICE = "1";
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;
-
@Value("${driverMsbExternalIp}")
private String driverMsbExternalIp;
@Value("${driverVnfmExternalIp}")
public void deRegister() {
try {
logger.info("Cancelling micro service registration");
- msbApiProvider.getMsbClient().cancelMicroServiceInfo(SERVICE_NAME, DRIVER_VERSION);
- } catch (RouteException e) {
+ msbApiProvider.getMsbApi().deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null).blockingFirst();
+ } catch (Exception e) {
//ONAP throws 500 internal server error, but deletes the micro service
+ boolean serviceFoundAfterDelete = false;
try {
- MicroServiceFullInfo microServiceFullInfo = msbApiProvider.getMsbClient().queryMicroServiceInfo(SERVICE_NAME, DRIVER_VERSION);
- logger.error("Unable to deRegister Nokia VNFM driver", e);
- //the micro service still exists
- throw new RuntimeException(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());
}
* @return the swagger API definition
*/
public byte[] getSwaggerApiDefinition() {
- return SystemFunctions.systemFunctions().loadFile(SWAGGER_API_DEFINITION);
+ return systemFunctions().loadFile(SWAGGER_API_DEFINITION);
}
private String getDriverVnfmUrl() {
logger.info("Deleting CBAM LCN subscription");
SubscriptionsApi lcnApi = cbamRestApiProvider.getCbamLcnApi(vnfmId);
try {
- String callbackUrl = getDriverVnfmUrl() + DriverProperties.LCN_PATH;
- for (Subscription subscription : lcnApi.subscriptionsGet(NOKIA_LCN_API_VERSION)) {
+ 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());
+ lcnApi.subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION).blockingFirst();
}
}
- } catch (ApiException e) {
- logger.error("Unable to delete CBAM LCN subscription");
- throw new RuntimeException(e);
+ } catch (Exception e) {
+ throw buildFatalFailure(logger, "Unable to delete CBAM LCN subscription", e);
}
}
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);
- //FIXME set enable_ssl to false after the field has been added to MSB SDK
- //currently defaults to false, which is good
+ 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) {
- logger.error("Unable to register Nokia VNFM driver", e);
- throw new RuntimeException(e);
+ return msbApiProvider.getMsbApi().addMicroService(microServiceInfo, true, false).blockingFirst();
+ } catch (Exception e) {
+ throw buildFatalFailure(logger, "Unable to register Nokia VNFM driver", e);
}
}
private void subscribeToLcn(String vnfmId) {
- String callbackUrl = getDriverVnfmUrl() + DriverProperties.LCN_PATH;
- logger.info("Subscribing to CBAM LCN " + driverProperties.getCbamLcnUrl() + " with callback to " + callbackUrl);
+ String callbackUrl = getDriverVnfmUrl() + DriverProperties.LCN_URL;
+ logger.info("Subscribing to CBAM LCN {} with callback to {}", driverProperties.getCbamLcnUrl(), callbackUrl);
SubscriptionsApi lcnApi = cbamRestApiProvider.getCbamLcnApi(vnfmId);
try {
- for (Subscription subscription : lcnApi.subscriptionsGet(NOKIA_LCN_API_VERSION)) {
+ 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;
}
}
request.getFilter().addOperationTypesItem(OperationType.SCALE);
request.getFilter().addOperationTypesItem(OperationType.TERMINATE);
SubscriptionAuthentication subscriptionAuthentication = new SubscriptionAuthentication();
- subscriptionAuthentication.setType(NONE);//FIXME improve authentication
+ subscriptionAuthentication.setType(NONE);
request.setAuthentication(subscriptionAuthentication);
- lcnApi.subscriptionsPost(request, NOKIA_LCN_API_VERSION);
- } catch (ApiException e) {
- logger.error("Unable to subscribe to CBAM LCN", e);
- throw new RuntimeException(e);
+ 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);
}
}