Skip to content

Commit

Permalink
feat(front50): adding front50 support for intents (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
emjburns authored Nov 7, 2017
1 parent 16d4b7d commit 97e88d5
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ abstract class Intent<out S : IntentSpec>

val status: IntentStatus = IntentStatus.ACTIVE

@JsonIgnore
abstract fun getId(): String

@JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ package com.netflix.spinnaker.keel

interface IntentRepository {

fun upsertIntent(intent: Intent<IntentSpec>)
fun upsertIntent(intent: Intent<IntentSpec>): Intent<IntentSpec>

fun getIntents(): List<Intent<IntentSpec>>

fun getIntents(statuses: List<IntentStatus>): List<Intent<IntentSpec>>
fun getIntents(status: List<IntentStatus>): List<Intent<IntentSpec>>

fun getIntent(id: String): Intent<IntentSpec>?
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ class MemoryIntentRepository : IntentRepository {
log.info("Using ${javaClass.simpleName}")
}

override fun upsertIntent(intent: Intent<IntentSpec>) {
override fun upsertIntent(intent: Intent<IntentSpec>): Intent<IntentSpec> {
intents.put(intent.getId(), intent)
return intent
}

override fun getIntents() = intents.values.toList()

override fun getIntents(statuses: List<IntentStatus>)
= intents.values.filter { statuses.contains(it.status) }.toList()
override fun getIntents(status: List<IntentStatus>)
= intents.values.filter { status.contains(it.status) }.toList()

override fun getIntent(id: String) = intents[id]
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.netflix.spinnaker.keel.front50.Front50Service
import com.netflix.spinnaker.keel.retrofit.RetrofitConfiguration
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Import
import retrofit.Endpoint
Expand All @@ -30,6 +31,9 @@ import retrofit.client.Client
import retrofit.converter.JacksonConverter

@Configuration
@ComponentScan(
basePackages = arrayOf("com.netflix.spinnaker.keel.front50")
)
@Import(RetrofitConfiguration::class)
open class Front50Configuration {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2017 Netflix, 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.
*/

package com.netflix.spinnaker.keel.front50

import com.fasterxml.jackson.databind.ObjectMapper
import com.netflix.spinnaker.keel.Intent
import com.netflix.spinnaker.keel.IntentRepository
import com.netflix.spinnaker.keel.IntentSpec
import com.netflix.spinnaker.keel.IntentStatus
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component
import javax.annotation.PostConstruct

@Component
class Front50IntentRepository
@Autowired constructor(
private val front50Service: Front50Service,
private val objectMapper: ObjectMapper
): IntentRepository {

private val log = LoggerFactory.getLogger(javaClass)

@PostConstruct
fun init() {
log.info("Using ${javaClass.simpleName}")
}

override fun upsertIntent(intent: Intent<IntentSpec>) = front50Service.upsertIntent(intent)

override fun getIntents() = front50Service.getIntents()

override fun getIntents(status: List<IntentStatus>) = front50Service.getIntentsByStatus(status)

override fun getIntent(id: String) = front50Service.getIntent(id)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,24 @@
package com.netflix.spinnaker.keel.front50

import com.netflix.spinnaker.keel.Intent
import com.netflix.spinnaker.keel.IntentSpec
import com.netflix.spinnaker.keel.IntentStatus
import com.netflix.spinnaker.keel.front50.model.Application
import retrofit.http.*

interface Front50Service {

@GET("/intents")
fun getIntentsByStatuses(@Query("statuses") statuses: List<IntentStatus>): List<Intent<*>>
fun getIntents(): List<Intent<IntentSpec>>

@PUT("/intents")
fun upsertIntent(@Body intent: Intent<*>)
@GET("/intents")
fun getIntentsByStatus(@Query("status") status: List<IntentStatus>?): List<Intent<IntentSpec>>

@GET("/intents/{id}")
fun getIntent(@Path("id") id: String): Intent<IntentSpec>

@POST("/intents")
fun upsertIntent(@Body intent: Intent<IntentSpec>): Intent<IntentSpec>

@GET("/v2/applications/{applicationName}")
fun getApplication(@Path("applicationName") applicationName: String): Application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ScheduleConvergeHandler
log.info("Scheduling intent convergence work")

try {
intentRepository.getIntents(statuses = listOf(IntentStatus.ACTIVE))
intentRepository.getIntents(status = listOf(IntentStatus.ACTIVE))
.also { log.info("Scheduling ${it.size} active intents") }
.forEach {
queue.push(ConvergeIntent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.netflix.spinnaker.keel.test

import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonTypeName
import com.github.jonpeterson.jackson.module.versioning.JsonVersionedModel
import com.netflix.spinnaker.keel.Intent
Expand All @@ -25,6 +26,7 @@ import com.netflix.spinnaker.keel.IntentSpec
@JsonVersionedModel(currentVersion = "1", propertyName = "schema")
class TestIntent
@JsonCreator constructor(spec: TestIntentSpec) : Intent<TestIntentSpec>("1", "Test", spec) {
@JsonIgnore
override fun getId() = "test:${spec.id}"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
*/
package com.netflix.spinnaker.keel.controllers.v1

import com.netflix.spinnaker.keel.IntentActivityRepository
import com.netflix.spinnaker.keel.IntentRepository
import com.netflix.spinnaker.keel.IntentStatus
import com.netflix.spinnaker.keel.*
import com.netflix.spinnaker.keel.dryrun.DryRunIntentLauncher
import com.netflix.spinnaker.keel.model.UpsertIntentRequest
import com.netflix.spinnaker.keel.tracing.TraceRepository
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.*
import javax.ws.rs.Consumes
import javax.ws.rs.Produces
import javax.ws.rs.QueryParam

@RestController
Expand All @@ -36,7 +37,20 @@ class IntentController
private val traceRepository: TraceRepository
) {

@RequestMapping(method = arrayOf(RequestMethod.PUT))
private val log = LoggerFactory.getLogger(javaClass)

@RequestMapping(method = arrayOf(RequestMethod.GET))
fun getIntents(@QueryParam("status") status: Array<IntentStatus>? ): List<Intent<IntentSpec>> {
status?.let {
return intentRepository.getIntents(status.toList())
}
return intentRepository.getIntents()
}

@RequestMapping(value = "/{id}", method = arrayOf(RequestMethod.GET))
fun getIntent(@PathVariable("id") id: String) = intentRepository.getIntent(id)

@RequestMapping(value = "", method = arrayOf(RequestMethod.POST))
@ResponseStatus(HttpStatus.ACCEPTED)
fun upsertIntent(@RequestBody req: UpsertIntentRequest): Any {
// TODO rz - validate intents
Expand All @@ -54,13 +68,6 @@ class IntentController
return req
}

@RequestMapping(method = arrayOf(RequestMethod.GET))
fun getIntent(@QueryParam("statuses") statuses: ArrayList<IntentStatus>)
= if (statuses.isEmpty()) intentRepository.getIntents() else intentRepository.getIntents(statuses)

@RequestMapping(value = "/{id}", method = arrayOf(RequestMethod.GET))
fun getIntent(@PathVariable("id") id: String) = intentRepository.getIntent(id)

@RequestMapping(value = "/{id}", method = arrayOf(RequestMethod.DELETE))
@ResponseStatus(HttpStatus.NO_CONTENT)
fun deleteIntent(@RequestParam("status", defaultValue = "CANCELED") status: IntentStatus): Nothing = TODO()
Expand All @@ -71,3 +78,4 @@ class IntentController
@RequestMapping(value = "/{id}/traces", method = arrayOf(RequestMethod.GET))
fun getIntentTrace(@PathVariable("id") id: String) = traceRepository.getForIntent(id)
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
package com.netflix.spinnaker.keel.model

import com.netflix.spinnaker.keel.Intent
import com.netflix.spinnaker.keel.IntentSpec

data class UpsertIntentRequest(
val intents: List<Intent<*>>,
val intents: List<Intent<IntentSpec>>,
val dryRun: Boolean = false
)
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ open class WebConfiguration
response.setHeader("Access-Control-Max-Age", "3600")
response.setHeader("Access-Control-Allow-Headers", "x-requested-with, content-type")
}
chain.doFilter(request, response);
chain.doFilter(request, response)
}

override fun init(filterConfig: FilterConfig?) {}
Expand Down

0 comments on commit 97e88d5

Please sign in to comment.