# \[AIAB-03] Create the workflow

You can now create a new workflow that you will use in your optimization study.

A workflow in an optimization study is typically composed of the following tasks:

* Apply a new configuration of the selected optimization parameters to the target system: in this example, you will leverage the Akamas *FileConfigurator* operator - this operator can be used to write parameter values into a generic file, which could represent a shell script, an application configuration file, or any other file used to apply parameters to the target systems
* Restart the application (optional): in this example, the Konakart docker container needs to be restarted in order to launch the Konakart JVM for the new configuration to be effectively applied
* Launch the performance test using LRE

To create the optimization workflow, update the `workflow-optimize.yaml` file replacing the correct references to your environment:

```yaml
name: konakart-optimize

tasks:
  - name: Configure JVM options
    operator: FileConfigurator
    arguments:
      source:
        hostname: target_host
        username: ubuntu
        key: /home/jsmith/.ssh/akamas.key
        path: /home/ubuntu/konakart-docker/konakart/docker-compose.yml.templ
      target:
        hostname: target_host
        username: ubuntu
        key: /home/jsmith/.ssh/akamas.key
        path: /home/ubuntu/konakart-docker/konakart/docker-compose.yml

  - name: Restart konakart
    operator: Executor
    arguments:
      command: "docker stack deploy --compose-file /home/ubuntu/konakart-docker/konakart/docker-compose.yml sut"
      host:
        hostname: target_host
        username: ubuntu
        key: /home/jsmith/.ssh/akamas.key

  - name: Performance test
    operator: LoadRunnerEnterprise
    arguments:
      retries: 0
      address: http://lre_target_host
      username: lre_user
      password: lre_user_password
      project: lre_project
      domain: lre_project_domain
      tenantID: lre_tenant_id
      testId: test_id
      testSet: test_set_name
      timeSlot: test_max_duration
      verifySSL: false
```

Make sure to replace the placeholders with the correct references to your environment:

* *hostname* should reference your Konakart instance in place of the placeholder *target\_host*
* *username* and *key* must reflect your Konakart instance user and SSH private key file (also change the path /home/jsmith)
* *path* and *commands* should have the correct file paths to Docker Compose files

Regarding the LoadRunnerEnterprise operator, update the configuration above with the actual values of:

* *address*: the FQDN of your LRE farm (LRE server)
* *username*: and *password* the credentials of the LRE user
* *project*: the name of the project created on LRE
* *domain*: the domain of the project you created on LRE
* *tenantID*: the tenant of your project (if multi-tenancy is enabled)
* *testId*: the id of your test on LRE
* *testSet*: the test set name your test belongs to
* *timeSlot*: the time slot reserved by Akamas on LRE to run your tests
* *verifySSL*: it configures Akamas to validate the SSL configuration or skip it (useful for self-signed certificates)

For more information about the configurations available for LoadRunner Enterprise, please refer to LRE dedicated integration guide.

Once you have edited this file, run the following command to create the workflow:

```bash
akamas create workflow workflow-optimize.yaml
```

### Enable parameter configuration

In the workflow, the *FileConfigurator* operator is used to automatically apply the configuration of the JVM parameters at each experiment. In order for this to work, you need to allow Akamas to set the parameter values being tested in each experiment. This is made possible by the following Akamas templating approach:

* locate your application configuration file where the optimization parameters need to be set
* find the place where the parameter that needs to be optimized is specified - for example, the heap size of the JVM: `tomcat_jvm_heapsize=1024`
* replace the hardcoded value with the Akamas parameter template string, where you specify both the component name and the name of the Akamas parameter - for example: `tomcat_jvm_heapsize=${jvm.maxHeapSize}`
* at this point, every time the FileConfiguration operator is invoked in your workflow, a new application configuration file will be created where each of the parameter templates replaced with the parameter values being tested by Akamas in the corresponding experiment (e.g. `tomcat_jvm_heapsize=537`).

Therefore, you will now prepare the Konakart configuration file (a Docker Compose file).

First of all, you want to inspect the Konakart configuration file by executing the following command:

```bash
cat konakart-docker/konakart/docker-compose.yml
```

which should return the following output, where you can see that the JAVA\_OPTS variable specifies a maximum heap size of 256 MB:

```yaml
version: "3.8"
services:
  konakart:
    image: chiabre/konakart_jmx_exporter:latest
    environment:
      JAVA_OPTS: "-Xmx256M"
    deploy:
      resources:
# ...
```

To allow Akamas to apply this hardcoded heap size value (and any other required optimization parameter) at each experiment, you need to prepare a new Konakart Docker Compose file `docker-compose.yml.templ` where you can put the Akamas parameter template.

First, copy the Docker Compose file and rename it so as to keep the original file:

```bash
cd konakart-docker/konakart
cp docker-compose.yml docker-compose.yml.templ
mv docker-compose.yml docker-compose.yml.orig
```

Now, edit the `docker-compose.yml.templ` file and replace the hardcoded value for the JAVA\_OPTS variable with the Akamas parameter template:

```yaml
version: "3.8"
services:
  konakart:
    image: chiabre/konakart_jmx_exporter:latest
    environment:
      JAVA_OPTS: "${jvm.*}"
# ...
```

> aside positive
>
> Notice that instead of specifying one single parameter at a time, Akamas also allows you to put wildcards ('\*') and have all the JVM parameters replaced in place.

Therefore, the FileConfigurator operator in your workflow will expand all the JVM parameters and replace them with the actual values provided by Akamas AI-driven optimization engine.

At this point, you are ready to create your optimization study!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.akamas.io/quick-guides/quick-guides-akamas-in-a-box/aiab-03-optimize-a-java-based-application-konakart-with-lre/aiab-03-create-the-workflow.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
