# Company demo on OpenShift

Use the [company deployment decisions](company-demo.md) for the `tdp` project. Publish the images
of a release first. Then [install the demo](#install-the-demo) once, or
[update to the new release](#update-to-a-new-release). Use Bash with `oc` and Podman on the
company host, in `~/tdp`.

## Download the release

Download `testdataplus-company-demo-<version>-amd64.zip` and its SHA-256 checksum, and extract
the ZIP into `~/tdp/<version>`. The ZIP contains both loadable `.tar.gz` image archives,
their checksums, `release.json`, the guides and three manifests:

| Manifest | Use |
| --- | --- |
| `testdataplus-company-demo-setup.yaml` | Template for the Oracle settings and the generated keys. Once per installation. |
| `testdataplus-company-demo.yaml` | Deployments, Services and ingress policies with the release's image tags. Applied unchanged for every release. |
| `testdataplus-company-demo-routes.yaml` | The two edge Routes. Once, from a private copy with the certificates. |

The same files are available individually in the numbered release folder.

## Publish the images

Set `version` to the release folder name. Keep this terminal for the later steps. Podman uses your Nexus login to publish the images. OpenShift pulls them with the credentials
on the `default` service account.

```bash
version=0.3.0-r19
registry=build.equateplus.net:49096/library

(
  set -eu
  cd ~/tdp/"$version"
  for repository in tdp-suite tdp-demo-identity; do
    archive="$repository-$version-amd64.tar.gz"
    image="$registry/$repository:$version"
    sha256sum -c "$archive.sha256"
    podman load -i "$archive"
    podman tag "$repository:$version-amd64" "$image"
    podman push "$image"
  done
)
```

## Install the demo

1. Ask the DBA for the Suite user and its grants under
   [application database](database-accounts.md#application-database). Use a dedicated schema for
   the Suite. To reuse a previously initialized Suite schema, restore [its Suite key](#suite-key)
   first.

2. Create `~/tdp/oracle.env` with permissions `600` and one `NAME=value` per line. Use the
   existing PDB service. Add `ORACLE_USER=...` only for a login other than `TDP1`.

   ```text
   ORACLE_JDBC_URL=jdbc:oracle:thin:@//ORACLE_HOST:1521/PDB_SERVICE
   ORACLE_PASSWORD=the password
   ```

3. Create the Secrets, the workloads and, if they do not exist yet, the Routes. `oc create`
   refuses an existing Secret, so the generated keys are never replaced. First fill the PEM
   placeholders in a private copy of the Routes file, `~/tdp/company-demo-routes.private.yaml`.

   ```bash
   oc login https://api.cloud-tst.equateplus.net:6443
   cd ~/tdp/"$version"
   oc process --local -f testdataplus-company-demo-setup.yaml --param-file=../oracle.env |
     oc -n tdp create -f -
   oc -n tdp apply -f testdataplus-company-demo.yaml
   oc -n tdp create -f ../company-demo-routes.private.yaml
   oc -n tdp rollout status deployment/tdp-company-demo-suite --timeout=15m
   ```

4. [Verify the installation](#verify-the-installation).

The project quota must allow 8 GiB memory and 11 GiB ephemeral storage for the Suite pod.
A pod that stays `Pending` names the missing resource in `oc -n tdp describe pod`.

## Update to a new release

For the first r19 deployment, use the [empty demo procedure](#start-over-with-an-empty-company-demo).
The application tables and Liquibase history are created fresh. Keep the existing Secrets and Routes.

Publish the new release's images. Wait for active scans and loads to finish. From the new
release folder, show the change and apply it. Both Deployments restart; users sign in again.

```bash
cd ~/tdp/"$version"
oc -n tdp diff -f testdataplus-company-demo.yaml
oc -n tdp apply -f testdataplus-company-demo.yaml
oc -n tdp rollout status deployment/tdp-company-demo-suite --timeout=15m
```

To go back, apply `testdataplus-company-demo.yaml` of the previous release folder the same way. A
release that changed the Suite schema cannot go back: the previous Suite refuses the newer
schema and stays unready, without changes. Apply the new release again.

### Switch from the single template

An installation from the earlier single template needs these steps once. Add the Oracle
URL and user to its Secret, then replace the workload objects so that `oc apply` manages them.
The Secrets and Routes stay.

```bash
oc -n tdp set data secret/tdp-company-demo-oracle \
  url=jdbc:oracle:thin:@//ORACLE_HOST:1521/PDB_SERVICE user=TDP1
oc -n tdp delete deployment/tdp-company-demo-suite deployment/tdp-company-demo-identity \
  service/tdp-company-demo-suite service/tdp-company-demo-identity \
  networkpolicy/tdp-company-demo-suite-ingress networkpolicy/tdp-company-demo-identity-ingress \
  --ignore-not-found
oc -n tdp apply -f testdataplus-company-demo.yaml
oc -n tdp rollout status deployment/tdp-company-demo-suite --timeout=15m
```

The former PostgreSQL demo used other objects. List them, and delete those that exist once you
no longer need their synthetic data. Deleting the claim removes its data for good.

```bash
oc -n tdp get deployment/tdp-company-demo-postgres pvc/tdp-company-demo-postgres-data \
  service/tdp-company-demo-db configmap/tdp-company-demo-service-ca \
  configmap/tdp-company-demo-route-tls secret/tdp-company-demo-db --ignore-not-found
```

## Start over with an empty company demo

The Suite no longer installs Oracle schema-level audit triggers. An earlier partial
migration can still contain committed tables and columns. For a fresh start, first
stop all Suite writers, then clear the dedicated application schema.

This procedure permanently erases the dedicated demo owner's application data. Use it
when that data is disposable. Oracle commits each successful DDL statement. Dropping
application tables can leave schema-level triggers in place, and restarting a partially
applied Liquibase changeset can fail on a column created by the previous attempt.

1. On the company host, open the selected release folder. Confirm that the packaged
   workload manifest is available, that both release images are published, and that
   the regular Oracle Secret names the intended owner. This example uses `TDP1`.

   ```bash
   oc -n tdp apply --dry-run=client -f testdataplus-company-demo.yaml -o name
   oc -n tdp get secret tdp-company-demo-oracle -o go-template='{{index .data "user" | base64decode}}{{"\n"}}'
   ```

2. Remove the diagnostic Job and both demo Deployments. This stops sign-in briefly and
   discards any previous Deployment patches. Wait for the Suite pods to disappear before
   starting the database reset.

   ```bash
   oc -n tdp delete job/tdp-suite-clean-start deployment/tdp-company-demo-suite \
     deployment/tdp-company-demo-identity --ignore-not-found --cascade=foreground --wait=true
   oc -n tdp get pods -l app=tdp-company-demo-suite
   ```

3. Run SQL*Plus as `TDP1` on the PDB from the regular Oracle Secret. Confirm the
   session user, current schema and PDB. Run the packaged `reset-company-demo-oracle.sql` only if
   this is the dedicated demo owner and all its application data can be erased.

   ```sql
   SELECT SYS_CONTEXT('USERENV','SESSION_USER') AS login,
          SYS_CONTEXT('USERENV','CURRENT_SCHEMA') AS owner,
          SYS_CONTEXT('USERENV','CON_NAME') AS pdb FROM dual;
   @reset-company-demo-oracle.sql TDP1
   ```

   The script preserves the account, password, quota and grants. It removes the
   former TDP schema triggers, drops the owner's application tables and sequences,
   purges its recycle bin and checks that no owned objects remain. A second login
   such as `TDP_1` owns a separate schema.

4. Apply the packaged workloads and follow the first startup until `event=suite_ready`.
   Preserve the existing Routes, certificates and regular Secrets. The setup template
   generates keys and is only used at initial installation.

   ```bash
   oc -n tdp apply -f testdataplus-company-demo.yaml
   oc -n tdp logs -f deployment/tdp-company-demo-suite -c suite \
     --timestamps --pod-running-timeout=5m | tee tdp-first-start.log
   ```

   After the ready event, stop following logs with Ctrl-C and run
   `oc -n tdp rollout status deployment/tdp-company-demo-suite --timeout=15m`.

## Suite key

The setup template generates the Suite key on the first installation. Keep the exact bytes of
`tdp-company-demo-suite-key` with the Oracle backup. Restore that Secret before installing
against an existing Suite schema. A Suite with another key refuses to start.

## Oracle password

After the DBA changes the password, update the Secret and restart the Suite.

```bash
oc -n tdp set data secret/tdp-company-demo-oracle tdp.db.password='the new password'
oc -n tdp rollout restart deployment/tdp-company-demo-suite
```

## Demo passwords

Sign in as `admin` with `admin.42`. Every demo account uses `<login>.42` by default.
Set the desired `TDP_DEMO_<LOGIN>_PASSWORD` key in the `tdp-company-demo-users` Secret
to override it. Restart Java sign-in after changing an override.

An existing installation may hold passwords in that Secret. To use the defaults for all
demo logins, clear its password entries and restart sign-in.

```sh
oc -n tdp patch secret tdp-company-demo-users --type=merge --patch '{"data":null}'
oc -n tdp rollout restart deployment/tdp-company-demo-identity
oc -n tdp rollout status deployment/tdp-company-demo-identity --timeout=5m
```

## Verify the installation

Company packages built after r17 write `event=suite_version` to the Suite container
output and its `suite.log` before connecting to Oracle. The line identifies the company
release, Git revision and component versions embedded in the image.

```bash
oc -n tdp logs deployment/tdp-company-demo-suite -c suite | grep 'event=suite_version'
```

1. Open <https://tdp-bt1.cloud-tst.equateplus.net/> and sign in with the
   [demo admin password](#demo-passwords). Complete first-run setup if prompted.
2. Under **Sources**, register the Oracle source with a
   [read-only source account](database-accounts.md#source-account).
3. Under **Test databases**, register the Oracle export target with its own
   [target account](database-accounts.md#target-account). Run a small synthetic export and read
   back the rows with an Oracle client.
4. For MCP, use <https://tdp-bt1.cloud-tst.equateplus.net/mcp> and OAuth client `tdp-ai`.
   Use the callback registered for your MCP client and sign in through the company sign-in Route.

## Operate the demo

```sh
oc -n tdp get deployments,pods,svc,route -l app.kubernetes.io/part-of=tdp-company-demo
oc -n tdp logs deployment/tdp-company-demo-suite -c suite --tail=80
oc -n tdp logs deployment/tdp-company-demo-identity -c identity --tail=80
```

For a startup failure, check the Oracle URL, user and password in `tdp-company-demo-oracle`,
the schema grants and the Suite key. For a Route failure, check the `http` Service port and
the ingress peers in the deployment decisions. For a failed source confirmation, match the
Workbench request ID to `source_change_resolution_proxy` and `source_change_resolution` in the
Suite log.

Keep Oracle backups with the Suite master key, OAuth and user Secrets, and private Route
certificates. Java sign-in generates a new signing key when its pod is replaced. Users may
need to sign in again.
