summaryrefslogtreecommitdiffstats
path: root/vnfm-simulator/vnfm-service/src
diff options
context:
space:
mode:
Diffstat (limited to 'vnfm-simulator/vnfm-service/src')
-rw-r--r--vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/controller/SvnfmController.java14
-rw-r--r--vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/repository/VnfmCacheRepository.java22
-rw-r--r--vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/InstantiateOperationProgressor.java123
-rw-r--r--vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/OperationProgressor.java119
-rw-r--r--vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/SvnfmService.java33
-rw-r--r--vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/TerminateOperationProgressor.java74
-rw-r--r--vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/VnfmHelper.java10
7 files changed, 274 insertions, 121 deletions
diff --git a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/controller/SvnfmController.java b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/controller/SvnfmController.java
index e6bc06374c..9c3a02d4e6 100644
--- a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/controller/SvnfmController.java
+++ b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/controller/SvnfmController.java
@@ -119,9 +119,12 @@ public class SvnfmController {
*/
@DeleteMapping(value = "/vnf_instances/{vnfInstanceId}")
@ResponseStatus(code = HttpStatus.OK)
- public InlineResponse201 deleteVnf(@PathVariable("vnfInstanceId") final String vnfId) {
+ public ResponseEntity<Void> deleteVnf(@PathVariable("vnfInstanceId") final String vnfId) {
LOGGER.info("Start deleting Vnf------");
- return vnfmCacheRepository.deleteVnf(vnfId);
+ vnfmCacheRepository.deleteVnf(vnfId);
+ final HttpHeaders headers = new HttpHeaders();
+ headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
+ return new ResponseEntity<>(headers, HttpStatus.NO_CONTENT);
}
/**
@@ -132,10 +135,11 @@ public class SvnfmController {
*/
@PostMapping(value = "/vnf_instances/{vnfInstanceId}/terminate")
public ResponseEntity<Object> terminateVnf(@PathVariable("vnfInstanceId") final String vnfId) {
- LOGGER.info("Start terminateVNFRequest");
+ LOGGER.info("Start terminateVNFRequest {}", vnfId);
final HttpHeaders headers = new HttpHeaders();
- headers.add("Content-Type", MediaType.APPLICATION_JSON);
- return new ResponseEntity<>(svnfmService.terminateVnf(vnfId), headers, HttpStatus.ACCEPTED);
+ headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
+ headers.add(HttpHeaders.LOCATION, svnfmService.terminateVnf(vnfId));
+ return new ResponseEntity<>(headers, HttpStatus.ACCEPTED);
}
diff --git a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/repository/VnfmCacheRepository.java b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/repository/VnfmCacheRepository.java
index 030b073da4..fbdbf744d0 100644
--- a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/repository/VnfmCacheRepository.java
+++ b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/repository/VnfmCacheRepository.java
@@ -20,16 +20,12 @@
package org.onap.svnfm.simulator.repository;
-import java.util.List;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.CreateVnfRequest;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201;
-import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201.InstantiationStateEnum;
-import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201InstantiatedVnfInfo;
-import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201VimConnectionInfo;
import org.onap.svnfm.simulator.constants.Constant;
import org.onap.svnfm.simulator.services.SvnfmService;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.cache.annotation.CachePut;
+import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;
@@ -49,15 +45,7 @@ public class VnfmCacheRepository {
return svnfmService.createVnf(createVnfRequest, id);
}
- @CachePut(value = Constant.IN_LINE_RESPONSE_201_CACHE, key = "#id")
- public InlineResponse201 updateVnf(final InlineResponse201InstantiatedVnfInfo instantiatedVnfInfo, final String id,
- final List<InlineResponse201VimConnectionInfo> vimConnectionInfo) {
- final InlineResponse201 vnf = getVnf(id);
- vnf.setInstantiatedVnfInfo(instantiatedVnfInfo);
- vnf.setInstantiationState(InstantiationStateEnum.INSTANTIATED);
- vnf.setVimConnectionInfo(vimConnectionInfo);
- return vnf;
- }
+
public InlineResponse201 getVnf(final String id) {
return svnfmService.getVnf(id);
@@ -67,8 +55,6 @@ public class VnfmCacheRepository {
* @param vnfId
* @return
*/
- public InlineResponse201 deleteVnf(final String vnfId) {
- // TODO
- return null;
- }
+ @CacheEvict(value = Constant.IN_LINE_RESPONSE_201_CACHE, key = "#id")
+ public void deleteVnf(final String id) {}
}
diff --git a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/InstantiateOperationProgressor.java b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/InstantiateOperationProgressor.java
new file mode 100644
index 0000000000..020fa0390d
--- /dev/null
+++ b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/InstantiateOperationProgressor.java
@@ -0,0 +1,123 @@
+package org.onap.svnfm.simulator.services;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import org.modelmapper.ModelMapper;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantsAddResources;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantsAddResources.TypeEnum;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.InlineResponse201;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.InlineResponse201AddResources;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.InlineResponse201VimConnections;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs.ChangeTypeEnum;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201.InstantiationStateEnum;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201InstantiatedVnfInfo;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201InstantiatedVnfInfoResourceHandle;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201InstantiatedVnfInfoVnfcResourceInfo;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201VimConnectionInfo;
+import org.onap.svnfm.simulator.config.ApplicationConfig;
+import org.onap.svnfm.simulator.model.VnfOperation;
+import org.onap.svnfm.simulator.model.Vnfds;
+import org.onap.svnfm.simulator.model.Vnfds.Vnfc;
+import org.onap.svnfm.simulator.model.Vnfds.Vnfd;
+import org.onap.svnfm.simulator.repository.VnfOperationRepository;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class InstantiateOperationProgressor extends OperationProgressor {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(InstantiateOperationProgressor.class);
+
+ public InstantiateOperationProgressor(final VnfOperation operation, final SvnfmService svnfmService,
+ final VnfOperationRepository vnfOperationRepository, final ApplicationConfig applicationConfig,
+ final Vnfds vnfds, final SubscriptionService subscriptionService) {
+ super(operation, svnfmService, vnfOperationRepository, applicationConfig, vnfds, subscriptionService);
+ }
+
+ @Override
+ protected List<GrantsAddResources> getAddResources(final String vnfdId) {
+ final List<GrantsAddResources> resources = new ArrayList<>();
+
+ for (final Vnfd vnfd : vnfds.getVnfdList()) {
+ if (vnfd.getVnfdId().equals(vnfdId)) {
+ for (final Vnfc vnfc : vnfd.getVnfcList()) {
+ final GrantsAddResources addResource = new GrantsAddResources();
+ vnfc.setGrantResourceId(UUID.randomUUID().toString());
+ addResource.setId(vnfc.getGrantResourceId());
+ addResource.setType(TypeEnum.fromValue(vnfc.getType()));
+ addResource.setResourceTemplateId(vnfc.getResourceTemplateId());
+ addResource.setVduId(vnfc.getVduId());
+ resources.add(addResource);
+ }
+ }
+ }
+ return resources;
+ }
+
+ @Override
+ protected List<GrantsAddResources> getRemoveResources(final String vnfdId) {
+ return Collections.emptyList();
+ }
+
+ @Override
+ protected List<InlineResponse201InstantiatedVnfInfoVnfcResourceInfo> handleGrantResponse(
+ final InlineResponse201 grantResponse) {
+ final InlineResponse201InstantiatedVnfInfo instantiatedVnfInfo = createInstantiatedVnfInfo(grantResponse);
+ svnfmService.updateVnf(InstantiationStateEnum.INSTANTIATED, instantiatedVnfInfo, operation.getVnfInstanceId(),
+ getVimConnections(grantResponse));
+ return instantiatedVnfInfo.getVnfcResourceInfo();
+ }
+
+ private InlineResponse201InstantiatedVnfInfo createInstantiatedVnfInfo(final InlineResponse201 grantResponse) {
+ final InlineResponse201InstantiatedVnfInfo instantiatedVnfInfo = new InlineResponse201InstantiatedVnfInfo();
+
+ final Map<String, String> mapOfGrantResourceIdToVimConnectionId = new HashMap<>();
+ for (final InlineResponse201AddResources addResource : grantResponse.getAddResources()) {
+ mapOfGrantResourceIdToVimConnectionId.put(addResource.getResourceDefinitionId(),
+ addResource.getVimConnectionId());
+ }
+ LOGGER.info("VIM connections in grant response: {}", mapOfGrantResourceIdToVimConnectionId);
+
+ for (final Vnfd vnfd : vnfds.getVnfdList()) {
+ if (vnfd.getVnfdId().equals(svnfmService.getVnf(operation.getVnfInstanceId()).getVnfdId())) {
+ for (final Vnfc vnfc : vnfd.getVnfcList()) {
+ final InlineResponse201InstantiatedVnfInfoVnfcResourceInfo vnfcResourceInfoItem =
+ new InlineResponse201InstantiatedVnfInfoVnfcResourceInfo();
+ vnfcResourceInfoItem.setId(vnfc.getVnfcId());
+ vnfcResourceInfoItem.setVduId(vnfc.getVduId());
+ final InlineResponse201InstantiatedVnfInfoResourceHandle computeResource =
+ new InlineResponse201InstantiatedVnfInfoResourceHandle();
+ computeResource.setResourceId(UUID.randomUUID().toString());
+ LOGGER.info("Checking for VIM connection id for : {}", vnfc.getGrantResourceId());
+ computeResource
+ .setVimConnectionId(mapOfGrantResourceIdToVimConnectionId.get(vnfc.getGrantResourceId()));
+
+ computeResource.setVimLevelResourceType("OS::Nova::Server");
+ vnfcResourceInfoItem.setComputeResource(computeResource);
+ instantiatedVnfInfo.addVnfcResourceInfoItem(vnfcResourceInfoItem);
+ }
+ }
+ }
+
+ return instantiatedVnfInfo;
+ }
+
+
+ private List<InlineResponse201VimConnectionInfo> getVimConnections(final InlineResponse201 grantResponse) {
+ final List<InlineResponse201VimConnectionInfo> vimConnectionInfo = new ArrayList<>();
+ for (final InlineResponse201VimConnections vimConnection : grantResponse.getVimConnections()) {
+ final ModelMapper modelMapper = new ModelMapper();
+ vimConnectionInfo.add(modelMapper.map(vimConnection, InlineResponse201VimConnectionInfo.class));
+ }
+ return vimConnectionInfo;
+ }
+
+ @Override
+ protected ChangeTypeEnum getVnfcChangeType() {
+ return ChangeTypeEnum.ADDED;
+ }
+
+}
diff --git a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/OperationProgressor.java b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/OperationProgressor.java
index d231e1b098..1e31ab2fdb 100644
--- a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/OperationProgressor.java
+++ b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/OperationProgressor.java
@@ -2,9 +2,7 @@ package org.onap.svnfm.simulator.services;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import java.util.UUID;
import javax.ws.rs.core.MediaType;
import org.apache.commons.codec.binary.Base64;
@@ -12,12 +10,9 @@ import org.modelmapper.ModelMapper;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.ApiResponse;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantRequest;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantsAddResources;
-import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantsAddResources.TypeEnum;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantsLinks;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantsLinksVnfLcmOpOcc;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.InlineResponse201;
-import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.InlineResponse201AddResources;
-import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.InlineResponse201VimConnections;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.ApiClient;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.ApiException;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.api.DefaultApi;
@@ -31,38 +26,32 @@ import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperatio
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification.OperationEnum;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification.OperationStateEnum;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200;
-import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201InstantiatedVnfInfo;
-import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201InstantiatedVnfInfoResourceHandle;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201InstantiatedVnfInfoVnfcResourceInfo;
-import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201VimConnectionInfo;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.SubscriptionsAuthenticationParamsBasic;
import org.onap.svnfm.simulator.config.ApplicationConfig;
import org.onap.svnfm.simulator.model.VnfOperation;
import org.onap.svnfm.simulator.model.Vnfds;
-import org.onap.svnfm.simulator.model.Vnfds.Vnfc;
-import org.onap.svnfm.simulator.model.Vnfds.Vnfd;
import org.onap.svnfm.simulator.repository.VnfOperationRepository;
-import org.onap.svnfm.simulator.repository.VnfmCacheRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class OperationProgressor implements Runnable {
+public abstract class OperationProgressor implements Runnable {
private static final Logger LOGGER = LoggerFactory.getLogger(OperationProgressor.class);
- private final VnfOperation operation;
- private final VnfmCacheRepository vnfRepository;
+ protected final VnfOperation operation;
+ protected final SvnfmService svnfmService;
private final VnfOperationRepository vnfOperationRepository;
private final ApplicationConfig applicationConfig;
- private final Vnfds vnfds;
+ protected final Vnfds vnfds;
private final SubscriptionService subscriptionService;
private final DefaultApi notificationClient;
private final org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.api.DefaultApi grantClient;
- public OperationProgressor(final VnfOperation operation, final VnfmCacheRepository vnfRepository,
+ public OperationProgressor(final VnfOperation operation, final SvnfmService svnfmService,
final VnfOperationRepository vnfOperationRepository, final ApplicationConfig applicationConfig,
final Vnfds vnfds, final SubscriptionService subscriptionService) {
this.operation = operation;
- this.vnfRepository = vnfRepository;
+ this.svnfmService = svnfmService;
this.vnfOperationRepository = vnfOperationRepository;
this.applicationConfig = applicationConfig;
this.vnfds = vnfds;
@@ -96,15 +85,15 @@ public class OperationProgressor implements Runnable {
final GrantRequest grantRequest = buildGrantRequest();
final InlineResponse201 grantResponse = sendGrantRequest(grantRequest);
- final InlineResponse201InstantiatedVnfInfo instantiatedVnfInfo = createInstantiatedVnfInfo(grantResponse);
- vnfRepository.updateVnf(instantiatedVnfInfo, operation.getVnfInstanceId(),
- getVimConnections(grantResponse));
+ final List<InlineResponse201InstantiatedVnfInfoVnfcResourceInfo> vnfcs = handleGrantResponse(grantResponse);
+
+ svnfmService.getVnf(operation.getVnfInstanceId()).getInstantiatedVnfInfo();
sleep(10000);
setState(InlineResponse200.OperationStateEnum.COMPLETED);
final VnfLcmOperationOccurrenceNotification notificationOfCompleted =
buildNotification(NotificationStatusEnum.RESULT, OperationStateEnum.COMPLETED);
- notificationOfCompleted.setAffectedVnfcs(getVnfcs(instantiatedVnfInfo.getVnfcResourceInfo()));
+ notificationOfCompleted.setAffectedVnfcs(getVnfcs(vnfcs));
sendNotification(notificationOfCompleted);
} catch (final Exception exception) {
@@ -136,6 +125,7 @@ public class OperationProgressor implements Runnable {
notification.setOperationState(operationState);
notification.setOperation(OperationEnum.fromValue(operation.getOperation().toString()));
notification.setVnfInstanceId(operation.getVnfInstanceId());
+ notification.setVnfLcmOpOccId(operation.getId());
final LcnVnfLcmOperationOccurrenceNotificationLinks links = new LcnVnfLcmOperationOccurrenceNotificationLinks();
final LcnVnfLcmOperationOccurrenceNotificationLinksVnfInstance vnfInstanceLink =
@@ -157,14 +147,16 @@ public class OperationProgressor implements Runnable {
private List<LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs> getVnfcs(
final List<InlineResponse201InstantiatedVnfInfoVnfcResourceInfo> instantiatedVnfcs) {
final List<LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs> vnfcs = new ArrayList<>();
- for (final InlineResponse201InstantiatedVnfInfoVnfcResourceInfo instantiatedVnfc : instantiatedVnfcs) {
- LOGGER.info("VNFC TO BE CONVERTED: {}", instantiatedVnfc);
- final ModelMapper mapper = new ModelMapper();
- final LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs vnfc =
- mapper.map(instantiatedVnfc, LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs.class);
- LOGGER.info("VNFC FROM CONVERSION: {}", vnfc);
- vnfc.setChangeType(ChangeTypeEnum.ADDED);
- vnfcs.add(vnfc);
+ if (instantiatedVnfcs != null) {
+ for (final InlineResponse201InstantiatedVnfInfoVnfcResourceInfo instantiatedVnfc : instantiatedVnfcs) {
+ LOGGER.info("VNFC TO BE CONVERTED: {}", instantiatedVnfc);
+ final ModelMapper mapper = new ModelMapper();
+ final LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs vnfc =
+ mapper.map(instantiatedVnfc, LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs.class);
+ LOGGER.info("VNFC FROM CONVERSION: {}", vnfc);
+ vnfc.setChangeType(getVnfcChangeType());
+ vnfcs.add(vnfc);
+ }
}
return vnfcs;
}
@@ -189,9 +181,10 @@ public class OperationProgressor implements Runnable {
public GrantRequest buildGrantRequest() {
final GrantRequest grantRequest = new GrantRequest();
grantRequest.setVnfInstanceId(operation.getVnfInstanceId());
- final String vnfdId = vnfRepository.getVnf(operation.getVnfInstanceId()).getVnfdId();
+ final String vnfdId = svnfmService.getVnf(operation.getVnfInstanceId()).getVnfdId();
grantRequest.setVnfdId(vnfdId);
grantRequest.setAddResources(getAddResources(vnfdId));
+ grantRequest.setRemoveResources(getRemoveResources(vnfdId));
grantRequest.setVnfLcmOpOccId(operation.getId());
grantRequest
.setOperation(org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantRequest.OperationEnum
@@ -209,24 +202,14 @@ public class OperationProgressor implements Runnable {
return grantRequest;
}
- private List<GrantsAddResources> getAddResources(final String vnfdId) {
- final List<GrantsAddResources> resources = new ArrayList<>();
-
- for (final Vnfd vnfd : vnfds.getVnfdList()) {
- if (vnfd.getVnfdId().equals(vnfdId)) {
- for (final Vnfc vnfc : vnfd.getVnfcList()) {
- final GrantsAddResources addResource = new GrantsAddResources();
- vnfc.setGrantResourceId(UUID.randomUUID().toString());
- addResource.setId(vnfc.getGrantResourceId());
- addResource.setType(TypeEnum.fromValue(vnfc.getType()));
- addResource.setResourceTemplateId(vnfc.getResourceTemplateId());
- addResource.setVduId(vnfc.getVduId());
- resources.add(addResource);
- }
- }
- }
- return resources;
- }
+ protected abstract List<GrantsAddResources> getAddResources(final String vnfdId);
+
+ protected abstract List<GrantsAddResources> getRemoveResources(final String vnfdId);
+
+ protected abstract List<InlineResponse201InstantiatedVnfInfoVnfcResourceInfo> handleGrantResponse(
+ InlineResponse201 grantResponse);
+
+ protected abstract ChangeTypeEnum getVnfcChangeType();
private InlineResponse201 sendGrantRequest(final GrantRequest grantRequest) {
LOGGER.info("Sending grant request: {}", grantRequest);
@@ -241,46 +224,6 @@ public class OperationProgressor implements Runnable {
}
}
- private InlineResponse201InstantiatedVnfInfo createInstantiatedVnfInfo(final InlineResponse201 grantResponse) {
- final InlineResponse201InstantiatedVnfInfo instantiatedVnfInfo = new InlineResponse201InstantiatedVnfInfo();
-
- final Map<String, String> mapOfGrantResourceIdToVimConnectionId = new HashMap<>();
- for (final InlineResponse201AddResources addResource : grantResponse.getAddResources()) {
- mapOfGrantResourceIdToVimConnectionId.put(addResource.getResourceDefinitionId(),
- addResource.getVimConnectionId());
- }
-
- for (final Vnfd vnfd : vnfds.getVnfdList()) {
- if (vnfd.getVnfdId().equals(vnfRepository.getVnf(operation.getVnfInstanceId()).getVnfdId())) {
- for (final Vnfc vnfc : vnfd.getVnfcList()) {
- final InlineResponse201InstantiatedVnfInfoVnfcResourceInfo vnfcResourceInfoItem =
- new InlineResponse201InstantiatedVnfInfoVnfcResourceInfo();
- vnfcResourceInfoItem.setId(vnfc.getVnfcId());
- vnfcResourceInfoItem.setVduId(vnfc.getVduId());
- final InlineResponse201InstantiatedVnfInfoResourceHandle computeResource =
- new InlineResponse201InstantiatedVnfInfoResourceHandle();
- computeResource.setResourceId(UUID.randomUUID().toString());
- computeResource
- .setVimConnectionId(mapOfGrantResourceIdToVimConnectionId.get(vnfc.getGrantResourceId()));
- computeResource.setVimLevelResourceType("OS::Nova::Server");
- vnfcResourceInfoItem.setComputeResource(computeResource);
- instantiatedVnfInfo.addVnfcResourceInfoItem(vnfcResourceInfoItem);
- }
- }
- }
-
- return instantiatedVnfInfo;
- }
-
- private List<InlineResponse201VimConnectionInfo> getVimConnections(final InlineResponse201 grantResponse) {
- final List<InlineResponse201VimConnectionInfo> vimConnectionInfo = new ArrayList<>();
- for (final InlineResponse201VimConnections vimConnection : grantResponse.getVimConnections()) {
- final ModelMapper modelMapper = new ModelMapper();
- vimConnectionInfo.add(modelMapper.map(vimConnection, InlineResponse201VimConnectionInfo.class));
- }
- return vimConnectionInfo;
- }
-
private String getVnfLink() {
return getLinkBaseUrl() + "/vnf_instances/" + operation.getVnfInstanceId();
}
diff --git a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/SvnfmService.java b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/SvnfmService.java
index cac5075682..21bb00dba7 100644
--- a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/SvnfmService.java
+++ b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/SvnfmService.java
@@ -21,6 +21,7 @@
package org.onap.svnfm.simulator.services;
import java.lang.reflect.InvocationTargetException;
+import java.util.List;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -28,6 +29,9 @@ import org.modelmapper.ModelMapper;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.CreateVnfRequest;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201.InstantiationStateEnum;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201InstantiatedVnfInfo;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201VimConnectionInfo;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InstantiateVnfRequest;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.LccnSubscriptionRequest;
import org.onap.svnfm.simulator.config.ApplicationConfig;
@@ -38,13 +42,13 @@ import org.onap.svnfm.simulator.model.Vnfds;
import org.onap.svnfm.simulator.notifications.VnfInstantiationNotification;
import org.onap.svnfm.simulator.notifications.VnfmAdapterCreationNotification;
import org.onap.svnfm.simulator.repository.VnfOperationRepository;
-import org.onap.svnfm.simulator.repository.VnfmCacheRepository;
import org.onap.svnfm.simulator.repository.VnfmRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
+import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.support.SimpleValueWrapper;
import org.springframework.stereotype.Service;
@@ -60,9 +64,6 @@ public class SvnfmService {
VnfmRepository vnfmRepository;
@Autowired
- VnfmCacheRepository vnfRepository;
-
- @Autowired
VnfOperationRepository vnfOperationRepository;
@Autowired
@@ -104,6 +105,17 @@ public class SvnfmService {
return inlineResponse201;
}
+ @CachePut(value = Constant.IN_LINE_RESPONSE_201_CACHE, key = "#id")
+ public InlineResponse201 updateVnf(final InstantiationStateEnum instantiationState,
+ final InlineResponse201InstantiatedVnfInfo instantiatedVnfInfo, final String id,
+ final List<InlineResponse201VimConnectionInfo> vimConnectionInfo) {
+ final InlineResponse201 vnf = getVnf(id);
+ vnf.setInstantiatedVnfInfo(instantiatedVnfInfo);
+ vnf.setInstantiationState(instantiationState);
+ vnf.setVimConnectionInfo(vimConnectionInfo);
+ return vnf;
+ }
+
/**
*
* @param vnfId
@@ -114,8 +126,8 @@ public class SvnfmService {
public String instantiateVnf(final String vnfId, final InstantiateVnfRequest instantiateVNFRequest) {
final VnfOperation vnfOperation = buildVnfOperation(InlineResponse200.OperationEnum.INSTANTIATE, vnfId);
vnfOperationRepository.save(vnfOperation);
- executor.submit(new OperationProgressor(vnfOperation, vnfRepository, vnfOperationRepository, applicationConfig,
- vnfds, subscriptionService));
+ executor.submit(new InstantiateOperationProgressor(vnfOperation, this, vnfOperationRepository,
+ applicationConfig, vnfds, subscriptionService));
return vnfOperation.getId();
}
@@ -173,9 +185,12 @@ public class SvnfmService {
* @param vnfId
* @return
*/
- public Object terminateVnf(final String vnfId) {
- // TODO
- return null;
+ public String terminateVnf(final String vnfId) {
+ final VnfOperation vnfOperation = buildVnfOperation(InlineResponse200.OperationEnum.TERMINATE, vnfId);
+ vnfOperationRepository.save(vnfOperation);
+ executor.submit(new TerminateOperationProgressor(vnfOperation, this, vnfOperationRepository, applicationConfig,
+ vnfds, subscriptionService));
+ return vnfOperation.getId();
}
public void registerSubscription(final LccnSubscriptionRequest subscription) {
diff --git a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/TerminateOperationProgressor.java b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/TerminateOperationProgressor.java
new file mode 100644
index 0000000000..c829be9a4f
--- /dev/null
+++ b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/TerminateOperationProgressor.java
@@ -0,0 +1,74 @@
+package org.onap.svnfm.simulator.services;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantsAddResources;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantsAddResources.TypeEnum;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantsResource;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.InlineResponse201;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs.ChangeTypeEnum;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201.InstantiationStateEnum;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201InstantiatedVnfInfoResourceHandle;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201InstantiatedVnfInfoVnfcResourceInfo;
+import org.onap.svnfm.simulator.config.ApplicationConfig;
+import org.onap.svnfm.simulator.model.VnfOperation;
+import org.onap.svnfm.simulator.model.Vnfds;
+import org.onap.svnfm.simulator.repository.VnfOperationRepository;
+
+public class TerminateOperationProgressor extends OperationProgressor {
+
+ public TerminateOperationProgressor(final VnfOperation operation, final SvnfmService svnfmService,
+ final VnfOperationRepository vnfOperationRepository, final ApplicationConfig applicationConfig,
+ final Vnfds vnfds, final SubscriptionService subscriptionService) {
+ super(operation, svnfmService, vnfOperationRepository, applicationConfig, vnfds, subscriptionService);
+ }
+
+ @Override
+ protected List<GrantsAddResources> getAddResources(final String vnfdId) {
+ return Collections.emptyList();
+ }
+
+ @Override
+ protected List<GrantsAddResources> getRemoveResources(final String vnfdId) {
+ final List<GrantsAddResources> resources = new ArrayList<>();
+
+ final org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201 vnf =
+ svnfmService.getVnf(operation.getVnfInstanceId());
+ for (final InlineResponse201InstantiatedVnfInfoVnfcResourceInfo vnfc : vnf.getInstantiatedVnfInfo()
+ .getVnfcResourceInfo()) {
+ final GrantsAddResources addResource = new GrantsAddResources();
+ addResource.setId(UUID.randomUUID().toString());
+ addResource.setType(TypeEnum.COMPUTE);
+ addResource.setVduId(vnfc.getVduId());
+ final GrantsResource resource = new GrantsResource();
+
+ final InlineResponse201InstantiatedVnfInfoResourceHandle computeResource = vnfc.getComputeResource();
+ resource.setResourceId(computeResource.getResourceId());
+ resource.setVimConnectionId(computeResource.getVimConnectionId());
+ resource.setVimLevelResourceType(computeResource.getVimLevelResourceType());
+ addResource.setResource(resource);
+ resources.add(addResource);
+
+ }
+ return resources;
+ }
+
+ @Override
+ protected List<InlineResponse201InstantiatedVnfInfoVnfcResourceInfo> handleGrantResponse(
+ final InlineResponse201 grantResponse) {
+ final List<InlineResponse201InstantiatedVnfInfoVnfcResourceInfo> vnfcs =
+ svnfmService.getVnf(operation.getVnfInstanceId()).getInstantiatedVnfInfo().getVnfcResourceInfo();
+ svnfmService.updateVnf(InstantiationStateEnum.NOT_INSTANTIATED, null, operation.getVnfInstanceId(), null);
+ return vnfcs;
+ }
+
+ @Override
+ protected ChangeTypeEnum getVnfcChangeType() {
+ return ChangeTypeEnum.REMOVED;
+ }
+
+
+
+}
diff --git a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/VnfmHelper.java b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/VnfmHelper.java
index 7c038b823f..60b251c4d4 100644
--- a/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/VnfmHelper.java
+++ b/vnfm-simulator/vnfm-service/src/main/java/org/onap/svnfm/simulator/services/VnfmHelper.java
@@ -21,6 +21,8 @@
package org.onap.svnfm.simulator.services;
import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.Map;
import org.apache.commons.beanutils.BeanUtils;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.CreateVnfRequest;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201;
@@ -74,11 +76,17 @@ public class VnfmHelper {
inlineResponse201.setVnfdVersion(Constant.VNFD_VERSION);
inlineResponse201.setVnfSoftwareVersion(Constant.VNF_SOFTWARE_VERSION);
inlineResponse201.setInstantiationState(InstantiationStateEnum.NOT_INSTANTIATED);
- inlineResponse201.setVnfConfigurableProperties(Constant.VNF_CONFIG_PROPERTIES);
+ inlineResponse201.setVnfConfigurableProperties(getConfigProperties());
addAdditionalPRopertyInlineResponse201(inlineResponse201);
return inlineResponse201;
}
+ private Map<String, String> getConfigProperties() {
+ final Map<String, String> configProperties = new HashMap<>();
+ configProperties.put("ipAddress", "10.11.12.13");
+ return configProperties;
+ }
+
private void addAdditionalPRopertyInlineResponse201(final InlineResponse201 inlineResponse201) {
final InlineResponse201LinksSelf VnfInstancesLinksSelf = new InlineResponse201LinksSelf();
VnfInstancesLinksSelf