public class TaskUtils
extends java.lang.Object
TaskInfo
s.Modifier and Type | Method and Description |
---|---|
static boolean |
areDifferent(TaskSpec oldTaskSpec,
TaskSpec newTaskSpec)
Determines whether two TaskSpecs are different.
|
static java.util.Collection<TaskInfo> |
clearReservations(java.util.Collection<TaskInfo> taskInfos)
Returns TaskInfos will all reservations and persistence IDs removed from their Resources.
|
static GoalState |
getGoalState(PodInstance podInstance,
java.lang.String taskName)
Gets the
GoalState of Task. |
static PodInstance |
getPodInstance(ConfigStore<ServiceSpec> configStore,
TaskInfo taskInfo) |
static PodInstance |
getPodInstance(PodSpec podSpec,
TaskInfo taskInfo) |
static java.util.List<PodInstanceRequirement> |
getPodRequirements(ConfigStore<ServiceSpec> configStore,
java.util.Collection<TaskInfo> failedTasks,
java.util.Collection<TaskInfo> allLaunchedTasks)
Given a list of all tasks and failed tasks, returns a list of tasks (via returned
PodInstanceRequirement.getTasksToLaunch() ) that should be relaunched. |
static java.util.Optional<PodSpec> |
getPodSpec(ServiceSpec serviceSpec,
TaskInfo taskInfo)
Returns the
TaskSpec in the provided DefaultServiceSpec
which matches the provided TaskInfo , or null if no match could be found. |
static java.util.List<TaskInfo> |
getPodTasks(PodInstance podInstance,
StateStore stateStore)
Returns the TaskInfos associated with a PodInstance if its ever been launched.
|
static java.lang.String |
getStepName(PodInstance podInstance,
java.util.Collection<java.lang.String> tasksToLaunch)
Returns a default name for a
Step given a PodInstance and the tasks to be launched in it. |
static java.lang.String |
getTaskIPAddress(TaskStatus taskStatus)
Gets the IP address associated with the task.
|
static java.util.List<java.lang.String> |
getTaskNames(PodInstance podInstance)
Returns all the Task names for a PodInstance.
|
static java.util.List<java.lang.String> |
getTaskNames(PodInstance podInstance,
java.util.Collection<java.lang.String> tasksToLaunch)
Returns all the task names for a pod, after filtering based on the passed in list of tasks to launch.
|
static java.util.Optional<TaskSpec> |
getTaskSpec(ConfigStore<ServiceSpec> configStore,
Protos.TaskInfo taskInfo) |
static java.util.Optional<TaskSpec> |
getTaskSpec(PodInstance podInstance,
java.lang.String taskName) |
static java.util.Optional<TaskSpec> |
getTaskSpec(ServiceSpec serviceSpec,
java.lang.String podType,
java.lang.String taskName) |
static java.lang.String |
getTaskZone(TaskInfo taskInfo)
Gets the zone of a task.
|
static boolean |
hasTasksWithTLS(ServiceSpec serviceSpec)
Returns whether any tasks within the provided
ServiceSpec have transport encryption specs defined. |
static boolean |
isRecoveryNeeded(TaskStatus taskStatus)
Returns whether the provided
TaskStatus shows that the task needs to recover. |
static boolean |
isSamePodInstance(TaskInfo taskInfo,
PodInstance podInstance)
Returns whether the provided
TaskInfo (representing a launched task) and PodInstance (from the
ServiceSpec ) are both effectively for the same pod instance. |
static boolean |
isSamePodInstance(TaskInfo taskInfo,
java.lang.String type,
int index)
Returns whether the provided
TaskInfo is in the provided pod type and index. |
static boolean |
isTerminal(TaskState taskState)
Returns whether the provided
TaskState has reached a terminal state. |
static boolean |
isTerminal(TaskStatus taskStatus)
Returns whether the provided
TaskStatus has reached a terminal state. |
static boolean |
needsRecovery(TaskSpec taskSpec,
TaskStatus taskStatus)
Determines whether a Task needs to be recovered based on its current definition (TaskSpec) and status
(TaskStatus).
|
static boolean |
taskHasZone(TaskInfo taskInfo)
Determines if a task is launched in any zones.
|
static boolean |
volumesEqual(TaskSpec first,
TaskSpec second)
Utility method for checking if volumes changed between the two provided
TaskSpec s. |
public static java.util.Optional<PodSpec> getPodSpec(ServiceSpec serviceSpec, TaskInfo taskInfo) throws TaskException
TaskSpec
in the provided DefaultServiceSpec
which matches the provided TaskInfo
, or null
if no match could be found.TaskException
public static java.util.List<java.lang.String> getTaskNames(PodInstance podInstance)
podInstance
- A PodInstancepublic static java.util.List<java.lang.String> getTaskNames(PodInstance podInstance, java.util.Collection<java.lang.String> tasksToLaunch)
podInstance
- A PodInstancetasksToLaunch
- The names of TaskSpecs which should be launched.public static boolean hasTasksWithTLS(ServiceSpec serviceSpec)
ServiceSpec
have transport encryption specs defined.public static java.util.List<TaskInfo> getPodTasks(PodInstance podInstance, StateStore stateStore)
podInstance
- A PodInstancestateStore
- A StateStore to search for the appropriate TaskInfos.public static boolean isSamePodInstance(TaskInfo taskInfo, PodInstance podInstance) throws TaskException
TaskInfo
(representing a launched task) and PodInstance
(from the
ServiceSpec
) are both effectively for the same pod instance.TaskException
public static boolean isSamePodInstance(TaskInfo taskInfo, java.lang.String type, int index) throws TaskException
TaskInfo
is in the provided pod type and index.TaskException
public static boolean areDifferent(TaskSpec oldTaskSpec, TaskSpec newTaskSpec)
oldTaskSpec
- The previous definition of a Task.newTaskSpec
- The new definition of a Task.public static boolean volumesEqual(TaskSpec first, TaskSpec second)
TaskSpec
s.public static GoalState getGoalState(PodInstance podInstance, java.lang.String taskName) throws TaskException
GoalState
of Task.podInstance
- A PodInstance containing tasks.taskName
- The name of the Task whose goal state is desiredGoalState
of the task.TaskException
- is thrown when unable to determine a task's GoalState
public static java.util.Optional<TaskSpec> getTaskSpec(ConfigStore<ServiceSpec> configStore, Protos.TaskInfo taskInfo) throws TaskException
TaskException
public static java.util.Optional<TaskSpec> getTaskSpec(PodInstance podInstance, java.lang.String taskName)
public static java.util.Optional<TaskSpec> getTaskSpec(ServiceSpec serviceSpec, java.lang.String podType, java.lang.String taskName)
public static java.util.List<PodInstanceRequirement> getPodRequirements(ConfigStore<ServiceSpec> configStore, java.util.Collection<TaskInfo> failedTasks, java.util.Collection<TaskInfo> allLaunchedTasks)
PodInstanceRequirement.getTasksToLaunch()
) that should be relaunched.failedTasks
- tasks marked as needing recoveryallLaunchedTasks
- all launched tasks in the servicepublic static PodInstance getPodInstance(ConfigStore<ServiceSpec> configStore, TaskInfo taskInfo) throws TaskException
TaskException
public static PodInstance getPodInstance(PodSpec podSpec, TaskInfo taskInfo) throws TaskException
TaskException
public static boolean isRecoveryNeeded(TaskStatus taskStatus)
TaskStatus
shows that the task needs to recover.public static boolean isTerminal(TaskStatus taskStatus)
TaskStatus
has reached a terminal state.public static boolean isTerminal(TaskState taskState)
TaskState
has reached a terminal state.public static boolean needsRecovery(TaskSpec taskSpec, TaskStatus taskStatus)
taskSpec
- The definition of a tasktaskStatus
- The status of the task.public static java.lang.String getStepName(PodInstance podInstance, java.util.Collection<java.lang.String> tasksToLaunch)
Step
given a PodInstance and the tasks to be launched in it.public static java.util.Collection<TaskInfo> clearReservations(java.util.Collection<TaskInfo> taskInfos)
public static boolean taskHasZone(TaskInfo taskInfo)
taskInfo
- The TaskInfo
to get zone information from.public static java.lang.String getTaskZone(TaskInfo taskInfo)
taskInfo
- The TaskInfo
to get zone information from.public static java.lang.String getTaskIPAddress(TaskStatus taskStatus) throws java.lang.IllegalStateException
taskStatus
- the TaskStatus
to get the IP address from.java.lang.IllegalStateException