Search in sources :

Example 6 with VduException

use of org.onap.so.adapters.vdu.VduException in project so by onap.

the class MsoHeatUtils method instantiateVdu.

/**
 *****************************************************************************
 *
 * Methods (and associated utilities) to implement the VduPlugin interface
 *
 ******************************************************************************
 */
/**
 * VduPlugin interface for instantiate function.
 *
 * Translate the VduPlugin parameters to the corresponding 'createStack' parameters, and then invoke the existing
 * function.
 */
@Override
public VduInstance instantiateVdu(CloudInfo cloudInfo, String instanceName, Map<String, Object> inputs, VduModelInfo vduModel, boolean rollbackOnFailure) throws VduException {
    String cloudSiteId = cloudInfo.getCloudSiteId();
    String cloudOwner = cloudInfo.getCloudOwner();
    String tenantId = cloudInfo.getTenantId();
    // Translate the VDU ModelInformation structure to that which is needed for
    // creating the Heat stack. Loop through the artifacts, looking specifically
    // for MAIN_TEMPLATE and ENVIRONMENT. Any other artifact will
    // be attached as a FILE.
    String heatTemplate = null;
    Map<String, Object> nestedTemplates = new HashMap<>();
    Map<String, Object> files = new HashMap<>();
    String heatEnvironment = null;
    for (VduArtifact vduArtifact : vduModel.getArtifacts()) {
        if (vduArtifact.getType() == ArtifactType.MAIN_TEMPLATE) {
            heatTemplate = new String(vduArtifact.getContent());
        } else if (vduArtifact.getType() == ArtifactType.NESTED_TEMPLATE) {
            nestedTemplates.put(vduArtifact.getName(), new String(vduArtifact.getContent()));
        } else if (vduArtifact.getType() == ArtifactType.ENVIRONMENT) {
            heatEnvironment = new String(vduArtifact.getContent());
        }
    }
    try {
        StackInfo stackInfo = createStack(cloudSiteId, cloudOwner, tenantId, instanceName, vduModel, heatTemplate, // poll
        inputs, // poll
        true, // completion
        vduModel.getTimeoutMinutes(), heatEnvironment, nestedTemplates, files, rollbackOnFailure, false);
        // Populate a vduInstance from the StackInfo
        return stackInfoToVduInstance(stackInfo);
    } catch (Exception e) {
        throw new VduException("MsoHeatUtils (instantiateVDU): createStack Exception", e);
    }
}
Also used : HashMap(java.util.HashMap) StackInfo(org.onap.so.openstack.beans.StackInfo) VduArtifact(org.onap.so.adapters.vdu.VduArtifact) VduException(org.onap.so.adapters.vdu.VduException) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) MsoException(org.onap.so.openstack.exceptions.MsoException) MsoOpenstackException(org.onap.so.openstack.exceptions.MsoOpenstackException) IOException(java.io.IOException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) VduException(org.onap.so.adapters.vdu.VduException)

Example 7 with VduException

use of org.onap.so.adapters.vdu.VduException in project so by onap.

the class MsoHeatUtils method deleteVdu.

/**
 * VduPlugin interface for delete function.
 */
@Override
public VduInstance deleteVdu(CloudInfo cloudInfo, String instanceId, int timeoutMinutes) throws VduException {
    String cloudSiteId = cloudInfo.getCloudSiteId();
    String cloudOwner = cloudInfo.getCloudOwner();
    String tenantId = cloudInfo.getTenantId();
    try {
        // Delete the Heat stack
        StackInfo stackInfo = deleteStack(tenantId, cloudOwner, cloudSiteId, instanceId, true, timeoutMinutes);
        // Populate a VduInstance based on the deleted Cloudify Deployment object
        VduInstance vduInstance = stackInfoToVduInstance(stackInfo);
        // Override return state to DELETED (HeatUtils sets to NOTFOUND)
        vduInstance.getStatus().setState(VduStateType.DELETED);
        return vduInstance;
    } catch (Exception e) {
        throw new VduException("Delete VDU Exception", e);
    }
}
Also used : VduInstance(org.onap.so.adapters.vdu.VduInstance) StackInfo(org.onap.so.openstack.beans.StackInfo) VduException(org.onap.so.adapters.vdu.VduException) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) MsoException(org.onap.so.openstack.exceptions.MsoException) MsoOpenstackException(org.onap.so.openstack.exceptions.MsoOpenstackException) IOException(java.io.IOException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) VduException(org.onap.so.adapters.vdu.VduException)

Example 8 with VduException

use of org.onap.so.adapters.vdu.VduException in project so by onap.

the class MsoVnfPluginAdapterImpl method createVfModule.

/**
 * This is the "Create VF Module" web service implementation. It will instantiate a new VF Module of the requested
 * type in the specified cloud and tenant. The tenant must exist before this service is called.
 *
 * If a VF Module with the same name already exists, this can be considered a success or failure, depending on the
 * value of the 'failIfExists' parameter.
 *
 * All VF Modules are defined in the MSO catalog. The caller must request one of the pre-defined module types or an
 * error will be returned. Within the catalog, each VF Module references (among other things) a collection of
 * artifacts that are used to deploy the required cloud resources (VMs, networks, etc.).
 *
 * Depending on the module templates, a variable set of input parameters will be defined, some of which are
 * required. The caller is responsible to pass the necessary input data for the module or an error will be thrown.
 *
 * The method returns the vfModuleId, a Map of output attributes, and a VnfRollback object. This last object can be
 * passed as-is to the rollbackVnf operation to undo everything that was created for the Module. This is useful if a
 * VF module is successfully created but the orchestration fails on a subsequent step.
 *
 * @param cloudSiteId CLLI code of the cloud site in which to create the VNF
 * @param cloudOwner cloud owner of the cloud site in which to create the VNF
 * @param tenantId Openstack tenant identifier
 * @param vfModuleType VF Module type key, should match a VNF definition in catalog DB. Deprecated - should use
 *        modelCustomizationUuid
 * @param vnfVersion VNF version key, should match a VNF definition in catalog DB Deprecated - VF Module versions
 *        also captured by modelCustomizationUuid
 * @param vnfId - VNF ID
 * @param vfModuleName Name to be assigned to the new VF Module
 * @param vfModuleId Id fo the new VF Module
 * @param requestType Indicates if this is a Volume Group or Module request
 * @param volumeGroupId Identifier (i.e. deployment ID) for a Volume Group to attach to a VF Module
 * @param baseVfModuleId Identifier (i.e. deployment ID) of the Base Module if this is an Add-on module
 * @param modelCustomizationUuid Unique ID for the VF Module's model. Replaces the use of vfModuleType.
 * @param inputs Map of key=value inputs for VNF stack creation
 * @param failIfExists Flag whether already existing VNF should be considered
 * @param backout Flag whether to suppress automatic backout (for testing)
 * @param msoRequest Request tracking information for logs
 * @param vnfId Holder for output VF Module instance ID in the cloud
 * @param outputs Holder for Map of VNF outputs from Deployment (assigned IPs, etc)
 * @param rollback Holder for returning VnfRollback object
 */
public void createVfModule(String cloudSiteId, String cloudOwner, String tenantId, String vfModuleType, String vnfVersion, String genericVnfId, String vfModuleName, String vfModuleId, String requestType, String volumeGroupId, String baseVfModuleId, String modelCustomizationUuid, Map<String, Object> inputs, Boolean failIfExists, Boolean backout, Boolean enableBridge, MsoRequest msoRequest, Holder<String> vnfId) throws VnfException {
    // Will capture execution time for metrics
    long startTime = System.currentTimeMillis();
    // Require a model customization ID. Every VF Module definition must have one.
    if (modelCustomizationUuid == null || modelCustomizationUuid.isEmpty()) {
        logger.debug("Missing required input: modelCustomizationUuid");
        String error = "Create vfModule error: Missing required input: modelCustomizationUuid";
        logger.error("{} {} {} {} {}", MessageEnum.RA_VNF_UNKNOWN_PARAM.toString(), "VF Module ModelCustomizationUuid", "VDU", ErrorCode.DataError, "Create VF Module: " + "Missing required input: modelCustomizationUuid");
        logger.debug(error);
        throw new VnfException(error, MsoExceptionCategory.USERDATA);
    }
    // Clean up some inputs to make comparisons easier
    if (requestType == null)
        requestType = "";
    if ("".equals(volumeGroupId) || "null".equals(volumeGroupId))
        volumeGroupId = null;
    if ("".equals(baseVfModuleId) || "null".equals(baseVfModuleId))
        baseVfModuleId = null;
    if (inputs == null) {
        // Create an empty set of inputs
        inputs = new HashMap<>();
        logger.debug("inputs == null - setting to empty");
    } else {
        this.sendMapToDebug(inputs);
    }
    // Check if this is for a "Volume" module
    boolean isVolumeRequest = false;
    if (requestType.startsWith("VOLUME")) {
        isVolumeRequest = true;
    }
    logger.debug("requestType = " + requestType + ", volumeGroupStackId = " + volumeGroupId + ", baseStackId = " + baseVfModuleId);
    // Get the VNF/VF Module definition from the Catalog DB first.
    // There are three relevant records: VfModule, VfModuleCustomization, VnfResource
    VfModule vfModule = null;
    VnfResource vnfResource = null;
    VfModuleCustomization vfModuleCust = null;
    try {
        vfModuleCust = vfModuleCustomRepo.findFirstByModelCustomizationUUIDOrderByCreatedDesc(modelCustomizationUuid);
        if (vfModuleCust == null) {
            String error = "Create vfModule error: Unable to find vfModuleCust with modelCustomizationUuid=" + modelCustomizationUuid;
            logger.debug(error);
            logger.error("{} {} {} {} {} {}", MessageEnum.RA_VNF_UNKNOWN_PARAM.toString(), "VF Module ModelCustomizationUuid", modelCustomizationUuid, "CatalogDb", ErrorCode.DataError, error);
            throw new VnfException(error, MsoExceptionCategory.USERDATA);
        } else {
            logger.debug("Found vfModuleCust entry {}", vfModuleCust.toString());
        }
        // Get the vfModule and vnfResource records
        vfModule = vfModuleCust.getVfModule();
        vnfResource = vfModuleCust.getVfModule().getVnfResources();
    } catch (Exception e) {
        logger.debug("unhandled exception in create VF - [Query]" + e.getMessage());
        throw new VnfException("Exception during create VF " + e.getMessage());
    }
    // Perform a version check against cloudSite
    // Obtain the cloud site information where we will create the VF Module
    Optional<CloudSite> cloudSiteOp = cloudConfig.getCloudSite(cloudSiteId);
    if (!cloudSiteOp.isPresent()) {
        // If cloudSiteId is not present in the catalog DB, then default to multicloud
        logger.debug("{} is not present in cloud_site catalog DB, defaulting to Multicloud plugin adapter", cloudSiteId);
    } else {
        CloudSite cloudSite = cloudSiteOp.get();
        MavenLikeVersioning aicV = new MavenLikeVersioning();
        aicV.setVersion(cloudSite.getCloudVersion());
        String vnfMin = vnfResource.getAicVersionMin();
        String vnfMax = vnfResource.getAicVersionMax();
        if ((vnfMin != null && !(aicV.isMoreRecentThan(vnfMin) || aicV.isTheSameVersion(vnfMin))) || (vnfMax != null && aicV.isMoreRecentThan(vnfMax))) {
            // ERROR
            String error = "VNF Resource type: " + vnfResource.getModelName() + ", ModelUuid=" + vnfResource.getModelUUID() + " VersionMin=" + vnfMin + " VersionMax:" + vnfMax + " NOT supported on Cloud: " + cloudSiteId + " with AIC_Version:" + cloudSite.getCloudVersion();
            logger.error("{} {} {} {} {}", MessageEnum.RA_CONFIG_EXC.toString(), error, "OpenStack", ErrorCode.BusinessProcessError.getValue(), "Exception - setVersion");
            logger.debug(error);
            throw new VnfException(error, MsoExceptionCategory.USERDATA);
        }
    }
    // End Version check
    VduInstance vduInstance = null;
    CloudInfo cloudInfo = new CloudInfo(cloudSiteId, cloudOwner, tenantId, null);
    // Use the VduPlugin.
    VduPlugin vduPlugin = getVduPlugin(cloudSiteId, cloudOwner);
    long subStartTime1 = System.currentTimeMillis();
    try {
        vduInstance = vduPlugin.queryVdu(cloudInfo, vfModuleName);
    } catch (VduException me) {
        // Failed to query the VDU due to a plugin exception.
        String error = "Create VF Module: Query " + vfModuleName + " in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId + ": " + me;
        logger.error("{} {} {} {} {} {} {} {} {}", MessageEnum.RA_QUERY_VNF_ERR.toString(), vfModuleName, cloudOwner, cloudSiteId, tenantId, "VDU", "queryVdu", ErrorCode.DataError.getValue(), "Exception - queryVdu", me);
        logger.debug(error);
        // Convert to a generic VnfException
        me.addContext("CreateVFModule");
        throw new VnfException(me);
    }
    // More precise handling/messaging if the Module already exists
    if (vduInstance != null && !(vduInstance.getStatus().getState() == VduStateType.NOTFOUND)) {
        VduStateType status = vduInstance.getStatus().getState();
        logger.debug("Found Existing VDU, status=" + status);
        if (status == VduStateType.INSTANTIATED) {
            if (failIfExists != null && failIfExists) {
                // fail - it exists
                String error = "Create VF: Deployment " + vfModuleName + " already exists in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId;
                logger.error("{} {} {} {} {} {} {} {} {}", MessageEnum.RA_VNF_ALREADY_EXIST.toString(), vfModuleName, cloudOwner, cloudSiteId, tenantId, "VDU", "queryVdu", ErrorCode.DataError.getValue(), "VF Module " + vfModuleName + " already exists");
                logger.debug(error);
                throw new VnfAlreadyExists(vfModuleName, cloudSiteId, cloudOwner, tenantId, vduInstance.getVduInstanceId());
            } else {
                // Found existing deployment and client has not requested "failIfExists".
                // Populate the outputs from the existing deployment.
                vnfId.value = vduInstance.getVduInstanceId();
                return;
            }
        } else // Check through various detailed error cases
        if (status == VduStateType.INSTANTIATING || status == VduStateType.DELETING || status == VduStateType.UPDATING) {
            // fail - it's in progress - return meaningful error
            String error = "Create VF: Deployment " + vfModuleName + " already exists and has status " + status.toString() + " in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId + "; please wait for it to complete, or fix manually.";
            logger.error("{} {} {} {} {} {} {} {} {}", MessageEnum.RA_VNF_ALREADY_EXIST.toString(), vfModuleName, cloudOwner, cloudSiteId, tenantId, "VDU", "queryVdu", ErrorCode.DataError.getValue(), "VF Module " + vfModuleName + " already exists");
            logger.debug(error);
            throw new VnfAlreadyExists(vfModuleName, cloudSiteId, cloudOwner, tenantId, vduInstance.getVduInstanceId());
        } else if (status == VduStateType.FAILED) {
            // fail - it exists and is in a FAILED state
            String error = "Create VF: Deployment " + vfModuleName + " already exists and is in FAILED state in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId + "; requires manual intervention.";
            logger.error("{} {} {} {} {} {} {} {} {}", MessageEnum.RA_VNF_ALREADY_EXIST.toString(), vfModuleName, cloudOwner, cloudSiteId, tenantId, "VDU", "queryVdu", ErrorCode.DataError.getValue(), "VF Module " + vfModuleName + " already exists and is in FAILED state");
            logger.debug(error);
            throw new VnfAlreadyExists(vfModuleName, cloudSiteId, cloudOwner, tenantId, vduInstance.getVduInstanceId());
        } else if (status == VduStateType.UNKNOWN) {
            // fail - it exists and is in a UNKNOWN state
            String error = "Create VF: Deployment " + vfModuleName + " already exists and has status " + status.toString() + " in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId + "; requires manual intervention.";
            logger.error("{} {} {} {} {} {} {} {} {}", MessageEnum.RA_VNF_ALREADY_EXIST.toString(), vfModuleName, cloudOwner, cloudSiteId, tenantId, "VDU", "queryVdu", ErrorCode.DataError.getValue(), "VF Module " + vfModuleName + " already exists and is in " + status.toString() + " state");
            logger.debug(error);
            throw new VnfAlreadyExists(vfModuleName, cloudSiteId, cloudOwner, tenantId, vduInstance.getVduInstanceId());
        } else {
            // Unexpected, since all known status values have been tested for
            String error = "Create VF: Deployment " + vfModuleName + " already exists with unexpected status " + status.toString() + " in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId + "; requires manual intervention.";
            logger.error("{} {} {} {} {} {} {} {} {}", MessageEnum.RA_VNF_ALREADY_EXIST.toString(), vfModuleName, cloudOwner, cloudSiteId, tenantId, "VDU", "queryVdu", ErrorCode.DataError.getValue(), "VF Module " + vfModuleName + " already exists and is in an unknown state");
            logger.debug(error);
            throw new VnfAlreadyExists(vfModuleName, cloudSiteId, cloudOwner, tenantId, vduInstance.getVduInstanceId());
        }
    }
    // Collect outputs from Base Modules and Volume Modules
    Map<String, Object> baseModuleOutputs = null;
    Map<String, Object> volumeGroupOutputs = null;
    // If a Volume Group was provided, query its outputs for inclusion in Module input parameters
    if (volumeGroupId != null) {
        long subStartTime2 = System.currentTimeMillis();
        VduInstance volumeVdu = null;
        try {
            volumeVdu = vduPlugin.queryVdu(cloudInfo, volumeGroupId);
        } catch (VduException me) {
            // Failed to query the Volume Group VDU due to a plugin exception.
            String error = "Create VF Module: Query Volume Group " + volumeGroupId + " in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId + ": " + me;
            logger.error("{} {} {} {} {} {} {} {} {}", MessageEnum.RA_QUERY_VNF_ERR.toString(), volumeGroupId, cloudOwner, cloudSiteId, tenantId, "VDU", "queryVdu(volume)", ErrorCode.DataError.getValue(), "Exception - queryVdu(volume)", me);
            logger.debug(error);
            // Convert to a generic VnfException
            me.addContext("CreateVFModule(QueryVolume)");
            throw new VnfException(me);
        }
        if (volumeVdu == null || volumeVdu.getStatus().getState() == VduStateType.NOTFOUND) {
            String error = "Create VFModule: Attached Volume Group DOES NOT EXIST " + volumeGroupId + " in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId + " USER ERROR";
            logger.error("{} {} {} {} {} {} {} {} {} {}", MessageEnum.RA_QUERY_VNF_ERR.toString(), volumeGroupId, cloudOwner, cloudSiteId, tenantId, error, "VDU", "queryVdu(volume)", ErrorCode.BusinessProcessError.getValue(), "Create VFModule: Attached Volume Group " + "DOES NOT EXIST");
            logger.debug(error);
            throw new VnfException(error, MsoExceptionCategory.USERDATA);
        } else {
            logger.debug("Found nested volume group");
            volumeGroupOutputs = volumeVdu.getOutputs();
            this.sendMapToDebug(volumeGroupOutputs, "volumeGroupOutputs");
        }
    }
    if (vfModule.getIsBase()) {
        logger.debug("This is a BASE Module request");
    } else {
        logger.debug("This is an Add-On Module request");
        // Add-on Volume requests may or may not specify a base.
        if (!isVolumeRequest && baseVfModuleId == null) {
            logger.debug("WARNING:  Add-on Module request - no Base Module ID provided");
        }
        if (baseVfModuleId != null) {
            long subStartTime2 = System.currentTimeMillis();
            VduInstance baseVdu = null;
            try {
                baseVdu = vduPlugin.queryVdu(cloudInfo, baseVfModuleId);
            } catch (MsoException me) {
                // Failed to query the Base VF Module due to a Vdu Plugin exception.
                String error = "Create VF Module: Query Base " + baseVfModuleId + " in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId + ": " + me;
                logger.error("{} {} {} {} {} {} {} {} {}", MessageEnum.RA_QUERY_VNF_ERR.toString(), baseVfModuleId, cloudOwner, cloudSiteId, tenantId, "VDU", "queryVdu(Base)", ErrorCode.DataError.getValue(), "Exception - queryVdu(Base)", me);
                logger.debug(error);
                // Convert to a generic VnfException
                me.addContext("CreateVFModule(QueryBase)");
                throw new VnfException(me);
            }
            if (baseVdu == null || baseVdu.getStatus().getState() == VduStateType.NOTFOUND) {
                String error = "Create VFModule: Base Module DOES NOT EXIST " + baseVfModuleId + " in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId + " USER ERROR";
                logger.error("{} {} {} {} {} {} {} {} {} {}", MessageEnum.RA_QUERY_VNF_ERR.toString(), baseVfModuleId, cloudOwner, cloudSiteId, tenantId, error, "VDU", "queryVdu(Base)", ErrorCode.BusinessProcessError.getValue(), "Create VFModule: Base Module DOES NOT EXIST");
                logger.debug(error);
                throw new VnfException(error, MsoExceptionCategory.USERDATA);
            } else {
                logger.debug("Found base module");
                baseModuleOutputs = baseVdu.getOutputs();
                this.sendMapToDebug(baseModuleOutputs, "baseModuleOutputs");
            }
        }
    }
    // NOTE: For this section, heatTemplate is used for all template artifacts.
    // In final implementation (post-POC), the template object would either be generic or there would
    // be a separate DB Table/Object for different sub-orchestrators.
    // NOTE: The template is fixed for the VF Module. The environment is part of the customization.
    HeatTemplate heatTemplate = null;
    HeatEnvironment heatEnvironment = null;
    if (isVolumeRequest) {
        heatTemplate = vfModule.getVolumeHeatTemplate();
        heatEnvironment = vfModuleCust.getVolumeHeatEnv();
    } else {
        heatTemplate = vfModule.getModuleHeatTemplate();
        heatEnvironment = vfModuleCust.getHeatEnvironment();
    }
    if (heatTemplate == null) {
        String error = "UpdateVF: No Heat Template ID defined in catalog database for " + vfModuleType + ", modelCustomizationUuid=" + modelCustomizationUuid + ", vfModuleUuid=" + vfModule.getModelUUID() + ", reqType=" + requestType;
        logger.error("{} {} {} {} {} {}", MessageEnum.RA_VNF_UNKNOWN_PARAM.toString(), "Heat Template ID", vfModuleType, "VNF", ErrorCode.DataError.getValue(), error);
        logger.debug(error);
        throw new VnfException(error, MsoExceptionCategory.INTERNAL);
    } else {
        logger.debug("Got HEAT Template from DB: " + heatTemplate.getHeatTemplate());
    }
    if (heatEnvironment == null) {
        String error = "Update VNF: undefined Heat Environment. VF=" + vfModuleType + ", modelCustomizationUuid=" + modelCustomizationUuid + ", vfModuleUuid=" + vfModule.getModelUUID() + ", reqType=" + requestType;
        logger.error("{} {} {} {} {}", MessageEnum.RA_VNF_UNKNOWN_PARAM.toString(), "Heat Environment ID", "OpenStack", ErrorCode.DataError.getValue(), error);
        throw new VnfException(error, MsoExceptionCategory.INTERNAL);
    } else {
        logger.debug("Got Heat Environment from DB: " + heatEnvironment.getEnvironment());
    }
    // Create the combined set of parameters from the incoming request, base-module outputs,
    // volume-module outputs. Also, convert all variables to their native object types.
    HashMap<String, Object> goldenInputs = new HashMap<String, Object>();
    List<String> extraInputs = new ArrayList<String>();
    Boolean skipInputChecks = false;
    if (skipInputChecks) {
        goldenInputs = new HashMap<String, Object>();
        for (String key : inputs.keySet()) {
            goldenInputs.put(key, inputs.get(key));
        }
    } else {
        // Build maps for the parameters (including aliases) to simplify checks
        HashMap<String, HeatTemplateParam> params = new HashMap<String, HeatTemplateParam>();
        Set<HeatTemplateParam> paramSet = heatTemplate.getParameters();
        logger.debug("paramSet has " + paramSet.size() + " entries");
        for (HeatTemplateParam htp : paramSet) {
            params.put(htp.getParamName(), htp);
            // Include aliases.
            String alias = htp.getParamAlias();
            if (alias != null && !alias.equals("") && !params.containsKey(alias)) {
                params.put(alias, htp);
            }
        }
        // First, convert all inputs to their "template" type
        for (String key : inputs.keySet()) {
            if (params.containsKey(key)) {
                Object value = convertInputValue(inputs.get(key), params.get(key));
                if (value != null) {
                    goldenInputs.put(key, value);
                } else {
                    logger.debug("Failed to convert input " + key + "='" + inputs.get(key) + "' to " + params.get(key).getParamType());
                }
            } else {
                extraInputs.add(key);
            }
        }
        if (!extraInputs.isEmpty()) {
            // Add multicloud inputs
            for (String key : MsoMulticloudUtils.MULTICLOUD_INPUTS) {
                if (extraInputs.contains(key)) {
                    goldenInputs.put(key, inputs.get(key));
                    extraInputs.remove(key);
                    if (extraInputs.isEmpty()) {
                        break;
                    }
                }
            }
            logger.debug("Ignoring extra inputs: " + extraInputs);
        }
        // Next add in Volume Group Outputs if there are any. Copy directly without conversions.
        if (volumeGroupOutputs != null && !volumeGroupOutputs.isEmpty()) {
            for (String key : volumeGroupOutputs.keySet()) {
                if (params.containsKey(key) && !goldenInputs.containsKey(key)) {
                    goldenInputs.put(key, volumeGroupOutputs.get(key));
                }
            }
        }
        // Next add in Base Module Outputs if there are any. Copy directly without conversions.
        if (baseModuleOutputs != null && !baseModuleOutputs.isEmpty()) {
            for (String key : baseModuleOutputs.keySet()) {
                if (params.containsKey(key) && !goldenInputs.containsKey(key)) {
                    goldenInputs.put(key, baseModuleOutputs.get(key));
                }
            }
        }
        // TODO: The model should support a mechanism to pre-assign default parameter values
        // per "customization" (i.e. usage) of a given module. In HEAT, this is specified by
        // an Environment file. There is not a general mechanism in the model to handle this.
        // For the general case, any such parameter/values can be added dynamically to the
        // inputs (only if not already specified).
        // Check that required parameters have been supplied from any of the sources
        String missingParams = null;
        boolean checkRequiredParameters = true;
        try {
            String propertyString = this.environment.getProperty(MsoVnfPluginAdapterImpl.CHECK_REQD_PARAMS);
            if ("false".equalsIgnoreCase(propertyString) || "n".equalsIgnoreCase(propertyString)) {
                checkRequiredParameters = false;
                logger.debug("CheckRequiredParameters is FALSE. Will still check but then skip blocking..." + MsoVnfPluginAdapterImpl.CHECK_REQD_PARAMS);
            }
        } catch (Exception e) {
            // No problem - default is true
            logger.debug("An exception occured trying to get property " + MsoVnfPluginAdapterImpl.CHECK_REQD_PARAMS, e);
        }
        // Do the actual parameter checking.
        // Include looking at the ENV file as a valid definition of a parameter value.
        // TODO: This handling of ENV applies only to Heat. A general mechanism to
        // support pre-set parameter/values does not yet exist in the model.
        // 
        StringBuilder sb = new StringBuilder(heatEnvironment.getEnvironment());
        MsoHeatEnvironmentEntry mhee = new MsoHeatEnvironmentEntry(sb);
        for (HeatTemplateParam parm : heatTemplate.getParameters()) {
            if (parm.isRequired() && (!goldenInputs.containsKey(parm.getParamName()))) {
                if (mhee != null && mhee.containsParameter(parm.getParamName())) {
                    logger.debug("Required parameter " + parm.getParamName() + " appears to be in environment - do not count as missing");
                } else {
                    logger.debug("adding to missing parameters list: " + parm.getParamName());
                    if (missingParams == null) {
                        missingParams = parm.getParamName();
                    } else {
                        missingParams += "," + parm.getParamName();
                    }
                }
            }
        }
        if (missingParams != null) {
            if (checkRequiredParameters) {
                // Problem - missing one or more required parameters
                String error = "Create VFModule: Missing Required inputs: " + missingParams;
                logger.error("{} {} {} {} {}", MessageEnum.RA_MISSING_PARAM.toString(), missingParams, "VDU", ErrorCode.DataError.getValue(), "Create VFModule: Missing Required inputs");
                logger.debug(error);
                throw new VnfException(error, MsoExceptionCategory.USERDATA);
            } else {
                logger.debug("found missing parameters [" + missingParams + "] - but checkRequiredParameters is false - " + "will not block");
            }
        } else {
            logger.debug("No missing parameters found - ok to proceed");
        }
    }
    // NOTE: END PARAMETER CHECKING
    // Here we go... ready to deploy the VF Module.
    long instantiateVduStartTime = System.currentTimeMillis();
    if (backout == null)
        backout = true;
    try {
        // Construct the VDU Model structure to pass to the targeted VduPlugin
        VduModelInfo vduModel = null;
        if (!isVolumeRequest) {
            vduModel = vduMapper.mapVfModuleCustomizationToVdu(vfModuleCust);
        } else {
            vduModel = vduMapper.mapVfModuleCustVolumeToVdu(vfModuleCust);
        }
        // Invoke the VduPlugin to instantiate the VF Module
        vduInstance = vduPlugin.instantiateVdu(cloudInfo, vfModuleName, goldenInputs, vduModel, backout);
    } catch (VduException me) {
        // Failed to instantiate the VDU.
        me.addContext("CreateVFModule");
        String error = "Create VF Module " + vfModuleType + " in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId + ": " + me;
        logger.error("{} {} {} {} {} {} {} {}", MessageEnum.RA_CREATE_VNF_ERR.toString(), vfModuleType, cloudOwner, cloudSiteId, tenantId, "VDU", ErrorCode.DataError.getValue(), "MsoException - instantiateVdu", me);
        logger.debug(error);
        // Convert to a generic VnfException
        throw new VnfException(me);
    } catch (NullPointerException npe) {
        String error = "Create VFModule " + vfModuleType + " in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId + ": " + npe;
        logger.error("{} {} {} {} {} {} {} {}", MessageEnum.RA_CREATE_VNF_ERR.toString(), vfModuleType, cloudOwner, cloudSiteId, tenantId, "VDU", ErrorCode.DataError.getValue(), "NullPointerException - instantiateVdu", npe);
        logger.debug(error);
        logger.debug("NULL POINTER EXCEPTION at vduPlugin.instantiateVdu", npe);
        throw new VnfException("NullPointerException during instantiateVdu");
    } catch (Exception e) {
        String error = "Create VFModule " + vfModuleType + " in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId + ": " + e;
        logger.debug("Unhandled exception at vduPlugin.instantiateVdu", e);
        logger.debug(error);
        throw new VnfException("Exception during instantiateVdu: " + e.getMessage());
    }
    vnfId.value = vduInstance.getVduInstanceId();
    logger.debug("VF Module " + vfModuleName + " successfully created");
    return;
}
Also used : HashMap(java.util.HashMap) HeatEnvironment(org.onap.so.db.catalog.beans.HeatEnvironment) VnfAlreadyExists(org.onap.so.adapters.vnf.exceptions.VnfAlreadyExists) ArrayList(java.util.ArrayList) VfModule(org.onap.so.db.catalog.beans.VfModule) VnfResource(org.onap.so.db.catalog.beans.VnfResource) VnfException(org.onap.so.adapters.vnf.exceptions.VnfException) MavenLikeVersioning(org.onap.so.db.catalog.utils.MavenLikeVersioning) VduPlugin(org.onap.so.adapters.vdu.VduPlugin) MsoException(org.onap.so.openstack.exceptions.MsoException) CloudInfo(org.onap.so.adapters.vdu.CloudInfo) VduInstance(org.onap.so.adapters.vdu.VduInstance) VduException(org.onap.so.adapters.vdu.VduException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) VnfException(org.onap.so.adapters.vnf.exceptions.VnfException) MsoException(org.onap.so.openstack.exceptions.MsoException) MsoHeatEnvironmentEntry(org.onap.so.openstack.utils.MsoHeatEnvironmentEntry) VduStateType(org.onap.so.adapters.vdu.VduStateType) HeatTemplate(org.onap.so.db.catalog.beans.HeatTemplate) CloudSite(org.onap.so.db.catalog.beans.CloudSite) VduModelInfo(org.onap.so.adapters.vdu.VduModelInfo) VfModuleCustomization(org.onap.so.db.catalog.beans.VfModuleCustomization) VduException(org.onap.so.adapters.vdu.VduException) HeatTemplateParam(org.onap.so.db.catalog.beans.HeatTemplateParam)

Example 9 with VduException

use of org.onap.so.adapters.vdu.VduException in project so by onap.

the class MsoVnfPluginAdapterImpl method deleteVfModule.

public void deleteVfModule(String cloudSiteId, String cloudOwner, String tenantId, String vfModuleId, MsoRequest msoRequest, Holder<Map<String, String>> outputs) throws VnfException {
    logger.debug("Deleting VF Module " + vfModuleId + " in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId);
    // Will capture execution time for metrics
    long startTime = System.currentTimeMillis();
    // Capture the output parameters on a delete, so need to query first
    VduInstance vduInstance = null;
    CloudInfo cloudInfo = new CloudInfo(cloudSiteId, cloudOwner, tenantId, null);
    // Use the VduPlugin.
    VduPlugin vduPlugin = getVduPlugin(cloudSiteId, cloudOwner);
    try {
        vduInstance = vduPlugin.queryVdu(cloudInfo, vfModuleId);
    } catch (VduException e) {
        // Failed to query the VDU due to a plugin exception.
        // Convert to a generic VnfException
        e.addContext("QueryVFModule");
        String error = "Query VfModule (VDU): " + vfModuleId + " in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId + ": " + e;
        logger.error("{} {} {} {} {} {} {} {} {}", MessageEnum.RA_QUERY_VNF_ERR.toString(), vfModuleId, cloudOwner, cloudSiteId, tenantId, "VDU", "QueryVFModule", ErrorCode.DataError.getValue(), "Exception - queryVDU", e);
        logger.debug(error);
        throw new VnfException(e);
    }
    // call method which handles the conversion from Map<String,Object> to Map<String,String> for our expected
    // Object types
    outputs.value = convertMapStringObjectToStringString(vduInstance.getOutputs());
    // Use the VduPlugin to delete the VDU.
    // The possible outcomes of deleteVdu are
    // - a vnfInstance object with status of DELETED (success)
    // - a vnfInstance object with status of NOTFOUND (VDU did not exist, treat as success)
    // - a vnfInstance object with status of FAILED (error)
    // Also, VduException could be thrown.
    long subStartTime = System.currentTimeMillis();
    try {
        // TODO: Get an appropriate timeout value - require access to the model
        if (!vduInstance.getStatus().getState().equals(VduStateType.NOTFOUND)) {
            vduPlugin.deleteVdu(cloudInfo, vfModuleId, 5);
        }
    } catch (VduException me) {
        me.addContext("DeleteVfModule");
        // Convert to a generic VnfException
        String error = "Delete VF: " + vfModuleId + " in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId + ": " + me;
        logger.error("{} {} {} {} {} {} {} {} {}", MessageEnum.RA_DELETE_VNF_ERR.toString(), vfModuleId, cloudOwner, cloudSiteId, tenantId, "VDU", "DeleteVdu", ErrorCode.DataError.getValue(), "Exception - DeleteVdu: " + me.getMessage());
        logger.debug(error);
        throw new VnfException(me);
    }
    // On success, nothing is returned.
    return;
}
Also used : VduPlugin(org.onap.so.adapters.vdu.VduPlugin) CloudInfo(org.onap.so.adapters.vdu.CloudInfo) VnfException(org.onap.so.adapters.vnf.exceptions.VnfException) VduInstance(org.onap.so.adapters.vdu.VduInstance) VduException(org.onap.so.adapters.vdu.VduException)

Example 10 with VduException

use of org.onap.so.adapters.vdu.VduException in project so by onap.

the class MsoVnfPluginAdapterImpl method rollbackVnf.

/**
 * 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.
 *
 * TODO: This should be rollbackVfModule and/or rollbackVolumeGroup, but APIs were apparently never updated.
 */
public void rollbackVnf(VnfRollback rollback) throws VnfException {
    long startTime = System.currentTimeMillis();
    // rollback may be null (e.g. if stack already existed when Create was called)
    if (rollback == null) {
        logger.info("{} {} {}", MessageEnum.RA_ROLLBACK_NULL.toString(), "OpenStack", "rollbackVnf");
        return;
    }
    // Don't rollback if nothing was done originally
    if (!rollback.getVnfCreated()) {
        return;
    }
    // Get the elements of the VnfRollback object for easier access
    String cloudSiteId = rollback.getCloudSiteId();
    String cloudOwner = rollback.getCloudOwner();
    String tenantId = rollback.getTenantId();
    CloudInfo cloudInfo = new CloudInfo(cloudSiteId, cloudOwner, tenantId, null);
    String vfModuleId = rollback.getVfModuleStackId();
    logger.debug("Rolling Back VF Module " + vfModuleId + " in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId);
    VduInstance vduInstance = null;
    // Use the VduPlugin to delete the VF Module.
    VduPlugin vduPlugin = getVduPlugin(cloudSiteId, cloudOwner);
    long subStartTime = System.currentTimeMillis();
    try {
        // TODO: Get a reasonable timeout. Use a global property, or store the creation timeout in rollback object
        // and use that.
        vduInstance = vduPlugin.deleteVdu(cloudInfo, vfModuleId, 5);
        logger.debug("Rolled back VDU instantiation: {}", vduInstance.getVduInstanceId());
    } catch (VduException ve) {
        // Failed to rollback the VF Module due to a plugin exception.
        // Convert to a generic VnfException
        ve.addContext("RollbackVFModule");
        String error = "Rollback VF Module: " + vfModuleId + " in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId + ": " + ve;
        logger.error("{} {} {} {} {} {} {} {} {}", MessageEnum.RA_DELETE_VNF_ERR.toString(), vfModuleId, cloudOwner, cloudSiteId, tenantId, "VDU", "DeleteVdu", ErrorCode.DataError.getValue(), "Exception - DeleteVdu", ve);
        logger.debug(error);
        throw new VnfException(ve);
    }
    return;
}
Also used : VduPlugin(org.onap.so.adapters.vdu.VduPlugin) CloudInfo(org.onap.so.adapters.vdu.CloudInfo) VnfException(org.onap.so.adapters.vnf.exceptions.VnfException) VduInstance(org.onap.so.adapters.vdu.VduInstance) VduException(org.onap.so.adapters.vdu.VduException)

Aggregations

VduException (org.onap.so.adapters.vdu.VduException)10 MsoException (org.onap.so.openstack.exceptions.MsoException)7 VduInstance (org.onap.so.adapters.vdu.VduInstance)6 StackInfo (org.onap.so.openstack.beans.StackInfo)6 MsoOpenstackException (org.onap.so.openstack.exceptions.MsoOpenstackException)6 CloudInfo (org.onap.so.adapters.vdu.CloudInfo)4 VduPlugin (org.onap.so.adapters.vdu.VduPlugin)4 VnfException (org.onap.so.adapters.vnf.exceptions.VnfException)4 OpenStackConnectException (com.woorea.openstack.base.client.OpenStackConnectException)3 OpenStackResponseException (com.woorea.openstack.base.client.OpenStackResponseException)3 IOException (java.io.IOException)3 MalformedURLException (java.net.MalformedURLException)3 HashMap (java.util.HashMap)3 UriBuilderException (javax.ws.rs.core.UriBuilderException)3 MsoAdapterException (org.onap.so.openstack.exceptions.MsoAdapterException)3 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)3 VduArtifact (org.onap.so.adapters.vdu.VduArtifact)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 ArrayList (java.util.ArrayList)1 VduModelInfo (org.onap.so.adapters.vdu.VduModelInfo)1