Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ATLAS-3219: New REST APIs for serviceType. #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public enum AtlasErrorCode {
// All Not found enums go here
TYPE_NAME_NOT_FOUND(404, "ATLAS-404-00-001", "Given typename {0} was invalid"),
TYPE_GUID_NOT_FOUND(404, "ATLAS-404-00-002", "Given type guid {0} was invalid"),
TYPE_SERVICE_TYPE_NOT_FOUND(404, "ATLAS-404-00-014", "Given service type {0} was invalid"),
NO_CLASSIFICATIONS_FOUND_FOR_ENTITY(404, "ATLAS-404-00-003", "No classifications associated with entity: {0}"),
EMPTY_RESULTS(404, "ATLAS-404-00-004", "No result found for {0}"),
INSTANCE_GUID_NOT_FOUND(404, "ATLAS-404-00-005", "Given instance guid {0} is invalid/not found"),
Expand Down
2 changes: 2 additions & 0 deletions intg/src/main/java/org/apache/atlas/model/SearchFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public class SearchFilter {
public static final String PARAM_TYPE = "type";
public static final String PARAM_NAME = "name";
public static final String PARAM_SUPERTYPE = "supertype";
public static final String PARAM_SERVICETYPE = "servicetype";
public static final String PARAM_NOT_SUPERTYPE = "notsupertype";
public static final String PARAM_NOT_SERVICETYPE = "notservicetype";
public static final String PARAM_NOT_NAME = "notname";

/**
Expand Down
17 changes: 16 additions & 1 deletion intg/src/main/java/org/apache/atlas/store/AtlasTypeDefStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.apache.atlas.store;

import java.util.List;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
Expand All @@ -39,6 +40,8 @@ public interface AtlasTypeDefStore {
AtlasEnumDef getEnumDefByName(String name) throws AtlasBaseException;

AtlasEnumDef getEnumDefByGuid(String guid) throws AtlasBaseException;

List<AtlasEnumDef> getEnumDefByServiceType(String serviceType) throws AtlasBaseException;

AtlasEnumDef updateEnumDefByName(String name, AtlasEnumDef enumDef) throws AtlasBaseException;

Expand All @@ -50,6 +53,8 @@ public interface AtlasTypeDefStore {

AtlasStructDef getStructDefByGuid(String guid) throws AtlasBaseException;

List<AtlasStructDef> getStructDefByServiceType(String serviceType) throws AtlasBaseException;

AtlasStructDef updateStructDefByName(String name, AtlasStructDef structDef) throws AtlasBaseException;

AtlasStructDef updateStructDefByGuid(String guid, AtlasStructDef structDef) throws AtlasBaseException;
Expand All @@ -72,6 +77,8 @@ AtlasClassificationDef updateClassificationDefByGuid(String guid, AtlasClassific

AtlasEntityDef getEntityDefByGuid(String guid) throws AtlasBaseException;

List<AtlasEntityDef> getEntityDefByServiceType(String serviceType)throws AtlasBaseException;

AtlasEntityDef updateEntityDefByName(String name, AtlasEntityDef entityDef) throws AtlasBaseException;

AtlasEntityDef updateEntityDefByGuid(String guid, AtlasEntityDef entityDef) throws AtlasBaseException;
Expand All @@ -80,6 +87,8 @@ AtlasClassificationDef updateClassificationDefByGuid(String guid, AtlasClassific
AtlasRelationshipDef getRelationshipDefByName(String name) throws AtlasBaseException;

AtlasRelationshipDef getRelationshipDefByGuid(String guid) throws AtlasBaseException;

List<AtlasRelationshipDef> getRelationshipDefByServiceType(String serviceType) throws AtlasBaseException;

AtlasRelationshipDef updateRelationshipDefByName(String name, AtlasRelationshipDef structDef) throws AtlasBaseException;

Expand All @@ -98,12 +107,18 @@ AtlasClassificationDef updateClassificationDefByGuid(String guid, AtlasClassific
void deleteTypesDef(AtlasTypesDef atlasTypesDef) throws AtlasBaseException;

AtlasTypesDef searchTypesDef(SearchFilter searchFilter) throws AtlasBaseException;


AtlasTypesDef getTypesByServiceType(String serviceType) throws AtlasBaseException;

/* Generic operation */
AtlasBaseTypeDef getByName(String name) throws AtlasBaseException;

AtlasBaseTypeDef getByGuid(String guid) throws AtlasBaseException;

List<AtlasBaseTypeDef> getByServiceType(String serviceType) throws AtlasBaseException;

void deleteTypeByName(String typeName) throws AtlasBaseException;

public void deleteTypesByServiceType(String serviceType) throws AtlasBaseException;

}
115 changes: 103 additions & 12 deletions intg/src/main/java/org/apache/atlas/type/AtlasTypeRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
Expand Down Expand Up @@ -129,6 +130,26 @@ public AtlasType getTypeByGuid(String guid) {

return ret;
}

public List<AtlasType> getTypesByServiceType(String serviceType) throws AtlasBaseException {
if(LOG.isDebugEnabled()) {
LOG.debug("==> AtlasTypeRegistry.getTypesByServiceType({}", serviceType);
}

List<AtlasType> ret = registryData.allTypes.getTypesByServiceType(serviceType);

if(ret==null) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_SERVICE_TYPE_NOT_FOUND, serviceType);
}

if (LOG.isDebugEnabled()) {
List<String> names = new ArrayList<>();
ret.forEach(at->names.add("{" + at.getTypeName() + "," + at.getTypeCategory()+"}"));
LOG.debug("<== AtlasTypeRegistry.getTypesByServiceType({}): {}", serviceType, names.toString());
}

return ret;
}

public AtlasBaseTypeDef getTypeDefByName(String name) { return registryData.getTypeDefByName(name); }

Expand All @@ -140,10 +161,16 @@ public AtlasType getTypeByGuid(String guid) {
public AtlasEnumDef getEnumDefByGuid(String guid) {
return registryData.enumDefs.getTypeDefByGuid(guid);
}

public List<AtlasEnumDef> getEnumDefByServiceType(String serviceType) {
return registryData.enumDefs.getTypeDefByServiceType(serviceType);
}


public AtlasEnumDef getEnumDefByName(String name) {
return registryData.enumDefs.getTypeDefByName(name);
}


public Collection<String> getAllEnumDefNames() { return registryData.enumDefs.getAllNames(); }

Expand All @@ -157,6 +184,11 @@ public AtlasEnumDef getEnumDefByName(String name) {
public AtlasStructDef getStructDefByGuid(String guid) {
return registryData.structDefs.getTypeDefByGuid(guid);
}

public List<AtlasStructDef> getStructDefByServiceType(String serviceType) {
return registryData.structDefs.getTypeDefByServiceType(serviceType);
}


public AtlasStructDef getStructDefByName(String name) { return registryData.structDefs.getTypeDefByName(name); }

Expand Down Expand Up @@ -195,6 +227,10 @@ public AtlasClassificationType getClassificationTypeByName(String name) {
public AtlasEntityDef getEntityDefByGuid(String guid) {
return registryData.entityDefs.getTypeDefByGuid(guid);
}

public List<AtlasEntityDef> getEntityDefByServiceType(String serviceType) {
return registryData.entityDefs.getTypeDefByServiceType(serviceType);
}

public AtlasEntityDef getEntityDefByName(String name) {
return registryData.entityDefs.getTypeDefByName(name);
Expand All @@ -211,6 +247,9 @@ public AtlasEntityDef getEntityDefByName(String name) {
public AtlasRelationshipDef getRelationshipDefByGuid(String guid) {
return registryData.relationshipDefs.getTypeDefByGuid(guid);
}
public List<AtlasRelationshipDef> getRelationshipDefByServiceType(String serviceType) {
return registryData.relationshipDefs.getTypeDefByServiceType(serviceType);
}
public AtlasRelationshipDef getRelationshipDefByName(String name) {
return registryData.relationshipDefs.getTypeDefByName(name);
}
Expand Down Expand Up @@ -933,29 +972,25 @@ void releaseTypeRegistryForUpdate(AtlasTransientTypeRegistry ttr, boolean commit
class TypeCache {
private final Map<String, AtlasType> typeGuidMap;
private final Map<String, AtlasType> typeNameMap;
private final Set<String> serviceTypes;
private final Map<String, List<AtlasType>> typeServiceTypeMap;

public TypeCache() {
typeGuidMap = new ConcurrentHashMap<>();
typeNameMap = new ConcurrentHashMap<>();
serviceTypes = new HashSet<>();
typeServiceTypeMap = new ConcurrentHashMap<>();
}

public TypeCache(TypeCache other) {
typeGuidMap = new ConcurrentHashMap<>(other.typeGuidMap);
typeNameMap = new ConcurrentHashMap<>(other.typeNameMap);
serviceTypes = new HashSet<>(other.serviceTypes);
typeServiceTypeMap = new ConcurrentHashMap<>(other.typeServiceTypeMap);
}

public void addType(AtlasType type) {
if (type != null) {
if (StringUtils.isNotEmpty(type.getTypeName())) {
typeNameMap.put(type.getTypeName(), type);
}

if (StringUtils.isNotEmpty(type.getServiceType())) {
serviceTypes.add(type.getServiceType());
}
}
}

Expand All @@ -970,7 +1005,11 @@ public void addType(AtlasBaseTypeDef typeDef, AtlasType type) {
}

if (StringUtils.isNotEmpty(type.getServiceType())) {
serviceTypes.add(type.getServiceType());
if(typeServiceTypeMap.get(typeDef.getServiceType()) == null) {
typeServiceTypeMap.put(typeDef.getServiceType(), new ArrayList<>(Arrays.asList(type)));
} else {
typeServiceTypeMap.get(type.getServiceType()).add(type);
}
}
}
}
Expand All @@ -988,7 +1027,7 @@ public Collection<AtlasType> getAllTypes() {
}

public Set<String> getAllServiceTypes() {
return Collections.unmodifiableSet(serviceTypes);
return Collections.unmodifiableSet(typeServiceTypeMap.keySet());
}

public AtlasType getTypeByGuid(String guid) {
Expand All @@ -1000,6 +1039,11 @@ public AtlasType getTypeByName(String name) {

return name != null ? typeNameMap.get(name) : null;
}

public List<AtlasType> getTypesByServiceType(String serviceType) {

return serviceType != null ? typeServiceTypeMap.get(serviceType) : null;
}

public void updateGuid(String typeName, String currGuid, String newGuid) {
if (currGuid != null) {
Expand All @@ -1026,10 +1070,19 @@ public void removeTypeByName(String name) {
typeNameMap.remove(name);
}
}

public void removeTypeByServiceType(String serviceType, AtlasType type) {
if(serviceType != null) {
typeServiceTypeMap.get(serviceType).remove(type);
if(typeServiceTypeMap.get(serviceType).size()==0)
typeServiceTypeMap.remove(serviceType );
}
}

public void clear() {
typeGuidMap.clear();
typeNameMap.clear();
typeServiceTypeMap.clear();
}
}

Expand All @@ -1039,19 +1092,22 @@ class TypeDefCache<T1 extends AtlasBaseTypeDef, T2 extends AtlasType> {
private final TypeCache typeCache;
private final Map<String, T1> typeDefGuidMap;
private final Map<String, T1> typeDefNameMap;
private final Map<String, List<T1>> typeDefServiceTypeMap;
private final Map<String, T2> typeNameMap;

public TypeDefCache(TypeCache typeCache) {
this.typeCache = typeCache;
this.typeDefGuidMap = new ConcurrentHashMap<>();
this.typeDefNameMap = new ConcurrentHashMap<>();
this.typeDefServiceTypeMap = new ConcurrentHashMap<>();
this.typeNameMap = new ConcurrentHashMap<>();
}

public TypeDefCache(TypeDefCache other, TypeCache typeCache) {
this.typeCache = typeCache;
this.typeDefGuidMap = new ConcurrentHashMap<>(other.typeDefGuidMap);
this.typeDefNameMap = new ConcurrentHashMap<>(other.typeDefNameMap);
this.typeDefServiceTypeMap =new ConcurrentHashMap<>(other.typeDefServiceTypeMap);
this.typeNameMap = new ConcurrentHashMap<>(other.typeNameMap);
}

Expand All @@ -1065,6 +1121,14 @@ public void addType(T1 typeDef, T2 type) {
typeDefNameMap.put(typeDef.getName(), typeDef);
typeNameMap.put(typeDef.getName(), type);
}

if(StringUtils.isNotEmpty(typeDef.getServiceType())) {
if(typeDefServiceTypeMap.get(typeDef.getServiceType())==null) {
typeDefServiceTypeMap.put(typeDef.getServiceType(), new ArrayList<>(Arrays.asList(typeDef)));
} else {
typeDefServiceTypeMap.get(typeDef.getServiceType()).add(typeDef);
}
}

typeCache.addType(typeDef, type);
}
Expand All @@ -1079,11 +1143,15 @@ public Collection<T1> getAll() {
public T1 getTypeDefByGuid(String guid) {
return guid != null ? typeDefGuidMap.get(guid) : null;
}

public List<T1> getTypeDefByServiceType(String serviceType) {
return serviceType != null ? typeDefServiceTypeMap.get(serviceType) : null;
}

public T1 getTypeDefByName(String name) {
return name != null ? typeDefNameMap.get(name) : null;
}

public Collection<T2> getAllTypes() {
return Collections.unmodifiableCollection(typeNameMap.values());
}
Expand Down Expand Up @@ -1125,7 +1193,8 @@ public void updateGuid(String typeName, String newGuid) {
public void removeTypeDefByGuid(String guid) {
if (guid != null) {
T1 typeDef = typeDefGuidMap.remove(guid);

AtlasType type = typeCache.getTypeByGuid(guid);

typeCache.removeTypeByGuid(guid);

String name = typeDef != null ? typeDef.getName() : null;
Expand All @@ -1135,13 +1204,24 @@ public void removeTypeDefByGuid(String guid) {
typeNameMap.remove(name);
typeCache.removeTypeByName(name);
}


String serviceType = typeDef != null ? typeDef.getServiceType() : null;

if(serviceType != null) {
typeDefServiceTypeMap.get(serviceType).remove(typeDef);
if(typeDefServiceTypeMap.get(serviceType).size()==0) {
typeDefServiceTypeMap.remove(serviceType);
}
typeCache.removeTypeByServiceType(serviceType, type);
}

}
}

public void removeTypeDefByName(String name) {
if (name != null) {
T1 typeDef = typeDefNameMap.remove(name);
AtlasType type = typeCache.getTypeByName(name);

typeNameMap.remove(name);
typeCache.removeTypeByName(name);
Expand All @@ -1152,6 +1232,16 @@ public void removeTypeDefByName(String name) {
typeDefGuidMap.remove(guid);
typeCache.removeTypeByGuid(guid);
}

String serviceType = typeDef != null ? typeDef.getServiceType() : null;

if(serviceType != null) {
typeDefServiceTypeMap.get(serviceType).remove(typeDef);
if(typeDefServiceTypeMap.get(serviceType).size()==0) {
typeDefServiceTypeMap.remove(serviceType);
}
typeCache.removeTypeByServiceType(serviceType, type);
}
}
}

Expand All @@ -1160,5 +1250,6 @@ public void clear() {
typeDefGuidMap.clear();
typeDefNameMap.clear();
typeNameMap.clear();
typeDefServiceTypeMap.clear();
}
}