Prepare a shared template
Shared template file contains information that is going to be used across instances, like: Component Types, IdExtractor functions for components and relations, Component Template functions, Relation Template functions, or Layers. They can be derived from the exported .stj file, by exporting configuration nodes with shared in their identifiers, for example "identifier": "urn:stackpack:{StackPackName}:shared:relation-template-function:test-relation-template",.
Shared template file contains information that is going to be used across instances, like:

Component Types

Component Type in a template file contains a PNG or SVG icon image that is base64 encoded as in the example below:
1
{
2
"_type": "ComponentType",
3
"name": "exchange_server",
4
"id": -147,
5
"identifier": "urn:stackpack:{{StackPackName}}:shared:component-type:exchange-server",
6
"iconbase64": "{{ include "./icons/icon.svg" "base64" }}"
7
},
Copied!

Relation Types

Contains Relation name and direction.
1
{
2
"_type": "RelationType",
3
"name": "hosted_on",
4
"id": -121,
5
"identifier": "urn:stackpack:{{StackPackName}}:shared:relation-type:hosted_on",
6
"dependencyDirection": "ONE_WAY"
7
}
Copied!

Component Template functions

1
{
2
"_type": "ComponentTemplateFunction",
3
"name": "Exchange component template",
4
"identifier": "urn:stackpack:{{StackPackName}}:shared:component-template-function:exchange-component-template",
5
"handlebarsTemplate": "{\n \"_type\": \"Component\",\n \"checks\": [],\n \"streams\": [],\n \"labels\": \{{#if element.data.labels\}}[\n \{{# join element.data.labels \",\" \}}\n {\n \"_type\": \"Label\",\n \"name\": \"\{{ this \}}\"\n }\n \{{/ join \}}\n ]\{{else\}}[]\{{/if\}},\n \"name\": \"\{{#if element.data.name\}}\{{ element.data.name \}}\{{else\}}\{{ element.externalId \}}\{{/if\}}\",\n\{{#if element.data.description\}}\"description\": \"\{{ element.data.description \}}\",\{{/if\}}\n\"type\" : \{{ getOrCreate \"ComponentType\" element.type.name \"Exchange component\" \}},\n \"version\": \"\{{ element.data.version \}}\",\n \"layer\": \{{ getOrCreate \"Layer\" element.data.layer \"Exchange Orgnization\" \}},\n \"domain\": \{{ getOrCreate \"Domain\" element.data.domain \"TEST\" \}},\n \"environments\": [\n \{{ getOrCreate \"Environment\" element.data.environment \"Production\" \}}\n ]\n}\n",
6
"id": -185,
7
"parameters": [{
8
"_type": "Parameter",
9
"name": "element",
10
"system": false,
11
"id": -184,
12
"multiple": false,
13
"type": "STRUCT_TYPE",
14
"required": true
15
}]
16
},
Copied!

Relation Template functions

1
{
2
"_type": "RelationTemplateFunction",
3
"handlebarsTemplate": "{\n \"_type\": \"Relation\",\n \"checks\": [],\n \"streams\": [],\n \"labels\": [],\n \"name\": \"\{{ element.name \}}\",\n \"description\": \"\{{ element.description \}}\",\n \"type\": \{{ getOrCreate \"RelationType\" element.type.name \"test-generic-relation\" \}},\n \"dependencyDirection\": \"ONE_WAY\",\n \"source\": \{{ element.sourceId \}},\n \"target\": \{{ element.targetId \}}\n}\n",
4
"id": -17,
5
"identifier": "urn:stackpack:{{StackPackName}}:shared:relation-template-function:relation-template",
6
"name": "TEST Relation Template",
7
"parameters": [
8
{
9
"_type": "Parameter",
10
"id": -18,
11
"multiple": false,
12
"name": "element",
13
"required": true,
14
"system": false,
15
"type": "STRUCT_TYPE"
16
}
17
]
18
},
Copied!

Component IdExtractor functions

1
{
2
"_type": "IdExtractorFunction",
3
"description": "A generic component id extractor function for topology component elements.",
4
"groovyScript": "element = topologyElement.asReadonlyMap()\n\nexternalId = element[\"externalId\"]\ntype = element[\"typeName\"].toLowerCase()\ndata = element[\"data\"]\n\nidentifiers = new HashSet()\n\nidentifiers.add(externalId)\n\nif(data.containsKey(\"identifiers\") && data[\"identifiers\"] instanceof List<String>) {\n data[\"identifiers\"].each{ id ->\n identifiers.add(id)\n }\n}\n\nreturn Sts.createId(externalId, identifiers, type)\n",
5
"id": -12,
6
"identifier": "urn:stackpack:{{StackPackName}}:shared:idextractor-function:component-id-extractor",
7
"name": "TEST component id extractor",
8
"parameters": [
9
{
10
"_type": "Parameter",
11
"id": -13,
12
"multiple": false,
13
"name": "topologyElement",
14
"required": true,
15
"system": true,
16
"type": "STRUCT_TYPE"
17
}
18
]
19
},
Copied!

Relation IdExtractor functions

1
{
2
"_type": "IdExtractorFunction",
3
"description": "A generic relation id extractor function for topology relation elements.",
4
"groovyScript": "element = topologyElement.asReadonlyMap()\n\nexternalId = element[\"externalId\"]\ntype = element[\"typeName\"].toLowerCase()\n\nreturn Sts.createId(externalId, new HashSet(), type)\n",
5
"id": -14,
6
"identifier": "urn:stackpack:{{StackPackName}}:shared:idextractor-function:relation-id-extractor",
7
"name": "TEST relation id extractor",
8
"parameters": [
9
{
10
"_type": "Parameter",
11
"id": -15,
12
"multiple": false,
13
"name": "topologyElement",
14
"required": true,
15
"system": true,
16
"type": "STRUCT_TYPE"
17
}
18
]
19
},
Copied!

Layers

1
{
2
"_type": "Layer",
3
"name": "Management Pack",
4
"id": -114,
5
"identifier": "urn:stackpack:{{StackPackName}}:shared:layer:management_pack",
6
"order": 703.0
7
},
Copied!

Domains

1
{
2
"_type": "Domain",
3
"name": "Management Pack",
4
"id": -114,
5
"identifier": "urn:stackpack:{{StackPackName}}:shared:domain:management_pack",
6
"order": 703.0
7
},
Copied!

Environments

1
{
2
"_type": "Environment",
3
"name": "Test",
4
"id": -114,
5
"identifier": "urn:stackpack:{{StackPackName}}:shared:environment:test",
6
"order": 703.0
7
},
Copied!
Last modified 11d ago