Commit 4925ec35 by Sarath Subramanian

ATLAS-3070: Create patch framework to persist typedef patches applied to atlas

parent 2e1c5634
{
"patches": [
{
"id": "TYPEDEF_PATCH_0000_001",
"description": "Add 'replicatedFrom' and 'replicatedTo' attributes to Referenceable",
"action": "ADD_ATTRIBUTE",
"typeName": "Referenceable",
"applyToVersion": "1.0",
......
{
"patches": [
{
"id": "TYPEDEF_PATCH_1000_033",
"description": "Add 'position' attribute to hive_column",
"action": "ADD_ATTRIBUTE",
"typeName": "hive_column",
"applyToVersion": "1.0",
......
{
"patches": [
{
"id": "TYPEDEF_PATCH_1000_034",
"description": "Add 'schemaAttributes' typeDefOptions to hive_column",
"action": "UPDATE_TYPEDEF_OPTIONS",
"typeName": "hive_column",
"applyToVersion": "1.1",
......@@ -10,6 +12,8 @@
}
},
{
"id": "TYPEDEF_PATCH_1000_035",
"description": "Add 'schemaElementsAttribute' typeDefOptions to hive_table",
"action": "UPDATE_TYPEDEF_OPTIONS",
"typeName": "hive_table",
"applyToVersion": "1.0",
......
{
"patches": [
{
"id": "TYPEDEF_PATCH_1000_036",
"description": "Update 'table' attribute in hive_column",
"action": "UPDATE_ATTRIBUTE",
"typeName": "hive_column",
"applyToVersion": "1.2",
......
{
"patches": [
{
"id": "TYPEDEF_PATCH_1000_037",
"description": "Add 'parameters', 'createTime' and 'modifiedTime' attributes to hbase_table",
"action": "ADD_ATTRIBUTE",
"typeName": "hbase_table",
"applyToVersion": "1.1",
......@@ -34,6 +36,8 @@
]
},
{
"id": "TYPEDEF_PATCH_1000_038",
"description": "Add 'createTime' and 'modifiedTime' attributes to hbase_column_family",
"action": "ADD_ATTRIBUTE",
"typeName": "hbase_column_family",
"applyToVersion": "1.0",
......
{
"patches": [
{
"id": "TYPEDEF_PATCH_1000_039",
"description": "Add attributes to hbase_table",
"action": "ADD_ATTRIBUTE",
"typeName": "hbase_table",
"applyToVersion": "1.2",
......@@ -59,6 +61,8 @@
]
},
{
"id": "TYPEDEF_PATCH_1000_040",
"description": "Add attributes to hbase_column_family",
"action": "ADD_ATTRIBUTE",
"typeName": "hbase_column_family",
"applyToVersion": "1.1",
......
{
"patches": [
{
"id": "TYPEDEF_PATCH_1000_041",
"description": "Add 'partitionCount' attribute to kafka_topic",
"action": "ADD_ATTRIBUTE",
"typeName": "kafka_topic",
"applyToVersion": "1.0",
......
{
"patches": [
{
"id": "TYPEDEF_PATCH_1000_096",
"description": "Remove legacy reference attribute 'db' from hive_table",
"action": "REMOVE_LEGACY_REF_ATTRIBUTES",
"typeName": "hive_table_db",
"applyToVersion": "1.1",
......@@ -10,6 +12,8 @@
}
},
{
"id": "TYPEDEF_PATCH_1000_097",
"description": "Remove legacy reference attribute 'columns' from hive_table",
"action": "REMOVE_LEGACY_REF_ATTRIBUTES",
"typeName": "hive_table_columns",
"applyToVersion": "1.1",
......@@ -19,6 +23,8 @@
}
},
{
"id": "TYPEDEF_PATCH_1000_098",
"description": "Remove legacy reference attribute 'partitionkeys' from hive_table",
"action": "REMOVE_LEGACY_REF_ATTRIBUTES",
"typeName": "hive_table_partitionkeys",
"applyToVersion": "1.1",
......@@ -28,6 +34,8 @@
}
},
{
"id": "TYPEDEF_PATCH_1000_099",
"description": "Remove legacy reference attribute 'sd' from hive_table",
"action": "REMOVE_LEGACY_REF_ATTRIBUTES",
"typeName": "hive_table_storagedesc",
"applyToVersion": "1.1",
......@@ -37,6 +45,8 @@
}
},
{
"id": "TYPEDEF_PATCH_1000_100",
"description": "Remove legacy reference attribute 'query' from hive_column_lineage",
"action": "REMOVE_LEGACY_REF_ATTRIBUTES",
"typeName": "hive_process_column_lineage",
"applyToVersion": "1.1",
......
{
"patches": [
{
"id": "TYPEDEF_PATCH_2000_101",
"description": "Add 'schemaAttributes' typeDefOptions to rdbms_column",
"action": "UPDATE_TYPEDEF_OPTIONS",
"typeName": "rdbms_column",
"applyToVersion": "1.1",
......@@ -10,6 +12,8 @@
}
},
{
"id": "TYPEDEF_PATCH_2000_102",
"description": "Add 'schemaElementsAttribute' typeDefOptions to rdbms_table",
"action": "UPDATE_TYPEDEF_OPTIONS",
"typeName": "rdbms_table",
"applyToVersion": "1.1",
......
{
"patches": [
{
"id": "TYPEDEF_PATCH_2000_103",
"description": "Set serviceType 'rdbms' to rdbms_instance",
"action": "SET_SERVICE_TYPE",
"typeName": "rdbms_instance",
"applyToVersion": "1.1",
......@@ -8,6 +10,8 @@
"serviceType": "rdbms"
},
{
"id": "TYPEDEF_PATCH_2000_104",
"description": "Set serviceType 'rdbms' to rdbms_db",
"action": "SET_SERVICE_TYPE",
"typeName": "rdbms_db",
"applyToVersion": "1.1",
......@@ -15,6 +19,8 @@
"serviceType": "rdbms"
},
{
"id": "TYPEDEF_PATCH_2000_105",
"description": "Set serviceType 'rdbms' to rdbms_table",
"action": "SET_SERVICE_TYPE",
"typeName": "rdbms_table",
"applyToVersion": "1.2",
......@@ -22,6 +28,8 @@
"serviceType": "rdbms"
},
{
"id": "TYPEDEF_PATCH_2000_106",
"description": "Set serviceType 'rdbms' to rdbms_column",
"action": "SET_SERVICE_TYPE",
"typeName": "rdbms_column",
"applyToVersion": "1.2",
......@@ -29,6 +37,8 @@
"serviceType": "rdbms"
},
{
"id": "TYPEDEF_PATCH_2000_107",
"description": "Set serviceType 'rdbms' to rdbms_index",
"action": "SET_SERVICE_TYPE",
"typeName": "rdbms_index",
"applyToVersion": "1.1",
......@@ -36,6 +46,8 @@
"serviceType": "rdbms"
},
{
"id": "TYPEDEF_PATCH_2000_108",
"description": "Set serviceType 'rdbms' to rdbms_foreign_key",
"action": "SET_SERVICE_TYPE",
"typeName": "rdbms_foreign_key",
"applyToVersion": "1.1",
......@@ -43,6 +55,8 @@
"serviceType": "rdbms"
},
{
"id": "TYPEDEF_PATCH_2000_109",
"description": "Set serviceType 'rdbms' to rdbms_instance_databases",
"action": "SET_SERVICE_TYPE",
"typeName": "rdbms_instance_databases",
"applyToVersion": "1.0",
......@@ -50,6 +64,8 @@
"serviceType": "rdbms"
},
{
"id": "TYPEDEF_PATCH_2000_110",
"description": "Set serviceType 'rdbms' to rdbms_db_tables",
"action": "SET_SERVICE_TYPE",
"typeName": "rdbms_db_tables",
"applyToVersion": "1.0",
......@@ -57,6 +73,8 @@
"serviceType": "rdbms"
},
{
"id": "TYPEDEF_PATCH_2000_111",
"description": "Set serviceType 'rdbms' to rdbms_table_columns",
"action": "SET_SERVICE_TYPE",
"typeName": "rdbms_table_columns",
"applyToVersion": "1.0",
......@@ -64,6 +82,8 @@
"serviceType": "rdbms"
},
{
"id": "TYPEDEF_PATCH_2000_112",
"description": "Set serviceType 'rdbms' to rdbms_table_indexes",
"action": "SET_SERVICE_TYPE",
"typeName": "rdbms_table_indexes",
"applyToVersion": "1.0",
......@@ -71,6 +91,8 @@
"serviceType": "rdbms"
},
{
"id": "TYPEDEF_PATCH_2000_113",
"description": "Set serviceType 'rdbms' to rdbms_index_columns",
"action": "SET_SERVICE_TYPE",
"typeName": "rdbms_index_columns",
"applyToVersion": "1.0",
......@@ -78,6 +100,8 @@
"serviceType": "rdbms"
},
{
"id": "TYPEDEF_PATCH_2000_114",
"description": "Set serviceType 'rdbms' to rdbms_table_foreign_key",
"action": "SET_SERVICE_TYPE",
"typeName": "rdbms_table_foreign_key",
"applyToVersion": "1.0",
......@@ -85,6 +109,8 @@
"serviceType": "rdbms"
},
{
"id": "TYPEDEF_PATCH_2000_115",
"description": "Set serviceType 'rdbms' to rdbms_foreign_key_key_columns",
"action": "SET_SERVICE_TYPE",
"typeName": "rdbms_foreign_key_key_columns",
"applyToVersion": "1.0",
......@@ -92,6 +118,8 @@
"serviceType": "rdbms"
},
{
"id": "TYPEDEF_PATCH_2000_116",
"description": "Set serviceType 'rdbms' to rdbms_foreign_key_table_references",
"action": "SET_SERVICE_TYPE",
"typeName": "rdbms_foreign_key_table_references",
"applyToVersion": "1.0",
......@@ -99,6 +127,8 @@
"serviceType": "rdbms"
},
{
"id": "TYPEDEF_PATCH_2000_117",
"description": "Set serviceType 'rdbms' to rdbms_foreign_key_column_references",
"action": "SET_SERVICE_TYPE",
"typeName": "rdbms_foreign_key_column_references",
"applyToVersion": "1.0",
......
{
"patches": [
{
"id": "TYPEDEF_PATCH_2000_118",
"description": "Remove legacy reference attribute 'databases' from rdbms_instance",
"action": "REMOVE_LEGACY_REF_ATTRIBUTES",
"typeName": "rdbms_instance_databases",
"applyToVersion": "1.1",
......@@ -11,6 +13,8 @@
}
},
{
"id": "TYPEDEF_PATCH_2000_119",
"description": "Remove legacy reference attribute 'tables' from rdbms_db",
"action": "REMOVE_LEGACY_REF_ATTRIBUTES",
"typeName": "rdbms_db_tables",
"applyToVersion": "1.1",
......@@ -21,6 +25,8 @@
}
},
{
"id": "TYPEDEF_PATCH_2000_120",
"description": "Remove legacy reference attribute 'columns' from rdbms_table",
"action": "REMOVE_LEGACY_REF_ATTRIBUTES",
"typeName": "rdbms_table_columns",
"applyToVersion": "1.1",
......@@ -31,6 +37,8 @@
}
},
{
"id": "TYPEDEF_PATCH_2000_121",
"description": "Remove legacy reference attribute 'indexes' from rdbms_table",
"action": "REMOVE_LEGACY_REF_ATTRIBUTES",
"typeName": "rdbms_table_indexes",
"applyToVersion": "1.1",
......@@ -41,6 +49,8 @@
}
},
{
"id": "TYPEDEF_PATCH_2000_122",
"description": "Remove legacy reference attribute 'foreign_keys' from rdbms_table",
"action": "REMOVE_LEGACY_REF_ATTRIBUTES",
"typeName": "rdbms_table_foreign_key",
"applyToVersion": "1.1",
......@@ -51,6 +61,8 @@
}
},
{
"id": "TYPEDEF_PATCH_2000_123",
"description": "Remove legacy reference attribute 'columns' from rdbms_index",
"action": "REMOVE_LEGACY_REF_ATTRIBUTES",
"typeName": "rdbms_index_columns",
"applyToVersion": "1.1",
......@@ -60,6 +72,8 @@
}
},
{
"id": "TYPEDEF_PATCH_2000_124",
"description": "Remove legacy reference attribute 'key_columns' from rdbms_foreign_key",
"action": "REMOVE_LEGACY_REF_ATTRIBUTES",
"typeName": "rdbms_foreign_key_key_columns",
"applyToVersion": "1.1",
......@@ -69,6 +83,8 @@
}
},
{
"id": "TYPEDEF_PATCH_2000_125",
"description": "Remove legacy reference attribute 'references_table' from rdbms_foreign_key",
"action": "REMOVE_LEGACY_REF_ATTRIBUTES",
"typeName": "rdbms_foreign_key_table_references",
"applyToVersion": "1.1",
......@@ -78,6 +94,8 @@
}
},
{
"id": "TYPEDEF_PATCH_2000_126",
"description": "Remove legacy reference attribute 'references_columns' from rdbms_foreign_key",
"action": "REMOVE_LEGACY_REF_ATTRIBUTES",
"typeName": "rdbms_foreign_key_column_references",
"applyToVersion": "1.1",
......
{
"patches": [
{
"id": "TYPEDEF_PATCH_3000_127",
"description": "Set serviceType 'aws' to aws_tag",
"action": "SET_SERVICE_TYPE",
"typeName": "aws_tag",
"applyToVersion": "1.0",
......@@ -8,6 +10,8 @@
"serviceType": "aws"
},
{
"id": "TYPEDEF_PATCH_3000_128",
"description": "Set serviceType 'aws' to aws_cloud_watch_metric",
"action": "SET_SERVICE_TYPE",
"typeName": "aws_cloud_watch_metric",
"applyToVersion": "1.0",
......@@ -15,6 +19,8 @@
"serviceType": "aws"
},
{
"id": "TYPEDEF_PATCH_3000_129",
"description": "Set serviceType 'aws' to aws_s3_bucket_lifeCycleRule",
"action": "SET_SERVICE_TYPE",
"typeName": "aws_s3_bucket_lifeCycleRule",
"applyToVersion": "1.0",
......@@ -22,6 +28,8 @@
"serviceType": "aws"
},
{
"id": "TYPEDEF_PATCH_3000_130",
"description": "Set serviceType 'aws' to aws_s3_access_policy",
"action": "SET_SERVICE_TYPE",
"typeName": "aws_s3_access_policy",
"applyToVersion": "1.0",
......@@ -29,6 +37,8 @@
"serviceType": "aws"
},
{
"id": "TYPEDEF_PATCH_3000_131",
"description": "Set serviceType 'aws' to aws_s3_object",
"action": "SET_SERVICE_TYPE",
"typeName": "aws_s3_object",
"applyToVersion": "1.0",
......@@ -36,6 +46,8 @@
"serviceType": "aws"
},
{
"id": "TYPEDEF_PATCH_3000_132",
"description": "Set serviceType 'aws' to aws_s3_pseudo_dir",
"action": "SET_SERVICE_TYPE",
"typeName": "aws_s3_pseudo_dir",
"applyToVersion": "1.0",
......@@ -43,6 +55,8 @@
"serviceType": "aws"
},
{
"id": "TYPEDEF_PATCH_3000_133",
"description": "Set serviceType 'aws' to aws_s3_bucket",
"action": "SET_SERVICE_TYPE",
"typeName": "aws_s3_bucket",
"applyToVersion": "1.0",
......@@ -50,6 +64,8 @@
"serviceType": "aws"
},
{
"id": "TYPEDEF_PATCH_3000_134",
"description": "Set serviceType 'aws' to aws_s3_bucket_aws_s3_pseudo_dirs",
"action": "SET_SERVICE_TYPE",
"typeName": "aws_s3_bucket_aws_s3_pseudo_dirs",
"applyToVersion": "1.0",
......@@ -57,6 +73,8 @@
"serviceType": "aws"
},
{
"id": "TYPEDEF_PATCH_3000_135",
"description": "Set serviceType 'aws' to aws_s3_pseudo_dir_aws_objects",
"action": "SET_SERVICE_TYPE",
"typeName": "aws_s3_pseudo_dir_aws_objects",
"applyToVersion": "1.0",
......@@ -64,6 +82,8 @@
"serviceType": "aws"
},
{
"id": "TYPEDEF_PATCH_3000_136",
"description": "Set serviceType 'aws' to aws_s3_object_avro_schema",
"action": "SET_SERVICE_TYPE",
"typeName": "aws_s3_object_avro_schema",
"applyToVersion": "1.0",
......@@ -71,6 +91,8 @@
"serviceType": "aws"
},
{
"id": "TYPEDEF_PATCH_3000_137",
"description": "Set serviceType 'aws' to aws_s3_pseudo_dir_avro_schema",
"action": "SET_SERVICE_TYPE",
"typeName": "aws_s3_pseudo_dir_avro_schema",
"applyToVersion": "1.0",
......
......@@ -86,6 +86,15 @@ public final class Constants {
public static final String MODIFIED_BY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "modifiedBy");
/**
* Patch vertices property keys.
*/
public static final String PATCH_ID_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "patch.id");
public static final String PATCH_DESCRIPTION_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "patch.description");
public static final String PATCH_TYPE_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "patch.type");
public static final String PATCH_ACTION_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "patch.action");
public static final String PATCH_STATE_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "patch.state");
/**
* The homeId field is used when saving into Atlas a copy of an object that is being imported from another
* repository. The homeId will be set to a String that identifies the other repository. The specific format
* of repository identifiers is domain dependent. Where it is set by Open Metadata Repository Services it will
......
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.model.patches;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.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.List;
import java.util.Objects;
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE;
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY;
/**
* Display all atlas patches.
*/
@JsonAutoDetect(getterVisibility = PUBLIC_ONLY, setterVisibility = PUBLIC_ONLY, fieldVisibility = NONE)
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
public class AtlasPatch implements Serializable {
private String id;
private String description;
private String type;
private String action;
private String updatedBy;
private String createdBy;
private long createdTime;
private long updatedTime;
private PatchStatus status;
public enum PatchStatus { APPLIED, SKIPPED, FAILED, UNKNOWN }
public AtlasPatch() { }
public AtlasPatch(String id, String patchName, String type, String action, PatchStatus status, String updatedBy,
String createdBy, long createdTime, long updatedTime) {
this.id = id;
this.description = patchName;
this.type = type;
this.action = action;
this.status = status;
this.updatedBy = updatedBy;
this.createdBy = createdBy;
this.createdTime = createdTime;
this.updatedTime = updatedTime;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
public PatchStatus getStatus() {
return status;
}
public void setStatus(PatchStatus status) {
this.status = status;
}
public String getUpdatedBy() {
return updatedBy;
}
public void setUpdatedBy(String updatedBy) {
this.updatedBy = updatedBy;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public long getCreatedTime() {
return createdTime;
}
public void setCreatedTime(long createdTime) {
this.createdTime = createdTime;
}
public long getUpdatedTime() {
return updatedTime;
}
public void setUpdatedTime(long updatedTime) {
this.updatedTime = updatedTime;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AtlasPatch that = (AtlasPatch) o;
return createdTime == that.createdTime &&
updatedTime == that.updatedTime &&
Objects.equals(id, that.id) &&
Objects.equals(description, that.description) &&
Objects.equals(type, that.type) &&
Objects.equals(action, that.action) &&
Objects.equals(updatedBy, that.updatedBy) &&
Objects.equals(createdBy, that.createdBy) &&
status == that.status;
}
@Override
public int hashCode() {
return Objects.hash(id, description, type, action, updatedBy, createdBy, createdTime, updatedTime, status);
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("AtlasPatch{");
sb.append("id=").append(id);
sb.append(", description='").append(description).append('\'');
sb.append(", type='").append(type).append('\'');
sb.append(", action='").append(action).append('\'');
sb.append(", updatedBy='").append(updatedBy).append('\'');
sb.append(", createdBy='").append(createdBy).append('\'');
sb.append(", createdTime=").append(createdTime);
sb.append(", updatedTime=").append(updatedTime);
sb.append(", status=").append(status);
sb.append('}');
return sb.toString();
}
@JsonAutoDetect(getterVisibility = PUBLIC_ONLY, setterVisibility = PUBLIC_ONLY, fieldVisibility = NONE)
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
public static class AtlasPatches implements Serializable {
private List<AtlasPatch> patches;
public AtlasPatches(List<AtlasPatch> patches) {
this.patches = patches;
}
public AtlasPatches() {
}
public List<AtlasPatch> getPatches() {
return patches;
}
public void setPatches(List<AtlasPatch> patches) {
this.patches = patches;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AtlasPatches that = (AtlasPatches) o;
return Objects.equals(patches, that.patches);
}
@Override
public int hashCode() {
return Objects.hash(patches);
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("AtlasPatches{");
sb.append("patches=").append(patches);
sb.append('}');
return sb.toString();
}
}
}
\ No newline at end of file
......@@ -332,6 +332,8 @@ public class AtlasTypeUtil {
if (typeDef != null) {
if (typeDef.getClass().equals(AtlasEntityDef.class)) {
ret.getEntityDefs().add((AtlasEntityDef) typeDef);
} else if (typeDef.getClass().equals(AtlasRelationshipDef.class)) {
ret.getRelationshipDefs().add((AtlasRelationshipDef) typeDef);
} else if (typeDef.getClass().equals(AtlasClassificationDef.class)) {
ret.getClassificationDefs().add((AtlasClassificationDef) typeDef);
} else if (typeDef.getClass().equals(AtlasStructDef.class)) {
......
......@@ -280,6 +280,12 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang
createVertexIndex(management, TRAIT_NAMES_PROPERTY_KEY, UniqueKind.NONE, String.class, SET, true, true);
createVertexIndex(management, PROPAGATED_TRAIT_NAMES_PROPERTY_KEY, UniqueKind.NONE, String.class, LIST, true, true);
createVertexIndex(management, PATCH_ID_PROPERTY_KEY, UniqueKind.GLOBAL_UNIQUE, String.class, SINGLE, true, false);
createVertexIndex(management, PATCH_DESCRIPTION_PROPERTY_KEY, UniqueKind.NONE, String.class, SINGLE, true, false);
createVertexIndex(management, PATCH_TYPE_PROPERTY_KEY, UniqueKind.NONE, String.class, SINGLE, true, false);
createVertexIndex(management, PATCH_ACTION_PROPERTY_KEY, UniqueKind.NONE, String.class, SINGLE, true, false);
createVertexIndex(management, PATCH_STATE_PROPERTY_KEY, UniqueKind.NONE, String.class, SINGLE, true, false);
// create vertex-centric index
createVertexCentricIndex(management, CLASSIFICATION_LABEL, AtlasEdgeDirection.BOTH, CLASSIFICATION_EDGE_NAME_PROPERTY_KEY, String.class, SINGLE);
createVertexCentricIndex(management, CLASSIFICATION_LABEL, AtlasEdgeDirection.BOTH, CLASSIFICATION_EDGE_IS_PROPAGATED_PROPERTY_KEY, Boolean.class, SINGLE);
......
......@@ -23,10 +23,14 @@ import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.GraphTransactionInterceptor;
import org.apache.atlas.RequestContext;
import org.apache.atlas.SortOrder;
import org.apache.atlas.annotation.GraphTransaction;
import org.apache.atlas.discovery.SearchProcessor;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.patches.AtlasPatch;
import org.apache.atlas.model.patches.AtlasPatch.AtlasPatches;
import org.apache.atlas.model.patches.AtlasPatch.PatchStatus;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graph.AtlasGraphProvider;
......@@ -35,12 +39,14 @@ import org.apache.atlas.repository.graphdb.AtlasEdge;
import org.apache.atlas.repository.graphdb.AtlasElement;
import org.apache.atlas.repository.graphdb.AtlasGraphQuery;
import org.apache.atlas.repository.graphdb.AtlasIndexQuery;
import org.apache.atlas.repository.graphdb.AtlasIndexQuery.Result;
import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasStructType;
import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.utils.AtlasPerfMetrics.MetricRecorder;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.StringUtils;
......@@ -51,13 +57,25 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.apache.atlas.model.patches.AtlasPatch.PatchStatus.UNKNOWN;
import static org.apache.atlas.repository.Constants.CREATED_BY_KEY;
import static org.apache.atlas.repository.Constants.INDEX_SEARCH_VERTEX_PREFIX_DEFAULT;
import static org.apache.atlas.repository.Constants.INDEX_SEARCH_VERTEX_PREFIX_PROPERTY;
import static org.apache.atlas.repository.Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.MODIFIED_BY_KEY;
import static org.apache.atlas.repository.Constants.PATCH_ACTION_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.PATCH_ID_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.PATCH_DESCRIPTION_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.PATCH_STATE_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.PATCH_TYPE_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.TIMESTAMP_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.VERTEX_INDEX;
import static org.apache.atlas.repository.graphdb.AtlasGraphQuery.SortOrder.*;
/**
......@@ -320,6 +338,22 @@ public class AtlasGraphUtilsV2 {
return vertex;
}
public static AtlasVertex findByPatchId(String patchId) {
AtlasVertex ret = null;
String indexQuery = getIndexSearchPrefix() + "\"" + PATCH_ID_PROPERTY_KEY + "\" : ("+ patchId +")";
Iterator<Result<Object, Object>> results = AtlasGraphProvider.getGraphInstance().indexQuery(VERTEX_INDEX, indexQuery).vertices();
while (results != null && results.hasNext()) {
ret = results.next().getVertex();
if (ret != null) {
break;
}
}
return ret;
}
public static AtlasVertex findByGuid(String guid) {
AtlasVertex ret = GraphTransactionInterceptor.getVertexFromCache(guid);
......@@ -433,6 +467,64 @@ public class AtlasGraphUtilsV2 {
return vertex;
}
public static Map<String, PatchStatus> initPatchesRegistry() {
Map<String, PatchStatus> ret = new HashMap<>();
AtlasPatches patches = getPatches();
for (AtlasPatch patch : patches.getPatches()) {
String patchId = patch.getId();
PatchStatus patchStatus = patch.getStatus();
if (patchId != null && patchStatus != null) {
ret.put(patchId, patchStatus);
}
}
return ret;
}
public static AtlasPatches getPatches() {
List<AtlasPatch> patches = new ArrayList<>();
String indexQuery = getIndexSearchPrefix() + "\"" + PATCH_ID_PROPERTY_KEY + "\" : (*)";
Iterator<Result<Object, Object>> results = AtlasGraphProvider.getGraphInstance().indexQuery(VERTEX_INDEX, indexQuery).vertices();
while (results != null && results.hasNext()) {
AtlasVertex patchVertex = results.next().getVertex();
AtlasPatch patch = toAtlasPatch(patchVertex);
patches.add(patch);
}
// Sort the patches based on patch id
if (CollectionUtils.isNotEmpty(patches)) {
Collections.sort(patches, (p1, p2) -> p1.getId().compareTo(p2.getId()));
}
return new AtlasPatches(patches);
}
private static AtlasPatch toAtlasPatch(AtlasVertex vertex) {
AtlasPatch ret = new AtlasPatch();
ret.setId(getEncodedProperty(vertex, PATCH_ID_PROPERTY_KEY, String.class));
ret.setDescription(getEncodedProperty(vertex, PATCH_DESCRIPTION_PROPERTY_KEY, String.class));
ret.setType(getEncodedProperty(vertex, PATCH_TYPE_PROPERTY_KEY, String.class));
ret.setAction(getEncodedProperty(vertex, PATCH_ACTION_PROPERTY_KEY, String.class));
ret.setCreatedBy(getEncodedProperty(vertex, CREATED_BY_KEY, String.class));
ret.setUpdatedBy(getEncodedProperty(vertex, MODIFIED_BY_KEY, String.class));
ret.setCreatedTime(getEncodedProperty(vertex, TIMESTAMP_PROPERTY_KEY, Long.class));
ret.setUpdatedTime(getEncodedProperty(vertex, MODIFICATION_TIMESTAMP_PROPERTY_KEY, Long.class));
ret.setStatus(getPatchStatus(vertex));
return ret;
}
private static PatchStatus getPatchStatus(AtlasVertex vertex) {
String patchStatus = AtlasGraphUtilsV2.getEncodedProperty(vertex, PATCH_STATE_PROPERTY_KEY, String.class);
return patchStatus != null ? PatchStatus.valueOf(patchStatus) : UNKNOWN;
}
public static List<String> findEntityGUIDsByType(String typename, SortOrder sortOrder) {
AtlasGraphQuery query = AtlasGraphProvider.getGraphInstance().query()
.has(Constants.ENTITY_TYPE_PROPERTY_KEY, typename);
......@@ -555,8 +647,8 @@ public class AtlasGraphUtilsV2 {
String propertyName = attribute.getVertexPropertyName();
AtlasIndexQuery query = getIndexQuery(entityType, propertyName, attrVal.toString());
for (Iterator<AtlasIndexQuery.Result> iter = query.vertices(); iter.hasNext(); ) {
AtlasIndexQuery.Result result = iter.next();
for (Iterator<Result> iter = query.vertices(); iter.hasNext(); ) {
Result result = iter.next();
AtlasVertex vertex = result.getVertex();
// skip non-entity vertices, if any got returned
......
......@@ -534,7 +534,7 @@ public class AtlasTypeDefGraphStoreV2 extends AtlasTypeDefGraphStore {
vertex.setProperty(Constants.VERSION_PROPERTY_KEY, newVersion);
}
private String getCurrentUser() {
public static String getCurrentUser() {
String ret = RequestContext.getCurrentUser();
if (StringUtils.isBlank(ret)) {
......
......@@ -28,7 +28,6 @@ import org.apache.atlas.authorize.AtlasPrivilege;
import org.apache.atlas.authorize.AtlasAuthorizationUtils;
import org.apache.atlas.discovery.SearchContext;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.discovery.AtlasSearchResult;
import org.apache.atlas.model.impexp.AtlasServer;
import org.apache.atlas.model.impexp.AtlasExportRequest;
import org.apache.atlas.model.impexp.AtlasExportResult;
......@@ -39,6 +38,7 @@ import org.apache.atlas.model.impexp.MigrationStatus;
import org.apache.atlas.model.instance.AtlasCheckStateRequest;
import org.apache.atlas.model.instance.AtlasCheckStateResult;
import org.apache.atlas.model.metrics.AtlasMetrics;
import org.apache.atlas.model.patches.AtlasPatch.AtlasPatches;
import org.apache.atlas.repository.impexp.AtlasServerService;
import org.apache.atlas.repository.impexp.ExportImportAuditService;
import org.apache.atlas.repository.impexp.ExportService;
......@@ -47,6 +47,7 @@ import org.apache.atlas.repository.impexp.MigrationProgressService;
import org.apache.atlas.repository.impexp.ZipSink;
import org.apache.atlas.repository.impexp.ZipSource;
import org.apache.atlas.repository.store.graph.AtlasEntityStore;
import org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2;
import org.apache.atlas.services.MetricsService;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
......@@ -555,6 +556,23 @@ public class AdminResource {
}
}
@GET
@Path("patches")
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasPatches getAtlasPatches() {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AdminResource.getAtlasPatches()");
}
AtlasPatches ret = AtlasGraphUtilsV2.getPatches();
if (LOG.isDebugEnabled()) {
LOG.debug("<== AdminResource.getAtlasPatches()");
}
return ret;
}
private String getEditableEntityTypes(Configuration config) {
String ret = DEFAULT_EDITABLE_ENTITY_TYPES;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment