Search in sources :

Example 1 with ELMFeatureDetail

use of com.emc.cams.elm.ELMFeatureDetail in project coprhd-controller by CoprHD.

the class LicenseManagerImpl method buildLicenseObjectFromText.

/**
 * Build a valid license object from the license string. If there is any
 * error while reading the license file, a license object will be created
 * with a licensed value of false.
 *
 * @return license object if successful, otherwise null
 */
protected License buildLicenseObjectFromText(String licenseText) throws ELMLicenseException {
    boolean bGetLock = false;
    try {
        bGetLock = parseLicenseLock.tryLock(waitAcquireParseLicenseLock, TimeUnit.SECONDS);
    } catch (Exception e) {
        _log.warn("Exception when adding license, msg: {}", e.getMessage());
        throw APIException.internalServerErrors.processLicenseError("failed getting lock to validate and parse license, error:" + e.getMessage());
    }
    if (bGetLock) {
        try {
            License license = new License();
            // Add the license test to disk in the .license file in root. This is required in order
            // to parse the license using the ELMS API.
            addLicenseToDiskLicenseFile(licenseText);
            ELMLicenseProps licProps = new ELMLicenseProps();
            licProps.setLicPath(LicenseConstants.LICENSE_FILE_PATH);
            ELMFeatureDetail[] featureDetails = null;
            ELMLicenseSource licSource = new ELMLicenseSource(licProps);
            featureDetails = licSource.getFeatureDetailList();
            LicenseFeature licenseFeature = null;
            for (ELMFeatureDetail featureDetail : featureDetails) {
                // create a license feature object.
                licenseFeature = new LicenseFeature();
                if (!featureDetail.getFeatureName().equals(LicenseConstants.VIPR_CONTROLLER)) {
                    throw APIException.badRequests.licenseIsNotValid(String.format("The license file contains a not supported feature: %s.", featureDetail.getFeatureName()) + "Non controller license is no longer supported.");
                }
                if (featureDetail.getDaysUntilExp() > 0) {
                    licenseFeature.setLicensed(true);
                    licenseFeature.setVersion(featureDetail.getVersion());
                    licenseFeature.setIssuer(featureDetail.getIssuer());
                    licenseFeature.setNotice(featureDetail.getNotice());
                    licenseFeature.setDateExpires(convertCalendarToString(featureDetail.getExpDate()));
                    licenseFeature.setExpired(isExpired(licenseFeature.getDateExpires()));
                    licenseFeature.setDateIssued(convertCalendarToString(featureDetail.getIssuedDate()));
                    String subModelId = LicenseFeature.OLD_LICENSE_SUBMODEL;
                    Properties p = featureDetail.getVendorString(";");
                    if (p.size() > 0) {
                        for (Enumeration e = p.propertyNames(); e.hasMoreElements(); ) {
                            String str = (String) e.nextElement();
                            if (str.equals(LicenseConstants.LICENSE_TYPE_PROPERTYNAME)) {
                                subModelId = p.getProperty(str);
                                _log.info("Get a license increment with type: {}", subModelId);
                                break;
                            }
                        }
                    }
                    licenseFeature.setModelId(featureDetail.getFeatureName() + LicenseFeature.MODELID_DELIMETER + subModelId);
                    setVendorStringFields(featureDetail, licenseFeature, p);
                } else {
                    _log.info("The license file contains a feature which is in an expired state. The license was not added to the system.");
                    throw APIException.badRequests.licenseIsNotValid("The license file contains a feature which is in an expired state. The license was not added to the system.");
                }
                license.addLicenseFeature(licenseFeature);
            }
            // delete /tmp/.license if it exists
            deleteCurrentLicenseFileOnDisk();
            _log.debug("Finished parsing of license");
            return license;
        } finally {
            parseLicenseLock.unlock();
        }
    } else {
        _log.warn("Cannot acquire lock. Another thread is holding the lock validating and parsing license");
        throw APIException.serviceUnavailable.postLicenseBusy();
    }
}
Also used : LicenseFeature(com.emc.vipr.model.sys.licensing.LicenseFeature) ELMFeatureDetail(com.emc.cams.elm.ELMFeatureDetail) ELMLicenseSource(com.emc.cams.elm.ELMLicenseSource) License(com.emc.vipr.model.sys.licensing.License) ELMLicenseProps(com.emc.cams.elm.ELMLicenseProps) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) ELMLicenseException(com.emc.cams.elm.exception.ELMLicenseException) LocalRepositoryException(com.emc.storageos.systemservices.exceptions.LocalRepositoryException) ParseException(java.text.ParseException) IOException(java.io.IOException) SysClientException(com.emc.storageos.systemservices.exceptions.SysClientException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) CoordinatorClientException(com.emc.storageos.systemservices.exceptions.CoordinatorClientException)

Aggregations

ELMFeatureDetail (com.emc.cams.elm.ELMFeatureDetail)1 ELMLicenseProps (com.emc.cams.elm.ELMLicenseProps)1 ELMLicenseSource (com.emc.cams.elm.ELMLicenseSource)1 ELMLicenseException (com.emc.cams.elm.exception.ELMLicenseException)1 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)1 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)1 CoordinatorClientException (com.emc.storageos.systemservices.exceptions.CoordinatorClientException)1 LocalRepositoryException (com.emc.storageos.systemservices.exceptions.LocalRepositoryException)1 SysClientException (com.emc.storageos.systemservices.exceptions.SysClientException)1 License (com.emc.vipr.model.sys.licensing.License)1 LicenseFeature (com.emc.vipr.model.sys.licensing.LicenseFeature)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1