Search in sources :

Example 1 with LicenseException

use of org.voltdb.licensetool.LicenseException in project voltdb by VoltDB.

the class MiscUtils method licenseApiFactory.

/**
     * Instantiate the license api impl based on enterprise/community editions
     * @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 isAnyKindOfTrial() {
                return false;
            }

            @Override
            public boolean isProTrial() {
                return false;
            }

            @Override
            public boolean isEnterpriseTrial() {
                return false;
            }

            @Override
            public int maxHostcount() {
                return Integer.MAX_VALUE;
            }

            @Override
            public Calendar expires() {
                Calendar result = Calendar.getInstance();
                // good enough?
                result.add(Calendar.YEAR, 20);
                return result;
            }

            @Override
            public boolean verify() {
                return true;
            }

            @Override
            public boolean isDrReplicationAllowed() {
                return false;
            }

            @Override
            public boolean isDrActiveActiveAllowed() {
                return false;
            }

            @Override
            public boolean isCommandLoggingAllowed() {
                return false;
            }

            @Override
            public boolean isAWSMarketplace() {
                return false;
            }

            @Override
            public boolean isEnterprise() {
                return false;
            }

            @Override
            public boolean isPro() {
                return false;
            }

            @Override
            public String licensee() {
                return "VoltDB Community Edition User";
            }

            @Override
            public Calendar issued() {
                Calendar result = Calendar.getInstance();
                return result;
            }

            @Override
            public String note() {
                return "";
            }

            @Override
            public boolean hardExpiration() {
                return false;
            }

            @Override
            public boolean secondaryInitialization() {
                return true;
            }
        };
    }
    // 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;
    }
    hostLog.info("Found VoltDB license file at path: " + pathToLicense);
    // 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) {
        hostLog.fatal(lex.getMessage());
        return null;
    }
    return licenseApi;
}
Also used : LicenseException(org.voltdb.licensetool.LicenseException) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) LicenseApi(org.voltdb.licensetool.LicenseApi) File(java.io.File)

Aggregations

File (java.io.File)1 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 LicenseApi (org.voltdb.licensetool.LicenseApi)1 LicenseException (org.voltdb.licensetool.LicenseException)1