Search in sources :

Example 1 with TopicElement

use of org.odpi.openmetadata.accessservices.datamanager.metadataelements.TopicElement in project egeria-connector-integration-topic-strimzi by odpi.

the class StrimziMonitorIntegrationConnector method determineMutations.

void determineMutations(List<TopicElement> cataloguedTopics, Map<String, TopicProperties> strimziTopicElements) {
    // existing strimzi topics
    Set<String> strimziTopicNames;
    Map<String, TopicElement> cataloguedTopicMap = new HashMap<>();
    if (cataloguedTopics != null) {
        for (TopicElement topicElement : cataloguedTopics) {
            String topicName = topicElement.getProperties().getQualifiedName();
            // restrict to the topic names we care about.
            if (includeTopicBasedOnName(topicName)) {
                cataloguedTopicMap.put(topicName, topicElement);
            }
        }
        /*
             * Loop through catalogued topics to decide whether to update or delete by populating the maps.
             * The delete and update maps need the Egeria guid to be able to action the mutation.
             */
        if (cataloguedTopics.size() > 0) {
            // uncomment and implement more code if we need to consider paging
            // startFrom = startFrom + cataloguedTopics.size();
            strimziTopicNames = strimziTopicElements.keySet();
            for (TopicElement cataloguedTopic : cataloguedTopics) {
                String cataloguedTopicName = cataloguedTopic.getProperties().getQualifiedName();
                String cataloguedEgeriaTopicGUID = cataloguedTopic.getElementHeader().getGUID();
                if (!strimziTopicNames.contains(cataloguedTopicName)) {
                    /*
                         * The topic no longer exists so delete it from the catalog.
                         */
                    deleteTopicNameToGuidMap.put(cataloguedTopicName, cataloguedEgeriaTopicGUID);
                } else {
                    // we have 2 topics of the same name in Strimzi and Egeria
                    if (updateRequired(strimziTopicElements.get(cataloguedTopicName), cataloguedTopicMap.get(cataloguedTopicName))) {
                        updateTopicNameToGuidMap.put(cataloguedTopicName, cataloguedEgeriaTopicGUID);
                    }
                }
            }
        }
    }
    /*
         * loop through Strimzi topics to determine what we need to add. The add is made without a guid, as the guid
         * does not exist yet.
         */
    if (strimziTopicElements != null && strimziTopicElements.size() > 0) {
        strimziTopicNames = strimziTopicElements.keySet();
        for (String strimziTopicName : strimziTopicNames) {
            Set<String> cataloguedTopicNames = cataloguedTopicMap.keySet();
            if (!cataloguedTopicNames.contains(strimziTopicName)) {
                addTopicNamesSet.add(strimziTopicName);
            }
        }
    }
}
Also used : TopicElement(org.odpi.openmetadata.accessservices.datamanager.metadataelements.TopicElement)

Example 2 with TopicElement

use of org.odpi.openmetadata.accessservices.datamanager.metadataelements.TopicElement in project egeria-connector-integration-topic-strimzi by odpi.

the class StrimziMonitorIntegrationConnectorTest method convertTopicPropertiesMapToTopicElementList.

private List<TopicElement> convertTopicPropertiesMapToTopicElementList(Map<String, TopicProperties> topicPropertiesMap) {
    List<TopicElement> topicElementList = new ArrayList<>();
    int guid = 1;
    for (String topicName : topicPropertiesMap.keySet()) {
        TopicElement topicElement = new TopicElement();
        TopicProperties topicProperties = topicPropertiesMap.get(topicName);
        topicElement.setProperties(topicProperties);
        ElementHeader elementHeader = new ElementHeader();
        elementHeader.setGUID("" + guid);
        guid++;
        topicElement.setElementHeader(elementHeader);
        topicElementList.add(topicElement);
    }
    return topicElementList;
}
Also used : ElementHeader(org.odpi.openmetadata.accessservices.datamanager.metadataelements.ElementHeader) TopicElement(org.odpi.openmetadata.accessservices.datamanager.metadataelements.TopicElement) TopicProperties(org.odpi.openmetadata.accessservices.datamanager.properties.TopicProperties)

Example 3 with TopicElement

use of org.odpi.openmetadata.accessservices.datamanager.metadataelements.TopicElement in project egeria-connector-integration-topic-strimzi by odpi.

the class StrimziMonitorIntegrationConnectorTest method testdetermineMutations.

@Test
void testdetermineMutations() throws IOException, ConnectorCheckedException {
    String textPath = "src/test/resources/SampleGetResponse.json";
    Path path = Paths.get(textPath);
    String content = Files.readString(path);
    StrimziMonitorIntegrationConnector conn = new StrimziMonitorIntegrationConnector();
    Map<String, TopicProperties> topicPropertiesMap = conn.convertStringToTopicMap(content);
    List<TopicElement> topicElementList = convertTopicPropertiesMapToTopicElementList(topicPropertiesMap);
    conn.determineMutations(topicElementList, topicPropertiesMap);
    assertTrue(conn.getupdateTopicNameToGuidMap().keySet().isEmpty());
    assertTrue(conn.getdeleteTopicNameToGuidMap().keySet().isEmpty());
    assertTrue(conn.getaddTopicNamesSet().isEmpty());
    // test add
    List<TopicElement> topicElementListReduced = new ArrayList<>();
    topicElementListReduced.add(topicElementList.get(0));
    conn.determineMutations(topicElementListReduced, topicPropertiesMap);
    assertTrue(conn.getupdateTopicNameToGuidMap().keySet().isEmpty());
    assertTrue(conn.getdeleteTopicNameToGuidMap().keySet().isEmpty());
    assertTrue(conn.getaddTopicNamesSet().size() == 17);
    // reset connection to clean
    conn = new StrimziMonitorIntegrationConnector();
    topicPropertiesMap = conn.convertStringToTopicMap(content);
    // test delete
    TopicElement newTopicElement = new TopicElement();
    TopicProperties properties = new TopicProperties();
    properties.setQualifiedName("aaa");
    properties.setDescription("bbb");
    Map<String, Object> extendedProperties = new HashMap<>();
    extendedProperties.put(StrimziMonitorIntegrationConnector.PARTITIONS, Integer.valueOf(10));
    extendedProperties.put(StrimziMonitorIntegrationConnector.REPLICAS, Integer.valueOf(20));
    properties.setExtendedProperties(extendedProperties);
    newTopicElement.setProperties(properties);
    ElementHeader elementHeader = new ElementHeader();
    elementHeader.setGUID("New guid");
    newTopicElement.setElementHeader(elementHeader);
    topicElementList.add(newTopicElement);
    conn.determineMutations(topicElementList, topicPropertiesMap);
    assertTrue(conn.getupdateTopicNameToGuidMap().keySet().isEmpty());
    assertTrue(conn.getdeleteTopicNameToGuidMap().keySet().size() == 1);
    assertTrue(conn.getaddTopicNamesSet().isEmpty());
    // reset connection to clean
    conn = new StrimziMonitorIntegrationConnector();
    topicPropertiesMap = conn.convertStringToTopicMap(content);
    TopicProperties topicProperties = new TopicProperties();
    // changed description
    topicProperties.setDescription("bbb bbb");
    topicProperties.setDisplayName("aaa");
    topicProperties.setQualifiedName("aaa");
    topicProperties.setExtendedProperties(extendedProperties);
    topicPropertiesMap.put("aaa", topicProperties);
    conn.determineMutations(topicElementList, topicPropertiesMap);
    assertTrue(conn.getupdateTopicNameToGuidMap().keySet().size() == 1);
    assertTrue(conn.getdeleteTopicNameToGuidMap().keySet().isEmpty());
    assertTrue(conn.getaddTopicNamesSet().isEmpty());
}
Also used : Path(java.nio.file.Path) ElementHeader(org.odpi.openmetadata.accessservices.datamanager.metadataelements.ElementHeader) TopicProperties(org.odpi.openmetadata.accessservices.datamanager.properties.TopicProperties) TopicElement(org.odpi.openmetadata.accessservices.datamanager.metadataelements.TopicElement) Test(org.junit.jupiter.api.Test)

Example 4 with TopicElement

use of org.odpi.openmetadata.accessservices.datamanager.metadataelements.TopicElement 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

TopicElement (org.odpi.openmetadata.accessservices.datamanager.metadataelements.TopicElement)4 ElementHeader (org.odpi.openmetadata.accessservices.datamanager.metadataelements.ElementHeader)2 TopicProperties (org.odpi.openmetadata.accessservices.datamanager.properties.TopicProperties)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Path (java.nio.file.Path)1 KeyManagementException (java.security.KeyManagementException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Test (org.junit.jupiter.api.Test)1 ConnectorCheckedException (org.odpi.openmetadata.frameworks.connectors.ffdc.ConnectorCheckedException)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 EndpointProperties (org.odpi.openmetadata.frameworks.connectors.properties.EndpointProperties)1