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

com.hubspot.singularity.executor.shells.SingularityExecutorShellCommandUpdater Maven / Gradle / Ivy

The newest version!
package com.hubspot.singularity.executor.shells;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hubspot.singularity.SingularityTaskShellCommandRequest;
import com.hubspot.singularity.SingularityTaskShellCommandUpdate;
import com.hubspot.singularity.SingularityTaskShellCommandUpdate.UpdateType;
import com.hubspot.singularity.executor.task.SingularityExecutorTask;
import java.util.Optional;

public class SingularityExecutorShellCommandUpdater {
  private final ObjectMapper objectMapper;
  private final SingularityTaskShellCommandRequest shellRequest;
  private final SingularityExecutorTask task;

  public SingularityExecutorShellCommandUpdater(
    ObjectMapper objectMapper,
    SingularityTaskShellCommandRequest shellRequest,
    SingularityExecutorTask task
  ) {
    this.objectMapper = objectMapper;
    this.shellRequest = shellRequest;
    this.task = task;
  }

  // TODO thread?
  public void sendUpdate(
    UpdateType updateType,
    Optional message,
    Optional outputFilename
  ) {
    SingularityTaskShellCommandUpdate update = new SingularityTaskShellCommandUpdate(
      shellRequest.getId(),
      System.currentTimeMillis(),
      message,
      outputFilename,
      updateType
    );

    try {
      byte[] data = objectMapper.writeValueAsBytes(update);

      task
        .getLog()
        .info(
          "Sending update {} ({}) for shell command {}",
          updateType,
          message.orElse(""),
          shellRequest.getId()
        );

      task.getDriver().sendFrameworkMessage(data);
    } catch (JsonProcessingException e) {
      task.getLog().error("Unable to serialize update {}", update, e);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy