Search in sources :

Example 6 with LicenseFeature

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

the class LicenseTest method expiredLicenseTest.

/**
 * Positive test for an expired license. Licensed date is current day minus
 * 1 day. Compares date to current day.
 */
@Test
public void expiredLicenseTest() {
    LicenseFeature license = new LicenseFeature();
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -1);
    Date nowMinusOneDay = cal.getTime();
    SimpleDateFormat sdf = new SimpleDateFormat(LicenseManager.EXPIRE_DATE_FORMAT);
    license.setDateExpires(sdf.format(nowMinusOneDay));
    license.setExpired(LicenseManagerImpl.isExpired(license.getDateExpires()));
    Assert.assertTrue(license.isExpired());
}
Also used : LicenseFeature(com.emc.vipr.model.sys.licensing.LicenseFeature) Calendar(java.util.Calendar) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 7 with LicenseFeature

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

the class LicenseManagerImpl method createLicenseObject.

/**
 * Update License object with data license information from coordinator service.
 *
 * @param licenseInfoExts licenseInfoExts, License license
 * @return
 */
private void createLicenseObject(List<LicenseInfoExt> licenseInfoExts, License license) {
    if (licenseInfoExts.isEmpty()) {
        return;
    }
    for (LicenseInfoExt licenseExt : licenseInfoExts) {
        LicenseFeature licenseFeature = createLicenseFeatureFromLicenseInfoExt(licenseExt);
        license.addLicenseFeature(licenseFeature);
    }
}
Also used : LicenseFeature(com.emc.vipr.model.sys.licensing.LicenseFeature)

Example 8 with LicenseFeature

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

the class LicenseManagerImpl method updateCoordinatorWithLicenseFeatures.

/**
 * Build the coordinator service version of the license features from the
 * License object.
 *
 * @param license license to update
 * @param checkClusterUpgradable check if cluster is upgradable
 * @throws CoordinatorClientException
 */
private void updateCoordinatorWithLicenseFeatures(License license, boolean checkClusterUpgradable) throws CoordinatorClientException {
    LicenseInfoListExt licenseList = null;
    List<LicenseInfoExt> licenseInfoList = new ArrayList<LicenseInfoExt>();
    for (LicenseFeature licenseFeature : license.getLicenseFeatures()) {
        LicenseType licenseType;
        if (licenseFeature.getModelId().startsWith(LicenseConstants.VIPR_CONTROLLER)) {
            licenseType = LicenseType.CONTROLLER;
        } else {
            throw APIException.internalServerErrors.licenseInfoNotFoundForType("invalid license model id" + licenseFeature.getModelId());
        }
        LicenseInfoExt licenseInfo = new LicenseInfoExt();
        licenseInfo.setLicenseType(licenseType);
        licenseInfo.setExpirationDate(licenseFeature.getDateExpires());
        licenseInfo.setStorageCapacity(licenseFeature.getStorageCapacity());
        licenseInfo.setProductId(licenseFeature.getProductId());
        licenseInfo.setModelId(licenseFeature.getModelId());
        licenseInfo.setIssuedDate(licenseFeature.getDateIssued());
        licenseInfo.setLicenseTypeIndicator(licenseFeature.getLicenseIdIndicator());
        licenseInfo.setVersion(licenseFeature.getVersion());
        licenseInfo.setNotice(licenseFeature.getNotice());
        if (licenseFeature.isTrialLicense()) {
            licenseInfo.setTrialLicense(true);
        }
        licenseInfoList.add(licenseInfo);
    }
    if (!licenseInfoList.isEmpty()) {
        licenseList = new LicenseInfoListExt(licenseInfoList);
        _coordinator.setTargetInfo(licenseList, checkClusterUpgradable);
    }
}
Also used : LicenseFeature(com.emc.vipr.model.sys.licensing.LicenseFeature) LicenseType(com.emc.storageos.coordinator.client.service.CoordinatorClient.LicenseType)

Example 9 with LicenseFeature

use of com.emc.vipr.model.sys.licensing.LicenseFeature 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 10 with LicenseFeature

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

LicenseFeature (com.emc.vipr.model.sys.licensing.LicenseFeature)14 License (com.emc.vipr.model.sys.licensing.License)7 Test (org.junit.Test)4 SimpleDateFormat (java.text.SimpleDateFormat)2 Calendar (java.util.Calendar)2 Date (java.util.Date)2 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 LicenseType (com.emc.storageos.coordinator.client.service.CoordinatorClient.LicenseType)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 IOException (java.io.IOException)1 Override (java.lang.Override)1 ParseException (java.text.ParseException)1