<commit_before>package mesosphere.marathon.core.task

import com.fasterxml.uuid.{ EthernetAddress, Generators }
import mesosphere.marathon.Protos.MarathonTask
import mesosphere.marathon.core.task.bus.MarathonTaskStatus
import mesosphere.marathon.core.task.tracker.impl.TaskSerializer
import mesosphere.marathon.state.{ AppDefinition, PathId, PersistentVolume, Timestamp }
import org.apache.mesos.Protos.{ NetworkInfo, TaskState }
import org.apache.mesos.Protos.TaskState._
import org.apache.mesos.{ Protos => MesosProtos }
import org.slf4j.LoggerFactory

import scala.collection.immutable.Seq

//scalastyle:off number.of.types
/**
  * The state for launching a task. This might be a launched task or a reservation for launching a task or both.
  *
  * <pre>
          +-----------------------+ +---------------------------------------+
          +EPHEMERAL              + +               RESIDENT                |
          +-----------------------+ +---------------------------------------+
                                     _  _
            | match offer      ___ (~ )( ~)                  | match
            | & launch        /   \_\ \/ /                   | offer
            |                |   D_ ]\ \/                    | & reserve
            |            +-> |   D _]/\ \   <-+              |
            |   terminal |    \___/ / /\ \    | confirmed(?) |
            |     status |         (_ )( _)   | unreserve /  |
            v     update |       DELETED      | expunge      v
                         |                    |
          +--------------+--------+ +---------+---------------+
          | LaunchedEphemeral     | | Reserved                |
          |                       | |                         |
          |  Started / Staged     | |  New / Launched         |
          |  Running              | |  Suspended / Garbage    |
          |                       | |  Unknown                | <-+
          +-----------------------+ +-------------------------+   |
                                    |                             |
                                    |   +---------------------+   |
                        match offer |   |LaunchedOnReservation|   | terminal
                        & launch    |   |                     |   | status
                                    |   | Started / Staged    |   | update
                                    |   | Running             |   |
                                    +-> |                     +---+
                                        +---------------------+

  * </pre>
  *
  * Note on wiping reserved tasks: It is not fully implemented right now so that
  * LaunchedOnReservation tasks might get immediately expunged right now.
  * Marathon will notice spurious tasks in the offer and create the appropriate
  * unreserve operations. See https://github.com/mesosphere/marathon/issues/3223
  */
sealed trait Task {
  def taskId: Task.Id
  def agentInfo: Task.AgentInfo
  def reservationWithVolumes: Option[Task.Reservation]
  def launched: Option[Task.Launched]

  /** update the task based on the given trigger - depending on its state the task will decide what should happen */
  def update(update: TaskStateOp): TaskStateChange

  def appId: PathId = taskId.appId

  /**
    * Legacy conversion to MarathonTask. Cache result to speed up repeated uses.
    * Should be removed before releasing 0.16.
    */<commit_msg>Task: Preserve ASCII-art even in the presence of<commit_after>package mesosphere.marathon.core.task

import com.fasterxml.uuid.{ EthernetAddress, Generators }
import mesosphere.marathon.Protos.MarathonTask
import mesosphere.marathon.core.task.bus.MarathonTaskStatus
import mesosphere.marathon.core.task.tracker.impl.TaskSerializer
import mesosphere.marathon.state.{ AppDefinition, PathId, PersistentVolume, Timestamp }
import org.apache.mesos.Protos.{ NetworkInfo, TaskState }
import org.apache.mesos.Protos.TaskState._
import org.apache.mesos.{ Protos => MesosProtos }
import org.slf4j.LoggerFactory

import scala.collection.immutable.Seq

//scalastyle:off number.of.types
/**
  * The state for launching a task. This might be a launched task or a reservation for launching a task or both.
  *
  * <pre>
  * +-----------------------+ +---------------------------------------+
  * +EPHEMERAL              + +               RESIDENT                |
  * +-----------------------+ +---------------------------------------+
  *                            _  _
  *   | match offer      ___ (~ )( ~)                  | match
  *   | & launch        /   \_\ \/ /                   | offer
  *   |                |   D_ ]\ \/                    | & reserve
  *   |            +-> |   D _]/\ \   <-+              |
  *   |   terminal |    \___/ / /\ \    | confirmed(?) |
  *   |     status |         (_ )( _)   | unreserve /  |
  *   v     update |       DELETED      | expunge      v
  *                |                    |
  * +--------------+--------+ +---------+---------------+
  * | LaunchedEphemeral     | | Reserved                |
  * |                       | |                         |
  * |  Started / Staged     | |  New / Launched         |
  * |  Running              | |  Suspended / Garbage    |
  * |                       | |  Unknown                | <-+
  * +-----------------------+ +-------------------------+   |
  *                           |                             |
  *                           |   +---------------------+   |
  *               match offer |   |LaunchedOnReservation|   | terminal
  *               & launch    |   |                     |   | status
  *                           |   | Started / Staged    |   | update
  *                           |   | Running             |   |
  *                           +-> |                     +---+
  *                               +---------------------+
  *
  * </pre>
  *
  * Note on wiping reserved tasks: It is not fully implemented right now so that
  * LaunchedOnReservation tasks might get immediately expunged right now.
  * Marathon will notice spurious tasks in the offer and create the appropriate
  * unreserve operations. See https://github.com/mesosphere/marathon/issues/3223
  */
sealed trait Task {
  def taskId: Task.Id
  def agentInfo: Task.AgentInfo
  def reservationWithVolumes: Option[Task.Reservation]
  def launched: Option[Task.Launched]

  /** update the task based on the given trigger - depending on its state the task will decide what should happen */
  def update(update: TaskStateOp): TaskStateChange

  def appId: PathId = taskId.appId

  /**
    * Legacy conversion to MarathonTask. Cache result to speed up repeated uses.
    * Should be removed before releasing 0.16.
    */
{'fraction_non_alphanumeric': 0.16498216409036862, 'fraction_numerical': 0.0023781212841854932, 'mean_word_length': 1.065377532228361, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4260654', 'n_tokens_mistral': 1770, 'n_tokens_neox': 1659, 'n_words': 393}