Execution { @SuppressWarnings("OptionalUsedAsFieldOrParameterType") @JsonCreator public static Execution create( @JsonProperty("execution_id") Optional<String> executionId, @JsonProperty("docker_image") Optional<String> dockerImage, @JsonProperty("commit_sha") Optional<String> commitSha, @JsonProperty("flyte_exec_conf") Optional<FlyteExecConf> flyteExecConf, @JsonProperty("runner_id") Optional<String> runnerId, @JsonProperty("statuses") List<ExecStatus> statuses) { if (dockerImage.isPresent() && flyteExecConf.isPresent()) { throw new IllegalArgumentException( "Conflicting configuration: Both docker image and flyte conf specified for exec id: " + executionId.orElse("unknown") ); } return new AutoValue_Execution(executionId, dockerImage, commitSha, flyteExecConf, runnerId, statuses); }  @JsonProperty abstract Optional<String> executionId(); @JsonProperty abstract Optional<String> dockerImage(); @JsonProperty abstract Optional<String> commitSha(); @JsonProperty abstract Optional<FlyteExecConf> flyteExecConf(); @JsonProperty abstract Optional<String> runnerId(); @JsonProperty abstract List<ExecStatus> statuses(); @SuppressWarnings("OptionalUsedAsFieldOrParameterType") @JsonCreator static Execution create(
      @JsonProperty("execution_id") Optional<String> executionId,
      @JsonProperty("docker_image") Optional<String> dockerImage,
      @JsonProperty("commit_sha") Optional<String> commitSha,
      @JsonProperty("flyte_exec_conf") Optional<FlyteExecConf> flyteExecConf,
      @JsonProperty("runner_id") Optional<String> runnerId,
      @JsonProperty("statuses") List<ExecStatus> statuses); @SuppressWarnings("OptionalUsedAsFieldOrParameterType") static Execution create(
      Optional<String> executionId,
      Optional<String> dockerImage,
      Optional<String> commitSha,
      Optional<String> runnerId,
      List<ExecStatus> statuses); @SuppressWarnings("OptionalUsedAsFieldOrParameterType") static Execution create(
      Optional<String> executionId,
      Optional<FlyteExecConf> flyteExecConf,
      Optional<String> runnerId,
      List<ExecStatus> statuses);  }
@Test public void shouldParseFlyteExecutions() throws IOException { String json = "{" + "\"execution_id\":\"123\"," + "\"flyte_exec_conf\":{" + "\"reference_id\":{" + "\"resource_type\":\"lp\"," + "\"project\":\"flytetest\"," + "\"domain\":\"production\"," + "\"name\":\"GoldenPathWF\"," + "\"version\":\"1\"" + "}," + "\"input_fields\":{}" + "}," + "\"runner_id\":\"1\"," + "\"statuses\":[{\"timestamp\":\"2020-08-20T00:00:00.0Z\",\"status\":\"0\",\"message\":\"ok\"}]}"; var expectedExecution = Execution.create( Optional.of("123"), Optional.empty(), Optional.empty(), Optional.of(FLYTE_EXEC_CONF), Optional.of("1"), STATUS_LIST ); var actualExecution = Json.deserialize(ByteString.encodeUtf8(json), Execution.class); assertEquals(expectedExecution, actualExecution); }
@Test public void shouldNotBePossibleToCreateExecutionForDockerAndFlyte() { var exception = assertThrows(IllegalArgumentException.class, () -> Execution.create( Optional.of("123"), Optional.of("busybox"), Optional.of("1"), Optional.of(FLYTE_EXEC_CONF), Optional.of("1"), STATUS_LIST ) ); assertEquals( "Conflicting configuration: Both docker image and flyte conf specified for exec id: 123", exception.getMessage() ); }