Skip to content

Commit bd4f938

Browse files
committed
Allow to generate even if 'derivedFrom' node types is null
1 parent 1486a9d commit bd4f938

File tree

5 files changed

+43
-96
lines changed

5 files changed

+43
-96
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
tosca_definitions_version: tosca_simple_yaml_1_3
2+
3+
imports:
4+
- file: .tosca
5+
namespace_uri: example.eu.myrtus.nodetypes
6+
namespace_prefix: MYRTUS-
7+
8+
node_types:
9+
example.eu.myrtus.nodetypes.Myrtus-Workstation:
10+
description: Representation of a computing node in the Myrtus systems.
11+
derived_from: tosca.nodes.Compute
12+
metadata:
13+
targetNamespace: "example.eu.myrtus.nodetypes"
14+
abstract: "false"
15+
final: "false"
16+
17+
18+

ToscaDesigner/Generated TOSCA files/MyrtusCameraFeed.tosca

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ node_types:
1717
- faceDetectionService:
1818
capability: Endpoint
1919
relationship: connectsTo
20-
occurrences: [, ]
20+
occurrences: [1, ]
2121
capabilities:
2222
CameraFeed.WebService:
23-
occurrences: [, ]
23+
occurrences: [0, ]
2424
type: tosca.capabilities.Endpoint
Lines changed: 10 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,13 @@
11
tosca_definitions_version: tosca_simple_yaml_1_3
22

3-
metadata:
4-
targetNamespace: "example.eu.myrtus.servicetemplates"
5-
name: "MyrtusFace_Application"
6-
imports:
7-
- file: MyrtusFaceDetectionService_0.tosca
8-
namespace_uri: example.eu.myrtus.nodetypes
9-
namespace_prefix: MYRTUS-
10-
- file: Myrtus_Proxy_0.tosca
11-
namespace_uri: example.eu.myrtus.nodetypes
12-
namespace_prefix: MYRTUS-
13-
- file: MyrtusCameraFeed_0.tosca
14-
namespace_uri: example.eu.myrtus.nodetypes
15-
namespace_prefix: MYRTUS-
16-
- file: Myrtus_Workstation_1.tosca
17-
namespace_uri: example.eu.myrtus.nodetypes
18-
namespace_prefix: MYRTUS-
193

20-
topology_template:
21-
node_templates:
22-
Myrtus_Workstation_1:
23-
type: example.eu.myrtus.nodetypes.Myrtus-Workstation
24-
metadata:
25-
displayName: "Myrtus-Workstation"
26-
MyrtusFaceDetectionService_0:
27-
type: example.eu.myrtus.nodetypes.MyrtusFaceDetectionService
28-
metadata:
29-
displayName: "FaceDetection"
30-
properties:
31-
dockerImage: "thebigpotatoe/face-recognition-docker"
32-
requirements:
33-
- host:
34-
node: Myrtus_Workstation_1
35-
relationship: con_HostedOn_0
36-
capability: host
37-
Myrtus_Proxy_0:
38-
type: example.eu.myrtus.nodetypes.MyrtusProxy
39-
metadata:
40-
displayName: "Proxy"
41-
properties:
42-
dockerImage: "nginx:alpine"
43-
port: "443"
44-
requirements:
45-
- egress1:
46-
node: MyrtusCameraFeed_0
47-
relationship: con_ConnectsTo_0
48-
capability: CameraFeed.WebService
49-
- egress2:
50-
node: MyrtusFaceDetectionService_0
51-
relationship: con_ConnectsTo_1
52-
capability: FaceDetectionService
53-
- host:
54-
node: Myrtus_Workstation_1
55-
relationship: con_HostedOn_2
56-
capability: host
57-
artifacts:
58-
fullchain.pem:
59-
type: File
60-
deploy_path: /certs/fullchain.pem
61-
file: /home/hesi/cert/fullchain.pem
62-
key:
63-
type: File
64-
deploy_path: /certs/privkey.pem
65-
file: /home/hesi/cert/privkey.pem
66-
nginx.conf:
67-
type: File
68-
deploy_path: /etc/nginx/conf.d/default.conf
69-
file: /servicetemplates/example.eu.myrtus.servicetemplates/MyrtusFace_Application_w1-wip2/files/MyrtusProxy_w1-wip1_0/nginx.conf/nginx.conf
70-
MyrtusCameraFeed_0:
71-
type: example.eu.myrtus.nodetypes.MyrtusCameraFeed
72-
metadata:
73-
displayName: "CameraFeed"
74-
properties:
75-
dockerImage: "ci.hesi.energy:5000/myrtus/examples/myrtusface/camera_feed:web"
76-
requirements:
77-
- host:
78-
node: Myrtus_Workstation_1
79-
relationship: con_HostedOn_1
80-
capability: host
81-
relationship_templates:
82-
con_HostedOn_2:
83-
type: hostedOn
84-
con_HostedOn_1:
85-
type: hostedOn
86-
con_HostedOn_0:
87-
type: hostedOn
88-
con_ConnectsTo_1:
89-
type: connectsTo
90-
con_ConnectsTo_0:
91-
type: connectsTo
4+
node_types:
5+
Service Template.NodeType:
6+
7+
metadata:
8+
targetNamespace: ""
9+
abstract: ""
10+
final: ""
11+
12+
13+

ToscaDesigner/src/main/java/fr/softeam/toscadesigner/export/AbstractToscaFileGenerator.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ private Handlebars setupHandlebars() {
125125
.safeInstantiate((Class) context);
126126
if (searchedPropertyName.equals("capabilityType")) {
127127
propertyStringValue = tCapabilityDefinition.getCapabilityType().getElement().getName();
128+
} else if (searchedPropertyName.equals("lowerBound")) {
129+
propertyStringValue = tCapabilityDefinition.getLowerBound().toString();
130+
} else if (searchedPropertyName.equals("upperBound")) {
131+
propertyStringValue = tCapabilityDefinition.getUpperBound().toString();
128132
}
129133
} else if (stereotype.getName().equals("TDeploymentArtifact")) {
130134
TDeploymentArtifact tDeploymentArtifact = TDeploymentArtifact.safeInstantiate((Class) context);
@@ -164,10 +168,13 @@ private Handlebars setupHandlebars() {
164168

165169
// 1. Check for non-tosca derived type
166170

167-
String derivedFromValue = tNodeType.getDerivedFrom().getName();
168-
String targetNamespace = tNodeType.getTargetNamespace();
169-
if (derivedFromValue != null && !derivedFromValue.startsWith("tosca")) {
170-
imports.add(new Import(derivedFromValue + ".tosca", targetNamespace, "MYRTUS-"));
171+
if (tNodeType.getDerivedFrom() != null) {
172+
173+
String derivedFromValue = tNodeType.getDerivedFrom().getName();
174+
String targetNamespace = tNodeType.getTargetNamespace();
175+
if (derivedFromValue != null && !derivedFromValue.startsWith("tosca")) {
176+
imports.add(new Import(derivedFromValue + ".tosca", targetNamespace, "MYRTUS-"));
177+
}
171178
}
172179

173180
// 2. Check for non-tosca valid source types in capabilities

ToscaDesigner/src/main/resources/fr/softeam/templates/TNodeType.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ node_types:
1616
- {{../name}}:
1717
capability: {{getProperty ../this "capability"}}
1818
relationship: {{getProperty ../this "relationshipType"}}
19-
occurrences: [{{../multiplicityMin}}, {{../multiplicityMax}}]
19+
occurrences: [{{getProperty ../this "lowerBound"}}, {{getProperty ../this "../upperBound"}}]
2020
{{/eq}}{{/extension}}{{/each}}{{/eq}}{{/extension}}{{/each}}
2121
{{#unless (noStereotypeApplications this "TCapabilityDefinitionsType")}}capabilities:{{/unless}}
2222
{{#each ownedElement}}{{#extension}}{{#eq name "TCapabilityDefinitionsType"}}{{#each ../ownedElement}}{{#extension}}{{#eq name "TCapabilityDefinition"}}
2323
{{../name}}:
24-
occurrences: [{{../multiplicityMin}}, {{../multiplicityMax}}]
24+
occurrences: [{{getProperty ../this "lowerBound"}}, {{getProperty ../this "../upperBound"}}]
2525
type: tosca.capabilities.Endpoint
2626
{{/eq}}{{/extension}}{{/each}}{{/eq}}{{/extension}}{{/each}}

0 commit comments

Comments
 (0)