Skip to content

Commit

Permalink
CSAS-17 add cmdInfo field in VirtualMachineDestroyEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
tomskikh committed Sep 4, 2018
1 parent 56badbb commit b9daf04
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class VmEventsRetrievingTest
it should "retrieve VirtualMachineCreateEvent with status 'Completed' from Kafka records" in {
val afterCreation = OffsetDateTime.now()
val actualVmCreateEvents = records.map(RecordToEventDeserializer.deserializeRecord).filter {
case VirtualMachineCreateEvent(Some(Constants.Statuses.COMPLETED), Some(`vmId`), Some(dateTime), _, Some(serviceOfferingId), Some(_)) =>
case VirtualMachineCreateEvent(Some(Constants.Statuses.COMPLETED), Some(`vmId`), Some(dateTime), _, Some(_), Some(_)) =>
dateTime.isAfter(beforeCreation) && dateTime.isBefore(afterCreation)
case _ => false
}
Expand All @@ -73,7 +73,7 @@ class VmEventsRetrievingTest
it should "retrieve VirtualMachineDestroyEvent with status 'Completed' from Kafka records" in {
val afterDeletion = OffsetDateTime.now()
val actualVmDestroyEvents = records.map(RecordToEventDeserializer.deserializeRecord).filter {
case VirtualMachineDestroyEvent(Some(Constants.Statuses.COMPLETED), Some(`vmId`), Some(dateTime), _) =>
case VirtualMachineDestroyEvent(Some(Constants.Statuses.COMPLETED), Some(`vmId`), Some(dateTime), _, _) =>
dateTime.isAfter(beforeDeletion) && dateTime.isBefore(afterDeletion)
case _ => false
}
Expand Down
38 changes: 38 additions & 0 deletions src/main/scala/com/bwsw/cloudstack/entities/common/CmdInfo.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.bwsw.cloudstack.entities.common

import spray.json.DefaultJsonProtocol._
import spray.json._

final case class CmdInfo(value: Map[String, String])


object CmdInfo {

implicit val cmdInfoJsonFormat: RootJsonFormat[CmdInfo] = new RootJsonFormat[CmdInfo] {
override def read(json: JsValue): CmdInfo = json match {
case JsString(string) => CmdInfo(string.parseJson.convertTo[Map[String, String]])
case _ => deserializationError(s"Expected CmdInfo as JsString, but got $json")
}

override def write(cmdInfo: CmdInfo): JsValue =
cmdInfo.value.toJson.toString().toJson
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package com.bwsw.cloudstack.entities.events.vm
import java.time.OffsetDateTime
import java.util.UUID

import com.bwsw.cloudstack.entities.common.CmdInfo
import com.bwsw.cloudstack.entities.common.CommonJsonFormats._
import com.bwsw.cloudstack.entities.events.{CloudStackEvent, EventDateTime}
import spray.json.DefaultJsonProtocol._
Expand All @@ -29,12 +30,13 @@ import spray.json.RootJsonFormat
final case class VirtualMachineDestroyEvent(status: Option[String],
entityuuid: Option[UUID],
eventDateTime: Option[OffsetDateTime],
description: Option[String])
description: Option[String],
cmdInfo: Option[CmdInfo])
extends CloudStackEvent with EventDateTime


object VirtualMachineDestroyEvent {

implicit val virtualMachineDestroyEventJsonFormat: RootJsonFormat[VirtualMachineDestroyEvent] =
jsonFormat4(VirtualMachineDestroyEvent.apply)
jsonFormat5(VirtualMachineDestroyEvent.apply)
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,16 @@ class DefaultJsonFormatsTests
| "account": "c1ebdda3-c69b-11e7-bdcf-0242ac110004",
| "entity": "com.cloud.vm.VirtualMachine",
| "status": "Scheduled",
| "cmdInfo": "{\"response\":\"json\",\"expunge\":\"true\"}",
| "VirtualMachine": "3a9c10f9-0474-4173-bdbd-3f2c29a75bff"
|}""".stripMargin

val expectedEvent = VirtualMachineDestroyEvent(
status = Some(Statuses.SCHEDULED),
entityuuid = Some(UUID.fromString("3a9c10f9-0474-4173-bdbd-3f2c29a75bff")),
eventDateTime = Some(OffsetDateTime.of(2017, 11, 12, 19, 44, 29, 0, ZoneOffset.ofHours(7))), //scalastyle:ignore
description = Some("destroying vm: 14")
description = Some("destroying vm: 14"),
cmdInfo = Some(CmdInfo(Map("response" -> "json", "expunge" -> "true")))
)

jsonString.parseJson.convertTo[CloudStackEvent] shouldBe expectedEvent
Expand Down

0 comments on commit b9daf04

Please sign in to comment.