Skip to content

Commit

Permalink
Merge branch 'release/2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Birchall committed Sep 5, 2014
2 parents 6818616 + d60c791 commit 4e79eda
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 180 deletions.
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
language: scala

jdk:
- oraclejdk8

scala:
- 2.11.2
- 2.10.4

addons:
postgresql: "9.3"

before_script:
- psql -c "CREATE DATABASE octoparts_test WITH ENCODING 'UTF8';" -U postgres
- psql -c "CREATE USER octoparts_app WITH PASSWORD '';" -U postgres
- psql -c "GRANT ALL PRIVILEGES ON DATABASE octoparts_test to octoparts_app;" -U postgres
13 changes: 13 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2014 M3, Inc.

Licensed 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.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Octoparts

[See documentation](http://m3dev.github.io/octoparts-site/)
[See documentation](http://m3dev.github.io/octoparts/)
20 changes: 8 additions & 12 deletions app/com/m3/octoparts/model/config/CacheGroup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ import org.joda.time.DateTime
* Defines a group of objects that need to have their cache invalidated as a group
*/
case class CacheGroup(
id: Option[Long] = None, // None means that the record is new
name: String,
owner: String,
description: String = "",
httpPartConfigs: Seq[HttpPartConfig] = Seq.empty,
partParams: Seq[PartParam] = Seq.empty,
createdAt: DateTime,
updatedAt: DateTime) extends ConfigModel[CacheGroup] {

override def mapper = CacheGroupRepository

}
id: Option[Long] = None, // None means that the record is new
name: String,
owner: String,
description: String = "",
httpPartConfigs: Seq[HttpPartConfig] = Seq.empty,
partParams: Seq[PartParam] = Seq.empty,
createdAt: DateTime,
updatedAt: DateTime) extends ConfigModel[CacheGroup]
11 changes: 0 additions & 11 deletions app/com/m3/octoparts/model/config/ConfigModel.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.m3.octoparts.model.config

import com.m3.octoparts.repository.config.ConfigMapper

/**
* The base trait for our models.
*
Expand All @@ -16,13 +14,4 @@ trait ConfigModel[A <: ConfigModel[A]] {
*/
def id: Option[Long]

/**
* Used for easy access to a mapper of an object.
*
* For our purposes, it's much easier and faster to implement this in code within
* implementing classes than to use tricks like implicits (requires more boiler
* plate) and reflection (runtime cost)
*/
def mapper: ConfigMapper[A]

}
2 changes: 0 additions & 2 deletions app/com/m3/octoparts/model/config/HttpPartConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ case class HttpPartConfig(id: Option[Long] = None, // None means that the record
createdAt: DateTime,
updatedAt: DateTime) extends ConfigModel[HttpPartConfig] {

override def mapper = HttpPartConfigRepository

/**
* Method to use when we are sure we have a HystrixConfig inside the
* hystrixConfig field.
Expand Down
2 changes: 0 additions & 2 deletions app/com/m3/octoparts/model/config/HystrixConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ case class HystrixConfig(
createdAt: DateTime,
updatedAt: DateTime) extends ConfigModel[HystrixConfig] {

override def mapper = HystrixConfigRepository

/**
* Method to use when we are sure we have a ThreadPoolConfig inside the
* threadPoolConfig field. Throws an error if it's empty
Expand Down
2 changes: 0 additions & 2 deletions app/com/m3/octoparts/model/config/PartParam.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ case class PartParam(
createdAt: DateTime,
updatedAt: DateTime) extends ConfigModel[PartParam] {

override def mapper = PartParamRepository

/**
* This is the key used to look for a value inside the PartRequest
*/
Expand Down
2 changes: 0 additions & 2 deletions app/com/m3/octoparts/model/config/ThreadPoolConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ case class ThreadPoolConfig(
createdAt: DateTime,
updatedAt: DateTime) extends ConfigModel[ThreadPoolConfig] {

override def mapper = ThreadPoolConfigRepository

// this setting is not yet available for users
def queueSize: Int = ThreadPoolConfig.defaultQueueSize

Expand Down
4 changes: 2 additions & 2 deletions app/com/m3/octoparts/repository/DBConfigsRepository.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ object DBConfigsRepository extends MutableConfigsRepository with Logging {
// A separate ExecutionContext to avoid starving the global one with blocking DB operations
implicit val dbFetchExecutionContext = Akka.system.dispatchers.lookup("contexts.db")

def save[A <: ConfigModel[A]](obj: A): Future[Long] = {
def save[A <: ConfigModel[A]: ConfigMapper](obj: A): Future[Long] = {
DB futureLocalTx { implicit session =>
saveWithSession(obj.mapper, obj)
saveWithSession(implicitly[ConfigMapper[A]], obj)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.m3.octoparts.cache.client.CacheAccessor
import com.m3.octoparts.cache.key.HttpPartConfigCacheKey
import com.m3.octoparts.http.HttpClientPool
import com.m3.octoparts.model.config.ConfigModel
import com.m3.octoparts.repository.config.ConfigMapper

import scala.concurrent.{ ExecutionContext, Future }

Expand All @@ -18,7 +19,7 @@ class MutableCachingRepository(
extends CachingRepository
with MutableConfigsRepository {

def save[A <: ConfigModel[A]](obj: A): Future[Long] = reloadCacheAfter(delegate.save(obj))
def save[A <: ConfigModel[A]: ConfigMapper](obj: A): Future[Long] = reloadCacheAfter(delegate.save(obj))

def deleteAllConfigs(): Future[Int] = reloadCacheAfter {
for {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.m3.octoparts.repository

import com.m3.octoparts.model.config.ConfigModel
import com.m3.octoparts.repository.config.ConfigMapper

import scala.concurrent.Future

Expand Down Expand Up @@ -43,6 +44,6 @@ trait MutableConfigsRepository extends ConfigsRepository {
*
* @return Long, the id of the model that was saved
*/
def save[A <: ConfigModel[A]](obj: A): Future[Long]
def save[A <: ConfigModel[A]: ConfigMapper](obj: A): Future[Long]

}
14 changes: 13 additions & 1 deletion app/com/m3/octoparts/repository/config/ConfigMapper.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.m3.octoparts.repository.config

import com.m3.octoparts.model.config.ConfigModel
import com.m3.octoparts.model.config._
import scalikejdbc.DBSession
import skinny.logging.Logging
import skinny.orm.SkinnyCRUDMapper
Expand Down Expand Up @@ -63,4 +63,16 @@ trait ConfigMapper[A <: ConfigModel[A]] extends SkinnyCRUDMapper[A] with Logging
}
}

}

/**
* This companion object exists to hold the type class instances of the [[ConfigMapper]]
* type class.
*/
object ConfigMapper {
implicit val CacheGroupMapper: ConfigMapper[CacheGroup] = CacheGroupRepository
implicit val HttpPartConfigMapper: ConfigMapper[HttpPartConfig] = HttpPartConfigRepository
implicit val HystrixConfigMapper: ConfigMapper[HystrixConfig] = HystrixConfigRepository
implicit val PartParamMapper: ConfigMapper[PartParam] = PartParamRepository
implicit val ThreadPoolConfigMapper: ConfigMapper[ThreadPoolConfig] = ThreadPoolConfigRepository
}

This file was deleted.

16 changes: 4 additions & 12 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import scalariform.formatter.preferences._

object OctopartsBuild extends Build {

val octopartsVersion = "2.0-SNAPSHOT"
val octopartsVersion = "2.0"

val httpPort = 9000
val theScalaVersion = "2.11.2"
Expand Down Expand Up @@ -187,21 +187,13 @@ object OctopartsBuild extends Build {
// -------------------------------------------------------
// Interface for authentication plugins
// -------------------------------------------------------
lazy val authPluginApi = Project(id = "auth-plugin-api", base = file("plugins/auth-plugin-api"), settings = commonSettings).settings(
lazy val authPluginApi = Project(id = "auth-plugin-api", base = file("plugins/auth-plugin-api"), settings = nonPlayAppSettings).settings(
name := "octoparts-auth-plugin-api",
libraryDependencies ++= Seq(
"com.typesafe.play" %% "play" % thePlayVersion % "provided"
)
)

// -------------------------------------------------------
// M3 OpenID implementation of the authentication plugin
// -------------------------------------------------------
lazy val m3openidPlugin = Project(id = "m3-openid-plugin", base = file("plugins/m3-openid"), settings = commonSettings).settings(
libraryDependencies ++= Seq(
ws
)
).dependsOn(authPluginApi)

// -------------------------------------------------------
// Model classes
// -------------------------------------------------------
Expand Down Expand Up @@ -260,7 +252,7 @@ object OctopartsBuild extends Build {
lazy val app = Project(id = "octoparts", base = file("."), settings = playAppSettings)
.enablePlugins(PlayScala)
.dependsOn(models, authPluginApi)
.aggregate(scalaWsClient, javaClient, models)
.aggregate(scalaWsClient, javaClient, models, authPluginApi)

// Settings for publishing to Maven Central
lazy val publishSettings = Seq(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.m3.octoparts.support.mocks

import com.m3.octoparts.repository.config.ConfigMapper
import com.m3.octoparts.repository.{ MutableConfigsRepository, ConfigsRepository }
import com.m3.octoparts.model.config._
import scala.concurrent.Future
Expand Down Expand Up @@ -39,6 +40,6 @@ trait MockMutableRepository extends MockConfigRespository with MutableConfigsRep

def deleteAllConfigs() = Future.successful(1)

def save[A <: ConfigModel[A]](obj: A): Future[Long] = Future.successful(123)
def save[A <: ConfigModel[A]: ConfigMapper](obj: A): Future[Long] = Future.successful(123)

}
Loading

0 comments on commit 4e79eda

Please sign in to comment.