use of org.odpi.openmetadata.connector.sas.event.model.catalog.CatalogEventPayload in project egeria-connector-sas-viya by odpi.
the class RepositoryEventMapper method processEvent.
/**
* Method to pass an event received on topic.
*
* @param event inbound event
*/
@Override
public void processEvent(String event) {
log.info("Processing event: {}", event);
CatalogEventPayload eventPayload;
try {
eventPayload = this.mapper.readValue(event, CatalogEventPayload.class);
} catch (IOException e) {
log.warn("Could not parse event payload", e);
return;
}
log.info("Received integration event for Catalog operation: {}", eventPayload.getOperation());
// Convert event payload into SASCatalogObject that rest of application uses
SASCatalogObject catalogObject = new SASCatalogObject();
String type;
if (eventPayload.getType().equals(CatalogEventPayload.TYPE_INSTANCE)) {
Instance instance = eventPayload.getInstance();
Definition definition = eventPayload.getDefinition();
type = instance.getInstanceType();
catalogObject.guid = instance.getId();
catalogObject.defId = instance.getDefinitionId();
catalogObject.addInstance(instance);
catalogObject.addDefinition(definition);
} else if (eventPayload.getType().equals(CatalogEventPayload.TYPE_DEFINITION)) {
Definition definition = eventPayload.getDefinition();
type = definition.getDefinitionType();
catalogObject.guid = definition.getId();
catalogObject.defId = definition.getId();
catalogObject.addDefinition(definition);
} else {
log.warn("Invalid catalog object type: " + eventPayload.getType());
return;
}
if (eventPayload.getOperation().startsWith(CREATE) && type.equals(CatalogType.ENTITY)) {
processNewEntity(catalogObject);
} else if (eventPayload.getOperation().startsWith(UPDATE) && type.equals(CatalogType.ENTITY)) {
processUpdatedEntity(catalogObject);
} else if (eventPayload.getOperation().startsWith(DELETE) && type.equals(CatalogType.ENTITY)) {
processRemovedEntity(catalogObject);
} else if (eventPayload.getOperation().startsWith(CREATE) && type.equals(CatalogType.RELATIONSHIP)) {
processNewRelationship(catalogObject);
} else if (eventPayload.getOperation().startsWith(UPDATE) && type.equals(CatalogType.RELATIONSHIP)) {
processUpdatedRelationship(catalogObject);
} else if (eventPayload.getOperation().startsWith(DELETE) && type.equals(CatalogType.RELATIONSHIP)) {
processRemovedRelationship(catalogObject);
} else {
log.info("Event processing does not support operation, {}, for type, {}", eventPayload.getOperation(), type);
}
}
use of org.odpi.openmetadata.connector.sas.event.model.catalog.CatalogEventPayload 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);
}
}
Aggregations