summaryrefslogtreecommitdiffstats
path: root/nokiav2/driver/src/main/java/org
diff options
context:
space:
mode:
authorDenes Nemeth <denes.nemeth@nokia.com>2018-04-03 17:32:13 +0200
committerDenes Nemeth <denes.nemeth@nokia.com>2018-04-04 14:08:23 +0200
commit2c1179b657efe2a291012d2b8f2eee2179402d27 (patch)
tree12343f52bda03c49e576ff72debe831c57c8cc5e /nokiav2/driver/src/main/java/org
parent0278d01123ce3de23d842a94a5ab99dba8853867 (diff)
Fixes in LCM
Change-Id: I9dfdacf32970c86b595939f6cd92b6eb276ebf90 Issue-ID: VFC-728 Signed-off-by: Denes Nemeth <denes.nemeth@nokia.com>
Diffstat (limited to 'nokiav2/driver/src/main/java/org')
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/AAIRestApiProvider.java3
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/direct/notification/VnfcManager.java10
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/so/SoLifecycleManager.java327
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/so/package-info.java20
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/LcmApi.java8
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/SoApi.java175
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/SystemFunctions.java2
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/AdditionalParameters.java19
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/LifecycleManager.java181
9 files changed, 653 insertions, 92 deletions
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 14bdea11..08bf2c41 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
@@ -23,10 +23,8 @@ 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.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Component;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager.SERVICE_NAME;
@@ -36,7 +34,6 @@ import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrati
* Handles authentication and mandatory parameters.
*/
@Component
-@Conditional(value = Conditions.UseForDirect.class)
public class AAIRestApiProvider {
private final MsbApiProvider msbApiProvider;
private final AaiSecurityProvider aaiSecurityProvider;
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 bc31f4fe..db65d2f1 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
@@ -27,6 +27,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Component;
+import static com.google.common.base.Splitter.on;
+import static com.google.common.collect.Lists.newArrayList;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.SEPARATOR;
/**
@@ -46,6 +48,14 @@ public class VnfcManager extends AbstractManager {
return vnfId + SEPARATOR + cbamVnfcId;
}
+ /**
+ * @param onapVnfcId the identifier of the VNFC in AAI
+ * @return the identifier of the VNFC in CBAM
+ */
+ public static String buildCbamId(String onapVnfcId) {
+ return newArrayList(on(SEPARATOR).split(onapVnfcId)).get(1);
+ }
+
@Override
protected Logger getLogger() {
return logger;
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/so/SoLifecycleManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/so/SoLifecycleManager.java
new file mode 100644
index 00000000..c6e07e83
--- /dev/null
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/so/SoLifecycleManager.java
@@ -0,0 +1,327 @@
+/*
+ * 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.so;
+
+
+import com.nokia.cbam.lcm.v32.model.*;
+import com.nokia.cbam.lcm.v32.model.VimInfo;
+import java.util.ArrayList;
+import java.util.List;
+import javax.servlet.http.HttpServletResponse;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.VimInfoProvider;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.AdditionalParameters;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider;
+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.vnfmadapter.so.model.*;
+import org.onap.vnfmdriver.model.ExtVirtualLinkInfo;
+import org.onap.vnfmdriver.model.*;
+import org.onap.vnfmdriver.model.VnfInfo;
+import org.slf4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import static java.util.Optional.of;
+
+import static com.nokia.cbam.lcm.v32.model.VimInfo.VimInfoTypeEnum.*;
+import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.VnfcManager.buildCbamId;
+import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider.NOKIA_LCM_API_VERSION;
+import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getVnfdIdFromModifyableAttributes;
+import static org.onap.vnfmadapter.so.model.SoJobStatus.*;
+import static org.slf4j.LoggerFactory.getLogger;
+import static org.springframework.util.StringUtils.isEmpty;
+
+/**
+ * Responsible for providing access to AAI APIs.
+ * Handles authentication and mandatory parameters.
+ */
+
+@Component
+public class SoLifecycleManager {
+ private static Logger logger = getLogger(SoLifecycleManager.class);
+ private final LifecycleManager lifecycleManager;
+ private final VimInfoProvider vimInfoProvider;
+ private final CbamRestApiProvider cbamRestApiProvider;
+ private final JobManager jobManager;
+
+ @Autowired
+ SoLifecycleManager(LifecycleManager lifecycleManager, VimInfoProvider vimInfoProvider, CbamRestApiProvider cbamRestApiProvider, JobManager jobManager) {
+ this.lifecycleManager = lifecycleManager;
+ this.vimInfoProvider = vimInfoProvider;
+ this.cbamRestApiProvider = cbamRestApiProvider;
+ this.jobManager = jobManager;
+ }
+
+ /**
+ * Creates the VNF in SO terminology
+ *
+ * @param vnfmId the identifier of the VNFM
+ * @param request the VNF creation request
+ * @return the VNF creation response
+ */
+ public SoVnfCreationResponse create(String vnfmId, SoVnfCreationRequest request) {
+ SoVnfCreationResponse response = new SoVnfCreationResponse();
+ LifecycleManager.VnfCreationResult result = lifecycleManager.create(vnfmId, request.getCsarId(), request.getName(), request.getDescription());
+ response.setVnfId(result.getVnfInfo().getId());
+ return response;
+ }
+
+ /**
+ * Activate the VNF in SO terminology
+ *
+ * @param vnfmId the identifier of the VNFM
+ * @param vnfId the identifier of the VNF
+ * @param soRequest the VNF activation request
+ * @param httpResponse the HTTP response
+ * @return the job handler of the VNF activation
+ */
+ public SoJobHandler activate(String vnfmId, String vnfId, SoVnfActivationRequest soRequest, HttpServletResponse httpResponse) {
+ AdditionalParameters additionalParameters = new AdditionalParameters();
+ additionalParameters.setAdditionalParams(buildAdditionalParameters(soRequest.getAdditionalParams()));
+ String vimId = soRequest.getVimId();
+ org.onap.vnfmdriver.model.VimInfo vimInfo = vimInfoProvider.getVimInfo(vimId);
+ additionalParameters.setVimType(vimTypeHeuristic(vimInfo.getUrl()));
+ processVdus(soRequest, additionalParameters, vimId);
+ if (isEmpty(additionalParameters.getInstantiationLevel())) {
+ additionalParameters.setInstantiationLevel("default");
+ }
+ processNetworks(soRequest, additionalParameters, vimId);
+ processZones(soRequest, additionalParameters, vimId);
+ com.nokia.cbam.lcm.v32.model.VnfInfo cbamVnfInfo = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdGet(vnfId, NOKIA_LCM_API_VERSION).blockingFirst();
+ String onapVnfdId = getVnfdIdFromModifyableAttributes(cbamVnfInfo);
+ VnfInfo vnfInfo = lifecycleManager.queryVnf(vnfmId, vnfId);
+ List<ExtVirtualLinkInfo> externalVirtualLinks = new ArrayList<>();
+ VnfInstantiateResponse instantiate = lifecycleManager.instantiate(vnfmId, externalVirtualLinks, httpResponse, soRequest.getAdditionalParams(), additionalParameters, vnfId, onapVnfdId, vnfInfo.getVnfdId());
+ return buildJobHandler(instantiate.getJobId());
+ }
+
+ /**
+ * Scale the VNF
+ *
+ * @param vnfmId the identifier of the VNFM
+ * @param vnfId the identifier of the VNF
+ * @param soRequest the VNF scale request
+ * @param httpResponse the HTTP response
+ * @return the job handler of the VNF activation
+ */
+ public SoJobHandler scale(String vnfmId, String vnfId, SoVnfScaleRequest soRequest, HttpServletResponse httpResponse) {
+ org.onap.vnfmdriver.model.VnfScaleRequest driverRequest = new org.onap.vnfmdriver.model.VnfScaleRequest();
+ driverRequest.setAdditionalParam(buildAdditionalParameters(soRequest.getAdditionalParams()));
+ driverRequest.setAspectId(soRequest.getAspectId());
+ driverRequest.setNumberOfSteps(soRequest.getSteps().toString());
+ driverRequest.setType(soRequest.getDirection() == SoScaleDirection.IN ? org.onap.vnfmdriver.model.ScaleDirection.IN : org.onap.vnfmdriver.model.ScaleDirection.OUT);
+ return buildJobHandler(lifecycleManager.scaleVnf(vnfmId, vnfId, driverRequest, httpResponse).getJobId());
+ }
+
+ /**
+ * Heal the VNF
+ *
+ * @param vnfmId the identifier of the VNFM
+ * @param vnfId the identifier of the VNF
+ * @param request the VNF heal request
+ * @param httpResponse the HTTP response
+ * @return the job handler of the VNF activation
+ */
+ public SoJobHandler heal(String vnfmId, String vnfId, SoVnfHealRequest request, HttpServletResponse httpResponse) {
+ org.onap.vnfmdriver.model.VnfHealRequest vnfHealRequest = new org.onap.vnfmdriver.model.VnfHealRequest();
+ VnfHealRequestAffectedvm affectedVm = new VnfHealRequestAffectedvm();
+ affectedVm.setVimid("notUsedByDriver");
+ affectedVm.setVduid("notUsedByDriver");
+ affectedVm.setVmname("unknown");
+ vnfHealRequest.setAffectedvm(affectedVm);
+ vnfHealRequest.setAction("heal");
+ return buildJobHandler(lifecycleManager.healVnf(vnfmId, vnfId, vnfHealRequest, of(buildCbamId(request.getVnfcId())), httpResponse).getJobId());
+ }
+
+ /**
+ * Deactivate the VNF
+ *
+ * @param vnfmId the identifier of the VNFM
+ * @param vnfId the identifier of the VNF
+ * @param soRequest the VNF deactivation request
+ * @param httpResponse the HTTP response
+ * @return the job handler of the VNF activation
+ */
+ public SoJobHandler deactivate(String vnfmId, String vnfId, SoVnfTerminationRequest soRequest, HttpServletResponse httpResponse) {
+ VnfTerminateRequest driverRequest = new VnfTerminateRequest();
+ driverRequest.setTerminationType(soRequest.getMode() == SoTerminationMode.FORCEFUL ? VnfTerminationType.FORCEFUL : VnfTerminationType.GRACEFUL);
+ driverRequest.setGracefulTerminationTimeout(soRequest.getGracefulTerminationTimeoutInMs().toString());
+ return buildJobHandler(lifecycleManager.terminateAndDelete(vnfmId, vnfId, driverRequest, httpResponse).getJobId());
+ }
+
+ /**
+ * Delete the VNF
+ *
+ * @param vnfmId the identifier of the VNFM
+ * @param vnfId the identifier of the VNF
+ * @return the job handler of the VNF activation
+ */
+ public void delete(String vnfmId, String vnfId) {
+ lifecycleManager.deleteVnf(vnfmId, vnfId);
+ }
+
+ /**
+ * Execute a custom operation on a VNF
+ *
+ * @param vnfmId the identifier of the VNFM
+ * @param vnfId the identifier of the VNF
+ * @param request the VNF custom
+ * @param httpResponse the HTTP response
+ * @return the job handler of the VNF activation
+ */
+ public SoJobHandler customOperation(String vnfmId, String vnfId, SoVnfCustomOperation request, HttpServletResponse httpResponse) {
+ String operationId = request.getOperationId();
+ CustomOperationRequest cbamRequest = new CustomOperationRequest();
+ cbamRequest.setAdditionalParams(buildAdditionalParameters(request.getAdditionalParams()));
+ return buildJobHandler(lifecycleManager.customOperation(vnfmId, vnfId, operationId, request.getAdditionalParams(), httpResponse).getJobId());
+ }
+
+ /**
+ * @param jobId the identifier of the job
+ * @param vnfmId the identifier of the VNFM
+ * @return the details of the job
+ */
+ public SoJobDetail getJobDetails(String vnfmId, String jobId) {
+ SoJobDetail jobDetail = new SoJobDetail();
+ jobDetail.setJobId(jobId);
+ JobStatus currentStatus = jobManager.getJob(vnfmId, jobId).getResponseDescriptor().getStatus();
+ if (JobStatus.STARTED.equals(currentStatus)) {
+ jobDetail.setStatus(STARTED);
+ } else if (JobStatus.PROCESSING.equals(currentStatus)) {
+ jobDetail.setStatus(STARTED);
+ } else if (JobStatus.FINISHED.equals(currentStatus)) {
+ jobDetail.setStatus(FINISHED);
+ } else if (JobStatus.TIMEOUT.equals(currentStatus)) {
+ jobDetail.setStatus(FAILED);
+ } else {//ERROR
+ jobDetail.setStatus(FAILED);
+ }
+ return jobDetail;
+ }
+
+ private VimInfo.VimInfoTypeEnum vimTypeHeuristic(String url) {
+ if (url.contains("/v3")) {
+ return OPENSTACK_V3_INFO;
+ } else if (url.contains("/v2")) {
+ return OPENSTACK_V2_INFO;
+ } else {
+ return VMWARE_VCLOUD_INFO;
+ }
+ }
+
+ private Object buildAdditionalParameters(Object additionalParams) {
+ return additionalParams;
+ }
+
+ private SoJobHandler buildJobHandler(String jobId) {
+ SoJobHandler jobHandler = new SoJobHandler();
+ jobHandler.setJobId(jobId);
+ return jobHandler;
+ }
+
+ private void processVdus(SoVnfActivationRequest request, AdditionalParameters additionalParameters, String vimId) {
+ if (request.getVduMappings() != null) {
+ for (SoVduMapping vduMapping : request.getVduMappings()) {
+ VimComputeResourceFlavour flavour = new VimComputeResourceFlavour();
+ flavour.setVimId(vimId);
+ flavour.setVnfdVirtualComputeDescId(vduMapping.getVduId());
+ flavour.setResourceId(vduMapping.getFlavourId());
+ additionalParameters.getComputeResourceFlavours().add(flavour);
+ VimSoftwareImage image = new VimSoftwareImage();
+ image.setVimId(vimId);
+ image.setResourceId(vduMapping.getImageId());
+ image.setVnfdSoftwareImageId(vduMapping.getVduId() + CbamUtils.SEPARATOR + "image");
+ additionalParameters.getSoftwareImages().add(image);
+ }
+ }
+ }
+
+ private void processNetworks(SoVnfActivationRequest request, AdditionalParameters additionalParameters, String vimId) {
+ if (request.getNetworkMappings() != null) {
+ for (SoNetworkMapping networkMapping : request.getNetworkMappings()) {
+ ExtVirtualLinkData extVirtualLinkData = createExtVirtualLinkData(additionalParameters, networkMapping.getVldId());
+ extVirtualLinkData.setVimId(vimId);
+ extVirtualLinkData.setResourceId(networkMapping.getNetworkProviderId());
+ if (networkMapping.getAssignedAddresses() != null) {
+ for (SoAssignedAddresses assignedAddresses : networkMapping.getAssignedAddresses()) {
+ VnfExtCpData extCpData = createExtVirtualLinkData(extVirtualLinkData.getExtCps(), assignedAddresses.getCpdId());
+ addMissing(extCpData, assignedAddresses.getIpAddress());
+ }
+ }
+ }
+ }
+ }
+
+ private void processZones(SoVnfActivationRequest request, AdditionalParameters additionalParameters, String vimId) {
+ if (request.getServerMappings() != null) {
+ for (SoServerMapping serverMapping : request.getServerMappings()) {
+ ZoneInfo zone = locateOrCreateZone(additionalParameters.getZones(), serverMapping.getVduId());
+ zone.setResourceId(serverMapping.getAvailabilityZoneId());
+ zone.setVimId(vimId);
+ }
+ }
+ }
+
+ private ZoneInfo locateOrCreateZone(List<ZoneInfo> zones, String vduId) {
+ if (zones != null) {
+ for (ZoneInfo zone : zones) {
+ if (zone.getId().equals(vduId)) {
+ return zone;
+ }
+ }
+ }
+ ZoneInfo zoneInfo = new ZoneInfo();
+ zoneInfo.setId(vduId);
+ zones.add(zoneInfo);
+ return zoneInfo;
+ }
+
+ private void addMissing(VnfExtCpData extCpData, String ipAddress) {
+ if (extCpData.getAddresses() == null) {
+ extCpData.setAddresses(new ArrayList<>());
+ }
+ for (NetworkAddress networkAddress : extCpData.getAddresses()) {
+ if (ipAddress.equals(networkAddress.getIp())) {
+ return;
+ }
+ }
+ NetworkAddress address = new NetworkAddress();
+ address.setIp(ipAddress);
+ extCpData.getAddresses().add(address);
+ }
+
+ private VnfExtCpData createExtVirtualLinkData(List<VnfExtCpData> extCps, String cpdId) {
+ if (extCps != null) {
+ for (VnfExtCpData extCp : extCps) {
+ if (extCp.getCpdId().equals(cpdId)) {
+ return extCp;
+ }
+ }
+ }
+ VnfExtCpData extCp = new VnfExtCpData();
+ extCp.setCpdId(cpdId);
+ extCps.add(extCp);
+ return extCp;
+ }
+
+ private ExtVirtualLinkData createExtVirtualLinkData(AdditionalParameters additionalParameters, String virtualLinkId) {
+ ExtVirtualLinkData nonExistingVl = new ExtVirtualLinkData();
+ nonExistingVl.setExtVirtualLinkId(virtualLinkId);
+ additionalParameters.getExtVirtualLinks().add(nonExistingVl);
+ return nonExistingVl;
+ }
+} \ No newline at end of file
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/so/package-info.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/so/package-info.java
new file mode 100644
index 00000000..0e29b927
--- /dev/null
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/so/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Handles information exchange with SO
+ */
+package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.so;
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 f7c9ed10..92148029 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
@@ -73,9 +73,9 @@ public class LcmApi {
/**
* Terminate the VNF (defined further in the VF-C driver integration documentation)
*
- * @param request the instantiation request
+ * @param request the termination request
* @param vnfmId the identifier of the VNFM
- * @param vnfInstanceId the identifer of the VNF
+ * @param vnfInstanceId the identifier of the VNF
* @param httpResponse the HTTP response
* @return the job representing the VNF termination operation
*/
@@ -90,7 +90,7 @@ public class LcmApi {
* Query the VNF (defined further in the VF-C driver integration documentation)
*
* @param vnfmId the identifier of the VNFM
- * @param vnfInstanceId the identifer of the VNF
+ * @param vnfInstanceId the identifier of the VNF
* @param httpResponse the HTTP response
* @return the VNF info
*/
@@ -104,7 +104,7 @@ public class LcmApi {
/**
* Query the job (defined further in the VF-C driver integration documentation)
*
- * @param jobId the identifer of the job
+ * @param jobId the identifier of the job
* @param vnfmId the identifier of the VNFM
* @param httpResponse the HTTP response
* @return the instantiated VNF info
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/SoApi.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/SoApi.java
new file mode 100644
index 00000000..b2c833bb
--- /dev/null
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/SoApi.java
@@ -0,0 +1,175 @@
+/*
+ * 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.restapi;
+
+import javax.servlet.http.HttpServletResponse;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.so.SoLifecycleManager;
+import org.onap.vnfmadapter.so.model.*;
+import org.slf4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import static javax.servlet.http.HttpServletResponse.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;
+import static org.springframework.web.bind.annotation.RequestMethod.*;
+
+/**
+ * Responsible for providing the Nokia sVNFM REST APIs
+ */
+@Controller
+@RequestMapping(value = BASE_URL + "/so")
+public class SoApi {
+ private static Logger logger = getLogger(SoApi.class);
+
+ private final SoLifecycleManager soLifecycleManager;
+
+ //private final LifecycleManager d;
+ @Autowired
+ SoApi(SoLifecycleManager lifecycleManager) {
+ this.soLifecycleManager = lifecycleManager;
+ }
+
+ /**
+ * Create the VNF
+ *
+ * @param request the creation request
+ * @param vnfmId the identifier of the VNFM
+ * @param httpResponse the HTTP response
+ * @return the descriptor of the created VNF
+ */
+ @RequestMapping(value = "/{vnfmId}/vnfs", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
+ @ResponseBody
+ public SoVnfCreationResponse createVnf(@RequestBody SoVnfCreationRequest request, @PathVariable("vnfmId") String vnfmId, HttpServletResponse httpResponse) {
+ logger.info("REST: Create the VNF");
+ SoVnfCreationResponse response = soLifecycleManager.create(vnfmId, request);
+ httpResponse.setStatus(SC_CREATED);
+ return response;
+ }
+
+ /**
+ * Activate the VNF
+ *
+ * @param request the activation request
+ * @param vnfmId the identifier of the VNFM
+ * @param httpResponse the HTTP response
+ * @return the descriptor of the created VNF
+ */
+ @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
+ @ResponseBody
+ public SoJobHandler activateVnf(@RequestBody SoVnfActivationRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) {
+ logger.info("REST: Create the VNF");
+ return soLifecycleManager.activate(vnfmId, vnfId, request, httpResponse);
+ }
+
+ /**
+ * Execute custom operation on the VNF
+ *
+ * @param request the custom operation request
+ * @param vnfmId the identifier of the VNFM
+ * @param httpResponse the HTTP response
+ * @return the descriptor of the created VNF
+ */
+ @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/customOperation", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
+ @ResponseBody
+ public SoJobHandler executeCustomOperation(@RequestBody SoVnfCustomOperation request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) {
+ logger.info("REST: Create the VNF");
+ return soLifecycleManager.customOperation(vnfmId, vnfId, request, httpResponse);
+ }
+
+ /**
+ * Terminate the VNF
+ *
+ * @param request the termination request
+ * @param vnfmId the identifier of the VNFM
+ * @param vnfId the identifier of the VNF
+ * @param httpResponse the HTTP response
+ * @return the job representing the VNF termination operation
+ */
+ @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/terminate", method = POST, produces = APPLICATION_JSON_VALUE)
+ @ResponseBody
+ public SoJobHandler deactivateVnf(@RequestBody SoVnfTerminationRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) {
+ logger.info("REST: Deactivate VNF");
+ return soLifecycleManager.deactivate(vnfmId, vnfId, request, httpResponse);
+ }
+
+ /**
+ * Delete the VNF
+ *
+ * @param vnfmId the identifier of the VNFM
+ * @param vnfId the identifier of the VNF
+ * @param httpResponse the HTTP response
+ */
+ @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}", method = DELETE)
+ public void deleteVnf(@PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) {
+ logger.info("REST: Delete VNF");
+ soLifecycleManager.delete(vnfmId, vnfId);
+ httpResponse.setStatus(HttpServletResponse.SC_NO_CONTENT);
+ }
+
+ /**
+ * Query the job
+ *
+ * @param jobId the identifier of the job
+ * @param vnfmId the identifier of the VNFM
+ * @param httpResponse the HTTP response
+ * @return the instantiated VNF info
+ */
+ @RequestMapping(value = "/{vnfmId}/jobs/{jobId}", method = GET, produces = APPLICATION_JSON_VALUE)
+ @ResponseBody
+ public SoJobDetail getJob(@PathVariable("vnfmId") String vnfmId, @PathVariable("jobId") String jobId, HttpServletResponse httpResponse) {
+ logger.debug("REST: Query the job");
+ return soLifecycleManager.getJobDetails(vnfmId, jobId);
+ }
+
+ /**
+ * Scale the VNF (defined further in the VF-C driver integration documentation)
+ *
+ * @param request the scaling request
+ * @param vnfmId the identifier of the VNFM
+ * @param vnfId the identifier of the VNF
+ * @param httpResponse the HTTP response
+ * @return the job representing the scaling operation
+ */
+ @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/scale", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
+ @ResponseBody
+ public SoJobHandler scaleVnf(@RequestBody SoVnfScaleRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfId, HttpServletResponse httpResponse) {
+ logger.info("REST: Scale the VNF");
+ return soLifecycleManager.scale(vnfmId, vnfId, request, httpResponse);
+ }
+
+ /**
+ * Heal the VNF (defined further in the VF-C driver integration documentation)
+ *
+ * @param request the healing request
+ * @param vnfmId the identifier of the VNFM
+ * @param vnfInstanceId the identifier of the VNF
+ * @param httpResponse the HTTP response
+ * @return the job representing the healing operation
+ */
+ @RequestMapping(value = "/{vnfmId}/vnfs/{vnfId}/heal", method = POST, produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
+ @ResponseBody
+ public SoJobHandler healVnf(@RequestBody SoVnfHealRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfInstanceId, HttpServletResponse httpResponse) {
+ logger.info("REST: Heal the VNF");
+ return soLifecycleManager.heal(vnfmId, vnfInstanceId, request, httpResponse);
+ }
+}
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 b67c7863..22d4c20d 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
@@ -67,7 +67,7 @@ public class SystemFunctions {
* operating system and may be larger. For example, many
* operating systems measure time in units of tens of
* milliseconds.
- * <p>
+ *
* <p> See the description of the class <code>Date</code> for
* a discussion of slight discrepancies that may arise between
* Unable to load /unittests/missing * "computer time" and coordinated universal time (UTC).
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 f585a6a2..1ec129ea 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
@@ -24,7 +24,6 @@ import java.util.*;
*/
public class AdditionalParameters {
private VimInfoTypeEnum vimType;
- private String domain;
private String instantiationLevel;
private List<VimComputeResourceFlavour> computeResourceFlavours = new ArrayList<>();
private List<ZoneInfo> zones = new ArrayList<>();
@@ -67,20 +66,6 @@ public class AdditionalParameters {
}
/**
- * @return the domain of the OpenStack (required for v3 API)
- */
- public String getDomain() {
- return domain;
- }
-
- /**
- * @param domain the domain of the OpenStack (required for v3 API)
- */
- public void setDomain(String domain) {
- this.domain = domain;
- }
-
- /**
* @return the flavours to be used for the VNF
*/
public List<VimComputeResourceFlavour> getComputeResourceFlavours() {
@@ -180,7 +165,6 @@ public class AdditionalParameters {
if (o == null || getClass() != o.getClass()) return false;
AdditionalParameters that = (AdditionalParameters) o;
return vimType == that.vimType &&
- Objects.equals(domain, that.domain) &&
Objects.equals(instantiationLevel, that.instantiationLevel) &&
Objects.equals(computeResourceFlavours, that.computeResourceFlavours) &&
Objects.equals(zones, that.zones) &&
@@ -194,14 +178,13 @@ public class AdditionalParameters {
@Override
public int hashCode() {
- return Objects.hash(vimType, domain, instantiationLevel, computeResourceFlavours, zones, softwareImages, extManagedVirtualLinks, externalConnectionPointAddresses, extVirtualLinks, additionalParams);
+ return Objects.hash(vimType, instantiationLevel, computeResourceFlavours, zones, softwareImages, extManagedVirtualLinks, externalConnectionPointAddresses, extVirtualLinks, additionalParams);
}
@Override
public String toString() {
return "AdditionalParameters{" +
"vimType=" + vimType +
- ", domain='" + domain + '\'' +
", instantiationLevel='" + instantiationLevel + '\'' +
", computeResourceFlavours=" + computeResourceFlavours +
", zones=" + zones +
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 94ab240a..5cd11058 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
@@ -30,7 +30,6 @@ 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;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.UserVisibleError;
import org.onap.vnfmdriver.model.ExtVirtualLinkInfo;
import org.onap.vnfmdriver.model.*;
import org.onap.vnfmdriver.model.VimInfo;
@@ -113,6 +112,10 @@ public class LifecycleManager {
return find(NEWEST_OPERATIONS_FIRST.sortedCopy(operationExecutions), op -> INSTANTIATE.equals(op.getOperationType()));
}
+ public static String getVnfdIdFromModifyableAttributes(com.nokia.cbam.lcm.v32.model.VnfInfo vnf) {
+ return find(vnf.getExtensions(), p -> p.getName().equals(ONAP_CSAR_ID)).getValue().toString();
+ }
+
/**
* Create the VNF. It consists of the following steps
* <ul>
@@ -123,7 +126,7 @@ public class LifecycleManager {
* The rollback of the failed operation is not implemented
* <ul>
* <li>delete the VNF if error occurs before instantiation</li>
- * <li>terminate & delete VNF if error occurs after instantiation</li>
+ * <li>terminateVnf & delete VNF if error occurs after instantiation</li>
* </ul>
*
* @param vnfmId the identifier of the VNFM
@@ -157,22 +160,25 @@ public class LifecycleManager {
/**
* Instantiate the VNF
*
- * @param vnfmId the identifier of the VNFM
- * @param request the VNF instantiation request
- * @param httpResponse the HTTP response that corresponds to the VNF instantiation request
- * @param additionalParameters additional parameters
- * @param vnfId thr identifier of the VNF
- * @param vnfdId the identifier of the VNF package in CBAM
+ * @param vnfmId the identifier of the VNFM
+ * @param externalVirtualLinks the external virtual links of the VNF
+ * @param httpResponse the HTTP response that corresponds to the VNF instantiation request
+ * @param additionalParameters additional parameters
+ * @param vnfId the identifier of the VNF
+ * @param vnfmVnfdId the identifier of the VNF package in CBAM
+ * @param operationAdditionalParameters the additional parameters of the operation
+ * @param onapVnfdId the identifier of the VNFD in the VNFM
* @return the instantiation response
*/
- public VnfInstantiateResponse instantiate(String vnfmId, VnfInstantiateRequest request, HttpServletResponse httpResponse, AdditionalParameters additionalParameters, String vnfId, String vnfdId) {
- logOperationInput(vnfId, "instantiation", request);
+ @SuppressWarnings("squid:S00107") //wrapping them into an object makes the code less readable
+ public VnfInstantiateResponse instantiate(String vnfmId, List<ExtVirtualLinkInfo> externalVirtualLinks, HttpServletResponse httpResponse, Object operationAdditionalParameters, AdditionalParameters additionalParameters, String vnfId, String onapVnfdId, String vnfmVnfdId) {
+ logOperationInput(vnfId, "instantiation", additionalParameters);
validateVimType(additionalParameters.getVimType());
VnfInstantiateResponse response = new VnfInstantiateResponse();
response.setVnfInstanceId(vnfId);
- String vimId = getVimId(request.getAdditionalParam());
+ String vimId = getVimId(operationAdditionalParameters);
JobInfo spawnJob = scheduleExecution(vnfId, httpResponse, "instantiate", jobInfo ->
- instantiateVnf(vnfmId, request, additionalParameters, vnfdId, vnfId, vimId, jobInfo)
+ instantiateVnf(vnfmId, externalVirtualLinks, additionalParameters, onapVnfdId, vnfmVnfdId, vnfId, vimId, jobInfo)
);
response.setJobId(spawnJob.getJobId());
return response;
@@ -193,7 +199,7 @@ public class LifecycleManager {
* The rollback of the failed operation is not implemented
* <ul>
* <li>delete the VNF if error occurs before instantiation</li>
- * <li>terminate & delete VNf if error occurs after instantiation</li>
+ * <li>terminateVnf & delete VNf if error occurs after instantiation</li>
* </ul>
*
* @param vnfmId the identifier of the VNFM
@@ -205,18 +211,19 @@ public class LifecycleManager {
AdditionalParameters additionalParameters = convertInstantiationAdditionalParams(request.getVnfPackageId(), request.getAdditionalParam());
validateVimType(additionalParameters.getVimType());
VnfCreationResult creationResult = create(vnfmId, request.getVnfDescriptorId(), request.getVnfInstanceName(), request.getVnfInstanceDescription());
- return instantiate(vnfmId, request, httpResponse, additionalParameters, creationResult.vnfInfo.getId(), creationResult.vnfdId);
+ return instantiate(vnfmId, request.getExtVirtualLink(), httpResponse, request.getAdditionalParam(), additionalParameters, creationResult.vnfInfo.getId(), request.getVnfPackageId(), creationResult.vnfdId);
}
- private void instantiateVnf(String vnfmId, VnfInstantiateRequest request, AdditionalParameters additionalParameters, String vnfdId, String vnfId, String vimId, JobInfo jobInfo) {
- String vnfdContent = catalogManager.getCbamVnfdContent(vnfmId, vnfdId);
- GrantVNFResponseVim vim = grantManager.requestGrantForInstantiate(vnfmId, vnfId, vimId, request.getVnfPackageId(), additionalParameters.getInstantiationLevel(), vnfdContent, jobInfo.getJobId());
+ @SuppressWarnings("squid:S00107") //wrapping them into an object makes the code less readable
+ private void instantiateVnf(String vnfmId, List<ExtVirtualLinkInfo> extVirtualLinkInfos, AdditionalParameters additionalParameters, String onapVnfdId, String vnfmVnfdId, String vnfId, String vimId, JobInfo jobInfo) {
+ String vnfdContent = catalogManager.getCbamVnfdContent(vnfmId, vnfmVnfdId);
+ GrantVNFResponseVim vim = grantManager.requestGrantForInstantiate(vnfmId, vnfId, vimId, onapVnfdId, additionalParameters.getInstantiationLevel(), vnfdContent, jobInfo.getJobId());
if (vim.getVimId() == null) {
throw buildFatalFailure(logger, "VF-C did not send VIM identifier in grant response");
}
VimInfo vimInfo = vimInfoProvider.getVimInfo(vim.getVimId());
InstantiateVnfRequest instantiationRequest = new InstantiateVnfRequest();
- addExternalLinksToRequest(request.getExtVirtualLink(), additionalParameters, instantiationRequest, vimId);
+ addExternalLinksToRequest(extVirtualLinkInfos, additionalParameters, instantiationRequest, vimId);
instantiationRequest.getVims().add(addVim(additionalParameters, vimId, vim, vimInfo));
instantiationRequest.setFlavourId(getFlavorId(vnfdContent));
instantiationRequest.setComputeResourceFlavours(additionalParameters.getComputeResourceFlavours());
@@ -328,7 +335,7 @@ public class LifecycleManager {
OpenStackAccessInfoV3 accessInfov3 = new OpenStackAccessInfoV3();
openstackv3INFO.accessInfo(accessInfov3);
accessInfov3.setPassword(vimInfo.getPassword());
- accessInfov3.setDomain(additionalParameters.getDomain());
+ accessInfov3.setDomain(vimInfo.getDomain());
accessInfov3.setProject(vim.getAccessInfo().getTenant());
accessInfov3.setRegion(getRegionName(vimId));
accessInfov3.setUsername(vimInfo.getUserName());
@@ -400,44 +407,71 @@ public class LifecycleManager {
*/
public JobInfo terminateAndDelete(String vnfmId, String vnfId, VnfTerminateRequest request, HttpServletResponse httpResponse) {
logOperationInput(vnfId, "termination", request);
- return scheduleExecution(vnfId, httpResponse, "terminate", jobInfo -> {
- TerminateVnfRequest cbamRequest = new TerminateVnfRequest();
- if (request.getTerminationType() == null) {
- cbamRequest.setTerminationType(TerminationType.FORCEFUL);
- } else {
- if (request.getTerminationType().equals(VnfTerminationType.GRACEFUL)) {
- cbamRequest.setTerminationType(TerminationType.GRACEFUL);
- cbamRequest.setGracefulTerminationTimeout(parseInt(request.getGracefulTerminationTimeout()));
- } else {
- 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) {
- terminateAndDelete(vnfmId, vnfId, jobInfo, cbamRequest, vnf);
- } else {
- logger.debug("The VNF {} with identifier is not instantiated no termination required", vnf.getId());
- deleteVnf(vnfmId, vnfId);
- }
+ return scheduleExecution(vnfId, httpResponse, "terminateVnf", jobInfo -> {
+ terminateVnf(vnfmId, vnfId, request, jobInfo);
+ deleteVnf(vnfmId, vnfId);
});
}
- private void terminateAndDelete(String vnfmId, String vnfId, JobInfo jobInfo, TerminateVnfRequest cbamRequest, com.nokia.cbam.lcm.v32.model.VnfInfo vnf) {
- String vimId = getVimIdFromInstantiationRequest(vnfmId, vnf);
- grantManager.requestGrantForTerminate(vnfmId, vnfId, vimId, getVnfdIdFromModifyableAttributes(vnf), vnf, jobInfo.getJobId());
- OperationExecution terminationOperation = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdTerminatePost(vnfId, cbamRequest, NOKIA_LCM_API_VERSION).blockingFirst();
- OperationExecution finishedOperation = waitForOperationToFinish(vnfmId, vnfId, terminationOperation.getId());
- if (finishedOperation.getStatus() == FINISHED) {
- notificationManager.waitForTerminationToBeProcessed(finishedOperation.getId());
- deleteVnf(vnfmId, vnfId);
+ /**
+ * Terminates the VNF
+ * <ul>
+ * <li>fails if the VNF does not exist</li>
+ * <li>terminates if instantiated</li>
+ * <li>deletes the VNF</li>
+ * </ul>
+ *
+ * @param vnfmId the identifier of the VNFM
+ * @param vnfId the identifier of the VNF
+ * @param request the termination request
+ * @param httpResponse the HTTP response
+ * @return the job for polling the progress of the termination
+ */
+ public JobInfo terminate(String vnfmId, String vnfId, VnfTerminateRequest request, HttpServletResponse httpResponse) {
+ logOperationInput(vnfId, "termination", request);
+ return scheduleExecution(vnfId, httpResponse, "terminate", jobInfo -> terminateVnf(vnfmId, vnfId, request, jobInfo));
+ }
+ private void terminateVnf(String vnfmId, String vnfId, VnfTerminateRequest request, JobInfo jobInfo) {
+ TerminateVnfRequest cbamRequest = new TerminateVnfRequest();
+ setState(request, cbamRequest);
+ 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) {
+ String vimId = getVimIdFromInstantiationRequest(vnfmId, vnf);
+ grantManager.requestGrantForTerminate(vnfmId, vnfId, vimId, getVnfdIdFromModifyableAttributes(vnf), vnf, jobInfo.getJobId());
+ OperationExecution terminationOperation = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdTerminatePost(vnfId, cbamRequest, NOKIA_LCM_API_VERSION).blockingFirst();
+ OperationExecution finishedOperation = waitForOperationToFinish(vnfmId, vnfId, terminationOperation.getId());
+ if (finishedOperation.getStatus() == FINISHED) {
+ notificationManager.waitForTerminationToBeProcessed(finishedOperation.getId());
+ } else {
+ throw buildFatalFailure(logger, "Unable to terminate VNF the operation did not finish with success");
+ }
} else {
- logger.error("Unable to terminate VNF the operation did not finish with success");
+ logger.warn("The VNF with {} identifier is not instantiated no termination is required", vnfId);
+ }
+ }
+
+ private void setState(VnfTerminateRequest request, TerminateVnfRequest cbamRequest) {
+ if (request.getTerminationType() == null) {
+ cbamRequest.setTerminationType(TerminationType.FORCEFUL);
+ } else {
+ if (request.getTerminationType().equals(VnfTerminationType.GRACEFUL)) {
+ cbamRequest.setTerminationType(TerminationType.GRACEFUL);
+ cbamRequest.setGracefulTerminationTimeout(parseInt(request.getGracefulTerminationTimeout()));
+ } else {
+ cbamRequest.setTerminationType(TerminationType.FORCEFUL);
+ }
}
}
- private void deleteVnf(String vnfmId, String vnfId) {
+ /**
+ * Delete the VNF
+ *
+ * @param vnfmId the identifier of the VNFM
+ * @param vnfId the identifier fo the VNF
+ */
+ public void deleteVnf(String vnfmId, String vnfId) {
logger.info("Deleting VNF with {} identifier", vnfId);
cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdDelete(vnfId, NOKIA_LCM_API_VERSION).blockingFirst();
logger.info("The VNF with {} identifier has been deleted", vnfId);
@@ -450,10 +484,6 @@ public class LifecycleManager {
return childElement(childElement(root, "vims").getAsJsonArray().get(0).getAsJsonObject(), "id").getAsString();
}
- private String getVnfdIdFromModifyableAttributes(com.nokia.cbam.lcm.v32.model.VnfInfo vnf) {
- return find(vnf.getExtensions(), p -> p.getName().equals(ONAP_CSAR_ID)).getValue().toString();
- }
-
/**
* @param vnfmId the identifier of the VNFM
* @param vnfId the identifier of the VNF
@@ -462,23 +492,27 @@ public class LifecycleManager {
public VnfInfo queryVnf(String vnfmId, String vnfId) {
try {
com.nokia.cbam.lcm.v32.model.VnfInfo cbamVnfInfo = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdGet(vnfId, NOKIA_LCM_API_VERSION).blockingFirst();
- VnfInfo vnfInfo = new VnfInfo();
- vnfInfo.setVersion(cbamVnfInfo.getVnfSoftwareVersion());
- vnfInfo.setVnfInstanceId(vnfId);
- String onapCsarId = getVnfdIdFromModifyableAttributes(cbamVnfInfo);
- vnfInfo.setVnfdId(onapCsarId);
- vnfInfo.setVnfPackageId(onapCsarId);
- vnfInfo.setVnfInstanceDescription(cbamVnfInfo.getDescription());
- vnfInfo.setVnfInstanceName(cbamVnfInfo.getName());
- vnfInfo.setVnfProvider(cbamVnfInfo.getVnfProvider());
- vnfInfo.setVnfStatus("ACTIVE");
- vnfInfo.setVnfType("Kuku");
- return vnfInfo;
+ return convertVnfInfo(vnfId, cbamVnfInfo);
} catch (Exception e) {
throw buildFatalFailure(logger, "Unable to query VNF (" + vnfId + ")", e);
}
}
+ private VnfInfo convertVnfInfo(String vnfId, com.nokia.cbam.lcm.v32.model.VnfInfo cbamVnfInfo) {
+ VnfInfo vnfInfo = new VnfInfo();
+ vnfInfo.setVersion(cbamVnfInfo.getVnfSoftwareVersion());
+ vnfInfo.setVnfInstanceId(vnfId);
+ String onapCsarId = getVnfdIdFromModifyableAttributes(cbamVnfInfo);
+ vnfInfo.setVnfdId(onapCsarId);
+ vnfInfo.setVnfPackageId(onapCsarId);
+ vnfInfo.setVnfInstanceDescription(cbamVnfInfo.getDescription());
+ vnfInfo.setVnfInstanceName(cbamVnfInfo.getName());
+ vnfInfo.setVnfProvider(cbamVnfInfo.getVnfProvider());
+ vnfInfo.setVnfStatus("ACTIVE");
+ vnfInfo.setVnfType("Kuku");
+ return vnfInfo;
+ }
+
private ScaleDirection convert(org.onap.vnfmdriver.model.ScaleDirection direction) {
if (org.onap.vnfmdriver.model.ScaleDirection.IN.equals(direction)) {
return ScaleDirection.IN;
@@ -566,6 +600,16 @@ public class LifecycleManager {
});
}
+ public JobInfo customOperation(String vnfmId, String vnfId, String operationId, Object additionalParams, HttpServletResponse httpResponse) {
+ logOperationInput(vnfId, "custom", additionalParams);
+ return scheduleExecution(vnfId, httpResponse, "custom", job -> {
+ CustomOperationRequest cbamRequest = new CustomOperationRequest();
+ cbamRequest.setAdditionalParams(additionalParams);
+ OperationExecution operationExecution = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdCustomCustomOperationNamePost(vnfId, operationId, cbamRequest, NOKIA_LCM_API_VERSION).blockingFirst();
+ waitForOperationToFinish(vnfmId, vnfId, operationExecution.getId());
+ });
+ }
+
private JobInfo scheduleExecution(String vnfId, HttpServletResponse httpResponse, String operation, AsynchronousExecution asynchronExecution) {
JobInfo jobInfo = new JobInfo();
jobInfo.setJobId(jobManager.spawnJob(vnfId, httpResponse));
@@ -609,11 +653,16 @@ public class LifecycleManager {
public static class VnfCreationResult {
private final com.nokia.cbam.lcm.v32.model.VnfInfo vnfInfo;
+
private final String vnfdId;
- VnfCreationResult(com.nokia.cbam.lcm.v32.model.VnfInfo vnfInfo, String vnfdId) {
+ public VnfCreationResult(com.nokia.cbam.lcm.v32.model.VnfInfo vnfInfo, String vnfdId) {
this.vnfInfo = vnfInfo;
this.vnfdId = vnfdId;
}
+
+ public com.nokia.cbam.lcm.v32.model.VnfInfo getVnfInfo() {
+ return vnfInfo;
+ }
}
}