Repository: incubator-atlas Updated Branches: refs/heads/master 9f643b5b9 -> 0c7468954
ATLAS-1241 New Instance APIs and POJOs (sumasai) Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/0c746895 Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/0c746895 Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/0c746895 Branch: refs/heads/master Commit: 0c7468954f5cf9f85fd066397707e3528ee89da8 Parents: 9f643b5 Author: Suma Shivaprasad <[email protected]> Authored: Tue Nov 1 20:49:47 2016 -0700 Committer: Suma Shivaprasad <[email protected]> Committed: Tue Nov 1 20:49:47 2016 -0700 ---------------------------------------------------------------------- .../atlas/model/instance/AtlasEntityHeader.java | 179 +++++++++++++++ .../instance/AtlasEntityWithAssociations.java | 149 +++++++++++++ .../model/instance/EntityMutationResponse.java | 136 ++++++++++++ .../atlas/model/instance/EntityMutations.java | 147 +++++++++++++ .../org/apache/atlas/type/AtlasTypeUtil.java | 52 ++--- .../test/java/org/apache/atlas/TestUtilsV2.java | 3 +- pom.xml | 8 + release-log.txt | 1 + .../apache/atlas/RepositoryMetadataModule.java | 4 + .../store/graph/AtlasEntityStore.java | 178 +++++++++++++++ .../store/graph/v1/AtlasEntityStoreV1.java | 122 +++++++++++ webapp/pom.xml | 8 + .../org/apache/atlas/web/rest/EntitiesREST.java | 128 +++++++++++ .../org/apache/atlas/web/rest/EntityRest.java | 217 +++++++++++++++++++ 14 files changed, 1305 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/0c746895/intg/src/main/java/org/apache/atlas/model/instance/AtlasEntityHeader.java ---------------------------------------------------------------------- diff --git a/intg/src/main/java/org/apache/atlas/model/instance/AtlasEntityHeader.java b/intg/src/main/java/org/apache/atlas/model/instance/AtlasEntityHeader.java new file mode 100644 index 0000000..d9c74ae --- /dev/null +++ b/intg/src/main/java/org/apache/atlas/model/instance/AtlasEntityHeader.java @@ -0,0 +1,179 @@ +/** + * 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.model.instance; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; +import java.util.Map; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSeeAlso; + +import org.apache.atlas.model.PList; +import org.apache.atlas.model.SearchFilter.SortType; +import org.apache.atlas.model.typedef.AtlasEntityDef; +import org.codehaus.jackson.annotate.JsonAutoDetect; +import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.PUBLIC_ONLY; +import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.NONE; +import org.codehaus.jackson.annotate.JsonIgnoreProperties; +import org.codehaus.jackson.map.annotate.JsonSerialize; + + +/** + * An instance of an entity - like hive_table, hive_database. + */ +@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE) +@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown=true) +@XmlRootElement +@XmlAccessorType(XmlAccessType.PROPERTY) +public class AtlasEntityHeader extends AtlasStruct implements Serializable { + private static final long serialVersionUID = 1L; + + private String guid = null; + private AtlasEntity.Status status = AtlasEntity.Status.STATUS_ACTIVE; + private String displayText = null; + + public AtlasEntityHeader() { + this(null, null); + } + + public AtlasEntityHeader(String typeName) { + this(typeName, null); + } + + public AtlasEntityHeader(AtlasEntityDef entityDef) { + this(entityDef != null ? entityDef.getName() : null, null); + } + + public AtlasEntityHeader(String typeName, Map<String, Object> attributes) { + super(typeName, attributes); + + setGuid(null); + setStatus(null); + } + + public AtlasEntityHeader(AtlasEntityHeader other) { + super(other); + + if (other != null) { + setGuid(other.getGuid()); + setStatus(other.getStatus()); + } + } + + public String getGuid() { + return guid; + } + + public void setGuid(String guid) { + this.guid = guid; + } + + public AtlasEntity.Status getStatus() { + return status; + } + + public void setStatus(AtlasEntity.Status status) { + this.status = status; + } + + public String getDisplayText() { + return displayText; + } + + public void setDisplayText(final String displayText) { + this.displayText = displayText; + } + + @Override + public StringBuilder toString(StringBuilder sb) { + if (sb == null) { + sb = new StringBuilder(); + } + + sb.append("AtlasEntityHeader{"); + sb.append("guid='").append(guid).append('\''); + sb.append(", status=").append(status); + sb.append(", displayText=").append(displayText); + sb.append(", "); + super.toString(sb); + sb.append('}'); + + return sb; + } + + @Override + public boolean equals(Object o) { + if (this == o) { return true; } + if (o == null || getClass() != o.getClass()) { return false; } + if (!super.equals(o)) { return false; } + + AtlasEntityHeader that = (AtlasEntityHeader) o; + + if (guid != null ? !guid.equals(that.guid) : that.guid != null) { return false; } + if (status != null ? !status.equals(that.status) : that.status != null) { return false; } + if (displayText != null ? !displayText.equals(that.displayText) : that.displayText != null) { return false; } + + return true; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + + result = 31 * result + (guid != null ? guid.hashCode() : 0); + result = 31 * result + (status != null ? status.hashCode() : 0); + result = 31 * result + (displayText != null ? displayText.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return toString(new StringBuilder()).toString(); + } + + /** + * REST serialization friendly list. + */ + @JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE) + @JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) + @JsonIgnoreProperties(ignoreUnknown=true) + @XmlRootElement + @XmlAccessorType(XmlAccessType.PROPERTY) + @XmlSeeAlso(AtlasEntity.class) + public static class AtlasEntityHeaders extends PList<AtlasEntityHeader> { + private static final long serialVersionUID = 1L; + + public AtlasEntityHeaders() { + super(); + } + + public AtlasEntityHeaders(List<AtlasEntityHeader> list) { + super(list); + } + + public AtlasEntityHeaders(List list, long startIndex, int pageSize, long totalCount, + SortType sortType, String sortBy) { + super(list, startIndex, pageSize, totalCount, sortType, sortBy); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/0c746895/intg/src/main/java/org/apache/atlas/model/instance/AtlasEntityWithAssociations.java ---------------------------------------------------------------------- diff --git a/intg/src/main/java/org/apache/atlas/model/instance/AtlasEntityWithAssociations.java b/intg/src/main/java/org/apache/atlas/model/instance/AtlasEntityWithAssociations.java new file mode 100644 index 0000000..4ddd585 --- /dev/null +++ b/intg/src/main/java/org/apache/atlas/model/instance/AtlasEntityWithAssociations.java @@ -0,0 +1,149 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * 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.model.instance; + +import org.apache.atlas.model.PList; +import org.apache.atlas.model.SearchFilter.SortType; +import org.apache.atlas.model.typedef.AtlasEntityDef; +import org.codehaus.jackson.annotate.JsonAutoDetect; +import org.codehaus.jackson.annotate.JsonIgnoreProperties; +import org.codehaus.jackson.map.annotate.JsonSerialize; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSeeAlso; +import java.io.Serializable; +import java.util.Date; +import java.util.List; +import java.util.Map; + +import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.NONE; +import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.PUBLIC_ONLY; + + +/** + * An instance of an entity - like hive_table, hive_database along with its assictaed classifications, terms etc. + */ +@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE) +@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown=true) +@XmlRootElement +@XmlAccessorType(XmlAccessType.PROPERTY) +public class AtlasEntityWithAssociations extends AtlasEntity implements Serializable { + private static final long serialVersionUID = 1L; + + List<AtlasClassification> classifications; + + public AtlasEntityWithAssociations() { + this(null, null); + } + + public AtlasEntityWithAssociations(String typeName) { + this(typeName, null); + } + + public AtlasEntityWithAssociations(AtlasEntityDef entityDef) { + this(entityDef != null ? entityDef.getName() : null, null); + } + + public AtlasEntityWithAssociations(String typeName, Map<String, Object> attributes) { + super(typeName, attributes); + setClassifications(null); + } + + public AtlasEntityWithAssociations(AtlasEntityWithAssociations other) { + super(other); + + setClassifications(other != null ? other.getClassifications() : null); + } + + @Override + public StringBuilder toString(StringBuilder sb) { + if (sb == null) { + sb = new StringBuilder(); + } + + sb.append("AtlasEntityWithAssociations{"); + sb.append("classifications='").append(classifications).append('\''); + sb.append(", "); + super.toString(sb); + sb.append('}'); + + return sb; + } + + @Override + public boolean equals(Object o) { + if (this == o) { return true; } + if (o == null || getClass() != o.getClass()) { return false; } + if (!super.equals(o)) { return false; } + + AtlasEntityWithAssociations that = (AtlasEntityWithAssociations) o; + + if (classifications != null ? !classifications.equals(that.classifications) : that.classifications != null) { return false; } + + return true; + } + + public List<AtlasClassification> getClassifications() { + return classifications; + } + + public void setClassifications(final List<AtlasClassification> classifications) { + this.classifications = classifications; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (classifications != null ? classifications.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return toString(new StringBuilder()).toString(); + } + + /** + * REST serialization friendly list. + */ + @JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE) + @JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) + @JsonIgnoreProperties(ignoreUnknown=true) + @XmlRootElement + @XmlAccessorType(XmlAccessType.PROPERTY) + @XmlSeeAlso(AtlasEntityWithAssociations.class) + public static class AtlasEntitiesWithAssociations extends PList<AtlasEntityWithAssociations> { + private static final long serialVersionUID = 1L; + + public AtlasEntitiesWithAssociations() { + super(); + } + + public AtlasEntitiesWithAssociations(List<AtlasEntityWithAssociations> list) { + super(list); + } + + public AtlasEntitiesWithAssociations(List list, long startIndex, int pageSize, long totalCount, + SortType sortType, String sortBy) { + super(list, startIndex, pageSize, totalCount, sortType, sortBy); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/0c746895/intg/src/main/java/org/apache/atlas/model/instance/EntityMutationResponse.java ---------------------------------------------------------------------- diff --git a/intg/src/main/java/org/apache/atlas/model/instance/EntityMutationResponse.java b/intg/src/main/java/org/apache/atlas/model/instance/EntityMutationResponse.java new file mode 100644 index 0000000..a6c75ed --- /dev/null +++ b/intg/src/main/java/org/apache/atlas/model/instance/EntityMutationResponse.java @@ -0,0 +1,136 @@ +/** + * 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.model.instance; + + +import org.apache.atlas.model.instance.AtlasEntityHeader; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.MapUtils; +import org.codehaus.jackson.annotate.JsonAutoDetect; +import org.codehaus.jackson.annotate.JsonIgnoreProperties; +import org.codehaus.jackson.map.annotate.JsonSerialize; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.NONE; +import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.PUBLIC_ONLY; + +@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE) +@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown=true) +@XmlRootElement +@XmlAccessorType(XmlAccessType.PROPERTY) +public class EntityMutationResponse { + + Map<EntityMutations.EntityOperation, List<AtlasEntityHeader>> entitiesMutated = new HashMap<>(); + + public EntityMutationResponse() { + } + + public EntityMutationResponse(final Map<EntityMutations.EntityOperation, List<AtlasEntityHeader>> opVsEntityMap) { + this.entitiesMutated = opVsEntityMap; + } + + public Map<EntityMutations.EntityOperation, List<AtlasEntityHeader>> getEntitiesMutated() { + return entitiesMutated; + } + + public void setEntitiesMutated(final Map<EntityMutations.EntityOperation, List<AtlasEntityHeader>> opVsEntityMap) { + this.entitiesMutated = opVsEntityMap; + } + + List<AtlasEntityHeader> getEntitiesByOperation(EntityMutations.EntityOperation op) { + if ( entitiesMutated != null) { + return entitiesMutated.get(op); + } + return null; + } + + public void addEntity(EntityMutations.EntityOperation op, AtlasEntityHeader header) { + if (entitiesMutated == null) { + entitiesMutated = new HashMap<EntityMutations.EntityOperation, List<AtlasEntityHeader>>(); + } + + if (entitiesMutated != null && entitiesMutated.get(op) == null) { + entitiesMutated.put(op, new ArrayList<AtlasEntityHeader>()); + } + entitiesMutated.get(op).add(header); + } + + + public StringBuilder toString(StringBuilder sb) { + if ( sb == null) { + sb = new StringBuilder(); + } + + if (MapUtils.isNotEmpty(entitiesMutated)) { + int i = 0; + for (Map.Entry<EntityMutations.EntityOperation, List<AtlasEntityHeader>> e : entitiesMutated.entrySet()) { + if (i > 0) { + sb.append(","); + } + sb.append(e.getKey()).append(":"); + if (CollectionUtils.isNotEmpty(e.getValue())) { + for (int j = 0; i < e.getValue().size(); j++) { + if (j > 0) { + sb.append(","); + } + e.getValue().get(i).toString(sb); + } + } + i++; + } + } + + return sb; + } + + @Override + public boolean equals(Object o) { + if ( this == o) return true; + + if ( this == null || getClass() != o.getClass()) return false; + if ( !super.equals(o)) return false; + + EntityMutationResponse that = (EntityMutationResponse) o; + + if ( entitiesMutated != null ? !entitiesMutated.equals(that.entitiesMutated) : that.entitiesMutated != null) { + return false; + } + + return true; + } + + @Override + public int hashCode() { + int result = (entitiesMutated != null ? entitiesMutated.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return toString(new StringBuilder()).toString(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/0c746895/intg/src/main/java/org/apache/atlas/model/instance/EntityMutations.java ---------------------------------------------------------------------- diff --git a/intg/src/main/java/org/apache/atlas/model/instance/EntityMutations.java b/intg/src/main/java/org/apache/atlas/model/instance/EntityMutations.java new file mode 100644 index 0000000..e489f33 --- /dev/null +++ b/intg/src/main/java/org/apache/atlas/model/instance/EntityMutations.java @@ -0,0 +1,147 @@ +/** + * 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.model.instance; + +import org.apache.commons.collections.CollectionUtils; +import org.codehaus.jackson.annotate.JsonAutoDetect; +import org.codehaus.jackson.annotate.JsonIgnoreProperties; +import org.codehaus.jackson.map.annotate.JsonSerialize; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.NONE; +import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.PUBLIC_ONLY; + +@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE) +@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown=true) +@XmlRootElement +@XmlAccessorType(XmlAccessType.PROPERTY) +public class EntityMutations implements Serializable { + + private List<EntityMutation> entityMutations = new ArrayList<>(); + + public enum EntityOperation { + CREATE_OR_UPDATE, + PARTIAL_UPDATE, + DELETE, + } + + public static final class EntityMutation implements Serializable { + private EntityOperation op; + private AtlasEntity entity; + + public EntityMutation(EntityOperation op, AtlasEntity entity) { + this.op = op; + this.entity = entity; + } + + public StringBuilder toString(StringBuilder sb) { + if ( sb == null) { + sb = new StringBuilder(); + } + sb.append("EntityMutation {"); + sb.append("op=").append(op); + if (entity != null) { + sb.append(", entity="); + entity.toString(sb); + } + sb.append("}"); + + return sb; + } + + @Override + public boolean equals(Object o) { + if (this == o) { return true; } + if (o == null || getClass() != o.getClass()) { return false; } + + EntityMutation that = (EntityMutation) o; + + if (op != null ? !op.equals(that.op) : that.op != null) { return false; } + if (entity != null ? !entity.equals(that.entity) : that.entity != null) { return false; } + + return true; + } + + @Override + public int hashCode() { + int result = (op != null ? op.hashCode() : 0); + result = 31 * result + (entity != null ? entity.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return toString(new StringBuilder()).toString(); + } + } + + public EntityMutations(List<EntityMutation> entityMutations) { + this.entityMutations = entityMutations; + } + + public StringBuilder toString(StringBuilder sb) { + if ( sb == null) { + sb = new StringBuilder(); + } + sb.append("EntityMutations{"); + if (CollectionUtils.isNotEmpty(entityMutations)) { + for (int i = 0; i < entityMutations.size(); i++) { + if (i > 0) { + sb.append(","); + } + entityMutations.get(i).toString(sb); + } + } + sb.append("}"); + + return sb; + } + + @Override + public String toString() { + return toString(new StringBuilder()).toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { return true; } + if (o == null || getClass() != o.getClass()) { return false; } + + EntityMutations that = (EntityMutations) o; + + if (entityMutations != null ? !entityMutations.equals(that.entityMutations) : that.entityMutations != null) { return false; } + + return true; + } + + @Override + public int hashCode() { + int result = (entityMutations != null ? entityMutations.hashCode() : 0); + return result; + } +} + + http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/0c746895/intg/src/main/java/org/apache/atlas/type/AtlasTypeUtil.java ---------------------------------------------------------------------- diff --git a/intg/src/main/java/org/apache/atlas/type/AtlasTypeUtil.java b/intg/src/main/java/org/apache/atlas/type/AtlasTypeUtil.java index 190364f..a2f7463 100644 --- a/intg/src/main/java/org/apache/atlas/type/AtlasTypeUtil.java +++ b/intg/src/main/java/org/apache/atlas/type/AtlasTypeUtil.java @@ -73,7 +73,7 @@ public class AtlasTypeUtil { public static boolean isMapType(String typeName) { return StringUtils.startsWith(typeName, ATLAS_TYPE_MAP_PREFIX) - && StringUtils.endsWith(typeName, ATLAS_TYPE_MAP_SUFFIX); + && StringUtils.endsWith(typeName, ATLAS_TYPE_MAP_SUFFIX); } @@ -109,44 +109,44 @@ public class AtlasTypeUtil { public static AtlasAttributeDef createOptionalAttrDef(String name, AtlasType dataType) { return new AtlasAttributeDef(name, dataType.getTypeName(), true, - Cardinality.SINGLE, 0, 1, - true, false, - Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()); + Cardinality.SINGLE, 0, 1, + true, false, + Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()); } public static AtlasAttributeDef createOptionalAttrDef(String name, String dataType) { return new AtlasAttributeDef(name, dataType, true, - Cardinality.SINGLE, 0, 1, - true, false, - Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()); + Cardinality.SINGLE, 0, 1, + true, false, + Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()); } public static AtlasAttributeDef createRequiredAttrDef(String name, String dataType) { return new AtlasAttributeDef(name, dataType, false, - Cardinality.SINGLE, 1, 1, - false, false, - Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()); + Cardinality.SINGLE, 1, 1, + false, false, + Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()); } public static AtlasAttributeDef createUniqueRequiredAttrDef(String name, AtlasType dataType) { return new AtlasAttributeDef(name, dataType.getTypeName(), false, - Cardinality.SINGLE, 1, 1, - true, true, - Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()); + Cardinality.SINGLE, 1, 1, + true, true, + Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()); } public static AtlasAttributeDef createUniqueRequiredAttrDef(String name, String typeName) { return new AtlasAttributeDef(name, typeName, false, - Cardinality.SINGLE, 1, 1, - true, true, - Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()); + Cardinality.SINGLE, 1, 1, + true, true, + Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()); } public static AtlasAttributeDef createRequiredAttrDef(String name, AtlasType dataType) { return new AtlasAttributeDef(name, dataType.getTypeName(), false, - Cardinality.SINGLE, 1, 1, - false, false, - Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()); + Cardinality.SINGLE, 1, 1, + false, false, + Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()); } public static AtlasEnumDef createEnumTypeDef(String name, String description, AtlasEnumElementDef... enumValues) { @@ -174,24 +174,24 @@ public class AtlasTypeUtil { } public static AtlasEntityDef createClassTypeDef(String name, - ImmutableSet<String> superTypes, AtlasAttributeDef... attrDefs) { + ImmutableSet<String> superTypes, AtlasAttributeDef... attrDefs) { return createClassTypeDef(name, null, "1.0", superTypes, attrDefs); } public static AtlasEntityDef createClassTypeDef(String name, String description, - ImmutableSet<String> superTypes, AtlasAttributeDef... attrDefs) { + ImmutableSet<String> superTypes, AtlasAttributeDef... attrDefs) { return createClassTypeDef(name, description, "1.0", superTypes, attrDefs); } public static AtlasEntityDef createClassTypeDef(String name, String description, String version, - ImmutableSet<String> superTypes, AtlasAttributeDef... attrDefs) { + ImmutableSet<String> superTypes, AtlasAttributeDef... attrDefs) { return new AtlasEntityDef(name, description, "1.0", Arrays.asList(attrDefs), superTypes); } public static AtlasTypesDef getTypesDef(List<AtlasEnumDef> enums, - List<AtlasStructDef> structs, - List<AtlasClassificationDef> traits, - List<AtlasEntityDef> classes) { + List<AtlasStructDef> structs, + List<AtlasClassificationDef> traits, + List<AtlasEntityDef> classes) { return new AtlasTypesDef(enums, structs, traits, classes); } -} +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/0c746895/intg/src/test/java/org/apache/atlas/TestUtilsV2.java ---------------------------------------------------------------------- diff --git a/intg/src/test/java/org/apache/atlas/TestUtilsV2.java b/intg/src/test/java/org/apache/atlas/TestUtilsV2.java index dcccc38..bae9d3b 100755 --- a/intg/src/test/java/org/apache/atlas/TestUtilsV2.java +++ b/intg/src/test/java/org/apache/atlas/TestUtilsV2.java @@ -22,6 +22,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import org.apache.atlas.model.instance.AtlasEntity; +import org.apache.atlas.model.instance.AtlasObjectId; import org.apache.atlas.model.typedef.AtlasClassificationDef; import org.apache.atlas.model.typedef.AtlasEntityDef; import org.apache.atlas.model.typedef.AtlasEnumDef; @@ -613,7 +614,7 @@ public final class TestUtilsV2 { entity.setAttribute("description", "random table"); entity.setAttribute("type", "type"); entity.setAttribute("tableType", "MANAGED"); -// entity.setAttribute("database", new Id(dbId, 0, DATABASE_TYPE)); + entity.setAttribute("database", new AtlasObjectId(DATABASE_TYPE, dbId)); entity.setAttribute("created", new Date()); return entity; } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/0c746895/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 62fc136..a6fa7fb 100644 --- a/pom.xml +++ b/pom.xml @@ -1069,6 +1069,14 @@ <dependency> <groupId>org.apache.atlas</groupId> + <artifactId>atlas-intg</artifactId> + <version>${project.version}</version> + <classifier>tests</classifier> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.atlas</groupId> <artifactId>atlas-typesystem</artifactId> <version>${project.version}</version> </dependency> http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/0c746895/release-log.txt ---------------------------------------------------------------------- diff --git a/release-log.txt b/release-log.txt index 7737109..19f5244 100644 --- a/release-log.txt +++ b/release-log.txt @@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai) ALL CHANGES: +ATLAS-1241 New Instance APIs and POJOs (sumasai) ATLAS-1259 Fix Test and compilation failure caused bt ATLAS-1233 changes (apoorvnaik via sumasai) ATLAS-1248 /bin/atlas_stop.py not killing the process and process is found alive even after 30 secs (zhangqiang2 via sumasai) ATLAS-1258 BugFix for Indexer NPE on StructDef lookup (apoorvnaik via sumasai) http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/0c746895/repository/src/main/java/org/apache/atlas/RepositoryMetadataModule.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/RepositoryMetadataModule.java b/repository/src/main/java/org/apache/atlas/RepositoryMetadataModule.java index 129591a..0325c80 100755 --- a/repository/src/main/java/org/apache/atlas/RepositoryMetadataModule.java +++ b/repository/src/main/java/org/apache/atlas/RepositoryMetadataModule.java @@ -37,6 +37,8 @@ import org.apache.atlas.repository.audit.EntityAuditRepository; import org.apache.atlas.repository.graph.DeleteHandler; import org.apache.atlas.repository.graph.GraphBackedMetadataRepository; import org.apache.atlas.repository.graph.GraphBackedSearchIndexer; +import org.apache.atlas.repository.store.graph.AtlasEntityStore; +import org.apache.atlas.repository.store.graph.v1.AtlasEntityStoreV1; import org.apache.atlas.repository.store.graph.v1.AtlasTypeDefGraphStoreV1; import org.apache.atlas.repository.typestore.GraphBackedTypeStore; import org.apache.atlas.repository.typestore.ITypeStore; @@ -83,6 +85,8 @@ public class RepositoryMetadataModule extends com.google.inject.AbstractModule { typeDefChangeListenerMultibinder.addBinding().to(DefaultMetadataService.class); typeDefChangeListenerMultibinder.addBinding().to(GraphBackedSearchIndexer.class).asEagerSingleton(); + bind(AtlasEntityStore.class).to(AtlasEntityStoreV1.class); + // bind the MetadataService interface to an implementation bind(MetadataService.class).to(DefaultMetadataService.class).asEagerSingleton(); http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/0c746895/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java new file mode 100644 index 0000000..f17b816 --- /dev/null +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java @@ -0,0 +1,178 @@ +/** + * 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.repository.store.graph; + + +import org.apache.atlas.exception.AtlasBaseException; +import org.apache.atlas.model.SearchFilter; +import org.apache.atlas.model.instance.AtlasClassification; +import org.apache.atlas.model.instance.AtlasEntity; +import org.apache.atlas.model.instance.AtlasEntityWithAssociations; +import org.apache.atlas.model.instance.EntityMutations; +import org.apache.atlas.model.instance.EntityMutationResponse; + +import java.util.List; + +/** + * Persistence/Retrieval API for AtlasEntity + */ +public interface AtlasEntityStore { + + /** + * Initialization + */ + void init() throws AtlasBaseException; + + /** + * Create or update an entity if it already exists. + * @param entity + * @return + */ + EntityMutationResponse createOrUpdate(AtlasEntity entity); + + + /** + * Update entity identified by its guid + * @param guid + * @param entity + * @return + */ + EntityMutationResponse updateById(String guid, AtlasEntity entity); + + /** + * + * Get entity definition by its guid + * @param guid + * @return + */ + AtlasEntity getById(String guid); + + /** + * Delete an entity by its guid + * @param guid + * @return + */ + EntityMutationResponse deleteById(String guid); + + + /** + * Create or update a list of entities + * @param entities List of AtlasEntity objects that need to be created + * @return EntityMutationResponse Entity mutations operations with the correspomding set of entities on which these operations were performed + * @throws AtlasBaseException + */ + + EntityMutationResponse createOrUpdate(List<AtlasEntity> entities) throws AtlasBaseException; + + /** + * + * Provides list of updated entity guids including any child entities + * @param guid + * @param entity + * @return + * @throws AtlasBaseException + */ + EntityMutationResponse updateByIds(String guid, AtlasEntity entity) throws AtlasBaseException; + + /** + * Batch GET to retrieve entities by their ID + * @param guid + * @return + * @throws AtlasBaseException + */ + AtlasEntity.AtlasEntities getByIds(List<String> guid) throws AtlasBaseException; + + /** + * Batch GET to retrieve entities and their associations by their ID + * @param guid + * @return + * @throws AtlasBaseException + */ + AtlasEntityWithAssociations getWithAssociationsByIds(List<String> guid) throws AtlasBaseException; + + /* + * Return list of deleted entity guids + */ + EntityMutationResponse deleteByIds(List<String> guid) throws AtlasBaseException; + + /** + * + * Get an eneity by its unique attribute + * @param typeName + * @param attrName + * @param attrValue + * @return + */ + AtlasEntity getByUniqueAttribute(String typeName, String attrName, String attrValue); + + /** + * @deprecated + * Create or update a single entity + * @param typeName The entity's type + * @param attributeName Attribute that uniquely identifies the entity + * @param attributeValue The unqiue attribute's value + * @return EntityMutationResponse Entity mutations operations with the correspomding set of entities on which these operations were performed + * @throws AtlasBaseException + * + */ + + EntityMutationResponse updateByUniqueAttribute(String typeName, String attributeName, String attributeValue, AtlasEntity entity) throws AtlasBaseException; + + /** + * @deprecated + * @param typeName + * @param attributeName + * @param attributeValue + * @return + * @throws AtlasBaseException + */ + EntityMutationResponse deleteByUniqueAttribute(String typeName, String attributeName, String attributeValue) throws AtlasBaseException; + + /** + * Compose any type of mutation op - EntityMutation.EntityOperation - CREATE_OR_UPDATE, PARTIAL_UPDATE, DELETE etc in a single transaction + * @param mutations + * @return + * @throws AtlasBaseException + */ + EntityMutationResponse batchMutate(EntityMutations mutations) throws AtlasBaseException; + + /** + * Add classification(s) + */ + void addClassifications(String guid, List<AtlasClassification> classification) throws AtlasBaseException; + + + /** + * Update classification(s) + */ + void updateClassifications(String guid, List<AtlasClassification> classification) throws AtlasBaseException; + + /** + * Delete classification(s) + */ + void deleteClassifications(String guid, List<String> classificationNames) throws AtlasBaseException; + + /** + * + * Search by AND filters like typename, pre-defined attribute(s) eg: name, qualifiedName + * @param searchFilter + * @return + * @throws AtlasBaseException + */ + AtlasEntity.AtlasEntities searchEntities(SearchFilter searchFilter) throws AtlasBaseException; +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/0c746895/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java new file mode 100644 index 0000000..6b2b216 --- /dev/null +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java @@ -0,0 +1,122 @@ +/** + * 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.repository.store.graph.v1; + + +import org.apache.atlas.exception.AtlasBaseException; +import org.apache.atlas.model.SearchFilter; +import org.apache.atlas.model.instance.AtlasClassification; +import org.apache.atlas.model.instance.AtlasEntity; +import org.apache.atlas.model.instance.AtlasEntityWithAssociations; +import org.apache.atlas.model.instance.EntityMutationResponse; +import org.apache.atlas.model.instance.EntityMutations; +import org.apache.atlas.repository.store.graph.AtlasEntityStore; + +import java.util.List; + +public class AtlasEntityStoreV1 implements AtlasEntityStore { + @Override + public void init() throws AtlasBaseException { + } + + @Override + public EntityMutationResponse createOrUpdate(final AtlasEntity entity) { + return null; + } + + @Override + public EntityMutationResponse updateById(final String guid, final AtlasEntity entity) { + return null; + } + + @Override + public AtlasEntity getById(final String guid) { + return null; + } + + @Override + public EntityMutationResponse deleteById(final String guid) { + return null; + } + + @Override + public EntityMutationResponse createOrUpdate(final List<AtlasEntity> entities) throws AtlasBaseException { + return null; + } + + @Override + public EntityMutationResponse updateByIds(final String guid, final AtlasEntity entity) throws AtlasBaseException { + return null; + } + + @Override + public AtlasEntity.AtlasEntities getByIds(final List<String> guid) throws AtlasBaseException { + return null; + } + + @Override + public AtlasEntityWithAssociations getWithAssociationsByIds(final List<String> guid) throws AtlasBaseException { + return null; + } + + @Override + public EntityMutationResponse deleteByIds(final List<String> guid) throws AtlasBaseException { + return null; + } + + @Override + public AtlasEntity getByUniqueAttribute(final String typeName, final String attrName, final String attrValue) { + return null; + } + + @Override + public EntityMutationResponse updateByUniqueAttribute(final String typeName, final String attributeName, final String attributeValue, final AtlasEntity entity) throws AtlasBaseException { + return null; + } + + @Override + public EntityMutationResponse deleteByUniqueAttribute(final String typeName, final String attributeName, final String attributeValue) throws AtlasBaseException { + return null; + } + + @Override + public EntityMutationResponse batchMutate(final EntityMutations mutations) throws AtlasBaseException { + return null; + } + + + @Override + public void addClassifications(final String guid, final List<AtlasClassification> classification) throws AtlasBaseException { + + } + + @Override + public void updateClassifications(final String guid, final List<AtlasClassification> classification) throws AtlasBaseException { + + } + + @Override + public void deleteClassifications(final String guid, final List<String> classificationNames) throws AtlasBaseException { + + } + + @Override + public AtlasEntity.AtlasEntities searchEntities(final SearchFilter searchFilter) throws AtlasBaseException { + return null; + } +} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/0c746895/webapp/pom.xml ---------------------------------------------------------------------- diff --git a/webapp/pom.xml b/webapp/pom.xml index 82f307c..6dbd484 100755 --- a/webapp/pom.xml +++ b/webapp/pom.xml @@ -347,6 +347,14 @@ <classifier>tests</classifier> <scope>test</scope> </dependency> + + <dependency> + <groupId>org.apache.atlas</groupId> + <artifactId>atlas-intg</artifactId> + <classifier>tests</classifier> + <scope>test</scope> + </dependency> + </dependencies> <build> http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/0c746895/webapp/src/main/java/org/apache/atlas/web/rest/EntitiesREST.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/rest/EntitiesREST.java b/webapp/src/main/java/org/apache/atlas/web/rest/EntitiesREST.java new file mode 100644 index 0000000..543cbe2 --- /dev/null +++ b/webapp/src/main/java/org/apache/atlas/web/rest/EntitiesREST.java @@ -0,0 +1,128 @@ +/** + * 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.web.rest; + +import com.google.inject.Inject; +import org.apache.atlas.exception.AtlasBaseException; +import org.apache.atlas.model.SearchFilter; +import org.apache.atlas.model.instance.AtlasClassification; +import org.apache.atlas.model.instance.AtlasEntity; +import org.apache.atlas.model.instance.EntityMutationResponse; +import org.apache.atlas.repository.store.graph.AtlasEntityStore; +import org.apache.atlas.services.MetadataService; +import org.apache.atlas.type.AtlasTypeRegistry; +import org.apache.atlas.typesystem.types.TypeSystem; +import org.apache.atlas.web.util.Servlets; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.inject.Singleton; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import java.util.List; + + +@Path("v2/entities") +@Singleton +public class EntitiesREST { + private static final Logger LOG = LoggerFactory.getLogger(EntitiesREST.class); + + private AtlasEntityStore entitiesStore; + + @Context + private HttpServletRequest httpServletRequest; + + @Inject + private MetadataService metadataService; + + private TypeSystem typeSystem = TypeSystem.getInstance(); + + + + @Inject + public EntitiesREST(AtlasEntityStore entitiesStore, AtlasTypeRegistry atlasTypeRegistry) { + LOG.info("EntitiesRest Init"); + this.entitiesStore = entitiesStore; + } + + /******* + * Entity Creation/Updation if it already exists in ATLAS + * An existing entity is matched by its guid if supplied or by its unique attribute eg: qualifiedName + * Any associations like Classifications, Business Terms will have to be handled through the respective APIs + *******/ + + @POST + @Consumes(Servlets.JSON_MEDIA_TYPE) + @Produces(Servlets.JSON_MEDIA_TYPE) + public EntityMutationResponse createOrUpdate(List<AtlasEntity> entities) throws AtlasBaseException { + return null; + } + + /******* + * Entity Updation - Allows full update of the specified entities. + * Any associations like Classifications, Business Terms will have to be handled through the respective APIs + * Null updates are supported i.e Set an attribute value to Null if its an optional attribute + *******/ + @PUT + @Consumes(Servlets.JSON_MEDIA_TYPE) + @Produces(Servlets.JSON_MEDIA_TYPE) + public EntityMutationResponse update(List<AtlasEntity> entities) throws AtlasBaseException { + return null; + } + + @GET + @Path("/guids") + @Consumes(Servlets.JSON_MEDIA_TYPE) + @Produces(Servlets.JSON_MEDIA_TYPE) + public EntityMutationResponse getById(@QueryParam("guid") List<String> guids) throws AtlasBaseException { + return null; + } + + /******* + * Entity Delete + *******/ + + @DELETE + @Path("/guids") + @Consumes(Servlets.JSON_MEDIA_TYPE) + @Produces(Servlets.JSON_MEDIA_TYPE) + public EntityMutationResponse deleteById(@QueryParam("guid") List<String> guids) throws AtlasBaseException { + return null; + } + + /** + * Bulk retrieval API for searching on entities by certain predefined attributes ( typeName, superType, name, qualifiedName etc) + optional user defined attributes + * + * @throws AtlasBaseException + */ + @GET + @Produces(Servlets.JSON_MEDIA_TYPE) + public AtlasEntity.AtlasEntities searchEntities() throws AtlasBaseException { + //SearchFilter searchFilter + return null; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/0c746895/webapp/src/main/java/org/apache/atlas/web/rest/EntityRest.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/rest/EntityRest.java b/webapp/src/main/java/org/apache/atlas/web/rest/EntityRest.java new file mode 100644 index 0000000..df5138e --- /dev/null +++ b/webapp/src/main/java/org/apache/atlas/web/rest/EntityRest.java @@ -0,0 +1,217 @@ +/** + * 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.web.rest; + +import org.apache.atlas.model.instance.AtlasClassification; +import org.apache.atlas.model.instance.AtlasEntity; +import org.apache.atlas.model.instance.EntityMutationResponse; +import org.apache.atlas.web.util.Servlets; + +import javax.inject.Singleton; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import java.util.List; + +/** + * REST for a single entity + */ +@Path("v2/entity") +@Singleton +public class EntityRest { + + /** + * Create or Update an entity if it already exists + * + * @param entity The updated entity + * @return + */ + @POST + @Consumes({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON}) + @Produces(Servlets.JSON_MEDIA_TYPE) + public EntityMutationResponse createOrUpdate(AtlasEntity entity) { + return null; + } + + /** + * Complete Update of an entity identified by its GUID + * + * @param guid + * @param entity The updated entity + * @return + */ + @PUT + @Path("guid/{guid}") + @Consumes({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON}) + @Produces(Servlets.JSON_MEDIA_TYPE) + public EntityMutationResponse updateByGuid(@PathParam("guid") String guid, AtlasEntity entity, @DefaultValue("false") @QueryParam("partialUpdate") boolean partialUpdate) { + return null; + } + + + /** + * Fetch the complete definition of an entity given its GUID. + * + * @param guid GUID for the entity + */ + @GET + @Path("/guid/{guid}") + @Produces(Servlets.JSON_MEDIA_TYPE) + public AtlasEntity getByGuid(@PathParam("guid") String guid) { + return null; + } + + + /** + * Delete an entity identified by its GUID + * + * @param guid + * @return + */ + @DELETE + @Path("guid/{guid}") + @Consumes({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON}) + @Produces(Servlets.JSON_MEDIA_TYPE) + public EntityMutationResponse deleteByGuid(@PathParam("guid") String guid) { + return null; + } + + + /******* + * Entity Partial Update - Allows a subset of attributes to be updated on + * an entity which is identified by its type and unique attribute eg: Referenceable.qualifiedName. + * Null updates are not possible + *******/ + + @Deprecated + @PUT + @Consumes(Servlets.JSON_MEDIA_TYPE) + @Produces(Servlets.JSON_MEDIA_TYPE) + @Path("/uniqueAttribute/type/{typeName}/attribute/{attrName}") + public EntityMutationResponse partialUpdateByUniqueAttribute(@PathParam("typeName") String entityType, + @PathParam("attrName") String attribute, + @QueryParam("value") String value, AtlasEntity entity) throws Exception { + return null; + } + + @Deprecated + @DELETE + @Consumes(Servlets.JSON_MEDIA_TYPE) + @Produces(Servlets.JSON_MEDIA_TYPE) + @Path("/uniqueAttribute/type/{typeName}/attribute/{attrName}") + public EntityMutationResponse deleteByUniqueAttribute(@PathParam("typeName") String entityType, + @PathParam("attrName") String attribute, + @QueryParam("value") String value) throws Exception { + return null; + } + + /** + * Fetch the complete definition of an entity + * which is identified by its type and unique attribute eg: Referenceable.qualifiedName. + */ + @Deprecated + @GET + @Consumes({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON}) + @Produces(Servlets.JSON_MEDIA_TYPE) + @Path("/uniqueAttribute/type/{typeName}/attribute/{attrName}") + public AtlasEntity getByUniqueAttribute(@PathParam("typeName") String entityType, + @PathParam("attrName") String attribute, + @QueryParam("value") String value) { + return null; + } + + + /** + * Gets the list of classifications for a given entity represented by a guid. + * + * @param guid globally unique identifier for the entity + * @return a list of classifications for the given entity guid + */ + @GET + @Path("/guid/{guid}/classification/{classificationName}") + @Produces(Servlets.JSON_MEDIA_TYPE) + public AtlasClassification.AtlasClassifications getClassification(@PathParam("guid") String guid, @PathParam("classificationName") String classificationName) { + return null; + } + + + /** + * Gets the list of classifications for a given entity represented by a guid. + * + * @param guid globally unique identifier for the entity + * @return a list of classifications for the given entity guid + */ + @GET + @Path("/guid/{guid}/classifications") + @Produces(Servlets.JSON_MEDIA_TYPE) + public AtlasClassification.AtlasClassifications getClassifications(@PathParam("guid") String guid) { + return null; + } + + /** + * Classification management + */ + + /** + * Adds classifications to an existing entity represented by a guid. + * + * @param guid globally unique identifier for the entity + */ + @POST + @Path("/guid/{guid}/classifications") + @Consumes({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON}) + @Produces(Servlets.JSON_MEDIA_TYPE) + public void addClassifications(@PathParam("guid") final String guid, List<AtlasClassification> classifications) { + } + + /** + * Update classification(s) for an entity represented by a guid. + * Classifications are identified by their guid or name + * + * @param guid globally unique identifier for the entity + */ + @PUT + @Path("/guid/{guid}/classifications") + @Consumes({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON}) + @Produces(Servlets.JSON_MEDIA_TYPE) + public void updateClassifications(@PathParam("guid") final String guid, List<AtlasClassification> classifications) { + } + + /** + * Deletes a given classification from an existing entity represented by a guid. + * + * @param guid globally unique identifier for the entity + * @param classificationName name of the trait + */ + @DELETE + @Path("/guid/{guid}/classification/{classificationName}") + @Consumes({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON}) + @Produces(Servlets.JSON_MEDIA_TYPE) + public void deleteClassification(@PathParam("guid") String guid, + @PathParam("classificationName") String classificationName) { + } +}
