use of org.onap.so.adapters.nwrest.UpdateNetworkRequest in project so by onap.
the class NetworkAdapterUpdateTasks method updateNetwork.
public void updateNetwork(BuildingBlockExecution execution) {
try {
GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
L3Network l3Network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
UpdateNetworkRequest updateNetworkRequest = networkAdapterObjectMapper.createNetworkUpdateRequestMapper(gBBInput.getRequestContext(), gBBInput.getCloudRegion(), gBBInput.getOrchContext(), serviceInstance, l3Network, gBBInput.getUserInput(), gBBInput.getCustomer());
execution.setVariable("networkAdapterRequest", updateNetworkRequest.toXmlString());
} catch (Exception ex) {
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
}
}
use of org.onap.so.adapters.nwrest.UpdateNetworkRequest in project so by onap.
the class NetworkAdapterUpdateTasksTest method updateNetworkTest.
@Test
public void updateNetworkTest() {
String cloudRegionPo = "cloudRegionPo";
UpdateNetworkRequest updateNetworkRequest = new UpdateNetworkRequest();
execution.setVariable("cloudRegionPo", cloudRegionPo);
doReturn(updateNetworkRequest).when(networkAdapterObjectMapper).createNetworkUpdateRequestMapper(isA(RequestContext.class), isA(CloudRegion.class), isA(OrchestrationContext.class), isA(ServiceInstance.class), isA(L3Network.class), isA(Map.class), isA(Customer.class));
networkAdapterUpdateTasks.updateNetwork(execution);
verify(networkAdapterObjectMapper, times(1)).createNetworkUpdateRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, network, userInput, customer);
assertEquals(updateNetworkRequest.toXmlString(), execution.getVariable("networkAdapterRequest"));
}
use of org.onap.so.adapters.nwrest.UpdateNetworkRequest in project so by onap.
the class NetworkAdapterObjectMapperTest method updateNetworkRequestMapperTest.
@Test
public void updateNetworkRequestMapperTest() throws UnsupportedEncodingException {
org.onap.so.openstack.beans.Subnet subnet = new org.onap.so.openstack.beans.Subnet();
subnet.setSubnetId("subnetId");
subnet.setGatewayIp("NULL");
subnet.setHostRoutes(new ArrayList<org.onap.so.openstack.beans.HostRoute>());
List<org.onap.so.openstack.beans.Subnet> subnets = new ArrayList<>();
subnets.add(subnet);
ProviderVlanNetwork providerVlanNetwork = new ProviderVlanNetwork("physicalNetworkName", new ArrayList<Integer>());
List<String> policyFqdns = Arrays.asList("networkPolicyFqdn");
org.onap.so.openstack.beans.RouteTarget expectedRouteTarget = new org.onap.so.openstack.beans.RouteTarget();
expectedRouteTarget.setRouteTarget("globalRouteTarget");
ContrailNetwork contrailNetwork = new ContrailNetwork();
contrailNetwork.setPolicyFqdns(policyFqdns);
contrailNetwork.setRouteTableFqdns(new ArrayList<String>());
contrailNetwork.setRouteTargets(new ArrayList<org.onap.so.openstack.beans.RouteTarget>());
contrailNetwork.getRouteTargets().add(expectedRouteTarget);
contrailNetwork.getRouteTableFqdns().add("routeTableReferenceFqdn");
MsoRequest msoRequest = new MsoRequest();
msoRequest.setServiceInstanceId("testServiceInstanceId1");
ModelInfoNetwork modelInfoNetwork = new ModelInfoNetwork();
modelInfoNetwork.setNetworkType("networkType");
modelInfoNetwork.setModelCustomizationUUID("modelCustomizationUuid");
modelInfoNetwork.setModelVersion("modelVersion");
Subnet actualSubnet = new Subnet();
actualSubnet.setSubnetId("subnetId");
actualSubnet.setDhcpEnabled(false);
actualSubnet.setIpVersion("4");
RouteTarget routeTarget = new RouteTarget();
routeTarget.setGlobalRouteTarget("globalRouteTarget");
VpnBinding vpnBinding = new VpnBinding();
vpnBinding.setVpnId("vpnId");
vpnBinding.getRouteTargets().add(routeTarget);
Customer customer = new Customer();
customer.getVpnBindings().add(vpnBinding);
ServiceSubscription serviceSubscription = new ServiceSubscription();
customer.setServiceSubscription(serviceSubscription);
// set Customer on service instance
customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
NetworkPolicy networkPolicy = new NetworkPolicy();
networkPolicy.setNetworkPolicyId("networkPolicyId");
networkPolicy.setNetworkPolicyFqdn("networkPolicyFqdn");
RouteTableReference routeTableReference = new RouteTableReference();
routeTableReference.setRouteTableReferenceFqdn("routeTableReferenceFqdn");
l3Network.setModelInfoNetwork(modelInfoNetwork);
l3Network.setPhysicalNetworkName("physicalNetworkName");
l3Network.getSubnets().add(actualSubnet);
l3Network.getNetworkPolicies().add(networkPolicy);
l3Network.getContrailNetworkRouteTableReferences().add(routeTableReference);
l3Network.setIsSharedNetwork(false);
l3Network.setIsExternalNetwork(false);
HashMap<String, String> networkParams = new HashMap<String, String>();
networkParams.put("shared", "false");
networkParams.put("external", "false");
networkParams.put("testUserInputKey", "testUserInputValue");
UpdateNetworkRequest expectedUpdateNetworkRequest = new UpdateNetworkRequest();
expectedUpdateNetworkRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
expectedUpdateNetworkRequest.setTenantId(cloudRegion.getTenantId());
expectedUpdateNetworkRequest.setNetworkId(l3Network.getNetworkId());
expectedUpdateNetworkRequest.setNetworkStackId(l3Network.getHeatStackId());
expectedUpdateNetworkRequest.setNetworkName(l3Network.getNetworkName());
expectedUpdateNetworkRequest.setNetworkType(l3Network.getModelInfoNetwork().getNetworkType());
expectedUpdateNetworkRequest.setNetworkTypeVersion(l3Network.getModelInfoNetwork().getModelVersion());
expectedUpdateNetworkRequest.setModelCustomizationUuid(l3Network.getModelInfoNetwork().getModelCustomizationUUID());
expectedUpdateNetworkRequest.setSubnets(subnets);
expectedUpdateNetworkRequest.setProviderVlanNetwork(providerVlanNetwork);
expectedUpdateNetworkRequest.setContrailNetwork(contrailNetwork);
expectedUpdateNetworkRequest.setNetworkParams(networkParams);
expectedUpdateNetworkRequest.setMsoRequest(msoRequest);
expectedUpdateNetworkRequest.setSkipAAI(true);
expectedUpdateNetworkRequest.setBackout(Boolean.TRUE.equals(orchestrationContext.getIsRollbackEnabled()));
expectedUpdateNetworkRequest.setMessageId("messageId");
expectedUpdateNetworkRequest.setNotificationUrl("http://localhost:28080/mso/WorkflowMesssage/NetworkAResponse/messageId");
doReturn("messageId").when(SPY_networkAdapterObjectMapper).getRandomUuid();
doReturn("http://localhost:28080/mso/WorkflowMesssage").when(SPY_networkAdapterObjectMapper).getEndpoint();
UpdateNetworkRequest actualUpdateNetworkRequest = SPY_networkAdapterObjectMapper.createNetworkUpdateRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, customer);
assertThat(actualUpdateNetworkRequest, sameBeanAs(expectedUpdateNetworkRequest).ignoring("msoRequest.requestId"));
}
use of org.onap.so.adapters.nwrest.UpdateNetworkRequest 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.nwrest.UpdateNetworkRequest in project so by onap.
the class NetworkAdapterClientIT method updateNetworkTest.
@Test
public void updateNetworkTest() throws NetworkAdapterClientException, JsonProcessingException {
UpdateNetworkRequest request = new UpdateNetworkRequest();
request.setCloudSiteId(TESTING_ID);
request.setNetworkId("test1");
UpdateNetworkResponse mockResponse = new UpdateNetworkResponse();
mockResponse.setNetworkId("test1");
wireMockServer.stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(mapper.writeValueAsString(mockResponse)).withStatus(200)));
UpdateNetworkResponse response = client.updateNetwork(AAI_NETWORK_ID, request);
assertEquals("Testing UpdateVfModule response", "test1", response.getNetworkId());
}
Aggregations