Search in sources :

Example 1 with RepositoryConnector

use of org.odpi.openmetadata.connector.sas.repository.connector.RepositoryConnector in project egeria-connector-sas-viya by odpi.

the class RepositoryEventMapper method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() throws ConnectorCheckedException {
    super.start();
    final String methodName = "start";
    auditLog.logMessage(methodName, AuditCode.EVENT_MAPPER_STARTING.getMessageDefinition());
    if (!(repositoryConnector instanceof RepositoryConnector)) {
        raiseConnectorCheckedException(ErrorCode.EVENT_MAPPER_IMPROPERLY_INITIALIZED, methodName, null, repositoryConnector.getServerName());
    }
    this.catalogOMRSRepositoryConnector = (RepositoryConnector) this.repositoryConnector;
    try {
        this.catalogOMRSMetadataCollection = (MetadataCollection) catalogOMRSRepositoryConnector.getMetadataCollection();
    } catch (RepositoryErrorException e) {
        raiseConnectorCheckedException(ErrorCode.REST_CLIENT_FAILURE, methodName, e, catalogOMRSRepositoryConnector.getServerName());
    }
    this.typeDefStore = catalogOMRSMetadataCollection.getTypeDefStore();
    catalogOMRSMetadataCollection.setEventMapper(this);
    this.metadataCollectionId = catalogOMRSRepositoryConnector.getMetadataCollectionId();
    this.originatorServerName = catalogOMRSRepositoryConnector.getServerName();
    this.originatorServerType = catalogOMRSRepositoryConnector.getServerType();
    DeliverCallback deliverCallback = (consumerTag, delivery) -> {
        String message = new String(delivery.getBody(), "UTF-8");
        log.debug("SAS Catalog Event received: '{}':'{}'", delivery.getEnvelope().getRoutingKey(), message);
        try {
            Event<CatalogEventPayload> event = this.mapper.readValue(message, Event.class);
            String eventPayload = event.getPayloadAsString();
            try {
                processEvent(eventPayload);
            } catch (Exception e) {
                log.error("Could not process event payload.", e);
                return;
            }
        } catch (IOException e) {
            log.warn("Could not parse event payload. Reason: {}", e.getLocalizedMessage());
            return;
        }
    };
    try {
        channel.basicConsume(queueName, true, deliverCallback, consumerTag -> {
        });
    } catch (Exception e) {
        log.error("RabbitMQ basic consumer failed to start", e);
    }
}
Also used : CatalogType(org.odpi.openmetadata.connector.sas.event.model.catalog.CatalogType) ErrorCode(org.odpi.openmetadata.connector.sas.auditlog.ErrorCode) OMRSRepositoryConnector(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.repositoryconnector.OMRSRepositoryConnector) DeliverCallback(com.rabbitmq.client.DeliverCallback) RepositoryConnector(org.odpi.openmetadata.connector.sas.repository.connector.RepositoryConnector) CatalogEventPayload(org.odpi.openmetadata.connector.sas.event.model.catalog.CatalogEventPayload) LoggerFactory(org.slf4j.LoggerFactory) SASCatalogGuid(org.odpi.openmetadata.connector.sas.repository.connector.model.SASCatalogGuid) Relationship(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship) Event(org.odpi.openmetadata.connector.sas.event.model.Event) AttributeTypeDef(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.AttributeTypeDef) Connection(com.rabbitmq.client.Connection) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) MapperFeature(com.fasterxml.jackson.databind.MapperFeature) SASCatalogObject(org.odpi.openmetadata.connector.sas.repository.connector.mapping.SASCatalogObject) EntityMappingSASCatalog2OMRS(org.odpi.openmetadata.connector.sas.repository.connector.mapping.EntityMappingSASCatalog2OMRS) Instance(org.odpi.openmetadata.connector.sas.event.model.catalog.instance.Instance) EntityDetail(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.EntityDetail) Map(java.util.Map) Definition(org.odpi.openmetadata.connector.sas.event.model.catalog.definition.Definition) TypeDef(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDef) RelationshipMapping(org.odpi.openmetadata.connector.sas.repository.connector.mapping.RelationshipMapping) AuditCode(org.odpi.openmetadata.connector.sas.auditlog.AuditCode) ConnectionProperties(org.odpi.openmetadata.frameworks.connectors.properties.ConnectionProperties) Logger(org.slf4j.Logger) ConnectionFactory(com.rabbitmq.client.ConnectionFactory) OMRSRepositoryEventMapperBase(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.repositoryeventmapper.OMRSRepositoryEventMapperBase) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MetadataCollection(org.odpi.openmetadata.connector.sas.repository.connector.MetadataCollection) IOException(java.io.IOException) ConnectorCheckedException(org.odpi.openmetadata.frameworks.connectors.ffdc.ConnectorCheckedException) TypeDefStore(org.odpi.openmetadata.connector.sas.repository.connector.stores.TypeDefStore) List(java.util.List) RepositoryErrorException(org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException) Channel(com.rabbitmq.client.Channel) EndpointProperties(org.odpi.openmetadata.frameworks.connectors.properties.EndpointProperties) OpenMetadataTopicListener(org.odpi.openmetadata.repositoryservices.connectors.openmetadatatopic.OpenMetadataTopicListener) RepositoryErrorException(org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException) OMRSRepositoryConnector(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.repositoryconnector.OMRSRepositoryConnector) RepositoryConnector(org.odpi.openmetadata.connector.sas.repository.connector.RepositoryConnector) Event(org.odpi.openmetadata.connector.sas.event.model.Event) DeliverCallback(com.rabbitmq.client.DeliverCallback) IOException(java.io.IOException) IOException(java.io.IOException) ConnectorCheckedException(org.odpi.openmetadata.frameworks.connectors.ffdc.ConnectorCheckedException) RepositoryErrorException(org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException)

Aggregations

MapperFeature (com.fasterxml.jackson.databind.MapperFeature)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Channel (com.rabbitmq.client.Channel)1 Connection (com.rabbitmq.client.Connection)1 ConnectionFactory (com.rabbitmq.client.ConnectionFactory)1 DeliverCallback (com.rabbitmq.client.DeliverCallback)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 StringUtils (org.apache.commons.lang3.StringUtils)1 AuditCode (org.odpi.openmetadata.connector.sas.auditlog.AuditCode)1 ErrorCode (org.odpi.openmetadata.connector.sas.auditlog.ErrorCode)1 Event (org.odpi.openmetadata.connector.sas.event.model.Event)1 CatalogEventPayload (org.odpi.openmetadata.connector.sas.event.model.catalog.CatalogEventPayload)1 CatalogType (org.odpi.openmetadata.connector.sas.event.model.catalog.CatalogType)1 Definition (org.odpi.openmetadata.connector.sas.event.model.catalog.definition.Definition)1 Instance (org.odpi.openmetadata.connector.sas.event.model.catalog.instance.Instance)1 MetadataCollection (org.odpi.openmetadata.connector.sas.repository.connector.MetadataCollection)1 RepositoryConnector (org.odpi.openmetadata.connector.sas.repository.connector.RepositoryConnector)1