Skip to content

Commit

Permalink
Merge pull request #179 from tomaslin/echo-rework
Browse files Browse the repository at this point in the history
surface webhooks endpoint from echo and remove deprecated endpoint
  • Loading branch information
tomaslin committed Feb 1, 2016
2 parents 76553c0 + a03c129 commit 4666f5e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package com.netflix.spinnaker.gate.controllers
import com.netflix.spinnaker.gate.services.EventService
import groovy.transform.CompileStatic
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.HttpEntity
import org.springframework.http.HttpHeaders
import org.springframework.web.bind.annotation.*

@CompileStatic
Expand All @@ -30,19 +28,8 @@ class EventController {
@Autowired
EventService eventService

@RequestMapping(value = "/events", method = RequestMethod.GET)
HttpEntity<List<Map>> all(@RequestParam(value = "offset", required = false, defaultValue = "0") Integer offset,
@RequestParam(value = "size", required = false, defaultValue = "10") Integer size) {
def events = eventService.getAll(offset, size)
def headers = new HttpHeaders()
headers.add("X-Result-Total", Integer.valueOf(events.total as String).toString())
headers.add("X-Result-Offset", offset.toString())
headers.add("X-Result-Size", Integer.valueOf(events.paginationSize as String).toString())
new HttpEntity(events.hits, headers)
}

@RequestMapping(value = "/applications/{app}/events", method = RequestMethod.GET)
List getForApp(@PathVariable("app") String app) {
eventService.getForApplication(app)?.hits as List<Map>
@RequestMapping(value = "/webhooks/{type}/{source}", method = RequestMethod.POST)
void webhooks(@PathVariable("type") String type, @PathVariable("source") String source, @RequestBody Map event) {
eventService.webhooks(type, source, event)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.netflix.spinnaker.gate.services

import com.netflix.spinnaker.gate.services.commands.HystrixFactory
import com.netflix.spinnaker.gate.services.internal.EchoService
import groovy.transform.CompileStatic
import org.springframework.beans.factory.annotation.Autowired
Expand All @@ -30,21 +29,8 @@ class EventService {
@Autowired(required = false)
EchoService echoService

Map getAll(int offset, int size) {
if (echoService == null) {
return [:]
}
HystrixFactory.newMapCommand(GROUP, "getAllEvents") {
echoService.getAllEvents(offset, size, true)
} execute()
void webhooks(String type, String source, Map event) {
echoService.webhooks(type, source, event)
}

Map getForApplication(String app) {
if (echoService == null) {
return [:]
}
HystrixFactory.newMapCommand(GROUP, "getEventsForApplication") {
echoService.getEvents(app, 0, Integer.MAX_VALUE, true)
} execute()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,62 +16,15 @@

package com.netflix.spinnaker.gate.services.internal

import com.fasterxml.jackson.annotation.JsonProperty
import retrofit.client.Response
import retrofit.http.*

interface EchoService {

@Headers("Accept: application/json")
@GET("/search/events/0")
Map getAllEvents(@Query("from") int offset,
@Query("size") int size,
@Query("full") boolean full)

@Headers("Accept: application/json")
@GET("/search/events/0")
Map getEvents(@Query("application") String application,
@Query("from") int offset,
@Query("size") int size,
@Query("full") boolean full)

@POST("/")
Response postEvent(@Body EventBuilder.Event event)
@POST("/webhooks/{type}/{source}")
void webhooks(@Path('type') String type, @Path('source') String source, @Body Map event)

@GET("/validateCronExpression")
Map validateCronExpression(@Query("cronExpression") String cronExpression)

static class EventBuilder {

private Event event = new Event()

static EventBuilder builder() {
new EventBuilder()
}

EventBuilder withType(String type) {
event.details.type = type
this
}

EventBuilder withSource(String source) {
event.details.source = source
this
}

EventBuilder withContent(Map content) {
event.contentMap = content
this
}

Event build() {
event
}

private static class Event {
@JsonProperty("content")
Map contentMap = [:]
Map details = [:]
}
}
}

0 comments on commit 4666f5e

Please sign in to comment.