Skip to content

Commit

Permalink
fix(state): Fixing upserting a state (#364)
Browse files Browse the repository at this point in the history
- fixed upsert to return the passed state rather than throwing
  • Loading branch information
jeyrschabu authored Mar 2, 2020
1 parent 8335777 commit 90d1f33
Showing 1 changed file with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import com.netflix.spectator.api.Registry
import com.netflix.spinnaker.config.REDIS_CHUNK_SIZE
import com.netflix.spinnaker.kork.jedis.RedisClientDelegate
import com.netflix.spinnaker.kork.jedis.RedisClientSelector
import com.netflix.spinnaker.kork.web.exceptions.NotFoundException
import com.netflix.spinnaker.swabbie.model.ResourceState
import com.netflix.spinnaker.swabbie.repository.ResourceStateRepository
import org.slf4j.LoggerFactory
Expand Down Expand Up @@ -54,15 +53,15 @@ class RedisResourceStateRepository(
override fun upsert(resourceState: ResourceState): ResourceState {
val markedResource = resourceState.markedResource
val uniqueId = "${markedResource.namespace}:${markedResource.resourceId}".toLowerCase()
statesKey(uniqueId).let {
redisClientDelegate.withCommandsClient { client ->
redisClientDelegate.run {
this.withCommandsClient { client ->
client.hset(SINGLE_STATE_KEY, uniqueId, objectMapper.writeValueAsString(resourceState))
client.sadd(ALL_STATES_KEY, uniqueId)
}
}

return get(resourceState.markedResource.resourceId, resourceState.markedResource.namespace)
?: throw NotFoundException()
return get(resourceState.markedResource.resourceId, resourceState.markedResource.namespace)
?: resourceState
}
}

override fun getAll(): List<ResourceState> {
Expand Down Expand Up @@ -189,5 +188,3 @@ class RedisResourceStateRepository(

const val SINGLE_STATE_KEY = "{swabbie:resourceState}"
const val ALL_STATES_KEY = "{swabbie:resourceStates}"

fun statesKey(id: String) = "{swabbie:resourceStates}:$id"

0 comments on commit 90d1f33

Please sign in to comment.