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);
}
}
}
}
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;
}
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());
}
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);
}
}
}
}
Aggregations