http://git-wip-us.apache.org/repos/asf/atlas/blob/8a57e657/omrs/src/main/java/org/apache/atlas/omrs/localrepository/repositoryconnector/LocalOMRSRepositoryConnector.java ---------------------------------------------------------------------- diff --git a/omrs/src/main/java/org/apache/atlas/omrs/localrepository/repositoryconnector/LocalOMRSRepositoryConnector.java b/omrs/src/main/java/org/apache/atlas/omrs/localrepository/repositoryconnector/LocalOMRSRepositoryConnector.java new file mode 100644 index 0000000..752a090 --- /dev/null +++ b/omrs/src/main/java/org/apache/atlas/omrs/localrepository/repositoryconnector/LocalOMRSRepositoryConnector.java @@ -0,0 +1,259 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.atlas.omrs.localrepository.repositoryconnector; + +import org.apache.atlas.ocf.ffdc.ConnectorCheckedException; +import org.apache.atlas.ocf.properties.Connection; +import org.apache.atlas.omrs.eventmanagement.*; +import org.apache.atlas.omrs.eventmanagement.events.OMRSInstanceEventProcessor; +import org.apache.atlas.omrs.eventmanagement.events.OMRSTypeDefEventProcessor; +import org.apache.atlas.omrs.eventmanagement.repositoryeventmapper.OMRSRepositoryEventMapper; +import org.apache.atlas.omrs.localrepository.OMRSLocalRepository; +import org.apache.atlas.omrs.localrepository.repositorycontentmanager.OMRSRepositoryContentManager; +import org.apache.atlas.omrs.localrepository.repositorycontentmanager.OMRSTypeDefValidator; +import org.apache.atlas.omrs.metadatacollection.OMRSMetadataCollection; +import org.apache.atlas.omrs.metadatacollection.repositoryconnector.OMRSRepositoryConnector; + + +/** + * LocalOMRSRepositoryConnector provides access the local metadata repository plus manages outbound + * repository events. + * + * It passes each request to both the real OMRS connector for the local metadata repository and an + * OMRSEventPublisher. The OMRSEventPublisher will use its configuration to decide if it needs to + * pass on the request to the rest of the metadata repository cohort. + */ +public class LocalOMRSRepositoryConnector extends OMRSRepositoryConnector implements OMRSLocalRepository +{ + private String localServerName = null; + private String localServerType = null; + private String localOrganizationName = null; + private OMRSRepositoryEventMapper repositoryEventMapper = null; + private OMRSRepositoryContentManager localTypeDefManager = null; + private OMRSInstanceEventProcessor incomingInstanceEventProcessor = null; + private OMRSRepositoryEventManager outboundRepositoryEventManager = null; + private OMRSRepositoryEventProcessor outboundRepositoryEventProcessor = null; + + private String localMetadataCollectionId = null; + private LocalOMRSMetadataCollection metadataCollection = null; + + private OMRSRepositoryConnector realLocalConnector = null; + private OMRSMetadataCollection realMetadataCollection = null; + + /** + * Constructor used by the LocalOMRSConnectorProvider. It provides the information necessary to run the + * local repository. + * + * @param localServerName - name of the local server + * @param localServerType - type of the local server + * @param localOrganizationName - name of organization that owns the server + * @param realLocalConnector - connector to the local repository + * @param repositoryEventMapper - optional event mapper for local repository + * @param outboundRepositoryEventManager - event manager to call for outbound events. + * @param localTypeDefManager - localTypeDefManager for supporting OMRS in managing TypeDefs. + * @param saveExchangeRule - rule to determine what events to save to the local repository. + */ + protected LocalOMRSRepositoryConnector(String localServerName, + String localServerType, + String localOrganizationName, + OMRSRepositoryConnector realLocalConnector, + OMRSRepositoryEventMapper repositoryEventMapper, + OMRSRepositoryEventManager outboundRepositoryEventManager, + OMRSRepositoryContentManager localTypeDefManager, + OMRSRepositoryEventExchangeRule saveExchangeRule) + { + this.localServerName = localServerName; + this.localServerType = localServerType; + this.localOrganizationName = localOrganizationName; + + this.realLocalConnector = realLocalConnector; + this.realMetadataCollection = realLocalConnector.getMetadataCollection(); + this.repositoryEventMapper = repositoryEventMapper; + this.outboundRepositoryEventManager = outboundRepositoryEventManager; + + /* + * Incoming events are processed directly with real local connector to avoid the outbound event + * propagation managed by LocalOMRSMetadataCollection. + */ + this.localTypeDefManager = localTypeDefManager; + if (localTypeDefManager != null) + { + localTypeDefManager.setupEventProcessor(this, + realLocalConnector, + saveExchangeRule, + outboundRepositoryEventManager); + + } + + this.incomingInstanceEventProcessor = new LocalOMRSInstanceEventProcessor(localMetadataCollectionId, + realLocalConnector, + localTypeDefManager, + saveExchangeRule); + + /* + * The repositoryEventMapper is a plug-in component that handles repository events for + * repository that have additional APIs for managing metadata and need their own mechanism for + * sending OMRS Repository Events. If there is no repositoryEventMapper then the localOMRSMetadataCollection + * will send the outbound repository events. + */ + if (repositoryEventMapper != null) + { + repositoryEventMapper.setRepositoryEventProcessor(outboundRepositoryEventManager); + } + else + { + /* + * When outboundRepositoryEventProcessor is not null then the local metadata collection creates events. + * Otherwise it assumes the event mapper will produce events. + */ + this.outboundRepositoryEventProcessor = outboundRepositoryEventManager; + } + } + + + /** + * Free up any resources held since the connector is no longer needed. + * + * @throws ConnectorCheckedException - there is a problem disconnecting the connector. + */ + public void disconnect() throws ConnectorCheckedException + { + if (realLocalConnector != null) + { + realLocalConnector.disconnect(); + } + } + + + /* + * ============================== + * OMRSMetadataCollectionManager + */ + + /** + * Set up the unique Id for this metadata collection. + * + * @param metadataCollectionId - String unique Id + */ + public void setMetadataCollectionId(String metadataCollectionId) + { + this.localMetadataCollectionId = metadataCollectionId; + + /* + * Initialize the metadata collection only once the connector is properly set up. + */ + metadataCollection = new LocalOMRSMetadataCollection(localMetadataCollectionId, + localServerName, + localServerType, + localOrganizationName, + realMetadataCollection, + outboundRepositoryEventProcessor, + localTypeDefManager); + + } + + /** + * Returns the metadata collection object that provides an OMRS abstraction of the metadata within + * a metadata repository. + * + * @return OMRSMetadataCollection - metadata information retrieved from the metadata repository. + */ + public OMRSMetadataCollection getMetadataCollection() + { + if (metadataCollection == null) + { + // TODO Throw Error + } + + return metadataCollection; + } + + /* + * ==================================== + * OMRSLocalRepository + */ + + /** + * Returns the unique identifier (guid) of the local repository's metadata collection. + * + * @return String guid + */ + public String getMetadataCollectionId() + { + return localMetadataCollectionId; + } + + + /** + * Returns the Connection to the local repository that can be used by remote servers to create + * an OMRS repository connector to call this server in order to access the local repository. + * + * @return Connection object + */ + public Connection getLocalRepositoryRemoteConnection() + { + return super.connection; + } + + + /** + * Return the TypeDefValidator. This is used to validate that a list of type definitions (TypeDefs) are + * compatible with the local repository. + * + * @return OMRSTypeDefValidator object for the local repository. + */ + public OMRSTypeDefValidator getTypeDefValidator() + { + return localTypeDefManager; + } + + + /** + * Return the event manager that the local repository uses to distribute events from the local repository. + * + * @return outbound repository event manager + */ + public OMRSRepositoryEventManager getOutboundRepositoryEventManager() + { + return outboundRepositoryEventManager; + } + + + /** + * Return the TypeDef event processor that should be passed all incoming TypeDef events received + * from the cohorts that this server is a member of. + * + * @return OMRSTypeDefEventProcessor for the local repository. + */ + public OMRSTypeDefEventProcessor getIncomingTypeDefEventProcessor() + { + return localTypeDefManager; + } + + + /** + * Return the instance event processor that should be passed all incoming instance events received + * from the cohorts that this server is a member of. + * + * @return OMRSInstanceEventProcessor for the local repository. + */ + public OMRSInstanceEventProcessor getIncomingInstanceEventProcessor() + { + return incomingInstanceEventProcessor; + } +}
http://git-wip-us.apache.org/repos/asf/atlas/blob/8a57e657/omrs/src/main/java/org/apache/atlas/omrs/localrepository/repositoryconnector/OMRSInstanceRetrievalEventProcessor.java ---------------------------------------------------------------------- diff --git a/omrs/src/main/java/org/apache/atlas/omrs/localrepository/repositoryconnector/OMRSInstanceRetrievalEventProcessor.java b/omrs/src/main/java/org/apache/atlas/omrs/localrepository/repositoryconnector/OMRSInstanceRetrievalEventProcessor.java new file mode 100644 index 0000000..2518397 --- /dev/null +++ b/omrs/src/main/java/org/apache/atlas/omrs/localrepository/repositoryconnector/OMRSInstanceRetrievalEventProcessor.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.atlas.omrs.localrepository.repositoryconnector; + +import org.apache.atlas.omrs.metadatacollection.properties.instances.EntityDetail; +import org.apache.atlas.omrs.metadatacollection.properties.instances.Relationship; + +import java.util.ArrayList; + + +/** + * OMRSInstanceRetrievalEventProcessor defines the interface used by the Enterprise OMRS Repository Connector + * to pass instance metadata retrieved from remote open metadata repository connectors. + */ +public interface OMRSInstanceRetrievalEventProcessor +{ + /** + * Pass an entity that has been retrieved from a remote open metadata repository so it can be validated and + * (if the rules permit) cached in the local repository. + * + * @param metadataCollectionId - unique identifier for the metadata from the remote repository + * @param entity - the retrieved entity. + * @return Validated and processed entity. + */ + EntityDetail processRetrievedEntity(String metadataCollectionId, + EntityDetail entity); + + + /** + * Pass a list of entities that have been retrieved from a remote open metadata repository so they can be + * validated and (if the rules permit) cached in the local repository. + * + * @param metadataCollectionId - unique identifier for the metadata from the remote repository + * @param entities - the retrieved relationships + * @return the validated and processed relationships + */ + ArrayList<EntityDetail> processRetrievedEntities(String metadataCollectionId, + ArrayList<EntityDetail> entities); + + + /** + * Pass a relationship that has been retrieved from a remote open metadata repository so it can be validated and + * (if the rules permit) cached in the local repository. + * + * @param metadataCollectionId - unique identifier for the metadata from the remote repository + * @param relationship - the retrieved relationship + * @return the validated and processed relationship + */ + Relationship processRetrievedRelationship(String metadataCollectionId, + Relationship relationship); + + + /** + * Pass a list of relationships that have been retrieved from a remote open metadata repository so they can be + * validated and (if the rules permit) cached in the local repository. + * + * @param metadataCollectionId - unique identifier for the metadata from the remote repository + * @param relationships - the list of retrieved relationships + * @return the validated and processed relationships + */ + ArrayList<Relationship> processRetrievedRelationships(String metadataCollectionId, + ArrayList<Relationship> relationships); +} http://git-wip-us.apache.org/repos/asf/atlas/blob/8a57e657/omrs/src/main/java/org/apache/atlas/omrs/localrepository/repositorycontentmanager/OMRSInstanceHelper.java ---------------------------------------------------------------------- diff --git a/omrs/src/main/java/org/apache/atlas/omrs/localrepository/repositorycontentmanager/OMRSInstanceHelper.java b/omrs/src/main/java/org/apache/atlas/omrs/localrepository/repositorycontentmanager/OMRSInstanceHelper.java new file mode 100644 index 0000000..5478249 --- /dev/null +++ b/omrs/src/main/java/org/apache/atlas/omrs/localrepository/repositorycontentmanager/OMRSInstanceHelper.java @@ -0,0 +1,149 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.atlas.omrs.localrepository.repositorycontentmanager; + + +import org.apache.atlas.omrs.ffdc.exception.TypeErrorException; +import org.apache.atlas.omrs.metadatacollection.properties.instances.*; + +import java.util.ArrayList; + + +/** + * OMRSInstanceHelper provides methods to help OMRS connectors and adapters ensure the content of + * entities and relationships match the type definitions recorded in the TypeDefs. + */ +public interface OMRSInstanceHelper +{ + /** + * Return an entity with the header and type information filled out. The caller only needs to add properties + * and classifications to complete the set up of the entity. + * + * @param sourceName - source of the request (used for logging) + * @param metadataCollectionId - unique identifier for the home metadata collection + * @param provenanceType - origin of the entity + * @param userName - name of the creator + * @param typeName - name of the type + * @return partially filled out entity - needs classifications and properties + * @throws TypeErrorException - the type name is not recognized. + */ + EntityDetail getSkeletonEntity(String sourceName, + String metadataCollectionId, + InstanceProvenanceType provenanceType, + String userName, + String typeName) throws TypeErrorException; + + + /** + * Return a classification with the header and type information filled out. The caller only needs to add properties + * and possibility origin information if it is propagated to complete the set up of the classification. + * + * @param sourceName - source of the request (used for logging) + * @param userName - name of the creator + * @param classificationTypeName - name of the classification type + * @param entityTypeName - name of the type for the entity that this classification is to be attached to. + * @return partially filled out classification - needs properties and possibly origin information + * @throws TypeErrorException - the type name is not recognized as a classification type. + */ + Classification getSkeletonClassification(String sourceName, + String userName, + String classificationTypeName, + String entityTypeName) throws TypeErrorException; + + + /** + * Return a relationship with the header and type information filled out. The caller only needs to add properties + * to complete the set up of the relationship. + * + * @param sourceName - source of the request (used for logging) + * @param metadataCollectionId - unique identifier for the home metadata collection + * @param provenanceType - origin type of the relationship + * @param userName - name of the creator + * @param typeName - name of the relationship's type + * @return partially filled out relationship - needs properties + * @throws TypeErrorException - the type name is not recognized as a relationship type. + */ + Relationship getSkeletonRelationship(String sourceName, + String metadataCollectionId, + InstanceProvenanceType provenanceType, + String userName, + String typeName) throws TypeErrorException; + + + /** + * Return a filled out entity. It just needs to add the classifications. + * + * @param sourceName - source of the request (used for logging) + * @param metadataCollectionId - unique identifier for the home metadata collection + * @param provenanceType - origin of the entity + * @param userName - name of the creator + * @param typeName - name of the type + * @param properties - properties for the entity + * @param classifications - list of classifications for the entity + * @return an entity that is filled out + * @throws TypeErrorException - the type name is not recognized as an entity type + */ + EntityDetail getNewEntity(String sourceName, + String metadataCollectionId, + InstanceProvenanceType provenanceType, + String userName, + String typeName, + InstanceProperties properties, + ArrayList<Classification> classifications) throws TypeErrorException; + + + /** + * Return a filled out relationship. + * + * @param sourceName - source of the request (used for logging) + * @param metadataCollectionId - unique identifier for the home metadata collection + * @param provenanceType - origin of the relationship + * @param userName - name of the creator + * @param typeName - name of the type + * @param properties - properties for the relationship + * @return a relationship that is filled out + * @throws TypeErrorException - the type name is not recognized as a relationship type + */ + Relationship getNewRelationship(String sourceName, + String metadataCollectionId, + InstanceProvenanceType provenanceType, + String userName, + String typeName, + InstanceProperties properties) throws TypeErrorException; + + + /** + * Return a classification with the header and type information filled out. The caller only needs to add properties + * to complete the set up of the classification. + * + * @param sourceName - source of the request (used for logging) + * @param userName - name of the creator + * @param typeName - name of the type + * @param entityTypeName - name of the type for the entity that this classification is to be attached to. + * @param properties - properties for the classification + * @return partially filled out classification - needs properties and possibly origin information + * @throws TypeErrorException - the type name is not recognized as a classification type. + */ + Classification getNewClassification(String sourceName, + String userName, + String typeName, + String entityTypeName, + ClassificationOrigin classificationOrigin, + String classificationOriginGUID, + InstanceProperties properties) throws TypeErrorException; +} http://git-wip-us.apache.org/repos/asf/atlas/blob/8a57e657/omrs/src/main/java/org/apache/atlas/omrs/localrepository/repositorycontentmanager/OMRSInstanceValidator.java ---------------------------------------------------------------------- diff --git a/omrs/src/main/java/org/apache/atlas/omrs/localrepository/repositorycontentmanager/OMRSInstanceValidator.java b/omrs/src/main/java/org/apache/atlas/omrs/localrepository/repositorycontentmanager/OMRSInstanceValidator.java new file mode 100644 index 0000000..02561ab --- /dev/null +++ b/omrs/src/main/java/org/apache/atlas/omrs/localrepository/repositorycontentmanager/OMRSInstanceValidator.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.atlas.omrs.localrepository.repositorycontentmanager; + +import org.apache.atlas.omrs.metadatacollection.properties.instances.EntityDetail; +import org.apache.atlas.omrs.metadatacollection.properties.instances.InstanceType; +import org.apache.atlas.omrs.metadatacollection.properties.instances.Relationship; +import org.apache.atlas.omrs.metadatacollection.properties.typedefs.TypeDef; +import org.apache.atlas.omrs.metadatacollection.properties.typedefs.TypeDefCategory; + + +/** + * OMRSInstanceValidator provides method to validate entities and relationships match their type definition + * (TypeDef). + */ +public interface OMRSInstanceValidator +{ + /** + * Test that the supplied entity is valid. + * + * @param sourceName - source of the entity (used for logging) + * @param entity - entity to test + * @return boolean result + */ + boolean validEntity(String sourceName, + EntityDetail entity); + + + /** + * Test that the supplied relationship is valid. + * + * @param sourceName - source of the relationship (used for logging) + * @param relationship - relationship to test + * @return boolean result + */ + boolean validRelationship(String sourceName, + Relationship relationship); + + /** + * Verify that the identifiers for an instance are correct. + * + * @param sourceName - source of the instance (used for logging) + * @param typeDefGUID - unique identifier for the type. + * @param typeDefName - unique name for the type. + * @param category - expected category of the instance. + * @param instanceGUID - unique identifier for the instance. + * @return boolean indicating whether the identifiers are ok. + */ + boolean validInstanceId(String sourceName, + String typeDefGUID, + String typeDefName, + TypeDefCategory category, + String instanceGUID); +}
