Skip to content

Commit

Permalink
Merge pull request #15796 from cdapio/CDAP-21110
Browse files Browse the repository at this point in the history
[CDAP-21110] Implement FailureDetailsProvider in DataprocRuntimeException to cover provisioning errors
  • Loading branch information
itsankit-google authored Jan 16, 2025
2 parents 62a1c3f + 323dd1f commit 6fb8647
Show file tree
Hide file tree
Showing 29 changed files with 1,027 additions and 461 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package io.cdap.cdap.api.exception;

import java.util.Objects;
import javax.annotation.Nullable;

/**
* Class representing the category of an error.
*
Expand All @@ -25,6 +28,7 @@
*/
public class ErrorCategory {
private final ErrorCategoryEnum errorCategory;
@Nullable
private final String subCategory;

/**
Expand All @@ -33,8 +37,7 @@ public class ErrorCategory {
* @param errorCategory The category of the error.
*/
public ErrorCategory(ErrorCategoryEnum errorCategory) {
this.errorCategory = errorCategory;
this.subCategory = null;
this(errorCategory, null);
}

/**
Expand All @@ -43,7 +46,7 @@ public ErrorCategory(ErrorCategoryEnum errorCategory) {
* @param errorCategory The category of the error.
* @param subCategory The sub-category of the error.
*/
public ErrorCategory(ErrorCategoryEnum errorCategory, String subCategory) {
public ErrorCategory(ErrorCategoryEnum errorCategory, @Nullable String subCategory) {
this.errorCategory = errorCategory;
this.subCategory = subCategory;
}
Expand All @@ -52,8 +55,24 @@ public ErrorCategory(ErrorCategoryEnum errorCategory, String subCategory) {
* Returns the category of the error.
*/
public String getErrorCategory() {
return errorCategory == null ? ErrorCategoryEnum.OTHERS.toString() : subCategory == null ?
errorCategory.toString() : String.format("%s-'%s'", errorCategory, subCategory);
return errorCategory == null ? ErrorCategoryEnum.OTHERS.toString() : subCategory == null
? errorCategory.toString() : String.format("%s-'%s'", errorCategory, subCategory);
}

@Override
public boolean equals(Object o) {
if (!(o instanceof ErrorCategory)) {
return false;
}

ErrorCategory that = (ErrorCategory) o;
return Objects.equals(this.errorCategory, that.errorCategory)
&& Objects.equals(this.subCategory, that.subCategory);
}

@Override
public int hashCode() {
return Objects.hash(this.errorCategory, this.subCategory);
}

/*
Expand All @@ -64,16 +83,25 @@ public String toString() {
return getErrorCategory();
}

/**
* Returns the parent category of the error.
*/
public ErrorCategoryEnum getParentCategory() {
return errorCategory == null ? ErrorCategoryEnum.OTHERS : errorCategory;
}

/**
* Enum representing the different categories of errors.
*/
public enum ErrorCategoryEnum {
PLUGIN("Plugin"),
ACCESS("Access"),
DEPROVISIONING("Deprovisioning"),
NETWORKING("Networking"),
OTHERS("Others"),
PLUGIN("Plugin"),
PROVISIONING("Provisioning"),
ACCESS("Access"),
SCHEDULES_AND_TRIGGERS("Schedules and Triggers"),
OTHERS("Others");
STARTING("Starting");

private final String displayName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

/**
* Interface for providing failure details.
* While implementing the interface, please don't forget to add the class the in
* {io.cdap.cdap.logging.ErrorLogsClassifier#ALLOWLIST_CLASSES} list.
*/
public interface FailureDetailsProvider {

Expand Down Expand Up @@ -69,4 +71,43 @@ default ErrorCategory getErrorCategory() {
default ErrorType getErrorType() {
return ErrorType.UNKNOWN;
}

/**
* Returns whether the error is coming from a dependent service.
*
* @return true if the error is a dependency service error, false otherwise.
*/
default boolean isDependency() {
return false;
}

/**
* Returns the type of error code.
*
* @return the type of error code.
*/
@Nullable
default ErrorCodeType getErrorCodeType() {
return null;
}

/**
* Returns the error code.
*
* @return the error code.
*/
@Nullable
default String getErrorCode() {
return null;
}

/**
* Returns the URL to the documentation.
*
* @return the URL to the documentation.
*/
@Nullable
default String getSupportedDocumentationUrl() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,46 +70,39 @@ public String getErrorReason() {

@Override
public ErrorCategory getErrorCategory() {
if (errorCategory == null) {
return FailureDetailsProvider.super.getErrorCategory();
}
return errorCategory;
}

@Override
public ErrorType getErrorType() {
return errorType == null ? ErrorType.UNKNOWN : errorType;
if (errorType == null) {
return FailureDetailsProvider.super.getErrorType();
}
return errorType;
}

/**
* Returns whether the error is coming from a dependent service.
*
* @return true if the error is a dependency service error, false otherwise.
*/
@Override
public boolean isDependency() {
return dependency;
}

/**
* Returns the type of error code.
*
* @return the type of error code.
*/
@Nullable
@Override
public ErrorCodeType getErrorCodeType() {
return errorCodeType;
}

/**
* Returns the error code.
*
* @return the error code.
*/
@Nullable
@Override
public String getErrorCode() {
return errorCode;
}

/**
* Returns the URL to the documentation.
*
* @return the URL to the documentation.
*/
@Nullable
@Override
public String getSupportedDocumentationUrl() {
return supportedDocumentationUrl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package io.cdap.cdap.internal.provision;

import io.cdap.cdap.api.exception.ErrorCategory;
import io.cdap.cdap.api.exception.ErrorCategory.ErrorCategoryEnum;
import io.cdap.cdap.api.metrics.MetricsCollectionService;
import io.cdap.cdap.common.conf.Constants;
import io.cdap.cdap.common.logging.LoggingContext;
Expand Down Expand Up @@ -62,14 +64,15 @@ public class DefaultProvisionerContext implements ProvisionerContext {
private final String profileName;
private final LoggingContext loggingContext;
private final Executor executor;
private final ErrorCategory errorCategory;

DefaultProvisionerContext(ProgramRunId programRunId, String provisionerName,
Map<String, String> properties,
SparkCompat sparkCompat, @Nullable SSHContext sshContext,
@Nullable VersionInfo appCDAPVersion, LocationFactory locationFactory,
RuntimeMonitorType runtimeMonitorType, MetricsCollectionService metricsCollectionService,
@Nullable String profileName, Executor executor,
LoggingContext loggingContext) {
LoggingContext loggingContext, ErrorCategory errorCategory) {
this.programRun = new ProgramRun(programRunId.getNamespace(), programRunId.getApplication(),
programRunId.getProgram(), programRunId.getRun());
this.programRunInfo = new ProgramRunInfo.Builder()
Expand All @@ -92,6 +95,7 @@ public class DefaultProvisionerContext implements ProvisionerContext {
this.metricsCollectionService = metricsCollectionService;
this.provisionerName = provisionerName;
this.executor = executor;
this.errorCategory = errorCategory;
}

@Override
Expand Down Expand Up @@ -146,6 +150,11 @@ public String getProfileName() {
return profileName;
}

@Override
public ErrorCategory getErrorCategory() {
return errorCategory == null ? new ErrorCategory(ErrorCategoryEnum.OTHERS) : errorCategory;
}

@Override
public ProvisionerMetrics getMetrics(Map<String, String> context) {
Map<String, String> tags = new HashMap<>(context);
Expand Down
Loading

0 comments on commit 6fb8647

Please sign in to comment.