Search in sources :

Example 6 with CreateNetworkRequest

use of org.onap.so.adapters.nwrest.CreateNetworkRequest in project so by onap.

the class RollbackService method executeExternalTask.

public void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) {
    mdcSetup.setupMDC(externalTask);
    logger.debug("Starting External Task Rollback Service");
    Map<String, Object> variables = new HashMap<>();
    boolean success = false;
    boolean pollRollbackStatus = false;
    try {
        String xmlRequest = externalTask.getVariable("openstackAdapterTaskRequest");
        if (xmlRequest != null) {
            Optional<String> requestType = findRequestType(xmlRequest);
            if ("createVolumeGroupRequest".equals(requestType.get())) {
                logger.debug("Executing External Task Rollback Service for Create Volume Group");
                CreateVolumeGroupRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateVolumeGroupRequest.class);
                boolean isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId());
                if (!isMulticloud) {
                    vnfAdapterImpl.deleteVfModule(req.getCloudSiteId(), req.getCloudOwner(), req.getTenantId(), req.getVolumeGroupName(), null, req.getMsoRequest(), new Holder<>());
                    pollRollbackStatus = true;
                    success = true;
                } else {
                    vnfPluginImpl.deleteVnf(req.getCloudSiteId(), req.getCloudOwner(), req.getTenantId(), req.getVolumeGroupName(), req.getMsoRequest());
                    pollRollbackStatus = false;
                    success = true;
                }
            } else if ("createVfModuleRequest".equals(requestType.get())) {
                logger.debug("Executing External Task Rollback Service for Create Vf Module");
                CreateVfModuleRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateVfModuleRequest.class);
                boolean isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId());
                if (!isMulticloud) {
                    vnfAdapterImpl.deleteVfModule(req.getCloudSiteId(), req.getCloudOwner(), req.getTenantId(), req.getVfModuleName(), req.getModelCustomizationUuid(), req.getMsoRequest(), new Holder<>());
                    pollRollbackStatus = true;
                    success = true;
                } else {
                    pollRollbackStatus = false;
                    success = true;
                }
            } else if ("createNetworkRequest".equals(requestType.get())) {
                logger.debug("Executing External Task Rollback Service for Create Network");
                CreateNetworkRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateNetworkRequest.class);
                networkAdapterImpl.deleteNetwork(req.getCloudSiteId(), req.getTenantId(), req.getNetworkType(), req.getModelCustomizationUuid(), req.getNetworkName(), req.getMsoRequest());
                pollRollbackStatus = true;
                success = true;
            }
        }
    } catch (Exception e) {
        logger.error("Error during External Task Rollback Service", e);
    }
    variables.put("OpenstackRollbackSuccess", success);
    variables.put("rollbackPerformed", true);
    variables.put("PollRollbackStatus", pollRollbackStatus);
    if (success) {
        externalTaskService.complete(externalTask, variables);
        logger.debug("The External Task Id: {}  Successful", externalTask.getId());
    } else {
        logger.debug("The External Task Id: {}  Failed. Not Retrying", externalTask.getId());
        externalTaskService.complete(externalTask, variables);
    }
}
Also used : CreateVolumeGroupRequest(org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest) CreateNetworkRequest(org.onap.so.adapters.nwrest.CreateNetworkRequest) HashMap(java.util.HashMap) Holder(javax.xml.ws.Holder) CreateVfModuleRequest(org.onap.so.adapters.vnfrest.CreateVfModuleRequest) StringReader(java.io.StringReader)

Example 7 with CreateNetworkRequest

use of org.onap.so.adapters.nwrest.CreateNetworkRequest in project so by onap.

the class NetworkAdapterClientIT method createNetworkTestThrowException.

@Test(expected = NetworkAdapterClientException.class)
public void createNetworkTestThrowException() throws NetworkAdapterClientException, JsonProcessingException {
    CreateNetworkRequest request = new CreateNetworkRequest();
    request.setCloudSiteId(TESTING_ID);
    CreateNetworkError mockResponse = new CreateNetworkError();
    mockResponse.setMessage("Error in create network");
    wireMockServer.stubFor(post(urlPathEqualTo(REST_ENDPOINT)).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(mapper.writeValueAsString(mockResponse)).withStatus(500)));
    client.createNetwork(request);
}
Also used : CreateNetworkError(org.onap.so.adapters.nwrest.CreateNetworkError) CreateNetworkRequest(org.onap.so.adapters.nwrest.CreateNetworkRequest) BaseIntegrationTest(org.onap.so.BaseIntegrationTest) Test(org.junit.Test)

Example 8 with CreateNetworkRequest

use of org.onap.so.adapters.nwrest.CreateNetworkRequest in project so by onap.

the class StackService method createNetwork.

private void createNetwork(String xmlRequest, Holder<String> canonicalStackId, MutableBoolean backout, MutableBoolean success, MutableBoolean os3) throws NetworkException {
    CreateNetworkRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateNetworkRequest.class);
    HashMap<String, String> params = (HashMap<String, String>) req.getNetworkParams();
    if (params == null) {
        params = new HashMap<>();
    }
    String shared = null;
    String external = null;
    String physicalNetworkName = null;
    List<Integer> vlans = null;
    List<RouteTarget> routeTargets = null;
    List<String> fqdns = null;
    List<String> routeTable = null;
    if (params.containsKey(SHARED))
        shared = params.get(SHARED);
    if (params.containsKey(EXTERNAL))
        external = params.get(EXTERNAL);
    if (req.isContrailRequest()) {
        ContrailNetwork ctn = req.getContrailNetwork();
        if (ctn == null) {
            ctn = new ContrailNetwork();
            req.setContrailNetwork(ctn);
        }
        if (shared == null && ctn.getShared() != null) {
            shared = ctn.getShared();
        }
        if (shared == null && ctn.getExternal() != null) {
            external = ctn.getExternal();
        }
        routeTargets = req.getContrailNetwork().getRouteTargets();
        fqdns = req.getContrailNetwork().getPolicyFqdns();
        routeTable = req.getContrailNetwork().getRouteTableFqdns();
    } else {
        ProviderVlanNetwork pvn = req.getProviderVlanNetwork();
        if (pvn == null) {
            pvn = new ProviderVlanNetwork();
            req.setProviderVlanNetwork(pvn);
        }
        physicalNetworkName = req.getProviderVlanNetwork().getPhysicalNetworkName();
        vlans = req.getProviderVlanNetwork().getVlans();
    }
    networkAdapterImpl.createNetwork(req.getCloudSiteId(), req.getTenantId(), req.getNetworkType(), req.getModelCustomizationUuid(), req.getNetworkName(), physicalNetworkName, vlans, routeTargets, shared, external, req.getFailIfExists(), false, req.getSubnets(), fqdns, routeTable, req.getMsoRequest(), canonicalStackId, os3);
    success.setTrue();
    backout.setValue(req.getBackout());
}
Also used : CreateNetworkRequest(org.onap.so.adapters.nwrest.CreateNetworkRequest) HashMap(java.util.HashMap) ContrailNetwork(org.onap.so.adapters.nwrest.ContrailNetwork) StringReader(java.io.StringReader) ProviderVlanNetwork(org.onap.so.adapters.nwrest.ProviderVlanNetwork) RouteTarget(org.onap.so.openstack.beans.RouteTarget)

Example 9 with CreateNetworkRequest

use of org.onap.so.adapters.nwrest.CreateNetworkRequest in project so by onap.

the class NetworkAdapterCreateTasks method createNetwork.

public void createNetwork(BuildingBlockExecution execution) {
    execution.setVariable("networkAdapterCreateRollback", false);
    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());
        execution.setVariable("networkAdapterRequest", createNetworkRequest.toXmlString());
    } catch (Exception ex) {
        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
    }
}
Also used : L3Network(org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network) GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) CreateNetworkRequest(org.onap.so.adapters.nwrest.CreateNetworkRequest) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance)

Example 10 with CreateNetworkRequest

use of org.onap.so.adapters.nwrest.CreateNetworkRequest in project so by onap.

the class NetworkAdapterObjectMapperTest method buildCreateNetworkRequestFromBbobjectTest.

@Test
public void buildCreateNetworkRequestFromBbobjectTest() 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.setNetworkType(l3Network.getNetworkType());
    expectedCreateNetworkRequest.setBackout(false);
    expectedCreateNetworkRequest.setFailIfExists(false);
    expectedCreateNetworkRequest.setNetworkTechnology("CONTRAIL");
    MsoRequest msoRequest = new MsoRequest();
    msoRequest.setRequestId(requestContext.getMsoRequestId());
    msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId());
    expectedCreateNetworkRequest.setMsoRequest(msoRequest);
    expectedCreateNetworkRequest.setSkipAAI(true);
    HashMap<String, String> networkParams = new HashMap<String, String>();
    networkParams.put("shared", "true");
    networkParams.put("external", "false");
    networkParams.put("testUserInputKey", "testUserInputValue");
    expectedCreateNetworkRequest.setNetworkParams(networkParams);
    expectedCreateNetworkRequest.setNotificationUrl("endpoint/NetworkAResponse/messageId");
    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.setNetworkTechnology("Contrail");
    l3Network.setIsSharedNetwork(true);
    l3Network.setIsExternalNetwork(false);
    doReturn("endpoint/").when(SPY_networkAdapterObjectMapper).getEndpoint();
    doReturn("messageId").when(SPY_networkAdapterObjectMapper).getRandomUuid();
    CreateNetworkRequest createNetworkRequest = SPY_networkAdapterObjectMapper.createNetworkRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, cloudRegionPo, customer);
    assertThat(createNetworkRequest, sameBeanAs(expectedCreateNetworkRequest).ignoring("contrailRequest").ignoring("contrailNetwork").ignoring("providerVlanNetwork").ignoring("subnets").ignoring("messageId"));
}
Also used : CreateNetworkRequest(org.onap.so.adapters.nwrest.CreateNetworkRequest) HashMap(java.util.HashMap) MsoRequest(org.onap.so.entity.MsoRequest) ArrayList(java.util.ArrayList) HostRoute(org.onap.so.bpmn.servicedecomposition.bbobjects.HostRoute) Subnet(org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet) Test(org.junit.Test)

Aggregations

CreateNetworkRequest (org.onap.so.adapters.nwrest.CreateNetworkRequest)14 Test (org.junit.Test)7 L3Network (org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network)6 HashMap (java.util.HashMap)4 ServiceInstance (org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance)4 StringReader (java.io.StringReader)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)2 BaseIntegrationTest (org.onap.so.BaseIntegrationTest)2 ContrailNetwork (org.onap.so.adapters.nwrest.ContrailNetwork)2 CreateNetworkResponse (org.onap.so.adapters.nwrest.CreateNetworkResponse)2 ProviderVlanNetwork (org.onap.so.adapters.nwrest.ProviderVlanNetwork)2 CreateVfModuleRequest (org.onap.so.adapters.vnfrest.CreateVfModuleRequest)2 CreateVolumeGroupRequest (org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest)2 CloudRegion (org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion)2 Customer (org.onap.so.bpmn.servicedecomposition.bbobjects.Customer)2 HostRoute (org.onap.so.bpmn.servicedecomposition.bbobjects.HostRoute)2 Subnet (org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet)2 GeneralBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock)2 OrchestrationContext (org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext)2