[
https://issues.apache.org/jira/browse/HIVE-23353?focusedWorklogId=435472&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-435472
]
ASF GitHub Bot logged work on HIVE-23353:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 20/May/20 14:27
Start Date: 20/May/20 14:27
Worklog Time Spent: 10m
Work Description: aasha commented on a change in pull request #1021:
URL: https://github.com/apache/hive/pull/1021#discussion_r428057392
##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/repl/AtlasLoadTask.java
##########
@@ -0,0 +1,142 @@
+/*
+ * 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.hadoop.hive.ql.exec.repl;
+
+import org.apache.atlas.model.impexp.AtlasImportRequest;
+import org.apache.atlas.model.impexp.AtlasImportResult;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.utils.StringUtils;
+import org.apache.hadoop.hive.ql.ErrorMsg;
+import org.apache.hadoop.hive.ql.exec.Task;
+import org.apache.hadoop.hive.ql.exec.repl.atlas.AtlasReplInfo;
+import org.apache.hadoop.hive.ql.exec.repl.atlas.AtlasRequestBuilder;
+import org.apache.hadoop.hive.ql.exec.repl.atlas.AtlasRestClientBuilder;
+import org.apache.hadoop.hive.ql.exec.repl.util.ReplUtils;
+import org.apache.hadoop.hive.ql.parse.EximUtil;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+import org.apache.hadoop.hive.ql.plan.api.StageType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Serializable;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.nio.charset.Charset;
+
+/**
+ * Atlas Metadata Replication Load Task.
+ **/
+public class AtlasLoadTask extends Task<AtlasLoadWork> implements Serializable
{
+ private static final long serialVersionUID = 1L;
+ private static final transient Logger LOG =
LoggerFactory.getLogger(AtlasLoadTask.class);
+
+ @Override
+ public int execute() {
+ try {
+ AtlasReplInfo atlasReplInfo = createAtlasReplInfo();
+ LOG.info("Loading atlas metadata from srcDb: {} to tgtDb: {} from
staging: {}",
+ atlasReplInfo.getSrcDB(), atlasReplInfo.getTgtDB(),
atlasReplInfo.getStagingDir());
+ int importCount = importAtlasMetadata(atlasReplInfo);
+ LOG.info("Atlas entities import count {}", importCount);
+ return 0;
+ } catch (Exception e) {
+ LOG.error("Exception while loading atlas metadata", e);
+ setException(e);
+ return ErrorMsg.getErrorMsg(e.getMessage()).getErrorCode();
+ }
+ }
+
+ private AtlasReplInfo createAtlasReplInfo() throws SemanticException,
MalformedURLException {
+ String errorFormat = "%s is mandatory config for Atlas metadata
replication";
+ //Also validates URL for endpoint.
+ String endpoint = new
URL(ReplUtils.getNonEmpty(HiveConf.ConfVars.REPL_ATLAS_ENDPOINT.varname, conf,
errorFormat))
+ .toString();
+ String srcCluster =
ReplUtils.getNonEmpty(HiveConf.ConfVars.REPL_SOURCE_CLUSTER_NAME.varname, conf,
errorFormat);
+ String tgtCluster =
ReplUtils.getNonEmpty(HiveConf.ConfVars.REPL_TARGET_CLUSTER_NAME.varname, conf,
errorFormat);
+ AtlasReplInfo atlasReplInfo = new AtlasReplInfo(endpoint, work.getSrcDB(),
work.getTgtDB(),
+ srcCluster, tgtCluster, work.getStagingDir(), conf);
+ atlasReplInfo.setSrcFsUri(getStoredFsUri(atlasReplInfo.getStagingDir()));
+ atlasReplInfo.setTgtFsUri(conf.get(ReplUtils.DEFAULT_FS_CONFIG));
+ return atlasReplInfo;
+ }
+
+ private String getStoredFsUri(Path atlasDumpDir) throws SemanticException {
+ Path metadataPath = new Path(atlasDumpDir, EximUtil.METADATA_NAME);
+ BufferedReader br = null;
+ try {
+ FileSystem fs = metadataPath.getFileSystem(conf);
+ br = new BufferedReader(new InputStreamReader(fs.open(metadataPath),
Charset.defaultCharset()));
+ String[] lineContents = br.readLine().split("\t", 5);
+ return lineContents[0];
+ } catch (Exception ex) {
+ throw new SemanticException(ex);
+ } finally {
+ if (br != null) {
+ try {
+ br.close();
+ } catch (IOException e) {
+ throw new SemanticException(e);
+ }
+ }
+ }
+ }
+
+ private String getNonEmpty(String config) throws SemanticException {
Review comment:
Can be removed
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 435472)
Time Spent: 4h (was: 3h 50m)
> Atlas metadata replication scheduling
> -------------------------------------
>
> Key: HIVE-23353
> URL: https://issues.apache.org/jira/browse/HIVE-23353
> Project: Hive
> Issue Type: Task
> Reporter: PRAVIN KUMAR SINHA
> Assignee: PRAVIN KUMAR SINHA
> Priority: Major
> Labels: pull-request-available
> Attachments: HIVE-23353.01.patch, HIVE-23353.02.patch,
> HIVE-23353.03.patch, HIVE-23353.04.patch
>
> Time Spent: 4h
> Remaining Estimate: 0h
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)