Skip to content

Commit

Permalink
implied properties (#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesstoetzner authored Nov 9, 2024
1 parent 6243e26 commit 0400cae
Show file tree
Hide file tree
Showing 57 changed files with 993 additions and 321 deletions.
158 changes: 81 additions & 77 deletions docs/docs/variability4tosca/specification/index.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ topology_template:
domain:
type: string

dbms_password:
type: string

retailer_name:
type: string

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ topology_template:
domain:
type: string

dbms_password:
type: string

retailer_name:
type: string

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ topology_template:
domain:
type: string

dbms_password:
type: string

retailer_name:
type: string

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ topology_template:
domain:
type: string

dbms_password:
type: string

retailer_name:
type: string

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ topology_template:
domain:
type: string

dbms_password:
type: string

retailer_name:
type: string

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ topology_template:
domain:
type: string

dbms_password:
type: string

retailer_name:
type: string

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ topology_template:
domain:
type: string

dbms_password:
type: string

retailer_name:
type: string

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ topology_template:
domain:
type: string

dbms_password:
type: string

retailer_name:
type: string

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ topology_template:
domain:
type: string

dbms_password:
type: string

retailer_name:
type: string

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ topology_template:
domain:
type: string

dbms_password:
type: string

retailer_name:
type: string

Expand Down
11 changes: 5 additions & 6 deletions src/enricher/constraints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ export class ConstraintEnricher {
}
assert.isDefined(left, 'Left not defined')

// Sanity check
if (!(element.isRelation() || element.isArtifact()))
throw new Error(`${element.Display} is not issued a manual id`)

this.graph.addConstraint({
implies: [{and: [element.container.id, element.manualId]}, element.id],
})
Expand Down Expand Up @@ -96,7 +92,7 @@ export class ConstraintEnricher {
}

/**
* Ensure that each property has maximum one value (also considering non-present nodes)
* Ensure that each property has exactly one value
*/
if (this.graph.options.constraints.uniqueProperty) {
for (const element of [
Expand All @@ -107,7 +103,10 @@ export class ConstraintEnricher {
...this.graph.artifacts,
]) {
for (const properties of element.propertiesMap.values()) {
this.graph.addConstraint({amo: properties.map(it => it.id)})
if (properties.length === 0) continue
this.graph.addConstraint({
implies: [properties[0].container.id, {exo: properties.map(it => it.id)}],
})
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/enricher/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class Enricher {
/**
* Regenerate graph
*/
graph = graph.regenerate()
graph = new Graph(this.serviceTemplate)

/**
* Condition Enricher
Expand Down
37 changes: 33 additions & 4 deletions src/graph/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,39 @@ export default class Graph {
new Populator(this).run()
}

guessElement(data: string, context: Context = {}): Element {
assert.isString(data)
try {
return this.getNode(data, context)
} catch (e) {
// NIL
}

try {
return this.getGroup(data, context)
} catch (e) {
// NIL
}

try {
return this.getPolicy(data, context)
} catch (e) {
// NIL
}

try {
return this.getGroup(data, context)
} catch (e) {
// NIL
}

// TODO: guess property? relation? artifact?

throw new Error(
`Could not get element "${data}" from context element "${context.element?.display}" and context cached "${context.cached?.display}"`
)
}

getNode(name: string | 'SELF' | 'CONTAINER' | 'SOURCE' | 'TARGET', context: Context = {}): Node {
assert.isString(name)

Expand Down Expand Up @@ -648,8 +681,4 @@ export default class Graph {
replaceTechnologies(node: Node, maps: TechnologyTemplateMap[]) {
node.raw.technology = maps
}

regenerate() {
return new Graph(this.serviceTemplate)
}
}
6 changes: 6 additions & 0 deletions src/graph/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {ServiceTemplate, TOSCA_DEFINITIONS_VERSION} from '#spec/service-template
import {
ArtifactDefaultConditionMode,
NodeDefaultConditionMode,
PropertyDefaultConditionMode,
RelationDefaultConditionMode,
TechnologyDefaultConditionMode,
VariabilityOptions,
Expand Down Expand Up @@ -91,6 +92,7 @@ class DefaultOptions extends BaseOptions {
readonly artifactDefaultSemanticCondition: boolean

readonly propertyDefaultCondition: boolean
readonly propertyDefaultConditionMode: PropertyDefaultConditionMode
readonly propertyDefaultConsistencyCondition: boolean
readonly propertyDefaultSemanticCondition: boolean

Expand Down Expand Up @@ -288,6 +290,10 @@ class DefaultOptions extends BaseOptions {
this.raw.property_default_condition ?? mode.property_default_condition ?? this.defaultCondition
assert.isBoolean(this.propertyDefaultCondition)

this.propertyDefaultConditionMode =
this.raw.property_default_condition_mode ?? mode.property_default_condition_mode ?? 'container-consuming'
assert.isString(this.propertyDefaultConditionMode)

this.propertyDefaultConsistencyCondition =
this.raw.property_default_consistency_condition ??
mode.property_default_consistency_condition ??
Expand Down
Loading

0 comments on commit 0400cae

Please sign in to comment.