use of org.onap.so.adapters.nwrest.CreateNetworkRequest in project so by onap.
the class CreateNetwork method buildCreateNetworkRequest.
/**
* BPMN access method to build CreateNetworkRequest object
*/
public void buildCreateNetworkRequest(BuildingBlockExecution execution) throws Exception {
try {
GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
L3Network l3Network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
Map<String, String> userInput = gBBInput.getUserInput();
String cloudRegionPo = execution.getVariable("cloudRegionPo");
CreateNetworkRequest createNetworkRequest = networkAdapterObjectMapper.createNetworkRequestMapper(gBBInput.getRequestContext(), gBBInput.getCloudRegion(), gBBInput.getOrchContext(), serviceInstance, l3Network, userInput, cloudRegionPo, gBBInput.getCustomer());
// set CreateNetowrkRequest object on execution to be re-used within current BB
execution.setVariable("createNetworkRequest", createNetworkRequest);
} catch (Exception ex) {
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
}
}
use of org.onap.so.adapters.nwrest.CreateNetworkRequest in project so by onap.
the class AAIQueryTasks method getNetworkVpnBinding.
/**
* BPMN access method to extract VPN Binding data from AAI result and populate proper fields into
* CreateNetworkRequest
*/
public void getNetworkVpnBinding(BuildingBlockExecution execution) {
try {
L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
AAIResultWrapper aaiResultWrapper = aaiNetworkResources.queryNetworkWrapperById(l3network);
CreateNetworkRequest createNetworkRequest = execution.getVariable("createNetworkRequest");
Optional<Relationships> networkRelationships = aaiResultWrapper.getRelationships();
if (!networkRelationships.isPresent()) {
throw (new Exception(ERROR_MSG));
}
List<AAIResourceUri> netBindingsUriList = networkRelationships.get().getRelatedUris(Types.VPN_BINDING);
List<org.onap.so.openstack.beans.RouteTarget> routeTargets = new ArrayList<>();
for (AAIResourceUri netBindingUri : netBindingsUriList) {
logger.info("Get Route Targests");
Optional<VpnBinding> oVpnBinding = aaiNetworkResources.getVpnBinding(netBindingUri);
if (oVpnBinding.isPresent()) {
VpnBinding vpnBinding = oVpnBinding.get();
RouteTargets rts = vpnBinding.getRouteTargets();
if (rts != null) {
List<org.onap.aai.domain.yang.RouteTarget> rtList = rts.getRouteTarget();
if (!rtList.isEmpty()) {
PropertyMap<org.onap.aai.domain.yang.RouteTarget, org.onap.so.openstack.beans.RouteTarget> personMap = new PropertyMap<org.onap.aai.domain.yang.RouteTarget, org.onap.so.openstack.beans.RouteTarget>() {
@Override
protected void configure() {
map().setRouteTarget(source.getGlobalRouteTarget());
map(source.getRouteTargetRole(), destination.getRouteTargetRole());
}
};
modelMapper.addMappings(personMap);
for (org.onap.aai.domain.yang.RouteTarget rt : rtList) {
org.onap.so.openstack.beans.RouteTarget openstackRtBean = modelMapper.map(rt, org.onap.so.openstack.beans.RouteTarget.class);
routeTargets.add(openstackRtBean);
}
}
}
}
}
// store route targets data in execution - to be used as part of
// Network adapter input
createNetworkRequest.getContrailNetwork().setRouteTargets(routeTargets);
execution.setVariable("createNetworkRequest", createNetworkRequest);
} catch (Exception ex) {
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
}
}
use of org.onap.so.adapters.nwrest.CreateNetworkRequest in project so by onap.
the class NetworkAdapterObjectMapperTest method buildOpenstackSubnetListTest.
@Test
public void buildOpenstackSubnetListTest() throws Exception {
ObjectMapper omapper = new ObjectMapper();
String bbJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "generalBB.json")));
org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock gbb = omapper.readValue(bbJson, org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock.class);
L3Network myNetwork = gbb.getServiceInstance().getNetworks().get(0);
String expectedCreateNetworkRequestJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "createNetworkRequest.json")));
org.onap.so.adapters.nwrest.CreateNetworkRequest expectedCreateNetworkRequest = omapper.readValue(expectedCreateNetworkRequestJson, org.onap.so.adapters.nwrest.CreateNetworkRequest.class);
String cloudRegionPo = "cloudRegionPo";
expectedCreateNetworkRequest.setNotificationUrl("endpoint/NetworkAResponse/messageId");
doReturn("endpoint/").when(SPY_networkAdapterObjectMapper).getEndpoint();
doReturn("messageId").when(SPY_networkAdapterObjectMapper).getRandomUuid();
CreateNetworkRequest createNetworkRequest = SPY_networkAdapterObjectMapper.createNetworkRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, myNetwork, userInput, cloudRegionPo, customer);
// ignoring dynamic fields and networkParams that throws parsing exception on json file load
assertThat(createNetworkRequest, sameBeanAs(expectedCreateNetworkRequest).ignoring("messageId").ignoring("msoRequest.requestId").ignoring("networkParams"));
}
use of org.onap.so.adapters.nwrest.CreateNetworkRequest in project so by onap.
the class CreateNetworkTest method buildCreateNetworkRequestTest.
@Test
public void buildCreateNetworkRequestTest() throws Exception {
execution.setVariable("cloudRegionPo", cloudRegionPo);
CreateNetworkRequest expectedCreateNetworkRequest = new CreateNetworkRequest();
doReturn(expectedCreateNetworkRequest).when(networkAdapterObjectMapper).createNetworkRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, network, userInput, cloudRegionPo, customer);
createNetwork.buildCreateNetworkRequest(execution);
verify(networkAdapterObjectMapper, times(1)).createNetworkRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, network, userInput, cloudRegionPo, customer);
assertThat(expectedCreateNetworkRequest, sameBeanAs(execution.getVariable("createNetworkRequest")));
}
use of org.onap.so.adapters.nwrest.CreateNetworkRequest 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