@@ -22,7 +22,8 @@ import akka.actor.{ActorSystem, CoordinatedShutdown}
2222import akka .event .Logging .InfoLevel
2323import akka .http .scaladsl .marshallers .sprayjson .SprayJsonSupport ._
2424import akka .http .scaladsl .model .StatusCodes ._
25- import akka .http .scaladsl .model .Uri
25+ import akka .http .scaladsl .model .{StatusCodes , Uri }
26+ import akka .http .scaladsl .model .headers .BasicHttpCredentials
2627import akka .http .scaladsl .server .Route
2728import akka .stream .ActorMaterializer
2829import kamon .Kamon
@@ -32,8 +33,8 @@ import spray.json.DefaultJsonProtocol._
3233import spray .json ._
3334import org .apache .openwhisk .common .Https .HttpsConfig
3435import org .apache .openwhisk .common .{AkkaLogging , ConfigMXBean , Logging , LoggingMarkers , TransactionId }
35- import org .apache .openwhisk .core .WhiskConfig
36- import org .apache .openwhisk .core .connector .MessagingProvider
36+ import org .apache .openwhisk .core .{ ConfigKeys , WhiskConfig }
37+ import org .apache .openwhisk .core .connector .{ InvokerConfiguration , MessagingProvider , UserMemoryMessage }
3738import org .apache .openwhisk .core .containerpool .logging .LogStoreProvider
3839import org .apache .openwhisk .core .database .{ActivationStoreProvider , CacheChangeNotification , RemoteCacheInvalidation }
3940import org .apache .openwhisk .core .entitlement ._
@@ -97,7 +98,7 @@ class Controller(val instance: ControllerInstanceId,
9798 (pathEndOrSingleSlash & get) {
9899 complete(info)
99100 }
100- } ~ apiV1.routes ~ swagger.swaggerRoutes ~ internalInvokerHealth
101+ } ~ apiV1.routes ~ swagger.swaggerRoutes ~ internalInvokerHealth ~ configMemory
101102 }
102103
103104 // initialize datastores
@@ -176,6 +177,41 @@ class Controller(val instance: ControllerInstanceId,
176177 LogLimit .config,
177178 runtimes,
178179 List (apiV1.basepath()))
180+
181+ private val controllerUsername = loadConfigOrThrow[String ](ConfigKeys .whiskControllerUsername)
182+ private val controllerPassword = loadConfigOrThrow[String ](ConfigKeys .whiskControllerPassword)
183+
184+ /**
185+ * config user memory of ContainerPool
186+ */
187+ import org .apache .openwhisk .core .connector .InvokerConfigurationProtocol ._
188+ private val configMemory = {
189+ implicit val executionContext = actorSystem.dispatcher
190+ (path(" config" / " memory" ) & post) {
191+ extractCredentials {
192+ case Some (BasicHttpCredentials (username, password)) =>
193+ if (username == controllerUsername && password == controllerPassword) {
194+ entity(as[String ]) { memory =>
195+ val configMemoryList = memory.parseJson.convertTo[List [InvokerConfiguration ]]
196+ configMemoryList.find(config => MemoryLimit .MIN_MEMORY .compare(config.memory) > 0 ) match {
197+ case Some (_) =>
198+ complete(StatusCodes .BadRequest , s " user memory can't be less than ${MemoryLimit .MIN_MEMORY }" )
199+ case None =>
200+ configMemoryList.foreach { config =>
201+ val invoker = config.invoker
202+ val userMemoryMessage = UserMemoryMessage (config.memory)
203+ loadBalancer.sendChangeRequestToInvoker(userMemoryMessage, invoker)
204+ }
205+ complete(StatusCodes .Accepted )
206+ }
207+ }
208+ } else {
209+ complete(StatusCodes .Unauthorized , " username or password is wrong" )
210+ }
211+ case _ => complete(StatusCodes .Unauthorized )
212+ }
213+ }
214+ }
179215}
180216
181217/**
0 commit comments