skipcheck-tm1-testcontainers 0.1.0.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- skipcheck_tm1_testcontainers/__init__.py +41 -0
- skipcheck_tm1_testcontainers/_container.py +392 -0
- skipcheck_tm1_testcontainers/cognos.py +250 -0
- skipcheck_tm1_testcontainers/environment.py +302 -0
- skipcheck_tm1_testcontainers/paw-local.sh +275 -0
- skipcheck_tm1_testcontainers/paw.py +399 -0
- skipcheck_tm1_testcontainers/plugin.py +151 -0
- skipcheck_tm1_testcontainers/requires.py +53 -0
- skipcheck_tm1_testcontainers/sources.py +500 -0
- skipcheck_tm1_testcontainers/tm1.py +379 -0
- skipcheck_tm1_testcontainers/web.py +179 -0
- skipcheck_tm1_testcontainers-0.1.0.dev0.dist-info/METADATA +123 -0
- skipcheck_tm1_testcontainers-0.1.0.dev0.dist-info/RECORD +15 -0
- skipcheck_tm1_testcontainers-0.1.0.dev0.dist-info/WHEEL +4 -0
- skipcheck_tm1_testcontainers-0.1.0.dev0.dist-info/entry_points.txt +2 -0
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
"""Several Planning Analytics parts wired together: Java's ``PlanningAnalyticsEnvironment``."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from collections.abc import Callable
|
|
7
|
+
from typing import Any, TypeVar
|
|
8
|
+
|
|
9
|
+
from typing_extensions import Self
|
|
10
|
+
|
|
11
|
+
from ._container import Network
|
|
12
|
+
from .cognos import NO_SOURCE_MESSAGE as NO_COGNOS_MESSAGE
|
|
13
|
+
from .cognos import CognosContainer, KeycloakContainer, Namespace
|
|
14
|
+
from .paw import NO_SOURCE_MESSAGE as NO_PAW_MESSAGE
|
|
15
|
+
from .paw import PawContainer
|
|
16
|
+
from .sources import CognosSource, PawSource, Tm1Source, Tm1WebSource
|
|
17
|
+
from .tm1 import NO_SOURCE_MESSAGE as NO_TM1_MESSAGE
|
|
18
|
+
from .tm1 import Tm1AdminServerContainer, Tm1ServerContainer
|
|
19
|
+
from .web import NO_SOURCE_MESSAGE as NO_TM1_WEB_MESSAGE
|
|
20
|
+
from .web import Tm1WebContainer
|
|
21
|
+
|
|
22
|
+
__all__ = ["PlanningAnalyticsEnvironment"]
|
|
23
|
+
|
|
24
|
+
T = TypeVar("T")
|
|
25
|
+
Part = KeycloakContainer | CognosContainer | Tm1AdminServerContainer | Tm1ServerContainer | Tm1WebContainer | PawContainer
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _nothing(_: Any) -> None:
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class PlanningAnalyticsEnvironment:
|
|
33
|
+
"""TM1 servers, and optionally a shared Admin Server, TM1 Web, PAW, Cognos (CAM security) and
|
|
34
|
+
Keycloak (OIDC), on one network and wired to each other. Build one with :meth:`builder`."""
|
|
35
|
+
|
|
36
|
+
def __init__(self, b: PlanningAnalyticsEnvironment.Builder, network: Any) -> None:
|
|
37
|
+
self._network = network
|
|
38
|
+
self._owns_network = b._network is None
|
|
39
|
+
self._keycloak = KeycloakContainer().with_network(network) if b._keycloak is not None else None
|
|
40
|
+
cognos: CognosContainer | None = None
|
|
41
|
+
if b._cognos is not None:
|
|
42
|
+
cognos = CognosContainer(b._get(b._cognos_source, CognosSource.discover, NO_COGNOS_MESSAGE)).with_network(network)
|
|
43
|
+
if self._keycloak is not None:
|
|
44
|
+
cognos.with_keycloak(self._keycloak)
|
|
45
|
+
# First: the TM1 servers' CAM security is wired from the test users
|
|
46
|
+
b._cognos(cognos)
|
|
47
|
+
self._cognos = cognos
|
|
48
|
+
tm1_source = b._get(b._tm1_source, Tm1Source.discover, NO_TM1_MESSAGE)
|
|
49
|
+
self._admin_server = Tm1AdminServerContainer(tm1_source).with_network(network) if b._admin_server is not None or len(b._tm1) > 1 else None
|
|
50
|
+
servers: dict[str, Tm1ServerContainer] = {}
|
|
51
|
+
for name in b._tm1:
|
|
52
|
+
server = Tm1ServerContainer(tm1_source).with_network(network).with_network_aliases(name).with_env("TM1_SERVER_NAME", name)
|
|
53
|
+
if self._admin_server is not None:
|
|
54
|
+
server.with_admin_server(self._admin_server)
|
|
55
|
+
if cognos is not None:
|
|
56
|
+
server.with_cam_security(cognos, b._cam_namespace, *b._cam_admins_for(cognos))
|
|
57
|
+
servers[name] = server
|
|
58
|
+
self._tm1_servers = servers
|
|
59
|
+
first = next(iter(servers.values()))
|
|
60
|
+
web: Tm1WebContainer | None = None
|
|
61
|
+
if b._tm1_web is not None:
|
|
62
|
+
web = Tm1WebContainer(b._get(b._tm1_web_source, Tm1WebSource.discover, NO_TM1_WEB_MESSAGE)).with_tm1_server(first)
|
|
63
|
+
if self._admin_server is not None:
|
|
64
|
+
web.with_admin_server(self._admin_server)
|
|
65
|
+
# List every server: start them all before TM1 Web
|
|
66
|
+
web.depends_on(*servers.values())
|
|
67
|
+
self._tm1_web = web
|
|
68
|
+
paw: PawContainer | None = None
|
|
69
|
+
if b._paw is not None:
|
|
70
|
+
paw = PawContainer(b._get(b._paw_source, PawSource.discover, NO_PAW_MESSAGE)).with_tm1_server(first)
|
|
71
|
+
if self._admin_server is not None:
|
|
72
|
+
paw.with_admin_server(self._admin_server)
|
|
73
|
+
self._paw = paw
|
|
74
|
+
# The callers' own settings last, so they can change anything set above
|
|
75
|
+
_apply(b._admin_server, self._admin_server)
|
|
76
|
+
for name, customizer in b._tm1.items():
|
|
77
|
+
customizer(servers[name])
|
|
78
|
+
_apply(b._tm1_web, self._tm1_web)
|
|
79
|
+
_apply(b._paw, self._paw)
|
|
80
|
+
_apply(b._keycloak, self._keycloak)
|
|
81
|
+
|
|
82
|
+
@staticmethod
|
|
83
|
+
def builder() -> PlanningAnalyticsEnvironment.Builder:
|
|
84
|
+
"""Starts building an environment."""
|
|
85
|
+
return PlanningAnalyticsEnvironment.Builder()
|
|
86
|
+
|
|
87
|
+
def start(self) -> None:
|
|
88
|
+
"""Starts every part, each after what it depends on; PAW last."""
|
|
89
|
+
for part in self.containers():
|
|
90
|
+
if part is not self._paw and not part.is_running:
|
|
91
|
+
part.start()
|
|
92
|
+
if self._paw is not None:
|
|
93
|
+
self._paw.start()
|
|
94
|
+
|
|
95
|
+
def stop(self) -> None:
|
|
96
|
+
"""Stops every part, the dependents first, and removes the network if it made it."""
|
|
97
|
+
for part in reversed(self.containers()):
|
|
98
|
+
part.stop()
|
|
99
|
+
if self._owns_network and isinstance(self._network, Network):
|
|
100
|
+
self._network.close()
|
|
101
|
+
|
|
102
|
+
def close(self) -> None:
|
|
103
|
+
"""The same as :meth:`stop`."""
|
|
104
|
+
self.stop()
|
|
105
|
+
|
|
106
|
+
def __enter__(self) -> Self:
|
|
107
|
+
self.start()
|
|
108
|
+
return self
|
|
109
|
+
|
|
110
|
+
def __exit__(self, *exc: Any) -> None:
|
|
111
|
+
self.stop()
|
|
112
|
+
|
|
113
|
+
def tm1(self, name: str) -> Tm1ServerContainer:
|
|
114
|
+
"""A TM1 server by the name it was added with. A ValueError if there's no such server."""
|
|
115
|
+
server = self._tm1_servers.get(name)
|
|
116
|
+
if server is None:
|
|
117
|
+
raise ValueError(f"No TM1 server {name}; there's {list(self._tm1_servers)}")
|
|
118
|
+
return server
|
|
119
|
+
|
|
120
|
+
def tm1_servers(self) -> dict[str, Tm1ServerContainer]:
|
|
121
|
+
"""The TM1 servers, by name, in the order they were added."""
|
|
122
|
+
return dict(self._tm1_servers)
|
|
123
|
+
|
|
124
|
+
def admin_server(self) -> Tm1AdminServerContainer | None:
|
|
125
|
+
"""The shared Admin Server, present with more than one TM1 server or when asked for; None
|
|
126
|
+
otherwise."""
|
|
127
|
+
return self._admin_server
|
|
128
|
+
|
|
129
|
+
def tm1_web(self) -> Tm1WebContainer:
|
|
130
|
+
"""TM1 Web. A RuntimeError if it wasn't added."""
|
|
131
|
+
return _require(self._tm1_web, "TM1 Web", "tm1_web()")
|
|
132
|
+
|
|
133
|
+
def paw(self) -> PawContainer:
|
|
134
|
+
"""PAW. A RuntimeError if it wasn't added."""
|
|
135
|
+
return _require(self._paw, "PAW", "paw(...)")
|
|
136
|
+
|
|
137
|
+
def cognos(self) -> CognosContainer:
|
|
138
|
+
"""Cognos, with the test users. A RuntimeError if it wasn't added."""
|
|
139
|
+
return _require(self._cognos, "Cognos", "cognos(...)")
|
|
140
|
+
|
|
141
|
+
def keycloak(self) -> KeycloakContainer:
|
|
142
|
+
"""Keycloak, the OIDC provider. A RuntimeError if it wasn't added."""
|
|
143
|
+
return _require(self._keycloak, "Keycloak", "keycloak()")
|
|
144
|
+
|
|
145
|
+
def network(self) -> Any:
|
|
146
|
+
"""The Docker network every part is on."""
|
|
147
|
+
return self._network
|
|
148
|
+
|
|
149
|
+
def containers(self) -> list[Part]:
|
|
150
|
+
"""Every part, in start order."""
|
|
151
|
+
parts: list[Part] = []
|
|
152
|
+
if self._keycloak is not None:
|
|
153
|
+
parts.append(self._keycloak)
|
|
154
|
+
if self._cognos is not None:
|
|
155
|
+
parts.append(self._cognos)
|
|
156
|
+
if self._admin_server is not None:
|
|
157
|
+
parts.append(self._admin_server)
|
|
158
|
+
parts.extend(self._tm1_servers.values())
|
|
159
|
+
if self._tm1_web is not None:
|
|
160
|
+
parts.append(self._tm1_web)
|
|
161
|
+
if self._paw is not None:
|
|
162
|
+
parts.append(self._paw)
|
|
163
|
+
return parts
|
|
164
|
+
|
|
165
|
+
class Builder:
|
|
166
|
+
"""Builds a :class:`PlanningAnalyticsEnvironment`. Every part is optional."""
|
|
167
|
+
|
|
168
|
+
def __init__(self) -> None:
|
|
169
|
+
self._tm1: dict[str, Callable[[Tm1ServerContainer], Any]] = {}
|
|
170
|
+
self._admin_server: Callable[[Tm1AdminServerContainer], Any] | None = None
|
|
171
|
+
self._tm1_web: Callable[[Tm1WebContainer], Any] | None = None
|
|
172
|
+
self._paw: Callable[[PawContainer], Any] | None = None
|
|
173
|
+
self._cognos: Callable[[CognosContainer], Any] | None = None
|
|
174
|
+
self._keycloak: Callable[[KeycloakContainer], Any] | None = None
|
|
175
|
+
self._cam_namespace = Namespace.LDAP
|
|
176
|
+
self._cam_admins: list[str] = []
|
|
177
|
+
self._tm1_source: Tm1Source | None = None
|
|
178
|
+
self._tm1_web_source: Tm1WebSource | None = None
|
|
179
|
+
self._paw_source: PawSource | None = None
|
|
180
|
+
self._cognos_source: CognosSource | None = None
|
|
181
|
+
self._network: Any = None
|
|
182
|
+
|
|
183
|
+
def tm1(self, name: str, customizer: Callable[[Tm1ServerContainer], Any] = _nothing) -> Self:
|
|
184
|
+
"""A TM1 server, its network alias and server name ``name``."""
|
|
185
|
+
if name is None or not re.fullmatch(r"[A-Za-z0-9_-]+", name):
|
|
186
|
+
raise ValueError(f"Bad TM1 server name '{name}': use letters, digits, _ and -")
|
|
187
|
+
if name in self._tm1:
|
|
188
|
+
raise ValueError(f"TM1 server {name} was already added")
|
|
189
|
+
self._tm1[name] = _required(customizer)
|
|
190
|
+
return self
|
|
191
|
+
|
|
192
|
+
def admin_server(self, customizer: Callable[[Tm1AdminServerContainer], Any] = _nothing) -> Self:
|
|
193
|
+
"""A shared Admin Server even for one TM1 server (several always share one)."""
|
|
194
|
+
self._admin_server = _required(customizer)
|
|
195
|
+
return self
|
|
196
|
+
|
|
197
|
+
def tm1_web(self, customizer: Callable[[Tm1WebContainer], Any] = _nothing) -> Self:
|
|
198
|
+
"""Adds TM1 Web, listing every TM1 server. ``customizer`` configures the container."""
|
|
199
|
+
self._tm1_web = _required(customizer)
|
|
200
|
+
return self
|
|
201
|
+
|
|
202
|
+
def paw(self, customizer: Callable[[PawContainer], Any]) -> Self:
|
|
203
|
+
"""Adds PAW, logging users on to the first TM1 server and listing every one. IBM's
|
|
204
|
+
license must be accepted (:meth:`PawContainer.accept_license` in the customizer, or
|
|
205
|
+
``PAW_ACCEPT_LICENSE=true``). Not available with Cognos yet: PAW logs users on with
|
|
206
|
+
TM1's own security."""
|
|
207
|
+
self._paw = _required(customizer)
|
|
208
|
+
return self
|
|
209
|
+
|
|
210
|
+
def cognos(self, customizer: Callable[[CognosContainer], Any]) -> Self:
|
|
211
|
+
"""Cognos, and every TM1 server in CAM security against it; add its test users here."""
|
|
212
|
+
self._cognos = _required(customizer)
|
|
213
|
+
return self
|
|
214
|
+
|
|
215
|
+
def keycloak(self, customizer: Callable[[KeycloakContainer], Any] = _nothing) -> Self:
|
|
216
|
+
"""Adds Keycloak, giving Cognos an OIDC namespace with the same test users. Needs
|
|
217
|
+
:meth:`cognos`."""
|
|
218
|
+
self._keycloak = _required(customizer)
|
|
219
|
+
return self
|
|
220
|
+
|
|
221
|
+
def cam_security(self, namespace: Namespace, *admins: str) -> Self:
|
|
222
|
+
"""The namespace TM1 authenticates against, and its administrators (default: the
|
|
223
|
+
first test user)."""
|
|
224
|
+
if namespace is None:
|
|
225
|
+
raise ValueError("namespace must not be None")
|
|
226
|
+
self._cam_namespace = namespace
|
|
227
|
+
self._cam_admins = list(admins)
|
|
228
|
+
return self
|
|
229
|
+
|
|
230
|
+
def tm1_source(self, source: Tm1Source) -> Self:
|
|
231
|
+
"""Where TM1 comes from; :meth:`Tm1Source.discover` by default."""
|
|
232
|
+
self._tm1_source = _required(source)
|
|
233
|
+
return self
|
|
234
|
+
|
|
235
|
+
def tm1_web_source(self, source: Tm1WebSource) -> Self:
|
|
236
|
+
"""Where TM1 Web comes from; :meth:`Tm1WebSource.discover` by default."""
|
|
237
|
+
self._tm1_web_source = _required(source)
|
|
238
|
+
return self
|
|
239
|
+
|
|
240
|
+
def paw_source(self, source: PawSource) -> Self:
|
|
241
|
+
"""Where PAW comes from; :meth:`PawSource.discover` by default."""
|
|
242
|
+
self._paw_source = _required(source)
|
|
243
|
+
return self
|
|
244
|
+
|
|
245
|
+
def cognos_source(self, source: CognosSource) -> Self:
|
|
246
|
+
"""Where Cognos comes from; :meth:`CognosSource.discover` by default."""
|
|
247
|
+
self._cognos_source = _required(source)
|
|
248
|
+
return self
|
|
249
|
+
|
|
250
|
+
def network(self, network: Any) -> Self:
|
|
251
|
+
"""The Docker network to put everything on; a new one, removed by
|
|
252
|
+
:meth:`PlanningAnalyticsEnvironment.close`, by default."""
|
|
253
|
+
self._network = _required(network)
|
|
254
|
+
return self
|
|
255
|
+
|
|
256
|
+
def build(self) -> PlanningAnalyticsEnvironment:
|
|
257
|
+
"""Creates the containers and wires them together. Nothing starts until
|
|
258
|
+
:meth:`PlanningAnalyticsEnvironment.start`. A RuntimeError if a part needs one that's
|
|
259
|
+
missing, or a source can't be found."""
|
|
260
|
+
if not self._tm1:
|
|
261
|
+
raise RuntimeError("Add at least one TM1 server with tm1(name)")
|
|
262
|
+
if self._keycloak is not None and self._cognos is None:
|
|
263
|
+
raise RuntimeError("Keycloak gives Cognos its OIDC namespace: add cognos(...) too")
|
|
264
|
+
if self._cam_namespace is Namespace.OIDC and self._keycloak is None:
|
|
265
|
+
raise RuntimeError("CAM security through OIDC needs keycloak()")
|
|
266
|
+
if self._paw is not None and self._cognos is not None:
|
|
267
|
+
raise RuntimeError("PAW with Cognos (CAM) security isn't supported yet: PAW logs users on with TM1's own security")
|
|
268
|
+
return PlanningAnalyticsEnvironment(self, self._network if self._network is not None else Network.new_network())
|
|
269
|
+
|
|
270
|
+
def _cam_admins_for(self, cognos: CognosContainer) -> list[str]:
|
|
271
|
+
if self._cam_admins:
|
|
272
|
+
return list(self._cam_admins)
|
|
273
|
+
users = cognos.users
|
|
274
|
+
if not users:
|
|
275
|
+
raise RuntimeError("Cognos needs test users for CAM security: add them with with_user")
|
|
276
|
+
return [users[0].name]
|
|
277
|
+
|
|
278
|
+
@staticmethod
|
|
279
|
+
def _get(configured: T | None, discover: Callable[[], T | None], message: str) -> T:
|
|
280
|
+
if configured is not None:
|
|
281
|
+
return configured
|
|
282
|
+
found = discover()
|
|
283
|
+
if found is None:
|
|
284
|
+
raise RuntimeError(message)
|
|
285
|
+
return found
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def _required(value: T) -> T:
|
|
289
|
+
if value is None:
|
|
290
|
+
raise ValueError("must not be None")
|
|
291
|
+
return value
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def _apply(customizer: Callable[[T], Any] | None, part: T | None) -> None:
|
|
295
|
+
if customizer is not None and part is not None:
|
|
296
|
+
customizer(part)
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def _require(part: T | None, what: str, how: str) -> T:
|
|
300
|
+
if part is None:
|
|
301
|
+
raise RuntimeError(f"This environment has no {what}; add it with {how}")
|
|
302
|
+
return part
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# paw-local.sh: run IBM Planning Analytics Workspace (PAW) Local next to tm1-server.
|
|
3
|
+
#
|
|
4
|
+
# IBM ships PAW Local as Docker images plus compose files and scripts, in
|
|
5
|
+
# ipa_workspace_local_<release>.<build>.zip. This script uses those as they are:
|
|
6
|
+
# it unpacks the zip, loads IBM's images, writes PAW's configuration and runs
|
|
7
|
+
# IBM's own scripts/paw.sh. No IBM software is in this repository.
|
|
8
|
+
#
|
|
9
|
+
# Usage: ./paw-local.sh [up|down|reset|status|logs [service...]|help]
|
|
10
|
+
#
|
|
11
|
+
# up Unpack the zip and load its images (first time only), write the
|
|
12
|
+
# config, start PAW and wait until it answers. The default.
|
|
13
|
+
# down Stop and remove the PAW containers. PAW's data is kept.
|
|
14
|
+
# reset Like down, and also delete PAW's data (its Docker volumes).
|
|
15
|
+
# status List the PAW containers.
|
|
16
|
+
# logs Show recent logs of all or the named PAW services.
|
|
17
|
+
#
|
|
18
|
+
# Settings (environment variables; all optional except PAW_ACCEPT_LICENSE):
|
|
19
|
+
# PAW_ACCEPT_LICENSE=true You accept IBM's license for PAW (the text is in
|
|
20
|
+
# the zip, licenses/LA_en). Required by "up".
|
|
21
|
+
# PAW_ZIP The PAW Local zip. Default: the newest
|
|
22
|
+
# ipa_workspace_local_*.zip in PAW_BUNDLE_DIR.
|
|
23
|
+
# PAW_BUNDLE_DIR Where to look for the zip. Default: ./bundles
|
|
24
|
+
# PAW_HOME Where the zip is unpacked. Default: ~/.cache/tm1-paw
|
|
25
|
+
# PAW_NETWORK Docker network PAW joins. Default: the network of a
|
|
26
|
+
# running tm1-admin container, else paw_default.
|
|
27
|
+
# PAW_TM1_ADMIN_URL TM1 Admin Server, as PAW sees it.
|
|
28
|
+
# Default: http://tm1-admin:5895
|
|
29
|
+
# PAW_AUTH_MODE tm1 (log on to a TM1 server) or cam (Cognos).
|
|
30
|
+
# Default: tm1
|
|
31
|
+
# PAW_TM1_LOGIN_URL The TM1 server PAW logs users on to (tm1 mode).
|
|
32
|
+
# Default: http://tm1:8010
|
|
33
|
+
# PAW_CAM_SERVLET Cognos dispatcher (cam mode), e.g.
|
|
34
|
+
# http://cognos:9300/p2pd/servlet/dispatch
|
|
35
|
+
# PAW_CAM_GATEWAY Cognos gateway URL (cam mode, optional).
|
|
36
|
+
# PAW_CAM_NAMESPACE Cognos namespace ID (cam mode).
|
|
37
|
+
# PAW_TM1WEB_URL TM1 Web, as PAW sees it, e.g. http://tm1-web:9510
|
|
38
|
+
# PAW_HTTP_PORT Host port for PAW. Default: 8800
|
|
39
|
+
# PAW_HTTPS_PORT Host port for PAW over https. Default: 8843
|
|
40
|
+
# PAW_JVM_ARGS JVM options of prism-platform, the largest service.
|
|
41
|
+
# Default: IBM's (-Xmx4096m -Xms4096m)
|
|
42
|
+
# PAW_WAIT Seconds "up" waits for PAW; 0 to not wait. Default: 600
|
|
43
|
+
set -euo pipefail
|
|
44
|
+
|
|
45
|
+
die() { printf 'paw-local: %s\n' "$*" >&2; exit 1; }
|
|
46
|
+
info() { printf 'paw-local: %s\n' "$*"; }
|
|
47
|
+
|
|
48
|
+
usage() {
|
|
49
|
+
sed -n '2,/^set -euo/p' "$0" | sed '$d' | sed 's/^# \{0,1\}//'
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
PAW_BUNDLE_DIR=${PAW_BUNDLE_DIR:-./bundles}
|
|
53
|
+
PAW_HOME=${PAW_HOME:-$HOME/.cache/tm1-paw}
|
|
54
|
+
PAW_HTTP_PORT=${PAW_HTTP_PORT:-8800}
|
|
55
|
+
PAW_HTTPS_PORT=${PAW_HTTPS_PORT:-8843}
|
|
56
|
+
PAW_WAIT=${PAW_WAIT:-600}
|
|
57
|
+
|
|
58
|
+
# The zip to use: PAW_ZIP, or the newest one in PAW_BUNDLE_DIR.
|
|
59
|
+
find_zip() {
|
|
60
|
+
if [ -n "${PAW_ZIP:-}" ]; then
|
|
61
|
+
[ -f "$PAW_ZIP" ] || die "PAW_ZIP is not a file: $PAW_ZIP"
|
|
62
|
+
printf '%s\n' "$PAW_ZIP"
|
|
63
|
+
return
|
|
64
|
+
fi
|
|
65
|
+
local newest
|
|
66
|
+
# shellcheck disable=SC2012 # IBM's fixed file names: no newlines
|
|
67
|
+
newest=$(ls -t "$PAW_BUNDLE_DIR"/ipa_workspace_local_*.zip 2>/dev/null | head -n 1 || true)
|
|
68
|
+
[ -n "$newest" ] || die "no PAW Local zip: set PAW_ZIP, or put ipa_workspace_local_*.zip in $PAW_BUNDLE_DIR"
|
|
69
|
+
printf '%s\n' "$newest"
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
# "<release>.<build>" from the zip's config/version.env, without unpacking it.
|
|
73
|
+
zip_version() {
|
|
74
|
+
local env release build
|
|
75
|
+
env=$(unzip -p "$1" config/version.env 2>/dev/null) || die "not a PAW Local zip (no config/version.env): $1"
|
|
76
|
+
release=$(printf '%s\n' "$env" | sed -n 's/^export PAW_RELEASE=\([0-9.]*\).*/\1/p')
|
|
77
|
+
build=$(printf '%s\n' "$env" | sed -n 's/^export PAW_BUILD=\([0-9]*\).*/\1/p')
|
|
78
|
+
[ -n "$release" ] && [ -n "$build" ] || die "can't read PAW_RELEASE and PAW_BUILD from $1"
|
|
79
|
+
printf '%s.%s\n' "$release" "$build"
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
# The unpacked PAW for down, reset, status and logs: the zip's, or the newest one.
|
|
83
|
+
find_paw_dir() {
|
|
84
|
+
if [ -n "${PAW_ZIP:-}" ] || ls "$PAW_BUNDLE_DIR"/ipa_workspace_local_*.zip >/dev/null 2>&1; then
|
|
85
|
+
printf '%s/%s\n' "$PAW_HOME" "$(zip_version "$(find_zip)")"
|
|
86
|
+
return
|
|
87
|
+
fi
|
|
88
|
+
local newest
|
|
89
|
+
# shellcheck disable=SC2012 # our own version-named folders
|
|
90
|
+
newest=$(ls -td "$PAW_HOME"/*/ 2>/dev/null | head -n 1 || true)
|
|
91
|
+
[ -n "$newest" ] || die "PAW hasn't been set up yet: run ./paw-local.sh up"
|
|
92
|
+
printf '%s\n' "${newest%/}"
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
require_license() {
|
|
96
|
+
[ "${PAW_ACCEPT_LICENSE:-}" = true ] && return
|
|
97
|
+
die "set PAW_ACCEPT_LICENSE=true to accept IBM's license for Planning Analytics Workspace.
|
|
98
|
+
Read it first: unzip -p '$1' licenses/LA_en | less
|
|
99
|
+
(This script skips IBM's admin tool, where the license is normally accepted.)"
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
# Unpack everything but the images into PAW_HOME/<version>, once.
|
|
103
|
+
unpack() {
|
|
104
|
+
local zip=$1 dir=$2 tmp
|
|
105
|
+
[ -f "$dir/.unpacked" ] && return
|
|
106
|
+
info "unpacking $(basename "$zip") into $dir"
|
|
107
|
+
mkdir -p "$PAW_HOME"
|
|
108
|
+
tmp=$(mktemp -d "$PAW_HOME/.unpack.XXXXXX")
|
|
109
|
+
unzip -q "$zip" -x 'images/images.tar' -d "$tmp"
|
|
110
|
+
[ -f "$tmp/scripts/paw.sh" ] || { rm -rf "$tmp"; die "not a PAW Local zip (no scripts/paw.sh): $zip"; }
|
|
111
|
+
rm -rf "$dir"
|
|
112
|
+
mv "$tmp" "$dir"
|
|
113
|
+
touch "$dir/.unpacked"
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
# IBM's paw.sh calls software/docker-compose, a Linux x86-64 binary. Point it at
|
|
117
|
+
# "docker compose" instead, which works on macOS and Windows too.
|
|
118
|
+
shim_compose() {
|
|
119
|
+
local bin="$1/software/docker-compose"
|
|
120
|
+
docker compose version >/dev/null 2>&1 || return 0
|
|
121
|
+
grep -q 'paw-local shim' "$bin" 2>/dev/null && return
|
|
122
|
+
if [ -f "$bin" ]; then mv "$bin" "$bin.ibm"; fi
|
|
123
|
+
printf '#!/bin/sh\n# paw-local shim: IBM ships a Linux-only binary here\nexec docker compose "$@"\n' >"$bin"
|
|
124
|
+
chmod +x "$bin"
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
# The images listed in images.env, as tags.
|
|
128
|
+
image_tags() {
|
|
129
|
+
(
|
|
130
|
+
# shellcheck disable=SC2034 # read by images.env
|
|
131
|
+
REGISTRY=127.0.0.1:5000/planninganalytics
|
|
132
|
+
# shellcheck disable=SC1091
|
|
133
|
+
. "$1/images/images.env"
|
|
134
|
+
for v in $(compgen -v | grep '_IMAGE$'); do printf '%s\n' "${!v}"; done
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
# docker load the images straight from the zip, when any is missing.
|
|
139
|
+
load_images() {
|
|
140
|
+
local zip=$1 dir=$2 tag missing=0
|
|
141
|
+
for tag in $(image_tags "$dir"); do
|
|
142
|
+
docker image inspect "$tag" >/dev/null 2>&1 || missing=$((missing + 1))
|
|
143
|
+
done
|
|
144
|
+
if [ "$missing" -eq 0 ]; then
|
|
145
|
+
info "PAW images already loaded"
|
|
146
|
+
return
|
|
147
|
+
fi
|
|
148
|
+
info "loading PAW images from the zip ($missing missing; several GB, a few minutes)"
|
|
149
|
+
unzip -p "$zip" images/images.tar | docker load
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
# random_text LENGTH: letters and digits. LC_ALL=C matters: macOS tr fails on
|
|
153
|
+
# binary input otherwise, and IBM's paw.sh then writes empty secret files.
|
|
154
|
+
random_text() {
|
|
155
|
+
LC_ALL=C tr -dc 'a-zA-Z0-9' </dev/urandom | head -c "$1" || true
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
# PAW's secrets, made before paw.sh would make them (empty on macOS).
|
|
159
|
+
make_secrets() {
|
|
160
|
+
local config="$1/config"
|
|
161
|
+
if [ ! -s "$config/db_secret.key" ] && docker volume inspect paw_mongo >/dev/null 2>&1; then
|
|
162
|
+
die "PAW's database exists but its password file is missing or empty ($config/db_secret.key).
|
|
163
|
+
Run ./paw-local.sh reset to start PAW with fresh data."
|
|
164
|
+
fi
|
|
165
|
+
[ -s "$config/db_secret.key" ] || random_text 20 >"$config/db_secret.key"
|
|
166
|
+
[ -s "$config/cookie_secret.key" ] || random_text 32 >"$config/cookie_secret.key"
|
|
167
|
+
[ -s "$config/credential_store.key" ] || head -c 512 /dev/urandom >"$config/credential_store.key"
|
|
168
|
+
chmod a+r "$config/db_secret.key" "$config/cookie_secret.key" "$config/credential_store.key"
|
|
169
|
+
[ -s "$config/db_secret.key" ] && [ -s "$config/cookie_secret.key" ] || die "couldn't write PAW's secrets in $config"
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
# The network PAW joins: PAW_NETWORK, or tm1-admin's. PAW's services dial the IP
|
|
173
|
+
# addresses the Admin Server advertises, so they must share its network.
|
|
174
|
+
pick_network() {
|
|
175
|
+
if [ -n "${PAW_NETWORK:-}" ]; then
|
|
176
|
+
printf '%s\n' "$PAW_NETWORK"
|
|
177
|
+
return
|
|
178
|
+
fi
|
|
179
|
+
local net
|
|
180
|
+
net=$(docker inspect -f '{{range $k, $v := .NetworkSettings.Networks}}{{$k}} {{end}}' tm1-admin 2>/dev/null | awk '{print $1}' || true)
|
|
181
|
+
printf '%s\n' "${net:-paw_default}"
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
# export NAME=VALUE, quoted for bash (paw.sh sources this file).
|
|
185
|
+
env_line() {
|
|
186
|
+
printf 'export %s=%q\n' "$1" "$2"
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
write_paw_env() {
|
|
190
|
+
local dir=$1 network=$2 mode=${PAW_AUTH_MODE:-tm1}
|
|
191
|
+
case "$mode" in
|
|
192
|
+
tm1) ;;
|
|
193
|
+
cam) [ -n "${PAW_CAM_SERVLET:-}" ] || die "PAW_AUTH_MODE=cam needs PAW_CAM_SERVLET (the Cognos dispatcher URL)" ;;
|
|
194
|
+
*) die "PAW_AUTH_MODE must be tm1 or cam, not: $mode" ;;
|
|
195
|
+
esac
|
|
196
|
+
{
|
|
197
|
+
echo "# Written by paw-local.sh on every start: set PAW_* variables instead of editing."
|
|
198
|
+
env_line PAW_NET "$network"
|
|
199
|
+
env_line TM1Location "${PAW_TM1_ADMIN_URL:-http://tm1-admin:5895}"
|
|
200
|
+
env_line TM1ApplicationsLocation "${PAW_TM1WEB_URL:-}"
|
|
201
|
+
env_line PAAuthMode "$mode"
|
|
202
|
+
env_line TM1LoginServerURL "${PAW_TM1_LOGIN_URL:-http://tm1:8010}"
|
|
203
|
+
env_line IBMCognosServlet "${PAW_CAM_SERVLET:-}"
|
|
204
|
+
env_line IBMCognosGatewayURL "${PAW_CAM_GATEWAY:-}"
|
|
205
|
+
env_line CAMLoginNamespace "${PAW_CAM_NAMESPACE:-}"
|
|
206
|
+
env_line EnableSSL false
|
|
207
|
+
env_line ServerName localhost
|
|
208
|
+
env_line PAGatewayHTTPPort "$PAW_HTTP_PORT"
|
|
209
|
+
env_line PAGatewayHTTPSPort "$PAW_HTTPS_PORT"
|
|
210
|
+
if [ -n "${PAW_JVM_ARGS:-}" ]; then env_line PRISM_PLATFORM_JVM_ARGS "$PAW_JVM_ARGS"; fi
|
|
211
|
+
} >"$dir/config/paw.env"
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
# IBM's paw.sh, run from the unpacked folder, passing its arguments to docker compose.
|
|
215
|
+
paw_sh() {
|
|
216
|
+
local dir=$1
|
|
217
|
+
shift
|
|
218
|
+
(cd "$dir" && LC_ALL=C ./scripts/paw.sh "$@")
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
wait_for_paw() {
|
|
222
|
+
local url="http://localhost:$PAW_HTTP_PORT" waited=0 code
|
|
223
|
+
if [ "$PAW_WAIT" = 0 ]; then
|
|
224
|
+
info "PAW is starting: $url (not waiting, PAW_WAIT=0)"
|
|
225
|
+
return
|
|
226
|
+
fi
|
|
227
|
+
info "waiting for PAW at $url (up to ${PAW_WAIT}s)"
|
|
228
|
+
while :; do
|
|
229
|
+
code=$(curl -s -o /dev/null -w '%{http_code}' -m 5 "$url/login" || true)
|
|
230
|
+
[ "$code" = 200 ] && break
|
|
231
|
+
[ "$waited" -ge "$PAW_WAIT" ] && die "PAW didn't answer within ${PAW_WAIT}s (last status: $code). See ./paw-local.sh status and logs."
|
|
232
|
+
sleep 5
|
|
233
|
+
waited=$((waited + 5))
|
|
234
|
+
done
|
|
235
|
+
info "PAW is up: $url"
|
|
236
|
+
if [ "${PAW_AUTH_MODE:-tm1}" = tm1 ]; then
|
|
237
|
+
info "log on as a user of the TM1 server at ${PAW_TM1_LOGIN_URL:-http://tm1:8010}"
|
|
238
|
+
fi
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
cmd_up() {
|
|
242
|
+
local zip dir network
|
|
243
|
+
command -v docker >/dev/null 2>&1 || die "docker isn't installed or isn't on the PATH"
|
|
244
|
+
command -v unzip >/dev/null 2>&1 || die "unzip isn't installed"
|
|
245
|
+
command -v curl >/dev/null 2>&1 || die "curl isn't installed"
|
|
246
|
+
zip=$(find_zip)
|
|
247
|
+
dir="$PAW_HOME/$(zip_version "$zip")"
|
|
248
|
+
require_license "$zip"
|
|
249
|
+
docker info >/dev/null 2>&1 || die "can't reach Docker: is it running?"
|
|
250
|
+
unpack "$zip" "$dir"
|
|
251
|
+
shim_compose "$dir"
|
|
252
|
+
load_images "$zip" "$dir"
|
|
253
|
+
make_secrets "$dir"
|
|
254
|
+
network=$(pick_network)
|
|
255
|
+
write_paw_env "$dir" "$network"
|
|
256
|
+
info "starting PAW $(basename "$dir") on network $network"
|
|
257
|
+
paw_sh "$dir" up -d --remove-orphans
|
|
258
|
+
wait_for_paw
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
main() {
|
|
262
|
+
local cmd=${1:-up}
|
|
263
|
+
if [ $# -gt 0 ]; then shift; fi
|
|
264
|
+
case "$cmd" in
|
|
265
|
+
up) cmd_up ;;
|
|
266
|
+
down) paw_sh "$(find_paw_dir)" down --remove-orphans ;;
|
|
267
|
+
reset) paw_sh "$(find_paw_dir)" down --remove-orphans --volumes ;;
|
|
268
|
+
status) paw_sh "$(find_paw_dir)" ps ;;
|
|
269
|
+
logs) paw_sh "$(find_paw_dir)" logs --tail 100 "$@" ;;
|
|
270
|
+
help | -h | --help) usage ;;
|
|
271
|
+
*) usage >&2; exit 2 ;;
|
|
272
|
+
esac
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
main "$@"
|