mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(emr): give a cluster a bootstrap failure ended its ErrorDetails (#8267)
A cluster whose bootstrap action failed in the docker runner mode ended with BOOTSTRAP_FAILURE and AWS's message, but DescribeCluster and ListClusters gave no Status.ErrorDetails, which the Management Guide's error code pages point to for the failed action, its return code and its script. - An action that exits with another code than 0 gives BOOTSTRAP_FAILURE_PRIMARY_WITH_NON_ZERO_CODE, with the ErrorData keys its page lists: primary-instance-id, bootstrap-action, return-code, amazon-s3-path and public-doc. A script that cannot be read gives BOOTSTRAP_FAILURE_BA_DOWNLOAD_FAILED_PRIMARY, with the same keys but return-code. ErrorData is a list of maps and no source shows how AWS spreads the keys over them: Floci gives one map holding them all. ErrorMessage is the reason's message and the error code's page, in Floci's words. - A bootstrap that cannot run at all, or that Floci stopped, ends with INTERNAL_ERROR as before and has no ErrorDetails: no documented code fits. - The details are stored with the cluster, so they survive a restart with persistent storage, and emr.md says what Floci gives.
This commit is contained in:
1 parent
d13d4cceb6
commit
16ff5a2c74
7 files changed
+195
-8
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package io.floci.aws.services.emr;
|
||||
|
||||
import io.floci.aws.services.emr.model.EmrCluster;
|
||||
import io.floci.aws.services.emr.model.EmrErrorDetail;
|
||||
import io.floci.aws.services.emr.model.EmrInstanceFleet;
|
||||
import io.floci.aws.services.emr.model.EmrInstanceGroup;
|
||||
import io.floci.aws.services.emr.model.EmrStep;
|
||||
@@ -242,12 +243,14 @@ final class EmrClusterLifecycle {
|
||||
/**
|
||||
* The bootstrap actions a cluster ran for real have ended: when {@code failureCode} is null they all
|
||||
* succeeded and left {@code image}, which its steps run in, and the cluster is ready to run them;
|
||||
* otherwise the cluster ends, for {@code failureCode} and {@code message}.
|
||||
* otherwise the cluster ends, for {@code failureCode} and {@code message}, with {@code errorDetails} as
|
||||
* its Status.ErrorDetails.
|
||||
*/
|
||||
void bootstrapEnded(EmrCluster cluster, String image, String failureCode, String message, Instant at,
|
||||
String region) {
|
||||
void bootstrapEnded(EmrCluster cluster, String image, String failureCode, String message,
|
||||
List<EmrErrorDetail> errorDetails, Instant at, String region) {
|
||||
cluster.setBootstrapInContainer(false);
|
||||
if (failureCode != null) {
|
||||
cluster.setErrorDetails(new ArrayList<>(errorDetails));
|
||||
terminate(cluster, failureCode, message, at, region);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import io.floci.aws.core.common.PaginatedResult;
|
||||
import io.floci.aws.core.common.SmithyValidationErrors;
|
||||
import io.floci.aws.services.emr.model.EmrBlockPublicAccess;
|
||||
import io.floci.aws.services.emr.model.EmrCluster;
|
||||
import io.floci.aws.services.emr.model.EmrErrorDetail;
|
||||
import io.floci.aws.services.emr.model.EmrInstanceFleet;
|
||||
import io.floci.aws.services.emr.model.EmrInstanceGroup;
|
||||
import io.floci.aws.services.emr.model.EmrStep;
|
||||
@@ -741,6 +742,19 @@ public class EmrHandler {
|
||||
putEpoch(timeline, "CreationDateTime", c.getCreationDateTime());
|
||||
putEpoch(timeline, "ReadyDateTime", c.getReadyDateTime());
|
||||
putEpoch(timeline, "EndDateTime", c.getEndDateTime());
|
||||
if (!c.getErrorDetails().isEmpty()) {
|
||||
ArrayNode details = status.putArray("ErrorDetails");
|
||||
for (EmrErrorDetail detail : c.getErrorDetails()) {
|
||||
ObjectNode node = details.addObject();
|
||||
node.put("ErrorCode", detail.getErrorCode());
|
||||
ArrayNode data = node.putArray("ErrorData");
|
||||
for (Map<String, String> pairs : detail.getErrorData()) {
|
||||
ObjectNode map = data.addObject();
|
||||
pairs.forEach(map::put);
|
||||
}
|
||||
node.put("ErrorMessage", detail.getErrorMessage());
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import io.floci.aws.core.storage.StorageBackend;
|
||||
import io.floci.aws.core.storage.StorageFactory;
|
||||
import io.floci.aws.services.emr.model.EmrBlockPublicAccess;
|
||||
import io.floci.aws.services.emr.model.EmrCluster;
|
||||
import io.floci.aws.services.emr.model.EmrErrorDetail;
|
||||
import io.floci.aws.services.emr.model.EmrInstanceFleet;
|
||||
import io.floci.aws.services.emr.model.EmrInstanceGroup;
|
||||
import io.floci.aws.services.emr.model.EmrStep;
|
||||
@@ -103,6 +104,11 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
"On the master instance (%s), bootstrap action %d could not be read from %s: %s";
|
||||
private static final String BOOTSTRAP_NOT_RUN = "Floci could not run the bootstrap actions: %s";
|
||||
static final String BOOTSTRAP_INTERRUPTED = "Floci stopped while the cluster's bootstrap actions were running.";
|
||||
// The ErrorDetail codes of an action that failed on the primary node and of one whose script it could not download,
|
||||
// each with a Management Guide page of its own name.
|
||||
static final String BOOTSTRAP_FAILURE_PRIMARY_WITH_NON_ZERO_CODE = "BOOTSTRAP_FAILURE_PRIMARY_WITH_NON_ZERO_CODE";
|
||||
static final String BOOTSTRAP_FAILURE_BA_DOWNLOAD_FAILED_PRIMARY = "BOOTSTRAP_FAILURE_BA_DOWNLOAD_FAILED_PRIMARY";
|
||||
private static final String ERROR_CODE_PAGE = "https://docs.aws.amazon.com/emr/latest/ManagementGuide/%s.html";
|
||||
// The release whose EMR Serverless Hive image runs the HDFS of a cluster of the AWS runtime for Apache Spark,
|
||||
// which publishes none. Hadoop keeps its wire protocols compatible across a major version's minor releases, so
|
||||
// a newer client, such as the runtime's, reaches its NameNode.
|
||||
@@ -1307,8 +1313,8 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
|| bootstrapping.contains(clusterKey(regionResolver.getAccountId(), cluster.getId()))) {
|
||||
return false;
|
||||
}
|
||||
lifecycle.bootstrapEnded(cluster, null, EmrClusterLifecycle.INTERNAL_ERROR, BOOTSTRAP_INTERRUPTED, now(),
|
||||
regionOf(cluster));
|
||||
lifecycle.bootstrapEnded(cluster, null, EmrClusterLifecycle.INTERNAL_ERROR, BOOTSTRAP_INTERRUPTED, List.of(),
|
||||
now(), regionOf(cluster));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1939,6 +1945,7 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
String master = masterInstanceId(cluster);
|
||||
String code = EmrClusterLifecycle.BOOTSTRAP_FAILURE;
|
||||
String message;
|
||||
List<EmrErrorDetail> errorDetails = List.of();
|
||||
if (outcome.image() != null) {
|
||||
code = null;
|
||||
message = null;
|
||||
@@ -1946,18 +1953,46 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
cluster.setBootstrapImageRunsYarn(runsYarn(cluster));
|
||||
} else if (outcome.exitCode() != null) {
|
||||
message = BOOTSTRAP_ACTION_FAILED.formatted(master, outcome.failedAction());
|
||||
errorDetails = List.of(bootstrapErrorDetail(BOOTSTRAP_FAILURE_PRIMARY_WITH_NON_ZERO_CODE, master,
|
||||
outcome.failedAction(), outcome.exitCode(), bootstrap, message));
|
||||
} else if (outcome.failedAction() != null) {
|
||||
message = BOOTSTRAP_ACTION_NOT_READ.formatted(master, outcome.failedAction(),
|
||||
bootstrap.actions().get(outcome.failedAction() - 1).path(), outcome.failure());
|
||||
errorDetails = List.of(bootstrapErrorDetail(BOOTSTRAP_FAILURE_BA_DOWNLOAD_FAILED_PRIMARY, master,
|
||||
outcome.failedAction(), null, bootstrap, message));
|
||||
} else {
|
||||
code = EmrClusterLifecycle.INTERNAL_ERROR;
|
||||
message = BOOTSTRAP_NOT_RUN.formatted(outcome.failure());
|
||||
}
|
||||
lifecycle.bootstrapEnded(cluster, outcome.image(), code, message, now(), regionOf(cluster));
|
||||
lifecycle.bootstrapEnded(cluster, outcome.image(), code, message, errorDetails, now(), regionOf(cluster));
|
||||
store(cluster);
|
||||
LOG.infov("The bootstrap actions of EMR cluster {0} ended; it is {1}", cluster.getId(), cluster.getState());
|
||||
}
|
||||
|
||||
/**
|
||||
* The ErrorDetail of bootstrap action {@code action}, counted from 1, that failed on the primary node
|
||||
* {@code master} for {@code code}, with the ErrorData its Management Guide page gives: the primary node, the
|
||||
* action, its return code when it ran ({@code returnCode}, null when it did not), its script and the page itself.
|
||||
* The model makes ErrorData a list of maps, and no source shows how the keys spread over them: Floci puts them all
|
||||
* in one, which a client that reads the first map and one that merges them all read alike. ErrorMessage is
|
||||
* "Description of the error with a link to more information in the Amazon EMR documentation", whose text AWS does
|
||||
* not give: Floci's is the cluster's reason, {@code message}, and the page.
|
||||
*/
|
||||
private static EmrErrorDetail bootstrapErrorDetail(String code, String master, int action, Integer returnCode,
|
||||
BootstrapRunner.Bootstrap bootstrap, String message) {
|
||||
String page = ERROR_CODE_PAGE.formatted(code);
|
||||
Map<String, String> data = new LinkedHashMap<>();
|
||||
data.put("primary-instance-id", master);
|
||||
data.put("bootstrap-action", String.valueOf(action));
|
||||
if (returnCode != null) {
|
||||
data.put("return-code", String.valueOf(returnCode));
|
||||
}
|
||||
data.put("amazon-s3-path", bootstrap.actions().get(action - 1).path());
|
||||
data.put("public-doc", page);
|
||||
String sentence = message.endsWith(".") ? message : message + ".";
|
||||
return new EmrErrorDetail(code, List.of(data), sentence + " For more information, see " + page);
|
||||
}
|
||||
|
||||
/** The EC2 instance id ListInstances gives a cluster's instance {@code index}, counted from 1. */
|
||||
static String ec2InstanceId(long index) {
|
||||
return "i-" + String.format("%017d", index);
|
||||
|
||||
@@ -68,6 +68,8 @@ public class EmrCluster {
|
||||
private Instant endDateTime;
|
||||
// When the cluster began TERMINATING; Floci's own, as the API's Timeline has no such time.
|
||||
private Instant terminatingDateTime;
|
||||
// Status.ErrorDetails: the errors that ended the cluster, empty unless one of those with an ErrorDetail code did.
|
||||
private List<EmrErrorDetail> errorDetails = new ArrayList<>();
|
||||
private Map<String, String> tags = new LinkedHashMap<>();
|
||||
private List<EmrStep> steps = new ArrayList<>();
|
||||
private List<EmrInstanceGroup> instanceGroups = new ArrayList<>();
|
||||
@@ -217,6 +219,9 @@ public class EmrCluster {
|
||||
public Instant getTerminatingDateTime() { return terminatingDateTime; }
|
||||
public void setTerminatingDateTime(Instant terminatingDateTime) { this.terminatingDateTime = terminatingDateTime; }
|
||||
|
||||
public List<EmrErrorDetail> getErrorDetails() { return errorDetails; }
|
||||
public void setErrorDetails(List<EmrErrorDetail> errorDetails) { this.errorDetails = errorDetails; }
|
||||
|
||||
public Map<String, String> getTags() { return tags; }
|
||||
public void setTags(Map<String, String> tags) { this.tags = tags; }
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package io.floci.aws.services.emr.model;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* One of a cluster's ErrorDetails, "A tuple that provides information about an error that caused a cluster to
|
||||
* terminate": its ErrorCode, its ErrorData, a list of key-value maps, and its ErrorMessage.
|
||||
*/
|
||||
@RegisterForReflection
|
||||
public class EmrErrorDetail {
|
||||
|
||||
private String errorCode;
|
||||
private List<Map<String, String>> errorData = new ArrayList<>();
|
||||
private String errorMessage;
|
||||
|
||||
public EmrErrorDetail() {}
|
||||
|
||||
public EmrErrorDetail(String errorCode, List<Map<String, String>> errorData, String errorMessage) {
|
||||
this.errorCode = errorCode;
|
||||
this.errorData = errorData;
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public String getErrorCode() { return errorCode; }
|
||||
public void setErrorCode(String errorCode) { this.errorCode = errorCode; }
|
||||
|
||||
public List<Map<String, String>> getErrorData() { return errorData; }
|
||||
public void setErrorData(List<Map<String, String>> errorData) { this.errorData = errorData; }
|
||||
|
||||
public String getErrorMessage() { return errorMessage; }
|
||||
public void setErrorMessage(String errorMessage) { this.errorMessage = errorMessage; }
|
||||
}
|
||||
Reference in new issue
Block a user