Skip to content

Commit f2c08ed

Browse files
start better handling of tosca types
1 parent ddfda89 commit f2c08ed

8 files changed

Lines changed: 64 additions & 24 deletions

File tree

engine/schema/src/main/resources/nimble/resource-types/auto-scaling-vm-profile.yaml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,6 @@ node_types:
4242
type: string
4343
description: Service offering ID for the VMs in the auto scaling VM profile.
4444
required: true
45-
template-id:
46-
type: string
47-
description: The ID of the template from which the VMs will be launched.
48-
required: true
49-
user-data-id:
50-
type: string
51-
description: The ID of the user data.
52-
required: false
53-
user-data-details:
54-
type: map
55-
entry_schema:
56-
type: string
57-
description: User data details.
58-
required: false
59-
user-data:
60-
type: string
61-
description: User data.
62-
required: false
6345
other-deploy-params:
6446
type: list
6547
entry_schema:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.apache.cloudstack.tosca.model;
22

33
public class ToscaAttributeDefinition extends ToscaFieldDefinition {
4-
public ToscaAttributeDefinition(String name, String description, ToscaPrimitiveType type) {
4+
public ToscaAttributeDefinition(String name, String description, ToscaTypeDefinition type) {
55
super(name, description, type);
66
}
77
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.apache.cloudstack.tosca.model;
2+
3+
public enum ToscaCollectionType {
4+
MAP, LIST
5+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.apache.cloudstack.tosca.model;
2+
3+
import java.util.List;
4+
5+
public class ToscaDataTypeDefinition {
6+
private final String name;
7+
private final List<ToscaPropertyDefinition> properties;
8+
9+
public ToscaDataTypeDefinition(String name, List<ToscaPropertyDefinition> properties) {
10+
this.name = name;
11+
this.properties = properties;
12+
}
13+
}

plugins/iac/nimble/src/main/java/org/apache/cloudstack/tosca/model/ToscaFieldDefinition.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
public abstract class ToscaFieldDefinition {
66
private String name;
77
private String description;
8-
private ToscaPrimitiveType type;
8+
private ToscaTypeDefinition type;
99

10-
public ToscaFieldDefinition(String name, String description, ToscaPrimitiveType type) {
10+
public ToscaFieldDefinition(String name, String description, ToscaTypeDefinition type) {
1111
this.name = name;
1212
this.description = description;
1313
this.type = type;
@@ -21,7 +21,7 @@ public String getDescription() {
2121
return description;
2222
}
2323

24-
public ToscaPrimitiveType getType() {
24+
public ToscaTypeDefinition getType() {
2525
return type;
2626
}
2727

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package org.apache.cloudstack.tosca.model;
22

33
public enum ToscaPrimitiveType {
4-
STRING, INTEGER, FLOAT, BOOLEAN, LIST
4+
STRING, INTEGER, FLOAT, BOOLEAN
55
}

plugins/iac/nimble/src/main/java/org/apache/cloudstack/tosca/model/ToscaPropertyDefinition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public class ToscaPropertyDefinition extends ToscaFieldDefinition {
44
private boolean required;
55
private Object validation;
66

7-
public ToscaPropertyDefinition(String name, String description, ToscaPrimitiveType type, boolean required, Object validation) {
7+
public ToscaPropertyDefinition(String name, String description, ToscaTypeDefinition type, boolean required, Object validation) {
88
super(name, description, type);
99
this.required = required;
1010
this.validation = validation;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.apache.cloudstack.tosca.model;
2+
3+
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
4+
5+
public class ToscaTypeDefinition {
6+
private enum Kind {
7+
PRIMITIVE, COLLECTION, DATA_TYPE
8+
}
9+
10+
private final Kind kind;
11+
private final ToscaPrimitiveType primitiveType;
12+
private final ToscaCollectionType collectionType;
13+
private final ToscaTypeDefinition entrySchema;
14+
private final ToscaDataTypeDefinition dataType;
15+
16+
public static ToscaTypeDefinition ofPrimitive(ToscaPrimitiveType type) {
17+
return new ToscaTypeDefinition(Kind.PRIMITIVE, type, null, null, null);
18+
}
19+
20+
public static ToscaTypeDefinition ofCollection(ToscaCollectionType collectionType, ToscaTypeDefinition entrySchema) {
21+
return new ToscaTypeDefinition(Kind.COLLECTION, null, collectionType, entrySchema, null);
22+
}
23+
24+
public static ToscaTypeDefinition ofDataType(ToscaDataTypeDefinition dataType) {
25+
return new ToscaTypeDefinition(Kind.DATA_TYPE, null, null, null, dataType);
26+
}
27+
28+
private ToscaTypeDefinition(Kind kind, ToscaPrimitiveType type, ToscaCollectionType collectionType, ToscaTypeDefinition entrySchema, ToscaDataTypeDefinition dataType) {
29+
this.primitiveType = type;
30+
this.collectionType = collectionType;
31+
this.entrySchema = entrySchema;
32+
this.dataType = dataType;
33+
this.kind = kind;
34+
}
35+
36+
@Override
37+
public String toString() {
38+
return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "type");
39+
}
40+
}

0 commit comments

Comments
 (0)