Added failure_strategy to Service Mode.

For cucumber and Spock test load the config from string instead of
resource files

References #64
This commit is contained in:
Mahesh V Kelkar 2015-02-24 19:21:35 -05:00
parent fc14eaf31c
commit a9654146c7
8 changed files with 67 additions and 73 deletions

View File

@ -68,7 +68,6 @@ Feature: Environment READ APIs
"""
@error
Scenario: Fetching an environment by name that doesn't exist
When I GET "/api/environments/faas"

View File

@ -6,28 +6,24 @@ Feature: Service READ APIs
Scenario: Fetching all services
Given there are services
Given a service configuration named "faas":
"""
description: "Fun as a Service"
artifacts:
- com.github.lookout:foas
- com.github.lookout.puppet:puppet-foas
- com.github.lookout:puppet-mysql
pipelines:
- devtoprod
promotions:
- status-check
- jenkins-smoke
"""
When I GET "/api/services"
Then the response should be 200
And the body should be JSON:
"""
[{
"ident" : "alas",
"description" : "Auditlog as a Service",
"artifacts" : [
"com.github.lookout:alas",
"com.github.lookout.puppet:puppet-alas",
"com.github.lookout:puppet-mysql"
],
"pipelines" : [
"detoprod"
],
"promotions" : [
"status-check",
"jenkins-smoke"
]
},
{
"ident" : "faas",
"description" : "Fun as a Service",
"artifacts" : [
@ -36,18 +32,31 @@ Feature: Service READ APIs
"com.github.lookout:puppet-mysql"
],
"pipelines" : [
"detoprod"
"devtoprod"
],
"promotions" : [
"status-check",
"jenkins-smoke"
]
],
"failure_strategy" : "Stop"
}]
"""
Scenario: Fetching an service by name that exists
Given there is an service
Given a service configuration named "faas":
"""
description: "Fun as a Service"
artifacts:
- com.github.lookout:foas
- com.github.lookout.puppet:puppet-foas
- com.github.lookout:puppet-mysql
pipelines:
- devtoprod
promotions:
- status-check
- jenkins-smoke
"""
When I GET "/api/services/faas"
Then the response should be 200
And the body should be JSON:
@ -61,15 +70,17 @@ Feature: Service READ APIs
"com.github.lookout:puppet-mysql"
],
"pipelines" : [
"detoprod"
"devtoprod"
],
"promotions" : [
"status-check",
"jenkins-smoke"
]
],
"failure_strategy" : "Stop"
}
"""
Scenario: Fetching an service by name that doesn't exist
When I GET "/api/services/faas"

View File

@ -56,7 +56,7 @@ class AppHelper {
* @param c (required) Closure to execute
*/
void withServiceRegistry(Closure c) {
c.call(this.runner.serviceRegistry)
c.call(this.runner.serviceRegistry, this.runner.serviceLoader)
}
/**

View File

@ -1,10 +1,6 @@
package deploydb.cucumber
import deploydb.models.Artifact
import deploydb.models.Promotion
import deploydb.models.Service
import deploydb.registry.ModelRegistry
class ModelHelper {
@ -19,35 +15,5 @@ class ModelHelper {
'cucumber-artifact',
'1.0.2',
'http://example.com/maven/com.example.cucumber/cucumber-artifact/1.0.2/cucumber-artifact-1.0.2.jar')
}
/**
* Creates a sample service object
*/
Service sampleService1(ModelRegistry<Service> serviceRegistry) {
Service service = new Service('faas', 'Fun as a Service',
[ 'com.github.lookout:foas',
'com.github.lookout.puppet:puppet-foas',
'com.github.lookout:puppet-mysql' ],
[ 'detoprod' ],
[ 'status-check',
'jenkins-smoke' ])
serviceRegistry.put(service.ident, service)
return service
}
/**
* Creates a sample service object
*/
Service sampleService2(ModelRegistry<Service> serviceRegistry) {
Service service = new Service('alas', 'Auditlog as a Service',
[ 'com.github.lookout:alas',
'com.github.lookout.puppet:puppet-alas',
'com.github.lookout:puppet-mysql' ],
[ 'detoprod' ],
[ 'status-check',
'jenkins-smoke' ])
serviceRegistry.put(service.ident, service)
return service
}
}

View File

@ -44,6 +44,7 @@ public class StubAppRunner<C extends Configuration> {
private Server jettyServer
private SessionFactory sessionFactory
private ModelRegistry<Service> serviceRegistry
private ModelLoader<Service> serviceLoader
private ModelRegistry<deploydb.models.Environment> environmentRegistry
private ModelLoader<deploydb.models.Environment> environmentLoader
private ModelRegistry<Promotion> promotionRegistry
@ -89,16 +90,16 @@ public class StubAppRunner<C extends Configuration> {
*/
sessionFactory = application.sessionFactory
/* Get a ModelRegistry<Service>
* out of the application once it's up and running
/**
* Get a ModelRegistry(s) from the application once it's up and running
*/
serviceRegistry = application.serviceRegistry
environmentRegistry = application.environmentRegistry
promotionRegistry = application.promotionRegistry
/* Get a ModelRegistry<Environment>, ModelLoader<Environment>
* out of the application once it's up and running
/* Get a ModelLoader(s) from the application once it's up and running
*/
environmentRegistry = application.environmentRegistry
serviceLoader = application.serviceLoader
environmentLoader = application.environmentLoader
/* We're running the DB migrations here to make sure we're running

View File

@ -4,15 +4,15 @@ this.metaClass.mixin(cucumber.api.groovy.EN)
import deploydb.models.Service
import deploydb.registry.ModelRegistry
import deploydb.ModelLoader
Given(~/^there is an service$/) { ->
withServiceRegistry { ModelRegistry<Service> serviceRegistry ->
Service a = sampleService1(serviceRegistry)
}
}
Given(~/^there are services$/) { ->
withServiceRegistry { ModelRegistry<Service> serviceRegistry ->
Service s1 = sampleService1(serviceRegistry)
Service s2 = sampleService2(serviceRegistry)
Given(~/^a service configuration named "(.*?)":$/) { String serviceIdent, String cfgBody ->
withServiceRegistry {
ModelRegistry<Service> serviceRegistry,
ModelLoader<Service> serviceLoader ->
Service a = serviceLoader.loadFromString(cfgBody)
a.ident = serviceIdent
serviceRegistry.put(serviceIdent, a)
}
}

View File

@ -28,6 +28,7 @@ class DeployDBApp extends Application<DeployDBConfiguration> {
private final Logger logger = LoggerFactory.getLogger(DeployDBApp.class)
private WebhookManager webhooks
private ModelRegistry<Service> serviceRegistry
private ModelLoader<Service> serviceLoader
private ModelRegistry<models.Environment> environmentRegistry
private ModelLoader<models.Environment> environmentLoader
private ModelRegistry<Promotion> promotionRegistry
@ -110,6 +111,7 @@ class DeployDBApp extends Application<DeployDBConfiguration> {
/**
* Instantiate in memory loaders for yaml parsing
*/
serviceLoader = new ModelLoader<Service>(Service.class)
environmentLoader = new ModelLoader<models.Environment>(models.Environment.class)
/**
@ -117,6 +119,9 @@ class DeployDBApp extends Application<DeployDBConfiguration> {
*/
environment.lifecycle().manage(webhooks)
/**
* Healthchecks
*/
environment.healthChecks().register('sanity', new SanityHealthCheck())
environment.healthChecks().register('webhook', new WebhookHealthCheck(webhooks))

View File

@ -2,6 +2,8 @@ package deploydb.models
import com.google.common.collect.Lists
import com.fasterxml.jackson.annotation.JsonProperty
import io.dropwizard.validation.OneOf
import javax.validation.constraints.Size
import org.hibernate.validator.constraints.NotEmpty
@ -48,7 +50,17 @@ class Service {
*/
@JsonProperty
@Size(max=10)
List<String> promotions
List<String> promotions = []
/**
* Failure Strategy.
*
* Defines actions to take on deployment failure for this Service:
* Stop (default), rollback (future), full_rollback (future)
*/
@OneOf(value = ["Stop"], ignoreCase = true)
@JsonProperty
String failure_strategy = "Stop"
/**
* Empty constructor used by Jackson for object deserialization