Skip to content

Commit be5a6e5

Browse files
committed
Review
1 parent 2af74d8 commit be5a6e5

File tree

13 files changed

+34
-164
lines changed

13 files changed

+34
-164
lines changed

ansible/group_vars/all

-2
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,6 @@ invoker:
203203
runcdir: "{{ invoker_runcdir | default('/run/docker/runtime-runc/moby') }}"
204204
volumes: "{{ invoker_docker_volumes | default([]) }}"
205205
loglevel: "{{ invoker_loglevel | default(whisk_loglevel) | default('INFO') }}"
206-
username: "{{ invoker_username | default('invoker.user') }}"
207-
password: "{{ invoker_password | default('invoker.pass') }}"
208206
jmxremote:
209207
jvmArgs: "{% if inventory_hostname in groups['invokers'] %}
210208
{{ jmx.jvmCommonArgs }} -Djava.rmi.server.hostname={{ invokerHostname }} -Dcom.sun.management.jmxremote.rmi.port={{ jmx.rmiBasePortInvoker + groups['invokers'].index(inventory_hostname) }} -Dcom.sun.management.jmxremote.port={{ jmx.basePortInvoker + groups['invokers'].index(inventory_hostname) }}

ansible/roles/invoker/tasks/deploy.yml

-2
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,6 @@
266266
"CONFIG_whisk_timeLimit_min": "{{ limit_action_time_min | default() }}"
267267
"CONFIG_whisk_timeLimit_max": "{{ limit_action_time_max | default() }}"
268268
"CONFIG_whisk_timeLimit_std": "{{ limit_action_time_std | default() }}"
269-
"CONFIG_whisk_credentials_invoker_username": "{{ invoker.username }}"
270-
"CONFIG_whisk_credentials_invoker_password": "{{ invoker.password }}"
271269
"CONFIG_whisk_concurrencyLimit_min": "{{ limit_action_concurrency_min | default() }}"
272270
"CONFIG_whisk_concurrencyLimit_max": "{{ limit_action_concurrency_max | default() }}"
273271
"CONFIG_whisk_concurrencyLimit_std": "{{ limit_action_concurrency_std | default() }}"

ansible/templates/whisk.properties.j2

-5
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 }}
@@ -60,8 +57,6 @@ controller.hosts={{ groups["controllers"] | map('extract', hostvars, 'ansible_ho
6057
controller.host.basePort={{ controller.basePort }}
6158
controller.instances={{ controller.instances }}
6259
controller.protocol={{ controller.protocol }}
63-
controller.username={{ controller.username }}
64-
controller.password={{ controller.password }}
6560

6661
invoker.container.network=bridge
6762
invoker.container.policy={{ invoker_container_policy_name | default()}}

common/scala/src/main/scala/org/apache/openwhisk/common/ComponentCredentials.scala

-2
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,3 @@
1818
package org.apache.openwhisk.common
1919

2020
case class ControllerCredentials(username: String, password: String)
21-
22-
case class InvokerCredentials(username: String, password: String)

common/scala/src/main/scala/org/apache/openwhisk/core/WhiskConfig.scala

-1
Original file line numberDiff line numberDiff line change
@@ -268,5 +268,4 @@ object ConfigKeys {
268268
val apacheClientConfig = "whisk.apache-client"
269269

270270
val controllerCredentials = "whisk.credentials.controller"
271-
val invokerCredentials = "whisk.credentials.invoker"
272271
}

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 latestPrewarmConfig = 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+
latestPrewarmConfig = 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+
latestPrewarmConfig.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-39
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,10 @@
1818
package org.apache.openwhisk.core.invoker
1919

2020
import akka.actor.ActorSystem
21-
import akka.http.scaladsl.model.StatusCodes
22-
import akka.http.scaladsl.model.headers.BasicHttpCredentials
2321
import akka.http.scaladsl.server.Route
24-
import org.apache.openwhisk.common.{InvokerCredentials, Logging, TransactionId}
25-
import org.apache.openwhisk.core.ConfigKeys
26-
import org.apache.openwhisk.core.containerpool.PrewarmingConfig
27-
import org.apache.openwhisk.core.entity.{CodeExecAsString, ExecManifest}
28-
import org.apache.openwhisk.http.BasicRasService
22+
import org.apache.openwhisk.common.{Logging, TransactionId}
2923

30-
import pureconfig._
31-
import pureconfig.generic.auto._
24+
import org.apache.openwhisk.http.BasicRasService
3225

3326
import scala.concurrent.ExecutionContext
3427

@@ -40,38 +33,10 @@ class DefaultInvokerServer(val invoker: InvokerCore)(implicit val ec: ExecutionC
4033
val logger: Logging)
4134
extends BasicRasService {
4235

43-
private val invokerCredentials = loadConfigOrThrow[InvokerCredentials](ConfigKeys.invokerCredentials)
44-
4536
override def routes(implicit transid: TransactionId): Route = {
4637
super.routes ~ {
47-
(path("config" / "runtime") & post) {
48-
extractCredentials {
49-
case Some(BasicHttpCredentials(username, password)) =>
50-
if (username == invokerCredentials.username && password == invokerCredentials.password) {
51-
entity(as[String]) { prewarmRuntime =>
52-
val execManifest = ExecManifest.initialize(prewarmRuntime)
53-
if (execManifest.isFailure) {
54-
logger.error(this, s"Received invalid runtimes manifest:${execManifest.failed.get}")
55-
complete(s"Received invalid runtimes manifest")
56-
} else {
57-
val prewarmingConfigs: List[PrewarmingConfig] = execManifest.get.stemcells.flatMap {
58-
case (mf, cells) =>
59-
cells.map { cell =>
60-
PrewarmingConfig(cell.count, new CodeExecAsString(mf, "", None), cell.memory)
61-
}
62-
}.toList
63-
invoker.configRuntime(prewarmingConfigs)
64-
}
65-
}
66-
} else {
67-
complete("username or password is wrong")
68-
}
69-
case _ => complete(StatusCodes.Unauthorized)
70-
}
71-
} ~ {
72-
(path("getRuntime") & get) {
73-
invoker.getRuntime()
74-
}
38+
(path("getRuntime") & get) {
39+
invoker.getRuntime()
7540
}
7641
}
7742
}

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import org.apache.openwhisk.common.Https.HttpsConfig
2727
import org.apache.openwhisk.common._
2828
import org.apache.openwhisk.core.WhiskConfig._
2929
import org.apache.openwhisk.core.connector.{MessageProducer, MessagingProvider}
30-
import org.apache.openwhisk.core.containerpool.{Container, ContainerPoolConfig, PrewarmingConfig}
30+
import org.apache.openwhisk.core.containerpool.{Container, ContainerPoolConfig}
3131
import org.apache.openwhisk.core.entity._
3232
import org.apache.openwhisk.core.entity.size._
3333
import org.apache.openwhisk.core.{ConfigKeys, WhiskConfig}
@@ -213,7 +213,6 @@ trait InvokerProvider extends Spi {
213213
// this trait can be used to add common implementation
214214
trait InvokerCore {
215215
def getRuntime(): Route
216-
def configRuntime(prewarmConfigList: List[PrewarmingConfig]): Route
217216
}
218217

219218
/**

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

-5
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,6 @@ class InvokerReactive(
323323
}
324324
})
325325

326-
override def configRuntime(prewarmConfigList: List[PrewarmingConfig]): Route = {
327-
pool ! PreWarmConfigList(prewarmConfigList)
328-
complete(s"config runtime request is handling")
329-
}
330-
331326
override def getRuntime(): Route = {
332327
complete {
333328
pool

docs/operation.md

-27
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,6 @@
1818
-->
1919

2020
# Runtime configuration
21-
## Change runtime on assigned invoker, e.g:
22-
```
23-
curl -u ${username}:${password} -X POST http://${invokerAddress}:${invokerPort}/config/runtime -d '
24-
{
25-
"runtimes": {
26-
"nodejs": [{
27-
"kind": "nodejs:10",
28-
"default": true,
29-
"image": {
30-
"prefix": "openwhisk",
31-
"name": "action-nodejs-v10",
32-
"tag": "nightly"
33-
},
34-
"deprecated": false,
35-
"attached": {
36-
"attachmentName": "codefile",
37-
"attachmentType": "text/plain"
38-
},
39-
"stemCells": [{
40-
"count": 2,
41-
"memory": "128 MB"
42-
}]
43-
}]
44-
}
45-
}
46-
'
47-
```
4821
## Change runtime to all managed invokers via controller. e.g.
4922
```
5023
curl -u ${username}:${password} -X POST http://${controllerAddress}:${controllerPort}/config/runtime -d '{...}'

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

+12-43
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@ import akka.http.scaladsl.unmarshalling.Unmarshal
2424
import akka.stream.ActorMaterializer
2525
import common._
2626
import common.rest.HttpConnection
27+
import org.apache.openwhisk.common.ControllerCredentials
2728
import org.apache.openwhisk.core.connector.PrewarmContainerDataList
2829
import org.apache.openwhisk.core.connector.PrewarmContainerDataProtocol._
2930
import org.junit.runner.RunWith
3031
import org.scalatest.Matchers
3132
import org.scalatest.concurrent.ScalaFutures
3233
import org.scalatest.junit.JUnitRunner
34+
import pureconfig.loadConfigOrThrow
35+
import pureconfig.generic.auto._
3336
import spray.json._
3437
import system.rest.RestUtil
3538

@@ -76,56 +79,21 @@ class RuntimeConfigurationTests
7679
}"""
7780
}
7881

79-
val invokerProtocol = WhiskProperties.getInvokerProtocol
82+
val invokerProtocol = loadConfigOrThrow[String]("whisk.invoker.protocol")
8083
val invokerAddress = WhiskProperties.getBaseInvokerAddress
81-
val invokerUsername = WhiskProperties.getInvokerUsername
82-
val invokerPassword = WhiskProperties.getInvokerPassword
83-
val invokerAuthHeader = Authorization(BasicHttpCredentials(invokerUsername, invokerPassword))
8484

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

9191
val getRuntimeUrl = s"${invokerProtocol}://${invokerAddress}/getRuntime"
9292
val invokerChangeRuntimeUrl = s"${invokerProtocol}://${invokerAddress}/config/runtime"
9393
val controllerChangeRuntimeUrl =
9494
s"${controllerProtocol}://${controllerAddress}/config/runtime"
9595

96-
it should "change assigned invoker node's runtime config directly" in {
97-
//Change config
98-
Http()
99-
.singleRequest(
100-
HttpRequest(
101-
method = HttpMethods.POST,
102-
uri = s"${invokerChangeRuntimeUrl}",
103-
headers = List(invokerAuthHeader),
104-
entity = HttpEntity(ContentTypes.`text/plain(UTF-8)`, getRuntimes)),
105-
connectionContext = HttpConnection.getContext(invokerProtocol))
106-
.map { response =>
107-
response.status shouldBe StatusCodes.OK
108-
}
109-
110-
Thread.sleep(5.seconds.toMillis)
111-
112-
//Cal the prewarm container number whether right
113-
Http()
114-
.singleRequest(
115-
HttpRequest(method = HttpMethods.GET, uri = s"${getRuntimeUrl}", headers = List(invokerAuthHeader)),
116-
connectionContext = HttpConnection.getContext(invokerProtocol))
117-
.map { response =>
118-
response.status shouldBe StatusCodes.OK
119-
val prewarmContainerDataList =
120-
Unmarshal(response).to[String].futureValue.parseJson.convertTo[PrewarmContainerDataList]
121-
val nodejs10ContainerData = prewarmContainerDataList.items.filter { prewarmContainerData =>
122-
prewarmContainerData.kind == kind && prewarmContainerData.memory == memory
123-
}
124-
nodejs10ContainerData.head.number shouldBe count
125-
}
126-
}
127-
128-
it should "change all managed invokers's prewarm config via controller" in {
96+
it should "change all managed invokers's prewarm config" in {
12997
//Change runtime config
13098
Http()
13199
.singleRequest(
@@ -136,15 +104,16 @@ class RuntimeConfigurationTests
136104
entity = HttpEntity(ContentTypes.`text/plain(UTF-8)`, getRuntimes)),
137105
connectionContext = HttpConnection.getContext(controllerProtocol))
138106
.map { response =>
139-
response.status shouldBe StatusCodes.OK
107+
response.status shouldBe StatusCodes.Accepted
140108
}
141109

110+
// Make sure previous http post call successfully
142111
Thread.sleep(5.seconds.toMillis)
143112

144113
//Cal the prewarm container number whether right
145114
Http()
146115
.singleRequest(
147-
HttpRequest(method = HttpMethods.GET, uri = s"${getRuntimeUrl}", headers = List(invokerAuthHeader)),
116+
HttpRequest(method = HttpMethods.GET, uri = s"${getRuntimeUrl}"),
148117
connectionContext = HttpConnection.getContext(invokerProtocol))
149118
.map { response =>
150119
response.status shouldBe StatusCodes.OK

0 commit comments

Comments
 (0)