@@ -80,16 +80,26 @@ trait EventJsonSupport extends SprayJsonSupport with DefaultJsonProtocol with In
80
80
}
81
81
82
82
}
83
- implicit val timestamp : JsonFormat [DateTime ] = new JsonFormat [DateTime ] {
83
+ // Custom JSON format for event TimeStamp.
84
+ implicit val timestampFormat : JsonFormat [DateTime ] = new JsonFormat [DateTime ] {
85
+ /**
86
+ * Custom write method for serialization of DateTime
87
+ * @param @obj DateTime object to serialize
88
+ * @throws DeserializationException Exception in case of wrong input
89
+ */
84
90
override def write (obj : DateTime ) = JsString (obj.toIsoDateTimeString())
85
-
91
+ /**
92
+ * Custom read method for deserialization of DateTime
93
+ * @param @json JsValue that is to be deserialized
94
+ * @throws DeserializationException Exception when JsValue is in incorrect format
95
+ */
86
96
override def read (json : JsValue ): DateTime = json match {
87
97
case JsString (value) =>
88
98
DateTime .fromIsoDateTimeString(value) match {
89
99
case Some (date) => date
90
- case _ => throw new DeserializationException (" Failed to parse date time [" + value + " ]." )
100
+ case _ => throw DeserializationException (" Failed to parse date time [" + value + " ]." )
91
101
}
92
- case _ => throw new DeserializationException (" Failed to parse json string [" + json + " ]." )
102
+ case _ => throw DeserializationException (" Failed to parse json string [" + json + " ]." )
93
103
}
94
104
}
95
105
@@ -116,7 +126,7 @@ trait EventJsonSupport extends SprayJsonSupport with DefaultJsonProtocol with In
116
126
* The RegistryEvent used for communicating with the management application
117
127
* @param eventType Type of the event
118
128
* @param payload Payload of the event, depends on the type
119
- * @param timestamp TimeStamp of the event
129
+ * @param timestamp TimeStamp of the event
120
130
*/
121
131
final case class RegistryEvent (
122
132
eventType : EventType .Value ,
@@ -133,56 +143,56 @@ object RegistryEventFactory {
133
143
* Creates a new NumbersChangedEvent. Sets EventType and payload accordingly.
134
144
* @param componentType ComponentType which's numbers have been updated
135
145
* @param newNumber New number of components of the specified type
136
- * @return RegistryEvent with the respective type and payload .
146
+ * @return RegistryEvent with the respective respective type, payload and current timestamp .
137
147
*/
138
148
def createNumbersChangedEvent (componentType : ComponentType , newNumber : Int ) : RegistryEvent =
139
- RegistryEvent (EventType .NumbersChangedEvent , NumbersChangedPayload (componentType, newNumber),DateTime .now)
149
+ RegistryEvent (EventType .NumbersChangedEvent , NumbersChangedPayload (componentType, newNumber), DateTime .now)
140
150
141
151
/**
142
152
* Creates a new InstanceAddedEvent. Sets EventType and payload accordingly.
143
153
* @param instance Instance that has been added.
144
- * @return RegistryEvent with the respective type and payload .
154
+ * @return RegistryEvent with the respective type, payload and current timestamp .
145
155
*/
146
156
def createInstanceAddedEvent (instance : Instance ) : RegistryEvent =
147
- RegistryEvent (EventType .InstanceAddedEvent , InstancePayload (instance),DateTime .now)
157
+ RegistryEvent (EventType .InstanceAddedEvent , InstancePayload (instance), DateTime .now)
148
158
149
159
/**
150
160
* Creates a new InstanceRemovedEvent. Sets EventType and payload accordingly.
151
161
* @param instance Instance that has been removed.
152
- * @return RegistryEvent with the respective type and payload .
162
+ * @return RegistryEvent with the respective type, payload and current timestamp .
153
163
*/
154
164
def createInstanceRemovedEvent (instance : Instance ) : RegistryEvent =
155
- RegistryEvent (EventType .InstanceRemovedEvent , InstancePayload (instance),DateTime .now)
165
+ RegistryEvent (EventType .InstanceRemovedEvent , InstancePayload (instance), DateTime .now)
156
166
157
167
/**
158
168
* Creates a new StateChangedEvent. Sets EventType and payload accordingly.
159
169
* @param instance Instance which's state was changed.
160
- * @return RegistryEvent with tht respective type and payload .
170
+ * @return RegistryEvent with tht respective type, payload and current timestamp .
161
171
*/
162
172
def createStateChangedEvent (instance : Instance ) : RegistryEvent =
163
- RegistryEvent (EventType .StateChangedEvent , InstancePayload (instance),DateTime .now)
173
+ RegistryEvent (EventType .StateChangedEvent , InstancePayload (instance), DateTime .now)
164
174
165
175
/**
166
176
* Creates a new DockerOperationErrorEvent. Sets EventType and payload accordingly.
167
177
* @param affectedInstance Option[Instance] containing the instance that may be affected
168
178
* @param message Error message
169
- * @return RegistryEvent with the respective type and payload .
179
+ * @return RegistryEvent with the respective respective type, payload and current timestamp .
170
180
*/
171
181
def createDockerOperationErrorEvent (affectedInstance : Option [Instance ], message : String ) : RegistryEvent =
172
182
RegistryEvent (EventType .DockerOperationErrorEvent , DockerOperationErrorPayload (affectedInstance, message),DateTime .now)
173
183
174
184
/**
175
185
* Creates a new LinkAddedEvent. Sets EventType and payload accordingly
176
186
* @param link Link that was added
177
- * @return RegistryEvent with the respective type and payload
187
+ * @return RegistryEvent with the respective type, payload and current timestamp.
178
188
*/
179
189
def createLinkAddedEvent (link : InstanceLink , instanceFrom : Instance , instanceTo : Instance ) : RegistryEvent =
180
190
RegistryEvent (EventType .LinkAddedEvent , InstanceLinkPayload (link, instanceFrom, instanceTo),DateTime .now)
181
191
182
192
/**
183
193
* Creates a new LinkStateChangedEvent. Sets EventType and payload accordingly.
184
194
* @param link Link whichs state has been changed
185
- * @return RegistryEvent with the respective type and payload
195
+ * @return RegistryEvent with the respective type, payload and current timestamp.
186
196
*/
187
197
def createLinkStateChangedEvent (link : InstanceLink , instanceFrom : Instance , instanceTo : Instance ) : RegistryEvent =
188
198
RegistryEvent (EventType .LinkStateChangedEvent , InstanceLinkPayload (link, instanceFrom, instanceTo),DateTime .now)
0 commit comments