Skip to content

Commit

Permalink
Merge pull request #8487 from mandy-chessell/oak2024
Browse files Browse the repository at this point in the history
Enable deeply nested virtual connections/connectors
  • Loading branch information
mandy-chessell authored Nov 13, 2024
2 parents f623918 + a824af4 commit 1420289
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 42 deletions.
2 changes: 1 addition & 1 deletion application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ platform.placeholder.variables=\
"kafkaEndpoint" : "localhost:9092",\
"egeriaEndpoint" : "https://localhost:9443",\
"postgreSQLDatabaseURL" : "jdbc:postgresql://localhost:5432/egeria",\
"secretsStore" : "loading_bay/secrets/defaults.omsecrets",\
"secretsStore" : "loading-bay/secrets/default.omsecrets",\
"postgreSQLServerCollectionName" : "PostgreSQL Server:LocalPostgreSQL1"\
}

Expand Down
4 changes: 2 additions & 2 deletions container.application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ platform.placeholder.variables=\
{\
"kafkaEndpoint" : "host.docker.internal:9192",\
"egeriaEndpoint" : "https://host.docker.internal:9443",\
"postgreSQLDatabaseURL" : "jdbc:postgresql://host.docker.internal:5432/egeria",\
"secretsStore" : "loading_bay/secrets/defaults.omsecrets",\
"postgreSQLDatabaseURL" : "jdbc:postgresql://host.docker.internal:5442/egeria",\
"secretsStore" : "loading-bay/secrets/default.omsecrets",\
"postgreSQLServerCollectionName" : "PostgreSQL Server:LocalPostgreSQL1"\
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4007,6 +4007,10 @@ private void addLatestChangeToAnchor(EntityDetail anchorEntity,
// Ignore exception, possibly a race condition - the entity is already classified
}
}
catch (PropertyServerException e)
{
// Ignore exception, possibly a race condition - the entity is already classified
}
catch (InvalidParameterException | TypeErrorException error)
{
throw new PropertyServerException(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,43 +214,61 @@ private ConnectorProvider getConnectorProvider(ConnectorTypeProperties reques
*/
private ConnectionProperties getConnection(EmbeddedConnectionProperties embeddedConnection)
{
ConnectionProperties connection = null;

if (embeddedConnection != null)
{
AccessibleConnection accessibleConnection = new AccessibleConnection(embeddedConnection.getConnectionProperties());
Connection connectionBean = accessibleConnection.getConnectionBean();

Map<String, Object> arguments = embeddedConnection.getArguments();

if (arguments != null)
if (embeddedConnection.getConnectionProperties() instanceof VirtualConnectionProperties virtualConnectionProperties)
{
Map<String, Object> configurationProperties = connectionBean.getConfigurationProperties();
if (configurationProperties == null)
{
configurationProperties = new HashMap<>();
}
AccessibleVirtualConnection accessibleConnection = new AccessibleVirtualConnection(virtualConnectionProperties);
VirtualConnection connectionBean = accessibleConnection.getConnectionBean();
connectionBean.setConfigurationProperties(this.addArgumentsToConfigurationProperties(embeddedConnection.getArguments(),
connectionBean.getConfigurationProperties()));
return new VirtualConnectionProperties(connectionBean);
}
else
{
AccessibleConnection accessibleConnection = new AccessibleConnection(embeddedConnection.getConnectionProperties());
Connection connectionBean = accessibleConnection.getConnectionBean();
connectionBean.setConfigurationProperties(this.addArgumentsToConfigurationProperties(embeddedConnection.getArguments(),
connectionBean.getConfigurationProperties()));
return new ConnectionProperties(connectionBean);
}
}

for (String argumentName : arguments.keySet())
{
configurationProperties.put(argumentName, arguments.get(argumentName).toString());
}
return null;
}

if (configurationProperties.isEmpty())
{
configurationProperties = null;
}

connectionBean.setConfigurationProperties(configurationProperties);
/**
* Combine arguments from the embedded connection with the embedded configuration properties
*
* @param arguments arguments
* @param configurationProperties configuration properties
* @return combination
*/
private Map<String, Object> addArgumentsToConfigurationProperties(Map<String, Object> arguments,
Map<String, Object> configurationProperties)
{
if (configurationProperties == null)
{
configurationProperties = new HashMap<>();
}

if (arguments != null)
{
for (String argumentName : arguments.keySet())
{
configurationProperties.put(argumentName, arguments.get(argumentName).toString());
}
}

connection = new ConnectionProperties(connectionBean);
if (configurationProperties.isEmpty())
{
configurationProperties = null;
}

return connection;
return configurationProperties;
}


/**
* Validate that the connection has sufficient properties to attempt to create a connector.
* Any problems found are expressed as a ConnectionCheckedException.
Expand Down Expand Up @@ -571,4 +589,27 @@ protected Connection getConnectionBean()
return super.getConnectionBean();
}
}


/**
* ProtectedConnection provides a subclass to Connection in order to extract protected values from the
* connection in order to supply them to the Connector implementation.
*/
private static class AccessibleVirtualConnection extends VirtualConnectionProperties
{
AccessibleVirtualConnection(VirtualConnectionProperties templateConnection)
{
super(templateConnection);
}

/**
* Return a copy of the ConnectionBean.
*
* @return Connection bean
*/
protected VirtualConnection getConnectionBean()
{
return super.getConnectionBean();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.odpi.openmetadata.frameworks.connectors.properties.beans.Connection;
import org.odpi.openmetadata.frameworks.connectors.properties.beans.ConnectorType;
import org.odpi.openmetadata.frameworks.connectors.properties.beans.Endpoint;
import org.odpi.openmetadata.frameworks.connectors.properties.beans.VirtualConnection;

import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -101,6 +102,10 @@ public ConnectionProperties(ConnectionProperties templateConnection)
{
this.connectionBean = new Connection();
}
else if (templateConnection instanceof VirtualConnectionProperties virtualConnectionProperties)
{
this.connectionBean = new VirtualConnection(virtualConnectionProperties.getConnectionBean());
}
else
{
this.connectionBean = new Connection(templateConnection.getConnectionBean());
Expand All @@ -123,6 +128,10 @@ public ConnectionProperties(ConnectionProperties templateConnection,
{
this.connectionBean = new Connection();
}
else if (templateConnection instanceof VirtualConnectionProperties virtualConnectionProperties)
{
this.connectionBean = new VirtualConnection(virtualConnectionProperties.getConnectionBean());
}
else
{
this.connectionBean = new Connection(templateConnection.getConnectionBean());
Expand Down Expand Up @@ -175,14 +184,14 @@ public String getConnectionName()
/*
* The qualifiedName is preferred because it is unique.
*/
if (qualifiedName != null && (!qualifiedName.equals("")))
if (qualifiedName != null && (!qualifiedName.isEmpty()))
{
/*
* Use qualified name.
*/
connectionName = qualifiedName;
}
else if (displayName != null && (!displayName.equals("")))
else if (displayName != null && (!displayName.isEmpty()))
{
/*
* The qualifiedName is not set but the displayName is available so use it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.odpi.openmetadata.frameworks.connectors.properties.beans.Connection;
import org.odpi.openmetadata.frameworks.connectors.properties.beans.EmbeddedConnection;
import org.odpi.openmetadata.frameworks.connectors.properties.beans.VirtualConnection;

import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -100,6 +101,10 @@ public ConnectionProperties getConnectionProperties()
{
return null;
}
else if (embeddedConnection instanceof VirtualConnection virtualConnection)
{
return new VirtualConnectionProperties(virtualConnection);
}
else
{
return new ConnectionProperties(embeddedConnection);
Expand Down Expand Up @@ -143,15 +148,14 @@ public boolean equals(Object objectToCompare)
{
return true;
}
if (!(objectToCompare instanceof EmbeddedConnectionProperties))
if (!(objectToCompare instanceof EmbeddedConnectionProperties that))
{
return false;
}
if (!super.equals(objectToCompare))
{
return false;
}
EmbeddedConnectionProperties that = (EmbeddedConnectionProperties) objectToCompare;
return Objects.equals(getEmbeddedConnectionBean(), that.getEmbeddedConnectionBean());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

Expand Down Expand Up @@ -136,14 +135,7 @@ public void setArguments(Map<String, Object> arguments)
*/
public Connection getEmbeddedConnection()
{
if (embeddedConnection == null)
{
return null;
}
else
{
return new Connection(embeddedConnection);
}
return embeddedConnection;
}


Expand Down
2 changes: 1 addition & 1 deletion test.application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ platform.placeholder.variables=\
{\
"egeriaEndpoint" : "https://localhost:9443",\
"postgreSQLDatabaseURL" : "jdbc:postgresql://localhost:5432/egeria",\
"secretsStore" : "loading_bay/secrets/defaults.omsecrets",\
"secretsStore" : "loading-bay/secrets/default.omsecrets",\
"postgreSQLServerCollectionName" : "PostgreSQL Server:LocalPostgreSQL1"\
}

Expand Down

0 comments on commit 1420289

Please sign in to comment.