-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add SPI for invoker #4453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add SPI for invoker #4453
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -22,23 +22,22 @@ import akka.actor.{ActorSystem, CoordinatedShutdown} | |
| import akka.stream.ActorMaterializer | ||
| import com.typesafe.config.ConfigValueFactory | ||
| import kamon.Kamon | ||
| import pureconfig.loadConfigOrThrow | ||
| import org.apache.openwhisk.common.Https.HttpsConfig | ||
| import org.apache.openwhisk.common._ | ||
| import org.apache.openwhisk.core.{ConfigKeys, WhiskConfig} | ||
| import org.apache.openwhisk.core.WhiskConfig._ | ||
| import org.apache.openwhisk.core.connector.{MessagingProvider, PingMessage} | ||
| import org.apache.openwhisk.core.connector.{MessageProducer, MessagingProvider} | ||
| import org.apache.openwhisk.core.containerpool.ContainerPoolConfig | ||
| import org.apache.openwhisk.core.entity.{ExecManifest, InvokerInstanceId} | ||
| import org.apache.openwhisk.core.entity.ActivationEntityLimit | ||
| import org.apache.openwhisk.core.entity.{ActivationEntityLimit, ConcurrencyLimitConfig, ExecManifest, InvokerInstanceId} | ||
| import org.apache.openwhisk.core.entity.size._ | ||
| import org.apache.openwhisk.core.{ConfigKeys, WhiskConfig} | ||
| import org.apache.openwhisk.http.{BasicHttpService, BasicRasService} | ||
| import org.apache.openwhisk.spi.SpiLoader | ||
| import org.apache.openwhisk.spi.{Spi, SpiLoader} | ||
| import org.apache.openwhisk.utils.ExecutionContextFactory | ||
| import pureconfig.loadConfigOrThrow | ||
|
|
||
| import scala.concurrent.duration._ | ||
| import scala.concurrent.Await | ||
| import scala.util.{Failure, Try} | ||
| import scala.concurrent.{Await, ExecutionContext} | ||
| import scala.util.Try | ||
|
|
||
| case class CmdLineArgs(uniqueName: Option[String] = None, id: Option[Int] = None, displayedName: Option[String] = None) | ||
|
|
||
|
|
@@ -71,6 +70,7 @@ object Invoker { | |
| ActorSystem(name = "invoker-actor-system", defaultExecutionContext = Some(ec)) | ||
| implicit val logger = new AkkaLogging(akka.event.Logging.getLogger(actorSystem, this)) | ||
| val poolConfig: ContainerPoolConfig = loadConfigOrThrow[ContainerPoolConfig](ConfigKeys.containerPool) | ||
| val limitConfig: ConcurrencyLimitConfig = loadConfigOrThrow[ConcurrencyLimitConfig](ConfigKeys.concurrencyLimit) | ||
|
|
||
| // Prepare Kamon shutdown | ||
| CoordinatedShutdown(actorSystem).addTask(CoordinatedShutdown.PhaseActorSystemTerminate, "shutdownKamon") { () => | ||
|
|
@@ -156,25 +156,50 @@ object Invoker { | |
| .isFailure) { | ||
| abort(s"failure during msgProvider.ensureTopic for topic $topicName") | ||
| } | ||
|
|
||
| val producer = msgProvider.getProducer(config, Some(ActivationEntityLimit.MAX_ACTIVATION_LIMIT)) | ||
| val invoker = try { | ||
| new InvokerReactive(config, invokerInstance, producer, poolConfig) | ||
| SpiLoader.get[InvokerProvider].instance(config, invokerInstance, producer, poolConfig, limitConfig) | ||
| } catch { | ||
| case e: Exception => abort(s"Failed to initialize reactive invoker: ${e.getMessage}") | ||
| } | ||
|
|
||
| Scheduler.scheduleWaitAtMost(1.seconds)(() => { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In some invoker implementations, health checking may not be performed via Kafka. |
||
| producer.send("health", PingMessage(invokerInstance)).andThen { | ||
| case Failure(t) => logger.error(this, s"failed to ping the controller: $t") | ||
| } | ||
| }) | ||
|
|
||
| val port = config.servicePort.toInt | ||
| val httpsConfig = | ||
| if (Invoker.protocol == "https") Some(loadConfigOrThrow[HttpsConfig]("whisk.invoker.https")) else None | ||
|
|
||
| BasicHttpService.startHttpService(new BasicRasService {}.route, port, httpsConfig)( | ||
| val invokerServer = SpiLoader.get[InvokerServerProvider].instance(invoker) | ||
| BasicHttpService.startHttpService(invokerServer.route, port, httpsConfig)( | ||
| actorSystem, | ||
| ActorMaterializer.create(actorSystem)) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * An Spi for providing invoker implementation. | ||
| */ | ||
| trait InvokerProvider extends Spi { | ||
| def instance(config: WhiskConfig, | ||
| instance: InvokerInstanceId, | ||
| producer: MessageProducer, | ||
| poolConfig: ContainerPoolConfig, | ||
| limitsConfig: ConcurrencyLimitConfig)(implicit actorSystem: ActorSystem, logging: Logging): InvokerCore | ||
| } | ||
|
|
||
| // this trait can be used to add common implementation | ||
| trait InvokerCore {} | ||
|
|
||
| /** | ||
| * An Spi for providing RestAPI implementation for invoker. | ||
| * The given invoker may require corresponding RestAPI implementation. | ||
| */ | ||
| trait InvokerServerProvider extends Spi { | ||
| def instance( | ||
| invoker: InvokerCore)(implicit ec: ExecutionContext, actorSystem: ActorSystem, logger: Logging): BasicRasService | ||
| } | ||
|
|
||
| object DefaultInvokerServer extends InvokerServerProvider { | ||
| override def instance( | ||
| invoker: InvokerCore)(implicit ec: ExecutionContext, actorSystem: ActorSystem, logger: Logging): BasicRasService = | ||
| new BasicRasService {} | ||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered many options to apply SPI in invoker.
For example, it would be possible to keep
InvokerReactiveand apply SPI toContainerPoolandContainerProxylevel.But I noticed that they are also highly dependent on
InvokerReactive.So it would be more natural to apply SPI at the highest level of implementation.
It will abstract and hide the fundamental implementation such as
ContainerPoolandContainerProxyfrom the top level Invoker implementation.Also, there could be some dependent RestAPI implementations corresponding to the Invoker implementation.
So I added SPI provider for
InvokerServerwhich provides REST API as well.