Search in sources :

Example 1 with EndpointProperties

use of org.odpi.openmetadata.frameworks.connectors.properties.EndpointProperties in project egeria-connector-sas-viya by odpi.

the class RepositoryConnector method connectToCatalog.

private void connectToCatalog(String methodName) throws Exception {
    if (this.sasCatalogClient == null) {
        EndpointProperties endpointProperties = connectionProperties.getEndpoint();
        if (endpointProperties == null) {
            raiseConnectorCheckedException(ErrorCode.REST_CLIENT_FAILURE, methodName, null, "null");
        } else {
            this.url = endpointProperties.getProtocol() + "://" + endpointProperties.getAddress();
            this.sasCatalogClient = new SASCatalogRestClient(this.url, this.securedProperties.get("userId"), this.securedProperties.get("password"));
        }
    }
    metadataCollection = new MetadataCollection(this, serverName, repositoryHelper, repositoryValidator, metadataCollectionId);
}
Also used : SASCatalogRestClient(org.odpi.openmetadata.connector.sas.client.SASCatalogRestClient) OMRSMetadataCollection(org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.OMRSMetadataCollection) EndpointProperties(org.odpi.openmetadata.frameworks.connectors.properties.EndpointProperties)

Example 2 with EndpointProperties

use of org.odpi.openmetadata.frameworks.connectors.properties.EndpointProperties in project egeria-connector-sas-viya by odpi.

the class RepositoryEventMapper method initialize.

@Override
public void initialize(String repositoryEventMapperName, OMRSRepositoryConnector repositoryConnector) {
    super.initialize(repositoryEventMapperName, repositoryConnector);
    final String methodName = "initialize";
    auditLog.logMessage(methodName, AuditCode.EVENT_MAPPER_INITIALIZING.getMessageDefinition());
    this.mapper = new ObjectMapper();
    this.mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
    try {
        log.debug("Set up connection factory for RabbitMQ");
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.useSslProtocol();
        ConnectionProperties connProperties = this.connectionProperties;
        if (connProperties != null) {
            EndpointProperties connEndpoint = connProperties.getEndpoint();
            Map<String, Object> cfgProperties = connProperties.getConfigurationProperties();
            if (connEndpoint != null) {
                String host = "";
                String portAsString = "";
                String address = connEndpoint.getAddress();
                if (StringUtils.isNotEmpty(address)) {
                    if (address.contains(":")) {
                        String[] addressParts = address.split(":", 2);
                        host = addressParts[0];
                        portAsString = addressParts[1];
                    } else {
                        host = address;
                    }
                }
                if (StringUtils.isEmpty(host)) {
                    host = "sas-rabbitmq-server";
                }
                // RabbitMQ host was configured, so set it in ConnectionFactory
                log.debug("Setting RabbitMQ host to: " + host);
                connectionFactory.setHost(host);
                if (StringUtils.isEmpty(portAsString)) {
                    portAsString = "5672";
                }
                try {
                    int port = Integer.valueOf(portAsString);
                    // RabbitMQ port was configured, so set it in ConnectionFactory
                    log.debug("Setting RabbitMQ port to: " + portAsString);
                    connectionFactory.setPort(port);
                } catch (NumberFormatException nfe) {
                    log.error("Could not convert '{}' to a port number.  Default port will be used.", portAsString);
                }
                String username = System.getenv("RABBITMQ_USER");
                String password = System.getenv("RABBITMQ_PASS");
                if (cfgProperties != null) {
                    username = (String) cfgProperties.getOrDefault("username", username);
                    password = (String) cfgProperties.getOrDefault("password", password);
                }
                if (StringUtils.isNotEmpty(username)) {
                    // RabbitMQ username was configured, so set it in ConnectionFactory
                    log.debug("Setting RabbitMQ username");
                    connectionFactory.setUsername(username);
                }
                if (StringUtils.isNotEmpty(password)) {
                    // RabbitMQ password was configured, so set it in ConnectionFactory
                    log.debug("Setting RabbitMQ password");
                    connectionFactory.setPassword(password);
                }
            }
        }
        log.debug("Create RabbitMQ connection");
        Connection connection = connectionFactory.newConnection();
        log.debug("Create RabbitMQ channel");
        channel = connection.createChannel();
        log.debug("Declare RabbitMQ exchange: " + EXCHANGE_NAME);
        channel.exchangeDeclare(EXCHANGE_NAME, "topic", true);
        log.debug("Declare RabbitMQ queue");
        queueName = channel.queueDeclare().getQueue();
        log.debug("Bind RabbitMQ queue: {}", queueName);
        channel.queueBind(queueName, EXCHANGE_NAME, "application.integration.catalog.change.*.success");
        log.debug("Finished establishment of RabbitMQ connection");
    } catch (Exception e) {
        log.error("Failed to initialize RabbitMQ connection " + e.getMessage());
    }
    auditLog.logMessage(methodName, AuditCode.EVENT_MAPPER_INITIALIZED.getMessageDefinition(repositoryConnector.getServerName()));
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) ConnectionProperties(org.odpi.openmetadata.frameworks.connectors.properties.ConnectionProperties) Connection(com.rabbitmq.client.Connection) SASCatalogObject(org.odpi.openmetadata.connector.sas.repository.connector.mapping.SASCatalogObject) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) EndpointProperties(org.odpi.openmetadata.frameworks.connectors.properties.EndpointProperties) IOException(java.io.IOException) ConnectorCheckedException(org.odpi.openmetadata.frameworks.connectors.ffdc.ConnectorCheckedException) RepositoryErrorException(org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException)

Example 3 with EndpointProperties

use of org.odpi.openmetadata.frameworks.connectors.properties.EndpointProperties in project egeria-connector-integration-topic-strimzi by odpi.

the class StrimziMonitorIntegrationConnector method start.

/**
 * Indicates that the connector is completely configured and can begin processing.
 * This call can be used to register with non-blocking services.
 *
 * @throws ConnectorCheckedException there is a problem within the connector.
 */
@Override
public void start() throws ConnectorCheckedException {
    super.start();
    final String methodName = "start";
    myContext = super.getContext();
    if (connectionProperties != null) {
        EndpointProperties endpoint = connectionProperties.getEndpoint();
        if (endpoint != null) {
            targetURL = endpoint.getAddress();
            try {
                new URI(targetURL);
            } catch (URISyntaxException e) {
                throwException(StrimziIntegrationConnectorErrorCode.INVALID_URL_IN_CONFIGURATION, "Endpoint address");
            }
        }
        Map<String, Object> configurationProperties = connectionProperties.getConfigurationProperties();
        templateQualifiedName = (String) configurationProperties.get(StrimziMonitorIntegrationProvider.TEMPLATE_QUALIFIED_NAME_CONFIGURATION_PROPERTY);
        // TODO check that this exists - manditory ???
        token = (String) configurationProperties.get(StrimziMonitorIntegrationProvider.TOKEN_PROPERTY);
        topicNamePrefix = (String) configurationProperties.get(StrimziMonitorIntegrationProvider.TOPIC_NAME_PREFIX);
        /*
             * Record the configuration
             */
        if (auditLog != null) {
            // do not record the token in the log which could be sensitive
            auditLog.logMessage(methodName, StrimziIntegrationConnectorAuditCode.CONNECTOR_CONFIGURATION.getMessageDefinition(connectorName, targetURL, templateQualifiedName));
        }
    } else {
        if (auditLog != null) {
            auditLog.logMessage(methodName, StrimziIntegrationConnectorAuditCode.NO_CONNECTION_PROPERTIES.getMessageDefinition(connectorName, targetURL));
        }
        throwException(StrimziIntegrationConnectorErrorCode.NO_CONNECTION_CONFIGURATION, StrimziMonitorIntegrationProvider.TOKEN_PROPERTY);
    }
    /*
         * Retrieve the template if one has been requested
         */
    if (templateQualifiedName != null) {
        try {
            List<TopicElement> templateElements = myContext.getTopicsByName(templateQualifiedName, 0, 0);
            if (templateElements != null) {
                for (TopicElement templateElement : templateElements) {
                    String qualifiedName = templateElement.getProperties().getQualifiedName();
                    if (templateQualifiedName.equals(qualifiedName)) {
                        templateGUID = templateElement.getElementHeader().getGUID();
                    }
                }
            }
        } catch (Exception error) {
            if (auditLog != null) {
                auditLog.logException(methodName, StrimziIntegrationConnectorAuditCode.MISSING_TEMPLATE.getMessageDefinition(connectorName, templateQualifiedName), error);
            }
        }
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) TopicElement(org.odpi.openmetadata.accessservices.datamanager.metadataelements.TopicElement) URI(java.net.URI) EndpointProperties(org.odpi.openmetadata.frameworks.connectors.properties.EndpointProperties) InvalidParameterException(org.odpi.openmetadata.frameworks.connectors.ffdc.InvalidParameterException) URISyntaxException(java.net.URISyntaxException) KeyStoreException(java.security.KeyStoreException) UserNotAuthorizedException(org.odpi.openmetadata.frameworks.connectors.ffdc.UserNotAuthorizedException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) KeyManagementException(java.security.KeyManagementException) ConnectorCheckedException(org.odpi.openmetadata.frameworks.connectors.ffdc.ConnectorCheckedException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) PropertyServerException(org.odpi.openmetadata.frameworks.connectors.ffdc.PropertyServerException)

Aggregations

EndpointProperties (org.odpi.openmetadata.frameworks.connectors.properties.EndpointProperties)3 ConnectorCheckedException (org.odpi.openmetadata.frameworks.connectors.ffdc.ConnectorCheckedException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Connection (com.rabbitmq.client.Connection)1 ConnectionFactory (com.rabbitmq.client.ConnectionFactory)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 KeyManagementException (java.security.KeyManagementException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 TopicElement (org.odpi.openmetadata.accessservices.datamanager.metadataelements.TopicElement)1 SASCatalogRestClient (org.odpi.openmetadata.connector.sas.client.SASCatalogRestClient)1 SASCatalogObject (org.odpi.openmetadata.connector.sas.repository.connector.mapping.SASCatalogObject)1 InvalidParameterException (org.odpi.openmetadata.frameworks.connectors.ffdc.InvalidParameterException)1 PropertyServerException (org.odpi.openmetadata.frameworks.connectors.ffdc.PropertyServerException)1 UserNotAuthorizedException (org.odpi.openmetadata.frameworks.connectors.ffdc.UserNotAuthorizedException)1 ConnectionProperties (org.odpi.openmetadata.frameworks.connectors.properties.ConnectionProperties)1 OMRSMetadataCollection (org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.OMRSMetadataCollection)1