-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(registration): Hit Keel at a known (configured) address
- Loading branch information
1 parent
6acc7a6
commit 33644f2
Showing
9 changed files
with
63 additions
and
41 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
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
7 changes: 0 additions & 7 deletions
7
keel-plugin/src/main/kotlin/com/netflix/spinnaker/keel/plugin/AssetPlugin.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 |
---|---|---|
@@ -1,15 +1,8 @@ | ||
package com.netflix.spinnaker.keel.plugin | ||
|
||
import com.netflix.spinnaker.keel.api.TypeMetadata | ||
import com.netflix.spinnaker.keel.api.engine.RegisterAssetPluginRequest | ||
import com.netflix.spinnaker.keel.api.plugin.AssetPluginGrpc.AssetPluginImplBase | ||
|
||
abstract class AssetPlugin : AssetPluginImplBase() { | ||
abstract val supportedTypes: Iterable<TypeMetadata> | ||
} | ||
|
||
val AssetPlugin.registrationRequest: RegisterAssetPluginRequest | ||
get() = RegisterAssetPluginRequest | ||
.newBuilder() | ||
.addAllTypes(supportedTypes) | ||
.build() |
54 changes: 36 additions & 18 deletions
54
keel-plugin/src/main/kotlin/com/netflix/spinnaker/keel/plugin/PluginRegistrar.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 |
---|---|---|
@@ -1,49 +1,67 @@ | ||
package com.netflix.spinnaker.keel.plugin | ||
|
||
import com.netflix.appinfo.InstanceInfo | ||
import com.netflix.appinfo.InstanceInfo.InstanceStatus.UP | ||
import com.netflix.discovery.EurekaClient | ||
import com.netflix.spinnaker.keel.api.engine.AssetPluginRegistryGrpc | ||
import com.netflix.spinnaker.keel.api.engine.AssetPluginRegistryGrpc.AssetPluginRegistryBlockingStub | ||
import com.netflix.spinnaker.keel.api.engine.RegisterAssetPluginRequest | ||
import com.netflix.spinnaker.kork.eureka.RemoteStatusChangedEvent | ||
import io.grpc.ManagedChannel | ||
import io.grpc.ManagedChannelBuilder | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.context.ApplicationListener | ||
import org.springframework.stereotype.Component | ||
import javax.annotation.PostConstruct | ||
|
||
@Component | ||
class PluginRegistrar( | ||
private val eurekaClient: EurekaClient, | ||
private val plugins: List<AssetPlugin> | ||
) { | ||
private val log = LoggerFactory.getLogger(javaClass) | ||
|
||
@PostConstruct | ||
fun registerPlugins() { | ||
registry().let { registry -> | ||
plugins.forEach { plugin -> | ||
plugin.register(registry) | ||
} | ||
private val plugins: List<AssetPlugin>, | ||
@Value("\${keel.registry.address:keel-test.us-west-2.spinnaker.netflix.net}") private val keelRegistryAddress: String, | ||
private val instanceInfo: InstanceInfo | ||
) : ApplicationListener<RemoteStatusChangedEvent> { | ||
|
||
private val log by lazy { LoggerFactory.getLogger(javaClass) } | ||
|
||
override fun onApplicationEvent(event: RemoteStatusChangedEvent) { | ||
if (event.source.status == UP) { | ||
onDiscoveryUp() | ||
} | ||
// TODO: should deregister as well | ||
} | ||
|
||
private fun AssetPlugin.register(registry: AssetPluginRegistryBlockingStub) { | ||
registry.register(registrationRequest).let { response -> | ||
fun onDiscoveryUp() { | ||
plugins.forEach { plugin -> | ||
plugin.registerWith(registry) | ||
} | ||
} | ||
|
||
private fun AssetPlugin.registerWith(registry: AssetPluginRegistryBlockingStub) { | ||
val request = RegisterAssetPluginRequest | ||
.newBuilder() | ||
.apply { | ||
vipAddress = instanceInfo.vipAddress | ||
addAllTypes(supportedTypes) | ||
} | ||
.build() | ||
registry.register(request).let { response -> | ||
if (response.succeeded) { | ||
log.info("Successfully registered {} with Keel", javaClass.simpleName) | ||
} | ||
} | ||
} | ||
|
||
private fun registry(): AssetPluginRegistryBlockingStub = | ||
eurekaClient | ||
.getNextServerFromEureka("keel", false) | ||
private val registry: AssetPluginRegistryBlockingStub by lazy { | ||
eurekaClient.getNextServerFromEureka(keelRegistryAddress, false) | ||
?.let(::createChannelTo) | ||
?.let(AssetPluginRegistryGrpc::newBlockingStub) | ||
?: throw IllegalStateException("Can't find keel in Eureka") | ||
} | ||
|
||
fun createChannelTo(instance: InstanceInfo): ManagedChannel = | ||
fun createChannelTo(it: InstanceInfo): ManagedChannel = | ||
ManagedChannelBuilder | ||
.forAddress(instance.ipAddr, instance.port) | ||
.forAddress(it.ipAddr, it.port) | ||
.usePlaintext() | ||
.build() | ||
} |
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
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
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
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
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