mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
feat(emr-serverless): start, get, list and cancel job runs (#6202)
Adds StartJobRun, GetJobRun, ListJobRuns and CancelJobRun under
/applications/{applicationId}/jobruns. Job runs are metadata only, like
Glue's: a run is RUNNING from submission and settles when read. With the
new floci.services.emrserverless.job-run-duration-seconds at its default
of 0, a BATCH run is SUCCESS as soon as it starts; a positive duration
keeps it RUNNING that long, and a run that would outlast its
executionTimeoutMinutes (720 when not given) is CANCELLED at the
timeout. A STREAMING run stays RUNNING until it is cancelled.
A run on a CREATED or STOPPED application starts it, as auto-start
defaults to on; with auto-start off the run is refused. clientToken is
the idempotency token: a retry returns the original run, and the same
token with another request answers ConflictException "Request did not
match the original". CancelJobRun on a finished run answers
ValidationException "Job run is not in a cancellable state". ListJobRuns
returns the newest runs first, filtered by states, creation time and
mode, and its nextToken resumes only the listing it came from. A run
needs a jobDriver that sets exactly one of sparkSubmit and hive, as
GetJobRun's JobRun always carries one, and tags are checked before
auto-start, so a refused run leaves the application as it was.
createdBy is the caller's ARN.
Application createdAt and updatedAt now go out as epoch seconds, the
restJson1 default for the model's Date shape, as job runs do. They were
epoch milliseconds, which the Java SDK reads as the year 58774 and
botocore refuses as out of range. Auto-start rewrites updatedAt, so a
run's own submission reached the bug. Applications persisted with
millisecond timestamps read back at the same instant.
Part of #6046 (part 8).
This commit is contained in:
1 parent
9e66185c9d
commit
1f1e5db1bc
25 files changed
+1918
-37
No files matched your search
@@ -1085,6 +1085,10 @@ public interface EmulatorConfig {
|
||||
interface EmrServerlessServiceConfig {
|
||||
@WithDefault("true")
|
||||
boolean enabled();
|
||||
|
||||
/** How long a BATCH job run stays RUNNING before it succeeds; 0 = a run succeeds as soon as it starts. */
|
||||
@WithDefault("0")
|
||||
int jobRunDurationSeconds();
|
||||
}
|
||||
|
||||
interface Route53ResolverServiceConfig {
|
||||
|
||||
+61
-1
@@ -4,13 +4,20 @@ import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.common.Pagination;
|
||||
import io.github.hectorvent.floci.services.emrserverless.model.Application;
|
||||
import io.github.hectorvent.floci.services.emrserverless.model.ApplicationSummary;
|
||||
import io.github.hectorvent.floci.services.emrserverless.model.CancelJobRunResponse;
|
||||
import io.github.hectorvent.floci.services.emrserverless.model.CreateApplicationRequest;
|
||||
import io.github.hectorvent.floci.services.emrserverless.model.CreateApplicationResponse;
|
||||
import io.github.hectorvent.floci.services.emrserverless.model.DeleteApplicationResponse;
|
||||
import io.github.hectorvent.floci.services.emrserverless.model.GetApplicationResponse;
|
||||
import io.github.hectorvent.floci.services.emrserverless.model.GetJobRunResponse;
|
||||
import io.github.hectorvent.floci.services.emrserverless.model.JobRun;
|
||||
import io.github.hectorvent.floci.services.emrserverless.model.JobRunSummary;
|
||||
import io.github.hectorvent.floci.services.emrserverless.model.ListApplicationsRequest;
|
||||
import io.github.hectorvent.floci.services.emrserverless.model.ListApplicationsResponse;
|
||||
import io.github.hectorvent.floci.services.emrserverless.model.ListJobRunsResponse;
|
||||
import io.github.hectorvent.floci.services.emrserverless.model.StartApplicationResponse;
|
||||
import io.github.hectorvent.floci.services.emrserverless.model.StartJobRunRequest;
|
||||
import io.github.hectorvent.floci.services.emrserverless.model.StartJobRunResponse;
|
||||
import io.github.hectorvent.floci.services.emrserverless.model.StopApplicationResponse;
|
||||
import io.github.hectorvent.floci.services.emrserverless.model.UpdateApplicationRequest;
|
||||
import io.github.hectorvent.floci.services.emrserverless.model.UpdateApplicationResponse;
|
||||
@@ -36,10 +43,12 @@ import java.util.List;
|
||||
public class EmrServerlessController {
|
||||
|
||||
private final EmrServerlessService service;
|
||||
private final EmrServerlessJobRunService jobRuns;
|
||||
|
||||
@Inject
|
||||
public EmrServerlessController(EmrServerlessService service) {
|
||||
public EmrServerlessController(EmrServerlessService service, EmrServerlessJobRunService jobRuns) {
|
||||
this.service = service;
|
||||
this.jobRuns = jobRuns;
|
||||
}
|
||||
|
||||
@POST
|
||||
@@ -116,4 +125,55 @@ public class EmrServerlessController {
|
||||
StopApplicationResponse response = new StopApplicationResponse();
|
||||
return response;
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/{applicationId}/jobruns")
|
||||
public StartJobRunResponse startJobRun(@PathParam("applicationId") String applicationId,
|
||||
StartJobRunRequest request) {
|
||||
JobRun run = jobRuns.startJobRun(applicationId, request);
|
||||
StartJobRunResponse response = new StartJobRunResponse();
|
||||
response.setApplicationId(run.getApplicationId());
|
||||
response.setJobRunId(run.getJobRunId());
|
||||
response.setArn(run.getArn());
|
||||
return response;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{applicationId}/jobruns")
|
||||
public ListJobRunsResponse listJobRuns(@PathParam("applicationId") String applicationId,
|
||||
@QueryParam("states") List<String> states,
|
||||
@QueryParam("createdAtAfter") String createdAtAfter,
|
||||
@QueryParam("createdAtBefore") String createdAtBefore,
|
||||
@QueryParam("mode") String mode,
|
||||
@QueryParam("maxResults") String maxResults,
|
||||
@QueryParam("nextToken") String nextToken) {
|
||||
PaginatedResult<JobRunSummary> page = jobRuns.listJobRuns(applicationId, states,
|
||||
EmrServerlessJobRunService.parseTimestamp(createdAtAfter, "createdAtAfter"),
|
||||
EmrServerlessJobRunService.parseTimestamp(createdAtBefore, "createdAtBefore"),
|
||||
mode, Pagination.parseMaxResults(maxResults, "ValidationException"), nextToken);
|
||||
ListJobRunsResponse response = new ListJobRunsResponse();
|
||||
response.setJobRuns(page.items());
|
||||
response.setNextToken(page.nextToken());
|
||||
return response;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{applicationId}/jobruns/{jobRunId}")
|
||||
public GetJobRunResponse getJobRun(@PathParam("applicationId") String applicationId,
|
||||
@PathParam("jobRunId") String jobRunId) {
|
||||
GetJobRunResponse response = new GetJobRunResponse();
|
||||
response.setJobRun(jobRuns.getJobRun(applicationId, jobRunId));
|
||||
return response;
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/{applicationId}/jobruns/{jobRunId}")
|
||||
public CancelJobRunResponse cancelJobRun(@PathParam("applicationId") String applicationId,
|
||||
@PathParam("jobRunId") String jobRunId) {
|
||||
JobRun run = jobRuns.cancelJobRun(applicationId, jobRunId);
|
||||
CancelJobRunResponse response = new CancelJobRunResponse();
|
||||
response.setApplicationId(run.getApplicationId());
|
||||
response.setJobRunId(run.getJobRunId());
|
||||
return response;
|
||||
}
|
||||
}
|
||||
+416
@@ -0,0 +1,416 @@
|
||||
package io.github.hectorvent.floci.services.emrserverless;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.common.Pagination;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.RequestContext;
|
||||
import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.emrserverless.model.Application;
|
||||
import io.github.hectorvent.floci.services.emrserverless.model.JobDriver;
|
||||
import io.github.hectorvent.floci.services.emrserverless.model.JobRun;
|
||||
import io.github.hectorvent.floci.services.emrserverless.model.JobRunRecord;
|
||||
import io.github.hectorvent.floci.services.emrserverless.model.JobRunSummary;
|
||||
import io.github.hectorvent.floci.services.emrserverless.model.StartJobRunRequest;
|
||||
import io.github.hectorvent.floci.services.iam.IamService;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* EMR Serverless job runs. Nothing executes: a run follows the job run states and GetJobRun's
|
||||
* shape, and settles lazily when read. Times are kept to the millisecond, as AWS reports them. With the default {@code job-run-duration-seconds} of 0 a
|
||||
* BATCH run is SUCCESS as soon as it starts; a positive duration keeps it RUNNING that long, which
|
||||
* makes CancelJobRun and the execution timeout observable. A STREAMING run, which EMR Serverless
|
||||
* "expects to run for a long time", stays RUNNING until it is cancelled.
|
||||
*
|
||||
* <p>Every public method is synchronized: admitting a run (look up its client token, then write
|
||||
* it), settling one and cancelling one each read and then write a run, and must not interleave.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class EmrServerlessJobRunService {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(EmrServerlessJobRunService.class);
|
||||
|
||||
static final String STATE_RUNNING = "RUNNING";
|
||||
static final String STATE_SUCCESS = "SUCCESS";
|
||||
static final String STATE_CANCELLED = "CANCELLED";
|
||||
private static final String MODE_BATCH = "BATCH";
|
||||
private static final String MODE_STREAMING = "STREAMING";
|
||||
|
||||
private static final Set<String> TERMINAL_STATES = Set.of(STATE_SUCCESS, "FAILED", STATE_CANCELLED);
|
||||
private static final List<String> MODES = List.of(MODE_BATCH, MODE_STREAMING);
|
||||
// JobRun.executionTimeoutMinutes: "If you didn't specify a timeout, this value defaults to 720 minutes."
|
||||
private static final long DEFAULT_EXECUTION_TIMEOUT_MINUTES = 720;
|
||||
// The model's Duration, which bounds executionTimeoutMinutes.
|
||||
private static final long MAX_EXECUTION_TIMEOUT_MINUTES = 1_000_000;
|
||||
private static final int MAX_LIST_RESULTS = 50;
|
||||
// IAMRoleArn's pattern, as the model and AWS's validation message spell it.
|
||||
private static final String ROLE_ARN_PATTERN =
|
||||
"arn:(aws[a-zA-Z0-9-]*):iam::([0-9]{12}):(role((\\u002F)|(\\u002F[\\u0021-\\u007F]+\\u002F))[\\w+=,.@-]+)";
|
||||
private static final Pattern ROLE_ARN = Pattern.compile(ROLE_ARN_PATTERN);
|
||||
|
||||
private final AccountAwareStorageBackend<JobRunRecord> store;
|
||||
private final EmrServerlessService applications;
|
||||
private final IamService iamService;
|
||||
private final RegionResolver regionResolver;
|
||||
private final RequestContext requestContext;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final int runDurationSeconds;
|
||||
private final Clock clock;
|
||||
|
||||
@Inject
|
||||
public EmrServerlessJobRunService(StorageFactory storageFactory, EmrServerlessService applications,
|
||||
IamService iamService, RegionResolver regionResolver,
|
||||
RequestContext requestContext, ObjectMapper objectMapper,
|
||||
EmulatorConfig config, Clock clock) {
|
||||
this(storageFactory.create("emrserverless", "emr-serverless-job-runs.json", new TypeReference<>() {}),
|
||||
applications, iamService, regionResolver, requestContext, objectMapper,
|
||||
config.services().emrserverless().jobRunDurationSeconds(), clock);
|
||||
}
|
||||
|
||||
EmrServerlessJobRunService(AccountAwareStorageBackend<JobRunRecord> store, EmrServerlessService applications,
|
||||
IamService iamService, RegionResolver regionResolver, RequestContext requestContext,
|
||||
ObjectMapper objectMapper, int runDurationSeconds, Clock clock) {
|
||||
if (runDurationSeconds < 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"floci.services.emrserverless.job-run-duration-seconds must not be negative: " + runDurationSeconds);
|
||||
}
|
||||
this.store = store;
|
||||
this.applications = applications;
|
||||
this.iamService = iamService;
|
||||
this.regionResolver = regionResolver;
|
||||
this.requestContext = requestContext;
|
||||
this.objectMapper = objectMapper;
|
||||
this.runDurationSeconds = runDurationSeconds;
|
||||
this.clock = clock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a run, or returns the run an earlier request with the same client token started. The
|
||||
* token is StartJobRun's idempotency token; reused with a different request it answers
|
||||
* {@code ConflictException} "Request did not match the original", as AWS does.
|
||||
*/
|
||||
public synchronized JobRun startJobRun(String applicationId, StartJobRunRequest request) {
|
||||
StartJobRunRequest body = request != null ? request : new StartJobRunRequest();
|
||||
validate(body);
|
||||
applications.getApplication(applicationId);
|
||||
JsonNode original = requestOf(applicationId, body);
|
||||
JobRunRecord existing = runWithClientToken(body.getClientToken());
|
||||
if (existing != null) {
|
||||
if (!original.equals(existing.getRequest())) {
|
||||
throw new AwsException("ConflictException", "Request did not match the original", 409);
|
||||
}
|
||||
return settle(existing).getJobRun();
|
||||
}
|
||||
// Before admission, which may auto-start the application: a refused run leaves it as it was.
|
||||
if (body.getTags() != null) {
|
||||
EmrServerlessService.validateTags(body.getTags());
|
||||
}
|
||||
JobRunRecord record = applications.admitJobRun(applicationId, app -> newRun(app, body, original));
|
||||
LOG.infov("Started EMR Serverless job run {0} on application {1}", record.getJobRun().getJobRunId(),
|
||||
applicationId);
|
||||
return settle(record).getJobRun();
|
||||
}
|
||||
|
||||
public synchronized JobRun getJobRun(String applicationId, String jobRunId) {
|
||||
applications.getApplication(applicationId);
|
||||
return settle(findRun(applicationId, jobRunId)).getJobRun();
|
||||
}
|
||||
|
||||
/**
|
||||
* The application's runs, newest first. ListJobRuns models no ResourceNotFoundException, so an
|
||||
* unknown application has no runs rather than an error. With several {@code states}, "the
|
||||
* resulting list will be grouped by the state", in the order the filter names them. A run
|
||||
* started without a mode is a BATCH run. A {@code nextToken} resumes only the listing it came
|
||||
* from: its cursor holds a state group, which means nothing under another application or filter.
|
||||
*/
|
||||
public synchronized PaginatedResult<JobRunSummary> listJobRuns(String applicationId, List<String> states,
|
||||
Instant createdAtAfter, Instant createdAtBefore,
|
||||
String mode, Integer maxResults, String nextToken) {
|
||||
if (maxResults != null) {
|
||||
String violation = outOfRange("maxResults", maxResults, 1, MAX_LIST_RESULTS);
|
||||
if (violation != null) {
|
||||
throw SmithyValidationErrors.validationException(violation);
|
||||
}
|
||||
}
|
||||
List<JobRunRecord> matching = new ArrayList<>();
|
||||
Map<String, String> cursors = new HashMap<>();
|
||||
for (JobRunRecord record : store.scan(key -> true)) {
|
||||
JobRun run = record.getJobRun();
|
||||
if (!applicationId.equals(run.getApplicationId()) || !inRequestRegion(run)) {
|
||||
continue;
|
||||
}
|
||||
settle(record);
|
||||
if ((states != null && !states.isEmpty() && !states.contains(run.getState()))
|
||||
|| (createdAtAfter != null && !run.getCreatedAt().isAfter(createdAtAfter))
|
||||
|| (createdAtBefore != null && !run.getCreatedAt().isBefore(createdAtBefore))
|
||||
|| (mode != null && !mode.equals(run.getMode() != null ? run.getMode() : MODE_BATCH))) {
|
||||
continue;
|
||||
}
|
||||
int group = states == null || states.isEmpty() ? 0 : states.indexOf(run.getState());
|
||||
cursors.put(run.getJobRunId(), String.format("%02d%020d%s", group,
|
||||
Long.MAX_VALUE - run.getCreatedAt().toEpochMilli(), run.getJobRunId()));
|
||||
matching.add(record);
|
||||
}
|
||||
String namespace = String.join("|", "ListJobRuns", applicationId,
|
||||
String.valueOf(states != null ? states : List.of()), String.valueOf(createdAtAfter),
|
||||
String.valueOf(createdAtBefore), String.valueOf(mode));
|
||||
PaginatedResult<JobRunRecord> page = Pagination.paginate(matching,
|
||||
record -> cursors.get(record.getJobRun().getJobRunId()),
|
||||
maxResults != null ? maxResults : MAX_LIST_RESULTS, nextToken, namespace,
|
||||
token -> new AwsException("ValidationException", "Invalid nextToken.", 400));
|
||||
return new PaginatedResult<>(page.items().stream().map(EmrServerlessJobRunService::toSummary).toList(),
|
||||
page.nextToken());
|
||||
}
|
||||
|
||||
/** Cancels a run that has not finished. A finished run is refused, with AWS's wording. */
|
||||
public synchronized JobRun cancelJobRun(String applicationId, String jobRunId) {
|
||||
applications.getApplication(applicationId);
|
||||
JobRunRecord record = settle(findRun(applicationId, jobRunId));
|
||||
if (isTerminal(record.getJobRun())) {
|
||||
throw new AwsException("ValidationException", "Job run is not in a cancellable state", 400);
|
||||
}
|
||||
finish(record, STATE_CANCELLED, clock.instant().truncatedTo(ChronoUnit.MILLIS));
|
||||
LOG.infov("Cancelled EMR Serverless job run {0} on application {1}", jobRunId, applicationId);
|
||||
return record.getJobRun();
|
||||
}
|
||||
|
||||
/**
|
||||
* A ListJobRuns time filter. Query-string timestamps are ISO 8601 in restJson1; epoch seconds
|
||||
* are accepted too.
|
||||
*/
|
||||
static Instant parseTimestamp(String value, String member) {
|
||||
if (value == null || value.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return OffsetDateTime.parse(value).toInstant();
|
||||
} catch (DateTimeParseException notIso) {
|
||||
try {
|
||||
return Instant.ofEpochMilli(Math.round(Double.parseDouble(value) * 1000));
|
||||
} catch (NumberFormatException notEpoch) {
|
||||
throw new AwsException("ValidationException", member + " must be a timestamp.", 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private JobRunRecord newRun(Application app, StartJobRunRequest request, JsonNode original) {
|
||||
AwsArnUtils.Arn applicationArn = AwsArnUtils.parse(app.getArn());
|
||||
String jobRunId = EmrServerlessService.newId();
|
||||
Instant now = clock.instant().truncatedTo(ChronoUnit.MILLIS);
|
||||
|
||||
JobRun run = new JobRun();
|
||||
run.setApplicationId(app.getApplicationId());
|
||||
run.setJobRunId(jobRunId);
|
||||
run.setName(request.getName());
|
||||
run.setArn(AwsArnUtils.Arn.of("emr-serverless", applicationArn.region(), applicationArn.accountId(),
|
||||
applicationArn.resource() + "/jobruns/" + jobRunId).toString());
|
||||
run.setCreatedBy(createdBy(applicationArn.accountId()));
|
||||
run.setCreatedAt(now);
|
||||
run.setUpdatedAt(now);
|
||||
run.setExecutionRole(request.getExecutionRoleArn());
|
||||
run.setExecutionIamPolicy(request.getExecutionIamPolicy());
|
||||
run.setState(STATE_RUNNING);
|
||||
run.setStateDetails("");
|
||||
run.setReleaseLabel(app.getReleaseLabel());
|
||||
run.setConfigurationOverrides(request.getConfigurationOverrides());
|
||||
run.setJobDriver(request.getJobDriver());
|
||||
run.setTags(request.getTags() != null ? new LinkedHashMap<>(request.getTags()) : new LinkedHashMap<>());
|
||||
run.setNetworkConfiguration(app.getNetworkConfiguration());
|
||||
run.setExecutionTimeoutMinutes(request.getExecutionTimeoutMinutes() != null
|
||||
? request.getExecutionTimeoutMinutes() : DEFAULT_EXECUTION_TIMEOUT_MINUTES);
|
||||
run.setMode(request.getMode());
|
||||
run.setRetryPolicy(request.getRetryPolicy());
|
||||
run.setStartedAt(now);
|
||||
|
||||
JobRunRecord record = new JobRunRecord();
|
||||
record.setJobRun(run);
|
||||
record.setClientToken(request.getClientToken());
|
||||
record.setRequest(original);
|
||||
record.setApplicationType(app.getType());
|
||||
store.put(jobRunId, record);
|
||||
return record;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finishes a BATCH run that has been RUNNING for the configured duration, or cancels it at its
|
||||
* execution timeout when that comes first: "If the job run exceeds this duration, Amazon EMR
|
||||
* Serverless cancels it automatically."
|
||||
*/
|
||||
private JobRunRecord settle(JobRunRecord record) {
|
||||
JobRun run = record.getJobRun();
|
||||
if (isTerminal(run) || MODE_STREAMING.equals(run.getMode())) {
|
||||
return record;
|
||||
}
|
||||
long timeoutSeconds = run.getExecutionTimeoutMinutes() == null || run.getExecutionTimeoutMinutes() == 0
|
||||
? Long.MAX_VALUE : run.getExecutionTimeoutMinutes() * 60;
|
||||
if (runDurationSeconds > timeoutSeconds) {
|
||||
Instant timedOutAt = run.getStartedAt().plusSeconds(timeoutSeconds);
|
||||
if (!clock.instant().isBefore(timedOutAt)) {
|
||||
finish(record, STATE_CANCELLED, timedOutAt);
|
||||
}
|
||||
return record;
|
||||
}
|
||||
Instant finishedAt = run.getStartedAt().plusSeconds(runDurationSeconds);
|
||||
if (!clock.instant().isBefore(finishedAt)) {
|
||||
finish(record, STATE_SUCCESS, finishedAt);
|
||||
}
|
||||
return record;
|
||||
}
|
||||
|
||||
private void finish(JobRunRecord record, String state, Instant endedAt) {
|
||||
JobRun run = record.getJobRun();
|
||||
run.setState(state);
|
||||
run.setEndedAt(endedAt);
|
||||
run.setUpdatedAt(endedAt);
|
||||
run.setTotalExecutionDurationSeconds((int) Duration.between(run.getStartedAt(), endedAt).toSeconds());
|
||||
store.put(run.getJobRunId(), record);
|
||||
}
|
||||
|
||||
private JobRunRecord findRun(String applicationId, String jobRunId) {
|
||||
return store.get(jobRunId)
|
||||
.filter(record -> applicationId.equals(record.getJobRun().getApplicationId()))
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"Job run " + jobRunId + " not found", 404));
|
||||
}
|
||||
|
||||
private JobRunRecord runWithClientToken(String clientToken) {
|
||||
for (JobRunRecord record : store.scan(key -> true)) {
|
||||
if (clientToken.equals(record.getClientToken()) && inRequestRegion(record.getJobRun())) {
|
||||
return record;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* What a retry must repeat: the application and every member of the body but the token itself.
|
||||
* Read back from its JSON text, so that its numbers compare equal to those of a stored request
|
||||
* once storage has written and read it.
|
||||
*/
|
||||
private JsonNode requestOf(String applicationId, StartJobRunRequest request) {
|
||||
ObjectNode node;
|
||||
try {
|
||||
node = (ObjectNode) objectMapper.readTree(objectMapper.writeValueAsString(request));
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new IllegalStateException("Cannot serialize a StartJobRun request", e);
|
||||
}
|
||||
node.remove("clientToken");
|
||||
node.put("applicationId", applicationId);
|
||||
return node;
|
||||
}
|
||||
|
||||
// The caller, as GetCallerIdentity reports it; the account root for a key IAM does not know.
|
||||
private String createdBy(String accountId) {
|
||||
String accessKeyId = requestContext != null ? requestContext.getAccessKeyId() : null;
|
||||
return iamService.resolveCallerArn(accessKeyId)
|
||||
.orElseGet(() -> regionResolver.buildGlobalArn("iam", accountId, "root"));
|
||||
}
|
||||
|
||||
private boolean inRequestRegion(JobRun run) {
|
||||
return regionResolver.getRegion().equals(AwsArnUtils.parse(run.getArn()).region());
|
||||
}
|
||||
|
||||
private static boolean isTerminal(JobRun run) {
|
||||
return TERMINAL_STATES.contains(run.getState());
|
||||
}
|
||||
|
||||
private static void validate(StartJobRunRequest request) {
|
||||
List<String> violations = new ArrayList<>();
|
||||
if (request.getClientToken() == null) {
|
||||
violations.add(notNull("clientToken"));
|
||||
}
|
||||
if (request.getExecutionRoleArn() == null) {
|
||||
violations.add(notNull("executionRoleArn"));
|
||||
} else if (!ROLE_ARN.matcher(request.getExecutionRoleArn()).matches()) {
|
||||
violations.add("Value at 'executionRoleArn' failed to satisfy constraint: "
|
||||
+ "Member must satisfy regular expression pattern: " + ROLE_ARN_PATTERN);
|
||||
}
|
||||
if (request.getMode() != null && !MODES.contains(request.getMode())) {
|
||||
violations.add("Value '" + request.getMode() + "' at 'mode' failed to satisfy constraint: "
|
||||
+ "Member must satisfy enum value set: " + MODES);
|
||||
}
|
||||
if (request.getExecutionTimeoutMinutes() != null) {
|
||||
String violation = outOfRange("executionTimeoutMinutes", request.getExecutionTimeoutMinutes(), 0,
|
||||
MAX_EXECUTION_TIMEOUT_MINUTES);
|
||||
if (violation != null) {
|
||||
violations.add(violation);
|
||||
}
|
||||
}
|
||||
JobDriver driver = request.getJobDriver();
|
||||
if (driver != null && driver.getSparkSubmit() != null && driver.getSparkSubmit().getEntryPoint() == null) {
|
||||
violations.add(notNull("jobDriver.sparkSubmit.entryPoint"));
|
||||
}
|
||||
if (driver != null && driver.getHive() != null && driver.getHive().getQuery() == null) {
|
||||
violations.add(notNull("jobDriver.hive.query"));
|
||||
}
|
||||
if (!violations.isEmpty()) {
|
||||
throw SmithyValidationErrors.validationException(violations);
|
||||
}
|
||||
// StartJobRun's shape leaves jobDriver optional, but GetJobRun's JobRun requires one, so a run is
|
||||
// refused without it. JobDriver is a union, "so only one of the following members can be
|
||||
// specified". No source gives AWS's wording for a run without a driver, or with both.
|
||||
if (driver == null || (driver.getSparkSubmit() == null) == (driver.getHive() == null)) {
|
||||
throw new AwsException("ValidationException", "jobDriver must contain exactly one union member", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static String notNull(String member) {
|
||||
return "Value null at '" + member + "' failed to satisfy constraint: Member must not be null";
|
||||
}
|
||||
|
||||
private static String outOfRange(String member, long value, long min, long max) {
|
||||
if (value < min) {
|
||||
return "Value '" + value + "' at '" + member + "' failed to satisfy constraint: "
|
||||
+ "Member must have value greater than or equal to " + min;
|
||||
}
|
||||
if (value > max) {
|
||||
return "Value '" + value + "' at '" + member + "' failed to satisfy constraint: "
|
||||
+ "Member must have value less than or equal to " + max;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static JobRunSummary toSummary(JobRunRecord record) {
|
||||
JobRun run = record.getJobRun();
|
||||
JobRunSummary summary = new JobRunSummary();
|
||||
summary.setApplicationId(run.getApplicationId());
|
||||
summary.setId(run.getJobRunId());
|
||||
summary.setName(run.getName());
|
||||
summary.setMode(run.getMode());
|
||||
summary.setArn(run.getArn());
|
||||
summary.setCreatedBy(run.getCreatedBy());
|
||||
summary.setCreatedAt(run.getCreatedAt());
|
||||
summary.setUpdatedAt(run.getUpdatedAt());
|
||||
summary.setExecutionRole(run.getExecutionRole());
|
||||
summary.setState(run.getState());
|
||||
summary.setStateDetails(run.getStateDetails());
|
||||
summary.setReleaseLabel(run.getReleaseLabel());
|
||||
summary.setType(record.getApplicationType());
|
||||
return summary;
|
||||
}
|
||||
}
|
||||
+53
-13
@@ -18,12 +18,15 @@ import io.github.hectorvent.floci.services.emrserverless.model.UpdateApplication
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -42,15 +45,17 @@ public class EmrServerlessService {
|
||||
private final EmulatorConfig config;
|
||||
private final AccountAwareStorageBackend<Application> storage;
|
||||
private final RegionResolver regionResolver;
|
||||
private final Clock clock;
|
||||
|
||||
@Inject
|
||||
RequestContext requestContext;
|
||||
|
||||
@Inject
|
||||
public EmrServerlessService(EmulatorConfig config, StorageFactory storageFactory,
|
||||
RegionResolver regionResolver) {
|
||||
RegionResolver regionResolver, Clock clock) {
|
||||
this.config = config;
|
||||
this.regionResolver = regionResolver;
|
||||
this.clock = clock;
|
||||
this.storage = storageFactory.create("emrserverless", "emr-serverless-applications.json",
|
||||
new TypeReference<Map<String, Application>>() {});
|
||||
}
|
||||
@@ -75,9 +80,9 @@ public class EmrServerlessService {
|
||||
}
|
||||
}
|
||||
|
||||
String id = generateId();
|
||||
String id = newId();
|
||||
String arn = buildArn(id);
|
||||
long now = System.currentTimeMillis();
|
||||
Instant createdAt = now();
|
||||
|
||||
Application app = new Application();
|
||||
app.setApplicationId(id);
|
||||
@@ -88,8 +93,8 @@ public class EmrServerlessService {
|
||||
app.setType(request.getType());
|
||||
app.setState("CREATED");
|
||||
app.setStateDetails("");
|
||||
app.setCreatedAt(now);
|
||||
app.setUpdatedAt(now);
|
||||
app.setCreatedAt(createdAt);
|
||||
app.setUpdatedAt(createdAt);
|
||||
if (request.getTags() != null) {
|
||||
validateTags(request.getTags());
|
||||
}
|
||||
@@ -188,7 +193,7 @@ public class EmrServerlessService {
|
||||
app.setJobLevelCostAllocationConfiguration(request.getJobLevelCostAllocationConfiguration());
|
||||
}
|
||||
|
||||
app.setUpdatedAt(System.currentTimeMillis());
|
||||
app.setUpdatedAt(now());
|
||||
storage.put(applicationId, app);
|
||||
return app;
|
||||
}
|
||||
@@ -200,7 +205,7 @@ public class EmrServerlessService {
|
||||
throw new AwsException("ValidationException", "Application must be in a stopped or created state in order to be deleted.", 400);
|
||||
}
|
||||
app.setState("TERMINATED");
|
||||
app.setUpdatedAt(System.currentTimeMillis());
|
||||
app.setUpdatedAt(now());
|
||||
storage.put(applicationId, app);
|
||||
}
|
||||
|
||||
@@ -214,7 +219,7 @@ public class EmrServerlessService {
|
||||
throw new AwsException("ValidationException", "Application is terminated.", 400);
|
||||
}
|
||||
app.setState("STARTED");
|
||||
app.setUpdatedAt(System.currentTimeMillis());
|
||||
app.setUpdatedAt(now());
|
||||
storage.put(applicationId, app);
|
||||
}
|
||||
|
||||
@@ -228,10 +233,40 @@ public class EmrServerlessService {
|
||||
throw new AwsException("ValidationException", "Application is terminated.", 400);
|
||||
}
|
||||
app.setState("STOPPED");
|
||||
app.setUpdatedAt(System.currentTimeMillis());
|
||||
app.setUpdatedAt(now());
|
||||
storage.put(applicationId, app);
|
||||
}
|
||||
|
||||
/**
|
||||
* Admits a job run to the application and returns what {@code admit} builds from it. An
|
||||
* application "only accepts jobs when it's in" STARTED, and auto-start, on unless the
|
||||
* application turns it off, starts a CREATED or STOPPED one "on job submission" (EMR Serverless
|
||||
* user guide, "Application states" and "Default application behavior"). This service's lock is
|
||||
* held throughout, so the application cannot be stopped or deleted while the run is admitted.
|
||||
*/
|
||||
public synchronized <T> T admitJobRun(String applicationId, Function<Application, T> admit) {
|
||||
Application app = getApplication(applicationId);
|
||||
String state = app.getState();
|
||||
if ("TERMINATED".equals(state)) {
|
||||
throw new AwsException("ValidationException", "Application is terminated.", 400);
|
||||
}
|
||||
if (!"STARTED".equals(state)) {
|
||||
if (!autoStartEnabled(app)) {
|
||||
throw new AwsException("ValidationException", "Application " + applicationId
|
||||
+ " must be started before a job run is submitted, as its auto-start is disabled.", 400);
|
||||
}
|
||||
startApplication(applicationId);
|
||||
app = getApplication(applicationId);
|
||||
}
|
||||
return admit.apply(app);
|
||||
}
|
||||
|
||||
// AutoStartConfig.enabled "Defaults to true".
|
||||
private static boolean autoStartEnabled(Application app) {
|
||||
return app.getAutoStartConfiguration() == null
|
||||
|| !Boolean.FALSE.equals(app.getAutoStartConfiguration().getEnabled());
|
||||
}
|
||||
|
||||
// ---- Tags ---------------------------------------------------------------------------------
|
||||
|
||||
public synchronized Map<String, String> listTags(String arn) {
|
||||
@@ -276,8 +311,8 @@ public class EmrServerlessService {
|
||||
/**
|
||||
* The application an EMR Serverless ARN names:
|
||||
* {@code arn:<partition>:emr-serverless:<region>:<account>:/applications/<id>}, the form
|
||||
* CreateApplication returns. A job run ARN ({@code .../jobruns/<id>}) is refused, as job runs are
|
||||
* not emulated.
|
||||
* CreateApplication returns. A job run ARN ({@code .../jobruns/<id>}) is refused, as job run tags
|
||||
* are not emulated yet.
|
||||
*/
|
||||
private Application applicationFor(String arn) {
|
||||
AwsArnUtils.Arn parsed;
|
||||
@@ -303,7 +338,7 @@ public class EmrServerlessService {
|
||||
}
|
||||
|
||||
/** At most 50 tags, each key and value within TagKey and TagValue and free of the reserved prefix. */
|
||||
private static void validateTags(Map<String, String> tags) {
|
||||
static void validateTags(Map<String, String> tags) {
|
||||
if (tags.size() > MAX_TAGS) {
|
||||
throw new AwsException("ValidationException",
|
||||
"A resource can have at most " + MAX_TAGS + " tags.", 400);
|
||||
@@ -334,7 +369,8 @@ public class EmrServerlessService {
|
||||
return text.regionMatches(true, 0, RESERVED_PREFIX, 0, RESERVED_PREFIX.length());
|
||||
}
|
||||
|
||||
private String generateId() {
|
||||
/** An application or job run id: 16 lowercase hexadecimal characters, within the model's [0-9a-z]+. */
|
||||
static String newId() {
|
||||
return UUID.randomUUID().toString().replace("-", "").substring(0, 16);
|
||||
}
|
||||
|
||||
@@ -356,6 +392,10 @@ public class EmrServerlessService {
|
||||
}
|
||||
}
|
||||
|
||||
private Instant now() {
|
||||
return clock.instant().truncatedTo(ChronoUnit.MILLIS);
|
||||
}
|
||||
|
||||
private ApplicationSummary toSummary(Application app) {
|
||||
ApplicationSummary summary = new ApplicationSummary();
|
||||
summary.setId(app.getApplicationId());
|
||||
|
||||
+22
-6
@@ -1,13 +1,22 @@
|
||||
package io.github.hectorvent.floci.services.emrserverless.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/** GetApplication's application. Timestamps go out as epoch seconds, the restJson1 default. */
|
||||
@RegisterForReflection
|
||||
public class Application {
|
||||
|
||||
// Applications persisted before their timestamps were epoch seconds hold epoch milliseconds, and
|
||||
// those read back as seconds. 1e11 seconds is the year 5138, while 1e11 milliseconds is 1973, before
|
||||
// any application, so a value at or past it was written as milliseconds.
|
||||
private static final long LEGACY_MILLIS_FLOOR = 100_000_000_000L;
|
||||
|
||||
private String applicationId;
|
||||
private String arn;
|
||||
private String name;
|
||||
@@ -16,8 +25,10 @@ public class Application {
|
||||
private String state;
|
||||
private String stateDetails;
|
||||
private String clientToken;
|
||||
private Long createdAt;
|
||||
private Long updatedAt;
|
||||
@JsonFormat(shape = JsonFormat.Shape.NUMBER)
|
||||
private Instant createdAt;
|
||||
@JsonFormat(shape = JsonFormat.Shape.NUMBER)
|
||||
private Instant updatedAt;
|
||||
private Map<String, String> tags;
|
||||
private String architecture;
|
||||
private Map<String, InitialCapacityConfig> initialCapacity;
|
||||
@@ -51,10 +62,10 @@ public class Application {
|
||||
public void setStateDetails(String stateDetails) { this.stateDetails = stateDetails; }
|
||||
public String getClientToken() { return clientToken; }
|
||||
public void setClientToken(String clientToken) { this.clientToken = clientToken; }
|
||||
public Long getCreatedAt() { return createdAt; }
|
||||
public void setCreatedAt(Long createdAt) { this.createdAt = createdAt; }
|
||||
public Long getUpdatedAt() { return updatedAt; }
|
||||
public void setUpdatedAt(Long updatedAt) { this.updatedAt = updatedAt; }
|
||||
public Instant getCreatedAt() { return createdAt; }
|
||||
public void setCreatedAt(Instant createdAt) { this.createdAt = fromLegacyMillis(createdAt); }
|
||||
public Instant getUpdatedAt() { return updatedAt; }
|
||||
public void setUpdatedAt(Instant updatedAt) { this.updatedAt = fromLegacyMillis(updatedAt); }
|
||||
public Map<String, String> getTags() { return tags; }
|
||||
public void setTags(Map<String, String> tags) { this.tags = tags; }
|
||||
public String getArchitecture() { return architecture; }
|
||||
@@ -87,4 +98,9 @@ public class Application {
|
||||
public void setIdentityCenterConfiguration(IdentityCenterConfiguration identityCenterConfiguration) { this.identityCenterConfiguration = identityCenterConfiguration; }
|
||||
public JobLevelCostAllocationConfiguration getJobLevelCostAllocationConfiguration() { return jobLevelCostAllocationConfiguration; }
|
||||
public void setJobLevelCostAllocationConfiguration(JobLevelCostAllocationConfiguration jobLevelCostAllocationConfiguration) { this.jobLevelCostAllocationConfiguration = jobLevelCostAllocationConfiguration; }
|
||||
|
||||
private static Instant fromLegacyMillis(Instant value) {
|
||||
return value != null && value.getEpochSecond() >= LEGACY_MILLIS_FLOOR
|
||||
? Instant.ofEpochMilli(value.getEpochSecond()) : value;
|
||||
}
|
||||
}
|
||||
+11
-6
@@ -1,19 +1,24 @@
|
||||
package io.github.hectorvent.floci.services.emrserverless.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
@RegisterForReflection
|
||||
public class ApplicationSummary {
|
||||
private String architecture;
|
||||
private String arn;
|
||||
private Long createdAt;
|
||||
@JsonFormat(shape = JsonFormat.Shape.NUMBER)
|
||||
private Instant createdAt;
|
||||
private String id;
|
||||
private String name;
|
||||
private String releaseLabel;
|
||||
private String state;
|
||||
private String stateDetails;
|
||||
private String type;
|
||||
private Long updatedAt;
|
||||
@JsonFormat(shape = JsonFormat.Shape.NUMBER)
|
||||
private Instant updatedAt;
|
||||
|
||||
public ApplicationSummary() {}
|
||||
|
||||
@@ -33,11 +38,11 @@ public class ApplicationSummary {
|
||||
this.arn = arn;
|
||||
}
|
||||
|
||||
public Long getCreatedAt() {
|
||||
public Instant getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(Long createdAt) {
|
||||
public void setCreatedAt(Instant createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
@@ -89,11 +94,11 @@ public class ApplicationSummary {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Long getUpdatedAt() {
|
||||
public Instant getUpdatedAt() {
|
||||
return updatedAt;
|
||||
}
|
||||
|
||||
public void setUpdatedAt(Long updatedAt) {
|
||||
public void setUpdatedAt(Instant updatedAt) {
|
||||
this.updatedAt = updatedAt;
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package io.github.hectorvent.floci.services.emrserverless.model;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
public class CancelJobRunResponse {
|
||||
private String applicationId;
|
||||
private String jobRunId;
|
||||
|
||||
public String getApplicationId() { return applicationId; }
|
||||
public void setApplicationId(String applicationId) { this.applicationId = applicationId; }
|
||||
public String getJobRunId() { return jobRunId; }
|
||||
public void setJobRunId(String jobRunId) { this.jobRunId = jobRunId; }
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package io.github.hectorvent.floci.services.emrserverless.model;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
public class GetJobRunResponse {
|
||||
private JobRun jobRun;
|
||||
|
||||
public JobRun getJobRun() { return jobRun; }
|
||||
public void setJobRun(JobRun jobRun) { this.jobRun = jobRun; }
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package io.github.hectorvent.floci.services.emrserverless.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** What a job run executes: a Spark submission or a Hive query. */
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class JobDriver {
|
||||
private SparkSubmit sparkSubmit;
|
||||
private Hive hive;
|
||||
|
||||
public SparkSubmit getSparkSubmit() { return sparkSubmit; }
|
||||
public void setSparkSubmit(SparkSubmit sparkSubmit) { this.sparkSubmit = sparkSubmit; }
|
||||
public Hive getHive() { return hive; }
|
||||
public void setHive(Hive hive) { this.hive = hive; }
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public static class SparkSubmit {
|
||||
private String entryPoint;
|
||||
private List<String> entryPointArguments;
|
||||
private String sparkSubmitParameters;
|
||||
|
||||
public String getEntryPoint() { return entryPoint; }
|
||||
public void setEntryPoint(String entryPoint) { this.entryPoint = entryPoint; }
|
||||
public List<String> getEntryPointArguments() { return entryPointArguments; }
|
||||
public void setEntryPointArguments(List<String> entryPointArguments) { this.entryPointArguments = entryPointArguments; }
|
||||
public String getSparkSubmitParameters() { return sparkSubmitParameters; }
|
||||
public void setSparkSubmitParameters(String sparkSubmitParameters) { this.sparkSubmitParameters = sparkSubmitParameters; }
|
||||
}
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public static class Hive {
|
||||
private String query;
|
||||
private String initQueryFile;
|
||||
private String parameters;
|
||||
|
||||
public String getQuery() { return query; }
|
||||
public void setQuery(String query) { this.query = query; }
|
||||
public String getInitQueryFile() { return initQueryFile; }
|
||||
public void setInitQueryFile(String initQueryFile) { this.initQueryFile = initQueryFile; }
|
||||
public String getParameters() { return parameters; }
|
||||
public void setParameters(String parameters) { this.parameters = parameters; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package io.github.hectorvent.floci.services.emrserverless.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Map;
|
||||
|
||||
/** GetJobRun's jobRun. Timestamps go out as epoch seconds, the restJson1 default. */
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class JobRun {
|
||||
private String applicationId;
|
||||
private String jobRunId;
|
||||
private String name;
|
||||
private String arn;
|
||||
private String createdBy;
|
||||
@JsonFormat(shape = JsonFormat.Shape.NUMBER)
|
||||
private Instant createdAt;
|
||||
@JsonFormat(shape = JsonFormat.Shape.NUMBER)
|
||||
private Instant updatedAt;
|
||||
private String executionRole;
|
||||
private Map<String, Object> executionIamPolicy;
|
||||
private String state;
|
||||
private String stateDetails;
|
||||
private String releaseLabel;
|
||||
private Map<String, Object> configurationOverrides;
|
||||
private JobDriver jobDriver;
|
||||
private Map<String, String> tags;
|
||||
private NetworkConfiguration networkConfiguration;
|
||||
private Integer totalExecutionDurationSeconds;
|
||||
private Long executionTimeoutMinutes;
|
||||
private String mode;
|
||||
private Map<String, Object> retryPolicy;
|
||||
@JsonFormat(shape = JsonFormat.Shape.NUMBER)
|
||||
private Instant startedAt;
|
||||
@JsonFormat(shape = JsonFormat.Shape.NUMBER)
|
||||
private Instant endedAt;
|
||||
|
||||
public String getApplicationId() { return applicationId; }
|
||||
public void setApplicationId(String applicationId) { this.applicationId = applicationId; }
|
||||
public String getJobRunId() { return jobRunId; }
|
||||
public void setJobRunId(String jobRunId) { this.jobRunId = jobRunId; }
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
public String getArn() { return arn; }
|
||||
public void setArn(String arn) { this.arn = arn; }
|
||||
public String getCreatedBy() { return createdBy; }
|
||||
public void setCreatedBy(String createdBy) { this.createdBy = createdBy; }
|
||||
public Instant getCreatedAt() { return createdAt; }
|
||||
public void setCreatedAt(Instant createdAt) { this.createdAt = createdAt; }
|
||||
public Instant getUpdatedAt() { return updatedAt; }
|
||||
public void setUpdatedAt(Instant updatedAt) { this.updatedAt = updatedAt; }
|
||||
public String getExecutionRole() { return executionRole; }
|
||||
public void setExecutionRole(String executionRole) { this.executionRole = executionRole; }
|
||||
public Map<String, Object> getExecutionIamPolicy() { return executionIamPolicy; }
|
||||
public void setExecutionIamPolicy(Map<String, Object> executionIamPolicy) { this.executionIamPolicy = executionIamPolicy; }
|
||||
public String getState() { return state; }
|
||||
public void setState(String state) { this.state = state; }
|
||||
public String getStateDetails() { return stateDetails; }
|
||||
public void setStateDetails(String stateDetails) { this.stateDetails = stateDetails; }
|
||||
public String getReleaseLabel() { return releaseLabel; }
|
||||
public void setReleaseLabel(String releaseLabel) { this.releaseLabel = releaseLabel; }
|
||||
public Map<String, Object> getConfigurationOverrides() { return configurationOverrides; }
|
||||
public void setConfigurationOverrides(Map<String, Object> configurationOverrides) { this.configurationOverrides = configurationOverrides; }
|
||||
public JobDriver getJobDriver() { return jobDriver; }
|
||||
public void setJobDriver(JobDriver jobDriver) { this.jobDriver = jobDriver; }
|
||||
public Map<String, String> getTags() { return tags; }
|
||||
public void setTags(Map<String, String> tags) { this.tags = tags; }
|
||||
public NetworkConfiguration getNetworkConfiguration() { return networkConfiguration; }
|
||||
public void setNetworkConfiguration(NetworkConfiguration networkConfiguration) { this.networkConfiguration = networkConfiguration; }
|
||||
public Integer getTotalExecutionDurationSeconds() { return totalExecutionDurationSeconds; }
|
||||
public void setTotalExecutionDurationSeconds(Integer totalExecutionDurationSeconds) { this.totalExecutionDurationSeconds = totalExecutionDurationSeconds; }
|
||||
public Long getExecutionTimeoutMinutes() { return executionTimeoutMinutes; }
|
||||
public void setExecutionTimeoutMinutes(Long executionTimeoutMinutes) { this.executionTimeoutMinutes = executionTimeoutMinutes; }
|
||||
public String getMode() { return mode; }
|
||||
public void setMode(String mode) { this.mode = mode; }
|
||||
public Map<String, Object> getRetryPolicy() { return retryPolicy; }
|
||||
public void setRetryPolicy(Map<String, Object> retryPolicy) { this.retryPolicy = retryPolicy; }
|
||||
public Instant getStartedAt() { return startedAt; }
|
||||
public void setStartedAt(Instant startedAt) { this.startedAt = startedAt; }
|
||||
public Instant getEndedAt() { return endedAt; }
|
||||
public void setEndedAt(Instant endedAt) { this.endedAt = endedAt; }
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package io.github.hectorvent.floci.services.emrserverless.model;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
/**
|
||||
* A stored job run: the run as GetJobRun reports it, plus what only Floci needs. The client token
|
||||
* and the request it came with decide whether a repeated StartJobRun is a retry or a conflict; the
|
||||
* application type fills ListJobRuns' {@code type}.
|
||||
*/
|
||||
@RegisterForReflection
|
||||
public class JobRunRecord {
|
||||
private JobRun jobRun;
|
||||
private String clientToken;
|
||||
private JsonNode request;
|
||||
private String applicationType;
|
||||
|
||||
public JobRun getJobRun() { return jobRun; }
|
||||
public void setJobRun(JobRun jobRun) { this.jobRun = jobRun; }
|
||||
public String getClientToken() { return clientToken; }
|
||||
public void setClientToken(String clientToken) { this.clientToken = clientToken; }
|
||||
public JsonNode getRequest() { return request; }
|
||||
public void setRequest(JsonNode request) { this.request = request; }
|
||||
public String getApplicationType() { return applicationType; }
|
||||
public void setApplicationType(String applicationType) { this.applicationType = applicationType; }
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package io.github.hectorvent.floci.services.emrserverless.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
/** One entry of ListJobRuns. Unlike JobRun, the run's id is {@code id}. */
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class JobRunSummary {
|
||||
private String applicationId;
|
||||
private String id;
|
||||
private String name;
|
||||
private String mode;
|
||||
private String arn;
|
||||
private String createdBy;
|
||||
@JsonFormat(shape = JsonFormat.Shape.NUMBER)
|
||||
private Instant createdAt;
|
||||
@JsonFormat(shape = JsonFormat.Shape.NUMBER)
|
||||
private Instant updatedAt;
|
||||
private String executionRole;
|
||||
private String state;
|
||||
private String stateDetails;
|
||||
private String releaseLabel;
|
||||
private String type;
|
||||
|
||||
public String getApplicationId() { return applicationId; }
|
||||
public void setApplicationId(String applicationId) { this.applicationId = applicationId; }
|
||||
public String getId() { return id; }
|
||||
public void setId(String id) { this.id = id; }
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
public String getMode() { return mode; }
|
||||
public void setMode(String mode) { this.mode = mode; }
|
||||
public String getArn() { return arn; }
|
||||
public void setArn(String arn) { this.arn = arn; }
|
||||
public String getCreatedBy() { return createdBy; }
|
||||
public void setCreatedBy(String createdBy) { this.createdBy = createdBy; }
|
||||
public Instant getCreatedAt() { return createdAt; }
|
||||
public void setCreatedAt(Instant createdAt) { this.createdAt = createdAt; }
|
||||
public Instant getUpdatedAt() { return updatedAt; }
|
||||
public void setUpdatedAt(Instant updatedAt) { this.updatedAt = updatedAt; }
|
||||
public String getExecutionRole() { return executionRole; }
|
||||
public void setExecutionRole(String executionRole) { this.executionRole = executionRole; }
|
||||
public String getState() { return state; }
|
||||
public void setState(String state) { this.state = state; }
|
||||
public String getStateDetails() { return stateDetails; }
|
||||
public void setStateDetails(String stateDetails) { this.stateDetails = stateDetails; }
|
||||
public String getReleaseLabel() { return releaseLabel; }
|
||||
public void setReleaseLabel(String releaseLabel) { this.releaseLabel = releaseLabel; }
|
||||
public String getType() { return type; }
|
||||
public void setType(String type) { this.type = type; }
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package io.github.hectorvent.floci.services.emrserverless.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class ListJobRunsResponse {
|
||||
private List<JobRunSummary> jobRuns;
|
||||
private String nextToken;
|
||||
|
||||
public List<JobRunSummary> getJobRuns() { return jobRuns; }
|
||||
public void setJobRuns(List<JobRunSummary> jobRuns) { this.jobRuns = jobRuns; }
|
||||
public String getNextToken() { return nextToken; }
|
||||
public void setNextToken(String nextToken) { this.nextToken = nextToken; }
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package io.github.hectorvent.floci.services.emrserverless.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* StartJobRun's body. configurationOverrides, executionIamPolicy and retryPolicy are kept as sent
|
||||
* and returned by GetJobRun unchanged.
|
||||
*/
|
||||
@RegisterForReflection
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class StartJobRunRequest {
|
||||
private String clientToken;
|
||||
private String executionRoleArn;
|
||||
private Map<String, Object> executionIamPolicy;
|
||||
private JobDriver jobDriver;
|
||||
private Map<String, Object> configurationOverrides;
|
||||
private Map<String, String> tags;
|
||||
private Long executionTimeoutMinutes;
|
||||
private String name;
|
||||
private String mode;
|
||||
private Map<String, Object> retryPolicy;
|
||||
|
||||
public String getClientToken() { return clientToken; }
|
||||
public void setClientToken(String clientToken) { this.clientToken = clientToken; }
|
||||
public String getExecutionRoleArn() { return executionRoleArn; }
|
||||
public void setExecutionRoleArn(String executionRoleArn) { this.executionRoleArn = executionRoleArn; }
|
||||
public Map<String, Object> getExecutionIamPolicy() { return executionIamPolicy; }
|
||||
public void setExecutionIamPolicy(Map<String, Object> executionIamPolicy) { this.executionIamPolicy = executionIamPolicy; }
|
||||
public JobDriver getJobDriver() { return jobDriver; }
|
||||
public void setJobDriver(JobDriver jobDriver) { this.jobDriver = jobDriver; }
|
||||
public Map<String, Object> getConfigurationOverrides() { return configurationOverrides; }
|
||||
public void setConfigurationOverrides(Map<String, Object> configurationOverrides) { this.configurationOverrides = configurationOverrides; }
|
||||
public Map<String, String> getTags() { return tags; }
|
||||
public void setTags(Map<String, String> tags) { this.tags = tags; }
|
||||
public Long getExecutionTimeoutMinutes() { return executionTimeoutMinutes; }
|
||||
public void setExecutionTimeoutMinutes(Long executionTimeoutMinutes) { this.executionTimeoutMinutes = executionTimeoutMinutes; }
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
public String getMode() { return mode; }
|
||||
public void setMode(String mode) { this.mode = mode; }
|
||||
public Map<String, Object> getRetryPolicy() { return retryPolicy; }
|
||||
public void setRetryPolicy(Map<String, Object> retryPolicy) { this.retryPolicy = retryPolicy; }
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package io.github.hectorvent.floci.services.emrserverless.model;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
public class StartJobRunResponse {
|
||||
private String applicationId;
|
||||
private String jobRunId;
|
||||
private String arn;
|
||||
|
||||
public String getApplicationId() { return applicationId; }
|
||||
public void setApplicationId(String applicationId) { this.applicationId = applicationId; }
|
||||
public String getJobRunId() { return jobRunId; }
|
||||
public void setJobRunId(String jobRunId) { this.jobRunId = jobRunId; }
|
||||
public String getArn() { return arn; }
|
||||
public void setArn(String arn) { this.arn = arn; }
|
||||
}
|
||||
Reference in new issue
Block a user