Skip to content

Commit f7df55f

Browse files
committed
YARN-9602. Use logger format in Container Executor. Contributed by Abhishek Modi.
1 parent b057479 commit f7df55f

File tree

3 files changed

+65
-65
lines changed

3 files changed

+65
-65
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/ContainerExecutor.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public int reacquireContainer(ContainerReacquisitionContext ctx)
290290
Path pidPath = getPidFilePath(containerId);
291291

292292
if (pidPath == null) {
293-
LOG.warn(containerId + " is not active, returning terminated error");
293+
LOG.warn("{} is not active, returning terminated error", containerId);
294294

295295
return ExitCode.TERMINATED.getExitCode();
296296
}
@@ -301,7 +301,7 @@ public int reacquireContainer(ContainerReacquisitionContext ctx)
301301
throw new IOException("Unable to determine pid for " + containerId);
302302
}
303303

304-
LOG.info("Reacquiring " + containerId + " with pid " + pid);
304+
LOG.info("Reacquiring {} with pid {}", containerId, pid);
305305

306306
ContainerLivenessContext livenessContext = new ContainerLivenessContext
307307
.Builder()
@@ -322,7 +322,7 @@ public int reacquireContainer(ContainerReacquisitionContext ctx)
322322

323323
while (!file.exists() && msecLeft >= 0) {
324324
if (!isContainerActive(containerId)) {
325-
LOG.info(containerId + " was deactivated");
325+
LOG.info("{} was deactivated", containerId);
326326

327327
return ExitCode.TERMINATED.getExitCode();
328328
}
@@ -754,7 +754,7 @@ public static String[] getLocalIpAndHost(Container container) {
754754
ipAndHost[0] = address.getHostAddress();
755755
ipAndHost[1] = address.getHostName();
756756
} catch (UnknownHostException e) {
757-
LOG.error("Unable to get Local hostname and ip for " + container
757+
LOG.error("Unable to get Local hostname and ip for {}", container
758758
.getContainerId(), e);
759759
}
760760
return ipAndHost;
@@ -782,7 +782,7 @@ public void deactivateContainer(ContainerId containerId) {
782782
* the Container
783783
*/
784784
public void pauseContainer(Container container) {
785-
LOG.warn(container.getContainerId() + " doesn't support pausing.");
785+
LOG.warn("{} doesn't support pausing.", container.getContainerId());
786786
throw new UnsupportedOperationException();
787787
}
788788

@@ -793,7 +793,7 @@ public void pauseContainer(Container container) {
793793
* the Container
794794
*/
795795
public void resumeContainer(Container container) {
796-
LOG.warn(container.getContainerId() + " doesn't support resume.");
796+
LOG.warn("{} doesn't support resume.", container.getContainerId());
797797
throw new UnsupportedOperationException();
798798
}
799799

@@ -835,7 +835,7 @@ public String getProcessId(ContainerId containerID) {
835835
try {
836836
pid = ProcessIdFileReader.getProcessId(pidFile);
837837
} catch (IOException e) {
838-
LOG.error("Got exception reading pid from pid-file " + pidFile, e);
838+
LOG.error("Got exception reading pid from pid-file {}", pidFile, e);
839839
}
840840
}
841841

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/DefaultContainerExecutor.java

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,15 @@ public void startLocalizer(LocalizerStartContext ctx)
167167
String tokenFn = String.format(TOKEN_FILE_NAME_FMT, locId);
168168
Path tokenDst = new Path(appStorageDir, tokenFn);
169169
copyFile(nmPrivateContainerTokensPath, tokenDst, user);
170-
LOG.info("Copying from " + nmPrivateContainerTokensPath
171-
+ " to " + tokenDst);
170+
LOG.info("Copying from {} to {}", nmPrivateContainerTokensPath, tokenDst);
172171

173172

174173
FileContext localizerFc =
175174
FileContext.getFileContext(lfs.getDefaultFileSystem(), getConf());
176175
localizerFc.setUMask(lfs.getUMask());
177176
localizerFc.setWorkingDirectory(appStorageDir);
178-
LOG.info("Localizer CWD set to " + appStorageDir + " = "
179-
+ localizerFc.getWorkingDirectory());
177+
LOG.info("Localizer CWD set to {} = {}", appStorageDir,
178+
localizerFc.getWorkingDirectory());
180179

181180
ContainerLocalizer localizer =
182181
createContainerLocalizer(user, appId, locId, tokenFn, localDirs,
@@ -292,8 +291,8 @@ public int launchContainer(ContainerStartContext ctx)
292291
if (pidFile != null) {
293292
sb.writeLocalWrapperScript(launchDst, pidFile);
294293
} else {
295-
LOG.info("Container " + containerIdStr
296-
+ " pid file not set. Returning terminated error");
294+
LOG.info("Container {} pid file not set. Returning terminated error",
295+
containerIdStr);
297296
return ExitCode.TERMINATED.getExitCode();
298297
}
299298

@@ -312,23 +311,23 @@ public int launchContainer(ContainerStartContext ctx)
312311
if (isContainerActive(containerId)) {
313312
shExec.execute();
314313
} else {
315-
LOG.info("Container " + containerIdStr +
316-
" was marked as inactive. Returning terminated error");
314+
LOG.info("Container {} was marked as inactive. "
315+
+ "Returning terminated error", containerIdStr);
317316
return ExitCode.TERMINATED.getExitCode();
318317
}
319318
} catch (IOException e) {
320319
if (null == shExec) {
321320
return -1;
322321
}
323322
int exitCode = shExec.getExitCode();
324-
LOG.warn("Exit code from container " + containerId + " is : " + exitCode);
323+
LOG.warn("Exit code from container {} is : {}", containerId, exitCode);
325324
// 143 (SIGTERM) and 137 (SIGKILL) exit codes means the container was
326325
// terminated/killed forcefully. In all other cases, log the
327326
// container-executor's output
328327
if (exitCode != ExitCode.FORCE_KILLED.getExitCode()
329328
&& exitCode != ExitCode.TERMINATED.getExitCode()) {
330-
LOG.warn("Exception from container-launch with container ID: "
331-
+ containerId + " and exit code: " + exitCode , e);
329+
LOG.warn("Exception from container-launch with container ID: {}"
330+
+ " and exit code: {}", containerId, exitCode, e);
332331

333332
StringBuilder builder = new StringBuilder();
334333
builder.append("Exception from container-launch.\n")
@@ -386,13 +385,13 @@ protected CommandExecutor buildCommandExecutor(String wrapperScriptPath,
386385
String[] command = getRunCommand(wrapperScriptPath,
387386
containerIdStr, user, pidFile, this.getConf(), resource);
388387

389-
LOG.info("launchContainer: " + Arrays.toString(command));
390-
return new ShellCommandExecutor(
391-
command,
392-
workDir,
393-
environment,
394-
0L,
395-
false);
388+
LOG.info("launchContainer: {}", Arrays.toString(command));
389+
return new ShellCommandExecutor(
390+
command,
391+
workDir,
392+
environment,
393+
0L,
394+
false);
396395
}
397396

398397
/**
@@ -648,19 +647,19 @@ public void deleteAsUser(DeletionAsUserContext ctx)
648647
List<Path> baseDirs = ctx.getBasedirs();
649648

650649
if (baseDirs == null || baseDirs.size() == 0) {
651-
LOG.info("Deleting absolute path : " + subDir);
650+
LOG.info("Deleting absolute path : {}", subDir);
652651
if (!lfs.delete(subDir, true)) {
653652
//Maybe retry
654-
LOG.warn("delete returned false for path: [" + subDir + "]");
653+
LOG.warn("delete returned false for path: [{}]", subDir);
655654
}
656655
return;
657656
}
658657
for (Path baseDir : baseDirs) {
659658
Path del = subDir == null ? baseDir : new Path(baseDir, subDir);
660-
LOG.info("Deleting path : " + del);
659+
LOG.info("Deleting path : {}", del);
661660
try {
662661
if (!lfs.delete(del, true)) {
663-
LOG.warn("delete returned false for path: [" + del + "]");
662+
LOG.warn("delete returned false for path: [{}]", del);
664663
}
665664
} catch (FileNotFoundException e) {
666665
continue;
@@ -743,7 +742,7 @@ protected Path getWorkingDir(List<String> localDirs, String user,
743742
try {
744743
space = getDiskFreeSpace(curBase);
745744
} catch (IOException e) {
746-
LOG.warn("Unable to get Free Space for " + curBase.toString(), e);
745+
LOG.warn("Unable to get Free Space for {}", curBase, e);
747746
}
748747
availableOnDisk[i++] = space;
749748
totalAvailable += space;
@@ -823,7 +822,7 @@ void createUserLocalDirs(List<String> localDirs, String user)
823822
createDir(getUserCacheDir(new Path(localDir), user), userperms, true,
824823
user);
825824
} catch (IOException e) {
826-
LOG.warn("Unable to create the user directory : " + localDir, e);
825+
LOG.warn("Unable to create the user directory : {}", localDir, e);
827826
continue;
828827
}
829828
userDirStatus = true;
@@ -850,7 +849,7 @@ void createUserLocalDirs(List<String> localDirs, String user)
850849
*/
851850
void createUserCacheDirs(List<String> localDirs, String user)
852851
throws IOException {
853-
LOG.info("Initializing user " + user);
852+
LOG.info("Initializing user {}", user);
854853

855854
boolean appcacheDirStatus = false;
856855
boolean distributedCacheDirStatus = false;
@@ -865,15 +864,15 @@ void createUserCacheDirs(List<String> localDirs, String user)
865864
createDir(appDir, appCachePerms, true, user);
866865
appcacheDirStatus = true;
867866
} catch (IOException e) {
868-
LOG.warn("Unable to create app cache directory : " + appDir, e);
867+
LOG.warn("Unable to create app cache directory : {}", appDir, e);
869868
}
870869
// create $local.dir/usercache/$user/filecache
871870
final Path distDir = getFileCacheDir(localDirPath, user);
872871
try {
873872
createDir(distDir, fileperms, true, user);
874873
distributedCacheDirStatus = true;
875874
} catch (IOException e) {
876-
LOG.warn("Unable to create file cache directory : " + distDir, e);
875+
LOG.warn("Unable to create file cache directory : {}", distDir, e);
877876
}
878877
}
879878
if (!appcacheDirStatus) {
@@ -911,7 +910,8 @@ void createAppDirs(List<String> localDirs, String user, String appId)
911910
createDir(fullAppDir, appperms, true, user);
912911
initAppDirStatus = true;
913912
} catch (IOException e) {
914-
LOG.warn("Unable to create app directory " + fullAppDir.toString(), e);
913+
LOG.warn("Unable to create app directory {}",
914+
fullAppDir, e);
915915
}
916916
}
917917
if (!initAppDirStatus) {
@@ -942,7 +942,7 @@ void createAppLogDirs(String appId, List<String> logDirs, String user)
942942
try {
943943
createDir(appLogDir, appLogDirPerms, true, user);
944944
} catch (IOException e) {
945-
LOG.warn("Unable to create the app-log directory : " + appLogDir, e);
945+
LOG.warn("Unable to create the app-log directory : {}", appLogDir, e);
946946
continue;
947947
}
948948
appLogDirStatus = true;
@@ -976,8 +976,8 @@ void createContainerLogDirs(String appId, String containerId,
976976
try {
977977
createDir(containerLogDir, containerLogDirPerms, true, user);
978978
} catch (IOException e) {
979-
LOG.warn("Unable to create the container-log directory : "
980-
+ appLogDir, e);
979+
LOG.warn("Unable to create the container-log directory : {}",
980+
appLogDir, e);
981981
continue;
982982
}
983983
containerLogDirStatus = true;

0 commit comments

Comments
 (0)