PlanningAnalyticsEnvironment
using Skipcheck.Tm1.Testcontainers;A whole Planning Analytics environment for tests, wired together on one Docker network: any number of named TM1 servers, and optionally an Admin Server, TM1 Web, PAW, and Cognos (CAM) security with LDAP and OIDC test users. Two servers and TM1 Web, with a client for each server:
// Two servers on one Admin Server, and TM1 Web listing both
await using var env = PlanningAnalyticsEnvironment.Builder().Tm1("planning", tm1 => tm1.WithSeed(Tm1Seed.Sdata)).Tm1("reporting").Tm1Web().Build();
await env.StartAsync(); // TM1 Web at env.Tm1Web().Url, log on with AdminHost
var cubes = new Dictionary<string, List<string>>();
foreach (var (name, server) in env.Tm1Servers)
{
await using var tm1 = Tm1Client.Builder().BaseUrl(server.RestUrl).BasicAuth(server.Username, server.Password).Build();
cubes[name] = await tm1.Cubes.ModelCubesAsync(ODataQuery.None().Select(Cube.Fields.Name)).Select(cube => cube.Name!).ToListAsync();
}
return cubes; // planning: SData's cubes; reporting: none
Every part is optional, but TM1 Web, PAW and Cognos need at least one TM1 server. Each
part is the module's ordinary container class (Tm1ServerContainer,
Tm1AdminServerContainer, Tm1WebContainer, PawContainer,
CognosContainer, KeycloakContainer), and each builder method takes a
customizer that receives it, so every setting of those classes is available. The TM1,
Admin Server, TM1 Web, PAW and Keycloak customizers run after the environment's own
wiring, so they can also change it. The Cognos customizer runs first, because the TM1
servers are wired from its test users.
The wiring:
- TM1 servers are named (
TM1_SERVER_NAME) and reachable by that name on the network. - With more than one TM1 server, or with
PlanningAnalyticsEnvironment.EnvironmentBuilder.AdminServer, they register with oneTm1AdminServerContainer, and TM1 Web and PAW list every server from it. With one server, its own Admin Server is used. - With Cognos, every TM1 server runs in CAM security against it
(
PlanningAnalyticsEnvironment.EnvironmentBuilder.CamSecurity); withPlanningAnalyticsEnvironment.EnvironmentBuilder.Keycloak, Cognos also has an OIDC namespace. PAW then logs users on through Cognos too, in the same namespace. StartAsyncstarts everything in dependency order, independent parts in parallel.Closestops it all.
Where IBM's software comes from is found from the environment, as for each container
(Tm1Source.Discover and the like), unless set on the builder.
With Cognos, each test user logs in to every server as themselves:
// Every server in CAM security, with Cognos's test users as its users
await using var env = PlanningAnalyticsEnvironment
.Builder()
.Tm1("planning")
.Cognos(cognos => cognos.WithUser("admin", "adminpw", "Admins").WithUser("viewer", "viewerpw", "Readers"))
.Build();
await env.StartAsync();
await using var viewer = Tm1Client
.Builder()
.BaseUrl(env.Tm1("planning").RestUrl)
.Authenticator(Tm1Authenticator.CamNamespace("viewer", "viewerpw", CognosContainer.NamespaceId))
.Build();
// The cubes the viewer's groups may see
return await viewer.Cubes.ModelCubesAsync(ODataQuery.None().Select(Cube.Fields.Name)).Select(cube => cube.Name!).ToListAsync();
Cognos takes minutes to start, and PAW longer. With PlanningAnalyticsEnvironment.EnvironmentBuilder.Reuse, the
environment keeps its containers running between test runs, so the next run starts in
seconds:
// Cognos and the server keep running after the run, for the next one, when
// testcontainers.reuse.enable=true is set too
await using var env = PlanningAnalyticsEnvironment
.Builder()
.Tm1("planning")
.Cognos(cognos => cognos.WithUser("admin", "adminpw", "Admins"))
.Reuse(true)
.Build();
await env.StartAsync(); // in seconds, once a run with this configuration has started it
return env.Tm1("planning").RestUrl;
// disposing leaves it running
Reuse also needs your own switch, as for any Testcontainers container:
testcontainers.reuse.enable=true in ~/.testcontainers.properties, or
TESTCONTAINERS_REUSE_ENABLE=true. Without it, Reuse has no effect. With
both:
- The containers and the network are named after the environment's configuration (its
identity, a hash): the label
io.skipcheck.tm1.environmenton each container, and the networktm1-environment-<identity>. A run with the same configuration finds them; a different configuration gets its own, and never another's. StopAsyncleaves them running, PAW too. Testcontainers doesn't remove reusable containers at the end of a run either.- What tests leave behind stays: objects they created in TM1, sessions, content saved
in Cognos. Tests should create uniquely named objects and delete them, as with
Tm1ServerContainer.SharedAsync. - A configuration you no longer use keeps its containers running, and Cognos holds
about 8 GB. To start clean, remove them all:
docker rm -f $(docker ps -aq --filter label=io.skipcheck.tm1.environment), thendocker network rm $(docker network ls -q --filter label=io.skipcheck.tm1.environment). - The identity covers each part's image, source, environment variables, command, network aliases, labels, exposed ports and copied files, the Cognos users and the CAM settings. A change to anything else about a container, such as how it's created, isn't seen: remove the containers after making one.
- PAW isn't a Testcontainers container: IBM's compose files give it fixed names, so there's one per Docker host whatever the identity. Each start runs IBM's compose again, which takes about a minute.
Members
Builder static | A builder for an environment. |
FromConfig static | Starts building the environment a pa-environment.yaml describes, the file pa-setup reads (docker/pa-setup), so tests run what developers run. |
StartAsync | Starts everything, what's depended on first, then PAW. |
StopAsync | Stops everything, last started first, and removes the network it made. |
DisposeAsync | Stops it. |
IsRunning property | Whether every part is running. |
Tm1 | The TM1 server named name. |
Tm1Servers property | The TM1 servers by name, in the order added. |
AdminServer property | The shared Admin Server, or null when the one TM1 server uses its own. |
Tm1Web | TM1 Web. |
Paw | PAW. |
Cognos | Cognos. |
Keycloak | Keycloak. |
Network property | The network everything is on. |
Builder
staticEnvironmentBuilder Builder()A builder for an environment.
FromConfig
staticEnvironmentBuilder FromConfig(string path)Starts building the environment a pa-environment.yaml describes, the file pa-setup reads
(docker/pa-setup), so tests run what developers run. The file is checked as pa-setup checks it, with its
defaults. The builder comes back configured; change it further, or call EnvironmentBuilder.Build.
How each setting maps:
tm1.servers.<name>: EnvironmentBuilder.Tm1, with seed as
Tm1ServerContainer.WithSeed and each cfg parameter as TM1_CFG_<name>, written as pa-setup
writes it (true is True);
tm1.adminServer: EnvironmentBuilder.AdminServer; with more than one server there's one anyway, and
false then fails, as in pa-setup;
tm1Web: EnvironmentBuilder.Tm1Web, with heap as TM1_WEB_HEAP (1g);
cognos: EnvironmentBuilder.Cognos, with users as CognosContainer.WithUser and
memory as COGNOS_MAX_MEMORY (6144); oidc adds EnvironmentBuilder.Keycloak; cam is
EnvironmentBuilder.CamSecurity, by default LDAP with the first user as administrator;
paw: EnvironmentBuilder.Paw with PawContainer.AcceptLicense, which the file must say
(acceptLicense: true); the zip is zip in ibm, or the newest there;
ibm: each part's source, the folder as Tm1Source.Bundle,
Tm1WebSource.Bundle and CognosSource.Zip. A relative path is from the
file's folder; ~ is the user's home;
images: the image each part runs, as a container's image argument. A part with no other source takes its image as
the private image with IBM's software built in (Tm1Source.PrivateImage and the like).
A part's source is the one set on the builder, else ibm, else what Discover() finds (the variables
pa-setup's .env sets, such as TM1_BUNDLE_URL), else its image as a private image.
Ignored, because they place things on the host that Testcontainers manages itself: name (the compose project; the
environment has its own network), every port, adminPort and keycloakPort (Testcontainers maps random host
ports), and files (the host folder pa-setup keeps databases in; each test environment starts from a new database, or one
copied in with Tm1ServerContainer.WithData). They're still checked as pa-setup checks them.
Refused, because the environment can't run them yet: cognos without tm1.servers, and
seed: 24retail.
// The environment pa-setup runs from the same file, with random host ports
await using var env = PlanningAnalyticsEnvironment.FromConfig("pa-environment.yaml").Build();
await env.StartAsync();
return env.Tm1("planning").RestUrl;Parameters
path- The file, usually
pa-environment.yaml.
Returns
- A builder configured from the file.
Throws
ArgumentException- The file can't be read, isn't valid, or asks for what the environment can't run; the message names the setting.
StartAsync
Task StartAsync(CancellationToken cancellationToken = default)Starts everything, what's depended on first, then PAW.
StopAsync
Task StopAsync(CancellationToken cancellationToken = default)Stops everything, last started first, and removes the network it made. A reused environment
(EnvironmentBuilder.Reuse) is left running for the next run.
DisposeAsync
ValueTask DisposeAsync()Stops it.
IsRunning
propertybool IsRunningWhether every part is running.
Tm1
Tm1ServerContainer Tm1(string name)The TM1 server named name.
Throws
ArgumentException- There's none.
Tm1Servers
propertyIReadOnlyDictionary<string, Tm1ServerContainer> Tm1ServersThe TM1 servers by name, in the order added.
AdminServer
propertyTm1AdminServerContainer? AdminServerThe shared Admin Server, or null when the one TM1 server uses its own.
Tm1Web
Tm1WebContainer Tm1Web()TM1 Web.
Throws
InvalidOperationException- It wasn't added.
Paw
PawContainer Paw()PAW.
Throws
InvalidOperationException- It wasn't added.
Cognos
CognosContainer Cognos()Cognos.
Throws
InvalidOperationException- It wasn't added.
Keycloak
KeycloakContainer Keycloak()Keycloak.
Throws
InvalidOperationException- It wasn't added.
Network
propertyNetwork NetworkThe network everything is on.