org.apache.hadoop.yarn.server.nodemanager.Context Java Examples

The following examples show how to use org.apache.hadoop.yarn.server.nodemanager.Context. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContainerLaunch.java    From big-c with Apache License 2.0 6 votes vote down vote up
public ContainerLaunch(Context context, Configuration configuration,
    Dispatcher dispatcher, ContainerExecutor exec, Application app,
    Container container, LocalDirsHandlerService dirsHandler,
    ContainerManagerImpl containerManager) {
  this.context = context;
  this.conf = configuration;
  this.app = app;
  this.exec = exec;
  this.container = container;
  this.dispatcher = dispatcher;
  this.dirsHandler = dirsHandler;
  this.containerManager = containerManager;
  this.sleepDelayBeforeSigKill =
      conf.getLong(YarnConfiguration.NM_SLEEP_DELAY_BEFORE_SIGKILL_MS,
          YarnConfiguration.DEFAULT_NM_SLEEP_DELAY_BEFORE_SIGKILL_MS);
  this.maxKillWaitTime =
      conf.getLong(YarnConfiguration.NM_PROCESS_KILL_WAIT_MS,
          YarnConfiguration.DEFAULT_NM_PROCESS_KILL_WAIT_MS);
}
 
Example #2
Source File: ContainerLogsUtils.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Finds the local directories that logs for the given container are stored
 * on.
 */
public static List<File> getContainerLogDirs(ContainerId containerId,
    String remoteUser, Context context) throws YarnException {
  Container container = context.getContainers().get(containerId);

  Application application = getApplicationForContainer(containerId, context);
  checkAccess(remoteUser, application, context);
  // It is not required to have null check for container ( container == null )
  // and throw back exception.Because when container is completed, NodeManager
  // remove container information from its NMContext.Configuring log
  // aggregation to false, container log view request is forwarded to NM. NM
  // does not have completed container information,but still NM serve request for
  // reading container logs. 
  if (container != null) {
    checkState(container.getContainerState());
  }
  
  return getContainerLogDirs(containerId, context.getLocalDirsHandler());
}
 
Example #3
Source File: TestContainerManagerRecovery.java    From big-c with Apache License 2.0 6 votes vote down vote up
private StartContainersResponse startContainer(Context context,
    final ContainerManagerImpl cm, ContainerId cid,
    ContainerLaunchContext clc, LogAggregationContext logAggregationContext)
        throws Exception {
  UserGroupInformation user = UserGroupInformation.createRemoteUser(
      cid.getApplicationAttemptId().toString());
  StartContainerRequest scReq = StartContainerRequest.newInstance(
      clc, TestContainerManager.createContainerToken(cid, 0,
          context.getNodeId(), user.getShortUserName(),
          context.getContainerTokenSecretManager(), logAggregationContext));
  final List<StartContainerRequest> scReqList =
      new ArrayList<StartContainerRequest>();
  scReqList.add(scReq);
  NMTokenIdentifier nmToken = new NMTokenIdentifier(
      cid.getApplicationAttemptId(), context.getNodeId(),
      user.getShortUserName(),
      context.getNMTokenSecretManager().getCurrentKey().getKeyId());
  user.addTokenIdentifier(nmToken);
  return user.doAs(new PrivilegedExceptionAction<StartContainersResponse>() {
    @Override
    public StartContainersResponse run() throws Exception {
      return cm.startContainers(
          StartContainersRequest.newInstance(scReqList));
    }
  });
}
 
Example #4
Source File: ContainerLogsUtils.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private static void checkAccess(String remoteUser, Application application,
    Context context) throws YarnException {
  UserGroupInformation callerUGI = null;
  if (remoteUser != null) {
    callerUGI = UserGroupInformation.createRemoteUser(remoteUser);
  }
  if (callerUGI != null
      && !context.getApplicationACLsManager().checkAccess(callerUGI,
          ApplicationAccessType.VIEW_APP, application.getUser(),
          application.getAppId())) {
    throw new YarnException(
        "User [" + remoteUser
            + "] is not authorized to view the logs for application "
            + application.getAppId());
  }
}
 
Example #5
Source File: ContainerLogsUtils.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Finds the log file with the given filename for the given container.
 */
public static File getContainerLogFile(ContainerId containerId,
    String fileName, String remoteUser, Context context) throws YarnException {
  Container container = context.getContainers().get(containerId);
  
  Application application = getApplicationForContainer(containerId, context);
  checkAccess(remoteUser, application, context);
  if (container != null) {
    checkState(container.getContainerState());
  }
  
  try {
    LocalDirsHandlerService dirsHandler = context.getLocalDirsHandler();
    String relativeContainerLogDir = ContainerLaunch.getRelativeContainerLogDir(
        application.getAppId().toString(), containerId.toString());
    Path logPath = dirsHandler.getLogPathToRead(
        relativeContainerLogDir + Path.SEPARATOR + fileName);
    URI logPathURI = new File(logPath.toString()).toURI();
    File logFile = new File(logPathURI.getPath());
    return logFile;
  } catch (IOException e) {
    LOG.warn("Failed to find log file", e);
    throw new NotFoundException("Cannot find this log on the local disk.");
  }
}
 
Example #6
Source File: ContainerLogsUtils.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public static FileInputStream openLogFileForRead(String containerIdStr, File logFile,
    Context context) throws IOException {
  ContainerId containerId = ConverterUtils.toContainerId(containerIdStr);
  ApplicationId applicationId = containerId.getApplicationAttemptId()
      .getApplicationId();
  String user = context.getApplications().get(
      applicationId).getUser();
  
  try {
    return SecureIOUtils.openForRead(logFile, user, null);
  } catch (IOException e) {
    if (e.getMessage().contains(
      "did not match expected owner '" + user
          + "'")) {
      LOG.error(
          "Exception reading log file " + logFile.getAbsolutePath(), e);
      throw new IOException("Exception reading log file. Application submitted by '"
          + user
          + "' doesn't own requested log file : "
          + logFile.getName(), e);
    } else {
      throw new IOException("Exception reading log file. It might be because log "
          + "file was aggregated : " + logFile.getName(), e);
    }
  }
}
 
Example #7
Source File: WebServer.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
protected void serviceStart() throws Exception {
  String bindAddress = WebAppUtils.getWebAppBindURL(getConfig(),
                        YarnConfiguration.NM_BIND_HOST,
                        WebAppUtils.getNMWebAppURLWithoutScheme(getConfig()));
  
  LOG.info("Instantiating NMWebApp at " + bindAddress);
  try {
    this.webApp =
        WebApps
          .$for("node", Context.class, this.nmContext, "ws")
          .at(bindAddress)
          .with(getConfig())
          .withHttpSpnegoPrincipalKey(
            YarnConfiguration.NM_WEBAPP_SPNEGO_USER_NAME_KEY)
          .withHttpSpnegoKeytabKey(
            YarnConfiguration.NM_WEBAPP_SPNEGO_KEYTAB_FILE_KEY)
          .start(this.nmWebApp);
    this.port = this.webApp.httpServer().getConnectorAddress(0).getPort();
  } catch (Exception e) {
    String msg = "NMWebapps failed to start.";
    LOG.error(msg, e);
    throw new YarnRuntimeException(msg, e);
  }
  super.serviceStart();
}
 
Example #8
Source File: ResourceLocalizationService.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public ResourceLocalizationService(Dispatcher dispatcher,
    ContainerExecutor exec, DeletionService delService,
    LocalDirsHandlerService dirsHandler, Context context) {

  super(ResourceLocalizationService.class.getName());
  this.exec = exec;
  this.dispatcher = dispatcher;
  this.delService = delService;
  this.dirsHandler = dirsHandler;

  this.cacheCleanup = new ScheduledThreadPoolExecutor(1,
      new ThreadFactoryBuilder()
        .setNameFormat("ResourceLocalizationService Cache Cleanup")
        .build());
  this.stateStore = context.getNMStateStore();
  this.nmContext = context;
}
 
Example #9
Source File: ContainerLaunch.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public ContainerLaunch(Context context, Configuration configuration,
    Dispatcher dispatcher, ContainerExecutor exec, Application app,
    Container container, LocalDirsHandlerService dirsHandler,
    ContainerManagerImpl containerManager) {
  this.context = context;
  this.conf = configuration;
  this.app = app;
  this.exec = exec;
  this.container = container;
  this.dispatcher = dispatcher;
  this.dirsHandler = dirsHandler;
  this.containerManager = containerManager;
  this.sleepDelayBeforeSigKill =
      conf.getLong(YarnConfiguration.NM_SLEEP_DELAY_BEFORE_SIGKILL_MS,
          YarnConfiguration.DEFAULT_NM_SLEEP_DELAY_BEFORE_SIGKILL_MS);
  this.maxKillWaitTime =
      conf.getLong(YarnConfiguration.NM_PROCESS_KILL_WAIT_MS,
          YarnConfiguration.DEFAULT_NM_PROCESS_KILL_WAIT_MS);

  this.olr = new OwnLocalResources();
}
 
Example #10
Source File: MiniYARNClusterSplice.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected NodeStatusUpdater createNodeStatusUpdater(Context context,
                                                    Dispatcher dispatcher, NodeHealthCheckerService healthChecker) {
    return new NodeStatusUpdaterImpl(context, dispatcher,
                                     healthChecker, metrics) {
        @Override
        protected ResourceTracker getRMClient() {
            final ResourceTrackerService rt =
                getResourceManager().getResourceTrackerService();
            final RecordFactory recordFactory =
                RecordFactoryProvider.getRecordFactory(null);

            // For in-process communication without RPC
            return Utils.getResourceTracker(rt);
        }

        @Override
        protected void stopRMProxy() { }
     };
}
 
Example #11
Source File: NodeInfo.java    From big-c with Apache License 2.0 6 votes vote down vote up
public NodeInfo(final Context context, final ResourceView resourceView) {

    this.id = context.getNodeId().toString();
    this.nodeHostName = context.getNodeId().getHost();
    this.totalVmemAllocatedContainersMB = resourceView
        .getVmemAllocatedForContainers() / BYTES_IN_MB;
    this.vmemCheckEnabled = resourceView.isVmemCheckEnabled();
    this.totalPmemAllocatedContainersMB = resourceView
        .getPmemAllocatedForContainers() / BYTES_IN_MB;
    this.pmemCheckEnabled = resourceView.isPmemCheckEnabled();
    this.totalVCoresAllocatedContainers = resourceView
        .getVCoresAllocatedForContainers();
    this.nodeHealthy = context.getNodeHealthStatus().getIsNodeHealthy();
    this.lastNodeUpdateTime = context.getNodeHealthStatus()
        .getLastHealthReportTime();

    this.healthReport = context.getNodeHealthStatus().getHealthReport();

    this.nodeManagerVersion = YarnVersionInfo.getVersion();
    this.nodeManagerBuildVersion = YarnVersionInfo.getBuildVersion();
    this.nodeManagerVersionBuiltOn = YarnVersionInfo.getDate();
    this.hadoopVersion = VersionInfo.getVersion();
    this.hadoopBuildVersion = VersionInfo.getBuildVersion();
    this.hadoopVersionBuiltOn = VersionInfo.getDate();
  }
 
Example #12
Source File: TestContainerManagerSecurity.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private void waitForContainerToFinishOnNM(ContainerId containerId) {
  Context nmContet = yarnCluster.getNodeManager(0).getNMContext();
  int interval = 4 * 60; // Max time for container token to expire.
  Assert.assertNotNull(nmContet.getContainers().containsKey(containerId));
  while ((interval-- > 0)
      && !nmContet.getContainers().get(containerId)
        .cloneAndGetContainerStatus().getState()
        .equals(ContainerState.COMPLETE)) {
    try {
      LOG.info("Waiting for " + containerId + " to complete.");
      Thread.sleep(1000);
    } catch (InterruptedException e) {
    }
  }
  // Normally, Containers will be removed from NM context after they are
  // explicitly acked by RM. Now, manually remove it for testing.
  yarnCluster.getNodeManager(0).getNodeStatusUpdater()
    .addCompletedContainer(containerId);
  nmContet.getContainers().remove(containerId);
}
 
Example #13
Source File: ResourceLocalizationService.java    From big-c with Apache License 2.0 6 votes vote down vote up
public ResourceLocalizationService(Dispatcher dispatcher,
    ContainerExecutor exec, DeletionService delService,
    LocalDirsHandlerService dirsHandler, Context context) {

  super(ResourceLocalizationService.class.getName());
  this.exec = exec;
  this.dispatcher = dispatcher;
  this.delService = delService;
  this.dirsHandler = dirsHandler;

  this.cacheCleanup = new ScheduledThreadPoolExecutor(1,
      new ThreadFactoryBuilder()
        .setNameFormat("ResourceLocalizationService Cache Cleanup")
        .build());
  this.stateStore = context.getNMStateStore();
  this.nmContext = context;
}
 
Example #14
Source File: WebServer.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
protected void serviceStart() throws Exception {
  String bindAddress = WebAppUtils.getWebAppBindURL(getConfig(),
                        YarnConfiguration.NM_BIND_HOST,
                        WebAppUtils.getNMWebAppURLWithoutScheme(getConfig()));
  
  LOG.info("Instantiating NMWebApp at " + bindAddress);
  try {
    this.webApp =
        WebApps
          .$for("node", Context.class, this.nmContext, "ws")
          .at(bindAddress)
          .with(getConfig())
          .withHttpSpnegoPrincipalKey(
            YarnConfiguration.NM_WEBAPP_SPNEGO_USER_NAME_KEY)
          .withHttpSpnegoKeytabKey(
            YarnConfiguration.NM_WEBAPP_SPNEGO_KEYTAB_FILE_KEY)
          .start(this.nmWebApp);
    this.port = this.webApp.httpServer().getConnectorAddress(0).getPort();
  } catch (Exception e) {
    String msg = "NMWebapps failed to start.";
    LOG.error(msg, e);
    throw new YarnRuntimeException(msg, e);
  }
  super.serviceStart();
}
 
Example #15
Source File: ContainerLogsUtils.java    From big-c with Apache License 2.0 6 votes vote down vote up
public static FileInputStream openLogFileForRead(String containerIdStr, File logFile,
    Context context) throws IOException {
  ContainerId containerId = ConverterUtils.toContainerId(containerIdStr);
  ApplicationId applicationId = containerId.getApplicationAttemptId()
      .getApplicationId();
  String user = context.getApplications().get(
      applicationId).getUser();
  
  try {
    return SecureIOUtils.openForRead(logFile, user, null);
  } catch (IOException e) {
    if (e.getMessage().contains(
      "did not match expected owner '" + user
          + "'")) {
      LOG.error(
          "Exception reading log file " + logFile.getAbsolutePath(), e);
      throw new IOException("Exception reading log file. Application submitted by '"
          + user
          + "' doesn't own requested log file : "
          + logFile.getName(), e);
    } else {
      throw new IOException("Exception reading log file. It might be because log "
          + "file was aggregated : " + logFile.getName(), e);
    }
  }
}
 
Example #16
Source File: ContainerLogsUtils.java    From big-c with Apache License 2.0 6 votes vote down vote up
private static void checkAccess(String remoteUser, Application application,
    Context context) throws YarnException {
  UserGroupInformation callerUGI = null;
  if (remoteUser != null) {
    callerUGI = UserGroupInformation.createRemoteUser(remoteUser);
  }
  if (callerUGI != null
      && !context.getApplicationACLsManager().checkAccess(callerUGI,
          ApplicationAccessType.VIEW_APP, application.getUser(),
          application.getAppId())) {
    throw new YarnException(
        "User [" + remoteUser
            + "] is not authorized to view the logs for application "
            + application.getAppId());
  }
}
 
Example #17
Source File: ContainerLogsUtils.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Finds the log file with the given filename for the given container.
 */
public static File getContainerLogFile(ContainerId containerId,
    String fileName, String remoteUser, Context context) throws YarnException {
  Container container = context.getContainers().get(containerId);
  
  Application application = getApplicationForContainer(containerId, context);
  checkAccess(remoteUser, application, context);
  if (container != null) {
    checkState(container.getContainerState());
  }
  
  try {
    LocalDirsHandlerService dirsHandler = context.getLocalDirsHandler();
    String relativeContainerLogDir = ContainerLaunch.getRelativeContainerLogDir(
        application.getAppId().toString(), containerId.toString());
    Path logPath = dirsHandler.getLogPathToRead(
        relativeContainerLogDir + Path.SEPARATOR + fileName);
    URI logPathURI = new File(logPath.toString()).toURI();
    File logFile = new File(logPathURI.getPath());
    return logFile;
  } catch (IOException e) {
    LOG.warn("Failed to find log file", e);
    throw new NotFoundException("Cannot find this log on the local disk.");
  }
}
 
Example #18
Source File: ContainerLogsUtils.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Finds the local directories that logs for the given container are stored
 * on.
 */
public static List<File> getContainerLogDirs(ContainerId containerId,
    String remoteUser, Context context) throws YarnException {
  Container container = context.getContainers().get(containerId);

  Application application = getApplicationForContainer(containerId, context);
  checkAccess(remoteUser, application, context);
  // It is not required to have null check for container ( container == null )
  // and throw back exception.Because when container is completed, NodeManager
  // remove container information from its NMContext.Configuring log
  // aggregation to false, container log view request is forwarded to NM. NM
  // does not have completed container information,but still NM serve request for
  // reading container logs. 
  if (container != null) {
    checkState(container.getContainerState());
  }
  
  return getContainerLogDirs(containerId, context.getLocalDirsHandler());
}
 
Example #19
Source File: TestContainerManagerSecurity.java    From big-c with Apache License 2.0 6 votes vote down vote up
private void waitForContainerToFinishOnNM(ContainerId containerId) {
  Context nmContet = yarnCluster.getNodeManager(0).getNMContext();
  int interval = 4 * 60; // Max time for container token to expire.
  Assert.assertNotNull(nmContet.getContainers().containsKey(containerId));
  while ((interval-- > 0)
      && !nmContet.getContainers().get(containerId)
        .cloneAndGetContainerStatus().getState()
        .equals(ContainerState.COMPLETE)) {
    try {
      LOG.info("Waiting for " + containerId + " to complete.");
      Thread.sleep(1000);
    } catch (InterruptedException e) {
    }
  }
  // Normally, Containers will be removed from NM context after they are
  // explicitly acked by RM. Now, manually remove it for testing.
  yarnCluster.getNodeManager(0).getNodeStatusUpdater()
    .addCompletedContainer(containerId);
  nmContet.getContainers().remove(containerId);
}
 
Example #20
Source File: NMController.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Inject
public NMController(Configuration nmConf, RequestContext requestContext,
    Context nmContext) {
  super(requestContext);
  this.nmContext = nmContext;
  this.nmConf = nmConf;
}
 
Example #21
Source File: ContainerManagerImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
protected LogHandler createLogHandler(Configuration conf, Context context,
    DeletionService deletionService) {
  if (conf.getBoolean(YarnConfiguration.LOG_AGGREGATION_ENABLED,
      YarnConfiguration.DEFAULT_LOG_AGGREGATION_ENABLED)) {
    return new LogAggregationService(this.dispatcher, context,
        deletionService, dirsHandler);
  } else {
    return new NonAggregatingLogHandler(this.dispatcher, deletionService,
                                        dirsHandler,
                                        context.getNMStateStore());
  }
}
 
Example #22
Source File: TestNMWebServer.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private void writeContainerLogs(Context nmContext,
    ContainerId containerId, LocalDirsHandlerService dirsHandler)
      throws IOException, YarnException {
  // ContainerLogDir should be created
  File containerLogDir =
      ContainerLogsUtils.getContainerLogDirs(containerId,
          dirsHandler).get(0);
  containerLogDir.mkdirs();
  for (String fileType : new String[] { "stdout", "stderr", "syslog" }) {
    Writer writer = new FileWriter(new File(containerLogDir, fileType));
    writer.write(ConverterUtils.toString(containerId) + "\n Hello "
        + fileType + "!");
    writer.close();
  }
}
 
Example #23
Source File: ContainersMonitorImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public ContainersMonitorImpl(ContainerExecutor exec,
    AsyncDispatcher dispatcher, Context context) {
  super("containers-monitor");

  this.containerExecutor = exec;
  this.eventDispatcher = dispatcher;
  this.context = context;

  this.containersToBeAdded = new HashMap<ContainerId, ProcessTreeInfo>();
  this.containersToBeRemoved = new ArrayList<ContainerId>();
  this.monitoringThread = new MonitoringThread();
}
 
Example #24
Source File: TestContainersMonitor.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 20000)
public void testContainerMonitorMemFlags() {
  ContainersMonitor cm = null;

  long expPmem = 8192 * 1024 * 1024l;
  long expVmem = (long) (expPmem * 2.1f);

  cm = new ContainersMonitorImpl(mock(ContainerExecutor.class),
      mock(AsyncDispatcher.class), mock(Context.class));
  cm.init(getConfForCM(false, false, 8192, 2.1f));
  assertEquals(expPmem, cm.getPmemAllocatedForContainers());
  assertEquals(expVmem, cm.getVmemAllocatedForContainers());
  assertEquals(false, cm.isPmemCheckEnabled());
  assertEquals(false, cm.isVmemCheckEnabled());

  cm = new ContainersMonitorImpl(mock(ContainerExecutor.class),
      mock(AsyncDispatcher.class), mock(Context.class));
  cm.init(getConfForCM(true, false, 8192, 2.1f));
  assertEquals(expPmem, cm.getPmemAllocatedForContainers());
  assertEquals(expVmem, cm.getVmemAllocatedForContainers());
  assertEquals(true, cm.isPmemCheckEnabled());
  assertEquals(false, cm.isVmemCheckEnabled());

  cm = new ContainersMonitorImpl(mock(ContainerExecutor.class),
      mock(AsyncDispatcher.class), mock(Context.class));
  cm.init(getConfForCM(true, true, 8192, 2.1f));
  assertEquals(expPmem, cm.getPmemAllocatedForContainers());
  assertEquals(expVmem, cm.getVmemAllocatedForContainers());
  assertEquals(true, cm.isPmemCheckEnabled());
  assertEquals(true, cm.isVmemCheckEnabled());

  cm = new ContainersMonitorImpl(mock(ContainerExecutor.class),
      mock(AsyncDispatcher.class), mock(Context.class));
  cm.init(getConfForCM(false, true, 8192, 2.1f));
  assertEquals(expPmem, cm.getPmemAllocatedForContainers());
  assertEquals(expVmem, cm.getVmemAllocatedForContainers());
  assertEquals(false, cm.isPmemCheckEnabled());
  assertEquals(true, cm.isVmemCheckEnabled());
}
 
Example #25
Source File: TestContainersMonitor.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 20000)
public void testContainerMonitorMemFlags() {
  ContainersMonitor cm = null;

  long expPmem = 8192 * 1024 * 1024l;
  long expVmem = (long) (expPmem * 2.1f);

  cm = new ContainersMonitorImpl(mock(ContainerExecutor.class),
      mock(AsyncDispatcher.class), mock(Context.class));
  cm.init(getConfForCM(false, false, 8192, 2.1f));
  assertEquals(expPmem, cm.getPmemAllocatedForContainers());
  assertEquals(expVmem, cm.getVmemAllocatedForContainers());
  assertEquals(false, cm.isPmemCheckEnabled());
  assertEquals(false, cm.isVmemCheckEnabled());

  cm = new ContainersMonitorImpl(mock(ContainerExecutor.class),
      mock(AsyncDispatcher.class), mock(Context.class));
  cm.init(getConfForCM(true, false, 8192, 2.1f));
  assertEquals(expPmem, cm.getPmemAllocatedForContainers());
  assertEquals(expVmem, cm.getVmemAllocatedForContainers());
  assertEquals(true, cm.isPmemCheckEnabled());
  assertEquals(false, cm.isVmemCheckEnabled());

  cm = new ContainersMonitorImpl(mock(ContainerExecutor.class),
      mock(AsyncDispatcher.class), mock(Context.class));
  cm.init(getConfForCM(true, true, 8192, 2.1f));
  assertEquals(expPmem, cm.getPmemAllocatedForContainers());
  assertEquals(expVmem, cm.getVmemAllocatedForContainers());
  assertEquals(true, cm.isPmemCheckEnabled());
  assertEquals(true, cm.isVmemCheckEnabled());

  cm = new ContainersMonitorImpl(mock(ContainerExecutor.class),
      mock(AsyncDispatcher.class), mock(Context.class));
  cm.init(getConfForCM(false, true, 8192, 2.1f));
  assertEquals(expPmem, cm.getPmemAllocatedForContainers());
  assertEquals(expVmem, cm.getVmemAllocatedForContainers());
  assertEquals(false, cm.isPmemCheckEnabled());
  assertEquals(true, cm.isVmemCheckEnabled());
}
 
Example #26
Source File: ContainerInfo.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public ContainerInfo(final Context nmContext, final Container container,
     String requestUri, String pathPrefix) {

  this.id = container.getContainerId().toString();
  this.nodeId = nmContext.getNodeId().toString();
  ContainerStatus containerData = container.cloneAndGetContainerStatus();
  this.exitCode = containerData.getExitStatus();
  this.exitStatus =
      (this.exitCode == ContainerExitStatus.INVALID) ?
          "N/A" : String.valueOf(exitCode);
  this.state = container.getContainerState().toString();
  this.diagnostics = containerData.getDiagnostics();
  if (this.diagnostics == null || this.diagnostics.isEmpty()) {
    this.diagnostics = "";
  }

  this.user = container.getUser();
  Resource res = container.getResource();
  if (res != null) {
    this.totalMemoryNeededMB = res.getMemory();
    this.totalVCoresNeeded = res.getVirtualCores();
  }
  this.containerLogsShortLink = ujoin("containerlogs", this.id,
      container.getUser());

  if (requestUri == null) {
    requestUri = "";
  }
  if (pathPrefix == null) {
    pathPrefix = "";
  }
  this.containerLogsLink = join(requestUri, pathPrefix,
      this.containerLogsShortLink);
}
 
Example #27
Source File: WebServer.java    From big-c with Apache License 2.0 5 votes vote down vote up
public WebServer(Context nmContext, ResourceView resourceView,
    ApplicationACLsManager aclsManager,
    LocalDirsHandlerService dirsHandler) {
  super(WebServer.class.getName());
  this.nmContext = nmContext;
  this.nmWebApp = new NMWebApp(resourceView, aclsManager, dirsHandler);
}
 
Example #28
Source File: NMWebServices.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Inject
public NMWebServices(final Context nm, final ResourceView view,
    final WebApp webapp) {
  this.nmContext = nm;
  this.rview = view;
  this.webapp = webapp;
}
 
Example #29
Source File: ContainerLogsUtils.java    From big-c with Apache License 2.0 5 votes vote down vote up
private static Application getApplicationForContainer(ContainerId containerId,
    Context context) {
  ApplicationId applicationId = containerId.getApplicationAttemptId()
      .getApplicationId();
  Application application = context.getApplications().get(
      applicationId);
  
  if (application == null) {
    throw new NotFoundException(
        "Unknown container. Container either has not started or "
            + "has already completed or "
            + "doesn't belong to this node at all.");
  }
  return application;
}
 
Example #30
Source File: ApplicationImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
public ApplicationImpl(Dispatcher dispatcher, String user, ApplicationId appId,
    Credentials credentials, Context context) {
  this.dispatcher = dispatcher;
  this.user = user;
  this.appId = appId;
  this.credentials = credentials;
  this.aclsManager = context.getApplicationACLsManager();
  this.context = context;
  ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
  readLock = lock.readLock();
  writeLock = lock.writeLock();
  stateMachine = stateMachineFactory.make(this);
}