Search in sources :

Example 1 with UpdateNetworkRequest

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);
    }
}
Also used : L3Network(org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network) GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) UpdateNetworkRequest(org.onap.so.adapters.nwrest.UpdateNetworkRequest)

Example 2 with UpdateNetworkRequest

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"));
}
Also used : CloudRegion(org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion) L3Network(org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network) Customer(org.onap.so.bpmn.servicedecomposition.bbobjects.Customer) UpdateNetworkRequest(org.onap.so.adapters.nwrest.UpdateNetworkRequest) 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)

Example 3 with UpdateNetworkRequest

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"));
}
Also used : Customer(org.onap.so.bpmn.servicedecomposition.bbobjects.Customer) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ServiceSubscription(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription) ContrailNetwork(org.onap.so.adapters.nwrest.ContrailNetwork) MsoRequest(org.onap.so.entity.MsoRequest) ModelInfoNetwork(org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoNetwork) HostRoute(org.onap.so.bpmn.servicedecomposition.bbobjects.HostRoute) UpdateNetworkRequest(org.onap.so.adapters.nwrest.UpdateNetworkRequest) ProviderVlanNetwork(org.onap.so.adapters.nwrest.ProviderVlanNetwork) NetworkPolicy(org.onap.so.bpmn.servicedecomposition.bbobjects.NetworkPolicy) RouteTableReference(org.onap.so.bpmn.servicedecomposition.bbobjects.RouteTableReference) VpnBinding(org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBinding) RouteTarget(org.onap.so.bpmn.servicedecomposition.bbobjects.RouteTarget) Subnet(org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet) Test(org.junit.Test)

Example 4 with UpdateNetworkRequest

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()));
        }
    }
}
Also used : DeleteNetworkResponse(org.onap.so.adapters.nwrest.DeleteNetworkResponse) CreateVolumeGroupRequest(org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest) CreateNetworkRequest(org.onap.so.adapters.nwrest.CreateNetworkRequest) HashMap(java.util.HashMap) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) RollbackNetworkRequest(org.onap.so.adapters.nwrest.RollbackNetworkRequest) DeleteVolumeGroupResponse(org.onap.so.adapters.vnfrest.DeleteVolumeGroupResponse) DeleteVfModuleResponse(org.onap.so.adapters.vnfrest.DeleteVfModuleResponse) UpdateNetworkResponse(org.onap.so.adapters.nwrest.UpdateNetworkResponse) MsoException(org.onap.so.openstack.exceptions.MsoException) CreateVfModuleRequest(org.onap.so.adapters.vnfrest.CreateVfModuleRequest) DeleteNetworkRequest(org.onap.so.adapters.nwrest.DeleteNetworkRequest) StringReader(java.io.StringReader) DeleteVolumeGroupRequest(org.onap.so.adapters.vnfrest.DeleteVolumeGroupRequest) UpdateNetworkRequest(org.onap.so.adapters.nwrest.UpdateNetworkRequest) StackInfo(org.onap.so.openstack.beans.StackInfo) DeleteVfModuleRequest(org.onap.so.adapters.vnfrest.DeleteVfModuleRequest)

Example 5 with UpdateNetworkRequest

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

Aggregations

UpdateNetworkRequest (org.onap.so.adapters.nwrest.UpdateNetworkRequest)10 Test (org.junit.Test)6 UpdateNetworkResponse (org.onap.so.adapters.nwrest.UpdateNetworkResponse)4 HashMap (java.util.HashMap)3 BaseIntegrationTest (org.onap.so.BaseIntegrationTest)3 Customer (org.onap.so.bpmn.servicedecomposition.bbobjects.Customer)3 L3Network (org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network)3 ServiceInstance (org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance)3 StringReader (java.io.StringReader)2 Map (java.util.Map)2 ContrailNetwork (org.onap.so.adapters.nwrest.ContrailNetwork)2 DeleteNetworkResponse (org.onap.so.adapters.nwrest.DeleteNetworkResponse)2 ProviderVlanNetwork (org.onap.so.adapters.nwrest.ProviderVlanNetwork)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 WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)1 ArrayList (java.util.ArrayList)1 Response (javax.ws.rs.core.Response)1 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)1