Implementing a Repository Connector¶
A repository connector is built from three classes: a connector provider, a connector, and the metadata collection that the connector returns. The interfaces and base classes are described in Writing Repository Connectors. This page walks through the steps to implement each of them, and to plug the result into an OMAG Server.
classDiagram
class OMRSRepositoryConnectorProviderBase
class OMRSRepositoryConnector
class OMRSMetadataCollection
class OMRSMetadataCollectionBase
class OMRSDynamicTypeMetadataCollectionBase
class OMRSFixedTypeMetadataCollectionBase
OMRSRepositoryConnectorProviderBase <|-- XXXOMRSRepositoryConnectorProvider
OMRSRepositoryConnector <|-- XXXOMRSRepositoryConnector
OMRSMetadataCollection <|-- OMRSMetadataCollectionBase
OMRSMetadataCollectionBase <|-- OMRSDynamicTypeMetadataCollectionBase
OMRSMetadataCollectionBase <|-- OMRSFixedTypeMetadataCollectionBase
OMRSDynamicTypeMetadataCollectionBase <|-- XXXOMRSMetadataCollection
XXXOMRSRepositoryConnectorProvider ..> XXXOMRSRepositoryConnector : creates
XXXOMRSRepositoryConnector ..> XXXOMRSMetadataCollection : creates
Build dependencies¶
The interfaces and base classes are in the repository-services-apis module. A repository connector also depends on the Open Connector Framework (OCF), the Audit Log Framework (ALF) and the Open Metadata Framework (OMF), whose exceptions appear on the OCF's API.
<dependencies>
<dependency>
<groupId>org.odpi.egeria</groupId>
<artifactId>open-connector-framework</artifactId>
</dependency>
<dependency>
<groupId>org.odpi.egeria</groupId>
<artifactId>audit-log-framework</artifactId>
</dependency>
<dependency>
<groupId>org.odpi.egeria</groupId>
<artifactId>open-metadata-framework</artifactId>
</dependency>
<dependency>
<groupId>org.odpi.egeria</groupId>
<artifactId>repository-services-apis</artifactId>
</dependency>
</dependencies>
dependencies {
compileOnly project(':open-metadata-implementation:frameworks:open-connector-framework')
compileOnly project(':open-metadata-implementation:frameworks:audit-log-framework')
compileOnly project(':open-metadata-implementation:frameworks:open-metadata-framework')
compileOnly project(':open-metadata-implementation:repository-services:repository-services-apis')
}
Writing the connector provider¶
Each connector provider extends the following abstract class:
org.odpi.openmetadata.frameworks.connectors.ConnectorProvider
There is a base class that provides much of the implementation for a connector provider:
org.odpi.openmetadata.frameworks.connectors.ConnectorProviderBase
and a subclass of it that sets up the connector provider from a single description of the connector:
org.odpi.openmetadata.frameworks.connectors.OpenConnectorProviderBase
These base classes assume:
- There is a single connector implementation class for the connector.
- The connector is instantiated with the default constructor. This means all of its configuration information is contained in the Connection object supplied on the
initialize()method.
If your connector implementation matches these requirements, its connector provider implementation need only implement a constructor to configure the base class's function with details of itself and the Java class of the connector it needs using:
- a GUID for the connector type
- a qualified name and display name for the connector type.
- a description of what the connector is for and how to configure it.
- the connector class it instantiates.
- a list of the additional properties, configuration properties and secured properties needed to configure instances of the connector.
- a description of the connector for its audit log (if the connector implements
AuditLoggingComponent).
Use the base class for your type of connector
Many types of connector have their own connector provider base class that extends OpenConnectorProviderBase, for example IntegrationConnectorProvider for integration connectors and OMRSRepositoryConnectorProviderBase for repository connectors. Extend the base class for the type of connector you are writing.
Using OpenConnectorProviderBase¶
The descriptive information about the connector is supplied through an implementation of the OpenConnectorDefinition interface. This is typically an enum that describes all the connectors in a module. Egeria's own connectors are described in the EgeriaOpenConnectorDefinition enum in the org.odpi.openmetadata.adapters.connectors package. An OpenConnectorDefinition returns:
getConnectorComponentId()- unique identifier of the connector for the audit log.getConnectorTypeGUID()- unique identifier of the connector type.getConnectorQualifiedName(),getConnectorDisplayName(),getConnectorDescription()andgetConnectorWikiPage()- descriptive information for the connector type and audit log.getConnectorProviderClassName()- the class name of the connector provider.OpenConnectorProviderBasechecks that this matches the class of the connector provider being constructed.getConnectorDevelopmentStatus()- theComponentDevelopmentStatusof the connector.getSupportedAssetTypeName()andgetSupportedDeployedImplementationType()- the type of asset and the deployed implementation type that the connector works with.getComponentDescription()- theAuditLogReportingComponentfor the connector's audit log messages.
The connector provider then passes this definition to the OpenConnectorProviderBase constructor, along with the connector class name and the names of its recognized configuration properties. The constructor builds the connector type and audit log component description from these values.
/**
* XXXStoreProvider is the OCF connector provider for the XXX connector.
*/
public class XXXStoreProvider extends OpenConnectorProviderBase
{
/*
* Define the name of the connector implementation.
*/
private static final String connectorClassName = "packagename.XXXStoreConnector";
/*
* Define the name of configuration properties.
*/
public static final String TEMPLATE_QUALIFIED_NAME_CONFIGURATION_PROPERTY = "templateQualifiedName";
/**
* Constructor used to initialize the ConnectorProviderBase class.
*/
public XXXStoreProvider()
{
super(MyOrgConnectorDefinition.XXX_STORE_CONNECTOR,
connectorClassName,
List.of(TEMPLATE_QUALIFIED_NAME_CONFIGURATION_PROPERTY));
}
}
There is also a constructor that takes the list of interfaces that the connector supports and a description of the data format that it expects. After calling super(...), the constructor may set up the supportedTechnologyTypes, supportedConfigurationProperties and supportedTemplateTypes variables inherited from ConnectorProvider.
Example: BasicFileStoreProvider
The BasicFileStoreProvider passes EgeriaOpenConnectorDefinition.BASIC_FILE_STORE_CONNECTOR, its connector class name and the BasicFileStore interface to OpenConnectorProviderBase, and then sets supportedTechnologyTypes to show that it works with files.
Using ConnectorProviderBase directly¶
Alternatively, the connector provider can extend ConnectorProviderBase and set up the connector type and component description itself.
/**
* XXXStoreProvider is the OCF connector provider for the XXX connector.
*/
public class XXXStoreProvider extends ConnectorProviderBase
{
/*
* Unique identifier of the connector for the audit log.
*/
private static final int connectorComponentId = 10001; /* Add unique number here */
/*
* Unique identifier for the connector type.
*/
private static final String connectorTypeGUID = "Add unique GUID here";
/*
* Descriptive information about the connector for the connector type and audit log.
*/
private static final String connectorQualifiedName = "MyOrg:XXXStoreConnector";
private static final String connectorDisplayName = "XXX Store Connector";
private static final String connectorDescription = "Connector supports ... add details here.";
private static final String connectorWikiPage = "Add url to documentation here";
/*
* Define the name of the connector implementation.
*/
private static final String connectorClassName = "packagename.XXXStoreConnector";
/*
* Define the name of configuration properties.
*/
public static final String TEMPLATE_QUALIFIED_NAME_CONFIGURATION_PROPERTY = "templateQualifiedName";
/**
* Constructor used to initialize the ConnectorProviderBase class.
*/
public XXXStoreProvider()
{
super();
/*
* Set up the class name of the connector that this provider creates.
*/
super.setConnectorClassName(connectorClassName);
/*
* Set up the connector type that should be included in a connection used to configure this connector.
*/
ConnectorType connectorType = new ConnectorType();
connectorType.setGUID(connectorTypeGUID);
connectorType.setQualifiedName(connectorQualifiedName);
connectorType.setDisplayName(connectorDisplayName);
connectorType.setDescription(connectorDescription);
connectorType.setConnectorProviderClassName(this.getClass().getName());
List<String> recognizedConfigurationProperties = new ArrayList<>();
recognizedConfigurationProperties.add(TEMPLATE_QUALIFIED_NAME_CONFIGURATION_PROPERTY);
connectorType.setRecognizedConfigurationProperties(recognizedConfigurationProperties);
super.connectorTypeBean = connectorType;
/*
* Set up the component description used in the connector's audit log messages.
*/
AuditLogReportingComponent componentDescription = new AuditLogReportingComponent();
componentDescription.setComponentId(connectorComponentId);
componentDescription.setComponentName(connectorQualifiedName);
componentDescription.setComponentDescription(connectorDescription);
componentDescription.setComponentWikiURL(connectorWikiPage);
super.setConnectorComponentDescription(componentDescription);
}
}
The connector provider for a repository connector extends OMRSRepositoryConnectorProviderBase. For example, the in-memory repository's provider is:
public class InMemoryOMRSRepositoryConnectorProvider extends OMRSRepositoryConnectorProviderBase
{
/*
* Class of the connector.
*/
private static final String connectorClassName = "org.odpi.openmetadata.adapters.repositoryservices.inmemory.repositoryconnector.InMemoryOMRSRepositoryConnector";
/**
* Constructor used to initialize the ConnectorProviderBase with the Java class name of the specific
* OMRS Connector implementation.
*/
public InMemoryOMRSRepositoryConnectorProvider()
{
super(EgeriaOpenConnectorDefinition.IN_MEMORY_REPOSITORY_CONNECTOR,
connectorClassName,
null);
}
}
Writing the connector¶
The connector extends OMRSRepositoryConnector. When the server starts, the Open Metadata Repository Services (OMRS) creates the connector from its connection and then calls the following methods, in this order, before calling start():
setAuditLogandsetMaxPageSize.setServerName,setServerType,setServerUserIdandsetOrganizationName.setRepositoryHelperandsetRepositoryValidator- these supply the repository helper and repository validator that the connector and its metadata collection use to build and check type definitions and instances.setMetadataCollectionNameand thensetMetadataCollectionId.
The OMRS calls getMetadataCollection() as soon as setMetadataCollectionId returns, so the connector should override setMetadataCollectionId to create its metadata collection. The base class's getMetadataCollection() throws a RepositoryErrorException if the metadataCollection variable has not been set. This is how the in-memory repository connector does it:
@Override
public void setMetadataCollectionId(String metadataCollectionId)
{
if (metadataCollectionId == null)
{
super.metadataCollectionId = UUID.randomUUID().toString();
}
else
{
super.metadataCollectionId = metadataCollectionId;
}
/*
* Initialize the metadata collection only once the connector is properly set up.
*/
super.metadataCollection = new InMemoryOMRSMetadataCollection(this,
super.serverName,
repositoryHelper,
repositoryValidator,
super.metadataCollectionId);
}
Use the start() and disconnect() methods to open and close the connection to the repository technology. The connection's endpoint, secured properties and configuration properties are available from the connectionBean variable inherited from ConnectorBase.
Writing the metadata collection¶
The metadata collection extends one of the base classes described in Choosing a base class for the metadata collection. Its constructor receives the parent connector, the repository name, the repository helper and validator, and the metadata collection id. OMRSFixedTypeMetadataCollectionBase also takes the names of the attribute types and types that the repository supports.
The methods of OMRSMetadataCollection fall into these groups:
- Methods to retrieve information about the metadata repository, such as
getMetadataCollectionId. - Methods for working with the type definitions (TypeDefs and AttributeTypeDefs). These are handled by
OMRSDynamicTypeMetadataCollectionBaseandOMRSFixedTypeMetadataCollectionBase. - Methods for querying entities and relationships, for example
getEntityDetail,findEntitiesandfindRelationships. - Methods for maintaining the instances, for example
addEntity,updateEntityProperties,classifyEntity,addRelationship,deleteEntity,restoreEntityandpurgeEntity. - Methods for repairing the metadata collections of the cohort, for example
reIdentifyEntity,reTypeEntityandreHomeEntity. - Methods for the local maintenance of reference copies, for example
saveEntityReferenceCopyandpurgeEntityReferenceCopy. These changes are not sent to the rest of the cohort.
Use the repository helper to build instances (for example getSkeletonEntity, getNewRelationship and getNewClassification) and the repository validator to check the parameters and the instances against their types. The OMRS metamodel describes the structures that the methods work with.
Use the existing connectors as a guide
The in-memory and PostgreSQL repository connectors are complete native repository implementations built on OMRSDynamicTypeMetadataCollectionBase. Both return an OMRSDynamicTypeStore from getDynamicTypeStore() so that the types defined through their API survive a restart.
Adding an event mapper¶
If the repository's content can be changed through the third party technology's own interfaces, add an event mapper connector so that these changes are sent to the other members of the cohort.
Configuring the connector in a server¶
Once the connector's JAR file is on the OMAG Server Platform's classpath, it is configured with the Administration Services:
- For a native repository in a metadata access store, use
POST /open-metadata/admin-services/servers/{serverName}/local-repository/mode/plugin-repository/details?connectorProvider={connectorProviderClassName}. The request body is an optional map of configuration properties. Alternatively, pass a complete connection to.../local-repository/mode/plugin-repository/connection. See Configuring a Metadata Access Store. - For an adapter to a third party repository in a repository proxy, use
POST .../local-repository/mode/repository-proxy/details?connectorProvider={connectorProviderClassName}(or.../repository-proxy/connection). See Configuring a Repository Proxy.
Testing the connector¶
The Conformance Test Suite runs a repository workbench against the connector to check that it correctly implements the repository services protocols.
Raise an issue or comment below