You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by sh...@apache.org on 2015/11/23 10:31:39 UTC
incubator-kylin git commit: KYLIN-1157 copy ACL when migrate cube
Repository: incubator-kylin
Updated Branches:
refs/heads/1.x-staging fc1d16c3f -> 01321755b
KYLIN-1157 copy ACL when migrate cube
Project: http://git-wip-us.apache.org/repos/asf/incubator-kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-kylin/commit/01321755
Tree: http://git-wip-us.apache.org/repos/asf/incubator-kylin/tree/01321755
Diff: http://git-wip-us.apache.org/repos/asf/incubator-kylin/diff/01321755
Branch: refs/heads/1.x-staging
Commit: 01321755b35ce516da3f5f58983811924a491eeb
Parents: fc1d16c
Author: shaofengshi <sh...@apache.org>
Authored: Mon Nov 23 17:07:23 2015 +0800
Committer: shaofengshi <sh...@apache.org>
Committed: Mon Nov 23 17:27:14 2015 +0800
----------------------------------------------------------------------
.../kylin/job/tools/CubeMigrationCLI.java | 58 +++++++++++++++-----
1 file changed, 43 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/01321755/job/src/main/java/org/apache/kylin/job/tools/CubeMigrationCLI.java
----------------------------------------------------------------------
diff --git a/job/src/main/java/org/apache/kylin/job/tools/CubeMigrationCLI.java b/job/src/main/java/org/apache/kylin/job/tools/CubeMigrationCLI.java
index 2d4b0bf..e3f7c11 100644
--- a/job/src/main/java/org/apache/kylin/job/tools/CubeMigrationCLI.java
+++ b/job/src/main/java/org/apache/kylin/job/tools/CubeMigrationCLI.java
@@ -23,18 +23,15 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import org.apache.commons.io.IOUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.hbase.HBaseConfiguration;
-import org.apache.hadoop.hbase.HTableDescriptor;
-import org.apache.hadoop.hbase.TableName;
-import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.*;
+import org.apache.hadoop.hbase.client.*;
import org.apache.kylin.common.KylinConfig;
-import org.apache.kylin.common.persistence.JsonSerializer;
-import org.apache.kylin.common.persistence.RawResource;
-import org.apache.kylin.common.persistence.ResourceStore;
-import org.apache.kylin.common.persistence.Serializer;
+import org.apache.kylin.common.persistence.*;
+import org.apache.kylin.common.util.Bytes;
import org.apache.kylin.cube.CubeInstance;
import org.apache.kylin.cube.CubeManager;
import org.apache.kylin.cube.CubeSegment;
@@ -54,6 +51,8 @@ import org.apache.kylin.metadata.realization.RealizationType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.jdo.identity.ObjectIdentity;
+
/**
* Created by honma on 9/3/14.
* <p/>
@@ -82,16 +81,16 @@ public class CubeMigrationCLI {
System.exit(1);
}
- moveCube(args[0], args[1], args[2], args[3], args[4], args[5]);
+ moveCube(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
}
private static void usage() {
- System.out.println("Usage: CubeMigrationCLI srcKylinConfigUri dstKylinConfigUri cubeName projectName overwriteIfExists realExecute");
- System.out.println(" srcKylinConfigUri: The KylinConfig of the cube’s source \n" + "dstKylinConfigUri: The KylinConfig of the cube’s new home \n" + "cubeName: the name of cube to be migrated. \n" + "projectName: The target project in the target environment.(Make sure it exist) \n" + "overwriteIfExists: overwrite cube if it already exists in the target environment. \n" + "realExecute: if false, just print the operations to take, if true, do the real migration. \n");
+ System.out.println("Usage: CubeMigrationCLI srcKylinConfigUri dstKylinConfigUri cubeName projectName copyAclOrNot overwriteIfExists realExecute");
+ System.out.println(" srcKylinConfigUri: The KylinConfig of the cube’s source \n" + "dstKylinConfigUri: The KylinConfig of the cube’s new home \n" + "cubeName: the name of cube to be migrated. \n" + "projectName: The target project in the target environment.(Make sure it exist) \n" + "copyAclOrNot: true or false: whether copy cube ACL to target environment. \n" + "overwriteIfExists: overwrite cube if it already exists in the target environment. \n" + "realExecute: if false, just print the operations to take, if true, do the real migration. \n");
}
- public static void moveCube(KylinConfig srcCfg, KylinConfig dstCfg, String cubeName, String projectName, String overwriteIfExists, String realExecute) throws IOException, InterruptedException {
+ public static void moveCube(KylinConfig srcCfg, KylinConfig dstCfg, String cubeName, String projectName, String copyAcl, String overwriteIfExists, String realExecute) throws IOException, InterruptedException {
srcConfig = srcCfg;
srcStore = ResourceStore.getStore(srcConfig);
@@ -124,6 +123,9 @@ public class CubeMigrationCLI {
renameFoldersInHdfs(cube);
changeHtableHost(cube);
addCubeIntoProject(cubeName, projectName);
+ if (Boolean.valueOf(copyAcl).booleanValue() == true) {
+ copyACL(cube);
+ }
if (realExecute.equalsIgnoreCase("true")) {
doOpts();
@@ -132,9 +134,9 @@ public class CubeMigrationCLI {
}
}
- public static void moveCube(String srcCfgUri, String dstCfgUri, String cubeName, String projectName, String overwriteIfExists, String realExecute) throws IOException, InterruptedException {
+ public static void moveCube(String srcCfgUri, String dstCfgUri, String cubeName, String projectName, String copyAcl, String overwriteIfExists, String realExecute) throws IOException, InterruptedException {
- moveCube(KylinConfig.createInstanceFromUri(srcCfgUri), KylinConfig.createInstanceFromUri(dstCfgUri), cubeName, projectName, overwriteIfExists, realExecute);
+ moveCube(KylinConfig.createInstanceFromUri(srcCfgUri), KylinConfig.createInstanceFromUri(dstCfgUri), cubeName, projectName, copyAcl, overwriteIfExists, realExecute);
}
private static String checkAndGetHbaseUrl() {
@@ -176,6 +178,10 @@ public class CubeMigrationCLI {
operations.add(new Opt(OptType.CHANGE_HTABLE_HOST, new Object[] { segment.getStorageLocationIdentifier() }));
}
}
+
+ private static void copyACL(CubeInstance cube) {
+ operations.add(new Opt(OptType.COPY_ACL, new Object[] { cube.getUuid() }));
+ }
private static void copyFilesInMetaStore(CubeInstance cube, String overwriteIfExists) throws IOException {
@@ -221,7 +227,7 @@ public class CubeMigrationCLI {
}
private static enum OptType {
- COPY_FILE_IN_META, COPY_DICT_OR_SNAPSHOT, RENAME_FOLDER_IN_HDFS, ADD_INTO_PROJECT, CHANGE_HTABLE_HOST
+ COPY_FILE_IN_META, COPY_DICT_OR_SNAPSHOT, RENAME_FOLDER_IN_HDFS, ADD_INTO_PROJECT, CHANGE_HTABLE_HOST, COPY_ACL
}
private static class Opt {
@@ -390,6 +396,28 @@ public class CubeMigrationCLI {
logger.info("Project instance for " + projectName + " is corrected");
break;
}
+ case COPY_ACL: {
+ String cubeId = (String) opt.params[0];
+ HTableInterface srcAclHtable = null;
+ HTableInterface destAclHtable = null;
+ try {
+ srcAclHtable = HBaseConnection.get(srcConfig.getMetadataUrl()).getTable(srcConfig.getMetadataUrlPrefix() + "_acl");
+ destAclHtable = HBaseConnection.get(dstConfig.getMetadataUrl()).getTable(dstConfig.getMetadataUrlPrefix() + "_acl");
+
+ Result result = srcAclHtable.get(new Get(Bytes.toBytes(cubeId)));
+
+ for (Cell cell : result.listCells()) {
+ Put put = new Put(Bytes.toBytes(cubeId));
+ put.add(CellUtil.cloneFamily(cell), CellUtil.cloneQualifier(cell), CellUtil.cloneValue(cell));
+ destAclHtable.put(put);
+ }
+ destAclHtable.flushCommits();
+ } finally {
+ IOUtils.closeQuietly(srcAclHtable);
+ IOUtils.closeQuietly(destAclHtable);
+ }
+ break;
+ }
}
}