events.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. // Package events holds event structures, methods and functions.
  2. package events
  3. import (
  4. "fmt"
  5. )
  6. // Notifier defines the methods an event notifier should have.
  7. type Notifier interface {
  8. Notify(eventType EventType, serviceName string, data map[string]string)
  9. }
  10. // Emitter defines the methods an event emitter should have.
  11. type Emitter interface {
  12. AddListener(c chan<- Event)
  13. }
  14. // Event holds project-wide event informations.
  15. type Event struct {
  16. EventType EventType
  17. ServiceName string
  18. Data map[string]string
  19. }
  20. // EventType defines a type of libcompose event.
  21. type EventType int
  22. // Definitions of libcompose events
  23. const (
  24. NoEvent = EventType(iota)
  25. ContainerCreated = EventType(iota)
  26. ContainerStarted = EventType(iota)
  27. ServiceAdd = EventType(iota)
  28. ServiceUpStart = EventType(iota)
  29. ServiceUpIgnored = EventType(iota)
  30. ServiceUp = EventType(iota)
  31. ServiceCreateStart = EventType(iota)
  32. ServiceCreate = EventType(iota)
  33. ServiceDeleteStart = EventType(iota)
  34. ServiceDelete = EventType(iota)
  35. ServiceDownStart = EventType(iota)
  36. ServiceDown = EventType(iota)
  37. ServiceRestartStart = EventType(iota)
  38. ServiceRestart = EventType(iota)
  39. ServicePullStart = EventType(iota)
  40. ServicePull = EventType(iota)
  41. ServiceKillStart = EventType(iota)
  42. ServiceKill = EventType(iota)
  43. ServiceStartStart = EventType(iota)
  44. ServiceStart = EventType(iota)
  45. ServiceBuildStart = EventType(iota)
  46. ServiceBuild = EventType(iota)
  47. ServicePauseStart = EventType(iota)
  48. ServicePause = EventType(iota)
  49. ServiceUnpauseStart = EventType(iota)
  50. ServiceUnpause = EventType(iota)
  51. ServiceStopStart = EventType(iota)
  52. ServiceStop = EventType(iota)
  53. ServiceRunStart = EventType(iota)
  54. ServiceRun = EventType(iota)
  55. VolumeAdd = EventType(iota)
  56. NetworkAdd = EventType(iota)
  57. ProjectDownStart = EventType(iota)
  58. ProjectDownDone = EventType(iota)
  59. ProjectCreateStart = EventType(iota)
  60. ProjectCreateDone = EventType(iota)
  61. ProjectUpStart = EventType(iota)
  62. ProjectUpDone = EventType(iota)
  63. ProjectDeleteStart = EventType(iota)
  64. ProjectDeleteDone = EventType(iota)
  65. ProjectRestartStart = EventType(iota)
  66. ProjectRestartDone = EventType(iota)
  67. ProjectReload = EventType(iota)
  68. ProjectReloadTrigger = EventType(iota)
  69. ProjectKillStart = EventType(iota)
  70. ProjectKillDone = EventType(iota)
  71. ProjectStartStart = EventType(iota)
  72. ProjectStartDone = EventType(iota)
  73. ProjectBuildStart = EventType(iota)
  74. ProjectBuildDone = EventType(iota)
  75. ProjectPauseStart = EventType(iota)
  76. ProjectPauseDone = EventType(iota)
  77. ProjectUnpauseStart = EventType(iota)
  78. ProjectUnpauseDone = EventType(iota)
  79. ProjectStopStart = EventType(iota)
  80. ProjectStopDone = EventType(iota)
  81. )
  82. func (e EventType) String() string {
  83. var m string
  84. switch e {
  85. case ContainerCreated:
  86. m = "Created container"
  87. case ContainerStarted:
  88. m = "Started container"
  89. case ServiceAdd:
  90. m = "Adding"
  91. case ServiceUpStart:
  92. m = "Starting"
  93. case ServiceUpIgnored:
  94. m = "Ignoring"
  95. case ServiceUp:
  96. m = "Started"
  97. case ServiceCreateStart:
  98. m = "Creating"
  99. case ServiceCreate:
  100. m = "Created"
  101. case ServiceDeleteStart:
  102. m = "Deleting"
  103. case ServiceDelete:
  104. m = "Deleted"
  105. case ServiceStopStart:
  106. m = "Stopping"
  107. case ServiceStop:
  108. m = "Stopped"
  109. case ServiceDownStart:
  110. m = "Stopping"
  111. case ServiceDown:
  112. m = "Stopped"
  113. case ServiceRestartStart:
  114. m = "Restarting"
  115. case ServiceRestart:
  116. m = "Restarted"
  117. case ServicePullStart:
  118. m = "Pulling"
  119. case ServicePull:
  120. m = "Pulled"
  121. case ServiceKillStart:
  122. m = "Killing"
  123. case ServiceKill:
  124. m = "Killed"
  125. case ServiceStartStart:
  126. m = "Starting"
  127. case ServiceStart:
  128. m = "Started"
  129. case ServiceBuildStart:
  130. m = "Building"
  131. case ServiceBuild:
  132. m = "Built"
  133. case ServiceRunStart:
  134. m = "Executing"
  135. case ServiceRun:
  136. m = "Executed"
  137. case ProjectDownStart:
  138. m = "Stopping project"
  139. case ProjectDownDone:
  140. m = "Project stopped"
  141. case ProjectStopStart:
  142. m = "Stopping project"
  143. case ProjectStopDone:
  144. m = "Project stopped"
  145. case ProjectCreateStart:
  146. m = "Creating project"
  147. case ProjectCreateDone:
  148. m = "Project created"
  149. case ProjectUpStart:
  150. m = "Starting project"
  151. case ProjectUpDone:
  152. m = "Project started"
  153. case ProjectDeleteStart:
  154. m = "Deleting project"
  155. case ProjectDeleteDone:
  156. m = "Project deleted"
  157. case ProjectRestartStart:
  158. m = "Restarting project"
  159. case ProjectRestartDone:
  160. m = "Project restarted"
  161. case ProjectReload:
  162. m = "Reloading project"
  163. case ProjectReloadTrigger:
  164. m = "Triggering project reload"
  165. case ProjectKillStart:
  166. m = "Killing project"
  167. case ProjectKillDone:
  168. m = "Project killed"
  169. case ProjectStartStart:
  170. m = "Starting project"
  171. case ProjectStartDone:
  172. m = "Project started"
  173. case ProjectBuildStart:
  174. m = "Building project"
  175. case ProjectBuildDone:
  176. m = "Project built"
  177. }
  178. if m == "" {
  179. m = fmt.Sprintf("EventType: %d", int(e))
  180. }
  181. return m
  182. }