Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Commit

Permalink
Merge pull request #4 from spotify/clean
Browse files Browse the repository at this point in the history
Remove v0 workflow instances API
  • Loading branch information
rouzwawi authored Nov 29, 2016
2 parents ac76136 + bfb5d44 commit 1dddfe5
Show file tree
Hide file tree
Showing 16 changed files with 5 additions and 892 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,15 @@
import static com.spotify.styx.api.Middlewares.json;
import static com.spotify.styx.util.StreamUtil.cat;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.google.auto.value.AutoValue;
import com.google.common.base.Throwables;
import com.spotify.apollo.Request;
import com.spotify.apollo.RequestContext;
import com.spotify.apollo.Response;
import com.spotify.apollo.Status;
import com.spotify.apollo.route.AsyncHandler;
import com.spotify.apollo.route.Route;
import com.spotify.styx.model.ExecutionStatus;
import com.spotify.styx.model.Workflow;
import com.spotify.styx.model.WorkflowExecutionInfo;
import com.spotify.styx.model.WorkflowId;
import com.spotify.styx.model.WorkflowInstance;
import com.spotify.styx.model.WorkflowInstanceExecutionData;
Expand All @@ -48,10 +42,8 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import okio.ByteString;

Expand All @@ -73,10 +65,10 @@ public Stream<? extends Route<? extends AsyncHandler<? extends Response<ByteStri
rc -> workflow(arg("cid", rc), arg("eid", rc))),
Route.with(
json(), "GET", BASE + "/<cid>/<eid>/instances",
rc -> instancesOld(arg("cid", rc), arg("eid", rc))),
rc -> Response.forStatus(Status.NOT_FOUND.withReasonPhrase("Use v1 api"))),
Route.with(
json(), "GET", BASE + "/<cid>/<eid>/instances/<iid>",
rc -> instanceOld(arg("cid", rc), arg("eid", rc), arg("iid", rc))),
rc -> Response.forStatus(Status.NOT_FOUND.withReasonPhrase("Use v1 api"))),
Route.with(
json(), "GET", BASE + "/<cid>/<eid>/state",
rc -> state(arg("cid", rc), arg("eid", rc))),
Expand Down Expand Up @@ -205,44 +197,6 @@ private Response<WorkflowState> state(String componentId, String endpointId) {
return Response.forPayload(workflowState);
}

private Response<List<WorkflowInstanceJson>> instancesOld(
String componentId,
String endpointId) {

final WorkflowId workflowId = WorkflowId.create(componentId, endpointId);

final List<WorkflowInstanceJson> workflowInstances;
try {
final Map<WorkflowInstance, List<WorkflowExecutionInfo>> executionInfos =
storage.getExecutionInfo(workflowId);
workflowInstances = executionInfos.entrySet().stream()
.map(entry -> getWorkflowInstance(entry.getKey(), entry.getValue()))
.collect(Collectors.toList());
} catch (IOException e) {
throw Throwables.propagate(e);
}

return Response.forPayload(workflowInstances);
}

private Response<WorkflowInstanceJson> instanceOld(
String componentId,
String endpointId,
String instanceId) {

final WorkflowId workflowId = WorkflowId.create(componentId, endpointId);
final WorkflowInstance workflowInstance = WorkflowInstance.create(workflowId, instanceId);

final WorkflowInstanceJson workflowInstanceJson;
try {
final List<WorkflowExecutionInfo> executionInfos = storage.getExecutionInfo(workflowInstance);
workflowInstanceJson = getWorkflowInstance(workflowInstance, executionInfos);
} catch (IOException e) {
throw Throwables.propagate(e);
}
return Response.forPayload(workflowInstanceJson);
}

private Response<List<WorkflowInstanceExecutionData>> instances(String componentId, String endpointId) {
final WorkflowId workflowId = WorkflowId.create(componentId, endpointId);
final List<WorkflowInstanceExecutionData> data;
Expand Down Expand Up @@ -274,79 +228,11 @@ private Response<WorkflowInstanceExecutionData> instance(
}
}

private WorkflowInstanceJson getWorkflowInstance(
WorkflowInstance workflowInstance,
List<WorkflowExecutionInfo> execInfos) {

final List<WorkflowInstanceExecutionJson> executions = execInfos.stream()
.map(this::execJson)
.collect(Collectors.toList());

return WorkflowInstanceJson.create(
workflowInstance.workflowId(),
workflowInstance.parameter(),
JsonNodeFactory.instance.objectNode(),
executions);
}

private WorkflowInstanceExecutionJson execJson(WorkflowExecutionInfo execInfo) {
return WorkflowInstanceExecutionJson.create(
execInfo.when().toString(), execInfo.executionStatus(), execInfo.executionId());
}

private static boolean isValidSHA1(String s) {
return s.matches("[a-fA-F0-9]{40}");
}

private static String arg(String name, RequestContext rc) {
return rc.pathArgs().get(name);
}

@AutoValue
abstract static class WorkflowInstanceJson {

@JsonProperty
public abstract WorkflowId workflowId();

@JsonProperty
public abstract String when();

@JsonProperty
public abstract JsonNode parameters();

@JsonProperty
public abstract List<WorkflowInstanceExecutionJson> executions();

static WorkflowInstanceJson create(
WorkflowId workflowId,
String when,
JsonNode parameters,
List<WorkflowInstanceExecutionJson> executions) {
return new AutoValue_WorkflowResource_WorkflowInstanceJson(
workflowId, when, parameters, executions);
}
}

@AutoValue
abstract static class WorkflowInstanceExecutionJson {

@JsonProperty
public abstract String when();

@JsonProperty
public abstract ExecutionStatus status();

@JsonProperty
public abstract Optional<String> executionId();

static WorkflowInstanceExecutionJson create(
String when,
ExecutionStatus status,
Optional<String> executionId) {
return new AutoValue_WorkflowResource_WorkflowInstanceExecutionJson(
when,
status,
executionId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

Expand Down Expand Up @@ -277,8 +276,8 @@ public void shouldReturnBadRequestOnImageWhenWorkflowNotFound() throws Exception
public void shouldReturnBadRequestOnImageWhenComponentNotFound() throws Exception {
}

@Theory
public void shouldReturnBadRequestWhenMalformedStatePayloadIsSent(Api.Version version) throws Exception {
@Test
public void shouldReturnBadRequestWhenMalformedStatePayloadIsSent() throws Exception {
Response<ByteString> response =
awaitResponse(serviceHelper.request("PATCH", path("/foo/bar/state"),
STATEPAYLOAD_BAD));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.google.cloud.datastore.Datastore;
import com.spotify.styx.model.SequenceEvent;
import com.spotify.styx.model.Workflow;
import com.spotify.styx.model.WorkflowExecutionInfo;
import com.spotify.styx.model.WorkflowId;
import com.spotify.styx.model.WorkflowInstance;
import com.spotify.styx.model.WorkflowInstanceExecutionData;
Expand Down Expand Up @@ -102,23 +101,6 @@ public List<WorkflowInstanceExecutionData> executionData(WorkflowId workflowId)
return bigtableStorage.executionData(workflowId);
}

@Override
public void store(WorkflowExecutionInfo workflowExecutionInfo) throws IOException {
bigtableStorage.store(workflowExecutionInfo);
}

@Override
public Map<WorkflowInstance, List<WorkflowExecutionInfo>> getExecutionInfo(WorkflowId workflowId)
throws IOException {
return bigtableStorage.getExecutionInfo(workflowId);
}

@Override
public List<WorkflowExecutionInfo> getExecutionInfo(WorkflowInstance workflowInstance)
throws IOException {
return bigtableStorage.getExecutionInfo(workflowInstance);
}

@Override
public boolean enabled(WorkflowId workflowId) throws IOException {
return datastoreStorage.enabled(workflowId);
Expand Down
Loading

0 comments on commit 1dddfe5

Please sign in to comment.