Search in sources :

Example 1 with ActivityType

use of io.nosqlbench.engine.api.activityapi.core.ActivityType 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 ActivityType

use of io.nosqlbench.engine.api.activityapi.core.ActivityType in project nosqlbench by nosqlbench.

the class ActivityTypeLoader method load.

public Optional<ActivityType> load(ActivityDef activityDef) {
    final String driverName = activityDef.getParams().getOptionalString("driver", "type").orElseThrow(() -> new BasicError("The parameter 'driver=' is required."));
    activityDef.getParams().getOptionalString("jar").map(jar -> {
        Set<URL> urls = NBIO.local().search(jar).list().stream().map(Content::getURL).collect(Collectors.toSet());
        return urls;
    }).ifPresent(this::extendClassLoader);
    return this.getDriverAdapter(driverName, activityDef).or(() -> ACTIVITYTYPE_SPI_FINDER.getOptionally(driverName));
}
Also used : NBConfigModel(io.nosqlbench.nb.api.config.standard.NBConfigModel) java.util(java.util) DriverAdapter(io.nosqlbench.engine.api.activityimpl.uniform.DriverAdapter) ActivityDef(io.nosqlbench.engine.api.activityimpl.ActivityDef) Maturity(io.nosqlbench.nb.annotations.Maturity) MalformedURLException(java.net.MalformedURLException) Files(java.nio.file.Files) StandardActivityType(io.nosqlbench.engine.api.activityimpl.uniform.StandardActivityType) URL(java.net.URL) Content(io.nosqlbench.nb.api.content.Content) Collectors(java.util.stream.Collectors) NBIO(io.nosqlbench.nb.api.content.NBIO) BasicError(io.nosqlbench.nb.api.errors.BasicError) URLClassLoader(java.net.URLClassLoader) Logger(org.apache.logging.log4j.Logger) StmtsDocList(io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList) StatementsLoader(io.nosqlbench.engine.api.activityconfig.StatementsLoader) NBConfiguration(io.nosqlbench.nb.api.config.standard.NBConfiguration) LogManager(org.apache.logging.log4j.LogManager) Path(java.nio.file.Path) ActivityType(io.nosqlbench.engine.api.activityapi.core.ActivityType) NBEnvironment(io.nosqlbench.nb.api.NBEnvironment) NBConfigurable(io.nosqlbench.nb.api.config.standard.NBConfigurable) SimpleServiceLoader(io.nosqlbench.nb.api.spi.SimpleServiceLoader) Content(io.nosqlbench.nb.api.content.Content) BasicError(io.nosqlbench.nb.api.errors.BasicError)

Example 3 with ActivityType

use of io.nosqlbench.engine.api.activityapi.core.ActivityType in project nosqlbench by nosqlbench.

the class MetricsMapper method metricsDetail.

public static String metricsDetail(String activitySpec) {
    // StringBuilder metricsDetail = new StringBuilder();
    List<String> metricsDetails = new ArrayList<>();
    ActivityDef activityDef = ActivityDef.parseActivityDef(activitySpec);
    logger.info("introspecting metric names for " + activitySpec);
    Optional<ActivityType> activityType = new ActivityTypeLoader().load(activityDef);
    if (!activityType.isPresent()) {
        throw new RuntimeException("Activity type '" + activityDef.getActivityType() + "' does not exist in this runtime.");
    }
    Activity activity = activityType.get().getAssembledActivity(activityDef, new HashMap<>());
    PolyglotMetricRegistryBindings nashornMetricRegistryBindings = new PolyglotMetricRegistryBindings(ActivityMetrics.getMetricRegistry());
    activity.initActivity();
    activity.getInputDispenserDelegate().getInput(0);
    activity.getActionDispenserDelegate().getAction(0);
    activity.getMotorDispenserDelegate().getMotor(activityDef, 0);
    Map<String, Metric> metricMap = nashornMetricRegistryBindings.getMetrics();
    for (Map.Entry<String, Metric> metricEntry : metricMap.entrySet()) {
        String metricName = metricEntry.getKey();
        Metric metricValue = metricEntry.getValue();
        Map<String, String> getterSummary = getGetterSummary(metricValue);
        // details.put(metricName,getterSummary);
        List<String> methodDetails = getterSummary.entrySet().stream().map(es -> metricName + es.getKey() + "  " + es.getValue()).collect(Collectors.toList());
        methodDetails.sort(String::compareTo);
        String getterText = methodDetails.stream().collect(Collectors.joining("\n"));
        metricsDetails.add(metricName + "\n" + getterText);
    }
    return metricsDetails.stream().collect(Collectors.joining("\n"));
}
Also used : java.util(java.util) ActivityDef(io.nosqlbench.engine.api.activityimpl.ActivityDef) Predicate(java.util.function.Predicate) Timer(java.util.Timer) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ActivityMetrics(io.nosqlbench.engine.api.metrics.ActivityMetrics) ActivityTypeLoader(io.nosqlbench.engine.core.lifecycle.ActivityTypeLoader) Logger(org.apache.logging.log4j.Logger) com.codahale.metrics(com.codahale.metrics) Activity(io.nosqlbench.engine.api.activityapi.core.Activity) PolyglotMetricRegistryBindings(io.nosqlbench.engine.core.metrics.PolyglotMetricRegistryBindings) LogManager(org.apache.logging.log4j.LogManager) Method(java.lang.reflect.Method) ActivityType(io.nosqlbench.engine.api.activityapi.core.ActivityType) ActivityType(io.nosqlbench.engine.api.activityapi.core.ActivityType) Activity(io.nosqlbench.engine.api.activityapi.core.Activity) ActivityDef(io.nosqlbench.engine.api.activityimpl.ActivityDef) PolyglotMetricRegistryBindings(io.nosqlbench.engine.core.metrics.PolyglotMetricRegistryBindings) ActivityTypeLoader(io.nosqlbench.engine.core.lifecycle.ActivityTypeLoader)

Aggregations

ActivityType (io.nosqlbench.engine.api.activityapi.core.ActivityType)3 StmtsDocList (io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList)2 ActivityDef (io.nosqlbench.engine.api.activityimpl.ActivityDef)2 DriverAdapter (io.nosqlbench.engine.api.activityimpl.uniform.DriverAdapter)2 StandardActivityType (io.nosqlbench.engine.api.activityimpl.uniform.StandardActivityType)2 NBConfigModel (io.nosqlbench.nb.api.config.standard.NBConfigModel)2 NBConfigurable (io.nosqlbench.nb.api.config.standard.NBConfigurable)2 NBConfiguration (io.nosqlbench.nb.api.config.standard.NBConfiguration)2 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 com.codahale.metrics (com.codahale.metrics)1 Activity (io.nosqlbench.engine.api.activityapi.core.Activity)1 StatementsLoader (io.nosqlbench.engine.api.activityconfig.StatementsLoader)1 ActivityMetrics (io.nosqlbench.engine.api.metrics.ActivityMetrics)1 ActivityTypeLoader (io.nosqlbench.engine.core.lifecycle.ActivityTypeLoader)1 PolyglotMetricRegistryBindings (io.nosqlbench.engine.core.metrics.PolyglotMetricRegistryBindings)1 Maturity (io.nosqlbench.nb.annotations.Maturity)1 NBEnvironment (io.nosqlbench.nb.api.NBEnvironment)1