Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PLUGIN-1830] Add PostgresErrorDetailsProvider #527

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private ProgramFailureException getProgramFailureException(SQLException e, Error
externalDocumentationLink);
}
return ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN),
errorMessage, errorMessageWithDetails, getErrorTypeFromErrorCode(errorCode), false, e);
errorMessage, errorMessageWithDetails, getErrorTypeFromErrorCode(errorCode, sqlState), false, e);
}

/**
Expand Down Expand Up @@ -118,7 +118,7 @@ protected String getExternalDocumentationLink() {
return null;
}

protected ErrorType getErrorTypeFromErrorCode(int errorCode) {
protected ErrorType getErrorTypeFromErrorCode(int errorCode, String sqlState) {
return ErrorType.UNKNOWN;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected String getExternalDocumentationLink() {
}

@Override
protected ErrorType getErrorTypeFromErrorCode(int errorCode) {
protected ErrorType getErrorTypeFromErrorCode(int errorCode, String sqlState) {
// https://dev.mysql.com/doc/refman/9.0/en/error-message-elements.html#error-code-ranges
if (errorCode >= 1000 && errorCode <= 5999) {
return ErrorType.USER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ Feature: PostgreSQL - Verify data transfer from PostgreSQL source to BigQuery si
And Save and Deploy Pipeline
And Run the Pipeline in Runtime
And Wait till pipeline is in running state
And Open and capture logs
And Verify the pipeline status is "Failed"
And Close the pipeline logs
Then Open Pipeline logs and verify Log entries having below listed Level and Message:
| Level | Message |
| ERROR | errorLogsMessageInvalidBoundingQuery |
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ Feature: PostgreSQL - Verify PostgreSQL plugin data transfer with macro argument
Then Enter runtime argument value "invalidUserName" for key "PostgreSQLUsername"
Then Enter runtime argument value "invalidPassword" for key "PostgreSQLPassword"
Then Run the preview of pipeline with runtime arguments
Then Open and capture pipeline preview logs
Then Verify the preview of pipeline is "Failed"

@POSTGRESQL_SOURCE_TEST @Postgresql_Required @POSTGRESQL_SINK_TEST
Expand Down Expand Up @@ -210,6 +211,7 @@ Feature: PostgreSQL - Verify PostgreSQL plugin data transfer with macro argument
Then Enter runtime argument value "invalidTable" for key "PostgreSQLTableName"
Then Enter runtime argument value "schema" for key "PostgreSQLSchemaName"
Then Run the preview of pipeline with runtime arguments
Then Open and capture pipeline preview logs
Then Verify the preview of pipeline is "Failed"

@POSTGRESQL_SOURCE_TEST @POSTGRESQL_SINK_TEST @BQ_SINK_TEST @Plugin-1526
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@

package io.cdap.plugin.postgres;

import io.cdap.cdap.api.exception.ErrorCategory;
import io.cdap.cdap.api.exception.ErrorType;
import io.cdap.cdap.api.exception.ErrorUtils;

/**
* Postgres constants.
*/
public final class PostgresConstants {

private PostgresConstants() {
throw new AssertionError("Should not instantiate static utility class.");
String errorMessage = "Should not instantiate static utility class.";
throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN),
errorMessage, errorMessage, ErrorType.SYSTEM, false, new AssertionError(errorMessage));
}

public static final String PLUGIN_NAME = "Postgres";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright © 2024 Cask Data, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package io.cdap.plugin.postgres;

import io.cdap.cdap.api.exception.ErrorType;
import io.cdap.plugin.db.DBErrorDetailsProvider;

/**
* A custom ErrorDetailsProvider for Postgres plugins.
*/
public class PostgresErrorDetailsProvider extends DBErrorDetailsProvider {
@Override
protected String getExternalDocumentationLink() {
return "https://www.postgresql.org/docs/current/errcodes-appendix.html";
}

@Override
protected ErrorType getErrorTypeFromErrorCode(int errorCode, String sqlState) {
if (sqlState.startsWith("42")) {
return ErrorType.USER;
} else if (sqlState.startsWith("08")) {
return ErrorType.SYSTEM;
}
return ErrorType.UNKNOWN;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ protected LineageRecorder getLineageRecorder(BatchSinkContext context) {
return new LineageRecorder(context, asset);
}

@Override
protected String getErrorDetailsProviderClassName() {
return PostgresErrorDetailsProvider.class.getName();
}

/**
* PostgreSQL action configuration.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ protected SchemaReader getSchemaReader() {
return new PostgresSchemaReader();
}

@Override
protected String getErrorDetailsProviderClassName() {
return PostgresErrorDetailsProvider.class.getName();
}

@Override
protected Class<? extends DBWritable> getDBRecordType() {
return PostgresDBRecord.class;
Expand Down
Loading