Class PlanningAnalyticsEnvironment
- All Implemented Interfaces:
AutoCloseable, org.testcontainers.lifecycle.Startable
// Two servers on one Admin Server, and TM1 Web listing both
try (var env = PlanningAnalyticsEnvironment.builder()
.tm1("planning", tm1 -> tm1.withSeed(Tm1Seed.SDATA))
.tm1("reporting")
.tm1Web()
.build()) {
env.start(); // TM1 Web at env.tm1Web().getUrl(), log on with getAdminHost()
Map<String, List<String>> cubes = new LinkedHashMap<>();
env.tm1Servers().forEach((name, server) -> {
Tm1Client tm1 = Tm1Client.builder()
.baseUrl(server.getRestUrl())
.basicAuth(server.getUsername(), server.getPassword())
.build();
cubes.put(name,
tm1.cubes()
.modelCubes(ODataQuery.none().select(Cube.NAME))
.map(Cube::name)
.collectList()
.block(WAIT));
tm1.close().block(WAIT);
});
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.Builder.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.Builder.camSecurity(CognosContainer.Namespace, String...)); withPlanningAnalyticsEnvironment.Builder.keycloak(), Cognos also has an OIDC namespace. PAW then logs users on through Cognos too, in the same namespace. start()starts everything in dependency order, independent parts in parallel.Startable.close()stops 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
try (var env = PlanningAnalyticsEnvironment.builder()
.tm1("planning")
.cognos(cognos -> cognos.withUser("admin", "adminpw", "Admins").withUser("viewer", "viewerpw", "Readers"))
.build()) {
env.start();
Tm1Client viewer = Tm1Client.builder()
.baseUrl(env.tm1("planning").getRestUrl())
.authenticator(Tm1Authenticator.camNamespace("viewer", "viewerpw", CognosContainer.NAMESPACE))
.build();
try {
// The cubes the viewer's groups may see
return viewer.cubes()
.modelCubes(ODataQuery.none().select(Cube.NAME))
.map(Cube::name)
.collectList()
.block(WAIT);
}
finally {
viewer.close().block(WAIT);
}
}
Cognos takes minutes to start, and PAW longer. With PlanningAnalyticsEnvironment.Builder.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
try (var env = PlanningAnalyticsEnvironment.builder()
.tm1("planning")
.cognos(cognos -> cognos.withUser("admin", "adminpw", "Admins"))
.reuse(true)
.build()) {
env.start(); // in seconds, once a run with this configuration has started it
return env.tm1("planning").getRestUrl();
}
// close() left 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. stop()leaves 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.shared(). - 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.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionThe shared Admin Server, present with more than one TM1 server or when asked for.builder()Starts building an environment.cognos()Cognos, with the test users.fromConfig(Path path) Starts building the environment apa-environment.yamldescribes, the filepa-setupreads (docker/pa-setup), so tests run what developers run.keycloak()Keycloak, the OIDC provider.org.testcontainers.containers.Networknetwork()The Docker network every part is on.paw()PAW.voidstart()Starts every part, in dependency order: Keycloak and Cognos, the Admin Server, the TM1 servers, then TM1 Web and PAW.voidstop()Stops every part, the dependents first, and removes the network if it made it.A TM1 server by the name it was added with.The TM1 servers, by name, in the order they were added.tm1Web()TM1 Web.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.testcontainers.lifecycle.Startable
close, getDependencies
-
Method Details
-
builder
Starts building an environment.- Returns:
- a new builder
-
fromConfig
Starts building the environment apa-environment.yamldescribes, the filepa-setupreads (docker/pa-setup), so tests run what developers run. The file is checked aspa-setupchecks it, with its defaults. The builder comes back configured; change it further, or callPlanningAnalyticsEnvironment.Builder.build():// The environment pa-setup runs from the same file, with random host ports try (var env = PlanningAnalyticsEnvironment.fromConfig(Path.of("pa-environment.yaml")).build()) { env.start(); return env.tm1("planning").getRestUrl(); }How each setting maps:
tm1.servers.<name>:PlanningAnalyticsEnvironment.Builder.tm1(String, Consumer), withseedasTm1ServerContainer.withSeed(Tm1Seed)and eachcfgparameter asTM1_CFG_<name>, written aspa-setupwrites it (trueisTrue);tm1.adminServer:PlanningAnalyticsEnvironment.Builder.adminServer(); with more than one server there's one anyway, andfalsethen fails, as inpa-setup;tm1Web:PlanningAnalyticsEnvironment.Builder.tm1Web(), withheapasTM1_WEB_HEAP(1g);cognos:PlanningAnalyticsEnvironment.Builder.cognos, withusersasCognosContainer.withUser(String, String, String...)andmemoryasCOGNOS_MAX_MEMORY(6144);oidcaddsPlanningAnalyticsEnvironment.Builder.keycloak();camisPlanningAnalyticsEnvironment.Builder.camSecurity(CognosContainer.Namespace, String...), by default LDAP with the first user as administrator;paw:PlanningAnalyticsEnvironment.Builder.pawwithPawContainer.acceptLicense(), which the file must say (acceptLicense: true); the zip iszipinibm, or the newest there;ibm: each part's source, the folder asTm1Source.Bundle,Tm1WebSource.BundleandCognosSource.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.PrivateImageand the like).
A part's source is the one set on the builder, else
ibm, else whatdiscover()finds (the variables pa-setup's.envsets, such asTM1_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), everyport,adminPortandkeycloakPort(Testcontainers maps random host ports), andfiles(the host folder pa-setup keeps databases in; each test environment starts from a new database, or one copied in withTm1ServerContainer.withData(Path)). They're still checked aspa-setupchecks them.Refused, because the environment can't run them yet:
cognoswithouttm1.servers, andseed: 24retail.- Parameters:
path- the file, usuallypa-environment.yaml- Returns:
- a builder configured from the file
- Throws:
IllegalArgumentException- if the file can't be read, isn't valid, or asks for what the environment can't run; the message names the setting
-
start
public void start()Starts every part, in dependency order: Keycloak and Cognos, the Admin Server, the TM1 servers, then TM1 Web and PAW. Parts that don't depend on each other start in parallel.- Specified by:
startin interfaceorg.testcontainers.lifecycle.Startable
-
stop
public void stop()Stops every part, the dependents first, and removes the network if it made it. A reused environment is left running for the next run.- Specified by:
stopin interfaceorg.testcontainers.lifecycle.Startable
-
tm1
A TM1 server by the name it was added with.- Parameters:
name- the server's name- Returns:
- the server
- Throws:
IllegalArgumentException- if there's no such server
-
tm1Servers
The TM1 servers, by name, in the order they were added.- Returns:
- the servers
-
adminServer
The shared Admin Server, present with more than one TM1 server or when asked for.- Returns:
- the Admin Server, if there is one
-
tm1Web
TM1 Web.- Returns:
- TM1 Web
- Throws:
IllegalStateException- if it wasn't added
-
paw
-
cognos
Cognos, with the test users.- Returns:
- Cognos
- Throws:
IllegalStateException- if it wasn't added
-
keycloak
Keycloak, the OIDC provider.- Returns:
- Keycloak
- Throws:
IllegalStateException- if it wasn't added
-
network
public org.testcontainers.containers.Network network()The Docker network every part is on.- Returns:
- the network
-