Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@
import org.apache.hadoop.yarn.webapp.NotFoundException;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;

import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Private
@Evolving
Expand All @@ -61,6 +62,7 @@ public class WebAppUtils {
"ssl.server.keystore.keypassword";
public static final String HTTPS_PREFIX = "https://";
public static final String HTTP_PREFIX = "http://";
public static final Logger LOG = LoggerFactory.getLogger(WebAppUtils.class);

public static void setRMWebAppPort(Configuration conf, int port) {
String hostname = getRMWebAppURLWithoutScheme(conf);
Expand Down Expand Up @@ -509,11 +511,16 @@ static String getPassword(Configuration conf, String alias) {
char[] passchars = conf.getPassword(alias);
if (passchars != null) {
password = new String(passchars);
LOG.debug("Successful password retrival for alias: {}", alias);
} else {
LOG.warn("Password retrieval failed, no password found for alias: {}", alias);
}
}
catch (IOException ioe) {
password = null;
LOG.error("Unable to retrieve password for alias: {}", alias, ioe);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If i see well here the void error(String var1, Object var2, Object var3); called, so the 3th throwable wont be logged in this case. Also in this case two error log will be created, so maybe debug level will be also fine here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @K0K0V0K,
Thank you for your feedbacks. By default SLF4J logging will handle the Throwable as the last parameter for exception logging. Therefore, I do not need another place {} holder for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried with a DEBUG level log and log message does not appear when I run the unit test that simulate the Exception. I think it better with an ERROR level because now I changed when the password is null it log with WARN level. So when the exception happens, it will log with two log messages in two levels ERROR and WARN.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, seems you are right

}

return password;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ void testGetPassword() throws Exception {
assertNull(WebAppUtils.getPassword(conf, "invalid-alias"));
}

@Test
void testGetPasswordIOException() throws Exception {
Configuration mockConf = Mockito.mock(Configuration.class);

Mockito.when(mockConf.getPassword("error-alias")).thenThrow(new IOException("Simulated IO error"));

assertNull(WebAppUtils.getPassword(mockConf, "error-alias"));
}

@Test
void testLoadSslConfiguration() throws Exception {
Configuration conf = provisionCredentialsForSSL();
Expand Down
Loading