Skip to content

Commit 25e35e6

Browse files
chaitalicodchaitalithombare
andauthored
ATLAS-5017: Patch to replace the long strings set in spark_process attributes (#337)
Co-authored-by: chaitalithombare <chaitalithombare@apache.org>
1 parent 18e9325 commit 25e35e6

File tree

3 files changed

+111
-2
lines changed

3 files changed

+111
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ public enum AtlasConfiguration {
114114
UI_TASKS_TAB_USE_ENABLED("atlas.tasks.ui.tab.enabled", false),
115115
ATLAS_ASYNC_IMPORT_MIN_DURATION_OVERRIDE_TEST_AUTOMATION("atlas.async.import.min.duration.override.test.automation", false),
116116
ASYNC_IMPORT_TOPIC_PREFIX("atlas.async.import.topic.prefix", "ATLAS_IMPORT_"),
117-
ASYNC_IMPORT_REQUEST_ID_PREFIX("atlas.async.import.request_id.prefix", "async_import_");
118-
117+
ASYNC_IMPORT_REQUEST_ID_PREFIX("atlas.async.import.request_id.prefix", "async_import_"),
118+
REPLACE_HUGE_SPARK_PROCESS_ATTRIBUTES_PATCH("atlas.process.spark.attributes.update.patch", false);
119119
private static final Configuration APPLICATION_PROPERTIES;
120120

121121
private final String propertyName;

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

Lines changed: 1 addition & 0 deletions
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
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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.type.AtlasEntityType;
28+
import org.slf4j.Logger;
29+
import org.slf4j.LoggerFactory;
30+
31+
import java.util.Iterator;
32+
33+
import static org.apache.atlas.model.patches.AtlasPatch.PatchStatus.APPLIED;
34+
35+
public class ReplaceHugeSparkProcessAttributesPatch extends AtlasPatchHandler {
36+
private static final Logger LOG = LoggerFactory.getLogger(ReplaceHugeSparkProcessAttributesPatch.class);
37+
38+
private static final String PATCH_ID = "JAVA_PATCH_0000_015";
39+
private static final String PATCH_DESCRIPTION = "Replace attributes details and sparkPlanDescription to null";
40+
41+
private final PatchContext context;
42+
43+
public ReplaceHugeSparkProcessAttributesPatch(PatchContext context) {
44+
super(context.getPatchRegistry(), PATCH_ID, PATCH_DESCRIPTION);
45+
46+
this.context = context;
47+
}
48+
49+
@Override
50+
public void apply() throws AtlasBaseException {
51+
if (AtlasConfiguration.REPLACE_HUGE_SPARK_PROCESS_ATTRIBUTES_PATCH.getBoolean() == false) {
52+
LOG.info("ReplaceHugeSparkProcessAttributesPatch: Skipped, since not enabled!");
53+
return;
54+
}
55+
ConcurrentPatchProcessor patchProcessor = new ReplaceHugeSparkProcessAttributesPatchProcessor(context);
56+
57+
patchProcessor.apply();
58+
59+
setStatus(APPLIED);
60+
61+
LOG.info("ReplaceHugeSparkProcessAttributesPatch.apply(): patchId={}, status={}", getPatchId(), getStatus());
62+
}
63+
64+
public static class ReplaceHugeSparkProcessAttributesPatchProcessor extends ConcurrentPatchProcessor {
65+
private static final String TYPE_NAME_SPARK_PROCESS = "spark_process";
66+
private static final String ATTR_NAME_DETAILS = "details";
67+
private static final String ATTR_NAME_SPARKPLANDESCRIPTION = "sparkPlanDescription";
68+
69+
public ReplaceHugeSparkProcessAttributesPatchProcessor(PatchContext context) {
70+
super(context);
71+
}
72+
73+
@Override
74+
protected void prepareForExecution() {
75+
}
76+
77+
@Override
78+
public void submitVerticesToUpdate(WorkItemManager manager) {
79+
AtlasGraph graph = getGraph();
80+
Iterable<Object> iterable = graph.query().has(Constants.ENTITY_TYPE_PROPERTY_KEY, TYPE_NAME_SPARK_PROCESS).vertexIds();
81+
int count = 0;
82+
83+
for (Iterator<Object> iter = iterable.iterator(); iter.hasNext(); ) {
84+
Object vertexId = iter.next();
85+
86+
manager.checkProduce(vertexId);
87+
88+
count++;
89+
}
90+
91+
LOG.info("found {} entities of type {}", count, TYPE_NAME_SPARK_PROCESS);
92+
}
93+
94+
@Override
95+
protected void processVertexItem(Long vertexId, AtlasVertex vertex, String typeName, AtlasEntityType entityType) {
96+
LOG.debug("processItem(typeName={}, vertexId={})", typeName, vertexId);
97+
98+
try {
99+
vertex.removeProperty(entityType.getVertexPropertyName(ATTR_NAME_DETAILS));
100+
vertex.removeProperty(entityType.getVertexPropertyName(ATTR_NAME_SPARKPLANDESCRIPTION));
101+
} catch (Exception e) {
102+
LOG.error("Error updating: {}", vertexId, e);
103+
}
104+
105+
LOG.debug("processItem(typeName={}, vertexId={}): Done!", typeName, vertexId);
106+
}
107+
}
108+
}

0 commit comments

Comments
 (0)