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();
}
}
Aggregations