Add support for notifies deployment started webhook.
- Updated the cucumber tests - Fixes #72
This commit is contained in:
parent
1522fa6eef
commit
bf69c07291
|
@ -1,14 +1,15 @@
|
|||
Feature: Webhook invocation when deployment is started
|
||||
|
||||
@wip @feezetime @webhook
|
||||
@freezetime @webhook
|
||||
Scenario: Webhooks should be invoked when deployment is started
|
||||
Given the webhooks configuration:
|
||||
Given a webhook "started" configuration:
|
||||
"""
|
||||
deployment:
|
||||
started: "http://{{webhook_url}}"
|
||||
started:
|
||||
- http://localhost:10000/job/notify-deployment-started/build
|
||||
"""
|
||||
And there is a deployment
|
||||
When I trigger deployment PATCH "/api/deployments/1" with:
|
||||
And there is a deployment in "CREATED" state
|
||||
When I PATCH "/api/deployments/1" with:
|
||||
"""
|
||||
{
|
||||
"status" : "STARTED"
|
||||
|
@ -26,8 +27,45 @@ Feature: Webhook invocation when deployment is started
|
|||
"sourceUrl" : "http://example.com/maven/com.example.cucumber/cucumber-artifact/1.0.1/cucumber-artifact-1.0.1.jar",
|
||||
"createdAt" : "{{created_timestamp}}"
|
||||
},
|
||||
"service" : "fun as service"
|
||||
"environment" : "dev-apha",
|
||||
"status" : "STARTED",
|
||||
"service" : "faas",
|
||||
"environment" : "pre-prod",
|
||||
"createdAt" : "{{created_timestamp}}"
|
||||
}
|
||||
"""
|
||||
|
||||
@freezetime @webhook
|
||||
Scenario: Environment webhooks should be invoked when artifacts are started
|
||||
Given an environment webhook "started" configuration named "pre-prod":
|
||||
"""
|
||||
description: "DeployDB Primary Integration"
|
||||
webhooks:
|
||||
deployment:
|
||||
started:
|
||||
- http://localhost:10000/job/notify-deployment-started/build
|
||||
"""
|
||||
And there is a deployment in "CREATED" state
|
||||
When I PATCH "/api/deployments/1" with:
|
||||
"""
|
||||
{
|
||||
"status" : "STARTED"
|
||||
}
|
||||
"""
|
||||
Then the webhook should be invoked with the JSON:
|
||||
"""
|
||||
{
|
||||
"id" : 1,
|
||||
"artifact" : {
|
||||
"id" : 1,
|
||||
"group" : "com.example.cucumber",
|
||||
"name" : "cucumber-artifact",
|
||||
"version" : "1.0.1",
|
||||
"sourceUrl" : "http://example.com/maven/com.example.cucumber/cucumber-artifact/1.0.1/cucumber-artifact-1.0.1.jar",
|
||||
"createdAt" : "{{created_timestamp}}"
|
||||
},
|
||||
"status" : "STARTED",
|
||||
"service" : "faas",
|
||||
"environment" : "pre-prod",
|
||||
"createdAt" : "{{created_timestamp}}"
|
||||
}
|
||||
"""
|
|
@ -5,12 +5,16 @@ import com.fasterxml.jackson.core.JsonToken
|
|||
import com.fasterxml.jackson.databind.JsonNode
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import deploydb.ModelLoader
|
||||
import deploydb.Status
|
||||
import deploydb.dao.ArtifactDAO
|
||||
import deploydb.dao.FlowDAO
|
||||
import deploydb.models.Artifact
|
||||
import deploydb.models.Deployment
|
||||
import deploydb.models.Environment
|
||||
import deploydb.models.Flow
|
||||
import deploydb.models.PromotionResult
|
||||
import deploydb.registry.ModelRegistry
|
||||
import org.joda.time.DateTime
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
|
||||
import com.fasterxml.jackson.core.JsonParser
|
||||
|
||||
|
||||
|
||||
import deploydb.WebhookManager
|
||||
|
@ -75,6 +79,44 @@ Then(~/^the webhook should be invoked with the JSON:$/) { String expectedMessage
|
|||
}
|
||||
|
||||
|
||||
When(~/I trigger deployment PATCH "(.*?)" with:$/) { String path ->
|
||||
When(~/I trigger deployment PATCH with:$/) { String path ->
|
||||
response = postJsonToPath(path, requestBody)
|
||||
}
|
||||
|
||||
And(~/there is a deployment in "(.*?)" state$/) { String deploymentState ->
|
||||
|
||||
withSession {
|
||||
|
||||
/**
|
||||
* Create sample artifact
|
||||
*/
|
||||
ArtifactDAO adao = new ArtifactDAO(sessionFactory)
|
||||
Artifact a1 = sampleArtifact()
|
||||
adao.persist(a1)
|
||||
|
||||
/**
|
||||
* Create sample promotionResult(s)
|
||||
*/
|
||||
PromotionResult p1 = new PromotionResult("jenkins-smoke", Status.STARTED, null)
|
||||
WebhookManager webhookManager = new WebhookManager()
|
||||
/**
|
||||
* Create deployment
|
||||
*/
|
||||
Deployment d1 = new Deployment(a1,
|
||||
"pre-prod",
|
||||
"faas",
|
||||
webhookManager.getMemberOfObject(Status, deploymentState))
|
||||
d1.addPromotionResult(p1)
|
||||
|
||||
/* Create a flow */
|
||||
Flow f = new Flow(a1, "faas")
|
||||
f.addDeployment(d1)
|
||||
|
||||
/**
|
||||
* Save flow in DB, which will save the deployments & promotionResults as well
|
||||
*/
|
||||
FlowDAO fdao = new FlowDAO(sessionFactory)
|
||||
fdao.persist(f)
|
||||
}
|
||||
|
||||
}
|
|
@ -81,7 +81,8 @@ class WebhookManager implements Managed {
|
|||
/*
|
||||
* Get all the configured webhooks - global + environment
|
||||
*/
|
||||
eventUrlList = environmentWebhook.deployment ? getMemberOfObject(environmentWebhook.deployment, eventType) : []
|
||||
eventUrlList = environmentWebhook? environmentWebhook.deployment ?
|
||||
getMemberOfObject(environmentWebhook.deployment, eventType) : [] : []
|
||||
eventUrlList += webhook.deployment ? getMemberOfObject(webhook.deployment, eventType) : []
|
||||
|
||||
/*
|
||||
|
|
|
@ -217,7 +217,25 @@ public class WorkFlow {
|
|||
/* Update deployment status */
|
||||
deployment.status = Status.STARTED
|
||||
|
||||
/* FIXME - Invoke deployment started webhooks */
|
||||
/*
|
||||
* Create the webhook mapper for deployment
|
||||
*/
|
||||
DeploymentWebhookMapper deploymentWebhookMapper = new DeploymentWebhookMapper(deployment)
|
||||
|
||||
/*
|
||||
* Get the environment based webhooks for this deployment
|
||||
*/
|
||||
Webhook environmentWebhook = this.environmentRegistry.get(deployment.environmentIdent)?
|
||||
this.environmentRegistry.get(deployment.environmentIdent).webhooks : null
|
||||
|
||||
/*
|
||||
* Use webhook manager to send the webhook
|
||||
*/
|
||||
if (deployDBApp.webhooksManager.sendDeploymentWebhook("started", environmentWebhook,
|
||||
deploymentWebhookMapper) == false) {
|
||||
throw new WebApplicationException(Response.Status.BAD_REQUEST)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue