Skip to content

Commit

Permalink
initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dzannotti committed Apr 21, 2020
1 parent 7495f63 commit ad2d6a6
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ docker/bootstrap/requirements.txt
*.iws
*.idea

# VSCode
.project

# generated self-signed cert
littleproxy_cert
littleproxy_keystore.jks
12 changes: 1 addition & 11 deletions digdag-cli/src/main/java/io/digdag/cli/client/ShowAttempt.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@ public SystemExitException usage(String error)
}

private void printAttempt(RestSessionAttempt attempt) {
String status;
if (attempt.getSuccess()) {
status = "success";
}
else if (attempt.getDone()) {
status = "error";
}
else {
status = "running";
}
ln(" session id: %s", attempt.getSessionId());
ln(" attempt id: %s", attempt.getId());
ln(" uuid: %s", attempt.getSessionUuid());
Expand All @@ -65,7 +55,7 @@ else if (attempt.getDone()) {
ln(" created at: %s", TimeUtil.formatTime(attempt.getCreatedAt()));
ln(" finished at: %s", attempt.getFinishedAt().transform(TimeUtil::formatTime).or(""));
ln(" kill requested: %s", attempt.getCancelRequested());
ln(" status: %s", status);
ln(" status: %s", attempt.getStatus());
ln("");
}
}
12 changes: 1 addition & 11 deletions digdag-cli/src/main/java/io/digdag/cli/client/ShowAttempts.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,6 @@ private void showAttempts(Id sessionId)
}

private void printAttempt(RestSessionAttempt attempt) {
String status;
if (attempt.getSuccess()) {
status = "success";
}
else if (attempt.getDone()) {
status = "error";
}
else {
status = "running";
}
ln(" session id: %s", attempt.getSessionId());
ln(" attempt id: %s", attempt.getId());
ln(" uuid: %s", attempt.getSessionUuid());
Expand All @@ -95,7 +85,7 @@ else if (attempt.getDone()) {
ln(" created at: %s", TimeUtil.formatTime(attempt.getCreatedAt()));
ln(" finished at: %s", attempt.getFinishedAt().transform(TimeUtil::formatTime).or(""));
ln(" kill requested: %s", attempt.getCancelRequested());
ln(" status: %s", status);
ln(" status: %s", attempt.getStatus());
ln("");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ default int getIndex()

Optional<Instant> getFinishedAt();

default String getStatus() {
if (this.getCancelRequested()) {
return "KILLED";
}
if (this.getSuccess()) {
return "SUCCESS";
}
if (!this.getSuccess() && this.getDone()) {
return "ERROR";
}
return "RUNNING";
}

static ImmutableRestSessionAttempt.Builder builder()
{
return ImmutableRestSessionAttempt.builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,96 @@ private String removeField(String json, String field)
assertThat(node.remove(field) == null, is(false));
return mapper.writeValueAsString(node);
}

@Test
public void testSessionAttemptStatusSuccess()
throws Exception
{
RestSessionAttempt attempt = RestSessionAttempt.builder()
.id(Id.of("1"))
.index(3)
.project(IdAndName.of(Id.of("1"), "p"))
.workflow(NameOptionalId.of("w", Optional.of(Id.of("1"))))
.sessionId(Id.of("1"))
.sessionUuid(UUID.randomUUID())
.sessionTime(OffsetDateTime.now(ZoneId.of("UTC")))
.retryAttemptName(Optional.absent())
.done(false)
.success(true)
.cancelRequested(false)
.params(newConfig())
.createdAt(Instant.now())
.finishedAt(Optional.absent())
.build();
assertThat(attempt.getStatus(), is("SUCCESS"));
}

@Test
public void testSessionAttemptStatusError()
throws Exception
{
RestSessionAttempt attempt = RestSessionAttempt.builder()
.id(Id.of("1"))
.index(3)
.project(IdAndName.of(Id.of("1"), "p"))
.workflow(NameOptionalId.of("w", Optional.of(Id.of("1"))))
.sessionId(Id.of("1"))
.sessionUuid(UUID.randomUUID())
.sessionTime(OffsetDateTime.now(ZoneId.of("UTC")))
.retryAttemptName(Optional.absent())
.done(true)
.success(false)
.cancelRequested(false)
.params(newConfig())
.createdAt(Instant.now())
.finishedAt(Optional.absent())
.build();
assertThat(attempt.getStatus(), is("ERROR"));
}

@Test
public void testSessionAttemptStatusKilled()
throws Exception
{
RestSessionAttempt attempt = RestSessionAttempt.builder()
.id(Id.of("1"))
.index(3)
.project(IdAndName.of(Id.of("1"), "p"))
.workflow(NameOptionalId.of("w", Optional.of(Id.of("1"))))
.sessionId(Id.of("1"))
.sessionUuid(UUID.randomUUID())
.sessionTime(OffsetDateTime.now(ZoneId.of("UTC")))
.retryAttemptName(Optional.absent())
.done(false)
.success(false)
.cancelRequested(true)
.params(newConfig())
.createdAt(Instant.now())
.finishedAt(Optional.absent())
.build();
assertThat(attempt.getStatus(), is("KILLED"));
}

@Test
public void testSessionAttemptStatusRunning()
throws Exception
{
RestSessionAttempt attempt = RestSessionAttempt.builder()
.id(Id.of("1"))
.index(3)
.project(IdAndName.of(Id.of("1"), "p"))
.workflow(NameOptionalId.of("w", Optional.of(Id.of("1"))))
.sessionId(Id.of("1"))
.sessionUuid(UUID.randomUUID())
.sessionTime(OffsetDateTime.now(ZoneId.of("UTC")))
.retryAttemptName(Optional.absent())
.done(false)
.success(false)
.cancelRequested(false)
.params(newConfig())
.createdAt(Instant.now())
.finishedAt(Optional.absent())
.build();
assertThat(attempt.getStatus(), is("RUNNING"));
}
}
14 changes: 14 additions & 0 deletions digdag-docs/src/_extra/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,13 @@ definitions:
cancelRequested:
type: "boolean"
default: false
status:
type: "string"
enum:
- "SUCCESS"
- "ERROR"
- "KILLED"
- "RUNNING"
RestLogFilePutResult:
type: "object"
properties:
Expand Down Expand Up @@ -1582,6 +1589,13 @@ definitions:
index:
type: "integer"
format: "int32"
status:
type: "string"
enum:
- "SUCCESS"
- "ERROR"
- "KILLED"
- "RUNNING"
OffsetDateTime:
type: "object"
properties:
Expand Down

0 comments on commit ad2d6a6

Please sign in to comment.