Skip to content

Commit d4ce17e

Browse files
committed
Fixed issues in event timestamps creation #56
1 parent 08f840b commit d4ce17e

File tree

1 file changed

+26
-16
lines changed
  • src/main/scala/de/upb/cs/swt/delphi/instanceregistry/io/swagger/client/model

1 file changed

+26
-16
lines changed

src/main/scala/de/upb/cs/swt/delphi/instanceregistry/io/swagger/client/model/Event.scala

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,26 @@ trait EventJsonSupport extends SprayJsonSupport with DefaultJsonProtocol with In
8080
}
8181

8282
}
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+
*/
8490
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+
*/
8696
override def read(json: JsValue): DateTime = json match {
8797
case JsString(value) =>
8898
DateTime.fromIsoDateTimeString(value) match {
8999
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 + "].")
91101
}
92-
case _ => throw new DeserializationException("Failed to parse json string [" + json + "].")
102+
case _ => throw DeserializationException("Failed to parse json string [" + json + "].")
93103
}
94104
}
95105

@@ -116,7 +126,7 @@ trait EventJsonSupport extends SprayJsonSupport with DefaultJsonProtocol with In
116126
* The RegistryEvent used for communicating with the management application
117127
* @param eventType Type of the event
118128
* @param payload Payload of the event, depends on the type
119-
* @param timestamp TimeStamp of the event
129+
* @param timestamp TimeStamp of the event
120130
*/
121131
final case class RegistryEvent (
122132
eventType: EventType.Value,
@@ -133,56 +143,56 @@ object RegistryEventFactory {
133143
* Creates a new NumbersChangedEvent. Sets EventType and payload accordingly.
134144
* @param componentType ComponentType which's numbers have been updated
135145
* @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.
137147
*/
138148
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)
140150

141151
/**
142152
* Creates a new InstanceAddedEvent. Sets EventType and payload accordingly.
143153
* @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.
145155
*/
146156
def createInstanceAddedEvent(instance: Instance) : RegistryEvent =
147-
RegistryEvent(EventType.InstanceAddedEvent, InstancePayload(instance),DateTime.now)
157+
RegistryEvent(EventType.InstanceAddedEvent, InstancePayload(instance), DateTime.now)
148158

149159
/**
150160
* Creates a new InstanceRemovedEvent. Sets EventType and payload accordingly.
151161
* @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.
153163
*/
154164
def createInstanceRemovedEvent(instance: Instance) : RegistryEvent =
155-
RegistryEvent(EventType.InstanceRemovedEvent, InstancePayload(instance),DateTime.now)
165+
RegistryEvent(EventType.InstanceRemovedEvent, InstancePayload(instance), DateTime.now)
156166

157167
/**
158168
* Creates a new StateChangedEvent. Sets EventType and payload accordingly.
159169
* @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.
161171
*/
162172
def createStateChangedEvent(instance: Instance) : RegistryEvent =
163-
RegistryEvent(EventType.StateChangedEvent, InstancePayload(instance),DateTime.now)
173+
RegistryEvent(EventType.StateChangedEvent, InstancePayload(instance), DateTime.now)
164174

165175
/**
166176
* Creates a new DockerOperationErrorEvent. Sets EventType and payload accordingly.
167177
* @param affectedInstance Option[Instance] containing the instance that may be affected
168178
* @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.
170180
*/
171181
def createDockerOperationErrorEvent(affectedInstance: Option[Instance], message: String) : RegistryEvent =
172182
RegistryEvent(EventType.DockerOperationErrorEvent, DockerOperationErrorPayload(affectedInstance, message),DateTime.now)
173183

174184
/**
175185
* Creates a new LinkAddedEvent. Sets EventType and payload accordingly
176186
* @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.
178188
*/
179189
def createLinkAddedEvent(link: InstanceLink, instanceFrom: Instance, instanceTo: Instance) : RegistryEvent =
180190
RegistryEvent(EventType.LinkAddedEvent, InstanceLinkPayload(link, instanceFrom, instanceTo),DateTime.now)
181191

182192
/**
183193
* Creates a new LinkStateChangedEvent. Sets EventType and payload accordingly.
184194
* @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.
186196
*/
187197
def createLinkStateChangedEvent(link: InstanceLink, instanceFrom: Instance, instanceTo: Instance) : RegistryEvent =
188198
RegistryEvent(EventType.LinkStateChangedEvent, InstanceLinkPayload(link, instanceFrom, instanceTo),DateTime.now)

0 commit comments

Comments
 (0)