Prepare a multi-instance provisioning script
This page describes StackState version 4.2.
The StackState 4.2 version range is End of Life (EOL) and no longer supported. We encourage customers still running the 4.2 version range to upgrade to a more recent release.
A multi-instance StackPack requires a provisioning script that is able to provision multiple StackPack instances. To achieve that, you need to provide a separate template file in the context for both stackPack and instance; stackPack needs to be provided with the shared-template.stj, and instance requires the instance-template.stj as in the example below:
Please note that instance-template.stj has some instance specific information, like topicName, instanceId and anything else defined in templateArguments, while shared-template passes without any specifics ([:]).
1
import com.stackstate.stackpack.ProvisioningScript
2
import com.stackstate.stackpack.ProvisioningContext
3
import com.stackstate.stackpack.ProvisioningIO
4
import com.stackstate.stackpack.Version
5
6
class Provision extends ProvisioningScript {
7
8
Provision(ProvisioningContext context) {
9
super(context)
10
}
11
12
@Override
13
ProvisioningIO<scala.Unit> install(Map<String, Object> config) {
14
def instance_url = instanceURL(config)
15
def templateArguments = [
16
'topicName': topicName(config),
17
'instance_url': instance_url,
18
'instanceId': context().instance().id()
19
]
20
templateArguments.putAll(config)
21
22
return context().stackPack().importSnapshot("templates/shared-template.stj", [:]) >>
23
context().instance().importSnapshot("templates/instance-template.stj", templateArguments)
24
}
25
26
@Override
27
ProvisioningIO<scala.Unit> upgrade(Map<String, Object> config, Version current) {
28
return install(config)
29
}
30
31
@Override
32
void waitingForData(Map<String, Object> config) {
33
context().sts().onDataReceived(topicName(config), {
34
context().sts().provisioningComplete()
35
})
36
}
37
38
private def topicName(Map<String, Object> exampleConfig) {
39
def instance_url = exampleConfig.test_instance_url
40
def topic = instance_url.replace("/", "_").replace(":", "_")
41
return context().sts().createTopologyTopicName("example", topic)
42
}
43
44
private def instanceURL(Map<String, Object> exampleConfig) {
45
def url = exampleConfig.test_instance_url
46
def instance_url = ''
47
if (url.startsWith('http') || url.startsWith('https')){
48
instance_url = url.split("//")[1].split("/")[0]
49
}
50
else{
51
instance_url = url.split("/")[0]
52
}
53
return instance_url
54
}
55
56
}
Copied!
Last modified 2mo ago
Copy link