Permalink
Browse files

Rename /processes to /stages

  • Loading branch information...
dustalov committed Apr 6, 2016
1 parent 760fc1a commit 3efab412fd101b5b735b7fe2fc81b9ce4f67961f
@@ -63,7 +63,7 @@
* The application-wide map that contains stages. Since it is convenient to preserve the database
* row order, it is implemented as a <tt>LinkedHashMap</tt>.
*/
private final Map<String, Stage> processes = new LinkedHashMap<>();
private final Map<String, Stage> stages = new LinkedHashMap<>();

private DBI jdbi;
private ServiceLocator locator;
@@ -82,7 +82,7 @@ public ServiceLocator getLocator() {
}

public Map<String, Stage> getStages() {
return processes;
return stages;
}

@Override
@@ -105,24 +105,24 @@ public void initialize(Bootstrap<MechanicalTsarConfiguration> bootstrap) {
}

private void bootstrap(MechanicalTsarConfiguration configuration, Environment environment) throws ClassNotFoundException {
synchronized (processes) {
synchronized (stages) {
if (jdbi == null)
jdbi = new DBIFactory().build(environment, configuration.getDataSourceFactory(), "postgresql");

if (locator == null)
locator = Injections.createLocator(new ApplicationBinder(jdbi, processes));
locator = Injections.createLocator(new ApplicationBinder(jdbi, stages));

final StageDAO stageDAO = requireNonNull(locator.getService(StageDAO.class));
final List<Stage.Definition> definitions = stageDAO.select();
processes.clear();
stages.clear();

for (final Stage.Definition definition : definitions) {
final Class<? extends WorkerRanker> workerRankerClass = Class.forName(definition.getWorkerRanker()).asSubclass(WorkerRanker.class);
final Class<? extends TaskAllocator> taskAllocatorClass = Class.forName(definition.getTaskAllocator()).asSubclass(TaskAllocator.class);
final Class<? extends AnswerAggregator> answerAggregatorClass = Class.forName(definition.getAnswerAggregator()).asSubclass(AnswerAggregator.class);
final ServiceLocator processLocator = Injections.createLocator(locator, new StageBinder(definition, workerRankerClass, taskAllocatorClass, answerAggregatorClass));
final Stage stage = requireNonNull(processLocator.getService(Stage.class));
processes.put(definition.getId(), stage);
stages.put(definition.getId(), stage);
}
}
}
@@ -133,7 +133,7 @@ private Answer fetchAnswer(Integer id) {

private URI getAnswersURI(UriInfo uriInfo) {
return uriInfo.getBaseUriBuilder().
path("processes").path(stage.getId()).
path("stages").path(stage.getId()).
path("answers").
build();
}
@@ -37,15 +37,15 @@
@Produces(mtsar.util.MediaType.APPLICATION_JSON)
public class MetaResource {
private final MechanicalTsarVersion version;
private final Map<String, Stage> processes;
private final Map<String, Stage> stages;
private final TaskDAO taskDAO;
private final WorkerDAO workerDAO;
private final AnswerDAO answerDAO;

@Inject
public MetaResource(MechanicalTsarVersion version, @Named("stages") Map<String, Stage> processes, TaskDAO taskDAO, WorkerDAO workerDAO, AnswerDAO answerDAO) {
public MetaResource(MechanicalTsarVersion version, @Named("stages") Map<String, Stage> stages, TaskDAO taskDAO, WorkerDAO workerDAO, AnswerDAO answerDAO) {
this.version = version;
this.processes = processes;
this.stages = stages;
this.taskDAO = taskDAO;
this.workerDAO = workerDAO;
this.answerDAO = answerDAO;
@@ -54,7 +54,7 @@ public MetaResource(MechanicalTsarVersion version, @Named("stages") Map<String,
@GET
@Produces(MediaType.TEXT_HTML)
public DashboardView getDashboardView() {
return new DashboardView(version, processes, taskDAO, workerDAO, answerDAO);
return new DashboardView(version, stages, taskDAO, workerDAO, answerDAO);
}

@GET
@@ -41,7 +41,7 @@
import java.util.Map;

@Singleton
@Path("/processes")
@Path("/stages")
@Produces(mtsar.util.MediaType.APPLICATION_JSON)
public class StageResource {
private final Map<String, Stage> stages;
@@ -144,14 +144,14 @@ private Task fetchTask(Integer id) {

private URI getTasksURI(UriInfo uriInfo) {
return uriInfo.getBaseUriBuilder().
path("processes").path(stage.getId()).
path("stages").path(stage.getId()).
path("tasks").
build();
}

private URI getTaskURI(UriInfo uriInfo, Task task) {
return uriInfo.getBaseUriBuilder().
path("processes").path(stage.getId()).
path("stages").path(stage.getId()).
path("tasks").path(task.getId().toString()).
build();
}
@@ -274,14 +274,14 @@ private Task fetchTask(Integer id) {

private URI getWorkersURI(UriInfo uriInfo) {
return uriInfo.getBaseUriBuilder().
path("processes").path(stage.getId()).
path("stages").path(stage.getId()).
path("workers").
build();
}

private URI getWorkerURI(UriInfo uriInfo, Worker worker) {
return uriInfo.getBaseUriBuilder().
path("processes").path(stage.getId()).
path("stages").path(stage.getId()).
path("workers").path(worker.getId().toString()).
build();
}
@@ -56,15 +56,15 @@ public int getAnswerCount() {
@SuppressWarnings("unused")
public String getStagePath() {
return uriInfo.getBaseUriBuilder().
path("processes").
path("stages").
path(stage.getId()).
toString();
}

@SuppressWarnings("unused")
public String getPath() {
return uriInfo.getBaseUriBuilder().
path("processes").
path("stages").
path(stage.getId()).
path("answers").
toString();
@@ -56,15 +56,15 @@ public int getTaskCount() {
@SuppressWarnings("unused")
public String getStagePath() {
return uriInfo.getBaseUriBuilder().
path("processes").
path("stages").
path(stage.getId()).
toString();
}

@SuppressWarnings("unused")
public String getPath() {
return uriInfo.getBaseUriBuilder().
path("processes").
path("stages").
path(stage.getId()).
path("tasks").
toString();
@@ -56,15 +56,15 @@ public int getWorkerCount() {
@SuppressWarnings("unused")
public String getStagePath() {
return uriInfo.getBaseUriBuilder().
path("processes").
path("stages").
path(stage.getId()).
toString();
}

@SuppressWarnings("unused")
public String getPath() {
return uriInfo.getBaseUriBuilder().
path("processes").
path("stages").
path(stage.getId()).
path("workers").
toString();
@@ -23,7 +23,7 @@
</a>
</div>
<div class="pure-u-1-3">
<a href="/processes" class="pure-button height-large width-max">
<a href="/stages" class="pure-button height-large width-max">
<i class="fa fa-cog"></i> Stages
</a>
</div>
@@ -19,7 +19,7 @@
<tr>
<td>workerCount</td>
<td>{{workerCount}}</td>
<td class="align-center"><a class="button-xsmall pure-button" href="/processes/{{id}}/workers">Details</a>
<td class="align-center"><a class="button-xsmall pure-button" href="/stages/{{id}}/workers">Details</a>
</td>
</tr>
<tr>
@@ -30,7 +30,7 @@
<td>taskCount</td>
<td>{{taskCount}}</td>
<td class="align-center"><a class="button-xsmall pure-button"
href="/processes/{{id}}/tasks">Details</a></td>
href="/stages/{{id}}/tasks">Details</a></td>
</tr>
<tr>
<td>taskAllocator</td>
@@ -39,7 +39,7 @@
<tr>
<td>answerCount</td>
<td>{{answerCount}}</td>
<td class="align-center"><a class="button-xsmall pure-button" href="/processes/{{id}}/answers">Details</a>
<td class="align-center"><a class="button-xsmall pure-button" href="/stages/{{id}}/answers">Details</a>
</td>
</tr>
<tr>
@@ -15,7 +15,7 @@
<tbody>
{{#stages}}
<tr>
<td><a href="/processes/{{id}}">{{id}}</a></td>
<td><a href="/stages/{{id}}">{{id}}</a></td>
<td>{{description}}</td>
<td class="align-center">{{#workerCount}}{{id}}{{/workerCount}}</td>
<td class="align-center">{{#taskCount}}{{id}}{{/taskCount}}</td>
@@ -76,10 +76,10 @@ public void setup() {

@Test
public void testGetStages() {
final Collection<Map> processes = RULE.getJerseyTest().target("/processes").request()
final Collection<Map> stages = RULE.getJerseyTest().target("/stages").request()
.accept(MediaType.APPLICATION_JSON_TYPE).get(MAP_COLLECTION);
assertThat(processes).hasSize(1);
final Map representation = processes.iterator().next();
assertThat(stages).hasSize(1);
final Map representation = stages.iterator().next();
assertThat(representation.get("id")).isEqualTo(stage.getId());
}

@@ -88,7 +88,7 @@ public void testGetStagesView() {
when(taskDAO.count(anyString())).thenReturn(0);
when(workerDAO.count(anyString())).thenReturn(0);
when(answerDAO.count(anyString())).thenReturn(0);
assertThat(RULE.getJerseyTest().target("/processes").request()
assertThat(RULE.getJerseyTest().target("/stages").request()
.accept(MediaType.TEXT_HTML_TYPE).get().getStatusInfo())
.isEqualTo(Response.Status.OK);
}

1 comment on commit 3efab41

@dustalov

This comment has been minimized.

Copy link
Member Author

dustalov commented on 3efab41 Apr 6, 2016

Tested the commit verification feature.

Please sign in to comment.