@@ -21,7 +21,8 @@ import akka.Done
2121import akka .actor .{ActorSystem , CoordinatedShutdown }
2222import akka .event .Logging .InfoLevel
2323import akka .http .scaladsl .marshallers .sprayjson .SprayJsonSupport ._
24- import akka .http .scaladsl .model .Uri
24+ import akka .http .scaladsl .model .{StatusCodes , Uri }
25+ import akka .http .scaladsl .model .headers .BasicHttpCredentials
2526import akka .http .scaladsl .server .Route
2627import akka .stream .ActorMaterializer
2728import kamon .Kamon
@@ -78,6 +79,17 @@ class Controller(val instance: ControllerInstanceId,
7879 implicit val logging : Logging )
7980 extends BasicRasService {
8081
82+ val controllerUsername = {
83+ val source = scala.io.Source .fromFile(" /conf/controllerauth.username" );
84+ try source.mkString.replaceAll(" \r |\n " , " " )
85+ finally source.close()
86+ }
87+ val controllerPassword = {
88+ val source = scala.io.Source .fromFile(" /conf/controllerauth.password" );
89+ try source.mkString.replaceAll(" \r |\n " , " " )
90+ finally source.close()
91+ }
92+
8193 TransactionId .controller.mark(
8294 this ,
8395 LoggingMarkers .CONTROLLER_STARTUP (instance.asString),
@@ -95,7 +107,7 @@ class Controller(val instance: ControllerInstanceId,
95107 (pathEndOrSingleSlash & get) {
96108 complete(info)
97109 }
98- } ~ apiV1.routes ~ swagger.swaggerRoutes ~ internalInvokerHealth
110+ } ~ apiV1.routes ~ swagger.swaggerRoutes ~ internalInvokerHealth ~ changeRuntime
99111 }
100112
101113 // initialize datastores
@@ -154,6 +166,38 @@ class Controller(val instance: ControllerInstanceId,
154166 }
155167 }
156168
169+ /**
170+ * Handles POST/DELETE prewarm container
171+ */
172+ private val changeRuntime = {
173+ implicit val executionContext = actorSystem.dispatcher
174+ (path(" prewarmContainer" ) & (post | delete)) {
175+ extractCredentials {
176+ case Some (BasicHttpCredentials (username, password)) =>
177+ if (username == controllerUsername && password == controllerPassword) {
178+ extractMethod { method =>
179+ entity(as[String ]) { prewarmRuntime =>
180+ val execManifest = ExecManifest .initializePrewarm(prewarmRuntime)
181+ if (execManifest.isFailure) {
182+ logging.error(
183+ this ,
184+ s " Received invalid prewarm runtimes manifest with ${method.name} request: ${execManifest.failed.get}" )
185+ complete(s " Received invalid prewarm runtimes manifest with ${method.name} request " )
186+ } else {
187+ logging.info(this , s " Received valid prewarm runtimes manifest with ${method.name} request " )
188+ loadBalancer.sendRuntimeToManageInvoker(prewarmRuntime, method.name)
189+ complete(s " Change prewarm container request with ${method.name} is already sent to managed invokers " )
190+ }
191+ }
192+ }
193+ } else {
194+ complete(" username or password is wrong" )
195+ }
196+ case _ => complete(StatusCodes .Unauthorized )
197+ }
198+ }
199+ }
200+
157201 // controller top level info
158202 private val info = Controller .info(
159203 whiskConfig,
0 commit comments