use of org.onap.so.adapters.vnfrest.DeleteVolumeGroupResponse in project so by onap.
the class VnfAdapterImpl method postProcessVnfAdapter.
public void postProcessVnfAdapter(BuildingBlockExecution execution) {
try {
String vnfAdapterResponse = execution.getVariable("WorkflowResponse");
if (!StringUtils.isEmpty(vnfAdapterResponse)) {
Object vnfRestResponse = unMarshal(vnfAdapterResponse);
if (vnfRestResponse instanceof CreateVfModuleResponse) {
VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
String heatStackId = ((CreateVfModuleResponse) vnfRestResponse).getVfModuleStackId();
if (!StringUtils.isEmpty(heatStackId)) {
vfModule.setHeatStackId(heatStackId);
execution.setVariable(HEAT_STACK_ID, heatStackId);
}
Map<String, String> vfModuleOutputs = ((CreateVfModuleResponse) vnfRestResponse).getVfModuleOutputs();
if (vfModuleOutputs != null) {
processVfModuleOutputs(execution, vfModuleOutputs);
}
} else if (vnfRestResponse instanceof DeleteVfModuleResponse) {
VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
Boolean vfModuleDelete = ((DeleteVfModuleResponse) vnfRestResponse).getVfModuleDeleted();
if (null != vfModuleDelete && vfModuleDelete) {
vfModule.setHeatStackId(null);
execution.setVariable(HEAT_STACK_ID, null);
Map<String, String> vfModuleOutputs = ((DeleteVfModuleResponse) vnfRestResponse).getVfModuleOutputs();
if (vfModuleOutputs != null) {
processVfModuleOutputs(execution, vfModuleOutputs);
if (execution.getVariable(OAM_MANAGEMENT_V4_ADDRESS) != null) {
genericVnf.setIpv4OamAddress("");
execution.setVariable(OAM_MANAGEMENT_V4_ADDRESS, "");
}
if (execution.getVariable(OAM_MANAGEMENT_V6_ADDRESS) != null) {
genericVnf.setManagementV6Address("");
execution.setVariable(OAM_MANAGEMENT_V6_ADDRESS, "");
}
if (execution.getVariable(CONTRAIL_SERVICE_INSTANCE_FQDN) != null) {
vfModule.setContrailServiceInstanceFqdn("");
execution.setVariable(CONTRAIL_SERVICE_INSTANCE_FQDN, "");
}
}
}
} else if (vnfRestResponse instanceof CreateVolumeGroupResponse) {
VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID);
String heatStackId = ((CreateVolumeGroupResponse) vnfRestResponse).getVolumeGroupStackId();
if (!StringUtils.isEmpty(heatStackId)) {
volumeGroup.setHeatStackId(heatStackId);
execution.setVariable(HEAT_STACK_ID, heatStackId);
} else {
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "HeatStackId is missing from create VolumeGroup Vnf Adapter response.");
}
} else if (vnfRestResponse instanceof DeleteVolumeGroupResponse) {
VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID);
Boolean volumeGroupDelete = ((DeleteVolumeGroupResponse) vnfRestResponse).getVolumeGroupDeleted();
if (null != volumeGroupDelete && volumeGroupDelete) {
volumeGroup.setHeatStackId(null);
execution.setVariable(HEAT_STACK_ID, null);
}
}
}
} catch (Exception ex) {
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
}
}
use of org.onap.so.adapters.vnfrest.DeleteVolumeGroupResponse in project so by onap.
the class VnfVolumeAdapterClientIT method deleteVolumeGroupTestThrowException.
@Test(expected = VnfAdapterClientException.class)
public void deleteVolumeGroupTestThrowException() throws VnfAdapterClientException {
DeleteVolumeGroupRequest request = new DeleteVolumeGroupRequest();
request.setCloudSiteId(TESTING_ID);
DeleteVolumeGroupResponse mockResponse = new DeleteVolumeGroupResponse();
mockResponse.setVolumeGroupDeleted(true);
VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class);
AdapterRestClient mockClient = mock(AdapterRestClient.class);
doReturn(mockClient).when(client).getAdapterRestClient("/" + AAI_VOLUME_GROUP_ID);
when(mockClient.delete(request, DeleteVolumeGroupResponse.class)).thenThrow(new InternalServerErrorException("Error in delete volume group"));
MockitoAnnotations.initMocks(this);
client.deleteVNFVolumes(AAI_VOLUME_GROUP_ID, request);
}
use of org.onap.so.adapters.vnfrest.DeleteVolumeGroupResponse in project so by onap.
the class VnfVolumeAdapterClientIT method deleteVolumeGroupTest.
@Test
public void deleteVolumeGroupTest() throws VnfAdapterClientException {
DeleteVolumeGroupRequest request = new DeleteVolumeGroupRequest();
request.setCloudSiteId(TESTING_ID);
DeleteVolumeGroupResponse mockResponse = new DeleteVolumeGroupResponse();
mockResponse.setVolumeGroupDeleted(true);
VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class);
AdapterRestClient mockClient = mock(AdapterRestClient.class);
doReturn(mockClient).when(client).getAdapterRestClient("/" + AAI_VOLUME_GROUP_ID);
when(mockClient.delete(request, DeleteVolumeGroupResponse.class)).thenReturn(mockResponse);
MockitoAnnotations.initMocks(this);
DeleteVolumeGroupResponse response = client.deleteVNFVolumes(AAI_VOLUME_GROUP_ID, request);
assertEquals("Testing DeleteVolumeGroup response", mockResponse.getVolumeGroupDeleted(), response.getVolumeGroupDeleted());
}
use of org.onap.so.adapters.vnfrest.DeleteVolumeGroupResponse 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()));
}
}
}
Aggregations