All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hubspot.singularity.executor.utils.ExecutorUtils Maven / Gradle / Ivy

There is a newer version: 1.5.0
Show newest version
package com.hubspot.singularity.executor.utils;

import org.apache.mesos.ExecutorDriver;
import org.apache.mesos.Protos;
import org.slf4j.Logger;

import com.google.inject.Inject;
import com.hubspot.singularity.executor.config.SingularityExecutorConfiguration;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

public class ExecutorUtils {

  private final SingularityExecutorConfiguration configuration;

  @Inject
  public ExecutorUtils(SingularityExecutorConfiguration configuration) {
    this.configuration = configuration;
  }

  @SuppressFBWarnings("DM_EXIT")
  public void sendStatusUpdate(ExecutorDriver driver, Protos.TaskID taskID, Protos.TaskState taskState, String message, Logger logger) {
    logger.info("Sending status update \"{}\" ({})", message, taskState.name());

    message = message.substring(0, Math.min(configuration.getMaxTaskMessageLength(), message.length()));

    try {
      final Protos.TaskStatus.Builder builder = Protos.TaskStatus.newBuilder()
          .setTaskId(taskID)
          .setState(taskState)
          .setMessage(message);

      driver.sendStatusUpdate(builder.build());
    } catch (Throwable t) {
      try {
        logger.error("Exception while sending status updates, exiting", t);
      } finally {
        System.exit(4);
      }
    }
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy