You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by rz...@apache.org on 2017/03/27 22:57:18 UTC
[08/51] [abbrv] ambari git commit: AMBARI-18755. Deployment failing
at creating principal (aonishuk)
AMBARI-18755. Deployment failing at creating principal (aonishuk)
(cherry picked from commit 6edba95a319d96ceabe77ea67aa9d81fec35057d)
Change-Id: Ib586c7bd576d3abe7c1346a017a63c1bce7990cd
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/e98d57ed
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e98d57ed
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e98d57ed
Branch: refs/heads/AMBARI-2.4.2.16
Commit: e98d57edfc1af84b692429719b3b07fc653cd2ee
Parents: 08f03f7
Author: Andrew Onishuk <ao...@hortonworks.com>
Authored: Wed Nov 9 14:27:04 2016 +0200
Committer: Andrew Onishuk <ao...@hortonworks.com>
Committed: Wed Nov 9 13:10:14 2016 +0000
----------------------------------------------------------------------
.../server/configuration/Configuration.java | 7 +++
.../kerberos/MITKerberosOperationHandler.java | 28 +++++++++-
.../MITKerberosOperationHandlerTest.java | 57 ++++++++++----------
3 files changed, 62 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/e98d57ed/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
index fae9378..a91eada 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
@@ -418,6 +418,8 @@ public class Configuration {
public static final String KERBEROS_KEYTAB_CACHE_DIR_DEFAULT = AmbariPath.getPath("/var/lib/ambari-server/data/cache");
public static final String KERBEROS_CHECK_JAAS_CONFIGURATION_KEY = "kerberos.check.jaas.configuration";
public static final String KERBEROS_CHECK_JAAS_CONFIGURATION_DEFAULT = "false";
+ public static final String KERBEROS_OPERATION_RETRIES_KEY = "kerberos.operation.retries";
+ public static final String KERBEROS_OPERATION_RETRIES_DEFAULT = "3";
/**
* Recovery related configuration
@@ -3322,4 +3324,9 @@ public class Configuration {
String.valueOf(TASK_ID_LIST_LIMIT_DEFAULT)));
}
+ public int getKerberosOperationRetries(){
+ return Integer.parseInt(properties.getProperty(
+ KERBEROS_OPERATION_RETRIES_KEY,
+ KERBEROS_OPERATION_RETRIES_DEFAULT));
+ }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/e98d57ed/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/MITKerberosOperationHandler.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/MITKerberosOperationHandler.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/MITKerberosOperationHandler.java
index 7e915fc..a21d330 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/MITKerberosOperationHandler.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/MITKerberosOperationHandler.java
@@ -18,6 +18,8 @@
package org.apache.ambari.server.serveraction.kerberos;
+import com.google.inject.Inject;
+import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.security.credential.PrincipalKeyCredential;
import org.apache.ambari.server.utils.ShellCommandUtil;
import org.apache.commons.lang.ArrayUtils;
@@ -44,6 +46,9 @@ import java.util.regex.Pattern;
*/
public class MITKerberosOperationHandler extends KerberosOperationHandler {
+ @Inject
+ private Configuration configuration;
+
/**
* A regular expression pattern to use to parse the key number from the text captured from the
* get_principal kadmin command
@@ -388,7 +393,7 @@ public class MITKerberosOperationHandler extends KerberosOperationHandler {
throw new KerberosOperationException("Missing kadmin query");
}
- ShellCommandUtil.Result result;
+ ShellCommandUtil.Result result = null;
PrincipalKeyCredential administratorCredential = getAdministratorCredential();
String defaultRealm = getDefaultRealm();
@@ -451,7 +456,26 @@ public class MITKerberosOperationHandler extends KerberosOperationHandler {
LOG.debug(String.format("Executing: %s", command));
}
- result = executeCommand(command.toArray(new String[command.size()]), null, interactiveHandler);
+ int retryCount = configuration.getKerberosOperationRetries();
+ int tries = 0;
+
+ while (tries <= retryCount) {
+ try {
+ result = executeCommand(command.toArray(new String[command.size()]), null, interactiveHandler);
+ } catch (KerberosOperationException exception) {
+ if (tries == retryCount) {
+ throw exception;
+ }
+ } finally {
+ if (result != null && result.isSuccessful()) {
+ break; // break on successful result
+ }
+ tries++;
+ String message = String.format("Retrying to execute kadmin:\n\tCommand: %s", command);
+ LOG.warn(message);
+ }
+ }
+
if (!result.isSuccessful()) {
String message = String.format("Failed to execute kadmin:\n\tCommand: %s\n\tExitCode: %s\n\tSTDOUT: %s\n\tSTDERR: %s",
http://git-wip-us.apache.org/repos/asf/ambari/blob/e98d57ed/ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/MITKerberosOperationHandlerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/MITKerberosOperationHandlerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/MITKerberosOperationHandlerTest.java
index 6fd30ee..4c40a5d 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/MITKerberosOperationHandlerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/MITKerberosOperationHandlerTest.java
@@ -32,6 +32,7 @@ import org.apache.ambari.server.utils.ShellCommandUtil;
import org.easymock.Capture;
import org.easymock.EasyMock;
import org.easymock.IAnswer;
+import org.easymock.IMockBuilder;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
@@ -122,10 +123,11 @@ public class MITKerberosOperationHandlerTest extends KerberosOperationHandlerTes
@Test(expected = KerberosPrincipalDoesNotExistException.class)
public void testSetPrincipalPasswordPrincipalDoesNotExist() throws Exception {
+
MITKerberosOperationHandler handler = createMockBuilder(MITKerberosOperationHandler.class)
.addMockedMethod(methodExecuteCommand)
.createNiceMock();
-
+ injector.injectMembers(handler);
expect(handler.executeCommand(anyObject(String[].class), anyObject(Map.class), anyObject(MITKerberosOperationHandler.InteractivePasswordHandler.class)))
.andAnswer(new IAnswer<ShellCommandUtil.Result>() {
@Override
@@ -187,9 +189,7 @@ public class MITKerberosOperationHandlerTest extends KerberosOperationHandlerTes
@Test(expected = KerberosPrincipalAlreadyExistsException.class)
public void testCreatePrincipalPrincipalAlreadyNotExists() throws Exception {
- MITKerberosOperationHandler handler = createMockBuilder(MITKerberosOperationHandler.class)
- .addMockedMethod(methodExecuteCommand)
- .createNiceMock();
+ MITKerberosOperationHandler handler = createMock();
expect(handler.executeCommand(anyObject(String[].class), anyObject(Map.class), anyObject(MITKerberosOperationHandler.InteractivePasswordHandler.class)))
.andAnswer(new IAnswer<ShellCommandUtil.Result>() {
@@ -254,9 +254,7 @@ public class MITKerberosOperationHandlerTest extends KerberosOperationHandlerTes
@Test(expected = KerberosAdminAuthenticationException.class)
public void testTestAdministratorCredentialsIncorrectAdminPassword() throws Exception {
- MITKerberosOperationHandler handler = createMockBuilder(MITKerberosOperationHandler.class)
- .addMockedMethod(methodExecuteCommand)
- .createNiceMock();
+ MITKerberosOperationHandler handler = createMock();
expect(handler.executeCommand(anyObject(String[].class), anyObject(Map.class), anyObject(MITKerberosOperationHandler.InteractivePasswordHandler.class)))
.andAnswer(new IAnswer<ShellCommandUtil.Result>() {
@@ -287,9 +285,7 @@ public class MITKerberosOperationHandlerTest extends KerberosOperationHandlerTes
@Test(expected = KerberosAdminAuthenticationException.class)
public void testTestAdministratorCredentialsIncorrectAdminPrincipal() throws Exception {
- MITKerberosOperationHandler handler = createMockBuilder(MITKerberosOperationHandler.class)
- .addMockedMethod(methodExecuteCommand)
- .createNiceMock();
+ MITKerberosOperationHandler handler = createMock();
expect(handler.executeCommand(anyObject(String[].class), anyObject(Map.class), anyObject(MITKerberosOperationHandler.InteractivePasswordHandler.class)))
.andAnswer(new IAnswer<ShellCommandUtil.Result>() {
@@ -320,9 +316,7 @@ public class MITKerberosOperationHandlerTest extends KerberosOperationHandlerTes
@Test(expected = KerberosRealmException.class)
public void testTestAdministratorCredentialsInvalidRealm() throws Exception {
- MITKerberosOperationHandler handler = createMockBuilder(MITKerberosOperationHandler.class)
- .addMockedMethod(methodExecuteCommand)
- .createNiceMock();
+ MITKerberosOperationHandler handler = createMock();
expect(handler.executeCommand(anyObject(String[].class), anyObject(Map.class), anyObject(MITKerberosOperationHandler.InteractivePasswordHandler.class)))
.andAnswer(new IAnswer<ShellCommandUtil.Result>() {
@@ -353,9 +347,7 @@ public class MITKerberosOperationHandlerTest extends KerberosOperationHandlerTes
@Test(expected = KerberosRealmException.class)
public void testTestAdministratorCredentialsInvalidRealm2() throws Exception {
- MITKerberosOperationHandler handler = createMockBuilder(MITKerberosOperationHandler.class)
- .addMockedMethod(methodExecuteCommand)
- .createNiceMock();
+ MITKerberosOperationHandler handler = createMock();
expect(handler.executeCommand(anyObject(String[].class), anyObject(Map.class), anyObject(MITKerberosOperationHandler.InteractivePasswordHandler.class)))
.andAnswer(new IAnswer<ShellCommandUtil.Result>() {
@@ -386,9 +378,7 @@ public class MITKerberosOperationHandlerTest extends KerberosOperationHandlerTes
@Test(expected = KerberosKDCConnectionException.class)
public void testTestAdministratorCredentialsKDCConnectionException() throws Exception {
- MITKerberosOperationHandler handler = createMockBuilder(MITKerberosOperationHandler.class)
- .addMockedMethod(methodExecuteCommand)
- .createNiceMock();
+ MITKerberosOperationHandler handler = createMock();
expect(handler.executeCommand(anyObject(String[].class), anyObject(Map.class), anyObject(MITKerberosOperationHandler.InteractivePasswordHandler.class)))
.andAnswer(new IAnswer<ShellCommandUtil.Result>() {
@@ -419,9 +409,7 @@ public class MITKerberosOperationHandlerTest extends KerberosOperationHandlerTes
@Test(expected = KerberosKDCConnectionException.class)
public void testTestAdministratorCredentialsKDCConnectionException2() throws Exception {
- MITKerberosOperationHandler handler = createMockBuilder(MITKerberosOperationHandler.class)
- .addMockedMethod(methodExecuteCommand)
- .createNiceMock();
+ MITKerberosOperationHandler handler = createMock();
expect(handler.executeCommand(anyObject(String[].class), anyObject(Map.class), anyObject(MITKerberosOperationHandler.InteractivePasswordHandler.class)))
.andAnswer(new IAnswer<ShellCommandUtil.Result>() {
@@ -452,9 +440,7 @@ public class MITKerberosOperationHandlerTest extends KerberosOperationHandlerTes
@Test
public void testTestAdministratorCredentialsNotFound() throws Exception {
- MITKerberosOperationHandler handler = createMockBuilder(MITKerberosOperationHandler.class)
- .addMockedMethod(methodExecuteCommand)
- .createNiceMock();
+ MITKerberosOperationHandler handler = createMock();
expect(handler.executeCommand(anyObject(String[].class), anyObject(Map.class), anyObject(MITKerberosOperationHandler.InteractivePasswordHandler.class)))
.andAnswer(new IAnswer<ShellCommandUtil.Result>() {
@@ -485,9 +471,7 @@ public class MITKerberosOperationHandlerTest extends KerberosOperationHandlerTes
@Test
public void testTestAdministratorCredentialsSuccess() throws Exception {
- MITKerberosOperationHandler handler = createMockBuilder(MITKerberosOperationHandler.class)
- .addMockedMethod(methodExecuteCommand)
- .createNiceMock();
+ MITKerberosOperationHandler handler = createMock();
expect(handler.executeCommand(anyObject(String[].class), anyObject(Map.class), anyObject(MITKerberosOperationHandler.InteractivePasswordHandler.class)))
.andAnswer(new IAnswer<ShellCommandUtil.Result>() {
@@ -562,4 +546,21 @@ public class MITKerberosOperationHandlerTest extends KerberosOperationHandlerTes
handler.testAdministratorCredentials();
handler.close();
}
+
+ private MITKerberosOperationHandler createMock(){
+ return createMock(false);
+ }
+
+ private MITKerberosOperationHandler createMock(boolean strict) {
+ IMockBuilder<MITKerberosOperationHandler> mockBuilder = createMockBuilder(MITKerberosOperationHandler.class)
+ .addMockedMethod(methodExecuteCommand);
+ MITKerberosOperationHandler result;
+ if(strict){
+ result = mockBuilder.createStrictMock();
+ } else {
+ result = mockBuilder.createNiceMock();
+ }
+ injector.injectMembers(result);
+ return result;
+ }
}
\ No newline at end of file