Skip to content

Commit ad8592d

Browse files
author
chaitalithombare
committed
ATLAS-5017: Patch to replace the long strings set in spark_process attributes
1 parent c4c4cf2 commit ad8592d

File tree

3 files changed

+113
-1
lines changed

3 files changed

+113
-1
lines changed

intg/src/main/java/org/apache/atlas/AtlasConfiguration.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ public enum AtlasConfiguration {
111111
ATLAS_AUDIT_DEFAULT_AGEOUT_IGNORE_TTL("atlas.audit.default.ageout.ignore.ttl", false),
112112
ATLAS_AUDIT_AGING_TTL_TEST_AUTOMATION("atlas.audit.aging.ttl.test.automation", false), //Only for test automation
113113
RELATIONSHIP_SEARCH_ENABLED("atlas.relationship.search.enabled", false),
114-
UI_TASKS_TAB_USE_ENABLED("atlas.tasks.ui.tab.enabled", false);
114+
UI_TASKS_TAB_USE_ENABLED("atlas.tasks.ui.tab.enabled", false),
115+
REPLACE_HUGE_SPARK_PROCESS_ATTRIBUTES_PATCH("atlas.process.spark.attributes.update.patch", false);
115116

116117
private static final Configuration APPLICATION_PROPERTIES;
117118

repository/src/main/java/org/apache/atlas/repository/patches/AtlasPatchManager.java

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ private void init() {
111111
handlers.add(new UpdateCompositeIndexStatusPatch(context));
112112
handlers.add(new RelationshipTypeNamePatch(context));
113113
handlers.add(new ProcessImpalaNamePatch(context));
114+
handlers.add(new ReplaceHugeSparkProcessAttributesPatch(context));
114115

115116
LOG.info("<== AtlasPatchManager.init()");
116117
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.atlas.repository.patches;
20+
21+
import org.apache.atlas.AtlasConfiguration;
22+
import org.apache.atlas.exception.AtlasBaseException;
23+
import org.apache.atlas.pc.WorkItemManager;
24+
import org.apache.atlas.repository.Constants;
25+
import org.apache.atlas.repository.graphdb.AtlasGraph;
26+
import org.apache.atlas.repository.graphdb.AtlasVertex;
27+
import org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2;
28+
import org.apache.atlas.type.AtlasEntityType;
29+
import org.slf4j.Logger;
30+
import org.slf4j.LoggerFactory;
31+
32+
import java.util.Iterator;
33+
34+
import static org.apache.atlas.model.patches.AtlasPatch.PatchStatus.APPLIED;
35+
36+
public class ReplaceHugeSparkProcessAttributesPatch extends AtlasPatchHandler {
37+
private static final Logger LOG = LoggerFactory.getLogger(ReplaceHugeSparkProcessAttributesPatch.class);
38+
39+
private static final String PATCH_ID = "JAVA_PATCH_0000_015";
40+
private static final String PATCH_DESCRIPTION = "Replace attributes details and sparkPlanDescription to null";
41+
42+
private final PatchContext context;
43+
44+
public ReplaceHugeSparkProcessAttributesPatch(PatchContext context) {
45+
super(context.getPatchRegistry(), PATCH_ID, PATCH_DESCRIPTION);
46+
47+
this.context = context;
48+
}
49+
50+
@Override
51+
public void apply() throws AtlasBaseException {
52+
if (AtlasConfiguration.REPLACE_HUGE_SPARK_PROCESS_ATTRIBUTES_PATCH.getBoolean() == false) {
53+
LOG.info("ReplaceHugeSparkProcessAttributesPatch: Skipped, since not enabled!");
54+
return;
55+
}
56+
ConcurrentPatchProcessor patchProcessor = new ReplaceHugeSparkProcessAttributesPatchProcessor(context);
57+
58+
patchProcessor.apply();
59+
60+
setStatus(APPLIED);
61+
62+
LOG.info("ReplaceHugeSparkProcessAttributesPatch.apply(): patchId={}, status={}", getPatchId(), getStatus());
63+
}
64+
65+
public static class ReplaceHugeSparkProcessAttributesPatchProcessor extends ConcurrentPatchProcessor {
66+
private static final String TYPE_NAME_SPARK_PROCESS = "spark_process";
67+
private static final String ATTR_NAME_DETAILS = "details";
68+
private static final String ATTR_NAME_SPARKPLANDESCRIPTION = "sparkPlanDescription";
69+
70+
public ReplaceHugeSparkProcessAttributesPatchProcessor(PatchContext context) {
71+
super(context);
72+
}
73+
74+
@Override
75+
protected void prepareForExecution() {
76+
}
77+
78+
@Override
79+
public void submitVerticesToUpdate(WorkItemManager manager) {
80+
AtlasGraph graph = getGraph();
81+
Iterable<Object> iterable = graph.query().has(Constants.ENTITY_TYPE_PROPERTY_KEY, TYPE_NAME_SPARK_PROCESS).vertexIds();
82+
int count = 0;
83+
84+
for (Iterator<Object> iter = iterable.iterator(); iter.hasNext(); ) {
85+
Object vertexId = iter.next();
86+
87+
manager.checkProduce(vertexId);
88+
89+
count++;
90+
91+
}
92+
93+
LOG.info("found {} entities of type {}", count, TYPE_NAME_SPARK_PROCESS);
94+
}
95+
96+
@Override
97+
protected void processVertexItem(Long vertexId, AtlasVertex vertex, String typeName, AtlasEntityType entityType) {
98+
LOG.debug("processItem(typeName={}, vertexId={})", typeName, vertexId);
99+
100+
try {
101+
AtlasGraphUtilsV2.setEncodedProperty(vertex, entityType.getVertexPropertyName(ATTR_NAME_DETAILS), null);
102+
AtlasGraphUtilsV2.setEncodedProperty(vertex, entityType.getVertexPropertyName(ATTR_NAME_SPARKPLANDESCRIPTION), null);
103+
} catch (AtlasBaseException e) {
104+
LOG.error("Error updating: {}", vertexId, e);
105+
}
106+
107+
LOG.debug("processItem(typeName={}, vertexId={}): Done!", typeName, vertexId);
108+
}
109+
}
110+
}

0 commit comments

Comments
 (0)