Search in sources :

Example 1 with NBConfigurable

use of io.nosqlbench.nb.api.config.standard.NBConfigurable in project nosqlbench by nosqlbench.

the class ActivityTypeLoader method getDriverAdapter.

private Optional<ActivityType> getDriverAdapter(String activityTypeName, ActivityDef activityDef) {
    Optional<DriverAdapter> oda = DRIVERADAPTER_SPI_FINDER.getOptionally(activityTypeName);
    if (oda.isPresent()) {
        DriverAdapter<?, ?> driverAdapter = oda.get();
        activityDef.getParams().remove("driver");
        if (driverAdapter instanceof NBConfigurable) {
            NBConfigModel cfgModel = ((NBConfigurable) driverAdapter).getConfigModel();
            Optional<String> op_yaml_loc = activityDef.getParams().getOptionalString("yaml", "workload");
            if (op_yaml_loc.isPresent()) {
                Map<String, Object> disposable = new LinkedHashMap<>(activityDef.getParams());
                StmtsDocList workload = StatementsLoader.loadPath(logger, op_yaml_loc.get(), disposable, "activities");
                cfgModel = cfgModel.add(workload.getConfigModel());
            }
            NBConfiguration cfg = cfgModel.apply(activityDef.getParams());
            ((NBConfigurable) driverAdapter).applyConfig(cfg);
        }
        ActivityType activityType = new StandardActivityType<>(driverAdapter, activityDef);
        return Optional.of(activityType);
    } else {
        return Optional.empty();
    }
}
Also used : NBConfigurable(io.nosqlbench.nb.api.config.standard.NBConfigurable) StandardActivityType(io.nosqlbench.engine.api.activityimpl.uniform.StandardActivityType) StandardActivityType(io.nosqlbench.engine.api.activityimpl.uniform.StandardActivityType) ActivityType(io.nosqlbench.engine.api.activityapi.core.ActivityType) NBConfiguration(io.nosqlbench.nb.api.config.standard.NBConfiguration) StmtsDocList(io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList) DriverAdapter(io.nosqlbench.engine.api.activityimpl.uniform.DriverAdapter) NBConfigModel(io.nosqlbench.nb.api.config.standard.NBConfigModel)

Example 2 with NBConfigurable

use of io.nosqlbench.nb.api.config.standard.NBConfigurable in project nosqlbench by nosqlbench.

the class Annotators method init.

/**
 * Initialize the active annotators. This method must be called before any others.
 *
 * @param annotatorsConfig A (possibly empty) set of annotator configurations, in any form
 *                         supported by {@link ConfigLoader}
 */
public static synchronized void init(String annotatorsConfig) {
    ConfigLoader loader = new ConfigLoader();
    annotators = new ArrayList<>();
    LinkedHashMap<String, ServiceLoader.Provider<Annotator>> providers = getProviders();
    List<Map> configs = loader.load(annotatorsConfig, Map.class);
    if (configs != null) {
        for (Map cmap : configs) {
            Object typeObj = cmap.remove("type");
            String typename = typeObj.toString();
            ServiceLoader.Provider<Annotator> annotatorProvider = providers.get(typename);
            if (annotatorProvider == null) {
                throw new RuntimeException("Annotation provider with selector '" + typename + "' was not found.");
            }
            Annotator annotator = annotatorProvider.get();
            if (annotator instanceof NBMapConfigurable) {
                NBMapConfigurable NBMapConfigurable = (NBMapConfigurable) annotator;
                NBMapConfigurable.applyConfig(cmap);
            }
            if (annotator instanceof NBConfigurable) {
                NBConfigurable nbConfigurable = (NBConfigurable) annotator;
                NBConfiguration cfg = nbConfigurable.getConfigModel().apply(cmap);
                nbConfigurable.applyConfig(cfg);
            }
            annotators.add(annotator);
        }
    }
    logger.debug("Initialized " + Annotators.annotators.size() + " annotators, since the configuration is empty.");
}
Also used : NBConfigurable(io.nosqlbench.nb.api.config.standard.NBConfigurable) ConfigLoader(io.nosqlbench.nb.api.config.standard.ConfigLoader) NBMapConfigurable(io.nosqlbench.nb.api.config.standard.NBMapConfigurable) Annotator(io.nosqlbench.nb.api.annotations.Annotator) NBConfiguration(io.nosqlbench.nb.api.config.standard.NBConfiguration)

Aggregations

NBConfigurable (io.nosqlbench.nb.api.config.standard.NBConfigurable)2 NBConfiguration (io.nosqlbench.nb.api.config.standard.NBConfiguration)2 ActivityType (io.nosqlbench.engine.api.activityapi.core.ActivityType)1 StmtsDocList (io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList)1 DriverAdapter (io.nosqlbench.engine.api.activityimpl.uniform.DriverAdapter)1 StandardActivityType (io.nosqlbench.engine.api.activityimpl.uniform.StandardActivityType)1 Annotator (io.nosqlbench.nb.api.annotations.Annotator)1 ConfigLoader (io.nosqlbench.nb.api.config.standard.ConfigLoader)1 NBConfigModel (io.nosqlbench.nb.api.config.standard.NBConfigModel)1 NBMapConfigurable (io.nosqlbench.nb.api.config.standard.NBMapConfigurable)1