You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by rl...@apache.org on 2015/01/27 14:02:13 UTC
ambari git commit: AMBARI-9317. Kerberos: Need stdout to show info on
Kerberos-related tasks (rlevas)
Repository: ambari
Updated Branches:
refs/heads/trunk e50a1a6a0 -> 9fbcce8a3
AMBARI-9317. Kerberos: Need stdout to show info on Kerberos-related tasks (rlevas)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9fbcce8a
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9fbcce8a
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9fbcce8a
Branch: refs/heads/trunk
Commit: 9fbcce8a36e5f50db0be847eae882695a1dddebd
Parents: e50a1a6
Author: Robert Levas <rl...@hortonworks.com>
Authored: Tue Jan 27 08:00:45 2015 -0500
Committer: Robert Levas <rl...@hortonworks.com>
Committed: Tue Jan 27 08:02:01 2015 -0500
----------------------------------------------------------------------
.../serveraction/AbstractServerAction.java | 5 +
.../ambari/server/serveraction/ActionLog.java | 99 ++++++++++++++++++++
.../kerberos/ADKerberosOperationHandler.java | 2 +-
.../kerberos/CreateKeytabFilesServerAction.java | 33 ++++---
.../kerberos/CreatePrincipalsServerAction.java | 34 ++++---
.../kerberos/FinalizeKerberosServerAction.java | 13 ++-
.../kerberos/KerberosServerAction.java | 20 +++-
.../kerberos/MITKerberosOperationHandler.java | 47 ++--------
.../UpdateKerberosConfigsServerAction.java | 36 ++++---
.../server/serveraction/ActionLogTest.java | 59 ++++++++++++
10 files changed, 266 insertions(+), 82 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/9fbcce8a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/AbstractServerAction.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/AbstractServerAction.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/AbstractServerAction.java
index ff396e6..33191bf 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/AbstractServerAction.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/AbstractServerAction.java
@@ -47,6 +47,11 @@ public abstract class AbstractServerAction implements ServerAction {
*/
private HostRoleCommand hostRoleCommand = null;
+ /**
+ * The ActionLog that used to log execution progress of ServerAction
+ */
+ protected ActionLog actionLog = new ActionLog();
+
@Override
public ExecutionCommand getExecutionCommand() {
return this.executionCommand;
http://git-wip-us.apache.org/repos/asf/ambari/blob/9fbcce8a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/ActionLog.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/ActionLog.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/ActionLog.java
new file mode 100644
index 0000000..c2c3fe1
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/ActionLog.java
@@ -0,0 +1,99 @@
+/*
+ * 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.ambari.server.serveraction;
+
+import org.apache.commons.lang.time.FastDateFormat;
+
+import java.util.Date;
+
+/**
+ * ActionLog is a class for logging progress of ServerAction execution.
+ */
+public class ActionLog {
+ /**
+ * The StringBuffer to hold the messages logged to STDERR
+ */
+ private StringBuffer stdErr = new StringBuffer();
+
+ /**
+ * The StringBuffer to hold the messages logged to STDOUT
+ */
+ private StringBuffer stdOut = new StringBuffer();
+
+ /**
+ * A date formatter to use to format timestamps
+ * <p/>
+ * This is a thread-safe version of a date formatter
+ */
+ private FastDateFormat dateFormat = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss,SSS");
+
+ /**
+ * Append message to stdErr of action log.
+ *
+ * @param message text to append
+ */
+ public void writeStdErr(String message) {
+ write(stdErr, message);
+ }
+
+ /**
+ * Append message to stdOut of action log.
+ *
+ * @param message text to append
+ */
+ public void writeStdOut(String message) {
+ write(stdOut, message);
+ }
+
+ /**
+ * Return all text from stdErr.
+ *
+ * @return text of stdErr
+ */
+ public String getStdErr() {
+ return stdErr.toString();
+ }
+
+ /**
+ * Return all text from stdOut.
+ *
+ * @return text of stdOut
+ */
+ public String getStdOut() {
+ return stdOut.toString();
+ }
+
+
+ /**
+ * Appends a message to the specified buffer
+ *
+ * @param buffer the StringBuffer to use to append the formatted message
+ * @param message a String containing the message to log
+ */
+ private void write(StringBuffer buffer, String message) {
+ if (message != null) {
+ Date date = new Date();
+ buffer.append(dateFormat.format(date));
+ buffer.append(" - ");
+ buffer.append(message);
+ buffer.append("\n");
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/9fbcce8a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/ADKerberosOperationHandler.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/ADKerberosOperationHandler.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/ADKerberosOperationHandler.java
index b5de64f..839a82a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/ADKerberosOperationHandler.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/ADKerberosOperationHandler.java
@@ -563,4 +563,4 @@ public class ADKerberosOperationHandler extends KerberosOperationHandler {
return dn;
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/9fbcce8a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreateKeytabFilesServerAction.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreateKeytabFilesServerAction.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreateKeytabFilesServerAction.java
index 6e53140..1f6dc7f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreateKeytabFilesServerAction.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreateKeytabFilesServerAction.java
@@ -108,11 +108,15 @@ public class CreateKeytabFilesServerAction extends KerberosServerAction {
CommandReport commandReport = null;
if (identityRecord != null) {
+ String message = String.format("Creating keytab file for %s", evaluatedPrincipal);
+ LOG.info(message);
+ actionLog.writeStdOut(message);
if (operationHandler == null) {
- String message = String.format("Failed to create keytab file for %s, missing handler", evaluatedPrincipal);
+ message = String.format("Failed to create keytab file for %s, missing KerberosOperationHandler", evaluatedPrincipal);
+ actionLog.writeStdErr(message);
LOG.error(message);
- commandReport = createCommandReport(1, HostRoleStatus.FAILED, "{}", "", message);
+ commandReport = createCommandReport(1, HostRoleStatus.FAILED, "{}", actionLog.getStdOut(), actionLog.getStdErr());
} else {
Map<String, String> principalPasswordMap = getPrincipalPasswordMap(requestSharedDataContext);
Map<String, Integer> principalKeyNumberMap = getPrincipalKeyNumberMap(requestSharedDataContext);
@@ -126,9 +130,10 @@ public class CreateKeytabFilesServerAction extends KerberosServerAction {
String password = principalPasswordMap.get(evaluatedPrincipal);
if (password == null) {
- String message = String.format("Failed to create keytab file for %s, missing password", evaluatedPrincipal);
+ message = String.format("Failed to create keytab file for %s, missing password", evaluatedPrincipal);
+ actionLog.writeStdErr(message);
LOG.error(message);
- commandReport = createCommandReport(1, HostRoleStatus.FAILED, "{}", "", message);
+ commandReport = createCommandReport(1, HostRoleStatus.FAILED, "{}", actionLog.getStdOut(), actionLog.getStdErr());
} else {
// Determine where to store the keytab file. It should go into a host-specific
// directory under the previously determined data directory.
@@ -141,24 +146,26 @@ public class CreateKeytabFilesServerAction extends KerberosServerAction {
try {
if (operationHandler.createKeytabFile(evaluatedPrincipal, password, keyNumber, keytabFile)) {
- LOG.debug("Successfully created keytab file for {} at {}",
- evaluatedPrincipal, keytabFile.getAbsolutePath());
+ message = String.format("Successfully created keytab file for %s at %s", evaluatedPrincipal, keytabFile.getAbsolutePath());
+ LOG.debug(message);
} else {
- String message = String.format("Failed to create keytab file for %s at %s",
- evaluatedPrincipal, keytabFile.getAbsolutePath());
+ message = String.format("Failed to create keytab file for %s at %s", evaluatedPrincipal, keytabFile.getAbsolutePath());
+ actionLog.writeStdErr(message);
LOG.error(message);
- commandReport = createCommandReport(1, HostRoleStatus.FAILED, "{}", "", message);
+ commandReport = createCommandReport(1, HostRoleStatus.FAILED, "{}", actionLog.getStdOut(), actionLog.getStdErr());
}
} catch (KerberosOperationException e) {
- String message = String.format("Failed to create keytab file for %s - %s", evaluatedPrincipal, e.getMessage());
+ message = String.format("Failed to create keytab file for %s - %s", evaluatedPrincipal, e.getMessage());
+ actionLog.writeStdErr(message);
LOG.error(message, e);
- commandReport = createCommandReport(1, HostRoleStatus.FAILED, "{}", "", message);
+ commandReport = createCommandReport(1, HostRoleStatus.FAILED, "{}", actionLog.getStdOut(), actionLog.getStdErr());
}
} else {
- String message = String.format("Failed to create keytab file for %s, the container directory does not exist: %s",
+ message = String.format("Failed to create keytab file for %s, the container directory does not exist: %s",
evaluatedPrincipal, hostDirectory.getAbsolutePath());
+ actionLog.writeStdErr(message);
LOG.error(message);
- commandReport = createCommandReport(1, HostRoleStatus.FAILED, "{}", "", message);
+ commandReport = createCommandReport(1, HostRoleStatus.FAILED, "{}", actionLog.getStdOut(), actionLog.getStdErr());
}
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/9fbcce8a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreatePrincipalsServerAction.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreatePrincipalsServerAction.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreatePrincipalsServerAction.java
index 947b033..0a9304b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreatePrincipalsServerAction.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreatePrincipalsServerAction.java
@@ -93,44 +93,56 @@ public class CreatePrincipalsServerAction extends KerberosServerAction {
String password = principalPasswordMap.get(evaluatedPrincipal);
if (password == null) {
+ String message = String.format("Creating principal, %s", evaluatedPrincipal);
+ LOG.info(message);
+ actionLog.writeStdOut(message);
+
password = operationHandler.createSecurePassword();
try {
if (operationHandler.principalExists(evaluatedPrincipal)) {
// Create a new password since we need to know what it is.
// A new password/key would have been generated after exporting the keytab anyways.
- LOG.warn("Principal already exists, setting new password - {}", evaluatedPrincipal);
-
+ message = String.format("Principal, %s, already exists, setting new password", evaluatedPrincipal);
+ LOG.warn(message);
+ actionLog.writeStdOut(message);
Integer keyNumber = operationHandler.setPrincipalPassword(evaluatedPrincipal, password);
if (keyNumber != null) {
principalPasswordMap.put(evaluatedPrincipal, password);
principalKeyNumberMap.put(evaluatedPrincipal, keyNumber);
- LOG.debug("Successfully set password for principal {}", evaluatedPrincipal);
+ message = String.format("Successfully set password for %s", evaluatedPrincipal);
+ LOG.debug(message);
} else {
- String message = String.format("Failed to set password for principal %s - unknown reason", evaluatedPrincipal);
+ message = String.format("Failed to set password for %s - unknown reason", evaluatedPrincipal);
LOG.error(message);
- commandReport = createCommandReport(1, HostRoleStatus.FAILED, "{}", "", message);
+ actionLog.writeStdErr(message);
+ commandReport = createCommandReport(1, HostRoleStatus.FAILED, "{}", actionLog.getStdOut(), actionLog.getStdErr());
}
} else {
- LOG.debug("Creating new principal - {}", evaluatedPrincipal);
+ message = String.format("Creating new principal, %s", evaluatedPrincipal);
+ LOG.debug(message);
+
boolean servicePrincipal = "service".equalsIgnoreCase(identityRecord.get(KerberosActionDataFile.PRINCIPAL_TYPE));
Integer keyNumber = operationHandler.createPrincipal(evaluatedPrincipal, password, servicePrincipal);
if (keyNumber != null) {
principalPasswordMap.put(evaluatedPrincipal, password);
principalKeyNumberMap.put(evaluatedPrincipal, keyNumber);
- LOG.debug("Successfully created new principal {}", evaluatedPrincipal);
+ message = String.format("Successfully created new principal, %s", evaluatedPrincipal);
+ LOG.debug(message);
} else {
- String message = String.format("Failed to create principal %s - unknown reason", evaluatedPrincipal);
+ message = String.format("Failed to create principal, %s - unknown reason", evaluatedPrincipal);
LOG.error(message);
- commandReport = createCommandReport(1, HostRoleStatus.FAILED, "{}", "", message);
+ actionLog.writeStdErr(message);
+ commandReport = createCommandReport(1, HostRoleStatus.FAILED, "{}", actionLog.getStdOut(), actionLog.getStdErr());
}
}
} catch (KerberosOperationException e) {
- String message = String.format("Failed to create principal %s - %s", evaluatedPrincipal, e.getMessage());
+ message = String.format("Failed to create principal, %s - %s", evaluatedPrincipal, e.getMessage());
LOG.error(message, e);
- commandReport = createCommandReport(1, HostRoleStatus.FAILED, "{}", "", message);
+ actionLog.writeStdErr(message);
+ commandReport = createCommandReport(1, HostRoleStatus.FAILED, "{}", actionLog.getStdOut(), actionLog.getStdErr());
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/9fbcce8a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/FinalizeKerberosServerAction.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/FinalizeKerberosServerAction.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/FinalizeKerberosServerAction.java
index 1860c97..4925582 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/FinalizeKerberosServerAction.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/FinalizeKerberosServerAction.java
@@ -83,6 +83,12 @@ public class FinalizeKerberosServerAction extends KerberosServerAction {
for (ServiceComponentHost sch : serviceComponentHosts) {
SecurityState securityState = sch.getSecurityState();
if (securityState.isTransitional()) {
+ String message = String.format("Setting securityState for %s/%s on host %s to state %s",
+ sch.getServiceName(), sch.getServiceComponentName(), sch.getHostName(),
+ sch.getDesiredSecurityState().toString());
+ LOG.info(message);
+ actionLog.writeStdOut(message);
+
sch.setSecurityState(sch.getDesiredSecurityState());
}
}
@@ -104,12 +110,13 @@ public class FinalizeKerberosServerAction extends KerberosServerAction {
} catch (IOException e) {
// We should log this exception, but don't let it fail the process since if we got to this
// KerberosServerAction it is expected that the the overall process was a success.
- LOG.warn(String.format("The data directory (%s) was not deleted due to an error condition - {%s}",
- dataDirectory.getAbsolutePath(), e.getMessage()), e);
+ String message = String.format("The data directory (%s) was not deleted due to an error condition - {%s}",
+ dataDirectory.getAbsolutePath(), e.getMessage());
+ LOG.warn(message, e);
}
}
}
- return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", null, null);
+ return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", actionLog.getStdOut(), actionLog.getStdErr());
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/9fbcce8a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/KerberosServerAction.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/KerberosServerAction.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/KerberosServerAction.java
index e965bd5..e2cb384 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/KerberosServerAction.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/KerberosServerAction.java
@@ -311,6 +311,9 @@ public abstract class KerberosServerAction extends AbstractServerAction {
CommandReport commandReport = null;
Map<String, String> commandParameters = getCommandParameters();
+ actionLog.writeStdOut("Processing identities...");
+ LOG.info("Processing identities...");
+
if (commandParameters != null) {
// Grab the relevant data from this action's command parameters map
KerberosCredential administratorCredential = getAdministratorCredential(commandParameters);
@@ -326,6 +329,7 @@ public abstract class KerberosServerAction extends AbstractServerAction {
if (!dataDirectory.isDirectory() || !dataDirectory.canRead()) {
String message = String.format("Failed to process the identities, the data directory is not accessible: %s",
dataDirectory.getAbsolutePath());
+ actionLog.writeStdErr(message);
LOG.error(message);
throw new AmbariException(message);
}
@@ -337,6 +341,7 @@ public abstract class KerberosServerAction extends AbstractServerAction {
if (!indexFile.canRead()) {
String message = String.format("Failed to process the identities, cannot read the index file: %s",
indexFile.getAbsolutePath());
+ actionLog.writeStdErr(message);
LOG.error(message);
throw new AmbariException(message);
}
@@ -345,6 +350,7 @@ public abstract class KerberosServerAction extends AbstractServerAction {
if (handler == null) {
String message = String.format("Failed to process the identities, a KDC operation handler was not found for the KDC type of : %s",
kdcType.toString());
+ actionLog.writeStdErr(message);
LOG.error(message);
throw new AmbariException(message);
}
@@ -354,6 +360,7 @@ public abstract class KerberosServerAction extends AbstractServerAction {
} catch (KerberosOperationException e) {
String message = String.format("Failed to process the identities, could not properly open the KDC operation handler: %s",
e.getMessage());
+ actionLog.writeStdErr(message);
LOG.error(message);
throw new AmbariException(message, e);
}
@@ -379,6 +386,7 @@ public abstract class KerberosServerAction extends AbstractServerAction {
} catch (IOException e) {
String message = String.format("Failed to process the identities, cannot read the index file: %s",
indexFile.getAbsolutePath());
+ actionLog.writeStdErr(message);
LOG.error(message, e);
throw new AmbariException(message, e);
} finally {
@@ -405,10 +413,13 @@ public abstract class KerberosServerAction extends AbstractServerAction {
}
}
+ actionLog.writeStdOut("Processing identities completed.");
+ LOG.info("Processing identities completed.");
+
// If commandReport is null, we can assume this operation was a success, so return a successful
// CommandReport; else return the previously created CommandReport.
return (commandReport == null)
- ? createCommandReport(0, HostRoleStatus.COMPLETED, "{}", null, null)
+ ? createCommandReport(0, HostRoleStatus.COMPLETED, "{}", actionLog.getStdOut(), actionLog.getStdErr())
: commandReport;
}
@@ -464,9 +475,14 @@ public abstract class KerberosServerAction extends AbstractServerAction {
String host = record.get(KerberosActionDataFile.HOSTNAME);
if (principal != null) {
- // Evaluate the principal "pattern" found in the record to generate the "evaluated p[rincipal"
+ // Evaluate the principal "pattern" found in the record to generate the "evaluated principal"
// by replacing the _HOST and _REALM variables.
String evaluatedPrincipal = principal.replace("_HOST", host).replace("_REALM", defaultRealm);
+
+ String message = String.format("Processing identity for %s", evaluatedPrincipal);
+ actionLog.writeStdOut(message);
+ LOG.info(message);
+
commandReport = processIdentity(record, evaluatedPrincipal, operationHandler, requestSharedDataContext);
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/9fbcce8a/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 c79b846..7425f1a 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
@@ -106,15 +106,7 @@ public class MITKerberosOperationHandler extends KerberosOperationHandler {
return false;
} else {
// Create the KAdmin query to execute:
- String query = String.format("get_principal %s", principal);
-
- ShellCommandUtil.Result result;
- try {
- result = invokeKAdmin(query);
- } catch (KerberosOperationException e) {
- LOG.error(String.format("Failed to query for principal %s", principal), e);
- throw e;
- }
+ ShellCommandUtil.Result result = invokeKAdmin(String.format("get_principal %s", principal));
// If there is data from STDOUT, see if the following string exists:
// Principal: <principal>
@@ -153,13 +145,7 @@ public class MITKerberosOperationHandler extends KerberosOperationHandler {
throw new KerberosOperationException("Failed to create new principal - no password specified");
} else {
// Create the kdamin query: add_principal <-randkey|-pw <password>> <principal>
- ShellCommandUtil.Result result;
- try {
- result = invokeKAdmin(String.format("add_principal -pw %s %s", password, principal));
- } catch (KerberosOperationException e) {
- LOG.error(String.format("Failed to create new principal for %s", principal), e);
- throw e;
- }
+ ShellCommandUtil.Result result = invokeKAdmin(String.format("add_principal -pw %s %s", password, principal));
// If there is data from STDOUT, see if the following string exists:
// Principal "<principal>" created
@@ -198,12 +184,7 @@ public class MITKerberosOperationHandler extends KerberosOperationHandler {
throw new KerberosOperationException("Failed to set password - no password specified");
} else {
// Create the kdamin query: change_password <-randkey|-pw <password>> <principal>
- try {
- invokeKAdmin(String.format("change_password -pw %s %s", password, principal));
- } catch (KerberosOperationException e) {
- LOG.error(String.format("Failed to set password for %s", principal), e);
- throw e;
- }
+ invokeKAdmin(String.format("change_password -pw %s %s", password, principal));
return getKeyNumber(principal);
}
@@ -230,14 +211,7 @@ public class MITKerberosOperationHandler extends KerberosOperationHandler {
if ((principal == null) || principal.isEmpty()) {
throw new KerberosOperationException("Failed to remove new principal - no principal specified");
} else {
- ShellCommandUtil.Result result;
-
- try {
- result = invokeKAdmin(String.format("delete_principal -force %s", principal));
- } catch (KerberosOperationException e) {
- LOG.error(String.format("Failed to remove new principal for %s", principal), e);
- throw e;
- }
+ ShellCommandUtil.Result result = invokeKAdmin(String.format("delete_principal -force %s", principal));
// If there is data from STDOUT, see if the following string exists:
// Principal "<principal>" created
@@ -265,15 +239,7 @@ public class MITKerberosOperationHandler extends KerberosOperationHandler {
throw new KerberosOperationException("Failed to get key number for principal - no principal specified");
} else {
// Create the kdamin query: get_principal <principal>
- String query = String.format("get_principal %s", principal);
-
- ShellCommandUtil.Result result;
- try {
- result = invokeKAdmin(query);
- } catch (KerberosOperationException e) {
- LOG.error(String.format("Failed to get key number for %s", principal), e);
- throw e;
- }
+ ShellCommandUtil.Result result = invokeKAdmin(String.format("get_principal %s", principal));
String stdOut = result.getStdout();
if (stdOut == null) {
@@ -422,6 +388,9 @@ public class MITKerberosOperationHandler extends KerberosOperationHandler {
else if (stdErr.contains("Cannot contact any KDC")) {
throw new KerberosKDCConnectionException(stdErr);
}
+ else if (stdErr.contains("Cannot resolve network address for admin server in requested realm while initializing kadmin interface")) {
+ throw new KerberosKDCConnectionException(stdErr);
+ }
// Was the realm invalid?
else if (stdErr.contains("Missing parameters in krb5.conf required for kadmin client")) {
throw new KerberosRealmException(stdErr);
http://git-wip-us.apache.org/repos/asf/ambari/blob/9fbcce8a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/UpdateKerberosConfigsServerAction.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/UpdateKerberosConfigsServerAction.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/UpdateKerberosConfigsServerAction.java
index cac45d3..00886db 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/UpdateKerberosConfigsServerAction.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/UpdateKerberosConfigsServerAction.java
@@ -140,8 +140,10 @@ public class UpdateKerberosConfigsServerAction extends AbstractServerAction {
}
} catch (IOException e) {
String message = "Could not update services configs to enable kerberos";
+ actionLog.writeStdErr(message);
LOG.error(message, e);
- commandReport = createCommandReport(1, HostRoleStatus.FAILED, "{}", "", message);
+ commandReport = createCommandReport(1, HostRoleStatus.FAILED, "{}", actionLog.getStdOut(),
+ actionLog.getStdErr());
} finally {
if (indexReader != null && !indexReader.isClosed()) {
try {
@@ -162,7 +164,7 @@ public class UpdateKerberosConfigsServerAction extends AbstractServerAction {
}
return (commandReport == null)
- ? createCommandReport(0, HostRoleStatus.COMPLETED, "{}", null, null)
+ ? createCommandReport(0, HostRoleStatus.COMPLETED, "{}", actionLog.getStdOut(), actionLog.getStdErr())
: commandReport;
}
@@ -189,7 +191,7 @@ public class UpdateKerberosConfigsServerAction extends AbstractServerAction {
throws AmbariException {
String newTag = "version" + System.currentTimeMillis();
-
+ String message;
if ((properties != null) && (properties.size() > 0)) {
Map<String, Config> all = cluster.getConfigsByType(configType);
if (all == null || !all.containsKey(newTag)) {
@@ -197,8 +199,10 @@ public class UpdateKerberosConfigsServerAction extends AbstractServerAction {
Config oldConfig = cluster.getDesiredConfigByType(configType);
if (oldConfig == null && !createNewConfigType) {
- LOG.info("Config " + configType + " not found. Assuming service not installed. " +
- "Skipping configuration properties update");
+ message = String.format("Config %s not found. Assuming service not installed. " +
+ "Skipping configuration properties update", configType);
+ actionLog.writeStdOut(message);
+ LOG.info(message);
return;
} else if (oldConfig == null) {
oldConfigProperties = new HashMap<String, String>();
@@ -211,8 +215,10 @@ public class UpdateKerberosConfigsServerAction extends AbstractServerAction {
mergeProperties(oldConfigProperties, properties, updateIfExists);
if (!Maps.difference(oldConfigProperties, mergedProperties).areEqual()) {
- LOG.info("Applying configuration with tag '{}' to " +
- "cluster '{}'", newTag, cluster.getClusterName());
+ message = String.format("Applying configuration with tag '%s' to " +
+ "cluster '%s'", newTag, cluster.getClusterName());
+ actionLog.writeStdOut(message);
+ LOG.info(message);
ConfigurationRequest cr = new ConfigurationRequest();
cr.setClusterName(cluster.getClusterName());
@@ -228,15 +234,19 @@ public class UpdateKerberosConfigsServerAction extends AbstractServerAction {
if (cluster.addDesiredConfig(authName, Collections.singleton(baseConfig)) != null) {
String oldConfigString = (oldConfig != null) ? " from='" + oldConfig.getTag() + "'" : "";
- LOG.info("cluster '" + cluster.getClusterName() + "' "
- + "changed by: '" + authName + "'; "
- + "type='" + baseConfig.getType() + "' "
- + "tag='" + baseConfig.getTag() + "'"
- + oldConfigString);
+ message = "cluster '" + cluster.getClusterName() + "' "
+ + "changed by: '" + authName + "'; "
+ + "type='" + baseConfig.getType() + "' "
+ + "tag='" + baseConfig.getTag() + "'"
+ + oldConfigString;
+ LOG.info(message);
+ actionLog.writeStdOut(message);
}
}
} else {
- LOG.info("No changes detected to config " + configType + ". Skipping configuration properties update");
+ message = "No changes detected to config " + configType + ". Skipping configuration properties update";
+ LOG.info(message);
+ actionLog.writeStdOut(message);
}
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/9fbcce8a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/ActionLogTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/ActionLogTest.java b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/ActionLogTest.java
new file mode 100644
index 0000000..69c9993
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/ActionLogTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.ambari.server.serveraction;
+
+import junit.framework.Assert;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class ActionLogTest {
+
+ @Test
+ public void testWriteStdErr() throws Exception {
+ ActionLog actionLog = new ActionLog();
+
+ // Null message should not produce ill effects, they should be ignored
+ actionLog.writeStdErr(null);
+ Assert.assertEquals("", actionLog.getStdErr());
+ Assert.assertEquals("", actionLog.getStdOut());
+
+ // Writing to STDERR, shouldn't alter STDOUT
+ actionLog.writeStdErr("This is a test message");
+ Assert.assertNotNull(actionLog.getStdErr());
+ Assert.assertTrue(actionLog.getStdErr().contains("This is a test message"));
+ Assert.assertEquals("", actionLog.getStdOut());
+ }
+
+ @Test
+ public void testWriteStdOut() throws Exception {
+ ActionLog actionLog = new ActionLog();
+
+ // Null message should not produce ill effects, they should be ignored
+ actionLog.writeStdOut(null);
+ Assert.assertEquals("", actionLog.getStdOut());
+ Assert.assertEquals("", actionLog.getStdErr());
+
+ // Writing to STDOUT, shouldn't alter STDERR
+ actionLog.writeStdOut("This is a test message");
+ Assert.assertNotNull(actionLog.getStdErr());
+ Assert.assertTrue(actionLog.getStdOut().contains("This is a test message"));
+ Assert.assertEquals("", actionLog.getStdErr());
+ }
+}
\ No newline at end of file