Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

technology plugin uses #444

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/night.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ jobs:
- name: (DOCKER) Ensure Vintner can be executed
run: docker exec vintner vintner --version

- name: (DOCKER) Ensure Vintner can be executed
- name: (DOCKER) Ensure Vintner version in Docker container and binary match
run: |
DOCKER_VERSION=$(docker exec vintner vintner --version)
echo "Docker version: $DOCKER_VERSION}"
Expand Down
1 change: 1 addition & 0 deletions docs/docs/variability4tosca/specification/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,7 @@ export type TechnologyPluginBuilder = {
export type TechnologyPlugin = {
assign: (node: Node) => {[technology: string]: TechnologyTemplate}[]
implement: (name: string, type: NodeType) => NodeTypeMap
uses: (artifact: Artifact) => Technology[]
}
```

Expand Down
4 changes: 2 additions & 2 deletions src/enricher/elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class ElementEnricher {

private getTechnologyCandidates(node: Node) {
const candidates: TechnologyTemplateMap[] = []
for (const plugin of this.graph.plugins.technology) {
for (const plugin of this.graph.plugins.technology.filter(it => it.backwards())) {
candidates.push(...plugin.assign(node))
}
return candidates
Expand All @@ -39,7 +39,7 @@ export class ElementEnricher {
*/
private enrichImplementations() {
// for backwards compatibility and testing purposed, continue if, e.g., no rules at all exists
if (utils.isEmpty(this.graph.plugins.technology)) return
if (utils.isEmpty(this.graph.plugins.technology.filter(it => it.backwards()))) return

for (const node of this.graph.nodes.filter(it => it.managed).filter(it => utils.isPopulated(it.technologies))) {
// Do not override manual assigned technologies but enrich them with an implementation
Expand Down
4 changes: 1 addition & 3 deletions src/graph/populator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ export class Populator {
* Technology Rule Plugin
*/
const technologyRulePlugin = new TechnologyRulePluginBuilder().build(this.graph)
if (technologyRulePlugin.hasRules()) {
this.graph.plugins.technology.push(technologyRulePlugin)
}
this.graph.plugins.technology.push(technologyRulePlugin)

/**
* Imported plugins
Expand Down
13 changes: 7 additions & 6 deletions src/resolver/solver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import * as check from '#check'
import Element from '#graph/element'
import Graph from '#graph/graph'
import Property from '#graph/property'
import Technology from '#graph/technology'
import {andify} from '#graph/utils'
import Optimizer from '#resolver/optimizer'
import {Result, ResultMap} from '#resolver/result'
import {InputAssignmentMap, InputAssignmentValue} from '#spec/topology-template'
import {LogicExpression, ValueExpression, VariabilityDefinition, VariabilityExpression} from '#spec/variability'
import {destructImplementationName} from '#technologies/utils'
import * as utils from '#utils'
import day from '#utils/day'
import {UnexpectedError} from '#utils/error'
Expand Down Expand Up @@ -629,11 +629,12 @@ export default class Solver {
*/
if (check.isDefined(expression.is_managed)) {
const artifact = this.graph.getArtifact(expression.is_managed, {element, cached})
const technologies = artifact.container.technologies.filter(it => {
const deconstructed = destructImplementationName(it.assign)
if (check.isUndefined(deconstructed.artifact)) return false
return artifact.getType().isA(deconstructed.artifact)
})

const technologies: Technology[] = []
for (const plugin of this.graph.plugins.technology) {
technologies.push(...plugin.uses(artifact))
}

return MiniSat.or(technologies.map(it => it.id))
}

Expand Down
21 changes: 20 additions & 1 deletion src/technologies/plugins/rules/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import * as assert from '#assert'
import * as check from '#check'
import Artifact from '#graph/artifact'
import Graph from '#graph/graph'
import Node from '#graph/node'
import Technology from '#graph/technology'
import {NodeType, NodeTypeMap} from '#spec/node-type'
import {TechnologyTemplateMap} from '#spec/technology-template'
import {LogicExpression} from '#spec/variability'
import std from '#std'
import Registry from '#technologies/plugins/rules/registry'
import {ASTERISK, METADATA} from '#technologies/plugins/rules/types'
import {TechnologyPlugin, TechnologyPluginBuilder} from '#technologies/types'
import {constructImplementationName, constructRuleName, isGenerated} from '#technologies/utils'
import {
constructImplementationName,
constructRuleName,
destructImplementationName,
isGenerated,
} from '#technologies/utils'
import * as utils from '#utils'

export class TechnologyRulePluginBuilder implements TechnologyPluginBuilder {
Expand All @@ -32,10 +39,22 @@ export class TechnologyRulePlugin implements TechnologyPlugin {
return rules
}

backwards() {
return this.hasRules()
}

hasRules() {
return utils.isPopulated(this.getRules())
}

uses(artifact: Artifact): Technology[] {
return artifact.container.technologies.filter(it => {
const deconstructed = destructImplementationName(it.assign)
if (check.isUndefined(deconstructed.artifact)) return false
return artifact.getType().isA(deconstructed.artifact)
})
}

implement(name: string, type: NodeType): NodeTypeMap {
const rules = this.getRules()
if (utils.isEmpty(rules)) return {}
Expand Down
6 changes: 6 additions & 0 deletions src/technologies/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Artifact from '#graph/artifact'
import Graph from '#graph/graph'
import Node from '#graph/node'
import Technology from '#graph/technology'
import {NodeType, NodeTypeMap} from '#spec/node-type'
import {TechnologyTemplateMap} from '#spec/technology-template'

Expand All @@ -8,7 +10,11 @@ export type TechnologyPluginBuilder = {
}

export type TechnologyPlugin = {
// for backwards compatibility and testing purposed, continue if, e.g., no rules at all exists
backwards: () => Boolean

// TODO: must assign technology.assign!
assign: (node: Node) => TechnologyTemplateMap[]
implement: (name: string, type: NodeType) => NodeTypeMap
uses: (artifact: Artifact) => Technology[]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const technology = require("technology");
module.exports = {
build: (graph) => {
return {
backwards: () => true,
assign: (node) => {
return [{ [technology.name()]: { assign: "this-is-assigned" } }];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const technology = require("technology");
module.exports = {
build: (graph) => {
return {
backwards: () => true,
assign: (node) => {
return [{ [technology.name()]: { assign: "this-is-assigned" } }];
}
Expand Down