use of org.onap.so.adapters.nwrest.CreateNetworkResponse in project so by onap.
the class PollService method determineCreateNetworkStatus.
private Optional<String> determineCreateNetworkStatus(CreateNetworkRequest req, ExternalTask externalTask, MutableBoolean success) throws MsoException {
String stackId = externalTask.getVariable("stackId");
boolean pollRollbackStatus = externalTask.getVariable("PollRollbackStatus");
int timeoutMinutes = msoHeatUtils.getNetworkHeatTimeoutValue(req.getModelCustomizationUuid(), req.getNetworkType());
if (pollRollbackStatus) {
logger.debug("Executing External Task Poll Service for Rollback Network");
pollDeleteResource(timeoutMinutes, req.getCloudSiteId(), req.getTenantId(), stackId, success);
return Optional.empty();
} else {
logger.debug("Executing External Task Poll Service for Create Network");
boolean os3Nw = externalTask.getVariable("os3Nw");
StackInfo stack = pollCreateResource(timeoutMinutes, req.getCloudSiteId(), req.getTenantId(), stackId, success);
String networkFqdn = "";
String neutronNetworkId = "";
Map<String, String> subnetMap = new HashMap<>();
if (stack.getOutputs() != null) {
networkFqdn = (String) stack.getOutputs().get("network_fqdn");
neutronNetworkId = (String) stack.getOutputs().get("network_id");
subnetMap = networkAdapterImpl.buildSubnetMap(stack.getOutputs(), req.getSubnets(), os3Nw);
}
CreateNetworkResponse response = new CreateNetworkResponse(req.getNetworkId(), neutronNetworkId, stackId, networkFqdn, true, subnetMap, buildNetworkRollback(req, stackId), req.getMessageId());
return Optional.of(response.toXmlString());
}
}
use of org.onap.so.adapters.nwrest.CreateNetworkResponse in project so by onap.
the class AAIUpdateTasks method updateNetworkCreated.
/**
* BPMN access method to update L3Network after it was created in cloud
*/
public void updateNetworkCreated(BuildingBlockExecution execution) throws Exception {
execution.setVariable("aaiNetworkActivateRollback", false);
L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
L3Network copiedl3network = l3network.shallowCopyId();
CreateNetworkResponse response = execution.getVariable("createNetworkResponse");
try {
if (response.getNetworkFqdn() != null) {
l3network.setContrailNetworkFqdn(response.getNetworkFqdn());
}
l3network.setOrchestrationStatus(OrchestrationStatus.CREATED);
l3network.setHeatStackId(response.getNetworkStackId());
l3network.setNeutronNetworkId(response.getNeutronNetworkId());
copiedl3network.setContrailNetworkFqdn(response.getNetworkFqdn());
copiedl3network.setOrchestrationStatus(OrchestrationStatus.CREATED);
copiedl3network.setHeatStackId(response.getNetworkStackId());
copiedl3network.setNeutronNetworkId(response.getNeutronNetworkId());
aaiNetworkResources.updateNetwork(copiedl3network);
Map<String, String> subnetMap = response.getSubnetMap();
List<Subnet> subnets = l3network.getSubnets();
if (subnets != null && subnetMap != null) {
for (Subnet subnet : subnets) {
Subnet copiedSubnet = subnet.shallowCopyId();
copiedSubnet.setNeutronSubnetId(subnetMap.get(copiedSubnet.getSubnetId()));
copiedSubnet.setOrchestrationStatus(OrchestrationStatus.CREATED);
aaiNetworkResources.updateSubnet(copiedl3network, copiedSubnet);
}
}
execution.setVariable("aaiNetworkActivateRollback", true);
} catch (Exception ex) {
logger.error("Exception occurred in AAIUpdateTasks updateNetworkCreated", ex);
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
}
}
use of org.onap.so.adapters.nwrest.CreateNetworkResponse in project so by onap.
the class NetworkAdapterClientIT method createNetworkTest.
@Test
public void createNetworkTest() throws NetworkAdapterClientException, JsonProcessingException {
CreateNetworkRequest request = new CreateNetworkRequest();
request.setCloudSiteId(TESTING_ID);
CreateNetworkResponse mockResponse = new CreateNetworkResponse();
mockResponse.setNetworkCreated(true);
wireMockServer.stubFor(post(urlPathEqualTo(REST_ENDPOINT)).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(mapper.writeValueAsString(mockResponse)).withStatus(200)));
CreateNetworkResponse response = client.createNetwork(request);
assertEquals("Testing CreateVfModule response", true, response.getNetworkCreated());
}
use of org.onap.so.adapters.nwrest.CreateNetworkResponse in project so by onap.
the class NetworkAdapterResourcesTest method createNetworTest.
@Test
public void createNetworTest() throws Exception {
String cloudRegionPo = "cloudRegionPo";
CreateNetworkRequest expectedCreateNetworkRequest = new CreateNetworkRequest();
expectedCreateNetworkRequest.setCloudSiteId(cloudRegionPo);
expectedCreateNetworkRequest.setTenantId(cloudRegion.getTenantId());
expectedCreateNetworkRequest.setNetworkId(l3Network.getNetworkId());
expectedCreateNetworkRequest.setNetworkName(l3Network.getNetworkName());
expectedCreateNetworkRequest.setBackout(false);
expectedCreateNetworkRequest.setFailIfExists(true);
MsoRequest msoRequest = new MsoRequest();
msoRequest.setRequestId(requestContext.getMsoRequestId());
msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId());
expectedCreateNetworkRequest.setMsoRequest(msoRequest);
expectedCreateNetworkRequest.setSkipAAI(true);
Subnet openstackSubnet = new Subnet();
HostRoute hostRoute = new HostRoute();
hostRoute.setHostRouteId("hostRouteId");
hostRoute.setNextHop("nextHop");
hostRoute.setRoutePrefix("routePrefix");
openstackSubnet.getHostRoutes().add(hostRoute);
List<Subnet> subnetList = new ArrayList<Subnet>();
subnetList.add(openstackSubnet);
l3Network.getSubnets().add(openstackSubnet);
l3Network.setOrchestrationStatus(OrchestrationStatus.ASSIGNED);
CreateNetworkRequest createNetworkRequest = new CreateNetworkRequest();
createNetworkRequest.setCloudSiteId("cloudSiteId");
CreateNetworkResponse expectedCreateNetworkResponse = new CreateNetworkResponse();
expectedCreateNetworkResponse.setNetworkStackId("networkStackId");
expectedCreateNetworkResponse.setNetworkCreated(true);
doReturn(expectedCreateNetworkResponse).when(MOCK_networkAdapterClient).createNetwork(isA(CreateNetworkRequest.class));
doReturn(createNetworkRequest).when(MOCK_networkAdapterObjectMapper).createNetworkRequestMapper(isA(RequestContext.class), isA(CloudRegion.class), isA(OrchestrationContext.class), isA(ServiceInstance.class), isA(L3Network.class), isA(Map.class), isA(String.class), isA(Customer.class));
CreateNetworkResponse actualCreateNetwrokResponse = (networkAdapterResources.createNetwork(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, cloudRegionPo, customer)).get();
verify(MOCK_networkAdapterClient, times(1)).createNetwork(createNetworkRequest);
verify(MOCK_networkAdapterObjectMapper, times(1)).createNetworkRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, cloudRegionPo, customer);
assertThat(expectedCreateNetworkResponse, Matchers.sameBeanAs(actualCreateNetwrokResponse));
}
use of org.onap.so.adapters.nwrest.CreateNetworkResponse in project so by onap.
the class NetworkAdapterResourcesTest method rollbackCreateNetworkTest.
@Test
public void rollbackCreateNetworkTest() throws Exception {
String cloudRegionPo = "cloudRegionPo";
RollbackNetworkResponse expectedRollbackNetworkResponse = new RollbackNetworkResponse();
expectedRollbackNetworkResponse.setMessageId("messageId");
expectedRollbackNetworkResponse.setNetworkRolledBack(true);
RollbackNetworkRequest rollbackNetworkRequest = new RollbackNetworkRequest();
rollbackNetworkRequest.setMessageId("messageId");
RollbackNetworkResponse rollbackNetworkResponse = new RollbackNetworkResponse();
rollbackNetworkResponse.setMessageId("messageId");
rollbackNetworkResponse.setNetworkRolledBack(true);
CreateNetworkResponse createNetworkResponse = new CreateNetworkResponse();
createNetworkResponse.setMessageId("messageId");
doReturn(rollbackNetworkResponse).when(MOCK_networkAdapterClient).rollbackNetwork(isA(String.class), isA(RollbackNetworkRequest.class));
doReturn(rollbackNetworkRequest).when(MOCK_networkAdapterObjectMapper).createNetworkRollbackRequestMapper(isA(RequestContext.class), isA(CloudRegion.class), isA(OrchestrationContext.class), isA(ServiceInstance.class), isA(L3Network.class), isA(Map.class), isA(String.class), isA(CreateNetworkResponse.class));
RollbackNetworkResponse actualRollbackCreateNetwrokResponse = (networkAdapterResources.rollbackCreateNetwork(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, cloudRegionPo, createNetworkResponse)).get();
verify(MOCK_networkAdapterClient, times(1)).rollbackNetwork(l3Network.getNetworkId(), rollbackNetworkRequest);
verify(MOCK_networkAdapterObjectMapper, times(1)).createNetworkRollbackRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, cloudRegionPo, createNetworkResponse);
assertThat(expectedRollbackNetworkResponse, Matchers.sameBeanAs(actualRollbackCreateNetwrokResponse));
}
Aggregations