Example usage for org.apache.cassandra.utils FBUtilities classForName

List of usage examples for org.apache.cassandra.utils FBUtilities classForName

Introduction

In this page you can find the example usage for org.apache.cassandra.utils FBUtilities classForName.

Prototype

public static <T> Class<T> classForName(String classname, String readable) throws ConfigurationException 

Source Link

Usage

From source file:com.protectwise.cassandra.db.compaction.DeletingCompactionStrategyOptions.java

License:Apache License

@SuppressWarnings("unchecked")
public DeletingCompactionStrategyOptions(ColumnFamilyStore cfs, Map<String, String> options) {
    this.cfs = cfs;
    boolean enabled = true;

    convictorClassName = options.get(CONVICTOR_CLASSNAME_KEY);
    this.convictorOptions = options;

    String optionValue = options.get(UNDERLYING_CLASSNAME_KEY);
    // TODO: See if there is a unified means in cassandra-core for resolving short names;
    // found snippets like this in other areas, but it seems like there should be something
    // more general purpose or reusable.
    if (!optionValue.contains(".")) {
        optionValue = "org.apache.cassandra.db.compaction." + optionValue;
    }/*from   www . ja  v a 2  s.c om*/
    AbstractCompactionStrategy underlying;
    try {
        Class<AbstractCompactionStrategy> underlyingClass = FBUtilities.classForName(optionValue,
                "deleting compaction underlying compactor");

        Constructor<AbstractCompactionStrategy> constructor = underlyingClass
                .getConstructor(ColumnFamilyStore.class, Map.class);
        underlying = constructor.newInstance(cfs, options);

    } catch (ConfigurationException | NoSuchMethodException | InstantiationException | IllegalAccessException
            | InvocationTargetException e) {
        logger.error(String.format("Unable to instantiate underlying compactor class %s: %s", optionValue,
                e.getMessage()), e);
        underlying = null;
        enabled = false;
    }
    this.underlying = underlying;

    boolean dryRun;
    if (options.containsKey(DRY_RUN_KEY)) {
        optionValue = options.get(DRY_RUN_KEY);
        // if we get _anything_ unexpected, default to being a dry run.
        dryRun = Boolean.parseBoolean(optionValue);
    } else {
        dryRun = false;
    }

    File backupDir = null;
    if (options.containsKey(DELETED_RECORDS_DIRECTORY)) {
        try {
            backupDir = validateBackupDirectory(new File(options.get(DELETED_RECORDS_DIRECTORY)));
        } catch (ConfigurationException e) {
            dryRun = true;
            logger.warn("Deletion backup directory cannot be used.  Compaction will revert to dry run.", e);
        }
    }

    long statusReportInterval = 0l;
    if (options.containsKey(STATUS_REPORT_INTERVAL)) {
        statusReportInterval = Long.parseLong(options.get(STATUS_REPORT_INTERVAL));
    }

    this.deletedRecordsSinkDirectory = backupDir;
    this.dryRun = dryRun;
    this.enabled = enabled;
    this.statsReportInterval = statusReportInterval;
}

From source file:com.protectwise.cassandra.db.compaction.DeletingCompactionStrategyOptions.java

License:Apache License

public AbstractSimpleDeletingConvictor buildConvictor() {
    AbstractSimpleDeletingConvictor convictor;
    try {// w w w  .  ja va 2  s .  c  o m
        Class<AbstractSimpleDeletingConvictor> convictorClass = FBUtilities.classForName(convictorClassName,
                "deleting compaction convictor");
        Constructor constructor = convictorClass.getConstructor(ColumnFamilyStore.class, Map.class);
        convictor = (AbstractSimpleDeletingConvictor) constructor.newInstance(cfs, convictorOptions);
    } catch (ConfigurationException | NoSuchMethodException | IllegalAccessException | InvocationTargetException
            | InstantiationException e) {
        logger.error(String.format("Unable to instantiate convictor class %s: %s", convictorClassName,
                e.getMessage()), e);
        convictor = null;
    }
    return convictor;
}

From source file:com.protectwise.cassandra.db.compaction.DeletingCompactionStrategyOptions.java

License:Apache License

public static Map<String, String> validateOptions(Map<String, String> options) throws ConfigurationException {
    String optionValue = options.get(CONVICTOR_CLASSNAME_KEY);
    Class<AbstractSimpleDeletingConvictor> convictor = FBUtilities.classForName(optionValue,
            "deleting compaction convictor");
    if (!AbstractSimpleDeletingConvictor.class.isAssignableFrom(convictor)) {
        throw new ConfigurationException(String.format(
                "%s must implement %s to be used as a deleting compaction strategy convictorClass",
                convictor.getCanonicalName(), AbstractSimpleDeletingConvictor.class.getCanonicalName()));
    }/*w w  w . j a va2s .  co  m*/
    options.remove(CONVICTOR_CLASSNAME_KEY);

    optionValue = options.get(UNDERLYING_CLASSNAME_KEY);
    Class<AbstractCompactionStrategy> underlyingClass = FBUtilities.classForName(optionValue,
            "deleting compaction underlying compactor");
    if (!AbstractCompactionStrategy.class.isAssignableFrom(underlyingClass)) {
        throw new ConfigurationException(String.format(
                "%s must implement %s to be used as a deleting compaction strategy underlying compactor",
                underlyingClass.getCanonicalName(), AbstractCompactionStrategy.class.getCanonicalName()));
    }
    options.remove(UNDERLYING_CLASSNAME_KEY);

    if (options.containsKey(DRY_RUN_KEY)) {
        optionValue = options.get(DRY_RUN_KEY);
        if (!optionValue.equals("true") && !optionValue.equals("false")) {
            throw new ConfigurationException(String
                    .format("%s must either be 'true' or 'false' - received '%s'", DRY_RUN_KEY, optionValue));
        }
        options.remove(DRY_RUN_KEY);
    }

    if (options.containsKey(DELETED_RECORDS_DIRECTORY)) {
        optionValue = options.get(DELETED_RECORDS_DIRECTORY);
        // Although these conditions can change after the strategy is applied to a table, or may not even be
        // consistent across the entire cluster, it doesn't hurt to validate that at least at the time it's set up,
        // initial conditions on the coordinating host look good.
        validateBackupDirectory(new File(optionValue));
        options.remove(DELETED_RECORDS_DIRECTORY);
    }

    if (options.containsKey(STATUS_REPORT_INTERVAL)) {
        optionValue = options.get(STATUS_REPORT_INTERVAL);
        Long.parseLong(optionValue);
        options.remove(STATUS_REPORT_INTERVAL);
    }

    return validatePassthrough(convictor, validatePassthrough(underlyingClass, options));
}

From source file:org.elassandra.cluster.routing.AbstractSearchStrategy.java

License:Apache License

public static Class<AbstractSearchStrategy> getSearchStrategyClass(String cls) throws ConfigurationException {
    String className = cls.contains(".") ? cls : "org.elassandra.cluster.routing." + cls;
    Class<AbstractSearchStrategy> searchClass = FBUtilities.classForName(className, "search strategy");
    if (!AbstractSearchStrategy.class.isAssignableFrom(searchClass)) {
        throw new ConfigurationException(String.format((Locale) null,
                "Specified search strategy class (%s) is not derived from AbstractSearchStrategy", className));
    }/*ww w . ja v a 2  s .c  o  m*/
    return searchClass;
}