Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

[egeria-connector-jdbc] initial commit #179

Merged
merged 5 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
19 changes: 19 additions & 0 deletions egeria-connector-jdbc/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Contributors to the ODPi Egeria project.
*/

// Artifact names are taken from the directory by default, set in settings.gradle to override
// The 'name' for the maven artifact, and description are set here
ext.name = 'JDBC Connector'
description = 'JDBC Connector for Egeria'
lcpopa marked this conversation as resolved.
Show resolved Hide resolved

dependencies {
lcpopa marked this conversation as resolved.
Show resolved Hide resolved
implementation 'org.slf4j:slf4j-api'
implementation 'org.odpi.egeria:data-manager-client'
lcpopa marked this conversation as resolved.
Show resolved Hide resolved
implementation 'org.odpi.egeria:data-manager-api'
implementation 'org.odpi.egeria:database-integrator-api'
implementation 'org.odpi.egeria:open-connector-framework'
implementation project(':egeria-resource-connector-jdbc')
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* SPDX-License-Identifier: Apache-2.0 */
/* Copyright Contributors to the ODPi Egeria project. */
package org.odpi.openmetadata.adapters.connectors.integration.jdbc;

import org.odpi.openmetadata.adapters.connectors.integration.jdbc.transfer.JdbcMetadataTransfer;
import org.odpi.openmetadata.adapters.connectors.resource.jdbc.JdbcMetadata;
import org.odpi.openmetadata.frameworks.connectors.Connector;
import org.odpi.openmetadata.frameworks.connectors.ffdc.ConnectorCheckedException;
import org.odpi.openmetadata.integrationservices.database.connector.DatabaseIntegratorConnector;

import java.util.List;

import static org.odpi.openmetadata.adapters.connectors.integration.jdbc.ffdc.JdbcConnectorAuditCode.EXITING_ON_TRANSFER_FAIL;
import static org.odpi.openmetadata.adapters.connectors.integration.jdbc.ffdc.JdbcConnectorAuditCode.EXITING_ON_COMPLETE;
import static org.odpi.openmetadata.adapters.connectors.integration.jdbc.ffdc.JdbcConnectorAuditCode.EXITING_ON_CONNECTION_FAIL;
import static org.odpi.openmetadata.adapters.connectors.integration.jdbc.ffdc.JdbcConnectorAuditCode.EXITING_ON_INTEGRATION_CONTEXT_FAIL;

public class JdbcDatabaseConnector extends DatabaseIntegratorConnector{

private JdbcMetadata jdbcMetadataConnector;

@Override
public void initializeEmbeddedConnectors(List<Connector> embeddedConnectors) {
super.initializeEmbeddedConnectors(embeddedConnectors);
jdbcMetadataConnector = (JdbcMetadata) embeddedConnectors.get(0);
}

@Override
public void refresh() {
String methodName = "refresh";
String exitAction = "Exiting " + methodName;

boolean successfulConnection = jdbcMetadataConnector.open();
if(!successfulConnection){
auditLog.logMessage(exitAction, EXITING_ON_CONNECTION_FAIL.getMessageDefinition(methodName));
return;
}
JdbcMetadataTransfer jdbcMetadataTransfer = createJdbcMetadataTransfer();
if(jdbcMetadataTransfer == null){
auditLog.logMessage(exitAction, EXITING_ON_INTEGRATION_CONTEXT_FAIL.getMessageDefinition(methodName));
return;
}

boolean successfulTransfer = jdbcMetadataTransfer.execute();

if(successfulTransfer) {
auditLog.logMessage(exitAction, EXITING_ON_COMPLETE.getMessageDefinition(methodName));
}else{
auditLog.logMessage(exitAction, EXITING_ON_TRANSFER_FAIL.getMessageDefinition(methodName));
}
jdbcMetadataConnector.close();
}

private JdbcMetadataTransfer createJdbcMetadataTransfer(){
String methodName = "createJdbcMetadataTransfer";
try{
return new JdbcMetadataTransfer(this.jdbcMetadataConnector, this.getContext(), auditLog);
}catch (ConnectorCheckedException e) {
auditLog.logException("Extracting integration context",
EXITING_ON_INTEGRATION_CONTEXT_FAIL.getMessageDefinition(methodName), e);
}
return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* SPDX-License-Identifier: Apache-2.0 */
/* Copyright Contributors to the ODPi Egeria project. */
package org.odpi.openmetadata.adapters.connectors.integration.jdbc;

import org.odpi.openmetadata.frameworks.connectors.ConnectorProviderBase;
import org.odpi.openmetadata.frameworks.connectors.properties.beans.ConnectorType;

public class JdbcDatabaseConnectorProvider extends ConnectorProviderBase {

static final String connectorTypeGUID = "49cd6772-1efd-40bb-a1d9-cc9460962ff6";
static final String connectorTypeName = "JDBC Database Connector";
static final String connectorTypeDescription = "Connector supports JDBC Database instance";

/**
* Constructor used to initialize the ConnectorProviderBase with the Java class name of the specific
* store implementation.
*/
public JdbcDatabaseConnectorProvider(){
super.setConnectorClassName(JdbcDatabaseConnector.class.getName());

ConnectorType connectorType = new ConnectorType();
connectorType.setType(ConnectorType.getConnectorTypeType());
connectorType.setGUID(connectorTypeGUID);
connectorType.setQualifiedName(connectorTypeName);
connectorType.setDisplayName(connectorTypeName);
connectorType.setDescription(connectorTypeDescription);
connectorType.setConnectorProviderClassName(this.getClass().getName());

super.connectorTypeBean = connectorType;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/* SPDX-License-Identifier: Apache-2.0 */
/* Copyright Contributors to the ODPi Egeria project. */
package org.odpi.openmetadata.adapters.connectors.integration.jdbc.ffdc;
import org.odpi.openmetadata.frameworks.auditlog.messagesets.AuditLogMessageDefinition;
import org.odpi.openmetadata.frameworks.auditlog.messagesets.AuditLogMessageSet;
import org.odpi.openmetadata.repositoryservices.auditlog.OMRSAuditLogRecordSeverity;


/**
* The JdbcConnectorAuditCode is used to define the message content for the Audit Log.
*
* The 5 fields in the enum are:
* <ul>
* <li>Log Message Id - to uniquely identify the message</li>
* <li>Severity - is this an event, decision, action, error or exception</li>
* <li>Log Message Text - includes placeholder to allow additional values to be captured</li>
* <li>SystemAction - describes the result of the situation</li>
* <li>UserAction - describes how a user should correct the situation</li>
* </ul>
*/
public enum JdbcConnectorAuditCode implements AuditLogMessageSet {

lcpopa marked this conversation as resolved.
Show resolved Hide resolved
EXITING_ON_CONNECTION_FAIL("JDBC-CONNECTOR-0001",
OMRSAuditLogRecordSeverity.INFO,
"Exiting from method {0} as a result of a failed connection",
"Stopping execution",
"Investigate database server availability. If the database server is available then contact the Egeria team for support"),
EXITING_ON_COMPLETE("JDBC-CONNECTOR-0002",
OMRSAuditLogRecordSeverity.INFO,
"Execution of method {0} is complete",
"Stopping execution",
"No user actions necessary"),
EXITING_ON_TRANSFER_FAIL("JDBC-CONNECTOR-0003",
OMRSAuditLogRecordSeverity.INFO,
"Execution of method {0} is complete, however it finished abnormally",
"Stopping execution",
"Consult logs for further details"),
EXITING_ON_INTEGRATION_CONTEXT_FAIL("JDBC-CONNECTOR-0004",
OMRSAuditLogRecordSeverity.INFO,
"Retrieving integration context failed in method {0}",
"Stopping execution",
"Consult logs for further details"),
ERROR_READING_JDBC("JDBC-CONNECTOR-0005",
OMRSAuditLogRecordSeverity.EXCEPTION,
"An sql exception was received by method {0}. Exception message is {1}",
"Reading JDBC",
"Investigate database server availability. If the database server is available then contact the Egeria team for support"),
ERROR_UPSERTING_INTO_OMAS("JDBC-CONNECTOR-0006",
OMRSAuditLogRecordSeverity.EXCEPTION,
"An exception was received by method {0}. Exception message is {1}",
"Upserting an entity into omas failed.",
"Investigate OMAS availability. If it is available then contact the Egeria team for support"),
EXITING_ON_METADATA_TRANSFER("JDBC-CONNECTOR-0007",
OMRSAuditLogRecordSeverity.INFO,
"Transferring metadata failed in method {0}",
"Stopping execution",
"Consult logs for further details"),
ERROR_READING_OMAS("JDBC-CONNECTOR-0008",
OMRSAuditLogRecordSeverity.EXCEPTION,
"Error reading data from omas in method {0}",
"Reading omas information",
"Consult logs for further details"),
UNKNOWN_ERROR_WHILE_METADATA_TRANSFER("JDBC-CONNECTOR-0009",
OMRSAuditLogRecordSeverity.EXCEPTION,
"Unknown error transferring metadata in method {0}.",
"Reading metadata information",
"Consult logs for further details"),
ERROR_WHEN_REMOVING_ELEMENT_IN_OMAS("JDBC-CONNECTOR-0010",
OMRSAuditLogRecordSeverity.INFO,
"Unknown error when removing element in omas with guid {0} and qualified name {1}.",
"Removing element in omas",
"Consult logs for further details");


private final AuditLogMessageDefinition messageDefinition;
lcpopa marked this conversation as resolved.
Show resolved Hide resolved


/**
* The constructor for JdbcConnectorAuditCode expects to be passed one of the enumeration rows defined above.
* Example:
*
* JdbcConnectorAuditCode auditCode = JdbcConnectorAuditCode.EXCEPTION_COMMITTING_OFFSETS;
*
* This will expand out to the 4 parameters shown below.
*
* @param messageId unique Id for the message
* @param severity severity of the message
* @param message text for the message
* @param systemAction description of the action taken by the system when the condition happened
* @param userAction instructions for resolving the situation, if any
*/
JdbcConnectorAuditCode(String messageId, OMRSAuditLogRecordSeverity severity, String message, String systemAction,
String userAction){
messageDefinition = new AuditLogMessageDefinition(messageId, severity, message, systemAction, userAction);
}


/**
* Retrieve a message definition object for logging. This method is used when there are no message inserts.
*
* @return message definition object.
*/
@Override
public AuditLogMessageDefinition getMessageDefinition() {
return messageDefinition;
}


/**
* Retrieve a message definition object for logging. This method is used when there are values to be inserted into the message.
*
* @param params array of parameters (all strings). They are inserted into the message according to the numbering in the message text.
*
* @return message definition object.
*/
@Override
public AuditLogMessageDefinition getMessageDefinition(String... params) {
messageDefinition.setMessageParameters(params);
return messageDefinition;
}
}
Loading