use of org.odpi.openmetadata.frameworks.connectors.ffdc.ConnectorCheckedException in project egeria-connector-integration-topic-strimzi by odpi.
the class StrimziMonitorIntegrationConnector method refresh.
/**
* Requests that the connector does a comparison of the metadata in the third party technology and open metadata repositories.
* Refresh is called when the integration connector first starts and then at intervals defined in the connector's configuration
* as well as any external REST API calls to explicitly refresh the connector.
* <p>
* This method performs two sweeps. It first retrieves the files in the directory and validates that are in the
* catalog - adding or updating them if necessary. The second sweep is to ensure that all of the assets catalogued
* in this directory actually exist on the file system.
*
* @throws ConnectorCheckedException there is a problem with the connector. It is not able to refresh the metadata.
*/
@Override
public void refresh() throws ConnectorCheckedException {
final String methodName = "refresh";
if (auditLog != null) {
auditLog.logMessage(methodName, StrimziIntegrationConnectorAuditCode.REFRESH_CALLED.getMessageDefinition(connectorName));
}
// clear out the maps
updateTopicNameToGuidMap = new HashMap<>();
deleteTopicNameToGuidMap = new HashMap<>();
// clear the set
addTopicNamesSet = new HashSet<>();
try {
/*
* Retrieve the list of active topics from Strimzi.
*/
Map<String, TopicProperties> strimziTopicElements = getStrimziTopicElements();
/*
* Retrieve the topics that are catalogued for this event broker.
* Remove the topics from the catalog that are no longer present in the event broker.
* Remove the names of the topics that are cataloged from the active topic names.
* At the end of this loop, the active topic names will just contain the names of the
* topics that are not catalogued.
*/
int startFrom = 0;
cataloguedTopics = myContext.getMyTopics(startFrom, 0);
// populate the delete map the update map and the add set
determineMutations(cataloguedTopics, strimziTopicElements);
Set<String> updateTopicNames = updateTopicNameToGuidMap.keySet();
/*
* Update topics to the catalog.
*/
for (String topicName : updateTopicNames) {
TopicProperties topicProperties = strimziTopicElements.get(topicName);
// Assume not a merge update.
myContext.updateTopic(updateTopicNameToGuidMap.get(topicName), false, topicProperties);
}
Set<String> deleteTopicNames = deleteTopicNameToGuidMap.keySet();
/*
* Delete topics to the catalog.
*/
for (String topicName : deleteTopicNames) {
myContext.removeTopic(deleteTopicNameToGuidMap.get(topicName), topicName);
}
/*
* Add topics
*/
for (String topicName : addTopicNamesSet) {
String topicGUID;
if (templateGUID == null) {
TopicProperties topicProperties = strimziTopicElements.get(topicName);
topicGUID = myContext.createTopic(topicProperties);
if (topicGUID != null) {
if (auditLog != null) {
auditLog.logMessage(methodName, StrimziIntegrationConnectorAuditCode.TOPIC_CREATED.getMessageDefinition(connectorName, topicName, topicGUID));
}
}
} else {
TemplateProperties templateProperties = new TemplateProperties();
templateProperties.setQualifiedName(topicName);
topicGUID = myContext.createTopicFromTemplate(templateGUID, templateProperties);
if (topicGUID != null) {
if (auditLog != null) {
auditLog.logMessage(methodName, StrimziIntegrationConnectorAuditCode.TOPIC_CREATED_FROM_TEMPLATE.getMessageDefinition(connectorName, topicName, topicGUID, templateQualifiedName, templateGUID));
}
}
}
}
} catch (Exception error) {
if (auditLog != null) {
auditLog.logException(methodName, StrimziIntegrationConnectorAuditCode.UNABLE_TO_RETRIEVE_TOPICS.getMessageDefinition(connectorName, "localhost:9092", error.getClass().getName(), error.getMessage()), error);
}
throw new ConnectorCheckedException(StrimziIntegrationConnectorErrorCode.UNEXPECTED_EXCEPTION.getMessageDefinition(connectorName, error.getClass().getName(), error.getMessage()), this.getClass().getName(), methodName, error);
}
}
use of org.odpi.openmetadata.frameworks.connectors.ffdc.ConnectorCheckedException in project egeria-connector-integration-topic-strimzi by odpi.
the class StrimziMonitorIntegrationConnector method getStrimziTopicElements.
/**
* Issue rest call to Strimzi, the url is obtained from the config.
* Return map with the key of topic name with the topic properties as the value
* The topicProperties should contain the qualifiedName as the topic name , the topic description and
* the additional properties.
* Probably should pass the additional properties through as configuration parameters.
*
* @return map with the key of topic name with the topic properties as the value.
*/
private Map<String, TopicProperties> getStrimziTopicElements() throws ConnectorCheckedException {
String methodName = "getStrimziTopicElements";
// set authentication
HttpHeaders authHeaders = new HttpHeaders();
authHeaders.setContentType(MediaType.APPLICATION_JSON);
authHeaders.add("Authorization", "Bearer " + token);
HttpEntity<?> request = new HttpEntity<>(authHeaders);
RestTemplate restTemplate;
try {
restTemplate = restTemplate();
} catch (Exception error) {
throw new ConnectorCheckedException(StrimziIntegrationConnectorErrorCode.ERROR_ON_STRIMZI_REST_CALL.getMessageDefinition(connectorName, targetURL, error.getClass().getName(), error.getMessage()), this.getClass().getName(), methodName, error);
}
ResponseEntity<String> responseEntity = restTemplate.exchange(targetURL, HttpMethod.GET, request, String.class);
String jsonString = responseEntity.getBody();
return convertStringToTopicMap(jsonString);
}
use of org.odpi.openmetadata.frameworks.connectors.ffdc.ConnectorCheckedException in project egeria-database-connectors by odpi.
the class PostgresDatabaseConnector method updateTableColumns.
/**
* @param postgresTable the Postgres table which contains the columns to be updates
* @param egeriaTable the column data from Egeria
* @throws AlreadyHandledException this exception has already been logged
*/
private void updateTableColumns(PostgresTable postgresTable, DatabaseTableElement egeriaTable) throws AlreadyHandledException {
final String methodName = "updateTableColumns";
PostgresSourceDatabase source = new PostgresSourceDatabase(this.connectionProperties);
String tableGuid = egeriaTable.getElementHeader().getGUID();
try {
List<PostgresColumn> postgresColumns = source.getColumns(postgresTable.getTable_name());
List<DatabaseColumnElement> egeriaColumns = getContext().getColumnsForDatabaseTable(tableGuid, startFrom, pageSize);
List<String> primarykeys = source.getPrimaryKeyColumnNamesForTable(postgresTable.getTable_name());
if (egeriaColumns != null && postgresColumns.size() > 0) {
egeriaColumns = deleteTableColumns(postgresColumns, egeriaColumns);
}
for (PostgresColumn postgresColumn : postgresColumns) {
boolean found = false;
/*
we have no columns in Egeria
so all columns are new
*/
if (egeriaColumns == null) {
if (postgresColumns.size() > 0) {
addColumn(postgresColumn, tableGuid);
}
} else {
/*
check if the database table is known to Egeria
and needs to be updated
*/
for (DatabaseColumnElement egeriaColumn : egeriaColumns) {
if (egeriaColumn.getDatabaseColumnProperties().getQualifiedName().equals(postgresColumn.getQualifiedName())) {
/*
we have found an exact instance to update
*/
found = true;
// updateColumn(postgresColumn, egeriaColumn);
break;
}
if (primarykeys.contains(egeriaColumn.getDatabaseColumnProperties().getDisplayName())) {
DatabasePrimaryKeyProperties props = new DatabasePrimaryKeyProperties();
getContext().setPrimaryKeyOnColumn(egeriaColumn.getElementHeader().getGUID(), props);
} else {
// was this a primary key previously.
if (egeriaColumn.getPrimaryKeyProperties() != null) {
getContext().removePrimaryKeyFromColumn(egeriaColumn.getElementHeader().getGUID());
}
}
}
/*
this is a new database so add it
*/
if (!found) {
addColumn(postgresColumn, tableGuid);
}
}
}
} catch (SQLException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.ERROR_READING_POSTGRES.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.ERROR_READING_FROM_POSTGRES.getMessageDefinition(methodName));
} catch (InvalidParameterException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.INVALID_PARAMETER_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.INVALID_PARAMETER_EXCEPTION.getMessageDefinition(methodName));
} catch (UserNotAuthorizedException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.USER_NOT_AUTHORIZED_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.USER_NOT_AUTHORIZED_EXCEPTION.getMessageDefinition(methodName));
} catch (PropertyServerException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.PROPERTY_SERVER_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.PROPERTY_SERVER_EXCEPTION.getMessageDefinition(methodName));
} catch (ConnectorCheckedException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.CONNECTOR_CHECKED_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.CONNECTOR_CHECKED_EXCEPTION.getMessageDefinition(methodName));
} catch (Exception error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.UNEXPECTED_ERROR.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.UNEXPECTED_ERROR.getMessageDefinition(methodName));
}
}
use of org.odpi.openmetadata.frameworks.connectors.ffdc.ConnectorCheckedException in project egeria-database-connectors by odpi.
the class PostgresDatabaseConnector method deleteTableColumns.
/**
* Checks if any columns need to be removed from Egeria
*
* @param postgresColumns a list of the bean properties of a Postgres cols
* @param egeriaColumns a list of the cols already known to Egeria
* @throws AlreadyHandledException this exception has already been logged
*/
private List<DatabaseColumnElement> deleteTableColumns(List<PostgresColumn> postgresColumns, List<DatabaseColumnElement> egeriaColumns) throws AlreadyHandledException {
String methodName = "deleteTableColumns";
try {
if (egeriaColumns != null) {
/*
for each column already known to Egeria
*/
for (Iterator<DatabaseColumnElement> itr = egeriaColumns.iterator(); itr.hasNext(); ) {
boolean found = false;
DatabaseColumnElement egeriaColumn = itr.next();
String knownName = egeriaColumn.getDatabaseColumnProperties().getQualifiedName();
/*
check that the database is still present in Postgres
*/
for (PostgresColumn postgresColumn : postgresColumns) {
String sourceName = postgresColumn.getQualifiedName();
if (sourceName.equals(knownName)) {
/*
if found then check the next column
*/
found = true;
break;
}
}
/*
not found in Postgres , so delete the table from Egeria
*/
if (!found) {
getContext().removeDatabaseView(egeriaColumn.getElementHeader().getGUID(), knownName);
itr.remove();
}
}
}
} catch (InvalidParameterException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.INVALID_PARAMETER_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.INVALID_PARAMETER_EXCEPTION.getMessageDefinition(methodName));
} catch (PropertyServerException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.PROPERTY_SERVER_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.PROPERTY_SERVER_EXCEPTION.getMessageDefinition(methodName));
} catch (UserNotAuthorizedException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.USER_NOT_AUTHORIZED_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.USER_NOT_AUTHORIZED_EXCEPTION.getMessageDefinition(methodName));
} catch (ConnectorCheckedException error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.CONNECTOR_CHECKED_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.CONNECTOR_CHECKED_EXCEPTION.getMessageDefinition(methodName));
} catch (Exception error) {
ExceptionHandler.handleException(auditLog, this.getClass().getName(), methodName, error, PostgresConnectorAuditCode.UNEXPECTED_ERROR.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), PostgresConnectorErrorCode.UNEXPECTED_ERROR.getMessageDefinition(methodName));
}
return egeriaColumns;
}
use of org.odpi.openmetadata.frameworks.connectors.ffdc.ConnectorCheckedException in project egeria-database-connectors by odpi.
the class PostgresDatabaseConnector method refresh.
@Override
public void refresh() throws ConnectorCheckedException {
String methodName = "PostgresConnector.refresh";
PostgresSourceDatabase source = new PostgresSourceDatabase(connectionProperties);
try {
/*
get a list of databases currently hosted in Postgres
and a list of databases already known by Egeria
*/
List<PostgresDatabase> postgresDatabases = source.getDabases();
List<DatabaseElement> egeriaDatabases = getContext().getMyDatabases(startFrom, pageSize);
/*
first we remove any Egeria databases that are no longer present in Postgres
*/
egeriaDatabases = deleteDatabases(postgresDatabases, egeriaDatabases);
for (PostgresDatabase postgresDatabase : postgresDatabases) {
boolean found = false;
if (egeriaDatabases == null) {
if (postgresDatabases.size() > 0) {
/*
we have no databases in Egeria
so all databases are new
*/
addDatabase(postgresDatabase);
}
} else {
/*
check if the database is known to Egeria
and needs to be updated
*/
for (DatabaseElement egeriaDatabase : egeriaDatabases) {
String egeriaQN = egeriaDatabase.getDatabaseProperties().getQualifiedName();
String postgresQN = postgresDatabase.getQualifiedName();
if (egeriaQN.equals(postgresQN)) {
/*
we have found an exact instance to update
*/
found = true;
updateDatabase(postgresDatabase, egeriaDatabase);
break;
}
}
/*
this is a new database so add it
*/
if (!found) {
addDatabase(postgresDatabase);
}
}
}
} catch (SQLException error) {
if (this.auditLog != null) {
auditLog.logException(methodName, PostgresConnectorAuditCode.ERROR_READING_POSTGRES.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), error);
}
throw new ConnectorCheckedException(PostgresConnectorErrorCode.ERROR_READING_FROM_POSTGRES.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), this.getClass().getName(), methodName, error);
} catch (InvalidParameterException error) {
if (this.auditLog != null) {
auditLog.logException(methodName, PostgresConnectorAuditCode.INVALID_PARAMETER_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), error);
}
throw new ConnectorCheckedException(PostgresConnectorErrorCode.INVALID_PARAMETER_EXCEPTION.getMessageDefinition(methodName), this.getClass().getName(), methodName, error);
} catch (UserNotAuthorizedException error) {
if (this.auditLog != null) {
auditLog.logException(methodName, PostgresConnectorAuditCode.USER_NOT_AUTHORIZED_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), error);
}
throw new ConnectorCheckedException(PostgresConnectorErrorCode.USER_NOT_AUTHORIZED_EXCEPTION.getMessageDefinition(methodName), this.getClass().getName(), methodName, error);
} catch (ConnectorCheckedException error) {
if (this.auditLog != null) {
auditLog.logException(methodName, PostgresConnectorAuditCode.CONNECTOR_CHECKED_EXCEPTION.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), error);
}
throw error;
} catch (AlreadyHandledException error) {
throw new ConnectorCheckedException(PostgresConnectorErrorCode.ALREADY_HANDLED_EXCEPTION.getMessageDefinition(error.getClass().getName(), error.getMessage()), this.getClass().getName(), methodName, error);
} catch (Exception error) {
if (this.auditLog != null) {
auditLog.logException(methodName, PostgresConnectorAuditCode.UNEXPECTED_ERROR.getMessageDefinition(methodName, error.getClass().getName(), error.getMessage()), error);
}
throw new ConnectorCheckedException(PostgresConnectorErrorCode.ERROR_READING_FROM_POSTGRES.getMessageDefinition(methodName), this.getClass().getName(), methodName, error);
}
}
Aggregations