Skip to content
Snippets Groups Projects
Commit 276d9ebb authored by Benedikt Wetzel's avatar Benedikt Wetzel
Browse files

Use a string array instead of a single string to define the command of an action

parent 0f24e4f7
No related branches found
No related tags found
1 merge request!201Introduce action commands
......@@ -87,7 +87,9 @@ spec:
type: object
properties:
command:
type: string
type: array
items:
type: string
afterActions:
type: array
default: []
......@@ -111,7 +113,9 @@ spec:
type: object
properties:
command:
type: string
type: array
items:
type: string
sut:
description: The appResourceSets specifies all Kubernetes resources required to start the sut. A resourceSet can be either a configMap resourceSet or a fileSystem resourceSet.
type: object
......@@ -172,7 +176,9 @@ spec:
type: object
properties:
command:
type: string
type: array
items:
type: string
afterActions:
type: array
default: []
......@@ -196,7 +202,9 @@ spec:
type: object
properties:
command:
type: string
type: array
items:
type: string
loadGenerator:
description: The loadGenResourceSets specifies all Kubernetes resources required to start the load generator. A resourceSet can be either a configMap resourceSet or a fileSystem resourceSet.
type: object
......@@ -257,7 +265,9 @@ spec:
type: object
properties:
command:
type: string
type: array
items:
type: string
afterActions:
type: array
default: []
......@@ -281,7 +291,9 @@ spec:
type: object
properties:
command:
type: string
type: array
items:
type: string
resourceTypes:
description: A list of resource types that can be scaled for this `benchmark` resource. For each resource type the concrete values are defined in the `execution` object.
type: array
......
......@@ -19,9 +19,9 @@ spec:
- selector:
pod:
matchLabels:
app: titan-ccp-aggregation
app: busybox1
exec:
command: "ls -l" # or list
command: ["rm", "test-folder"]
loadGenerator:
resources:
- configMap:
......@@ -29,15 +29,7 @@ spec:
files:
- uc1-load-generator-service.yaml
- uc1-load-generator-deployment.yaml
beforeActions:
- selector:
pod:
matchLabels:
'app.kubernetes.io/name': grafana
#container: "abc" # optional (if there is only one container or there exists something like a default container)
exec:
command: "kafka-topics.sh --create --topic abc" # or list
beforeActions: []
resourceTypes:
- typeName: "Instances"
patchers:
......
......@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import io.fabric8.kubernetes.client.NamespacedKubernetesClient
import io.quarkus.runtime.annotations.RegisterForReflection
import theodolite.util.ActionCommandFailedException
@JsonDeserialize
@RegisterForReflection
......@@ -14,12 +15,15 @@ class Action {
lateinit var exec: Command
fun exec(client: NamespacedKubernetesClient) {
ActionCommand(client = client)
val exitCode = ActionCommand(client = client)
.exec(
matchLabels = selector.pod.matchLabels,
container = selector.container,
command = exec.command
)
)
if(exitCode != 0){
throw ActionCommandFailedException("Error while executing action, finished with exit code $exitCode")
}
}
}
......@@ -37,5 +41,5 @@ class PodSelector {
@JsonDeserialize
@RegisterForReflection
class Command {
lateinit var command: String
lateinit var command: Array<String>
}
\ No newline at end of file
......@@ -27,9 +27,9 @@ class ActionCommand(val client: NamespacedKubernetesClient) {
* `of any` of is used and the command is called on one of the possible pods.
* @param container (Optional) The container to run the command. Is optional iff exactly one container exist.
* @param command The command to be executed.
* @return
* @return the exit code of this executed command
*/
fun exec(matchLabels: MutableMap<String, String>, command: String, container: String = ""): Int {
fun exec(matchLabels: MutableMap<String, String>, command: Array<String>, container: String = ""): Int {
val exitCode = ExitCode()
......@@ -48,7 +48,7 @@ class ActionCommand(val client: NamespacedKubernetesClient) {
.writingOutput(out)
.writingError(error)
.usingListener(MyPodExecListener(execLatch, exitCode))
.exec(*command.split(" ").toTypedArray())
.exec(*command)
val latchTerminationStatus = execLatch.await(TIMEOUT, TimeUnit.SECONDS);
if (!latchTerminationStatus) {
......@@ -60,7 +60,7 @@ class ActionCommand(val client: NamespacedKubernetesClient) {
throw ActionCommandFailedException("Interrupted while waiting for the exec", e)
}
logger.info { "Action command finished with code $exitCode" }
logger.info { "Action command finished with code ${exitCode.code}" }
return exitCode.code
}
......@@ -101,7 +101,7 @@ class ActionCommand(val client: NamespacedKubernetesClient) {
override fun onFailure(throwable: Throwable, response: Response) {
execLatch.countDown()
throw ActionCommandFailedException("Some error encountered while executing action")
throw ActionCommandFailedException("Some error encountered while executing action: ${throwable.printStackTrace()}")
}
override fun onClose(code: Int, reason: String) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment