Search in sources :

Example 6 with License

use of com.emc.vipr.model.sys.licensing.License in project coprhd-controller by CoprHD.

the class LicenseManagerTest method testForNoLicense.

@Test
public void testForNoLicense() throws Exception {
    LicenseManager manager = new LicenseManagerImpl() {

        public License getLicense() {
            return new License();
        }
    };
    License license = manager.getLicense();
    Assert.assertEquals(license.getLicenseFeatures().size(), 0);
}
Also used : License(com.emc.vipr.model.sys.licensing.License) Test(org.junit.Test)

Example 7 with License

use of com.emc.vipr.model.sys.licensing.License in project coprhd-controller by CoprHD.

the class LicenseManagerImpl method addLicense.

/**
 * Configure the license information in properties file, disk and coordinator.
 *
 * @param license
 * @throws LocalRepositoryException
 * @throws CoordinatorClientException
 */
public void addLicense(License license) throws LocalRepositoryException, CoordinatorClientException, ELMLicenseException {
    if (getTargetInfoLock()) {
        try {
            // Step 1: Add the license test to disk in the .license file
            // Step 2: parse the .license file on disk in root directory using the ELMS API. This is required by the
            // ELMS API.
            License fullLicense = buildLicenseObjectFromText(license.getLicenseText());
            if (fullLicense != null) {
                boolean isTrial = false;
                for (LicenseFeature feature : fullLicense.getLicenseFeatures()) {
                    if (feature.getModelId().startsWith(LicenseConstants.VIPR_CONTROLLER) && feature.isTrialLicense()) {
                        isTrial = true;
                    }
                }
                if (!isTrial) {
                    // Do not support the licenses of pre-yoda releases unless it is trial license.
                    for (LicenseFeature licenseFeature : fullLicense.getLicenseFeatures()) {
                        if (licenseFeature.getModelId().contains(LicenseFeature.OLD_LICENSE_SUBMODEL)) {
                            _log.info("The license file contains a feature which is not supported any more. The license was not added to the system.");
                            throw APIException.badRequests.licenseIsNotValid("The license file contains a feature which is not supported any more. The license was not added to the system.");
                        }
                    }
                }
            }
            // Step 3: Add license features to coordinator service.
            updateCoordinatorWithLicenseFeatures(fullLicense, true);
            // Step 4: Add the raw license file to coordinator to keep a copy of the actual license file.
            updateCoordinatorWithLicenseText(license);
            // Step 5: Force the events to run
            _sendEventScheduler.run();
        } finally {
            releaseTargetVersionLock();
        }
    } else {
        _log.warn("Cannot acquire lock for adding license");
        throw APIException.serviceUnavailable.postLicenseBusy();
    }
}
Also used : LicenseFeature(com.emc.vipr.model.sys.licensing.LicenseFeature) License(com.emc.vipr.model.sys.licensing.License)

Example 8 with License

use of com.emc.vipr.model.sys.licensing.License 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)

Example 9 with License

use of com.emc.vipr.model.sys.licensing.License in project coprhd-controller by CoprHD.

the class OpenSourceLicenseManagerImpl method getLicense.

/**
 * Returns a full license object complete with features.
 *
 * @return
 */
public License getLicense() throws Exception {
    License license = new License();
    LicenseFeature licenseFeature = new LicenseFeature();
    licenseFeature.setDateExpires(null);
    licenseFeature.setExpired(false);
    licenseFeature.setStorageCapacity("1152921504606846976");
    licenseFeature.setProductId("R27WRZ98BBF6XS");
    licenseFeature.setSerial("R27WRZ98BBF6XS");
    String subModelId = LicenseFeature.NEW_MANAGED_LICENSE_SUBMODEL;
    licenseFeature.setModelId(LicenseConstants.VIPR_CONTROLLER + LicenseFeature.MODELID_DELIMETER + subModelId);
    licenseFeature.setDateIssued("01/10/2014");
    licenseFeature.setLicenseIdIndicator("U");
    licenseFeature.setVersion("2.0");
    licenseFeature.setNotice("Distributed under the Apache License, Version 2.0");
    licenseFeature.setTrialLicense(false);
    licenseFeature.setLicensed(true);
    license.addLicenseFeature(licenseFeature);
    license.setLicenseText(LICENSE_TEXT);
    return license;
}
Also used : LicenseFeature(com.emc.vipr.model.sys.licensing.LicenseFeature) License(com.emc.vipr.model.sys.licensing.License)

Example 10 with License

use of com.emc.vipr.model.sys.licensing.License in project coprhd-controller by CoprHD.

the class OpenSourceLicensingServiceImpl method getLicense.

@Override
public License getLicense() throws Exception {
    _log.info("Received GET /license request");
    // Changing invalid 01/01/12006 license expiration date to null
    License license = _licenseManager.getLicense();
    if (license != null && license.getLicenseFeatures() != null) {
        for (LicenseFeature feature : license.getLicenseFeatures()) {
            if (LicenseConstants.LICENSE_EXPIRATION_DATE.equals(feature.getDateExpires())) {
                feature.setDateExpires(null);
            }
            if (feature.getStorageCapacity().equals(LicenseInfo.VALUE_NOT_SET)) {
                feature.setStorageCapacity(null);
            }
        }
    }
    return license;
}
Also used : LicenseFeature(com.emc.vipr.model.sys.licensing.LicenseFeature) License(com.emc.vipr.model.sys.licensing.License) Override(java.lang.Override)

Aggregations

License (com.emc.vipr.model.sys.licensing.License)13 LicenseFeature (com.emc.vipr.model.sys.licensing.LicenseFeature)7 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 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 Restrictions (controllers.deadbolt.Restrictions)1 IOException (java.io.IOException)1 Override (java.lang.Override)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1 Test (org.junit.Test)1 Promise (play.libs.F.Promise)1 StorageStatsWrapper (util.StorageStatsWrapper)1