Skip to content

Commit

Permalink
[hotfix][yarn-tests] Check the applicationId in verifyStringsInNamedL…
Browse files Browse the repository at this point in the history
…ogFiles
  • Loading branch information
wangyang0918 authored and tillrohrmann committed Apr 9, 2021
1 parent aff7bb3 commit 3b6af3d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void testDetachedMode() throws Exception {
}

/** Test regular operation, including command line parameter parsing. */
void runDetachedModeTest(Map<String, String> securityProperties) throws Exception {
ApplicationId runDetachedModeTest(Map<String, String> securityProperties) throws Exception {
LOG.info("Starting testDetachedMode()");

File exampleJarLocation = getTestJarPath("StreamingWordCount.jar");
Expand Down Expand Up @@ -169,10 +169,12 @@ void runDetachedModeTest(Map<String, String> securityProperties) throws Exceptio
+ ")");

LOG.info("Waiting until the job reaches FINISHED state");
final ApplicationId applicationId = getOnlyApplicationReport().getApplicationId();
CommonTestUtils.waitUntilCondition(
() ->
verifyStringsInNamedLogFiles(
new String[] {"switched from state RUNNING to FINISHED"},
applicationId,
"jobmanager.log"),
Deadline.fromNow(timeout),
testConditionIntervalInMillis,
Expand Down Expand Up @@ -242,6 +244,7 @@ void runDetachedModeTest(Map<String, String> securityProperties) throws Exceptio
}

LOG.info("Finished testDetachedMode()");
return applicationId;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import org.apache.flink.shaded.guava18.com.google.common.collect.Lists;

import org.apache.hadoop.yarn.api.records.ApplicationId;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.hadoop.yarn.security.AMRMTokenIdentifier;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler;
Expand Down Expand Up @@ -150,8 +151,8 @@ public void testDetachedModeSecureWithPreInstallKeytab() throws Exception {
SecurityOptions.KERBEROS_LOGIN_PRINCIPAL.key(),
SecureTestEnvironment.getHadoopServicePrincipal());
}
runDetachedModeTest(securityProperties);
verifyResultContainsKerberosKeytab();
final ApplicationId applicationId = runDetachedModeTest(securityProperties);
verifyResultContainsKerberosKeytab(applicationId);
});
}

Expand All @@ -171,17 +172,18 @@ public void testDetachedMode() throws Exception {
SecurityOptions.KERBEROS_LOGIN_PRINCIPAL.key(),
SecureTestEnvironment.getHadoopServicePrincipal());
}
runDetachedModeTest(securityProperties);
verifyResultContainsKerberosKeytab();
final ApplicationId applicationId = runDetachedModeTest(securityProperties);
verifyResultContainsKerberosKeytab(applicationId);
});
}

private static void verifyResultContainsKerberosKeytab() throws Exception {
private static void verifyResultContainsKerberosKeytab(ApplicationId applicationId)
throws Exception {
final String[] mustHave = {"Login successful for user", "using keytab file"};
final boolean jobManagerRunsWithKerberos =
verifyStringsInNamedLogFiles(mustHave, "jobmanager.log");
verifyStringsInNamedLogFiles(mustHave, applicationId, "jobmanager.log");
final boolean taskManagerRunsWithKerberos =
verifyStringsInNamedLogFiles(mustHave, "taskmanager.log");
verifyStringsInNamedLogFiles(mustHave, applicationId, "taskmanager.log");

Assert.assertThat(
"The JobManager and the TaskManager should both run with Kerberos.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import static org.apache.flink.util.Preconditions.checkState;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -599,14 +600,14 @@ public boolean accept(File dir, String name) {
}

public static boolean verifyStringsInNamedLogFiles(
final String[] mustHave, final String fileName) {
List<String> mustHaveList = Arrays.asList(mustHave);
File cwd = new File("target/" + YARN_CONFIGURATION.get(TEST_CLUSTER_NAME_KEY));
final String[] mustHave, final ApplicationId applicationId, final String fileName) {
final List<String> mustHaveList = Arrays.asList(mustHave);
final File cwd = new File("target", YARN_CONFIGURATION.get(TEST_CLUSTER_NAME_KEY));
if (!cwd.exists() || !cwd.isDirectory()) {
return false;
}

File foundFile =
final File foundFile =
TestUtils.findFile(
cwd.getAbsolutePath(),
new FilenameFilter() {
Expand All @@ -615,10 +616,15 @@ public boolean accept(File dir, String name) {
if (fileName != null && !name.equals(fileName)) {
return false;
}
File f = new File(dir.getAbsolutePath() + "/" + name);
final File f = new File(dir.getAbsolutePath(), name);
// Only check the specified application logs
if (StreamSupport.stream(f.toPath().spliterator(), false)
.noneMatch(p -> p.endsWith(applicationId.toString()))) {
return false;
}
LOG.info("Searching in {}", f.getAbsolutePath());
try (Scanner scanner = new Scanner(f)) {
Set<String> foundSet = new HashSet<>(mustHave.length);
final Set<String> foundSet = new HashSet<>(mustHave.length);
while (scanner.hasNextLine()) {
final String lineFromFile = scanner.nextLine();
for (String str : mustHave) {
Expand Down

0 comments on commit 3b6af3d

Please sign in to comment.