Skip to content

Commit

Permalink
Merge pull request #614 from indykish/1.5.2
Browse files Browse the repository at this point in the history
Upgraded scala to 2.11.11, hopefuly our last commits..
  • Loading branch information
Kishorekumar Neelamegam committed Jun 13, 2017
2 parents c2fc914 + 71a1fce commit c6dd987
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 19 deletions.
38 changes: 32 additions & 6 deletions app/models/disks/Backups.scala
Expand Up @@ -39,7 +39,7 @@ import controllers.stack.ImplicitJsonFormats
*
*/
case class BackupsInput( asm_id: String, org_id: String, account_id: String, name: String, status: String, tosca_type: String,
inputs: models.tosca.KeyValueList, outputs: models.tosca.KeyValueList)
inputs: models.tosca.KeyValueList, labels: models.tosca.KeyValueList, outputs: models.tosca.KeyValueList)

case class BackupsResult(
id: String,
Expand All @@ -52,15 +52,20 @@ case class BackupsResult(
tosca_type: String,
inputs: models.tosca.KeyValueList,
outputs: models.tosca.KeyValueList,
labels: models.tosca.KeyValueList,
json_claz: String,
created_at: DateTime)

object BackupsResult {
def apply(id: String, asm_id: String, org_id: String, account_id: String, name: String, status: String, image_id: String, tosca_type: String, inputs: models.tosca.KeyValueList, outputs: models.tosca.KeyValueList) = new BackupsResult(id, asm_id, org_id, account_id, name, status, image_id, tosca_type, inputs, outputs, "Megam::Backups", DateTime.now())
def apply(id: String, asm_id: String, org_id: String, account_id: String, name: String, status: String, image_id: String, tosca_type: String, inputs: models.tosca.KeyValueList, labels: models.tosca.KeyValueList, outputs: models.tosca.KeyValueList) = new BackupsResult(id, asm_id, org_id, account_id, name, status, image_id, tosca_type, inputs, labels, outputs, "Megam::Backups", DateTime.now())
}

sealed class BackupsSacks extends CassandraTable[BackupsSacks, BackupsResult] with ImplicitJsonFormats {

val EMAIL = "email"
val SHARED_WITH = "shared_with"
val PUBLICLY_SHARED = "public"

object id extends StringColumn(this) with PartitionKey[String]
object asm_id extends StringColumn(this) with PrimaryKey[String]
object org_id extends StringColumn(this)
Expand All @@ -79,6 +84,16 @@ sealed class BackupsSacks extends CassandraTable[BackupsSacks, BackupsResult] wi
}
}

object labels extends JsonListColumn[BackupsSacks, BackupsResult, KeyValueField](this) {
override def fromJson(obj: String): KeyValueField = {
JsonParser.parse(obj).extract[KeyValueField]
}

override def toJson(obj: KeyValueField): String = {
compactRender(Extraction.decompose(obj))
}
}

object outputs extends JsonListColumn[BackupsSacks, BackupsResult, KeyValueField](this) {
override def fromJson(obj: String): KeyValueField = {
JsonParser.parse(obj).extract[KeyValueField]
Expand All @@ -102,6 +117,7 @@ sealed class BackupsSacks extends CassandraTable[BackupsSacks, BackupsResult] wi
image_id(row),
tosca_type(row),
inputs(row),
labels(row),
outputs(row),
json_claz(row),
created_at(row))
Expand All @@ -124,6 +140,7 @@ abstract class ConcreteBackups extends BackupsSacks with RootConnector {
.value(_.image_id, sps.image_id)
.value(_.tosca_type, sps.tosca_type)
.value(_.inputs, sps.inputs)
.value(_.labels, sps.labels)
.value(_.outputs, sps.outputs)
.value(_.json_claz, sps.json_claz)
.value(_.created_at, sps.created_at)
Expand All @@ -144,12 +161,22 @@ abstract class ConcreteBackups extends BackupsSacks with RootConnector {
.modify(_.status setTo StringStuff.NilOrNot(newstatus, oldstatus))
.and(_.image_id setTo StringStuff.NilOrNot(newimage_id, oldimage_id))
.and(_.inputs setTo rip.inputs)
.and(_.labels setTo rip.labels)
.and(_.outputs setTo rip.outputs)
.future()
Await.result(res, 5.seconds).successNel
}

def listRecords(email: String): ValidationNel[Throwable, Seq[BackupsResult]] = {
def listRecords(email: String) = for {
lst <- listAllRecords
lmy <- listMyRecords(email)
} yield {
lmy ++
lst.filter{ x => (KeyValueList.filter(x.inputs, SHARED_WITH).filter(_.value.contains(PUBLICLY_SHARED))).length > 0 } ++
lst.filter{ y => (KeyValueList.filter(y.labels, EMAIL).filter(_.value.contains(email))).length > 0 }
}

def listMyRecords(email: String): ValidationNel[Throwable, Seq[BackupsResult]] = {
val res = select.allowFiltering().where(_.account_id eqs email).fetch()
Await.result(res, 5.seconds).successNel
}
Expand Down Expand Up @@ -193,7 +220,7 @@ private def mkBackupsSack(email: String, input: String): ValidationNel[Throwable
uir <- (UID("BAK").get leftMap { ut: NonEmptyList[Throwable] => ut })
} yield {
val uname = uir.get._2.toString.substring(0, 5)
val json = new BackupsResult(uir.get._1 + uir.get._2, back.asm_id, back.org_id, email, back.name + uname, back.status, "", back.tosca_type, back.inputs, back.outputs, "Megam::Backups", DateHelper.now())
val json = new BackupsResult(uir.get._1 + uir.get._2, back.asm_id, back.org_id, email, back.name + uname, back.status, "", back.tosca_type, back.inputs, back.labels, back.outputs, "Megam::Backups", DateHelper.now())
json
}
}
Expand Down Expand Up @@ -289,7 +316,6 @@ def update(email: String, input: String): ValidationNel[Throwable, BackupsResult

}

//Admin authority can list all snapshots for 1.5.
def list: ValidationNel[Throwable, Seq[BackupsResult]] = {
listAllRecords match {
case Success(value) => Validation.success[Throwable, Seq[BackupsResult]](value).toValidationNel
Expand Down Expand Up @@ -318,7 +344,7 @@ def update(email: String, input: String): ValidationNel[Throwable, BackupsResult
if (!output.isEmpty)
output.head
else
BackupsResult("","","","","","","", "", models.tosca.KeyValueList.empty, models.tosca.KeyValueList.empty).successNel
BackupsResult("","","","","","","", "", models.tosca.KeyValueList.empty,models.tosca.KeyValueList.empty, models.tosca.KeyValueList.empty).successNel
}


Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Expand Up @@ -6,7 +6,7 @@ name := "verticegateway"

version := "1.5.6"

scalaVersion := "2.11.8"
scalaVersion := "2.11.11"

ivyScala := ivyScala.value map { _.copy(overrideScalaVersion = true) }

Expand Down
2 changes: 2 additions & 0 deletions db/1.5.2.cql
Expand Up @@ -8,3 +8,5 @@ GRANT ALL PERMISSIONS ON KEYSPACE vertice TO vertadmin;
use vertice;

CREATE TABLE IF NOT EXISTS flavors (id text, name text, cpu text, ram text, disk text, category list<text>, regions list<text>, price list<text>, properties list<text>, status text, json_claz text, created_at timestamp, updated_at timestamp, PRIMARY KEY(name, id));

ALTER TABLE backups ADD labels list<text>;
11 changes: 0 additions & 11 deletions db/2.0.cql

This file was deleted.

2 changes: 1 addition & 1 deletion project/plugins.sbt
Expand Up @@ -9,7 +9,7 @@ resolvers += "sonatype-releases" at "https://oss.sonatype.org/content/repositori

addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.7.0")

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.10")
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.11")

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.3")

Expand Down

0 comments on commit c6dd987

Please sign in to comment.