|
| 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