consolidate scenario transfer types

This commit is contained in:
Jonathan Shook 2020-08-14 10:05:54 -05:00
parent 20ef64d252
commit 3d16789b2f
4 changed files with 95 additions and 95 deletions

View File

@ -8,16 +8,14 @@ import io.nosqlbench.engine.cli.ScriptBuffer;
import io.nosqlbench.engine.core.ScenarioResult; import io.nosqlbench.engine.core.ScenarioResult;
import io.nosqlbench.engine.core.script.Scenario; import io.nosqlbench.engine.core.script.Scenario;
import io.nosqlbench.engine.core.script.ScenariosExecutor; import io.nosqlbench.engine.core.script.ScenariosExecutor;
import io.nosqlbench.engine.rest.services.WorkspaceService;
import io.nosqlbench.engine.rest.transfertypes.RunScenarioRequest; import io.nosqlbench.engine.rest.transfertypes.RunScenarioRequest;
import io.nosqlbench.engine.rest.transfertypes.ScenarioInfo; import io.nosqlbench.engine.rest.transfertypes.ScenarioInfo;
import io.nosqlbench.engine.rest.transfertypes.ResultInfo;
import io.nosqlbench.nb.annotations.Service; import io.nosqlbench.nb.annotations.Service;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.*;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
@ -32,6 +30,10 @@ public class ScenarioExecutorEndpoint implements WebServiceObject {
private ScenariosExecutor executor = new ScenariosExecutor("executor-service", 1); private ScenariosExecutor executor = new ScenariosExecutor("executor-service", 1);
@Context
private Configuration config;
@POST @POST
@Path("cli") @Path("cli")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ -92,12 +94,13 @@ public class ScenarioExecutorEndpoint implements WebServiceObject {
private void storeFiles(RunScenarioRequest rq) { private void storeFiles(RunScenarioRequest rq) {
Map<String, String> filemap = rq.getFilemap(); Map<String, String> filemap = rq.getFilemap();
WorkspaceService workspaces = new WorkspaceService(config);
for (String filename : filemap.keySet()) { for (String filename : filemap.keySet()) {
try { try {
Paths.get(rq.getBasedir(),rq.getScenarioName());
Files.createDirectories( Files.createDirectories(
Paths.get(rq.getBasedir(),rq.getScenarioName()), workspaces.getWorkspace(rq.getWorkspace()).getWorkspacePath(),
PosixFilePermissions.asFileAttribute( PosixFilePermissions.asFileAttribute(
PosixFilePermissions.fromString("rwxr-x---") PosixFilePermissions.fromString("rwxr-x---")
)); ));
@ -167,8 +170,10 @@ public class ScenarioExecutorEndpoint implements WebServiceObject {
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public synchronized ScenarioInfo getScenario(@PathParam("scenarioName") String scenarioName) { public synchronized ScenarioInfo getScenario(@PathParam("scenarioName") String scenarioName) {
Optional<Scenario> pendingScenario = executor.getPendingScenario(scenarioName); Optional<Scenario> pendingScenario = executor.getPendingScenario(scenarioName);
if (pendingScenario.isPresent()) { if (pendingScenario.isPresent()) {
return new ScenarioInfo(pendingScenario.get()); Optional<ScenarioResult> pendingResult = executor.getPendingResult(scenarioName);
return new ScenarioInfo(pendingScenario.get(),pendingResult.orElse(null));
} else { } else {
throw new RuntimeException("Scenario name '" + scenarioName + "' not found."); throw new RuntimeException("Scenario name '" + scenarioName + "' not found.");
} }
@ -178,33 +183,16 @@ public class ScenarioExecutorEndpoint implements WebServiceObject {
@Path("scenarios") @Path("scenarios")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public synchronized List<ScenarioInfo> getScenarios() { public synchronized List<ScenarioInfo> getScenarios() {
List<ScenarioInfo> scenarioInfos = new ArrayList<>(); List<ScenarioInfo> scenarioInfos = new ArrayList<>();
List<String> pendingScenarios = executor.getPendingScenarios(); List<String> pendingScenarios = executor.getPendingScenarios();
for (String pendingName : pendingScenarios) {
Optional<Scenario> pendingScenario = executor.getPendingScenario(pendingName); for (String pendingScenario : pendingScenarios) {
pendingScenario.ifPresent(scenario -> scenarioInfos.add(new ScenarioInfo(scenario))); ScenarioInfo scenarioInfo = getScenario(pendingScenario);
scenarioInfos.add(scenarioInfo);
} }
return scenarioInfos; return scenarioInfos;
} }
@GET
@Path("result/{scenarioName}")
@Produces(MediaType.APPLICATION_JSON)
public synchronized ResultInfo getResult(@PathParam("scenarioName") String scenarioName) {
return new ResultInfo(scenarioName, executor.getPendingResult(scenarioName).orElse(null));
}
@GET
@Path("results")
@Produces(MediaType.APPLICATION_JSON)
public synchronized List<ResultInfo> getResults() {
List<ResultInfo> results = new ArrayList<>();
List<String> pendingScenarios = executor.getPendingScenarios();
for (String pendingScenario : pendingScenarios) {
Optional<ScenarioResult> pendingResult = executor.getPendingResult(pendingScenario);
results.add(new ResultInfo(pendingScenario, pendingResult.orElse(null)));
}
return results;
}
} }

View File

@ -0,0 +1,36 @@
package io.nosqlbench.engine.rest.transfertypes;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.nosqlbench.engine.api.activityapi.core.ProgressMeter;
public class ProgressView {
private final ProgressMeter progressMeter;
public ProgressView(ProgressMeter progressMeter) {
this.progressMeter = progressMeter;
}
@JsonProperty("details")
public String getProgressDetails() {
return progressMeter.getProgressDetails();
}
@JsonProperty("name")
public String getName() {
return progressMeter.getProgressName();
}
@JsonProperty("state")
public String getState() {
return progressMeter.getProgressState().toString();
}
@JsonProperty("completed")
public double getProgress() {
return progressMeter.getProgress();
}
}

View File

@ -1,50 +0,0 @@
package io.nosqlbench.engine.rest.transfertypes;
import io.nosqlbench.engine.core.ScenarioResult;
/**
* TODO: Combine scenario status and pending state to one view
* <pre>{@code
* {
* "scenarioName": "myscenarioname",
* "isComplete": (true|false),
* "isErrored": (true|false),
* "ioLog": "IOLOGLine1\n...\n"
*
* [same progress data as for the pending scenario view]
*
* " whole scenario "
* [constructed link to grafana dashboard for current duration, with selected update interval]
*
* [create snapshot in grafana from the time range of the scenario once complete]
* [link to grafana snapshot]
*
* }
* }</pre>
*/
public class ResultInfo {
private final String scenarioName;
private final ScenarioResult result;
public ResultInfo(String scenarioName, ScenarioResult result) {
this.scenarioName = scenarioName;
this.result = result;
}
public String getScenarioName() {
return scenarioName;
}
public boolean isComplete() {
return result != null;
}
public boolean isErrored() {
return (result != null && result.getException().isPresent());
}
public String getIOLog() {
return result.getIOLog();
}
}

View File

@ -1,35 +1,61 @@
package io.nosqlbench.engine.rest.transfertypes; package io.nosqlbench.engine.rest.transfertypes;
import io.nosqlbench.engine.api.activityapi.core.ProgressMeter; import com.fasterxml.jackson.annotation.JsonProperty;
import io.nosqlbench.engine.core.ActivityExecutor;
import io.nosqlbench.engine.core.ScenarioResult;
import io.nosqlbench.engine.core.script.Scenario; import io.nosqlbench.engine.core.script.Scenario;
import java.util.Collection; import java.util.ArrayList;
import java.util.HashMap; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
public class ScenarioInfo { public class ScenarioInfo {
private final Scenario scenario;
public ScenarioInfo(Scenario scenario) { private final Scenario scenario;
private final ScenarioResult result;
public ScenarioInfo(Scenario scenario, ScenarioResult result) {
this.scenario = scenario; this.scenario = scenario;
this.result = result;
} }
@JsonProperty("scenario_name")
public String getScenarioName() { public String getScenarioName() {
return scenario.getScenarioName(); return scenario.getScenarioName();
} }
public Map<String,String> getProgress() { @JsonProperty("started_at")
Map<String,String> progress = new HashMap<>(); public long getStartMillis() {
return scenario.getStartedAtMillis();
}
Collection<ProgressMeter> progressMeters = @JsonProperty("ended_at")
scenario.getScenarioController().getProgressMeters(); public long getEndMillis() {
for (ProgressMeter meter : progressMeters) { return scenario.getEndedAtMillis();
String activityName = meter.getProgressName();
String activityProgress = meter.getProgressDetails(); }
if (activityName!=null && activityProgress!=null) {
progress.put(activityName, activityProgress); @JsonProperty("progress")
} public List<ProgressView> getProgress() {
List<ProgressView> progress = new ArrayList<>();
return scenario.getScenarioController().getProgressMeters()
.stream().map(ProgressView::new).collect(Collectors.toList());
}
@JsonProperty("activity_states")
public List<Map<String, String>> getActivityStates() {
List<Map<String, String>> states = new ArrayList<>();
for (ActivityExecutor ae : scenario.getScenarioController().getActivityExecutorMap().values()) {
states.add(
Map.of(
"name", ae.getProgressName(),
"completion", String.valueOf(ae.getProgress()),
"state", ae.getProgressState().toString()
)
);
} }
return progress; return states;
} }
} }