-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b6664d
commit 23495b9
Showing
12 changed files
with
456 additions
and
596 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 0 additions & 79 deletions
79
src/main/java/io/codeka/gaia/stacks/controller/JobRestController.java
This file was deleted.
Oops, something went wrong.
67 changes: 67 additions & 0 deletions
67
src/main/java/io/codeka/gaia/stacks/controller/JobRestController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package io.codeka.gaia.stacks.controller | ||
|
||
import io.codeka.gaia.modules.repository.TerraformModuleRepository | ||
import io.codeka.gaia.runner.StackRunner | ||
import io.codeka.gaia.stacks.bo.Job | ||
import io.codeka.gaia.stacks.repository.JobRepository | ||
import io.codeka.gaia.stacks.repository.StackRepository | ||
import io.codeka.gaia.stacks.repository.StepRepository | ||
import io.codeka.gaia.stacks.workflow.JobWorkflow | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.web.bind.annotation.* | ||
|
||
@RestController | ||
@RequestMapping("/api/jobs") | ||
class JobRestController( | ||
private val jobRepository: JobRepository, | ||
private val stackRepository: StackRepository, | ||
private val moduleRepository: TerraformModuleRepository, | ||
private val stackRunner: StackRunner, | ||
private val stepRepository: StepRepository) { | ||
|
||
@GetMapping(params = ["stackId"]) | ||
fun jobs(@RequestParam stackId: String) = jobRepository.findAllByStackId(stackId) | ||
|
||
@GetMapping("/{id}") | ||
fun job(@PathVariable id: String): Job { | ||
val runningJob = stackRunner.getJob(id); | ||
if (runningJob.isPresent) { | ||
return runningJob.get(); | ||
} | ||
return jobRepository.findById(id).orElseThrow { JobNotFoundException() } | ||
} | ||
|
||
@PostMapping("/{id}/plan") | ||
fun plan(@PathVariable id: String) { | ||
val job = jobRepository.findById(id).orElseThrow { JobNotFoundException() } | ||
val stack = stackRepository.findById(job.stackId).orElseThrow() | ||
val module = moduleRepository.findById(stack.moduleId).orElseThrow() | ||
stackRunner.plan(JobWorkflow(job), module, stack) | ||
} | ||
|
||
@PostMapping("/{id}/apply") | ||
fun apply(@PathVariable id: String) { | ||
val job = jobRepository.findById(id).orElseThrow { JobNotFoundException() } | ||
val stack = stackRepository.findById(job.stackId).orElseThrow() | ||
val module = moduleRepository.findById(stack.moduleId).orElseThrow() | ||
stackRunner.apply(JobWorkflow(job), module, stack) | ||
} | ||
|
||
@PostMapping("/{id}/retry") | ||
fun retry(@PathVariable id: String) { | ||
val job = jobRepository.findById(id).orElseThrow { JobNotFoundException() } | ||
val stack = stackRepository.findById(job.stackId).orElseThrow() | ||
val module = moduleRepository.findById(stack.moduleId).orElseThrow() | ||
stackRunner.retry(JobWorkflow(job), module, stack) | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
fun delete(@PathVariable id: String) { | ||
stepRepository.deleteByJobId(id) | ||
jobRepository.deleteById(id) | ||
} | ||
|
||
} | ||
|
||
@ResponseStatus(HttpStatus.NOT_FOUND) | ||
internal class JobNotFoundException : RuntimeException() |
80 changes: 0 additions & 80 deletions
80
src/main/java/io/codeka/gaia/stacks/controller/StackController.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.