Search in sources :

Example 6 with CreateNetworkResponse

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());
    }
}
Also used : HashMap(java.util.HashMap) CreateNetworkResponse(org.onap.so.adapters.nwrest.CreateNetworkResponse) StackInfo(org.onap.so.openstack.beans.StackInfo)

Example 7 with CreateNetworkResponse

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);
    }
}
Also used : CreateNetworkResponse(org.onap.so.adapters.nwrest.CreateNetworkResponse)

Example 8 with CreateNetworkResponse

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());
}
Also used : CreateNetworkRequest(org.onap.so.adapters.nwrest.CreateNetworkRequest) CreateNetworkResponse(org.onap.so.adapters.nwrest.CreateNetworkResponse) BaseIntegrationTest(org.onap.so.BaseIntegrationTest) Test(org.junit.Test)

Example 9 with CreateNetworkResponse

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));
}
Also used : CloudRegion(org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion) L3Network(org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network) CreateNetworkRequest(org.onap.so.adapters.nwrest.CreateNetworkRequest) Customer(org.onap.so.bpmn.servicedecomposition.bbobjects.Customer) CreateNetworkResponse(org.onap.so.adapters.nwrest.CreateNetworkResponse) ArrayList(java.util.ArrayList) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) OrchestrationContext(org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext) MsoRequest(org.onap.so.entity.MsoRequest) HostRoute(org.onap.so.bpmn.servicedecomposition.bbobjects.HostRoute) RequestContext(org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext) Subnet(org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet) Map(java.util.Map) Test(org.junit.Test)

Example 10 with CreateNetworkResponse

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));
}
Also used : CloudRegion(org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion) L3Network(org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network) RollbackNetworkResponse(org.onap.so.adapters.nwrest.RollbackNetworkResponse) CreateNetworkResponse(org.onap.so.adapters.nwrest.CreateNetworkResponse) RollbackNetworkRequest(org.onap.so.adapters.nwrest.RollbackNetworkRequest) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) RequestContext(org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext) Map(java.util.Map) OrchestrationContext(org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext) Test(org.junit.Test)

Aggregations

CreateNetworkResponse (org.onap.so.adapters.nwrest.CreateNetworkResponse)11 Test (org.junit.Test)6 L3Network (org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network)4 ServiceInstance (org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CreateNetworkRequest (org.onap.so.adapters.nwrest.CreateNetworkRequest)2 RollbackNetworkRequest (org.onap.so.adapters.nwrest.RollbackNetworkRequest)2 CloudRegion (org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion)2 OrchestrationContext (org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext)2 RequestContext (org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext)2 ArrayList (java.util.ArrayList)1 JAXBException (javax.xml.bind.JAXBException)1 BaseIntegrationTest (org.onap.so.BaseIntegrationTest)1 DeleteNetworkResponse (org.onap.so.adapters.nwrest.DeleteNetworkResponse)1 RollbackNetworkResponse (org.onap.so.adapters.nwrest.RollbackNetworkResponse)1 UpdateNetworkResponse (org.onap.so.adapters.nwrest.UpdateNetworkResponse)1 Customer (org.onap.so.bpmn.servicedecomposition.bbobjects.Customer)1 HostRoute (org.onap.so.bpmn.servicedecomposition.bbobjects.HostRoute)1 Subnet (org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet)1