backend.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Package backend includes types to send information to server backends.
  2. package backend
  3. import (
  4. "io"
  5. "time"
  6. "github.com/docker/docker/api/types"
  7. "github.com/docker/docker/pkg/streamformatter"
  8. )
  9. // ContainerAttachConfig holds the streams to use when connecting to a container to view logs.
  10. type ContainerAttachConfig struct {
  11. GetStreams func() (io.ReadCloser, io.Writer, io.Writer, error)
  12. UseStdin bool
  13. UseStdout bool
  14. UseStderr bool
  15. Logs bool
  16. Stream bool
  17. DetachKeys string
  18. // Used to signify that streams are multiplexed and therefore need a StdWriter to encode stdout/stderr messages accordingly.
  19. // TODO @cpuguy83: This shouldn't be needed. It was only added so that http and websocket endpoints can use the same function, and the websocket function was not using a stdwriter prior to this change...
  20. // HOWEVER, the websocket endpoint is using a single stream and SHOULD be encoded with stdout/stderr as is done for HTTP since it is still just a single stream.
  21. // Since such a change is an API change unrelated to the current changeset we'll keep it as is here and change separately.
  22. MuxStreams bool
  23. }
  24. // LogMessage is datastructure that represents piece of output produced by some
  25. // container. The Line member is a slice of an array whose contents can be
  26. // changed after a log driver's Log() method returns.
  27. // changes to this struct need to be reflect in the reset method in
  28. // daemon/logger/logger.go
  29. type LogMessage struct {
  30. Line []byte
  31. Source string
  32. Timestamp time.Time
  33. Attrs LogAttributes
  34. Partial bool
  35. // Err is an error associated with a message. Completeness of a message
  36. // with Err is not expected, tho it may be partially complete (fields may
  37. // be missing, gibberish, or nil)
  38. Err error
  39. }
  40. // LogAttributes is used to hold the extra attributes available in the log message
  41. // Primarily used for converting the map type to string and sorting.
  42. type LogAttributes map[string]string
  43. // LogSelector is a list of services and tasks that should be returned as part
  44. // of a log stream. It is similar to swarmapi.LogSelector, with the difference
  45. // that the names don't have to be resolved to IDs; this is mostly to avoid
  46. // accidents later where a swarmapi LogSelector might have been incorrectly
  47. // used verbatim (and to avoid the handler having to import swarmapi types)
  48. type LogSelector struct {
  49. Services []string
  50. Tasks []string
  51. }
  52. // ContainerStatsConfig holds information for configuring the runtime
  53. // behavior of a backend.ContainerStats() call.
  54. type ContainerStatsConfig struct {
  55. Stream bool
  56. OutStream io.Writer
  57. Version string
  58. }
  59. // ExecInspect holds information about a running process started
  60. // with docker exec.
  61. type ExecInspect struct {
  62. ID string
  63. Running bool
  64. ExitCode *int
  65. ProcessConfig *ExecProcessConfig
  66. OpenStdin bool
  67. OpenStderr bool
  68. OpenStdout bool
  69. CanRemove bool
  70. ContainerID string
  71. DetachKeys []byte
  72. Pid int
  73. }
  74. // ExecProcessConfig holds information about the exec process
  75. // running on the host.
  76. type ExecProcessConfig struct {
  77. Tty bool `json:"tty"`
  78. Entrypoint string `json:"entrypoint"`
  79. Arguments []string `json:"arguments"`
  80. Privileged *bool `json:"privileged,omitempty"`
  81. User string `json:"user,omitempty"`
  82. }
  83. // ContainerCommitConfig is a wrapper around
  84. // types.ContainerCommitConfig that also
  85. // transports configuration changes for a container.
  86. type ContainerCommitConfig struct {
  87. types.ContainerCommitConfig
  88. Changes []string
  89. }
  90. // ProgressWriter is a data object to transport progress streams to the client
  91. type ProgressWriter struct {
  92. Output io.Writer
  93. StdoutFormatter *streamformatter.StdoutFormatter
  94. StderrFormatter *streamformatter.StderrFormatter
  95. ProgressReaderFunc func(io.ReadCloser) io.ReadCloser
  96. }