You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sqoop.apache.org by ja...@apache.org on 2015/02/20 03:32:45 UTC
sqoop git commit: SQOOP-1978: Sqoop2: Command line support
Repository: sqoop
Updated Branches:
refs/heads/sqoop2 4d539410d -> 98d0db1f5
SQOOP-1978: Sqoop2: Command line support
(Abraham Elmahrek via Jarek Jarcec Cecho)
Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/98d0db1f
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/98d0db1f
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/98d0db1f
Branch: refs/heads/sqoop2
Commit: 98d0db1f5231e9e63f3af606d8d1500405ebfcd1
Parents: 4d53941
Author: Jarek Jarcec Cecho <ja...@apache.org>
Authored: Thu Feb 19 18:32:07 2015 -0800
Committer: Jarek Jarcec Cecho <ja...@apache.org>
Committed: Thu Feb 19 18:32:07 2015 -0800
----------------------------------------------------------------------
.../org/apache/sqoop/shell/CreateCommand.java | 3 +-
.../apache/sqoop/shell/CreateRoleFunction.java | 53 +++++++++
.../org/apache/sqoop/shell/DeleteCommand.java | 3 +-
.../apache/sqoop/shell/DeleteRoleFunction.java | 49 +++++++++
.../org/apache/sqoop/shell/GrantCommand.java | 39 +++++++
.../sqoop/shell/GrantPrivilegeFunction.java | 109 ++++++++++++++++++
.../apache/sqoop/shell/GrantRoleFunction.java | 83 ++++++++++++++
.../org/apache/sqoop/shell/RevokeCommand.java | 39 +++++++
.../sqoop/shell/RevokePrivilegeFunction.java | 110 +++++++++++++++++++
.../apache/sqoop/shell/RevokeRoleFunction.java | 83 ++++++++++++++
.../org/apache/sqoop/shell/SqoopCommand.java | 10 +-
.../java/org/apache/sqoop/shell/SqoopShell.java | 2 +
.../org/apache/sqoop/shell/core/Constants.java | 51 +++++++++
.../main/resources/shell-resource.properties | 24 ++++
14 files changed, 655 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/sqoop/blob/98d0db1f/shell/src/main/java/org/apache/sqoop/shell/CreateCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/CreateCommand.java b/shell/src/main/java/org/apache/sqoop/shell/CreateCommand.java
index 1ef2418..a16ba5b 100644
--- a/shell/src/main/java/org/apache/sqoop/shell/CreateCommand.java
+++ b/shell/src/main/java/org/apache/sqoop/shell/CreateCommand.java
@@ -32,7 +32,8 @@ public class CreateCommand extends SqoopCommand {
Constants.CMD_CREATE_SC,
ImmutableMap.of(
Constants.FN_LINK, CreateLinkFunction.class,
- Constants.FN_JOB, CreateJobFunction.class
+ Constants.FN_JOB, CreateJobFunction.class,
+ Constants.FN_ROLE, CreateRoleFunction.class
)
);
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/98d0db1f/shell/src/main/java/org/apache/sqoop/shell/CreateRoleFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/CreateRoleFunction.java b/shell/src/main/java/org/apache/sqoop/shell/CreateRoleFunction.java
new file mode 100644
index 0000000..10d06b5
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/CreateRoleFunction.java
@@ -0,0 +1,53 @@
+/**
+ * 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.sqoop.shell;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.model.MRole;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.validation.Status;
+
+import java.io.IOException;
+
+import static org.apache.sqoop.shell.ShellEnvironment.client;
+import static org.apache.sqoop.shell.ShellEnvironment.printlnResource;
+import static org.apache.sqoop.shell.ShellEnvironment.resourceString;
+
+@SuppressWarnings("serial")
+public class CreateRoleFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ public CreateRoleFunction() {
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_PROMPT_ROLE))
+ .withLongOpt(Constants.OPT_ROLE)
+ .isRequired()
+ .hasArg()
+ .create(Constants.OPT_ROLE_CHAR)
+ );
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Object executeFunction(CommandLine line, boolean isInteractive) throws IOException {
+ String role = line.getOptionValue(Constants.OPT_ROLE);
+ client.createRole(new MRole(role));
+ printlnResource(Constants.RES_CREATE_ROLE_SUCCESSFUL, role);
+ return Status.OK;
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/98d0db1f/shell/src/main/java/org/apache/sqoop/shell/DeleteCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/DeleteCommand.java b/shell/src/main/java/org/apache/sqoop/shell/DeleteCommand.java
index 26e2bf6..4b66505 100644
--- a/shell/src/main/java/org/apache/sqoop/shell/DeleteCommand.java
+++ b/shell/src/main/java/org/apache/sqoop/shell/DeleteCommand.java
@@ -32,7 +32,8 @@ public class DeleteCommand extends SqoopCommand {
Constants.CMD_DELETE_SC,
ImmutableMap.of(
Constants.FN_LINK, DeleteLinkFunction.class,
- Constants.FN_JOB, DeleteJobFunction.class
+ Constants.FN_JOB, DeleteJobFunction.class,
+ Constants.FN_ROLE, DeleteRoleFunction.class
)
);
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/98d0db1f/shell/src/main/java/org/apache/sqoop/shell/DeleteRoleFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/DeleteRoleFunction.java b/shell/src/main/java/org/apache/sqoop/shell/DeleteRoleFunction.java
new file mode 100644
index 0000000..d3c9f4d
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/DeleteRoleFunction.java
@@ -0,0 +1,49 @@
+/**
+ * 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.sqoop.shell;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.model.MRole;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.validation.Status;
+
+import static org.apache.sqoop.shell.ShellEnvironment.client;
+import static org.apache.sqoop.shell.ShellEnvironment.printlnResource;
+import static org.apache.sqoop.shell.ShellEnvironment.resourceString;
+
+@SuppressWarnings("serial")
+public class DeleteRoleFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ public DeleteRoleFunction() {
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_PROMPT_ROLE))
+ .withLongOpt(Constants.OPT_ROLE)
+ .isRequired()
+ .hasArg()
+ .create(Constants.OPT_ROLE_CHAR));
+ }
+
+ @Override
+ public Object executeFunction(CommandLine line, boolean isInteractive) {
+ String role = line.getOptionValue(Constants.OPT_ROLE);
+ client.dropRole(new MRole(role));
+ printlnResource(Constants.RES_DELETE_ROLE_SUCCESSFUL, role);
+ return Status.OK;
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/98d0db1f/shell/src/main/java/org/apache/sqoop/shell/GrantCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/GrantCommand.java b/shell/src/main/java/org/apache/sqoop/shell/GrantCommand.java
new file mode 100644
index 0000000..b4b77b0
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/GrantCommand.java
@@ -0,0 +1,39 @@
+/**
+ * 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.sqoop.shell;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.sqoop.shell.core.Constants;
+import org.codehaus.groovy.tools.shell.Shell;
+
+/**
+ *
+ */
+public class GrantCommand extends SqoopCommand {
+
+ public GrantCommand(Shell shell) {
+ super(shell,
+ Constants.CMD_GRANT,
+ Constants.CMD_GRANT_SC,
+ ImmutableMap.of(
+ Constants.FN_ROLE, GrantRoleFunction.class,
+ Constants.FN_PRIVILEGE, GrantPrivilegeFunction.class
+ )
+ );
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/98d0db1f/shell/src/main/java/org/apache/sqoop/shell/GrantPrivilegeFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/GrantPrivilegeFunction.java b/shell/src/main/java/org/apache/sqoop/shell/GrantPrivilegeFunction.java
new file mode 100644
index 0000000..d16e097
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/GrantPrivilegeFunction.java
@@ -0,0 +1,109 @@
+/**
+ * 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.sqoop.shell;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.model.MPrincipal;
+import org.apache.sqoop.model.MPrivilege;
+import org.apache.sqoop.model.MResource;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.validation.Status;
+
+import java.io.IOException;
+import java.text.MessageFormat;
+import java.util.Arrays;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+public class GrantPrivilegeFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ public GrantPrivilegeFunction() {
+ this.addOption(OptionBuilder
+ .withLongOpt(Constants.OPT_RESOURCE_TYPE)
+ .withDescription(resourceString(Constants.RES_PROMPT_RESOURCE_TYPE))
+ .isRequired()
+ .hasArg()
+ .create()
+ );
+ this.addOption(OptionBuilder
+ .withLongOpt(Constants.OPT_RESOURCE)
+ .withDescription(resourceString(Constants.RES_PROMPT_RESOURCE))
+ .isRequired()
+ .hasArg()
+ .create()
+ );
+ this.addOption(OptionBuilder
+ .withLongOpt(Constants.OPT_ACTION)
+ .withDescription(resourceString(Constants.RES_PROMPT_ACTION))
+ .isRequired()
+ .hasArg()
+ .create(Constants.OPT_ACTION_CHAR)
+ );
+ this.addOption(OptionBuilder
+ .withLongOpt(Constants.OPT_PRINCIPAL)
+ .withDescription(resourceString(Constants.RES_PROMPT_PRINCIPAL))
+ .isRequired()
+ .hasArg()
+ .create()
+ );
+ this.addOption(OptionBuilder
+ .withLongOpt(Constants.OPT_PRINCIPAL_TYPE)
+ .withDescription(resourceString(Constants.RES_PROMPT_PRINCIPAL_TYPE))
+ .isRequired()
+ .hasArg()
+ .create()
+ );
+ this.addOption(OptionBuilder
+ .withLongOpt(Constants.OPT_WITH_GRANT)
+ .withDescription(resourceString(Constants.RES_PROMPT_WITH_GRANT))
+ .create(Constants.OPT_WITH_GRANT_CHAR)
+ );
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Object executeFunction(CommandLine line, boolean isInteractive) throws IOException {
+ return grantPrivilege(
+ line.getOptionValue(Constants.OPT_ACTION),
+ line.getOptionValue(Constants.OPT_RESOURCE_TYPE),
+ line.getOptionValue(Constants.OPT_RESOURCE),
+ line.getOptionValue(Constants.OPT_PRINCIPAL_TYPE),
+ line.getOptionValue(Constants.OPT_PRINCIPAL),
+ line.hasOption(Constants.OPT_WITH_GRANT));
+ }
+
+ private Status grantPrivilege(String action, String resourceType, String resource,
+ String principalType, String principal, boolean withGrant)
+ throws IOException {
+ MResource resourceObject = new MResource(resourceType, resource);
+ MPrivilege privilegeObject = new MPrivilege(resourceObject, action, withGrant);
+ MPrincipal principalObject = new MPrincipal(principalType, principal);
+
+ client.grantPrivilege(
+ Arrays.asList(principalObject),
+ Arrays.asList(privilegeObject));
+
+ printlnResource(Constants.RES_GRANT_PRIVILEGE_SUCCESSFUL,
+ action, resourceType + " " + resource,
+ ((withGrant) ? " " + resourceString(Constants.RES_GRANT_PRIVILEGE_SUCCESSFUL_WITH_GRANT) : ""),
+ principalType + " " + principal);
+
+ return Status.OK;
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/98d0db1f/shell/src/main/java/org/apache/sqoop/shell/GrantRoleFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/GrantRoleFunction.java b/shell/src/main/java/org/apache/sqoop/shell/GrantRoleFunction.java
new file mode 100644
index 0000000..9dfe90f
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/GrantRoleFunction.java
@@ -0,0 +1,83 @@
+/**
+ * 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.sqoop.shell;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.model.MPrincipal;
+import org.apache.sqoop.model.MRole;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.validation.Status;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+import static org.apache.sqoop.shell.ShellEnvironment.client;
+import static org.apache.sqoop.shell.ShellEnvironment.printlnResource;
+import static org.apache.sqoop.shell.ShellEnvironment.resourceString;
+
+@SuppressWarnings("serial")
+public class GrantRoleFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ public GrantRoleFunction() {
+ this.addOption(OptionBuilder
+ .withLongOpt(Constants.OPT_PRINCIPAL_TYPE)
+ .withDescription(resourceString(Constants.RES_PROMPT_PRINCIPAL_TYPE))
+ .isRequired()
+ .hasArgs()
+ .create()
+ );
+ this.addOption(OptionBuilder
+ .withLongOpt(Constants.OPT_PRINCIPAL)
+ .withDescription(resourceString(Constants.RES_PROMPT_PRINCIPAL))
+ .isRequired()
+ .hasArgs()
+ .create()
+ );
+ this.addOption(OptionBuilder
+ .withLongOpt(Constants.OPT_ROLE)
+ .withDescription(resourceString(Constants.RES_PROMPT_ROLE))
+ .isRequired()
+ .hasArgs()
+ .create(Constants.OPT_ROLE_CHAR)
+ );
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Object executeFunction(CommandLine line, boolean isInteractive) throws IOException {
+ return grantRole(
+ line.getOptionValue(Constants.OPT_ROLE),
+ line.getOptionValue(Constants.OPT_PRINCIPAL_TYPE),
+ line.getOptionValue(Constants.OPT_PRINCIPAL));
+ }
+
+ private Status grantRole(String role, String principalType, String principal) throws IOException {
+ MRole roleObject = new MRole(role);
+ MPrincipal principalObject = new MPrincipal(principalType, principal);
+
+ client.grantRole(
+ Arrays.asList(roleObject),
+ Arrays.asList(principalObject));
+
+ printlnResource(Constants.RES_GRANT_ROLE_SUCCESSFUL,
+ role, principalType + " " + principal);
+
+ return Status.OK;
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/98d0db1f/shell/src/main/java/org/apache/sqoop/shell/RevokeCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/RevokeCommand.java b/shell/src/main/java/org/apache/sqoop/shell/RevokeCommand.java
new file mode 100644
index 0000000..0cb30e4
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/RevokeCommand.java
@@ -0,0 +1,39 @@
+/**
+ * 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.sqoop.shell;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.sqoop.shell.core.Constants;
+import org.codehaus.groovy.tools.shell.Shell;
+
+/**
+ *
+ */
+public class RevokeCommand extends SqoopCommand {
+
+ public RevokeCommand(Shell shell) {
+ super(shell,
+ Constants.CMD_REVOKE,
+ Constants.CMD_REVOKE_SC,
+ ImmutableMap.of(
+ Constants.FN_ROLE, RevokeRoleFunction.class,
+ Constants.FN_PRIVILEGE, RevokePrivilegeFunction.class
+ )
+ );
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/98d0db1f/shell/src/main/java/org/apache/sqoop/shell/RevokePrivilegeFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/RevokePrivilegeFunction.java b/shell/src/main/java/org/apache/sqoop/shell/RevokePrivilegeFunction.java
new file mode 100644
index 0000000..b49a9ad
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/RevokePrivilegeFunction.java
@@ -0,0 +1,110 @@
+/**
+ * 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.sqoop.shell;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.model.MPrincipal;
+import org.apache.sqoop.model.MPrivilege;
+import org.apache.sqoop.model.MResource;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.validation.Status;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+import static org.apache.sqoop.shell.ShellEnvironment.client;
+import static org.apache.sqoop.shell.ShellEnvironment.printlnResource;
+import static org.apache.sqoop.shell.ShellEnvironment.resourceString;
+
+public class RevokePrivilegeFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ public RevokePrivilegeFunction() {
+ this.addOption(OptionBuilder
+ .withLongOpt(Constants.OPT_RESOURCE_TYPE)
+ .withDescription(resourceString(Constants.RES_PROMPT_RESOURCE_TYPE))
+ .isRequired()
+ .hasArg()
+ .create()
+ );
+ this.addOption(OptionBuilder
+ .withLongOpt(Constants.OPT_RESOURCE)
+ .withDescription(resourceString(Constants.RES_PROMPT_RESOURCE))
+ .isRequired()
+ .hasArg()
+ .create()
+ );
+ this.addOption(OptionBuilder
+ .withLongOpt(Constants.OPT_ACTION)
+ .withDescription(resourceString(Constants.RES_PROMPT_ACTION))
+ .isRequired()
+ .hasArg()
+ .create(Constants.OPT_ACTION_CHAR)
+ );
+ this.addOption(OptionBuilder
+ .withLongOpt(Constants.OPT_PRINCIPAL)
+ .withDescription(resourceString(Constants.RES_PROMPT_PRINCIPAL))
+ .isRequired()
+ .hasArg()
+ .create()
+ );
+ this.addOption(OptionBuilder
+ .withLongOpt(Constants.OPT_PRINCIPAL_TYPE)
+ .withDescription(resourceString(Constants.RES_PROMPT_PRINCIPAL_TYPE))
+ .isRequired()
+ .hasArg()
+ .create()
+ );
+ this.addOption(OptionBuilder
+ .withLongOpt(Constants.OPT_WITH_GRANT)
+ .withDescription(resourceString(Constants.RES_PROMPT_WITH_GRANT))
+ .create(Constants.OPT_WITH_GRANT_CHAR)
+ );
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Object executeFunction(CommandLine line, boolean isInteractive) throws IOException {
+ return revokePrivilege(
+ line.getOptionValue(Constants.OPT_ACTION),
+ line.getOptionValue(Constants.OPT_RESOURCE_TYPE),
+ line.getOptionValue(Constants.OPT_RESOURCE),
+ line.getOptionValue(Constants.OPT_PRINCIPAL_TYPE),
+ line.getOptionValue(Constants.OPT_PRINCIPAL),
+ line.hasOption(Constants.OPT_WITH_GRANT));
+ }
+
+ private Status revokePrivilege(String action, String resourceType, String resource,
+ String principalType, String principal, boolean withGrant)
+ throws IOException {
+ MResource resourceObject = new MResource(resourceType, resource);
+ MPrivilege privilegeObject = new MPrivilege(resourceObject, action, withGrant);
+ MPrincipal principalObject = new MPrincipal(principalType, principal);
+
+ client.revokePrivilege(
+ Arrays.asList(principalObject),
+ Arrays.asList(privilegeObject));
+
+ printlnResource(Constants.RES_REVOKE_PRIVILEGE_SUCCESSFUL,
+ action, resourceType + " " + resource,
+ ((withGrant) ? " " + resourceString(Constants.RES_REVOKE_PRIVILEGE_SUCCESSFUL_WITH_GRANT) : ""),
+ principalType + " " + principal);
+
+ return Status.OK;
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/98d0db1f/shell/src/main/java/org/apache/sqoop/shell/RevokeRoleFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/RevokeRoleFunction.java b/shell/src/main/java/org/apache/sqoop/shell/RevokeRoleFunction.java
new file mode 100644
index 0000000..cf69faa
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/RevokeRoleFunction.java
@@ -0,0 +1,83 @@
+/**
+ * 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.sqoop.shell;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.model.MPrincipal;
+import org.apache.sqoop.model.MRole;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.validation.Status;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+import static org.apache.sqoop.shell.ShellEnvironment.client;
+import static org.apache.sqoop.shell.ShellEnvironment.printlnResource;
+import static org.apache.sqoop.shell.ShellEnvironment.resourceString;
+
+@SuppressWarnings("serial")
+public class RevokeRoleFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ public RevokeRoleFunction() {
+ this.addOption(OptionBuilder
+ .withLongOpt(Constants.OPT_PRINCIPAL_TYPE)
+ .withDescription(resourceString(Constants.RES_PROMPT_PRINCIPAL_TYPE))
+ .isRequired()
+ .hasArgs()
+ .create()
+ );
+ this.addOption(OptionBuilder
+ .withLongOpt(Constants.OPT_PRINCIPAL)
+ .withDescription(resourceString(Constants.RES_PROMPT_PRINCIPAL))
+ .isRequired()
+ .hasArgs()
+ .create()
+ );
+ this.addOption(OptionBuilder
+ .withLongOpt(Constants.OPT_ROLE)
+ .withDescription(resourceString(Constants.RES_PROMPT_ROLE))
+ .isRequired()
+ .hasArgs()
+ .create(Constants.OPT_ROLE_CHAR)
+ );
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Object executeFunction(CommandLine line, boolean isInteractive) throws IOException {
+ return revokeRole(
+ line.getOptionValue(Constants.OPT_ROLE),
+ line.getOptionValue(Constants.OPT_PRINCIPAL_TYPE),
+ line.getOptionValue(Constants.OPT_PRINCIPAL));
+ }
+
+ private Status revokeRole(String role, String principalType, String principal) throws IOException {
+ MRole roleObject = new MRole(role);
+ MPrincipal principalObject = new MPrincipal(principalType, principal);
+
+ client.revokeRole(
+ Arrays.asList(roleObject),
+ Arrays.asList(principalObject));
+
+ printlnResource(Constants.RES_REVOKE_ROLE_SUCCESSFUL,
+ role, principalType + " " + principal);
+
+ return Status.OK;
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/98d0db1f/shell/src/main/java/org/apache/sqoop/shell/SqoopCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/SqoopCommand.java b/shell/src/main/java/org/apache/sqoop/shell/SqoopCommand.java
index cbd34f5..fdb7a5b 100644
--- a/shell/src/main/java/org/apache/sqoop/shell/SqoopCommand.java
+++ b/shell/src/main/java/org/apache/sqoop/shell/SqoopCommand.java
@@ -63,6 +63,12 @@ public abstract class SqoopCommand extends ComplexCommandSupport {
protected SqoopCommand(Shell shell,
String name,
+ String shortcut) {
+ this(shell, name, shortcut, null);
+ }
+
+ protected SqoopCommand(Shell shell,
+ String name,
String shortcut,
Map<String, Class<? extends SqoopFunction>> funcs) {
super(shell, name, shortcut);
@@ -72,7 +78,9 @@ public abstract class SqoopCommand extends ComplexCommandSupport {
this.functionInstances = new HashMap<String, SqoopFunction>();
this.functions = new LinkedList<String>();
- this.functions.addAll(funcs.keySet());
+ if (funcs != null) {
+ this.functions.addAll(funcs.keySet());
+ }
}
@Override
http://git-wip-us.apache.org/repos/asf/sqoop/blob/98d0db1f/shell/src/main/java/org/apache/sqoop/shell/SqoopShell.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/SqoopShell.java b/shell/src/main/java/org/apache/sqoop/shell/SqoopShell.java
index 2e87965..e319839 100644
--- a/shell/src/main/java/org/apache/sqoop/shell/SqoopShell.java
+++ b/shell/src/main/java/org/apache/sqoop/shell/SqoopShell.java
@@ -99,6 +99,8 @@ public final class SqoopShell {
shell.register(new StatusCommand(shell));
shell.register(new EnableCommand(shell));
shell.register(new DisableCommand(shell));
+ shell.register(new GrantCommand(shell));
+ shell.register(new RevokeCommand(shell));
// Configure shared shell io object
setIo(shell.getIo());
http://git-wip-us.apache.org/repos/asf/sqoop/blob/98d0db1f/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java b/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java
index 482ddd9..fc8ef42 100644
--- a/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java
+++ b/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java
@@ -53,6 +53,13 @@ public class Constants {
public static final String OPT_SYNCHRONOUS = "synchronous";
public static final String OPT_POLL_TIMEOUT = "poll-timeout";
public static final String OPT_DETAIL = "detail";
+ public static final String OPT_ROLE = "role";
+ public static final String OPT_ACTION = "action";
+ public static final String OPT_RESOURCE = "resource";
+ public static final String OPT_RESOURCE_TYPE = "resource-type";
+ public static final String OPT_PRINCIPAL = "principal";
+ public static final String OPT_PRINCIPAL_TYPE = "principal-type";
+ public static final String OPT_WITH_GRANT = "with-grant";
public static final char OPT_LID_CHAR = 'l';
public static final char OPT_FROM_CHAR = 'f';
@@ -72,6 +79,9 @@ public class Constants {
public static final char OPT_SYNCHRONOUS_CHAR = 's';
public static final char OPT_POLL_TIMEOUT_CHAR = 'p';
public static final char OPT_DETAIL_CHAR = 'd';
+ public static final char OPT_ROLE_CHAR = 'r';
+ public static final char OPT_ACTION_CHAR = 'a';
+ public static final char OPT_WITH_GRANT_CHAR = 'g';
// Resource keys for various commands, command options,
// functions and descriptions
@@ -111,6 +121,12 @@ public class Constants {
public static final String CMD_DISABLE = "disable";
public static final String CMD_DISABLE_SC = "\\di";
+ public static final String CMD_GRANT = "grant";
+ public static final String CMD_GRANT_SC = "\\g";
+
+ public static final String CMD_REVOKE = "revoke";
+ public static final String CMD_REVOKE_SC = "\\r";
+
public static final String FN_LINK = "link";
public static final String FN_JOB = "job";
public static final String FN_SUBMISSION = "submission";
@@ -119,6 +135,8 @@ public class Constants {
public static final String FN_CONNECTOR = "connector";
public static final String FN_VERSION = "version";
public static final String FN_DRIVER_CONFIG = "driver";
+ public static final String FN_ROLE = "role";
+ public static final String FN_PRIVILEGE = "privilege";
public static final String PROP_HOMEDIR = "user.home";
public static final String PROP_CURDIR = "user.dir";
@@ -173,11 +191,16 @@ public class Constants {
"create.link_successful";
public static final String RES_CREATE_JOB_SUCCESSFUL =
"create.job_successful";
+ public static final String RES_CREATE_ROLE_SUCCESSFUL =
+ "create.role_successful";
public static final String RES_CREATE_CREATING_LINK =
"create.creating_link";
public static final String RES_CREATE_CREATING_JOB =
"create.creating_job";
+ public static final String RES_DELETE_ROLE_SUCCESSFUL =
+ "delete.role_successful";
+
public static final String RES_DISABLE_LINK_SUCCESSFUL =
"disable.link_successful";
public static final String RES_DISABLE_JOB_SUCCESSFUL =
@@ -415,6 +438,34 @@ public class Constants {
public static final String RES_TO_SCHEMA =
"submission.to_schema";
+ public static final String RES_GRANT_ROLE_SUCCESSFUL =
+ "grant.role_successful";
+ public static final String RES_GRANT_PRIVILEGE_SUCCESSFUL =
+ "grant.privilege_successful";
+ public static final String RES_GRANT_PRIVILEGE_SUCCESSFUL_WITH_GRANT =
+ "grant.privilege_successful_with_grant";
+ public static final String RES_REVOKE_ROLE_SUCCESSFUL =
+ "revoke.role_successful";
+ public static final String RES_REVOKE_PRIVILEGE_SUCCESSFUL =
+ "revoke.privilege_successful";
+ public static final String RES_REVOKE_PRIVILEGE_SUCCESSFUL_WITH_GRANT =
+ "revoke.privilege_successful_with_grant";
+
+ public static final String RES_PROMPT_ROLE =
+ "prompt.role";
+ public static final String RES_PROMPT_RESOURCE_TYPE =
+ "prompt.resource_type";
+ public static final String RES_PROMPT_RESOURCE =
+ "prompt.resource";
+ public static final String RES_PROMPT_ACTION =
+ "prompt.action";
+ public static final String RES_PROMPT_PRINCIPAL =
+ "prompt.principal";
+ public static final String RES_PROMPT_PRINCIPAL_TYPE =
+ "prompt.principal_type";
+ public static final String RES_PROMPT_WITH_GRANT =
+ "prompt.with_grant";
+
private Constants() {
// Instantiation is prohibited
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/98d0db1f/shell/src/main/resources/shell-resource.properties
----------------------------------------------------------------------
diff --git a/shell/src/main/resources/shell-resource.properties b/shell/src/main/resources/shell-resource.properties
index a462184..750fd59 100644
--- a/shell/src/main/resources/shell-resource.properties
+++ b/shell/src/main/resources/shell-resource.properties
@@ -77,11 +77,13 @@ create.link_successful = New link was successfully created with \
validation status {0} and persistent id {1}
create.job_successful = New job was successfully created with validation \
status {0} and persistent id {1}
+create.role_successful = New role was successfully created with name {0}
create.creating_link = Creating link for connector with id {0}
create.creating_job = Creating job for links with from id {0} and to id {1}
# Delete command
delete.description = Delete existing object in Sqoop repository
+delete.role_successful = Deleted role {0} successfully
# Enable command
enable.description = Enable object in Sqoop repository
@@ -186,6 +188,20 @@ stop.description = Stop job
# Status command
status.description = Display status of a job
+# Grant command
+grant.description = Grant access to roles and assign privileges
+grant.privilege_successful = Granted action {0} on resource {1}{2} to \
+ principal {3} successfully
+grant.privilege_successful_with_grant = with grant
+grant.role_successful = Granted role {0} to principal {1} successfully
+
+# Revoke command
+revoke.description = Revoke access from roles and remove privileges
+revoke.privilege_successful = Revoked action {0} on resource {1}{2} to \
+ principal {3} successfully
+revoke.privilege_successful_with_grant = with grant
+revoke.role_successful = Revoked role {0} from principal {1} successfully
+
# Various Table headers
table.header.id = Id
table.header.name = Name
@@ -234,3 +250,11 @@ submission.server_url = Server URL
submission.from_schema = Source Connector schema
submission.to_schema = Target Connector schema
+# Grant/revoke resources
+prompt.role = "Role name"
+prompt.resource_type = "Resource type"
+prompt.resource = "Resource name"
+prompt.action = "Action"
+prompt.principal_type = "Principal type"
+prompt.principal = "Principal"
+prompt.with_grant = "With grant"
\ No newline at end of file