mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
delegate activity instancing to dedicated loader
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2022 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.engine.core.lifecycle.activity;
|
||||
|
||||
import io.nosqlbench.api.engine.activityimpl.ActivityDef;
|
||||
import io.nosqlbench.engine.api.activityapi.core.Activity;
|
||||
import io.nosqlbench.engine.api.activityimpl.uniform.StandardActivityType;
|
||||
import io.nosqlbench.engine.core.lifecycle.scenario.Scenario;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Consolidates the activity type and activity instantiation logic into one place
|
||||
* per scope. Within the lifetime of this ActivityLoader, all activities may
|
||||
* see each other by name.
|
||||
*/
|
||||
public class ActivityLoader {
|
||||
private final static Logger logger = LogManager.getLogger("ACTIVITIES");
|
||||
private final Map<String, Activity> activityMap = new ConcurrentHashMap<>();
|
||||
private final Scenario scenario;
|
||||
|
||||
public ActivityLoader(Scenario scenario) {
|
||||
this.scenario = scenario;
|
||||
}
|
||||
|
||||
public synchronized Activity loadActivity(ActivityDef activityDef) {
|
||||
Activity activity = new StandardActivityType(activityDef).getAssembledActivity(activityDef, activityMap);
|
||||
activityMap.put(activity.getAlias(),activity);
|
||||
logger.debug("Resolved activity for alias '" + activityDef.getAlias() + "'");
|
||||
return activity;
|
||||
}
|
||||
|
||||
public void purgeActivity(String activityAlias) {
|
||||
this.activityMap.remove(activityAlias);
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.engine.core.lifecycle;
|
||||
package io.nosqlbench.engine.core.lifecycle.activity;
|
||||
|
||||
import io.nosqlbench.engine.api.activityapi.core.ActivityType;
|
||||
import io.nosqlbench.api.engine.activityimpl.ActivityDef;
|
||||
@@ -150,18 +150,6 @@ public class ActivityTypeLoader {
|
||||
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 {
|
||||
@@ -47,11 +47,13 @@ public class ScenarioController {
|
||||
private static final Logger logger = LogManager.getLogger(ScenarioController.class);
|
||||
private static final Logger scenariologger = LogManager.getLogger("SCENARIO");
|
||||
|
||||
private final Map<String, ActivityThreadsManager> activityExecutors = new ConcurrentHashMap<>();
|
||||
private final String sessionId;
|
||||
private final ActivityLoader activityLoader;
|
||||
|
||||
private final Map<String, ActivityRuntimeInfo> activityInfoMap = new ConcurrentHashMap<>();
|
||||
private final Scenario scenario;
|
||||
private final Maturity minMaturity;
|
||||
|
||||
private ExecutorService activitiesExecutor;
|
||||
private final ExecutorService activitiesExecutor;
|
||||
|
||||
public ScenarioController(Scenario scenario, Maturity minMaturity) {
|
||||
this.scenario = scenario;
|
||||
|
||||
Reference in New Issue
Block a user