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

com.hubspot.singularity.mesos.SingularityTaskRequestHolder Maven / Gradle / Ivy

package com.hubspot.singularity.mesos;

import com.hubspot.mesos.Resources;
import com.hubspot.singularity.SingularityTaskRequest;
import java.util.ArrayList;
import java.util.List;

public class SingularityTaskRequestHolder {
  private final SingularityTaskRequest taskRequest;
  private final Resources executorResources;
  private final Resources taskResources;
  private final Resources totalResources;
  private final List requestedPorts;

  public SingularityTaskRequestHolder(
    SingularityTaskRequest taskRequest,
    Resources defaultResources,
    Resources defaultCustomExecutorResources
  ) {
    this.taskRequest = taskRequest;
    this.executorResources =
      taskRequest.getDeploy().getCustomExecutorCmd().isPresent()
        ? taskRequest
          .getDeploy()
          .getCustomExecutorResources()
          .orElse(defaultCustomExecutorResources)
        : Resources.EMPTY_RESOURCES;
    this.taskResources =
      taskRequest.getPendingTask().getResources().isPresent()
        ? taskRequest.getPendingTask().getResources().get()
        : taskRequest.getDeploy().getResources().orElse(defaultResources);
    this.totalResources = Resources.add(taskResources, executorResources);
    this.requestedPorts = new ArrayList<>();
    if (
      taskRequest.getDeploy().getContainerInfo().isPresent() &&
      taskRequest.getDeploy().getContainerInfo().get().getDocker().isPresent()
    ) {
      requestedPorts.addAll(
        taskRequest
          .getDeploy()
          .getContainerInfo()
          .get()
          .getDocker()
          .get()
          .getLiteralHostPorts()
      );
    }
  }

  public SingularityTaskRequest getTaskRequest() {
    return taskRequest;
  }

  public Resources getExecutorResources() {
    return executorResources;
  }

  public Resources getTaskResources() {
    return taskResources;
  }

  public Resources getTotalResources() {
    return totalResources;
  }

  public List getRequestedPorts() {
    return requestedPorts;
  }

  @Override
  public String toString() {
    return (
      "SingularityTaskRequestHolder [" +
      (taskRequest != null ? "taskRequest=" + taskRequest + ", " : "") +
      (executorResources != null ? "executorResources=" + executorResources + ", " : "") +
      (taskResources != null ? "taskResources=" + taskResources + ", " : "") +
      (totalResources != null ? "totalResources=" + totalResources + ", " : "") +
      (requestedPorts != null ? "requestedPorts=" + requestedPorts : "") +
      "]"
    );
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy