Search in sources :

Example 1 with NetworkException

use of org.onap.so.adapters.network.exceptions.NetworkException 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 2 with NetworkException

use of org.onap.so.adapters.network.exceptions.NetworkException 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 3 with NetworkException

use of org.onap.so.adapters.network.exceptions.NetworkException in project so by onap.

the class MsoNetworkAdapterImpl method rollbackNetwork.

/**
 * This web service endpoint will rollback a previous Create VNF operation. A rollback object is returned to the
 * client in a successful creation response. The client can pass that object as-is back to the rollbackVnf operation
 * to undo the creation.
 *
 * The rollback includes removing the VNF and deleting the tenant if the tenant did not exist prior to the VNF
 * creation.
 */
public void rollbackNetwork(NetworkRollback rollback) throws NetworkException {
    if (rollback == null) {
        logger.error("{} {} rollback is null", MessageEnum.RA_ROLLBACK_NULL, ErrorCode.DataError.getValue());
        return;
    }
    // Get the elements of the VnfRollback object for easier access
    String cloudSiteId = rollback.getCloudId();
    String tenantId = rollback.getTenantId();
    String networkId = rollback.getNetworkStackId();
    logger.debug("*** ROLLBACK Network {} in {}/{}", networkId, cloudSiteId, tenantId);
    if (rollback.getNetworkCreated()) {
        try {
            heat.deleteStack(tenantId, CLOUD_OWNER, cloudSiteId, networkId, false, 120);
        } catch (MsoException me) {
            me.addContext("RollbackNetwork");
            logger.error("{} {} Exception - Rollback Network (heat): {} in {}/{} ", MessageEnum.RA_DELETE_NETWORK_EXC, ErrorCode.BusinessProcessError.getValue(), networkId, cloudSiteId, tenantId, me);
            throw new NetworkException(me);
        }
    }
}
Also used : MsoException(org.onap.so.openstack.exceptions.MsoException) NetworkException(org.onap.so.adapters.network.exceptions.NetworkException)

Example 4 with NetworkException

use of org.onap.so.adapters.network.exceptions.NetworkException 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)

Example 5 with NetworkException

use of org.onap.so.adapters.network.exceptions.NetworkException in project so by onap.

the class MsoNetworkAdapterImpl method deleteNetwork.

/**
 * This is the "Delete Network" web service implementation. It will delete a Network in the specified cloud and
 * tenant.
 *
 * If the network is not found, it is treated as a success.
 *
 * This service supports two modes of Network creation/update/delete: - via Heat Templates - via Neutron API The
 * network orchestration mode for each network type is declared in its catalog definition.
 *
 * For Heat-based orchestration, the networkId should be the stack ID. For Neutron-based orchestration, the
 * networkId should be the Neutron network UUID.
 *
 * The method returns nothing on success. Rollback is not possible for delete commands, so any failure on delete
 * will require manual fallout in the client.
 */
public void deleteNetwork(String cloudSiteId, String tenantId, String networkType, String modelCustomizationUuid, String networkId, MsoRequest msoRequest) throws NetworkException {
    logger.debug("*** DELETE Network adapter with Network: {} in {}/{}", networkId, cloudSiteId, tenantId);
    if (commonUtils.isNullOrEmpty(cloudSiteId) || commonUtils.isNullOrEmpty(tenantId) || commonUtils.isNullOrEmpty(networkId)) {
        String error = "Missing mandatory parameter cloudSiteId, tenantId or networkId";
        logger.error(LoggingAnchor.THREE, MessageEnum.RA_MISSING_PARAM, ErrorCode.DataError.getValue(), error);
        throw new NetworkException(error, MsoExceptionCategory.USERDATA);
    }
    int timeoutMinutes = heat.getNetworkHeatTimeoutValue(modelCustomizationUuid, networkType);
    boolean networkDeleted = false;
    try {
        StackInfo stack = heat.deleteStack(tenantId, CLOUD_OWNER, cloudSiteId, networkId, false, timeoutMinutes);
        networkDeleted = stack.isOperationPerformed();
    } catch (MsoException me) {
        me.addContext("DeleteNetwork");
        logger.error("{} {} Delete Network (heat): {} in {}/{} ", MessageEnum.RA_DELETE_NETWORK_EXC, ErrorCode.DataError.getValue(), networkId, cloudSiteId, tenantId, me);
        throw new NetworkException(me);
    }
    try {
        heat.updateResourceStatus(msoRequest.getRequestId(), networkDeleted ? NETWORK_DELETED_STATUS_MESSAGE : NETWORK_NOT_EXIST_STATUS_MESSAGE);
    } catch (Exception e) {
        logger.warn("Exception while updating infra active request", e);
    }
}
Also used : MsoException(org.onap.so.openstack.exceptions.MsoException) NetworkException(org.onap.so.adapters.network.exceptions.NetworkException) StackInfo(org.onap.so.openstack.beans.StackInfo) NetworkException(org.onap.so.adapters.network.exceptions.NetworkException) MsoException(org.onap.so.openstack.exceptions.MsoException) MsoAdapterException(org.onap.so.openstack.exceptions.MsoAdapterException)

Aggregations

NetworkException (org.onap.so.adapters.network.exceptions.NetworkException)5 MsoException (org.onap.so.openstack.exceptions.MsoException)4 NetworkResource (org.onap.so.db.catalog.beans.NetworkResource)3 StackInfo (org.onap.so.openstack.beans.StackInfo)3 NetworkType (org.onap.so.openstack.utils.MsoNeutronUtils.NetworkType)3 CloudSite (org.onap.so.db.catalog.beans.CloudSite)2 HeatTemplate (org.onap.so.db.catalog.beans.HeatTemplate)2 MsoAdapterException (org.onap.so.openstack.exceptions.MsoAdapterException)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 CollectionNetworkResourceCustomization (org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization)1 NetworkResourceCustomization (org.onap.so.db.catalog.beans.NetworkResourceCustomization)1 MavenLikeVersioning (org.onap.so.db.catalog.utils.MavenLikeVersioning)1 NetworkInfo (org.onap.so.openstack.beans.NetworkInfo)1