Skip to content

Commit

Permalink
Merge pull request #256 from anotherchrisberry/trigger-by-id
Browse files Browse the repository at this point in the history
(core) allow pipeline triggering by id or name
  • Loading branch information
anotherchrisberry committed Jul 12, 2016
2 parents 5e22b13 + a061d2f commit 1287e81
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,20 @@ class PipelineController {
pipelineService.startPipeline(map, authenticatedUser)
}

@RequestMapping(value = "/{application}/{pipelineName:.+}", method = RequestMethod.POST)
@RequestMapping(value = "/{application}/{pipelineNameOrId:.+}", method = RequestMethod.POST)
HttpEntity invokePipelineConfig(@PathVariable("application") String application,
@PathVariable("pipelineName") String pipelineName,
@PathVariable("pipelineNameOrId") String pipelineNameOrId,
@RequestBody(required = false) Map trigger) {
trigger = trigger ?: [:]
trigger.user = trigger.user ?: AuthenticatedRequest.getSpinnakerUser().orElse('anonymous')

try {
def body = pipelineService.trigger(application, pipelineName, trigger)
def body = pipelineService.trigger(application, pipelineNameOrId, trigger)
new ResponseEntity(body, HttpStatus.ACCEPTED)
} catch (PipelineConfigNotFoundException e) {
throw e
} catch (e) {
log.error("Unable to trigger pipeline (application: ${application}, pipelineName: ${pipelineName})", e)
log.error("Unable to trigger pipeline (application: ${application}, pipelineName: ${pipelineNameOrId})", e)
new ResponseEntity([message: e.message], new HttpHeaders(), HttpStatus.UNPROCESSABLE_ENTITY)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ class ApplicationService {
} execute()
}

Map getPipelineConfigForApplication(String app, String pipelineName) {
Map getPipelineConfigForApplication(String app, String pipelineNameOrId) {
HystrixFactory.newMapCommand(GROUP, "getPipelineConfig") {
front50Service.getPipelineConfigsForApplication(app).find { it.name == pipelineName }
front50Service.getPipelineConfigsForApplication(app).find { it.name == pipelineNameOrId || it.id == pipelineNameOrId }
} execute()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class PipelineService {
front50Service.movePipelineConfig(moveCommand)
}

Map trigger(String application, String pipelineName, Map trigger) {
def pipelineConfig = applicationService.getPipelineConfigForApplication(application, pipelineName)
Map trigger(String application, String pipelineNameOrId, Map trigger) {
def pipelineConfig = applicationService.getPipelineConfigForApplication(application, pipelineNameOrId)
if (!pipelineConfig) {
throw new PipelineConfigNotFoundException()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,34 @@ class ApplicationServiceSpec extends Specification {
"prod" | "test" || "prod,test"
null | null || ""
}

@Unroll
void "should return pipeline config based on name or id"() {
given:
HystrixRequestContext.initializeContext()

def service = new ApplicationService()
def front50 = Mock(Front50Service)
def clouddriver = Mock(ClouddriverService)
def config = new ServiceConfiguration(services: [front50: new Service()])

service.serviceConfiguration = config
service.front50Service = front50
service.clouddriverService = clouddriver
service.executorService = Executors.newFixedThreadPool(1)
def app = "theApp"

when:
def result = service.getPipelineConfigForApplication(app, nameOrId) != null

then:
result == expected
1 * front50.getPipelineConfigsForApplication(app) >> [ [ id: "by-id", name: "by-name" ] ]

where:
nameOrId || expected
"by-id" || true
"by-name" || true
"not-id" || false
}
}

0 comments on commit 1287e81

Please sign in to comment.