http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/30711973/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java b/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java new file mode 100755 index 0000000..07ba7f3 --- /dev/null +++ b/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java @@ -0,0 +1,427 @@ +/** + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.services; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; +import org.apache.atlas.GraphTransaction; +import org.apache.atlas.MetadataException; +import org.apache.atlas.MetadataServiceClient; +import org.apache.atlas.ParamChecker; +import org.apache.atlas.classification.InterfaceAudience; +import org.apache.atlas.discovery.SearchIndexer; +import org.apache.atlas.listener.EntityChangeListener; +import org.apache.atlas.listener.TypesChangeListener; +import org.apache.atlas.repository.MetadataRepository; +import org.apache.atlas.repository.typestore.ITypeStore; +import org.apache.atlas.typesystem.ITypedReferenceableInstance; +import org.apache.atlas.typesystem.ITypedStruct; +import org.apache.atlas.typesystem.Referenceable; +import org.apache.atlas.typesystem.Struct; +import org.apache.atlas.typesystem.TypesDef; +import org.apache.atlas.typesystem.json.InstanceSerialization; +import org.apache.atlas.typesystem.json.TypesSerialization; +import org.apache.atlas.typesystem.types.AttributeDefinition; +import org.apache.atlas.typesystem.types.ClassType; +import org.apache.atlas.typesystem.types.DataTypes; +import org.apache.atlas.typesystem.types.EnumTypeDefinition; +import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition; +import org.apache.atlas.typesystem.types.IDataType; +import org.apache.atlas.typesystem.types.Multiplicity; +import org.apache.atlas.typesystem.types.StructTypeDefinition; +import org.apache.atlas.typesystem.types.TraitType; +import org.apache.atlas.typesystem.types.TypeSystem; +import org.apache.atlas.typesystem.types.TypeUtils; +import org.apache.atlas.typesystem.types.utils.TypesUtil; +import org.codehaus.jettison.json.JSONException; +import org.codehaus.jettison.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.inject.Inject; +import javax.inject.Singleton; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Simple wrapper over TypeSystem and MetadataRepository services with hooks + * for listening to changes to the repository. + */ +@Singleton +public class DefaultMetadataService implements MetadataService { + + private static final Logger LOG = + LoggerFactory.getLogger(DefaultMetadataService.class); + + private final Set<TypesChangeListener> typesChangeListeners = new LinkedHashSet<>(); + private final Set<EntityChangeListener> entityChangeListeners + = new LinkedHashSet<>(); + + private final TypeSystem typeSystem; + private final MetadataRepository repository; + private final ITypeStore typeStore; + + @Inject + DefaultMetadataService(MetadataRepository repository, + SearchIndexer searchIndexer, ITypeStore typeStore) throws MetadataException { + this.typeStore = typeStore; + this.typeSystem = TypeSystem.getInstance(); + this.repository = repository; + + registerListener(searchIndexer); + restoreTypeSystem(); + } + + private void restoreTypeSystem() { + LOG.info("Restoring type system from the store"); + try { + TypesDef typesDef = typeStore.restore(); + typeSystem.defineTypes(typesDef); + + // restore types before creating super types + createSuperTypes(); + + } catch (MetadataException e) { + throw new RuntimeException(e); + } + LOG.info("Restored type system from the store"); + } + + private static final AttributeDefinition NAME_ATTRIBUTE = + TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE); + private static final AttributeDefinition DESCRIPTION_ATTRIBUTE = + TypesUtil.createOptionalAttrDef("description", DataTypes.STRING_TYPE); + + @InterfaceAudience.Private + private void createSuperTypes() throws MetadataException { + if (typeSystem.isRegistered(MetadataServiceClient.DATA_SET_SUPER_TYPE)) { + return; // this is already registered + } + + HierarchicalTypeDefinition<ClassType> infraType = + TypesUtil.createClassTypeDef(MetadataServiceClient.INFRASTRUCTURE_SUPER_TYPE, + ImmutableList.<String>of(), NAME_ATTRIBUTE, DESCRIPTION_ATTRIBUTE); + + HierarchicalTypeDefinition<ClassType> datasetType = TypesUtil + .createClassTypeDef(MetadataServiceClient.DATA_SET_SUPER_TYPE, + ImmutableList.<String>of(), + NAME_ATTRIBUTE, DESCRIPTION_ATTRIBUTE); + + HierarchicalTypeDefinition<ClassType> processType = TypesUtil + .createClassTypeDef(MetadataServiceClient.PROCESS_SUPER_TYPE, ImmutableList.<String>of(), + NAME_ATTRIBUTE, DESCRIPTION_ATTRIBUTE, new AttributeDefinition("inputs", + DataTypes.arrayTypeName(MetadataServiceClient.DATA_SET_SUPER_TYPE), + Multiplicity.OPTIONAL, false, null), + new AttributeDefinition("outputs", + DataTypes.arrayTypeName(MetadataServiceClient.DATA_SET_SUPER_TYPE), + Multiplicity.OPTIONAL, false, null)); + + TypesDef typesDef = TypeUtils + .getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), + ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), + ImmutableList.of(infraType, datasetType, processType)); + createType(TypesSerialization.toJson(typesDef)); + } + + /** + * Creates a new type based on the type system to enable adding + * entities (instances for types). + * + * @param typeDefinition definition as json + * @return a unique id for this type + */ + @Override + @GraphTransaction + public JSONObject createType(String typeDefinition) throws MetadataException { + ParamChecker.notEmpty(typeDefinition, "type definition cannot be empty"); + + TypesDef typesDef; + try { + typesDef = TypesSerialization.fromJson(typeDefinition); + if(typesDef.isEmpty()) { + throw new MetadataException("Invalid type definition"); + } + } catch (Exception e) { + LOG.error("Unable to deserialize json={}", typeDefinition, e); + throw new IllegalArgumentException("Unable to deserialize json"); + } + + try { + final Map<String, IDataType> typesAdded = typeSystem.defineTypes(typesDef); + + try { + typeStore.store(typeSystem, ImmutableList.copyOf(typesAdded.keySet())); + onTypesAddedToRepo(typesAdded); + } catch(Throwable t) { + typeSystem.removeTypes(ImmutableList.copyOf(typesAdded.keySet())); + throw new MetadataException(t); + } + + return new JSONObject() {{ + put(MetadataServiceClient.TYPES, typesAdded.keySet()); + }}; + } catch (JSONException e) { + LOG.error("Unable to create response for types={}", typeDefinition, e); + throw new MetadataException("Unable to create response"); + } + } + + /** + * Return the definition for the given type. + * + * @param typeName name for this type, must be unique + * @return type definition as JSON + */ + @Override + public String getTypeDefinition(String typeName) throws MetadataException { + final IDataType dataType = typeSystem.getDataType(IDataType.class, typeName); + return TypesSerialization.toJson(typeSystem, dataType.getName()); + } + + /** + * Return the list of types in the repository. + * + * @return list of type names in the repository + */ + @Override + public List<String> getTypeNamesList() throws MetadataException { + return typeSystem.getTypeNames(); + } + + /** + * Return the list of trait type names in the type system. + * + * @return list of trait type names in the type system + */ + @Override + public List<String> getTypeNamesByCategory(DataTypes.TypeCategory typeCategory) throws MetadataException { + return typeSystem.getTypeNamesByCategory(typeCategory); + } + + /** + * Creates an entity, instance of the type. + * + * @param entityInstanceDefinition definition + * @return guid + */ + @Override + public String createEntity(String entityInstanceDefinition) throws MetadataException { + ParamChecker.notEmpty(entityInstanceDefinition, "Entity instance definition cannot be empty"); + + ITypedReferenceableInstance entityTypedInstance = + deserializeClassInstance(entityInstanceDefinition); + + final String guid = repository.createEntity(entityTypedInstance); + + onEntityAddedToRepo(entityTypedInstance); + return guid; + } + + private ITypedReferenceableInstance deserializeClassInstance( + String entityInstanceDefinition) throws MetadataException { + + final Referenceable entityInstance; + try { + entityInstance = InstanceSerialization.fromJsonReferenceable( + entityInstanceDefinition, true); + } catch (Exception e) { // exception from deserializer + LOG.error("Unable to deserialize json={}", entityInstanceDefinition, e); + throw new IllegalArgumentException("Unable to deserialize json"); + } + final String entityTypeName = entityInstance.getTypeName(); + ParamChecker.notEmpty(entityTypeName, "Entity type cannot be null"); + + ClassType entityType = typeSystem.getDataType(ClassType.class, entityTypeName); + return entityType.convert(entityInstance, Multiplicity.REQUIRED); + } + + /** + * Return the definition for the given guid. + * + * @param guid guid + * @return entity definition as JSON + */ + @Override + public String getEntityDefinition(String guid) throws MetadataException { + ParamChecker.notEmpty(guid, "guid cannot be null"); + + final ITypedReferenceableInstance instance = repository.getEntityDefinition(guid); + return InstanceSerialization.toJson(instance, true); + } + + /** + * Return the list of entity names for the given type in the repository. + * + * @param entityType type + * @return list of entity names for the given type in the repository + */ + @Override + public List<String> getEntityList(String entityType) throws MetadataException { + validateTypeExists(entityType); + + return repository.getEntityList(entityType); + } + + @Override + public void updateEntity(String guid, String property, String value) throws MetadataException { + ParamChecker.notEmpty(guid, "guid cannot be null"); + ParamChecker.notEmpty(property, "property cannot be null"); + ParamChecker.notEmpty(value, "property value cannot be null"); + + repository.updateEntity(guid, property, value); + } + + private void validateTypeExists(String entityType) throws MetadataException { + ParamChecker.notEmpty(entityType, "entity type cannot be null"); + + // verify if the type exists + if (!typeSystem.isRegistered(entityType)) { + throw new MetadataException("type is not defined for : " + entityType); + } + } + + /** + * Gets the list of trait names for a given entity represented by a guid. + * + * @param guid globally unique identifier for the entity + * @return a list of trait names for the given entity guid + * @throws MetadataException + */ + @Override + public List<String> getTraitNames(String guid) throws MetadataException { + ParamChecker.notEmpty(guid, "entity GUID cannot be null"); + return repository.getTraitNames(guid); + } + + /** + * Adds a new trait to an existing entity represented by a guid. + * + * @param guid globally unique identifier for the entity + * @param traitInstanceDefinition trait instance json that needs to be added to entity + * @throws MetadataException + */ + @Override + public void addTrait(String guid, + String traitInstanceDefinition) throws MetadataException { + ParamChecker.notEmpty(guid, "entity GUID cannot be null"); + ParamChecker.notEmpty(traitInstanceDefinition, "Trait instance cannot be null"); + + ITypedStruct traitInstance = deserializeTraitInstance(traitInstanceDefinition); + final String traitName = traitInstance.getTypeName(); + + // ensure trait type is already registered with the TS + Preconditions.checkArgument(typeSystem.isRegistered(traitName), + "trait=%s should be defined in type system before it can be added", traitName); + // ensure trait is not already defined + Preconditions.checkArgument(!getTraitNames(guid).contains(traitName), + "trait=%s is already defined for entity=%s", traitName, guid); + + repository.addTrait(guid, traitInstance); + + onTraitAddedToEntity(guid, traitName); + } + + private ITypedStruct deserializeTraitInstance(String traitInstanceDefinition) + throws MetadataException { + + try { + Struct traitInstance = InstanceSerialization.fromJsonStruct( + traitInstanceDefinition, true); + final String entityTypeName = traitInstance.getTypeName(); + ParamChecker.notEmpty(entityTypeName, "entity type cannot be null"); + + TraitType traitType = typeSystem.getDataType(TraitType.class, entityTypeName); + return traitType.convert( + traitInstance, Multiplicity.REQUIRED); + } catch (Exception e) { + throw new MetadataException("Error deserializing trait instance", e); + } + } + + /** + * Deletes a given trait from an existing entity represented by a guid. + * + * @param guid globally unique identifier for the entity + * @param traitNameToBeDeleted name of the trait + * @throws MetadataException + */ + @Override + public void deleteTrait(String guid, + String traitNameToBeDeleted) throws MetadataException { + ParamChecker.notEmpty(guid, "entity GUID cannot be null"); + ParamChecker.notEmpty(traitNameToBeDeleted, "Trait name cannot be null"); + + // ensure trait type is already registered with the TS + Preconditions.checkArgument(typeSystem.isRegistered(traitNameToBeDeleted), + "trait=%s should be defined in type system before it can be deleted", + traitNameToBeDeleted); + + repository.deleteTrait(guid, traitNameToBeDeleted); + + onTraitDeletedFromEntity(guid, traitNameToBeDeleted); + } + + private void onTypesAddedToRepo(Map<String, IDataType> typesAdded) throws MetadataException { + for (TypesChangeListener listener : typesChangeListeners) { + for (Map.Entry<String, IDataType> entry : typesAdded.entrySet()) { + listener.onAdd(entry.getKey(), entry.getValue()); + } + } + } + + public void registerListener(TypesChangeListener listener) { + typesChangeListeners.add(listener); + } + + public void unregisterListener(TypesChangeListener listener) { + typesChangeListeners.remove(listener); + } + + private void onEntityAddedToRepo(ITypedReferenceableInstance typedInstance) + throws MetadataException { + + for (EntityChangeListener listener : entityChangeListeners) { + listener.onEntityAdded(typedInstance); + } + } + + private void onTraitAddedToEntity(String typeName, + String traitName) throws MetadataException { + for (EntityChangeListener listener : entityChangeListeners) { + listener.onTraitAdded(typeName, traitName); + } + } + + private void onTraitDeletedFromEntity(String typeName, + String traitName) throws MetadataException { + for (EntityChangeListener listener : entityChangeListeners) { + listener.onTraitDeleted(typeName, traitName); + } + } + + public void registerListener(EntityChangeListener listener) { + entityChangeListeners.add(listener); + } + + public void unregisterListener(EntityChangeListener listener) { + entityChangeListeners.remove(listener); + } +}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/30711973/repository/src/main/java/org/apache/atlas/services/MetadataService.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/services/MetadataService.java b/repository/src/main/java/org/apache/atlas/services/MetadataService.java new file mode 100755 index 0000000..42e86da --- /dev/null +++ b/repository/src/main/java/org/apache/atlas/services/MetadataService.java @@ -0,0 +1,125 @@ +/** + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.services; + +import org.apache.atlas.MetadataException; +import org.apache.atlas.typesystem.types.DataTypes; +import org.codehaus.jettison.json.JSONObject; + +import java.util.List; + +/** + * Metadata service. + */ +public interface MetadataService { + + /** + * Creates a new type based on the type system to enable adding + * entities (instances for types). + * + * @param typeDefinition definition as json + * @return a unique id for this type + */ + JSONObject createType(String typeDefinition) throws MetadataException; + + /** + * Return the definition for the given type. + * + * @param typeName name for this type, must be unique + * @return type definition as JSON + */ + String getTypeDefinition(String typeName) throws MetadataException; + + /** + * Return the list of types in the type system. + * + * @return list of type names in the type system + */ + List<String> getTypeNamesList() throws MetadataException; + + /** + * Return the list of trait type names in the type system. + * + * @return list of trait type names in the type system + */ + List<String> getTypeNamesByCategory(DataTypes.TypeCategory typeCategory) throws MetadataException; + + /** + * Creates an entity, instance of the type. + * + * @param entityDefinition definition + * @return guid + */ + String createEntity(String entityDefinition) throws MetadataException; + + /** + * Return the definition for the given guid. + * + * @param guid guid + * @return entity definition as JSON + */ + String getEntityDefinition(String guid) throws MetadataException; + + /** + * Return the list of entity names for the given type in the repository. + * + * @param entityType type + * @return list of entity names for the given type in the repository + */ + List<String> getEntityList(String entityType) throws MetadataException; + + /** + * Adds the property to the given entity id(guid). + * + * @param guid entity id + * @param property property name + * @param value property value + */ + void updateEntity(String guid, String property, String value) throws MetadataException; + + // Trait management functions + /** + * Gets the list of trait names for a given entity represented by a guid. + * + * @param guid globally unique identifier for the entity + * @return a list of trait names for the given entity guid + * @throws MetadataException + */ + List<String> getTraitNames(String guid) throws MetadataException; + + /** + * Adds a new trait to an existing entity represented by a guid. + * + * @param guid globally unique identifier for the entity + * @param traitInstanceDefinition trait instance that needs to be added to entity + * @throws MetadataException + */ + void addTrait(String guid, + String traitInstanceDefinition) throws MetadataException; + + /** + * Deletes a given trait from an existing entity represented by a guid. + * + * @param guid globally unique identifier for the entity + * @param traitNameToBeDeleted name of the trait + * @throws MetadataException + */ + void deleteTrait(String guid, + String traitNameToBeDeleted) throws MetadataException; +} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/30711973/repository/src/main/java/org/apache/hadoop/metadata/GraphTransaction.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/hadoop/metadata/GraphTransaction.java b/repository/src/main/java/org/apache/hadoop/metadata/GraphTransaction.java deleted file mode 100644 index e4a099f..0000000 --- a/repository/src/main/java/org/apache/hadoop/metadata/GraphTransaction.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.hadoop.metadata; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) -public @interface GraphTransaction {} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/30711973/repository/src/main/java/org/apache/hadoop/metadata/GraphTransactionInterceptor.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/hadoop/metadata/GraphTransactionInterceptor.java b/repository/src/main/java/org/apache/hadoop/metadata/GraphTransactionInterceptor.java deleted file mode 100644 index 1e25867..0000000 --- a/repository/src/main/java/org/apache/hadoop/metadata/GraphTransactionInterceptor.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.hadoop.metadata; - -import com.google.inject.Inject; -import com.thinkaurelius.titan.core.TitanGraph; -import org.aopalliance.intercept.MethodInterceptor; -import org.aopalliance.intercept.MethodInvocation; -import org.apache.hadoop.metadata.repository.graph.GraphProvider; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class GraphTransactionInterceptor implements MethodInterceptor { - private static final Logger LOG = LoggerFactory.getLogger(GraphTransactionInterceptor.class); - private TitanGraph titanGraph; - - @Inject - GraphProvider<TitanGraph> graphProvider; - - public Object invoke(MethodInvocation invocation) throws Throwable { - if (titanGraph == null) { - titanGraph = graphProvider.get(); - } - - try { - Object response = invocation.proceed(); - titanGraph.commit(); - LOG.debug("graph commit"); - return response; - } catch (Throwable t){ - titanGraph.rollback(); - LOG.debug("graph rollback"); - throw t; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/30711973/repository/src/main/java/org/apache/hadoop/metadata/RepositoryMetadataModule.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/hadoop/metadata/RepositoryMetadataModule.java b/repository/src/main/java/org/apache/hadoop/metadata/RepositoryMetadataModule.java deleted file mode 100755 index ab870e3..0000000 --- a/repository/src/main/java/org/apache/hadoop/metadata/RepositoryMetadataModule.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.hadoop.metadata; - -import com.google.inject.Scopes; -import com.google.inject.matcher.Matchers; -import com.google.inject.throwingproviders.ThrowingProviderBinder; -import com.thinkaurelius.titan.core.TitanGraph; -import org.aopalliance.intercept.MethodInterceptor; -import org.apache.hadoop.metadata.discovery.DiscoveryService; -import org.apache.hadoop.metadata.discovery.HiveLineageService; -import org.apache.hadoop.metadata.discovery.LineageService; -import org.apache.hadoop.metadata.discovery.SearchIndexer; -import org.apache.hadoop.metadata.discovery.graph.GraphBackedDiscoveryService; -import org.apache.hadoop.metadata.repository.MetadataRepository; -import org.apache.hadoop.metadata.repository.graph.GraphBackedMetadataRepository; -import org.apache.hadoop.metadata.repository.graph.GraphBackedSearchIndexer; -import org.apache.hadoop.metadata.repository.graph.GraphProvider; -import org.apache.hadoop.metadata.repository.graph.TitanGraphProvider; -import org.apache.hadoop.metadata.repository.typestore.GraphBackedTypeStore; -import org.apache.hadoop.metadata.repository.typestore.ITypeStore; -import org.apache.hadoop.metadata.services.DefaultMetadataService; -import org.apache.hadoop.metadata.services.MetadataService; - -/** - * Guice module for Repository module. - */ -public class RepositoryMetadataModule extends com.google.inject.AbstractModule { - @Override - protected void configure() { - // special wiring for Titan Graph - ThrowingProviderBinder.create(binder()) - .bind(GraphProvider.class, TitanGraph.class) - .to(TitanGraphProvider.class) - .asEagerSingleton(); - - // allow for dynamic binding of the metadata repo & graph service - - // bind the MetadataRepositoryService interface to an implementation - bind(MetadataRepository.class).to(GraphBackedMetadataRepository.class).asEagerSingleton(); - - // bind the ITypeStore interface to an implementation - bind(ITypeStore.class).to(GraphBackedTypeStore.class).asEagerSingleton(); - - // bind the GraphService interface to an implementation - // bind(GraphService.class).to(graphServiceClass); - - // bind the MetadataService interface to an implementation - bind(MetadataService.class).to(DefaultMetadataService.class).asEagerSingleton(); - - // bind the DiscoveryService interface to an implementation - bind(DiscoveryService.class).to(GraphBackedDiscoveryService.class).asEagerSingleton(); - - bind(SearchIndexer.class).to(GraphBackedSearchIndexer.class).asEagerSingleton(); - - bind(LineageService.class).to(HiveLineageService.class).asEagerSingleton(); - - MethodInterceptor interceptor = new GraphTransactionInterceptor(); - requestInjection(interceptor); - bindInterceptor(Matchers.any(), Matchers.annotatedWith(GraphTransaction.class), interceptor); - } -} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/30711973/repository/src/main/java/org/apache/hadoop/metadata/discovery/DiscoveryException.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/hadoop/metadata/discovery/DiscoveryException.java b/repository/src/main/java/org/apache/hadoop/metadata/discovery/DiscoveryException.java deleted file mode 100755 index c93cac0..0000000 --- a/repository/src/main/java/org/apache/hadoop/metadata/discovery/DiscoveryException.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.hadoop.metadata.discovery; - -import org.apache.hadoop.metadata.MetadataException; - -import java.security.PrivilegedActionException; - -public class DiscoveryException extends MetadataException { - - /** - * Constructs a new exception with the specified detail message. The - * cause is not initialized, and may subsequently be initialized by - * a call to {@link #initCause}. - * - * @param message the detail message. The detail message is saved for - * later retrieval by the {@link #getMessage()} method. - */ - public DiscoveryException(String message) { - super(message); - } - - /** - * Constructs a new exception with the specified detail message and - * cause. <p>Note that the detail message associated with - * {@code cause} is <i>not</i> automatically incorporated in - * this exception's detail message. - * - * @param message the detail message (which is saved for later retrieval - * by the {@link #getMessage()} method). - * @param cause the cause (which is saved for later retrieval by the - * {@link #getCause()} method). (A <tt>null</tt> value is - * permitted, and indicates that the cause is nonexistent or - * unknown.) - * @since 1.4 - */ - public DiscoveryException(String message, Throwable cause) { - super(message, cause); - } - - /** - * Constructs a new exception with the specified cause and a detail - * message of <tt>(cause==null ? null : cause.toString())</tt> (which - * typically contains the class and detail message of <tt>cause</tt>). - * This constructor is useful for exceptions that are little more than - * wrappers for other throwables (for example, {@link - * PrivilegedActionException}). - * - * @param cause the cause (which is saved for later retrieval by the - * {@link #getCause()} method). (A <tt>null</tt> value is - * permitted, and indicates that the cause is nonexistent or - * unknown.) - * @since 1.4 - */ - public DiscoveryException(Throwable cause) { - super(cause); - } -} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/30711973/repository/src/main/java/org/apache/hadoop/metadata/discovery/DiscoveryService.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/hadoop/metadata/discovery/DiscoveryService.java b/repository/src/main/java/org/apache/hadoop/metadata/discovery/DiscoveryService.java deleted file mode 100755 index 0952436..0000000 --- a/repository/src/main/java/org/apache/hadoop/metadata/discovery/DiscoveryService.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.hadoop.metadata.discovery; - -import org.apache.hadoop.metadata.MetadataException; - -import java.util.List; -import java.util.Map; - -/** - * Metadata discovery service. - */ -public interface DiscoveryService { - - /** - * Full text search - */ - String searchByFullText(String query) throws DiscoveryException; - - /** - * Search using query DSL. - * - * @param dslQuery query in DSL format. - * @return JSON representing the type and results. - */ - String searchByDSL(String dslQuery) throws DiscoveryException; - - /** - * Assumes the User is familiar with the persistence structure of the Repository. - * The given query is run uninterpreted against the underlying Graph Store. - * The results are returned as a List of Rows. each row is a Map of Key,Value pairs. - * - * @param gremlinQuery query in gremlin dsl format - * @return List of Maps - * @throws org.apache.hadoop.metadata.discovery.DiscoveryException - */ - List<Map<String, String>> searchByGremlin(String gremlinQuery) throws DiscoveryException; -} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/30711973/repository/src/main/java/org/apache/hadoop/metadata/discovery/HiveLineageService.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/hadoop/metadata/discovery/HiveLineageService.java b/repository/src/main/java/org/apache/hadoop/metadata/discovery/HiveLineageService.java deleted file mode 100644 index 53d042f..0000000 --- a/repository/src/main/java/org/apache/hadoop/metadata/discovery/HiveLineageService.java +++ /dev/null @@ -1,229 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.hadoop.metadata.discovery; - -import com.thinkaurelius.titan.core.TitanGraph; -import org.apache.commons.configuration.PropertiesConfiguration; -import org.apache.hadoop.metadata.GraphTransaction; -import org.apache.hadoop.metadata.MetadataException; -import org.apache.hadoop.metadata.ParamChecker; -import org.apache.hadoop.metadata.PropertiesUtil; -import org.apache.hadoop.metadata.discovery.graph.DefaultGraphPersistenceStrategy; -import org.apache.hadoop.metadata.discovery.graph.GraphBackedDiscoveryService; -import org.apache.hadoop.metadata.query.Expressions; -import org.apache.hadoop.metadata.query.GremlinQueryResult; -import org.apache.hadoop.metadata.query.HiveLineageQuery; -import org.apache.hadoop.metadata.query.HiveWhereUsedQuery; -import org.apache.hadoop.metadata.repository.EntityNotFoundException; -import org.apache.hadoop.metadata.repository.MetadataRepository; -import org.apache.hadoop.metadata.repository.graph.GraphProvider; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import scala.Option; -import scala.Some; -import scala.collection.immutable.List; - -import javax.inject.Inject; -import javax.inject.Singleton; - -/** - * Hive implementation of Lineage service interface. - */ -@Singleton -public class HiveLineageService implements LineageService { - - private static final Logger LOG = LoggerFactory.getLogger(HiveLineageService.class); - - private static final Option<List<String>> SELECT_ATTRIBUTES = - Some.<List<String>>apply(List.<String>fromArray(new String[]{"name"})); - - private static final String HIVE_TABLE_TYPE_NAME; - private static final String HIVE_PROCESS_TYPE_NAME; - private static final String HIVE_PROCESS_INPUT_ATTRIBUTE_NAME; - private static final String HIVE_PROCESS_OUTPUT_ATTRIBUTE_NAME; - - private static final String HIVE_TABLE_SCHEMA_QUERY; - private static final String HIVE_TABLE_EXISTS_QUERY; - - static { - // todo - externalize this using type system - dog food - try { - PropertiesConfiguration conf = PropertiesUtil.getApplicationProperties(); - HIVE_TABLE_TYPE_NAME = - conf.getString("metadata.lineage.hive.table.type.name", "DataSet"); - HIVE_PROCESS_TYPE_NAME = - conf.getString("metadata.lineage.hive.process.type.name", "Process"); - HIVE_PROCESS_INPUT_ATTRIBUTE_NAME = - conf.getString("metadata.lineage.hive.process.inputs.name", "inputs"); - HIVE_PROCESS_OUTPUT_ATTRIBUTE_NAME = - conf.getString("metadata.lineage.hive.process.outputs.name", "outputs"); - - HIVE_TABLE_SCHEMA_QUERY = conf.getString( - "metadata.lineage.hive.table.schema.query", - "hive_table where name=\"%s\", columns"); - HIVE_TABLE_EXISTS_QUERY = conf.getString( - "metadata.lineage.hive.table.exists.query", - "from hive_table where name=\"%s\""); - } catch (MetadataException e) { - throw new RuntimeException(e); - } - } - - - private final TitanGraph titanGraph; - private final DefaultGraphPersistenceStrategy graphPersistenceStrategy; - private final GraphBackedDiscoveryService discoveryService; - - @Inject - HiveLineageService(GraphProvider<TitanGraph> graphProvider, - MetadataRepository metadataRepository, - GraphBackedDiscoveryService discoveryService) throws DiscoveryException { - this.titanGraph = graphProvider.get(); - this.graphPersistenceStrategy = new DefaultGraphPersistenceStrategy(metadataRepository); - this.discoveryService = discoveryService; - } - - /** - * Return the lineage outputs for the given tableName. - * - * @param tableName tableName - * @return Lineage Outputs as JSON - */ - @Override - @GraphTransaction - public String getOutputs(String tableName) throws MetadataException { - LOG.info("Fetching lineage outputs for tableName={}", tableName); - ParamChecker.notEmpty(tableName, "table name cannot be null"); - validateTableExists(tableName); - - HiveWhereUsedQuery outputsQuery = new HiveWhereUsedQuery( - HIVE_TABLE_TYPE_NAME, tableName, HIVE_PROCESS_TYPE_NAME, - HIVE_PROCESS_INPUT_ATTRIBUTE_NAME, HIVE_PROCESS_OUTPUT_ATTRIBUTE_NAME, - Option.empty(), SELECT_ATTRIBUTES, true, - graphPersistenceStrategy, titanGraph); - - Expressions.Expression expression = outputsQuery.expr(); - LOG.debug("Expression is [" + expression.toString() +"]"); - try { - return discoveryService.evaluate(expression).toJson(); - } catch (Exception e) { // unable to catch ExpressionException - throw new DiscoveryException("Invalid expression [" + expression.toString() + "]", e); - } - } - - /** - * Return the lineage outputs graph for the given tableName. - * - * @param tableName tableName - * @return Outputs Graph as JSON - */ - @Override - @GraphTransaction - public String getOutputsGraph(String tableName) throws MetadataException { - LOG.info("Fetching lineage outputs graph for tableName={}", tableName); - ParamChecker.notEmpty(tableName, "table name cannot be null"); - validateTableExists(tableName); - - HiveWhereUsedQuery outputsQuery = new HiveWhereUsedQuery( - HIVE_TABLE_TYPE_NAME, tableName, HIVE_PROCESS_TYPE_NAME, - HIVE_PROCESS_INPUT_ATTRIBUTE_NAME, HIVE_PROCESS_OUTPUT_ATTRIBUTE_NAME, - Option.empty(), SELECT_ATTRIBUTES, true, - graphPersistenceStrategy, titanGraph); - return outputsQuery.graph().toInstanceJson(); - } - - /** - * Return the lineage inputs for the given tableName. - * - * @param tableName tableName - * @return Lineage Inputs as JSON - */ - @Override - @GraphTransaction - public String getInputs(String tableName) throws MetadataException { - LOG.info("Fetching lineage inputs for tableName={}", tableName); - ParamChecker.notEmpty(tableName, "table name cannot be null"); - validateTableExists(tableName); - - HiveLineageQuery inputsQuery = new HiveLineageQuery( - HIVE_TABLE_TYPE_NAME, tableName, HIVE_PROCESS_TYPE_NAME, - HIVE_PROCESS_INPUT_ATTRIBUTE_NAME, HIVE_PROCESS_OUTPUT_ATTRIBUTE_NAME, - Option.empty(), SELECT_ATTRIBUTES, true, - graphPersistenceStrategy, titanGraph); - - Expressions.Expression expression = inputsQuery.expr(); - LOG.debug("Expression is [" + expression.toString() +"]"); - try { - return discoveryService.evaluate(expression).toJson(); - } catch (Exception e) { // unable to catch ExpressionException - throw new DiscoveryException("Invalid expression [" + expression.toString() + "]", e); - } - } - - /** - * Return the lineage inputs graph for the given tableName. - * - * @param tableName tableName - * @return Inputs Graph as JSON - */ - @Override - @GraphTransaction - public String getInputsGraph(String tableName) throws MetadataException { - LOG.info("Fetching lineage inputs graph for tableName={}", tableName); - ParamChecker.notEmpty(tableName, "table name cannot be null"); - validateTableExists(tableName); - - HiveLineageQuery inputsQuery = new HiveLineageQuery( - HIVE_TABLE_TYPE_NAME, tableName, HIVE_PROCESS_TYPE_NAME, - HIVE_PROCESS_INPUT_ATTRIBUTE_NAME, HIVE_PROCESS_OUTPUT_ATTRIBUTE_NAME, - Option.empty(), SELECT_ATTRIBUTES, true, - graphPersistenceStrategy, titanGraph); - return inputsQuery.graph().toInstanceJson(); - } - - /** - * Return the schema for the given tableName. - * - * @param tableName tableName - * @return Schema as JSON - */ - @Override - @GraphTransaction - public String getSchema(String tableName) throws MetadataException { - LOG.info("Fetching schema for tableName={}", tableName); - ParamChecker.notEmpty(tableName, "table name cannot be null"); - validateTableExists(tableName); - - final String schemaQuery = String.format(HIVE_TABLE_SCHEMA_QUERY, tableName); - return discoveryService.searchByDSL(schemaQuery); - } - - /** - * Validate if indeed this is a table type and exists. - * - * @param tableName table name - */ - private void validateTableExists(String tableName) throws MetadataException { - final String tableExistsQuery = String.format(HIVE_TABLE_EXISTS_QUERY, tableName); - GremlinQueryResult queryResult = discoveryService.evaluate(tableExistsQuery); - if (!(queryResult.rows().length() > 0)) { - throw new EntityNotFoundException(tableName + " does not exist"); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/30711973/repository/src/main/java/org/apache/hadoop/metadata/discovery/LineageService.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/hadoop/metadata/discovery/LineageService.java b/repository/src/main/java/org/apache/hadoop/metadata/discovery/LineageService.java deleted file mode 100644 index 1bf2b53..0000000 --- a/repository/src/main/java/org/apache/hadoop/metadata/discovery/LineageService.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.hadoop.metadata.discovery; - -import org.apache.hadoop.metadata.MetadataException; - -/** - * Lineage service interface. - */ -public interface LineageService { - - /** - * Return the lineage outputs for the given tableName. - * - * @param tableName tableName - * @return Outputs as JSON - */ - String getOutputs(String tableName) throws MetadataException; - - /** - * Return the lineage outputs graph for the given tableName. - * - * @param tableName tableName - * @return Outputs Graph as JSON - */ - String getOutputsGraph(String tableName) throws MetadataException; - - /** - * Return the lineage inputs for the given tableName. - * - * @param tableName tableName - * @return Inputs as JSON - */ - String getInputs(String tableName) throws MetadataException; - - /** - * Return the lineage inputs graph for the given tableName. - * - * @param tableName tableName - * @return Inputs Graph as JSON - */ - String getInputsGraph(String tableName) throws MetadataException; - - /** - * Return the schema for the given tableName. - * - * @param tableName tableName - * @return Schema as JSON - */ - String getSchema(String tableName) throws MetadataException; -} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/30711973/repository/src/main/java/org/apache/hadoop/metadata/discovery/SearchIndexer.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/hadoop/metadata/discovery/SearchIndexer.java b/repository/src/main/java/org/apache/hadoop/metadata/discovery/SearchIndexer.java deleted file mode 100755 index 9921038..0000000 --- a/repository/src/main/java/org/apache/hadoop/metadata/discovery/SearchIndexer.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.hadoop.metadata.discovery; - -import org.apache.hadoop.metadata.listener.TypesChangeListener; - - -/** - * Interface for indexing types. - */ -public interface SearchIndexer extends TypesChangeListener { - -} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/30711973/repository/src/main/java/org/apache/hadoop/metadata/discovery/graph/DefaultGraphPersistenceStrategy.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/hadoop/metadata/discovery/graph/DefaultGraphPersistenceStrategy.java b/repository/src/main/java/org/apache/hadoop/metadata/discovery/graph/DefaultGraphPersistenceStrategy.java deleted file mode 100755 index 1e34abd..0000000 --- a/repository/src/main/java/org/apache/hadoop/metadata/discovery/graph/DefaultGraphPersistenceStrategy.java +++ /dev/null @@ -1,203 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.hadoop.metadata.discovery.graph; - -import com.thinkaurelius.titan.core.TitanVertex; -import org.apache.hadoop.metadata.MetadataException; -import org.apache.hadoop.metadata.query.*; -import org.apache.hadoop.metadata.query.TypeUtils; -import org.apache.hadoop.metadata.repository.MetadataRepository; -import org.apache.hadoop.metadata.repository.Constants; -import org.apache.hadoop.metadata.repository.graph.GraphBackedMetadataRepository; -import org.apache.hadoop.metadata.typesystem.ITypedReferenceableInstance; -import org.apache.hadoop.metadata.typesystem.ITypedStruct; -import org.apache.hadoop.metadata.typesystem.persistence.Id; -import org.apache.hadoop.metadata.typesystem.types.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import scala.collection.Traversable; - -import java.util.List; - -/** - * Default implementation of GraphPersistenceStrategy. - */ -public class DefaultGraphPersistenceStrategy implements GraphPersistenceStrategies { - - private static final Logger LOG = LoggerFactory - .getLogger(DefaultGraphPersistenceStrategy.class); - - private final GraphBackedMetadataRepository metadataRepository; - - public DefaultGraphPersistenceStrategy(MetadataRepository metadataRepository) { - this.metadataRepository = (GraphBackedMetadataRepository) metadataRepository; - } - - @Override - public String typeAttributeName() { - return metadataRepository.getTypeAttributeName(); - } - - @Override - public String superTypeAttributeName() { - return metadataRepository.getSuperTypeAttributeName(); - } - - @Override - public String edgeLabel(IDataType<?> dataType, AttributeInfo aInfo) { - return metadataRepository.getEdgeLabel(dataType, aInfo); - } - - @Override - public String traitLabel(IDataType<?> dataType, String traitName) { - return metadataRepository.getTraitLabel(dataType, traitName); - } - - @Override - public String fieldNameInVertex(IDataType<?> dataType, AttributeInfo aInfo) { - try { - return metadataRepository.getFieldNameInVertex(dataType, aInfo); - } catch (MetadataException e) { - throw new RuntimeException(e); - } - } - - @Override - public List<String> traitNames(TitanVertex vertex) { - return metadataRepository.getTraitNames(vertex); - } - - @Override - public String fieldPrefixInSelect() { - return "it"; - } - - @Override - public Id getIdFromVertex(String dataTypeName, TitanVertex vertex) { - return metadataRepository.getIdFromVertex(dataTypeName, vertex); - } - - @Override - public <U> U constructInstance(IDataType<U> dataType, Object value) { - try { - switch (dataType.getTypeCategory()) { - case PRIMITIVE: - case ENUM: - return dataType.convert(value, Multiplicity.OPTIONAL); - - case ARRAY: - // todo - break; - - case MAP: - // todo - break; - - case STRUCT: - TitanVertex structVertex = (TitanVertex) value; - StructType structType = (StructType) dataType; - ITypedStruct structInstance = structType.createInstance(); - - TypeSystem.IdType idType = TypeSystem.getInstance().getIdType(); - - if (dataType.getName().equals(idType.getName())) { - structInstance.set(idType.typeNameAttrName(), - structVertex.getProperty(typeAttributeName())); - structInstance.set(idType.idAttrName(), - structVertex.getProperty(idAttributeName())); - - } else { - metadataRepository.getGraphToInstanceMapper().mapVertexToInstance( - structVertex, structInstance, structType.fieldMapping().fields); - } - return dataType.convert(structInstance, Multiplicity.OPTIONAL); - - case TRAIT: - TitanVertex traitVertex = (TitanVertex) value; - TraitType traitType = (TraitType) dataType; - ITypedStruct traitInstance = traitType.createInstance(); - // todo - this is not right, we should load the Instance associated with this - // trait. for now just loading the trait struct. - // metadataRepository.getGraphToInstanceMapper().mapVertexToTraitInstance( - // traitVertex, dataType.getName(), , traitType, traitInstance); - metadataRepository.getGraphToInstanceMapper().mapVertexToInstance( - traitVertex, traitInstance, traitType.fieldMapping().fields); - break; - - case CLASS: - TitanVertex classVertex = (TitanVertex) value; - ITypedReferenceableInstance classInstance = - metadataRepository.getGraphToInstanceMapper().mapGraphToTypedInstance( - classVertex.<String>getProperty(Constants.GUID_PROPERTY_KEY), - classVertex); - return dataType.convert(classInstance, Multiplicity.OPTIONAL); - - default: - throw new UnsupportedOperationException( - "Load for type " + dataType + "is not supported"); - } - } catch (MetadataException e) { - LOG.error("error while constructing an instance", e); - } - - return null; - } - - @Override - public String edgeLabel(TypeUtils.FieldInfo fInfo) { - return fInfo.reverseDataType() == null - ? edgeLabel(fInfo.dataType(), fInfo.attrInfo()) - : edgeLabel(fInfo.reverseDataType(), fInfo.attrInfo()); - } - - @Override - public String gremlinCompOp(Expressions.ComparisonExpression op) { - return GraphPersistenceStrategies$class.gremlinCompOp(this, op); - } - - @Override - public String loopObjectExpression(IDataType<?> dataType) { - return GraphPersistenceStrategies$class.loopObjectExpression(this, dataType); - } - - @Override - public String instanceToTraitEdgeDirection() { return "out"; } - - @Override - public String traitToInstanceEdgeDirection() { return "in"; } - - @Override - public String idAttributeName() { return metadataRepository.getIdAttributeName(); } - - @Override - public scala.collection.Seq<String> typeTestExpression(String typeName, IntSequence intSeq) { - return GraphPersistenceStrategies$class.typeTestExpression(this, typeName, intSeq); - } - - @Override - public boolean collectTypeInstancesIntoVar() { - return GraphPersistenceStrategies$class.collectTypeInstancesIntoVar(this); - } - - @Override - public boolean addGraphVertexPrefix(scala.collection.Traversable<String> preStatements) { - return GraphPersistenceStrategies$class.addGraphVertexPrefix(this, preStatements); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/30711973/repository/src/main/java/org/apache/hadoop/metadata/discovery/graph/GraphBackedDiscoveryService.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/hadoop/metadata/discovery/graph/GraphBackedDiscoveryService.java b/repository/src/main/java/org/apache/hadoop/metadata/discovery/graph/GraphBackedDiscoveryService.java deleted file mode 100755 index 37cb835..0000000 --- a/repository/src/main/java/org/apache/hadoop/metadata/discovery/graph/GraphBackedDiscoveryService.java +++ /dev/null @@ -1,219 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.hadoop.metadata.discovery.graph; - -import com.thinkaurelius.titan.core.TitanGraph; -import com.thinkaurelius.titan.core.TitanIndexQuery; -import com.thinkaurelius.titan.core.TitanProperty; -import com.thinkaurelius.titan.core.TitanVertex; -import com.tinkerpop.blueprints.Vertex; -import org.apache.hadoop.metadata.GraphTransaction; -import org.apache.hadoop.metadata.MetadataServiceClient; -import org.apache.hadoop.metadata.discovery.DiscoveryException; -import org.apache.hadoop.metadata.discovery.DiscoveryService; -import org.apache.hadoop.metadata.query.Expressions; -import org.apache.hadoop.metadata.query.GremlinEvaluator; -import org.apache.hadoop.metadata.query.GremlinQuery; -import org.apache.hadoop.metadata.query.GremlinQueryResult; -import org.apache.hadoop.metadata.query.GremlinTranslator; -import org.apache.hadoop.metadata.query.QueryParser; -import org.apache.hadoop.metadata.query.QueryProcessor; -import org.apache.hadoop.metadata.repository.Constants; -import org.apache.hadoop.metadata.repository.MetadataRepository; -import org.apache.hadoop.metadata.repository.graph.GraphProvider; -import org.codehaus.jettison.json.JSONArray; -import org.codehaus.jettison.json.JSONException; -import org.codehaus.jettison.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import scala.util.Either; -import scala.util.parsing.combinator.Parsers; - -import javax.inject.Inject; -import javax.inject.Singleton; -import javax.script.Bindings; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; -import javax.script.ScriptException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -/** - * Graph backed implementation of Search. - */ -@Singleton -public class GraphBackedDiscoveryService implements DiscoveryService { - - private static final Logger LOG = LoggerFactory.getLogger(GraphBackedDiscoveryService.class); - - private final TitanGraph titanGraph; - private final DefaultGraphPersistenceStrategy graphPersistenceStrategy; - - public final static String SCORE = "score"; - - @Inject - GraphBackedDiscoveryService(GraphProvider<TitanGraph> graphProvider, - MetadataRepository metadataRepository) throws DiscoveryException { - this.titanGraph = graphProvider.get(); - this.graphPersistenceStrategy = new DefaultGraphPersistenceStrategy(metadataRepository); - } - - //Refer http://s3.thinkaurelius.com/docs/titan/0.5.4/index-backends.html for indexed query - //http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query - // .html#query-string-syntax for query syntax - @Override - @GraphTransaction - public String searchByFullText(String query) throws DiscoveryException { - String graphQuery = String.format("v.%s:(%s)", Constants.ENTITY_TEXT_PROPERTY_KEY, query); - LOG.debug("Full text query: {}", graphQuery); - Iterator<TitanIndexQuery.Result<Vertex>> results = - titanGraph.indexQuery(Constants.FULLTEXT_INDEX, graphQuery).vertices().iterator(); - JSONArray response = new JSONArray(); - - while (results.hasNext()) { - TitanIndexQuery.Result<Vertex> result = results.next(); - Vertex vertex = result.getElement(); - - JSONObject row = new JSONObject(); - String guid = vertex.getProperty(Constants.GUID_PROPERTY_KEY); - if (guid != null) { //Filter non-class entities - try { - row.put("guid", guid); - row.put(MetadataServiceClient.TYPENAME, vertex.<String>getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY)); - row.put(SCORE, result.getScore()); - } catch (JSONException e) { - LOG.error("Unable to create response", e); - throw new DiscoveryException("Unable to create response"); - } - - response.put(row); - } - } - return response.toString(); - } - - /** - * Search using query DSL. - * - * @param dslQuery query in DSL format. - * @return JSON representing the type and results. - */ - @Override - @GraphTransaction - public String searchByDSL(String dslQuery) throws DiscoveryException { - LOG.info("Executing dsl query={}", dslQuery); - GremlinQueryResult queryResult = evaluate(dslQuery); - return queryResult.toJson(); - } - - public GremlinQueryResult evaluate(String dslQuery) throws DiscoveryException { - LOG.info("Executing dsl query={}", dslQuery); - try { - QueryParser queryParser = new QueryParser(); - Either<Parsers.NoSuccess, Expressions.Expression> either = queryParser.apply(dslQuery); - if (either.isRight()) { - Expressions.Expression expression = either.right().get(); - return evaluate(expression); - } else { - throw new DiscoveryException("Invalid expression : " + dslQuery + ". " + either.left()); - } - } catch (Exception e) { // unable to catch ExpressionException - throw new DiscoveryException("Invalid expression : " + dslQuery, e); - } - } - - public GremlinQueryResult evaluate(Expressions.Expression expression) { - Expressions.Expression validatedExpression = QueryProcessor.validate(expression); - GremlinQuery gremlinQuery = - new GremlinTranslator(validatedExpression, graphPersistenceStrategy).translate(); - LOG.debug("Query = {}", validatedExpression); - LOG.debug("Expression Tree = {}", validatedExpression.treeString()); - LOG.debug("Gremlin Query = {}", gremlinQuery.queryStr()); - return new GremlinEvaluator(gremlinQuery, graphPersistenceStrategy, titanGraph).evaluate(); - } - - /** - * Assumes the User is familiar with the persistence structure of the Repository. - * The given query is run uninterpreted against the underlying Graph Store. - * The results are returned as a List of Rows. each row is a Map of Key,Value pairs. - * - * @param gremlinQuery query in gremlin dsl format - * @return List of Maps - * @throws org.apache.hadoop.metadata.discovery.DiscoveryException - */ - @Override - @GraphTransaction - public List<Map<String, String>> searchByGremlin(String gremlinQuery) - throws DiscoveryException { - LOG.info("Executing gremlin query={}", gremlinQuery); - ScriptEngineManager manager = new ScriptEngineManager(); - ScriptEngine engine = manager.getEngineByName("gremlin-groovy"); - Bindings bindings = engine.createBindings(); - bindings.put("g", titanGraph); - - try { - Object o = engine.eval(gremlinQuery, bindings); - return extractResult(o); - } catch (ScriptException se) { - throw new DiscoveryException(se); - } - } - - private List<Map<String, String>> extractResult(Object o) throws DiscoveryException { - if (!(o instanceof List)) { - throw new DiscoveryException(String.format("Cannot process result %s", o.toString())); - } - - List l = (List) o; - List<Map<String, String>> result = new ArrayList<>(); - for (Object r : l) { - - Map<String, String> oRow = new HashMap<>(); - if (r instanceof Map) { - @SuppressWarnings("unchecked") - Map<Object, Object> iRow = (Map) r; - for (Map.Entry e : iRow.entrySet()) { - Object k = e.getKey(); - Object v = e.getValue(); - oRow.put(k.toString(), v.toString()); - } - } else if (r instanceof TitanVertex) { - Iterable<TitanProperty> ps = ((TitanVertex) r).getProperties(); - for (TitanProperty tP : ps) { - String pName = tP.getPropertyKey().getName(); - Object pValue = ((TitanVertex) r).getProperty(pName); - if (pValue != null) { - oRow.put(pName, pValue.toString()); - } - } - - } else if (r instanceof String) { - oRow.put("", r.toString()); - } else { - throw new DiscoveryException(String.format("Cannot process result %s", o.toString())); - } - - result.add(oRow); - } - return result; - } -} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/30711973/repository/src/main/java/org/apache/hadoop/metadata/listener/EntityChangeListener.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/hadoop/metadata/listener/EntityChangeListener.java b/repository/src/main/java/org/apache/hadoop/metadata/listener/EntityChangeListener.java deleted file mode 100755 index 12943cc..0000000 --- a/repository/src/main/java/org/apache/hadoop/metadata/listener/EntityChangeListener.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.hadoop.metadata.listener; - -import org.apache.hadoop.metadata.MetadataException; -import org.apache.hadoop.metadata.typesystem.ITypedReferenceableInstance; - -/** - * Entity (a Typed instance) change notification listener. - */ -public interface EntityChangeListener { - - /** - * This is upon adding a new typed instance to the repository. - * - * @param typedInstance a typed instance - * @throws org.apache.hadoop.metadata.MetadataException - */ - void onEntityAdded(ITypedReferenceableInstance typedInstance) throws MetadataException; - - /** - * This is upon adding a new trait to a typed instance. - * - * @param guid globally unique identifier for the entity - * @param traitName trait name for the instance that needs to be added to entity - * @throws org.apache.hadoop.metadata.MetadataException - */ - void onTraitAdded(String guid, String traitName) throws MetadataException; - - /** - * This is upon deleting a trait from a typed instance. - * - * @param guid globally unique identifier for the entity - * @param traitName trait name for the instance that needs to be deleted from entity - * @throws org.apache.hadoop.metadata.MetadataException - */ - void onTraitDeleted(String guid, String traitName) throws MetadataException; -} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/30711973/repository/src/main/java/org/apache/hadoop/metadata/listener/TypesChangeListener.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/hadoop/metadata/listener/TypesChangeListener.java b/repository/src/main/java/org/apache/hadoop/metadata/listener/TypesChangeListener.java deleted file mode 100755 index ad83129..0000000 --- a/repository/src/main/java/org/apache/hadoop/metadata/listener/TypesChangeListener.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.hadoop.metadata.listener; - -import org.apache.hadoop.metadata.MetadataException; -import org.apache.hadoop.metadata.typesystem.types.IDataType; - -/** - * Types change notification listener. - */ -public interface TypesChangeListener { - - /** - * This is upon adding a new type to Store. - * - * @param typeName type name - * @param dataType data type - * @throws MetadataException - */ - void onAdd(String typeName, IDataType dataType) throws MetadataException; - - /** - * This is upon removing an existing type from the Store. - * - * @param typeName type name - * @throws MetadataException - */ - // void onRemove(String typeName) throws MetadataException; - - // This is upon updating an existing type to the store - // void onChange() throws MetadataException; -} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/30711973/repository/src/main/java/org/apache/hadoop/metadata/repository/Constants.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/hadoop/metadata/repository/Constants.java b/repository/src/main/java/org/apache/hadoop/metadata/repository/Constants.java deleted file mode 100755 index c16f5d2..0000000 --- a/repository/src/main/java/org/apache/hadoop/metadata/repository/Constants.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.hadoop.metadata.repository; - -public final class Constants { - - /** - * Globally Unique identifier property key. - */ - - public static final String INTERNAL_PROPERTY_KEY_PREFIX = "__"; - public static final String GUID_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "guid"; - public static final String GUID_INDEX = "guid_index"; - - /** - * Entity type name property key. - */ - public static final String ENTITY_TYPE_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "typeName"; - public static final String ENTITY_TYPE_INDEX = "type_index"; - - /** - * Entity type's super types property key. - */ - public static final String SUPER_TYPES_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "superTypeNames"; - public static final String SUPER_TYPES_INDEX = "super_types_index"; - - /** - * Full-text for the entity for enabling full-text search. - */ - //weird issue in TitanDB if __ added to this property key. Not adding it for now - public static final String ENTITY_TEXT_PROPERTY_KEY = "entityText"; - - /** - * Properties for type store graph - */ - public static final String TYPE_CATEGORY_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "type.category"; - public static final String VERTEX_TYPE_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "type"; - public static final String TYPENAME_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "type.name"; - - /** - * Trait names property key and index name. - */ - public static final String TRAIT_NAMES_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "traitNames"; - public static final String TRAIT_NAMES_INDEX = "trait_names_index"; - - public static final String VERSION_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "version"; - public static final String TIMESTAMP_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "timestamp"; - - /** - * search backing index name. - */ - public static final String BACKING_INDEX = "search"; - - /** - * search backing index name for vertex keys. - */ - public static final String VERTEX_INDEX = "vertex_index"; - - /** - * search backing index name for edge labels. - */ - public static final String EDGE_INDEX = "edge_index"; - - public static final String FULLTEXT_INDEX = "fulltext_index"; - - private Constants() { - } -} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/30711973/repository/src/main/java/org/apache/hadoop/metadata/repository/DiscoverInstances.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/hadoop/metadata/repository/DiscoverInstances.java b/repository/src/main/java/org/apache/hadoop/metadata/repository/DiscoverInstances.java deleted file mode 100755 index c937ece..0000000 --- a/repository/src/main/java/org/apache/hadoop/metadata/repository/DiscoverInstances.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.hadoop.metadata.repository; - -import org.apache.hadoop.metadata.MetadataException; -import org.apache.hadoop.metadata.typesystem.IReferenceableInstance; -import org.apache.hadoop.metadata.typesystem.persistence.Id; -import org.apache.hadoop.metadata.typesystem.types.DataTypes; -import org.apache.hadoop.metadata.typesystem.types.ObjectGraphWalker; - -import java.util.HashMap; -import java.util.Map; - -/** - * Graph walker implementation for discovering instances. - */ -public class DiscoverInstances implements ObjectGraphWalker.NodeProcessor { - - public final Map<Id, Id> idToNewIdMap; - public final Map<Id, IReferenceableInstance> idToInstanceMap; - final IRepository repository; - - public DiscoverInstances(IRepository repository) { - this.repository = repository; - idToNewIdMap = new HashMap<>(); - idToInstanceMap = new HashMap<>(); - } - - @Override - public void processNode(ObjectGraphWalker.Node nd) throws MetadataException { - - IReferenceableInstance ref = null; - Id id = null; - - if (nd.attributeName == null) { - ref = (IReferenceableInstance) nd.instance; - id = ref.getId(); - } else if (nd.aInfo.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS) { - if (nd.value != null && (nd.value instanceof Id)) { - id = (Id) nd.value; - } - } - - if (id != null) { - if (id.isUnassigned()) { - if (!idToNewIdMap.containsKey(id)) { - idToNewIdMap.put(id, repository.newId(id.className)); - } - if (ref != null && idToInstanceMap.containsKey(ref)) { - // Oops - throw new RepositoryException( - String.format("Unexpected internal error: Id %s processed again", id)); - } - if (ref != null) { - idToInstanceMap.put(id, ref); - } - } - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/30711973/repository/src/main/java/org/apache/hadoop/metadata/repository/EntityNotFoundException.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/hadoop/metadata/repository/EntityNotFoundException.java b/repository/src/main/java/org/apache/hadoop/metadata/repository/EntityNotFoundException.java deleted file mode 100644 index f41bd42..0000000 --- a/repository/src/main/java/org/apache/hadoop/metadata/repository/EntityNotFoundException.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.hadoop.metadata.repository; - -import org.apache.hadoop.metadata.MetadataException; - -/** - * A simple wrapper for 404. - */ -public class EntityNotFoundException extends RepositoryException { - public EntityNotFoundException() { - } - - public EntityNotFoundException(String message) { - super(message); - } - - public EntityNotFoundException(String message, Throwable cause) { - super(message, cause); - } - - public EntityNotFoundException(Throwable cause) { - super(cause); - } - - public EntityNotFoundException(String message, Throwable cause, boolean enableSuppression, - boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - } -} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/30711973/repository/src/main/java/org/apache/hadoop/metadata/repository/IRepository.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/hadoop/metadata/repository/IRepository.java b/repository/src/main/java/org/apache/hadoop/metadata/repository/IRepository.java deleted file mode 100755 index 4339ec5..0000000 --- a/repository/src/main/java/org/apache/hadoop/metadata/repository/IRepository.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.hadoop.metadata.repository; - -import org.apache.hadoop.metadata.typesystem.IReferenceableInstance; -import org.apache.hadoop.metadata.typesystem.ITypedReferenceableInstance; -import org.apache.hadoop.metadata.typesystem.persistence.Id; -import org.apache.hadoop.metadata.typesystem.types.ClassType; -import org.apache.hadoop.metadata.typesystem.types.HierarchicalType; -import org.apache.hadoop.metadata.typesystem.types.TraitType; - -import java.util.List; - -/** - * Metadata Repository interface. - */ -public interface IRepository { - - ITypedReferenceableInstance create(IReferenceableInstance i) throws RepositoryException; - - ITypedReferenceableInstance update(ITypedReferenceableInstance i) throws RepositoryException; - - void delete(ITypedReferenceableInstance i) throws RepositoryException; - - Id newId(String typeName); - - ITypedReferenceableInstance get(Id id) throws RepositoryException; - - void defineClass(ClassType type) throws RepositoryException; - - void defineTrait(TraitType type) throws RepositoryException; - - void defineTypes(List<HierarchicalType> types) throws RepositoryException; -}
