Skip to content

Commit 3e0603d

Browse files
committed
Review
1 parent fec81ef commit 3e0603d

File tree

7 files changed

+35
-54
lines changed

7 files changed

+35
-54
lines changed

ansible/templates/whisk.properties.j2

-6
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ kafka.hosts={{ kafka_connect_string }}
4646
redis.host={{ groups["redis"]|default([""])|first }}
4747
router.host={{ groups["edge"]|first }}
4848
zookeeper.hosts={{ zookeeper_connect_string }}
49-
invoker.protocol={{ invoker.protocol }}
5049
invoker.hosts={{ groups["invokers"] | map('extract', hostvars, 'ansible_host') | list | join(",") }}
51-
invoker.username={{ invoker.username }}
52-
invoker.password={{ invoker.password }}
5350

5451
edge.host.apiport=443
5552
kafkaras.host.port={{ kafka.ras.port }}
@@ -59,9 +56,6 @@ invoker.hosts.basePort={{ invoker.port }}
5956
controller.hosts={{ groups["controllers"] | map('extract', hostvars, 'ansible_host') | list | join(",") }}
6057
controller.host.basePort={{ controller.basePort }}
6158
controller.instances={{ controller.instances }}
62-
controller.protocol={{ controller.protocol }}
63-
controller.username={{ controller.username }}
64-
controller.password={{ controller.password }}
6559

6660
invoker.container.network=bridge
6761
invoker.container.policy={{ invoker_container_policy_name | default()}}

core/controller/src/main/scala/org/apache/openwhisk/core/controller/Controller.scala

+13-8
Original file line numberDiff line numberDiff line change
@@ -186,36 +186,41 @@ class Controller(val instance: ControllerInstanceId,
186186
entity(as[String]) { runtime =>
187187
val execManifest = ExecManifest.initialize(runtime)
188188
if (execManifest.isFailure) {
189-
logging.error(this, s"Received invalid runtimes manifest")
190-
complete(s"Received invalid runtimes manifest")
189+
logging.info(this, s"received invalid runtimes manifest")
190+
complete(StatusCodes.BadRequest)
191191
} else {
192192
parameter('limit.?) { limit =>
193193
limit match {
194194
case Some(targetValue) =>
195-
val pattern = "\\d+:\\d"
195+
val pattern = """\d+:\d"""
196196
if (targetValue.matches(pattern)) {
197197
val invokerArray = targetValue.split(":")
198198
val beginIndex = invokerArray(0).toInt
199199
val finishIndex = invokerArray(1).toInt
200200
if (finishIndex < beginIndex) {
201-
complete(s"finishIndex can't be less than beginIndex")
201+
logging.info(this, "finishIndex can't be less than beginIndex")
202+
complete(StatusCodes.BadRequest)
202203
} else {
203204
val targetInvokers = (beginIndex to finishIndex).toList
204205
loadBalancer.sendRuntimeToInvokers(runtime, Some(targetInvokers))
205-
complete(s"config runtime request is already sent to target invokers")
206+
logging.info(this, "config runtime request is already sent to target invokers")
207+
complete(StatusCodes.BadRequest)
206208
}
207209
} else {
208-
complete(s"limit value can't match [beginIndex:finishIndex]")
210+
logging.info(this, "limit value can't match [beginIndex:finishIndex]")
211+
complete(StatusCodes.BadRequest)
209212
}
210213
case None =>
211214
loadBalancer.sendRuntimeToInvokers(runtime, None)
212-
complete(s"config runtime request is already sent to all managed invokers")
215+
logging.info(this, "config runtime request is already sent to all managed invokers")
216+
complete(StatusCodes.Accepted)
213217
}
214218
}
215219
}
216220
}
217221
} else {
218-
complete("username or password is wrong")
222+
logging.info(this, s"username or password is wrong")
223+
complete(StatusCodes.Unauthorized)
219224
}
220225
case _ => complete(StatusCodes.Unauthorized)
221226
}

core/invoker/src/main/scala/org/apache/openwhisk/core/containerpool/ContainerPool.scala

+4-2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class ContainerPool(childFactory: ActorRefFactory => ActorRef,
7575
var busyPool = immutable.Map.empty[ActorRef, ContainerData]
7676
var prewarmedPool = immutable.Map.empty[ActorRef, ContainerData]
7777
var prewarmStartingPool = immutable.Map.empty[ActorRef, (String, ByteSize)]
78+
var laststPrewarmConfig = prewarmConfig
7879
// If all memory slots are occupied and if there is currently no container to be removed, than the actions will be
7980
// buffered here to keep order of computation.
8081
// Otherwise actions with small memory-limits could block actions with large memory limits.
@@ -285,14 +286,15 @@ class ContainerPool(childFactory: ActorRefFactory => ActorRef,
285286
freePool = freePool - sender()
286287
busyPool = busyPool - sender()
287288
case prewarmConfigList: PreWarmConfigList =>
289+
laststPrewarmConfig = prewarmConfigList.list
288290
// Delete prewarmedPool firstly
289291
prewarmedPool foreach { element =>
290292
val actor = element._1
291293
actor ! Remove
292294
prewarmedPool = prewarmedPool - actor
293295
}
294296
prewarmConfigList.list foreach { config =>
295-
logging.info(this, s"add extra pre-warming ${config.count} ${config.exec.kind} ${config.memoryLimit.toString}")(
297+
logging.info(this, s"add pre-warming ${config.count} ${config.exec.kind} ${config.memoryLimit.toString}")(
296298
TransactionId.invokerWarmup)
297299
(1 to config.count).foreach { _ =>
298300
prewarmContainer(config.exec, config.memoryLimit)
@@ -325,7 +327,7 @@ class ContainerPool(childFactory: ActorRefFactory => ActorRef,
325327

326328
/** Install prewarm containers up to the configured requirements for each kind/memory combination. */
327329
def backfillPrewarms(init: Boolean) = {
328-
prewarmConfig.foreach { config =>
330+
laststPrewarmConfig.foreach { config =>
329331
val kind = config.exec.kind
330332
val memory = config.memoryLimit
331333
val currentCount = prewarmedPool.count {

core/invoker/src/main/scala/org/apache/openwhisk/core/invoker/DefaultInvokerServer.scala

+4-3
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ class DefaultInvokerServer(val invoker: InvokerCore)(implicit val ec: ExecutionC
5151
entity(as[String]) { prewarmRuntime =>
5252
val execManifest = ExecManifest.initialize(prewarmRuntime)
5353
if (execManifest.isFailure) {
54-
logger.error(this, s"Received invalid runtimes manifest:${execManifest.failed.get}")
55-
complete(s"Received invalid runtimes manifest")
54+
logger.info(this, s"received invalid runtimes manifest")
55+
complete(StatusCodes.BadRequest)
5656
} else {
5757
val prewarmingConfigs: List[PrewarmingConfig] = execManifest.get.stemcells.flatMap {
5858
case (mf, cells) =>
@@ -64,7 +64,8 @@ class DefaultInvokerServer(val invoker: InvokerCore)(implicit val ec: ExecutionC
6464
}
6565
}
6666
} else {
67-
complete("username or password is wrong")
67+
logger.info(this, s"username or password is wrong")
68+
complete(StatusCodes.Unauthorized)
6869
}
6970
case _ => complete(StatusCodes.Unauthorized)
7071
}

core/invoker/src/main/scala/org/apache/openwhisk/core/invoker/InvokerReactive.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import akka.Done
2424
import akka.actor.{ActorRefFactory, ActorSystem, CoordinatedShutdown, Props}
2525
import akka.event.Logging.InfoLevel
2626
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._
27+
import akka.http.scaladsl.model.StatusCodes
2728
import akka.http.scaladsl.server.Directives._
2829
import akka.http.scaladsl.server.Route
2930
import akka.stream.ActorMaterializer
@@ -325,7 +326,8 @@ class InvokerReactive(
325326

326327
override def configRuntime(prewarmConfigList: List[PrewarmingConfig]): Route = {
327328
pool ! PreWarmConfigList(prewarmConfigList)
328-
complete(s"config runtime request is handling")
329+
logging.info(this, "config runtime request is handling")
330+
complete(StatusCodes.Accepted)
329331
}
330332

331333
override def getRuntime(): Route = {

tests/src/test/scala/common/WhiskProperties.java

-26
Original file line numberDiff line numberDiff line change
@@ -258,40 +258,14 @@ public static int getControllerBasePort() {
258258
return Integer.parseInt(whiskProperties.getProperty("controller.host.basePort"));
259259
}
260260

261-
public static String getControllerProtocol() {
262-
return whiskProperties.getProperty("controller.protocol");
263-
}
264-
265261
public static String getBaseControllerHost() {
266262
return getControllerHosts().split(",")[0];
267263
}
268264

269-
public static String getInvokerProtocol() {
270-
return whiskProperties.getProperty("invoker.protocol");
271-
}
272-
273-
274265
public static String getBaseInvokerAddress(){
275266
return getInvokerHosts()[0] + ":" + whiskProperties.getProperty("invoker.hosts.basePort");
276267
}
277268

278-
public static String getControllerUsername() {
279-
return whiskProperties.getProperty("controller.username");
280-
}
281-
282-
public static String getControllerPassword() {
283-
return whiskProperties.getProperty("controller.password");
284-
}
285-
286-
287-
public static String getInvokerUsername() {
288-
return whiskProperties.getProperty("invoker.username");
289-
}
290-
291-
public static String getInvokerPassword() {
292-
return whiskProperties.getProperty("invoker.password");
293-
}
294-
295269
public static String getBaseDBHost() {
296270
return getDBHosts().split(",")[0];
297271
}

tests/src/test/scala/org/apache/openwhisk/operation/RuntimeConfiguration.scala tests/src/test/scala/org/apache/openwhisk/operation/RuntimeConfigurationTests.scala

+11-8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import org.junit.runner.RunWith
3030
import org.scalatest.Matchers
3131
import org.scalatest.concurrent.ScalaFutures
3232
import org.scalatest.junit.JUnitRunner
33+
import pureconfig.loadConfigOrThrow
3334
import spray.json._
3435
import system.rest.RestUtil
3536

@@ -76,16 +77,16 @@ class RuntimeConfigurationTests
7677
}"""
7778
}
7879

79-
val invokerProtocol = WhiskProperties.getInvokerProtocol
80+
val invokerProtocol = loadConfigOrThrow[String]("whisk.invoker.protocol")
8081
val invokerAddress = WhiskProperties.getBaseInvokerAddress
81-
val invokerUsername = WhiskProperties.getInvokerUsername
82-
val invokerPassword = WhiskProperties.getInvokerPassword
82+
val invokerUsername = loadConfigOrThrow[String]("whisk.credentials.invoker.username")
83+
val invokerPassword = loadConfigOrThrow[String]("whisk.credentials.invoker.password")
8384
val invokerAuthHeader = Authorization(BasicHttpCredentials(invokerUsername, invokerPassword))
8485

85-
val controllerProtocol = WhiskProperties.getControllerProtocol
86+
val controllerProtocol = loadConfigOrThrow[String]("whisk.controller.protocol")
8687
val controllerAddress = WhiskProperties.getBaseControllerAddress
87-
val controllerUsername = WhiskProperties.getControllerUsername
88-
val controllerPassword = WhiskProperties.getControllerPassword
88+
val controllerUsername = loadConfigOrThrow[String]("whisk.credentials.controller.username")
89+
val controllerPassword = loadConfigOrThrow[String]("whisk.credentials.controller.password")
8990
val controllerAuthHeader = Authorization(BasicHttpCredentials(controllerUsername, controllerPassword))
9091

9192
val getRuntimeUrl = s"${invokerProtocol}://${invokerAddress}/getRuntime"
@@ -104,9 +105,10 @@ class RuntimeConfigurationTests
104105
entity = HttpEntity(ContentTypes.`text/plain(UTF-8)`, getRuntimes)),
105106
connectionContext = HttpConnection.getContext(invokerProtocol))
106107
.map { response =>
107-
response.status shouldBe StatusCodes.OK
108+
response.status shouldBe StatusCodes.Accepted
108109
}
109110

111+
// Make sure previous http post call successfully
110112
Thread.sleep(5.seconds.toMillis)
111113

112114
//Cal the prewarm container number whether right
@@ -136,9 +138,10 @@ class RuntimeConfigurationTests
136138
entity = HttpEntity(ContentTypes.`text/plain(UTF-8)`, getRuntimes)),
137139
connectionContext = HttpConnection.getContext(controllerProtocol))
138140
.map { response =>
139-
response.status shouldBe StatusCodes.OK
141+
response.status shouldBe StatusCodes.Accepted
140142
}
141143

144+
// Make sure previous http post call successfully
142145
Thread.sleep(5.seconds.toMillis)
143146

144147
//Cal the prewarm container number whether right

0 commit comments

Comments
 (0)