* @return a valid API for community and pro editions, or null on error.
*/
public static LicenseApi licenseApiFactory(String pathToLicense) {
if (MiscUtils.isPro() == false) {
return new LicenseApi() {
@Override
public boolean initializeFromFile(File license) {
return true;
}
@Override
public boolean isTrial() {
return false;
}
@Override
public int maxHostcount() {
return Integer.MAX_VALUE;
}
@Override
public Calendar expires() {
Calendar result = Calendar.getInstance();
result.add(Calendar.YEAR, 20); // good enough?
return result;
}
@Override
public boolean verify() {
return true;
}
@Override
public boolean isDrReplicationAllowed() {
return false;
}
@Override
public boolean isCommandLoggingAllowed() {
return false;
}
};
}
// boilerplate to create a license api interface
LicenseApi licenseApi = null;
Class<?> licApiKlass = MiscUtils.loadProClass("org.voltdb.licensetool.LicenseApiImpl",
"License API", false);
if (licApiKlass != null) {
try {
licenseApi = (LicenseApi)licApiKlass.newInstance();
} catch (InstantiationException e) {
hostLog.fatal("Unable to process license file: could not create license API.");
return null;
} catch (IllegalAccessException e) {
hostLog.fatal("Unable to process license file: could not create license API.");
return null;
}
}
if (licenseApi == null) {
hostLog.fatal("Unable to load license file: could not create License API.");
return null;
}
// verify the license file exists.
File licenseFile = new File(pathToLicense);
if (licenseFile.exists() == false) {
return null;
}
// Initialize the API. This parses the file but does NOT verify signatures.
if (licenseApi.initializeFromFile(licenseFile) == false) {
hostLog.fatal("Unable to load license file: could not parse license.");
return null;
}
// Perform signature verification - detect modified files
try
{
if (licenseApi.verify() == false) {
hostLog.fatal("Unable to load license file: could not verify license signature.");
return null;
}
}
catch (LicenseException lex)