Search in sources :

Example 6 with NetworkResource

use of org.onap.so.db.catalog.beans.NetworkResource in project so by onap.

the class MsoHeatUtilsTest method testGetNetworkHeatTimeoutValue.

@Test
public void testGetNetworkHeatTimeoutValue() {
    NetworkResourceCustomization mc = new NetworkResourceCustomization();
    NetworkResource nr = new NetworkResource();
    HeatTemplate heat = new HeatTemplate();
    heat.setTimeoutMinutes(110);
    nr.setHeatTemplate(heat);
    mc.setNetworkResource(nr);
    Mockito.when(catalogDbClient.getNetworkResourceCustomizationByModelCustomizationUUID("uuid")).thenReturn(mc);
    int timeout = heatUtils.getNetworkHeatTimeoutValue("uuid", "type");
    assertEquals(110, timeout);
    Mockito.verify(catalogDbClient, times(1)).getNetworkResourceCustomizationByModelCustomizationUUID("uuid");
}
Also used : NetworkResource(org.onap.so.db.catalog.beans.NetworkResource) HeatTemplate(org.onap.so.db.catalog.beans.HeatTemplate) NetworkResourceCustomization(org.onap.so.db.catalog.beans.NetworkResourceCustomization) Test(org.junit.Test)

Example 7 with NetworkResource

use of org.onap.so.db.catalog.beans.NetworkResource in project so by onap.

the class CatalogDbAdapterRest method serviceNetworksImpl.

public Response serviceNetworksImpl(String version, boolean isArray, String networkModelCustomizationUuid, String networkType, String serviceModelUuid, String serviceModelInvariantUuid, String serviceModelVersion) {
    QueryServiceNetworks qryResp;
    int respStatus = HttpStatus.SC_OK;
    String uuid = "";
    List<NetworkResourceCustomization> ret = new ArrayList<>();
    Service service = null;
    try {
        if (networkModelCustomizationUuid != null && !"".equals(networkModelCustomizationUuid)) {
            uuid = networkModelCustomizationUuid;
            ret = networkCustomizationRepo.findByModelCustomizationUUID(networkModelCustomizationUuid);
        } else if (networkType != null && !"".equals(networkType)) {
            uuid = networkType;
            NetworkResource networkResources = networkResourceRepo.findFirstByModelNameOrderByModelVersionDesc(networkType);
            if (networkResources != null)
                ret = networkResources.getNetworkResourceCustomization();
        } else if (serviceModelInvariantUuid != null && !"".equals(serviceModelInvariantUuid)) {
            uuid = serviceModelInvariantUuid;
            if (serviceModelVersion != null && !"".equals(serviceModelVersion)) {
                service = serviceRepo.findFirstByModelVersionAndModelInvariantUUID(serviceModelVersion, uuid);
            } else {
                service = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc(uuid);
            }
        } else if (serviceModelUuid != null && !"".equals(serviceModelUuid)) {
            uuid = serviceModelUuid;
            service = serviceRepo.findOneByModelUUID(serviceModelUuid);
        } else {
            throw (new Exception(NO_MATCHING_PARAMETERS));
        }
        if (service != null)
            ret = service.getNetworkCustomizations();
        if (ret == null || ret.isEmpty()) {
            logger.debug("serviceNetworks not found");
            respStatus = HttpStatus.SC_NOT_FOUND;
            qryResp = new QueryServiceNetworks();
        } else {
            qryResp = new QueryServiceNetworks(ret);
            logger.debug("serviceNetworks found qryResp= {}", qryResp);
        }
        return respond(version, respStatus, isArray, qryResp);
    } catch (Exception e) {
        logger.error("Exception - queryServiceNetworks", e);
        CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
        return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(new GenericEntity<CatalogQueryException>(excResp) {
        }).build();
    }
}
Also used : NetworkResource(org.onap.so.db.catalog.beans.NetworkResource) ArrayList(java.util.ArrayList) Service(org.onap.so.db.catalog.beans.Service) NetworkResourceCustomization(org.onap.so.db.catalog.beans.NetworkResourceCustomization) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException) QueryServiceNetworks(org.onap.so.adapters.catalogdb.catalogrest.QueryServiceNetworks) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException)

Example 8 with NetworkResource

use of org.onap.so.db.catalog.beans.NetworkResource in project so by onap.

the class MsoNetworkAdapterImpl method networkCheck.

private NetworkResource networkCheck(long startTime, String networkType, String modelCustomizationUuid, String networkName, String physicalNetworkName, List<Integer> vlans, List<RouteTarget> routeTargets, String cloudSiteId, CloudSite cloudSite) throws NetworkException {
    // Retrieve the Network Resource definition
    NetworkResource networkResource = null;
    NetworkResourceCustomization networkCust = null;
    CollectionNetworkResourceCustomization collectionNetworkCust = null;
    if (commonUtils.isNullOrEmpty(modelCustomizationUuid)) {
        if (!commonUtils.isNullOrEmpty(networkType)) {
            networkResource = networkResourceRepo.findFirstByModelNameOrderByModelVersionDesc(networkType);
        }
    } else {
        networkCust = networkCustomRepo.findOneByModelCustomizationUUID(modelCustomizationUuid);
        if (networkCust == null) {
            collectionNetworkCust = collectionNetworkCustomRepo.findOneByModelCustomizationUUID(modelCustomizationUuid);
        }
    }
    if (networkCust != null) {
        logger.debug("Got Network Customization definition from Catalog: {}", networkCust);
        networkResource = networkCust.getNetworkResource();
    } else if (collectionNetworkCust != null) {
        logger.debug("Retrieved Collection Network Resource Customization from Catalog: {}", collectionNetworkCust);
        networkResource = collectionNetworkCust.getNetworkResource();
    }
    if (networkResource == null) {
        String error = String.format("Create/UpdateNetwork: Unable to get network resource with NetworkType: %s or ModelCustomizationUUID:%s", networkType, modelCustomizationUuid);
        logger.error(LoggingAnchor.THREE, MessageEnum.RA_UNKOWN_PARAM, ErrorCode.DataError.getValue(), error);
        throw new NetworkException(error, MsoExceptionCategory.USERDATA);
    }
    logger.debug(LOG_DEBUG_MSG, networkResource);
    String mode = networkResource.getOrchestrationMode();
    NetworkType neutronNetworkType = NetworkType.valueOf(networkResource.getNeutronNetworkType());
    // All Networks are orchestrated via HEAT or Neutron
    if (!("HEAT".equals(mode) || NEUTRON_MODE.equals(mode))) {
        String error = "CreateNetwork: Configuration Error: Network Type = " + networkType;
        logger.error(LoggingAnchor.THREE, MessageEnum.RA_NETWORK_ORCHE_MODE_NOT_SUPPORT, ErrorCode.DataError.getValue(), error);
        throw new NetworkException(error, MsoExceptionCategory.INTERNAL);
    }
    MavenLikeVersioning osV = new MavenLikeVersioning();
    osV.setVersion(cloudSite.getCloudVersion());
    if ((osV.isMoreRecentThan(networkResource.getAicVersionMin()) || // os
    osV.isTheSameVersion(networkResource.getAicVersionMin())) && // min
    (osV.isTheSameVersion(networkResource.getAicVersionMax()) || // os <= max
    !(osV.isMoreRecentThan(networkResource.getAicVersionMax())))) {
        logger.debug("Network Type:{} VersionMin:{} VersionMax:{} supported on Cloud:{} with AIC_Version:{}", networkType, networkResource.getAicVersionMin(), networkResource.getAicVersionMax(), cloudSiteId, cloudSite.getCloudVersion());
    } else {
        String error = String.format("Network Type:%s Version_Min:%s Version_Max:%s not supported on Cloud:%s with AIC_Version:%s", networkType, networkResource.getAicVersionMin(), networkResource.getAicVersionMax(), cloudSiteId, cloudSite.getCloudVersion());
        logger.error(LoggingAnchor.THREE, MessageEnum.RA_CONFIG_EXC, ErrorCode.DataError.getValue(), error);
        throw new NetworkException(error, MsoExceptionCategory.USERDATA);
    }
    // Validate the Network parameters.
    String missing = validateNetworkParams(neutronNetworkType, networkName, physicalNetworkName, vlans, routeTargets);
    if (!missing.isEmpty()) {
        String error = "Create Network: Missing parameters: " + missing;
        logger.error(LoggingAnchor.THREE, MessageEnum.RA_MISSING_PARAM, ErrorCode.DataError.getValue(), error);
        throw new NetworkException(error, MsoExceptionCategory.USERDATA);
    }
    return networkResource;
}
Also used : NetworkResource(org.onap.so.db.catalog.beans.NetworkResource) NetworkType(org.onap.so.openstack.utils.MsoNeutronUtils.NetworkType) CollectionNetworkResourceCustomization(org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization) CollectionNetworkResourceCustomization(org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization) NetworkResourceCustomization(org.onap.so.db.catalog.beans.NetworkResourceCustomization) NetworkException(org.onap.so.adapters.network.exceptions.NetworkException) MavenLikeVersioning(org.onap.so.db.catalog.utils.MavenLikeVersioning)

Example 9 with NetworkResource

use of org.onap.so.db.catalog.beans.NetworkResource in project so by onap.

the class MsoNetworkAdapterImpl method updateNetwork.

/**
 * This is the "Update Network" web service implementation. It will update an existing Network of the requested type
 * in the specified cloud and tenant. The typical use will be to replace the VLANs with the supplied list (to add or
 * remove a VLAN), but other properties may be updated as well.
 *
 * There will be a pre-defined set of network types defined in the MSO Catalog. All such networks will have a
 * similar configuration, based on the allowable Openstack networking definitions. This includes basic networks,
 * provider networks (with a single VLAN), and multi-provider networks (one or more VLANs).
 *
 * Initially, all provider networks must currently be "vlan" type, and multi-provider networks must be multiple
 * VLANs on the same physical network.
 *
 * This service supports two modes of Network update: - via Heat Templates - via Neutron API The network
 * orchestration mode for each network type is declared in its catalog definition. All Heat-based templates must
 * support some subset of the same input parameters: network_name, physical_network, vlan, segments.
 *
 * The method returns a NetworkRollback object. This object can be passed as-is to the rollbackNetwork operation to
 * undo everything that was updated. This is useful if a network is successfully updated but orchestration fails on
 * a subsequent operation.
 */
public void updateNetwork(String cloudSiteId, String tenantId, String networkType, String modelCustomizationUuid, String networkId, String networkName, String physicalNetworkName, List<Integer> vlans, List<RouteTarget> routeTargets, String shared, String external, List<Subnet> subnets, List<String> policyFqdns, List<String> routeTableFqdns, MsoRequest msoRequest, Holder<String> stackId) throws NetworkException {
    logger.debug("***UPDATE Network adapter with Network: {} of type {} in {}/{}", networkName, networkType, cloudSiteId, tenantId);
    // Will capture execution time for metrics
    long startTime = System.currentTimeMillis();
    Optional<CloudSite> cloudSiteOpt = cloudConfig.getCloudSite(cloudSiteId);
    if (!cloudSiteOpt.isPresent()) {
        String error = String.format("UpdateNetwork: Configuration Error. Stack %s in %s/%s: CloudSite does not exist in MSO Configuration", networkName, cloudSiteId, tenantId);
        logger.error(LoggingAnchor.THREE, MessageEnum.RA_CONFIG_EXC, ErrorCode.DataError.getValue(), error);
        // Set the detailed error as the Exception 'message'
        throw new NetworkException(error, MsoExceptionCategory.USERDATA);
    }
    NetworkResource networkResource = networkCheck(startTime, networkType, modelCustomizationUuid, networkName, physicalNetworkName, vlans, routeTargets, cloudSiteId, cloudSiteOpt.get());
    String mode = networkResource.getOrchestrationMode();
    NetworkType neutronNetworkType = NetworkType.valueOf(networkResource.getNeutronNetworkType());
    if (NEUTRON_MODE.equals(mode)) {
        // Verify that the Network exists
        // For Neutron-based orchestration, the networkId is the Neutron Network UUID.
        NetworkInfo netInfo = null;
        try {
            netInfo = neutron.queryNetwork(networkId, tenantId, cloudSiteId);
        } catch (MsoException me) {
            me.addContext(UPDATE_NETWORK_CONTEXT);
            logger.error("{} {} Exception - queryNetwork query {} in {}/{} ", MessageEnum.RA_QUERY_NETWORK_EXC, ErrorCode.BusinessProcessError.getValue(), networkId, cloudSiteId, tenantId, me);
            throw new NetworkException(me);
        }
        if (netInfo == null) {
            String error = String.format("Update Nework: Network %s does not exist in %s/%s", networkId, cloudSiteId, tenantId);
            logger.error(LoggingAnchor.THREE, MessageEnum.RA_NETWORK_NOT_FOUND, ErrorCode.BusinessProcessError.getValue(), error);
            // Does not exist. Throw an exception (can't update a non-existent network)
            throw new NetworkException(error, MsoExceptionCategory.USERDATA);
        }
        try {
            netInfo = neutron.updateNetwork(cloudSiteId, tenantId, networkId, neutronNetworkType, physicalNetworkName, vlans);
        } catch (MsoException me) {
            me.addContext(UPDATE_NETWORK_CONTEXT);
            logger.error("{} {} Exception - updateNetwork {} in {}/{} ", MessageEnum.RA_UPDATE_NETWORK_ERR, ErrorCode.DataError.getValue(), networkId, cloudSiteId, tenantId, me);
            throw new NetworkException(me);
        }
        logger.debug("Network {} updated, id = {}", networkId, netInfo.getId());
    } else if ("HEAT".equals(mode)) {
        // First, look up to see that the Network already exists.
        // For Heat-based orchestration, the networkId is the network Stack ID.
        StackInfo heatStack = null;
        try {
            heatStack = heat.queryStack(cloudSiteId, CLOUD_OWNER, tenantId, networkName);
        } catch (MsoException me) {
            me.addContext(UPDATE_NETWORK_CONTEXT);
            logger.error("{} {} Exception - QueryStack query {} in {}/{} ", MessageEnum.RA_QUERY_NETWORK_EXC, ErrorCode.DataError.getValue(), networkId, cloudSiteId, tenantId, me);
            throw new NetworkException(me);
        }
        if (heatStack == null || (heatStack.getStatus() == HeatStatus.NOTFOUND)) {
            String error = String.format("UpdateNetwork: Stack %s does not exist in %s/%s", networkName, cloudSiteId, tenantId);
            logger.error(LoggingAnchor.THREE, MessageEnum.RA_NETWORK_NOT_FOUND, ErrorCode.DataError.getValue(), error);
            // Network stack does not exist. Return an error
            throw new NetworkException(error, MsoExceptionCategory.USERDATA);
        }
        // Get the previous parameters for rollback
        Map<String, Object> heatParams = heatStack.getParameters();
        List<Integer> previousVlans = new ArrayList<>();
        String vlansParam = (String) heatParams.get(VLANS);
        if (vlansParam != null) {
            for (String vlan : vlansParam.split(",")) {
                try {
                    previousVlans.add(Integer.parseInt(vlan));
                } catch (NumberFormatException e) {
                    logger.warn("{} {} Exception - VLAN parse for params {} ", MessageEnum.RA_VLAN_PARSE, ErrorCode.DataError.getValue(), vlansParam, e);
                }
            }
        }
        logger.debug("Update Stack:  Previous VLANS: {}", previousVlans);
        // Ready to deploy the updated Network via Heat
        HeatTemplate heatTemplate = networkResource.getHeatTemplate();
        if (heatTemplate == null) {
            String error = "Network error - undefined Heat Template. Network Type=" + networkType;
            logger.error(LoggingAnchor.THREE, MessageEnum.RA_PARAM_NOT_FOUND, ErrorCode.DataError.getValue(), error);
            throw new NetworkException(error, MsoExceptionCategory.INTERNAL);
        }
        logger.debug("Got HEAT Template from DB: {}", heatTemplate);
        // "Fix" the template if it has CR/LF (getting this from Oracle)
        String template = heatTemplate.getHeatTemplate();
        template = template.replaceAll("\r\n", "\n");
        boolean os3template = false;
        String os3nw = OS3_NW;
        os3nw = environment.getProperty(OS3_NW_PROPERTY, OS3_NW);
        if (template.contains(os3nw))
            os3template = true;
        // Build the common set of HEAT template parameters
        Map<String, Object> stackParams = populateNetworkParams(neutronNetworkType, networkName, physicalNetworkName, vlans, routeTargets, shared, external, os3template);
        // Shouldn't happen unless DB config is wrong, since all networks use same inputs
        try {
            stackParams = heat.validateStackParams(stackParams, heatTemplate);
        } catch (IllegalArgumentException e) {
            String error = "UpdateNetwork: Configuration Error: Network Type=" + networkType;
            logger.error(LoggingAnchor.THREE, MessageEnum.RA_CONFIG_EXC, ErrorCode.DataError.getValue(), error);
            throw new NetworkException(error, MsoExceptionCategory.INTERNAL, e);
        }
        if (subnets != null) {
            try {
                if (os3template) {
                    template = mergeSubnetsAIC3(template, subnets, stackParams);
                } else {
                    template = mergeSubnets(template, subnets);
                }
            } catch (MsoException me) {
                me.addContext(UPDATE_NETWORK_CONTEXT);
                logger.error("{} {} Exception - UpdateNetwork mergeSubnets for network type {} in {}/{} ", MessageEnum.RA_UPDATE_NETWORK_ERR, ErrorCode.DataError.getValue(), neutronNetworkType.toString(), cloudSiteId, tenantId, me);
                throw new NetworkException(me);
            }
        }
        if (policyFqdns != null && os3template) {
            try {
                mergePolicyRefs(policyFqdns, stackParams);
            } catch (MsoException me) {
                me.addContext(UPDATE_NETWORK_CONTEXT);
                logger.error("{} {} Exception - UpdateNetwork mergePolicyRefs type {} in {}/{} ", MessageEnum.RA_UPDATE_NETWORK_ERR, ErrorCode.DataError.getValue(), neutronNetworkType.toString(), cloudSiteId, tenantId, me);
                throw new NetworkException(me);
            }
        }
        if (routeTableFqdns != null && !routeTableFqdns.isEmpty() && os3template) {
            try {
                mergeRouteTableRefs(routeTableFqdns, stackParams);
            } catch (MsoException me) {
                me.addContext(UPDATE_NETWORK_CONTEXT);
                logger.error("{} {} Exception - UpdateNetwork mergeRouteTableRefs type {} in {}/{} ", MessageEnum.RA_UPDATE_NETWORK_ERR, ErrorCode.DataError.getValue(), neutronNetworkType.toString(), cloudSiteId, tenantId, me);
                throw new NetworkException(me);
            }
        }
        // Ignore MsoStackNotFound exception because we already checked.
        try {
            heatStack = heatWithUpdate.updateStack(cloudSiteId, CLOUD_OWNER, tenantId, networkId, template, stackParams, false, heatTemplate.getTimeoutMinutes());
        } catch (MsoException me) {
            me.addContext(UPDATE_NETWORK_CONTEXT);
            logger.error("{} {} Exception - update network {} in {}/{} ", MessageEnum.RA_UPDATE_NETWORK_ERR, ErrorCode.DataError.getValue(), networkId, cloudSiteId, tenantId, me);
            throw new NetworkException(me);
        }
        stackId.value = heatStack.getCanonicalName();
        logger.debug("Network {} successfully updated via HEAT", networkId);
    }
    return;
}
Also used : MsoException(org.onap.so.openstack.exceptions.MsoException) NetworkInfo(org.onap.so.openstack.beans.NetworkInfo) NetworkResource(org.onap.so.db.catalog.beans.NetworkResource) NetworkType(org.onap.so.openstack.utils.MsoNeutronUtils.NetworkType) HeatTemplate(org.onap.so.db.catalog.beans.HeatTemplate) CloudSite(org.onap.so.db.catalog.beans.CloudSite) List(java.util.List) ArrayList(java.util.ArrayList) NetworkException(org.onap.so.adapters.network.exceptions.NetworkException) StackInfo(org.onap.so.openstack.beans.StackInfo) Map(java.util.Map) HashMap(java.util.HashMap)

Example 10 with NetworkResource

use of org.onap.so.db.catalog.beans.NetworkResource in project so by onap.

the class MsoNetworkAdapterImpl method createNetwork.

/**
 * This is the "Create Network" web service implementation. It will create a new Network of the requested type in
 * the specified cloud and tenant. The tenant must exist at the time this service is called.
 *
 * If a network with the same name already exists, this can be considered a success or failure, depending on the
 * value of the 'failIfExists' parameter.
 *
 * There will be a pre-defined set of network types defined in the MSO Catalog. All such networks will have a
 * similar configuration, based on the allowable Openstack networking definitions. This includes basic networks,
 * provider networks (with a single VLAN), and multi-provider networks (one or more VLANs)
 *
 * Initially, all provider networks must be "vlan" type, and multiple segments in a multi-provider network must be
 * multiple VLANs on the same physical network.
 *
 * This service supports two modes of Network creation/update: - via Heat Templates - via Neutron API The network
 * orchestration mode for each network type is declared in its catalog definition. All Heat-based templates must
 * support some subset of the same input parameters: network_name, physical_network, vlan(s).
 *
 * The method returns the network ID and a NetworkRollback object. This latter object can be passed as-is to the
 * rollbackNetwork operation to undo everything that was created. This is useful if a network is successfully
 * created but the orchestration fails on a subsequent operation.
 */
public void createNetwork(String cloudSiteId, String tenantId, String networkType, String modelCustomizationUuid, String networkName, String physicalNetworkName, List<Integer> vlans, List<RouteTarget> routeTargets, String shared, String external, Boolean failIfExists, Boolean backout, List<Subnet> subnets, List<String> policyFqdns, List<String> routeTableFqdns, MsoRequest msoRequest, Holder<String> stackId, MutableBoolean isOs3Nw) throws NetworkException {
    logger.debug("*** CREATE Network: {} of type {} in {}/{}", networkName, networkType, cloudSiteId, tenantId);
    // Will capture execution time for metrics
    long startTime = System.currentTimeMillis();
    Optional<CloudSite> cloudSiteOpt = cloudConfig.getCloudSite(cloudSiteId);
    if (!cloudSiteOpt.isPresent()) {
        String error = String.format("Configuration Error. Stack %s in %s/%s: CloudSite does not exist in MSO Configuration", networkName, cloudSiteId, tenantId);
        logger.error(LoggingAnchor.THREE, MessageEnum.RA_CONFIG_EXC, ErrorCode.DataError.getValue(), error);
        // Set the detailed error as the Exception 'message'
        throw new NetworkException(error, MsoExceptionCategory.USERDATA);
    }
    NetworkResource networkResource = networkCheck(startTime, networkType, modelCustomizationUuid, networkName, physicalNetworkName, vlans, routeTargets, cloudSiteId, cloudSiteOpt.get());
    NetworkType neutronNetworkType = NetworkType.valueOf(networkResource.getNeutronNetworkType());
    HeatTemplate heatTemplate = networkResource.getHeatTemplate();
    if (heatTemplate == null) {
        String error = String.format("Network error - undefined Heat Template. Network Type = %s", networkType);
        logger.error(LoggingAnchor.THREE, MessageEnum.RA_PARAM_NOT_FOUND, ErrorCode.DataError.getValue(), error);
        throw new NetworkException(error, MsoExceptionCategory.INTERNAL);
    }
    logger.debug("Got HEAT Template from DB: {}", heatTemplate);
    // "Fix" the template if it has CR/LF (getting this from Oracle)
    String template = heatTemplate.getHeatTemplate();
    template = template.replaceAll("\r\n", "\n");
    boolean os3template = false;
    String os3nw = environment.getProperty(OS3_NW_PROPERTY, OS3_NW);
    if (template.contains(os3nw))
        os3template = true;
    isOs3Nw.setValue(os3template);
    // First, look up to see if the Network already exists (by name).
    // For HEAT orchestration of networks, the stack name will always match the network name
    StackInfo heatStack = null;
    try {
        heatStack = heat.queryStack(cloudSiteId, CLOUD_OWNER, tenantId, networkName);
    } catch (MsoException me) {
        me.addContext(CREATE_NETWORK_CONTEXT);
        logger.error("{} {} Create Network (heat): query network {} in {}/{}: ", MessageEnum.RA_QUERY_NETWORK_EXC, ErrorCode.DataError.getValue(), networkName, cloudSiteId, tenantId, me);
        throw new NetworkException(me);
    }
    if (heatStack != null && (heatStack.getStatus() != HeatStatus.NOTFOUND)) {
        // Stack exists. Return success or error depending on input directive
        if (failIfExists != null && failIfExists) {
            String error = String.format("CreateNetwork: Stack %s already exists in %s/%s as %s", networkName, cloudSiteId, tenantId, heatStack.getCanonicalName());
            logger.error(LoggingAnchor.THREE, MessageEnum.RA_NETWORK_ALREADY_EXIST, ErrorCode.DataError.getValue(), error);
            throw new NetworkException(error, MsoExceptionCategory.USERDATA);
        } else {
            logger.warn("{} {} Found Existing network stack, status={} networkName={} for {}/{}", MessageEnum.RA_NETWORK_ALREADY_EXIST, ErrorCode.DataError.getValue(), heatStack.getStatus(), networkName, cloudSiteId, tenantId);
        }
        heat.updateResourceStatus(msoRequest.getRequestId(), NETWORK_EXIST_STATUS_MESSAGE);
        return;
    }
    // Ready to deploy the new Network
    // Build the common set of HEAT template parameters
    Map<String, Object> stackParams = populateNetworkParams(neutronNetworkType, networkName, physicalNetworkName, vlans, routeTargets, shared, external, os3template);
    // and inputs were already validated.
    try {
        stackParams = heat.validateStackParams(stackParams, heatTemplate);
    } catch (IllegalArgumentException e) {
        String error = "Create Network: Configuration Error: " + e.getMessage();
        logger.error(LoggingAnchor.THREE, MessageEnum.RA_CONFIG_EXC, ErrorCode.DataError.getValue(), error, e);
        // Input parameters were not valid
        throw new NetworkException(error, MsoExceptionCategory.INTERNAL);
    }
    if (subnets != null) {
        try {
            if (os3template) {
                template = mergeSubnetsAIC3(template, subnets, stackParams);
            } else {
                template = mergeSubnets(template, subnets);
            }
        } catch (MsoException me) {
            me.addContext(CREATE_NETWORK_CONTEXT);
            logger.error("{} {} Exception Create Network, merging subnets for network (heat) type {} in {}/{} ", MessageEnum.RA_CREATE_NETWORK_EXC, ErrorCode.DataError.getValue(), neutronNetworkType.toString(), cloudSiteId, tenantId, me);
            throw new NetworkException(me);
        }
    }
    if (policyFqdns != null && !policyFqdns.isEmpty() && os3template) {
        try {
            mergePolicyRefs(policyFqdns, stackParams);
        } catch (MsoException me) {
            me.addContext(CREATE_NETWORK_CONTEXT);
            logger.error("{} {} Exception Create Network, merging policyRefs type {} in {}/{} ", MessageEnum.RA_CREATE_NETWORK_EXC, ErrorCode.DataError.getValue(), neutronNetworkType.toString(), cloudSiteId, tenantId, me);
            throw new NetworkException(me);
        }
    }
    if (routeTableFqdns != null && !routeTableFqdns.isEmpty() && os3template) {
        try {
            mergeRouteTableRefs(routeTableFqdns, stackParams);
        } catch (MsoException me) {
            me.addContext(CREATE_NETWORK_CONTEXT);
            logger.error("{} {} Exception Create Network, merging routeTableRefs type {} in {}/{} ", MessageEnum.RA_CREATE_NETWORK_EXC, ErrorCode.DataError.getValue(), neutronNetworkType.toString(), cloudSiteId, tenantId, me);
            throw new NetworkException(me);
        }
    }
    // Ignore MsoStackAlreadyExists exception because we already checked.
    try {
        if (backout == null)
            backout = true;
        heatStack = heat.createStack(cloudSiteId, CLOUD_OWNER, tenantId, networkName, null, template, stackParams, false, heatTemplate.getTimeoutMinutes(), null, null, null, backout.booleanValue(), failIfExists);
    } catch (MsoException me) {
        me.addContext(CREATE_NETWORK_CONTEXT);
        logger.error("{} {} Exception creating network type {} in {}/{} ", MessageEnum.RA_CREATE_NETWORK_EXC, ErrorCode.DataError.getValue(), networkName, cloudSiteId, tenantId, me);
        throw new NetworkException(me);
    }
    // Reach this point if createStack is successful.
    stackId.value = heatStack.getCanonicalName();
    try {
        heat.updateResourceStatus(msoRequest.getRequestId(), NETWORK_CREATED_STATUS_MESSAGE);
    } catch (Exception e) {
        logger.warn("Exception while updating infra active request", e);
    }
    logger.debug("Network {} successfully created via HEAT", networkName);
    return;
}
Also used : MsoException(org.onap.so.openstack.exceptions.MsoException) NetworkException(org.onap.so.adapters.network.exceptions.NetworkException) MsoException(org.onap.so.openstack.exceptions.MsoException) MsoAdapterException(org.onap.so.openstack.exceptions.MsoAdapterException) NetworkResource(org.onap.so.db.catalog.beans.NetworkResource) NetworkType(org.onap.so.openstack.utils.MsoNeutronUtils.NetworkType) HeatTemplate(org.onap.so.db.catalog.beans.HeatTemplate) CloudSite(org.onap.so.db.catalog.beans.CloudSite) NetworkException(org.onap.so.adapters.network.exceptions.NetworkException) StackInfo(org.onap.so.openstack.beans.StackInfo)

Aggregations

NetworkResource (org.onap.so.db.catalog.beans.NetworkResource)14 NetworkResourceCustomization (org.onap.so.db.catalog.beans.NetworkResourceCustomization)8 HeatTemplate (org.onap.so.db.catalog.beans.HeatTemplate)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 NetworkException (org.onap.so.adapters.network.exceptions.NetworkException)3 CollectionNetworkResourceCustomization (org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization)3 Service (org.onap.so.db.catalog.beans.Service)3 MsoException (org.onap.so.openstack.exceptions.MsoException)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Metadata (org.onap.sdc.toscaparser.api.elements.Metadata)2 AllottedResource (org.onap.so.db.catalog.beans.AllottedResource)2 TempNetworkHeatTemplateLookup (org.onap.so.db.catalog.beans.TempNetworkHeatTemplateLookup)2 NetworkType (org.onap.so.openstack.utils.MsoNeutronUtils.NetworkType)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)1 WireMock.post (com.github.tomakehurst.wiremock.client.WireMock.post)1 WireMock.urlPathEqualTo (com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo)1