use of org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest in project so by onap.
the class VnfAdapterCreateTasksTest method test_createVolumeGroupRequest.
@Test
public void test_createVolumeGroupRequest() throws Exception {
RequestContext requestContext = setRequestContext();
ServiceInstance serviceInstance = setServiceInstance();
GenericVnf genericVnf = setGenericVnf();
VfModule vfModule = setVfModule();
vfModule.setSelflink("vfModuleSelfLink");
VolumeGroup volumeGroup = setVolumeGroup();
volumeGroup.setOrchestrationStatus(OrchestrationStatus.ASSIGNED);
CloudRegion cloudRegion = setCloudRegion();
OrchestrationContext orchestrationContext = setOrchestrationContext();
orchestrationContext.setIsRollbackEnabled(true);
String sdncVnfQueryResponse = "SDNCVnfQueryResponse";
execution.setVariable("SDNCQueryResponse_" + vfModule.getVfModuleId(), sdncVnfQueryResponse);
CreateVolumeGroupRequest request = new CreateVolumeGroupRequest();
request.setVolumeGroupId("volumeGroupStackId");
when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(genericVnf);
when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VOLUME_GROUP_ID))).thenReturn(volumeGroup);
when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule);
doReturn(request).when(vnfAdapterVolumeGroupResources).createVolumeGroupRequest(requestContext, cloudRegion, orchestrationContext, serviceInstance, genericVnf, volumeGroup, sdncVnfQueryResponse);
vnfAdapterCreateTasks.createVolumeGroupRequest(execution);
verify(vnfAdapterVolumeGroupResources, times(1)).createVolumeGroupRequest(requestContext, cloudRegion, orchestrationContext, serviceInstance, genericVnf, volumeGroup, sdncVnfQueryResponse);
assertEquals(request.toXmlString(), execution.getVariable("VNFREST_Request"));
}
use of org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest in project so by onap.
the class VnfAdapterObjectMapperTest method test_createVolumeGroupRequestMapper_for_alaCarte_flow.
@Test
public void test_createVolumeGroupRequestMapper_for_alaCarte_flow() throws Exception {
RequestContext requestContext = new RequestContext();
requestContext.setMsoRequestId("msoRequestId");
ServiceInstance serviceInstance = new ServiceInstance();
serviceInstance.setServiceInstanceId("serviceInstanceId");
ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance();
modelInfoServiceInstance.setModelVersion("modelVersion");
serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance);
GenericVnf genericVnf = new GenericVnf();
genericVnf.setVnfId("vnfId");
genericVnf.setVnfName("vnfName");
genericVnf.setVnfType("vnfType");
serviceInstance.getVnfs().add(genericVnf);
ModelInfoVfModule modelInfoVfModule = new ModelInfoVfModule();
modelInfoVfModule.setModelName("modelName");
modelInfoVfModule.setModelCustomizationUUID("modelCustomizationUUID");
VolumeGroup volumeGroup = new VolumeGroup();
volumeGroup.setVolumeGroupId("volumeGroupId");
volumeGroup.setVolumeGroupName("volumeGroupName");
volumeGroup.setOrchestrationStatus(OrchestrationStatus.ASSIGNED);
volumeGroup.setModelInfoVfModule(modelInfoVfModule);
serviceInstance.getVnfs().get(0).getVolumeGroups().add(volumeGroup);
CloudRegion cloudRegion = new CloudRegion();
cloudRegion.setLcpCloudRegionId("lcpCloudRegionId");
cloudRegion.setTenantId("tenantId");
OrchestrationContext orchestrationContext = new OrchestrationContext();
orchestrationContext.setIsRollbackEnabled(true);
CreateVolumeGroupRequest expectedCreateVolumeGroupRequest = new CreateVolumeGroupRequest();
expectedCreateVolumeGroupRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
expectedCreateVolumeGroupRequest.setTenantId(cloudRegion.getTenantId());
expectedCreateVolumeGroupRequest.setVolumeGroupId(volumeGroup.getVolumeGroupId());
expectedCreateVolumeGroupRequest.setVolumeGroupName(volumeGroup.getVolumeGroupName());
expectedCreateVolumeGroupRequest.setVnfType(genericVnf.getVnfType());
expectedCreateVolumeGroupRequest.setVnfVersion(serviceInstance.getModelInfoServiceInstance().getModelVersion());
expectedCreateVolumeGroupRequest.setVfModuleType(volumeGroup.getModelInfoVfModule().getModelName());
expectedCreateVolumeGroupRequest.setModelCustomizationUuid(volumeGroup.getModelInfoVfModule().getModelCustomizationUUID());
Map<String, Object> volumeGroupParams = new HashMap<>();
volumeGroupParams.put("vnf_id", genericVnf.getVnfId());
volumeGroupParams.put("vnf_name", genericVnf.getVnfName());
volumeGroupParams.put("vf_module_id", volumeGroup.getVolumeGroupId());
volumeGroupParams.put("vf_module_name", volumeGroup.getVolumeGroupName());
expectedCreateVolumeGroupRequest.setVolumeGroupParams(volumeGroupParams);
expectedCreateVolumeGroupRequest.setSkipAAI(true);
expectedCreateVolumeGroupRequest.setSuppressBackout(Boolean.TRUE.equals(orchestrationContext.getIsRollbackEnabled()));
expectedCreateVolumeGroupRequest.setFailIfExists(false);
MsoRequest msoRequest = new MsoRequest();
msoRequest.setRequestId(requestContext.getMsoRequestId());
msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId());
expectedCreateVolumeGroupRequest.setMsoRequest(msoRequest);
expectedCreateVolumeGroupRequest.setMessageId("messageId");
expectedCreateVolumeGroupRequest.setNotificationUrl("endpoint/VNFAResponse/messageId");
doReturn("endpoint/").when(vnfAdapterObjectMapper).getProperty(isA(String.class));
doReturn("messageId").when(vnfAdapterObjectMapper).getRandomUuid();
CreateVolumeGroupRequest actualCreateVolumeGroupRequest = vnfAdapterObjectMapper.createVolumeGroupRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, genericVnf, volumeGroup, null);
assertThat(actualCreateVolumeGroupRequest, sameBeanAs(expectedCreateVolumeGroupRequest));
}
use of org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest in project so by onap.
the class VnfAdapterVolumeGroupResourcesTest method test_createVolumeGroup.
@Test
public void test_createVolumeGroup() throws Exception {
volumeGroup.setOrchestrationStatus(OrchestrationStatus.ASSIGNED);
CreateVolumeGroupRequest createVolumeGroupRequest = new CreateVolumeGroupRequest();
createVolumeGroupRequest.setCloudSiteId("cloudSiteId");
CreateVolumeGroupResponse expectedCreateVolumeGroupResponse = new CreateVolumeGroupResponse();
expectedCreateVolumeGroupResponse.setVolumeGroupStackId("volumeGroupStackId");
expectedCreateVolumeGroupResponse.setVolumeGroupCreated(true);
String sdncVfModuleQueryResponse = "sdncVfModuleQueryResponse";
doReturn(createVolumeGroupRequest).when(MOCK_vnfAdapterObjectMapper).createVolumeGroupRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, genericVnf, volumeGroup, sdncVfModuleQueryResponse);
CreateVolumeGroupRequest actualCreateVolumeGroupResponse = vnfAdapterVolumeGroupResources.createVolumeGroupRequest(requestContext, cloudRegion, orchestrationContext, serviceInstance, genericVnf, volumeGroup, sdncVfModuleQueryResponse);
verify(MOCK_vnfAdapterObjectMapper, times(1)).createVolumeGroupRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, genericVnf, volumeGroup, sdncVfModuleQueryResponse);
assertThat(createVolumeGroupRequest, Matchers.sameBeanAs(actualCreateVolumeGroupResponse));
}
use of org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest in project so by onap.
the class PollService method executeExternalTask.
public void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) {
mdcSetup.setupMDC(externalTask);
logger.debug("Starting External Task Poll Service");
Map<String, Object> variables = new HashMap<>();
MutableBoolean success = new MutableBoolean();
String errorMessage = null;
Optional<String> response = Optional.empty();
boolean isMulticloud = false;
try {
String xmlRequest = externalTask.getVariable("openstackAdapterTaskRequest");
if (xmlRequest != null) {
Optional<String> requestType = findRequestType(xmlRequest);
if ("createVolumeGroupRequest".equals(requestType.get())) {
CreateVolumeGroupRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateVolumeGroupRequest.class);
isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId());
response = determineCreateVolumeGroupStatus(req, externalTask, success, isMulticloud);
} else if ("createVfModuleRequest".equals(requestType.get())) {
CreateVfModuleRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateVfModuleRequest.class);
isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId());
response = determineCreateVfModuleStatus(req, externalTask, success, isMulticloud);
} else if ("deleteVfModuleRequest".equals(requestType.get())) {
logger.debug("Executing External Task Poll Service for Delete Vf Module");
String stackId = externalTask.getVariable("stackId");
DeleteVfModuleRequest req = JAXB.unmarshal(new StringReader(xmlRequest), DeleteVfModuleRequest.class);
isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId());
if (!isMulticloud) {
int timeoutMinutes = msoHeatUtils.getVfHeatTimeoutValue(req.getModelCustomizationUuid(), false);
StackInfo stack = pollDeleteResource(timeoutMinutes, req.getCloudSiteId(), req.getTenantId(), stackId, success);
DeleteVfModuleResponse deleteResponse = new DeleteVfModuleResponse(req.getVnfId(), req.getVfModuleId(), Boolean.TRUE, req.getMessageId(), vnfAdapterImpl.copyStringOutputs(stack.getOutputs()));
response = Optional.of(deleteResponse.toXmlString());
}
} else if ("deleteVolumeGroupRequest".equals(requestType.get())) {
logger.debug("Executing External Task Poll Service for Delete Volume Group");
String stackId = externalTask.getVariable("stackId");
DeleteVolumeGroupRequest req = JAXB.unmarshal(new StringReader(xmlRequest), DeleteVolumeGroupRequest.class);
isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId());
if (!isMulticloud) {
pollDeleteResource(118, req.getCloudSiteId(), req.getTenantId(), stackId, success);
DeleteVolumeGroupResponse deleteResponse = new DeleteVolumeGroupResponse(true, req.getMessageId());
response = Optional.of(deleteResponse.toXmlString());
}
} else if ("createNetworkRequest".equals(requestType.get())) {
CreateNetworkRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateNetworkRequest.class);
response = determineCreateNetworkStatus(req, externalTask, success);
} else if ("deleteNetworkRequest".equals(requestType.get())) {
logger.debug("Executing External Task Poll Service for Delete Network");
String stackId = externalTask.getVariable("stackId");
DeleteNetworkRequest req = JAXB.unmarshal(new StringReader(xmlRequest), DeleteNetworkRequest.class);
pollDeleteResource(118, req.getCloudSiteId(), req.getTenantId(), stackId, success);
DeleteNetworkResponse deleteResponse = new DeleteNetworkResponse(req.getNetworkId(), true, req.getMessageId());
response = Optional.of(deleteResponse.toXmlString());
} else if ("updateNetworkRequest".equals(requestType.get())) {
UpdateNetworkRequest req = JAXB.unmarshal(new StringReader(xmlRequest), UpdateNetworkRequest.class);
pollUpdateResource(req.getCloudSiteId(), req.getTenantId(), externalTask, success);
UpdateNetworkResponse updateResponse = new UpdateNetworkResponse(req.getNetworkId(), null, null, req.getMessageId());
response = Optional.of(updateResponse.toXmlString());
} else if ("rollbackNetworkRequest".equals(requestType.get())) {
logger.debug("Executing External Task Poll Service for Rollback Network");
String stackId = externalTask.getVariable("stackId");
RollbackNetworkRequest req = JAXB.unmarshal(new StringReader(xmlRequest), RollbackNetworkRequest.class);
pollDeleteResource(118, req.getNetworkRollback().getCloudId(), req.getNetworkRollback().getTenantId(), stackId, success);
}
}
} catch (Exception e) {
logger.error("Error during External Task Poll Service", e);
errorMessage = e.toString();
variables.put("openstackAdapterErrorMessage", errorMessage);
}
if (isMulticloud) {
success.setTrue();
}
if (response.isPresent()) {
variables.put("WorkflowResponse", response.get());
}
variables.put("OpenstackPollSuccess", success.booleanValue());
if (success.isTrue()) {
externalTaskService.complete(externalTask, variables);
logger.debug("The External Task Id: {} Successful", externalTask.getId());
} else {
if (externalTask.getRetries() == null) {
logger.debug("The External Task Id: {} Failed, Setting Retries to Default Start Value: {}", externalTask.getId(), getRetrySequence().length);
externalTaskService.handleFailure(externalTask, "errorMessage", "errorDetails", getRetrySequence().length, 10000);
} else if (externalTask.getRetries() != null && externalTask.getRetries() - 1 == 0) {
logger.debug("The External Task Id: {} Failed, All Retries Exhausted", externalTask.getId());
externalTaskService.complete(externalTask, variables);
} else {
logger.debug("The External Task Id: {} Failed, Decrementing Retries: {} , Retry Delay: {}", externalTask.getId(), externalTask.getRetries() - 1, calculateRetryDelay(externalTask.getRetries()));
externalTaskService.handleFailure(externalTask, "errorMessage", "errorDetails", externalTask.getRetries() - 1, calculateRetryDelay(externalTask.getRetries()));
}
}
}
use of org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest in project so by onap.
the class RollbackService method executeExternalTask.
public void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) {
mdcSetup.setupMDC(externalTask);
logger.debug("Starting External Task Rollback Service");
Map<String, Object> variables = new HashMap<>();
boolean success = false;
boolean pollRollbackStatus = false;
try {
String xmlRequest = externalTask.getVariable("openstackAdapterTaskRequest");
if (xmlRequest != null) {
Optional<String> requestType = findRequestType(xmlRequest);
if ("createVolumeGroupRequest".equals(requestType.get())) {
logger.debug("Executing External Task Rollback Service for Create Volume Group");
CreateVolumeGroupRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateVolumeGroupRequest.class);
boolean isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId());
if (!isMulticloud) {
vnfAdapterImpl.deleteVfModule(req.getCloudSiteId(), req.getCloudOwner(), req.getTenantId(), req.getVolumeGroupName(), null, req.getMsoRequest(), new Holder<>());
pollRollbackStatus = true;
success = true;
} else {
vnfPluginImpl.deleteVnf(req.getCloudSiteId(), req.getCloudOwner(), req.getTenantId(), req.getVolumeGroupName(), req.getMsoRequest());
pollRollbackStatus = false;
success = true;
}
} else if ("createVfModuleRequest".equals(requestType.get())) {
logger.debug("Executing External Task Rollback Service for Create Vf Module");
CreateVfModuleRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateVfModuleRequest.class);
boolean isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId());
if (!isMulticloud) {
vnfAdapterImpl.deleteVfModule(req.getCloudSiteId(), req.getCloudOwner(), req.getTenantId(), req.getVfModuleName(), req.getModelCustomizationUuid(), req.getMsoRequest(), new Holder<>());
pollRollbackStatus = true;
success = true;
} else {
pollRollbackStatus = false;
success = true;
}
} else if ("createNetworkRequest".equals(requestType.get())) {
logger.debug("Executing External Task Rollback Service for Create Network");
CreateNetworkRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateNetworkRequest.class);
networkAdapterImpl.deleteNetwork(req.getCloudSiteId(), req.getTenantId(), req.getNetworkType(), req.getModelCustomizationUuid(), req.getNetworkName(), req.getMsoRequest());
pollRollbackStatus = true;
success = true;
}
}
} catch (Exception e) {
logger.error("Error during External Task Rollback Service", e);
}
variables.put("OpenstackRollbackSuccess", success);
variables.put("rollbackPerformed", true);
variables.put("PollRollbackStatus", pollRollbackStatus);
if (success) {
externalTaskService.complete(externalTask, variables);
logger.debug("The External Task Id: {} Successful", externalTask.getId());
} else {
logger.debug("The External Task Id: {} Failed. Not Retrying", externalTask.getId());
externalTaskService.complete(externalTask, variables);
}
}
Aggregations