YARN-2301. Improved yarn container command. Contributed by Naganarasimha G R
This commit is contained in:
parent
565b0e60a8
commit
258623ff8b
|
@ -121,6 +121,8 @@ Release 2.7.0 - UNRELEASED
|
||||||
YARN-1156. Enhance NodeManager AllocatedGB and AvailableGB metrics
|
YARN-1156. Enhance NodeManager AllocatedGB and AvailableGB metrics
|
||||||
for aggregation of decimal values. (Tsuyoshi OZAWA via junping_du)
|
for aggregation of decimal values. (Tsuyoshi OZAWA via junping_du)
|
||||||
|
|
||||||
|
YARN-2301. Improved yarn container command. (Naganarasimha G R via jianhe)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
|
|
@ -44,6 +44,7 @@ import org.apache.hadoop.yarn.api.records.YarnApplicationState;
|
||||||
import org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException;
|
import org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException;
|
||||||
import org.apache.hadoop.yarn.exceptions.YarnException;
|
import org.apache.hadoop.yarn.exceptions.YarnException;
|
||||||
import org.apache.hadoop.yarn.util.ConverterUtils;
|
import org.apache.hadoop.yarn.util.ConverterUtils;
|
||||||
|
import org.apache.hadoop.yarn.util.Times;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
|
||||||
|
@ -536,8 +537,11 @@ public class ApplicationCLI extends YarnCLI {
|
||||||
writer.printf(CONTAINER_PATTERN, "Container-Id", "Start Time",
|
writer.printf(CONTAINER_PATTERN, "Container-Id", "Start Time",
|
||||||
"Finish Time", "State", "Host", "LOG-URL");
|
"Finish Time", "State", "Host", "LOG-URL");
|
||||||
for (ContainerReport containerReport : appsReport) {
|
for (ContainerReport containerReport : appsReport) {
|
||||||
writer.printf(CONTAINER_PATTERN, containerReport.getContainerId(),
|
writer.printf(
|
||||||
containerReport.getCreationTime(), containerReport.getFinishTime(),
|
CONTAINER_PATTERN,
|
||||||
|
containerReport.getContainerId(),
|
||||||
|
Times.format(containerReport.getCreationTime()),
|
||||||
|
Times.format(containerReport.getFinishTime()),
|
||||||
containerReport.getContainerState(), containerReport
|
containerReport.getContainerState(), containerReport
|
||||||
.getAssignedNode(), containerReport.getLogUrl());
|
.getAssignedNode(), containerReport.getLogUrl());
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,19 +32,17 @@ import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.cli.Options;
|
import org.apache.commons.cli.Options;
|
||||||
import org.apache.commons.lang.time.DateFormatUtils;
|
import org.apache.commons.lang.time.DateFormatUtils;
|
||||||
import org.apache.hadoop.yarn.api.protocolrecords.GetClusterNodeLabelsResponse;
|
|
||||||
import org.apache.hadoop.yarn.api.protocolrecords.GetNodesToLabelsResponse;
|
|
||||||
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
|
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
|
||||||
import org.apache.hadoop.yarn.api.records.ApplicationAttemptReport;
|
import org.apache.hadoop.yarn.api.records.ApplicationAttemptReport;
|
||||||
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
||||||
|
@ -65,9 +63,7 @@ import org.apache.hadoop.yarn.api.records.YarnApplicationAttemptState;
|
||||||
import org.apache.hadoop.yarn.api.records.YarnApplicationState;
|
import org.apache.hadoop.yarn.api.records.YarnApplicationState;
|
||||||
import org.apache.hadoop.yarn.client.api.YarnClient;
|
import org.apache.hadoop.yarn.client.api.YarnClient;
|
||||||
import org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException;
|
import org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException;
|
||||||
import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager;
|
|
||||||
import org.apache.hadoop.yarn.util.Records;
|
import org.apache.hadoop.yarn.util.Records;
|
||||||
import org.jboss.netty.logging.CommonsLoggerFactory;
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -257,25 +253,31 @@ public class TestYarnCLI {
|
||||||
applicationId, 1);
|
applicationId, 1);
|
||||||
ContainerId containerId = ContainerId.newContainerId(attemptId, 1);
|
ContainerId containerId = ContainerId.newContainerId(attemptId, 1);
|
||||||
ContainerId containerId1 = ContainerId.newContainerId(attemptId, 2);
|
ContainerId containerId1 = ContainerId.newContainerId(attemptId, 2);
|
||||||
|
ContainerId containerId2 = ContainerId.newContainerId(attemptId, 3);
|
||||||
|
long time1=1234,time2=5678;
|
||||||
ContainerReport container = ContainerReport.newInstance(containerId, null,
|
ContainerReport container = ContainerReport.newInstance(containerId, null,
|
||||||
NodeId.newInstance("host", 1234), Priority.UNDEFINED, 1234, 5678,
|
NodeId.newInstance("host", 1234), Priority.UNDEFINED, time1, time2,
|
||||||
"diagnosticInfo", "logURL", 0, ContainerState.COMPLETE);
|
"diagnosticInfo", "logURL", 0, ContainerState.COMPLETE);
|
||||||
ContainerReport container1 = ContainerReport.newInstance(containerId1, null,
|
ContainerReport container1 = ContainerReport.newInstance(containerId1, null,
|
||||||
NodeId.newInstance("host", 1234), Priority.UNDEFINED, 1234, 5678,
|
NodeId.newInstance("host", 1234), Priority.UNDEFINED, time1, time2,
|
||||||
"diagnosticInfo", "logURL", 0, ContainerState.COMPLETE);
|
"diagnosticInfo", "logURL", 0, ContainerState.COMPLETE);
|
||||||
|
ContainerReport container2 = ContainerReport.newInstance(containerId2, null,
|
||||||
|
NodeId.newInstance("host", 1234), Priority.UNDEFINED, time1,0,
|
||||||
|
"diagnosticInfo", "", 0, ContainerState.RUNNING);
|
||||||
List<ContainerReport> reports = new ArrayList<ContainerReport>();
|
List<ContainerReport> reports = new ArrayList<ContainerReport>();
|
||||||
reports.add(container);
|
reports.add(container);
|
||||||
reports.add(container1);
|
reports.add(container1);
|
||||||
|
reports.add(container2);
|
||||||
|
DateFormat dateFormat=new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy");
|
||||||
when(client.getContainers(any(ApplicationAttemptId.class))).thenReturn(
|
when(client.getContainers(any(ApplicationAttemptId.class))).thenReturn(
|
||||||
reports);
|
reports);
|
||||||
int result = cli.run(new String[] { "container", "-list",
|
int result = cli.run(new String[] { "container", "-list",
|
||||||
attemptId.toString() });
|
attemptId.toString() });
|
||||||
assertEquals(0, result);
|
assertEquals(0, result);
|
||||||
verify(client).getContainers(attemptId);
|
verify(client).getContainers(attemptId);
|
||||||
Log.info(sysOutStream.toString());
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
PrintWriter pw = new PrintWriter(baos);
|
PrintWriter pw = new PrintWriter(baos);
|
||||||
pw.println("Total number of containers :2");
|
pw.println("Total number of containers :3");
|
||||||
pw.print(" Container-Id");
|
pw.print(" Container-Id");
|
||||||
pw.print("\t Start Time");
|
pw.print("\t Start Time");
|
||||||
pw.print("\t Finish Time");
|
pw.print("\t Finish Time");
|
||||||
|
@ -283,19 +285,30 @@ public class TestYarnCLI {
|
||||||
pw.print("\t Host");
|
pw.print("\t Host");
|
||||||
pw.println("\t LOG-URL");
|
pw.println("\t LOG-URL");
|
||||||
pw.print(" container_1234_0005_01_000001");
|
pw.print(" container_1234_0005_01_000001");
|
||||||
pw.print("\t 1234");
|
pw.print("\t"+dateFormat.format(new Date(time1)));
|
||||||
pw.print("\t 5678");
|
pw.print("\t"+dateFormat.format(new Date(time2)));
|
||||||
pw.print("\t COMPLETE");
|
pw.print("\t COMPLETE");
|
||||||
pw.print("\t host:1234");
|
pw.print("\t host:1234");
|
||||||
pw.println("\t logURL");
|
pw.println("\t logURL");
|
||||||
pw.print(" container_1234_0005_01_000002");
|
pw.print(" container_1234_0005_01_000002");
|
||||||
pw.print("\t 1234");
|
pw.print("\t"+dateFormat.format(new Date(time1)));
|
||||||
pw.print("\t 5678");
|
pw.print("\t"+dateFormat.format(new Date(time2)));
|
||||||
pw.print("\t COMPLETE");
|
pw.print("\t COMPLETE");
|
||||||
pw.print("\t host:1234");
|
pw.print("\t host:1234");
|
||||||
pw.println("\t logURL");
|
pw.println("\t logURL");
|
||||||
|
pw.print(" container_1234_0005_01_000003");
|
||||||
|
pw.print("\t"+dateFormat.format(new Date(time1)));
|
||||||
|
pw.print("\t N/A");
|
||||||
|
pw.print("\t RUNNING");
|
||||||
|
pw.print("\t host:1234");
|
||||||
|
pw.println("\t ");
|
||||||
pw.close();
|
pw.close();
|
||||||
String appReportStr = baos.toString("UTF-8");
|
String appReportStr = baos.toString("UTF-8");
|
||||||
|
Log.info("ExpectedOutput");
|
||||||
|
Log.info("["+appReportStr+"]");
|
||||||
|
Log.info("OutputFrom command");
|
||||||
|
String actualOutput = sysOutStream.toString();
|
||||||
|
Log.info("["+actualOutput+"]");
|
||||||
Assert.assertEquals(appReportStr, sysOutStream.toString());
|
Assert.assertEquals(appReportStr, sysOutStream.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.apache.hadoop.yarn.server.resourcemanager;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState;
|
import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState;
|
||||||
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
||||||
import org.apache.hadoop.yarn.api.records.NodeId;
|
import org.apache.hadoop.yarn.api.records.NodeId;
|
||||||
|
@ -121,4 +122,6 @@ public interface RMContext {
|
||||||
ReservationSystem getReservationSystem();
|
ReservationSystem getReservationSystem();
|
||||||
|
|
||||||
boolean isSchedulerReadyForAllocatingContainers();
|
boolean isSchedulerReadyForAllocatingContainers();
|
||||||
|
|
||||||
|
Configuration getYarnConfiguration();
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import java.nio.ByteBuffer;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
import org.apache.hadoop.classification.InterfaceAudience.Private;
|
import org.apache.hadoop.classification.InterfaceAudience.Private;
|
||||||
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.classification.InterfaceStability.Unstable;
|
import org.apache.hadoop.classification.InterfaceStability.Unstable;
|
||||||
import org.apache.hadoop.ha.HAServiceProtocol;
|
import org.apache.hadoop.ha.HAServiceProtocol;
|
||||||
import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState;
|
import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState;
|
||||||
|
@ -65,6 +66,8 @@ public class RMContextImpl implements RMContext {
|
||||||
|
|
||||||
private RMActiveServiceContext activeServiceContext;
|
private RMActiveServiceContext activeServiceContext;
|
||||||
|
|
||||||
|
private Configuration yarnConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor. To be used in conjunction with setter methods for
|
* Default constructor. To be used in conjunction with setter methods for
|
||||||
* individual fields.
|
* individual fields.
|
||||||
|
@ -399,4 +402,12 @@ public class RMContextImpl implements RMContext {
|
||||||
this.activeServiceContext = activeServiceContext;
|
this.activeServiceContext = activeServiceContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Configuration getYarnConfiguration() {
|
||||||
|
return this.yarnConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setYarnConfiguration(Configuration yarnConfiguration) {
|
||||||
|
this.yarnConfiguration=yarnConfiguration;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -246,6 +246,8 @@ public class ResourceManager extends CompositeService implements Recoverable {
|
||||||
addService(adminService);
|
addService(adminService);
|
||||||
rmContext.setRMAdminService(adminService);
|
rmContext.setRMAdminService(adminService);
|
||||||
|
|
||||||
|
rmContext.setYarnConfiguration(conf);
|
||||||
|
|
||||||
createAndInitActiveServices();
|
createAndInitActiveServices();
|
||||||
|
|
||||||
webAppAddress = WebAppUtils.getWebAppBindURL(this.conf,
|
webAppAddress = WebAppUtils.getWebAppBindURL(this.conf,
|
||||||
|
|
|
@ -285,8 +285,13 @@ public class RMContainerImpl implements RMContainer {
|
||||||
public String getLogURL() {
|
public String getLogURL() {
|
||||||
try {
|
try {
|
||||||
readLock.lock();
|
readLock.lock();
|
||||||
return WebAppUtils.getRunningLogURL("//" + container.getNodeHttpAddress(),
|
StringBuilder logURL = new StringBuilder();
|
||||||
ConverterUtils.toString(containerId), user);
|
logURL.append(WebAppUtils.getHttpSchemePrefix(rmContext
|
||||||
|
.getYarnConfiguration()));
|
||||||
|
logURL.append(WebAppUtils.getRunningLogURL(
|
||||||
|
container.getNodeHttpAddress(), ConverterUtils.toString(containerId),
|
||||||
|
user));
|
||||||
|
return logURL.toString();
|
||||||
} finally {
|
} finally {
|
||||||
readLock.unlock();
|
readLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
|
@ -443,6 +443,7 @@ public class TestClientRMService {
|
||||||
ConcurrentHashMap<ApplicationId, RMApp> apps = getRMApps(rmContext,
|
ConcurrentHashMap<ApplicationId, RMApp> apps = getRMApps(rmContext,
|
||||||
yarnScheduler);
|
yarnScheduler);
|
||||||
when(rmContext.getRMApps()).thenReturn(apps);
|
when(rmContext.getRMApps()).thenReturn(apps);
|
||||||
|
when(rmContext.getYarnConfiguration()).thenReturn(new Configuration());
|
||||||
RMAppManager appManager = new RMAppManager(rmContext, yarnScheduler, null,
|
RMAppManager appManager = new RMAppManager(rmContext, yarnScheduler, null,
|
||||||
mock(ApplicationACLsManager.class), new Configuration());
|
mock(ApplicationACLsManager.class), new Configuration());
|
||||||
when(rmContext.getDispatcher().getEventHandler()).thenReturn(
|
when(rmContext.getDispatcher().getEventHandler()).thenReturn(
|
||||||
|
|
|
@ -107,6 +107,7 @@ public class TestRMContainerImpl {
|
||||||
when(rmContext.getRMApplicationHistoryWriter()).thenReturn(writer);
|
when(rmContext.getRMApplicationHistoryWriter()).thenReturn(writer);
|
||||||
when(rmContext.getRMApps()).thenReturn(rmApps);
|
when(rmContext.getRMApps()).thenReturn(rmApps);
|
||||||
when(rmContext.getSystemMetricsPublisher()).thenReturn(publisher);
|
when(rmContext.getSystemMetricsPublisher()).thenReturn(publisher);
|
||||||
|
when(rmContext.getYarnConfiguration()).thenReturn(new YarnConfiguration());
|
||||||
RMContainer rmContainer = new RMContainerImpl(container, appAttemptId,
|
RMContainer rmContainer = new RMContainerImpl(container, appAttemptId,
|
||||||
nodeId, "user", rmContext);
|
nodeId, "user", rmContext);
|
||||||
|
|
||||||
|
@ -130,7 +131,7 @@ public class TestRMContainerImpl {
|
||||||
RMContainerEventType.LAUNCHED));
|
RMContainerEventType.LAUNCHED));
|
||||||
drainDispatcher.await();
|
drainDispatcher.await();
|
||||||
assertEquals(RMContainerState.RUNNING, rmContainer.getState());
|
assertEquals(RMContainerState.RUNNING, rmContainer.getState());
|
||||||
assertEquals("//host:3465/node/containerlogs/container_1_0001_01_000001/user",
|
assertEquals("http://host:3465/node/containerlogs/container_1_0001_01_000001/user",
|
||||||
rmContainer.getLogURL());
|
rmContainer.getLogURL());
|
||||||
|
|
||||||
// In RUNNING state. Verify RELEASED and associated actions.
|
// In RUNNING state. Verify RELEASED and associated actions.
|
||||||
|
@ -196,6 +197,7 @@ public class TestRMContainerImpl {
|
||||||
when(rmContext.getContainerAllocationExpirer()).thenReturn(expirer);
|
when(rmContext.getContainerAllocationExpirer()).thenReturn(expirer);
|
||||||
when(rmContext.getRMApplicationHistoryWriter()).thenReturn(writer);
|
when(rmContext.getRMApplicationHistoryWriter()).thenReturn(writer);
|
||||||
when(rmContext.getSystemMetricsPublisher()).thenReturn(publisher);
|
when(rmContext.getSystemMetricsPublisher()).thenReturn(publisher);
|
||||||
|
when(rmContext.getYarnConfiguration()).thenReturn(new YarnConfiguration());
|
||||||
RMContainer rmContainer = new RMContainerImpl(container, appAttemptId,
|
RMContainer rmContainer = new RMContainerImpl(container, appAttemptId,
|
||||||
nodeId, "user", rmContext);
|
nodeId, "user", rmContext);
|
||||||
|
|
||||||
|
@ -220,7 +222,7 @@ public class TestRMContainerImpl {
|
||||||
RMContainerEventType.LAUNCHED));
|
RMContainerEventType.LAUNCHED));
|
||||||
drainDispatcher.await();
|
drainDispatcher.await();
|
||||||
assertEquals(RMContainerState.RUNNING, rmContainer.getState());
|
assertEquals(RMContainerState.RUNNING, rmContainer.getState());
|
||||||
assertEquals("//host:3465/node/containerlogs/container_1_0001_01_000001/user",
|
assertEquals("http://host:3465/node/containerlogs/container_1_0001_01_000001/user",
|
||||||
rmContainer.getLogURL());
|
rmContainer.getLogURL());
|
||||||
|
|
||||||
// In RUNNING state. Verify EXPIRE and associated actions.
|
// In RUNNING state. Verify EXPIRE and associated actions.
|
||||||
|
|
Loading…
Reference in New Issue