Skip to content

Commit

Permalink
fix transformation to TOSCA so that properties are splitted correctly…
Browse files Browse the repository at this point in the history
… between node and relationship; added endpoint properties
  • Loading branch information
r0light committed Aug 13, 2024
1 parent cac420b commit 52d2deb
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 19 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"build": "vite build",
"ghpages": "vite build --base=/",
"preview": "vite preview",
"test": "vitest run"
"test": "vitest run",
"parseProfiles": "cd ./src/totypa/parsers/v2dot0-parsers && npx tsx profileParser.ts && cd /../../.."
},
"dependencies": {
"@joint/core": "^4.0.2",
Expand Down
16 changes: 8 additions & 8 deletions src/core/entities/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ function getEndpointProperties(): EntityProperty[] {

for (const prop of parsed) {
switch (prop.getKey) {
case "protocol":
prop.setName = "Endpoint Type:";
prop.setExample = "e.g. HTTP GET";
case "method_name":
prop.setName = "Method name";
prop.setExample = "e.g. GET if protocol is http";
(prop as TextEntityProperty).setOptions = [{
value: "GET",
text: "GET"
Expand All @@ -33,12 +33,12 @@ function getEndpointProperties(): EntityProperty[] {
text: "POST"
},
{
value: "Topic send-to",
text: "Topic send-to"
value: "publish",
text: "publish"
},
{
value: "Topic receive-from",
text: "Topic receive-from"
value: "subscribe",
text: "subscribe"
}
];
break;
Expand Down Expand Up @@ -158,4 +158,4 @@ class Endpoint {
}
}

export { Endpoint, ENDPOINT_TOSCA_KEY, getEndpointProperties };
export { Endpoint, ENDPOINT_TOSCA_KEY, ENDPOINT_TOSCA_EQUIVALENT, ENDPOINT_CAPABILITY_EQUIVALENT, getEndpointProperties };
41 changes: 38 additions & 3 deletions src/core/entities/externalEndpoint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EntityProperty, parseProperties } from "../common/entityProperty.js"
import { EntityProperty, parseProperties, TextEntityProperty } from "../common/entityProperty.js"
import { Endpoint } from "./endpoint.js";
import { tosca_simple_2_0 } from '../../totypa/parsedProfiles/v2dot0-profiles/tosca_simple_2_0.js'
import { MetaData } from "../common/entityDataTypes.js";
Expand All @@ -16,7 +16,42 @@ const EXTERNAL_ENDPOINT_CAPABILITY_EQUIVALENT = tosca_simple_2_0.capability_type


function getExternalEndpointProperties(): EntityProperty[] {
let parsed = parseProperties(EXTERNAL_ENDPOINT_CAPABILITY_EQUIVALENT.properties);
let parsed = parseProperties(EXTERNAL_ENDPOINT_CAPABILITY_EQUIVALENT.properties).concat(parseProperties(EXTERNAL_ENDPOINT_TOSCA_EQUIVALENT.properties));

/*
for (const prop of parsed) {
switch (prop.getKey) {
case "method_name":
prop.setName = "Method name";
prop.setExample = "e.g. GET if protocol is http";
(prop as TextEntityProperty).setOptions = [{
value: "GET",
text: "GET"
},
{
value: "POST",
text: "POST"
},
{
value: "publish",
text: "publish"
},
{
value: "subscribe",
text: "subscribe"
}
];
break;
case "url_path":
prop.setName = "Endpoint Path:";
prop.setExample = "e.g. /orders";
break;
case "port": // TODO transform to Number type?
prop.setName = "Port: ";
prop.setExample = "e.g. 3306"
break;
}
*/
return parsed;
}

Expand Down Expand Up @@ -49,4 +84,4 @@ class ExternalEndpoint extends Endpoint {
}
}

export { ExternalEndpoint, EXTERNAL_ENDPOINT_TOSCA_KEY, getExternalEndpointProperties };
export { ExternalEndpoint, EXTERNAL_ENDPOINT_TOSCA_KEY, EXTERNAL_ENDPOINT_TOSCA_EQUIVALENT, EXTERNAL_ENDPOINT_CAPABILITY_EQUIVALENT, getExternalEndpointProperties };
16 changes: 11 additions & 5 deletions src/core/tosca-adapter/EntitiesToToscaConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import * as Entities from '../entities'
import { TwoWayKeyIdMap } from "./TwoWayKeyIdMap";
import { UniqueKeyManager } from "./UniqueKeyManager";
import { flatMetaData } from '../common/entityDataTypes';
import { ENDPOINT_TOSCA_KEY } from '../entities/endpoint';
import { ENDPOINT_CAPABILITY_EQUIVALENT, ENDPOINT_TOSCA_EQUIVALENT, ENDPOINT_TOSCA_KEY } from '../entities/endpoint';
import { REQUEST_TRACE_TOSCA_KEY } from '../entities/requestTrace';
import { DEPLOYMENT_MAPPING_TOSCA_KEY } from '../entities/deploymentMapping';
import { LINK_TOSCA_KEY } from '../entities/link';
import { EntityProperty } from '../common/entityProperty';
import { EntityProperty, parseProperties } from '../common/entityProperty';
import { DATA_AGGREGATE_TOSCA_KEY } from '../entities/dataAggregate';
import { BACKING_DATA_TOSCA_KEY } from '../entities/backingData';
import { INFRASTRUCTURE_TOSCA_KEY } from '../entities/infrastructure';
import { SERVICE_TOSCA_KEY } from '../entities/service';
import { BACKING_SERVICE_TOSCA_KEY } from '../entities/backingService';
import { STORAGE_BACKING_SERVICE_TOSCA_KEY } from '../entities/storageBackingService';
import { COMPONENT_TOSCA_KEY } from '../entities/component';
import { EXTERNAL_ENDPOINT_TOSCA_KEY } from '../entities/externalEndpoint';
import { EXTERNAL_ENDPOINT_CAPABILITY_EQUIVALENT, EXTERNAL_ENDPOINT_TOSCA_EQUIVALENT, EXTERNAL_ENDPOINT_TOSCA_KEY } from '../entities/externalEndpoint';
import { TOSCA_File } from '@/totypa/tosca-types/v2dot0-types/definition-types';
import { TOSCA_Node_Template, TOSCA_Relationship_Template, TOSCA_Requirement_Assignment, TOSCA_Service_Template } from '@/totypa/tosca-types/v2dot0-types/template-types';
import { TOSCA_Property_Assignment } from '@/totypa/tosca-types/v2dot0-types/alias-types';
Expand Down Expand Up @@ -433,27 +433,33 @@ class EntitiesToToscaConverter {


#createEndpointTemplate(endpoint: Entities.Endpoint): TOSCA_Node_Template {
let endpointNodePropertyKeys = parseProperties(ENDPOINT_TOSCA_EQUIVALENT.properties).map(property => property.getKey);
let template: TOSCA_Node_Template = {
type: ENDPOINT_TOSCA_KEY,
metadata: flatMetaData(endpoint.getMetaData),
properties: this.#parsePropertiesForYaml(endpoint.getProperties().filter(property => endpointNodePropertyKeys.includes(property.getKey))),
capabilities: {}
};

let endpointCapabilityPropertyKeys = parseProperties(ENDPOINT_CAPABILITY_EQUIVALENT.properties).map(property => property.getKey);
template.capabilities.endpoint = {
properties: this.#parsePropertiesForYaml(endpoint.getProperties())
properties: this.#parsePropertiesForYaml(endpoint.getProperties().filter(property => endpointCapabilityPropertyKeys.includes(property.getKey)))
}
return template;
}

#createExternalEndpointTemplate(endpoint: Entities.ExternalEndpoint): TOSCA_Node_Template {
let externalEndpointNodePropertyKeys = parseProperties(EXTERNAL_ENDPOINT_TOSCA_EQUIVALENT.properties).map(property => property.getKey);
let template: TOSCA_Node_Template = {
type: EXTERNAL_ENDPOINT_TOSCA_KEY,
metadata: flatMetaData(endpoint.getMetaData),
properties: this.#parsePropertiesForYaml(endpoint.getProperties().filter(property => externalEndpointNodePropertyKeys.includes(property.getKey))),
capabilities: {}
};

let externalEndpointCapabilityPropertyKeys = parseProperties(EXTERNAL_ENDPOINT_CAPABILITY_EQUIVALENT.properties).map(property => property.getKey);
template.capabilities.external_endpoint = {
properties: this.#parsePropertiesForYaml(endpoint.getProperties())
properties: this.#parsePropertiesForYaml(endpoint.getProperties().filter(property => externalEndpointCapabilityPropertyKeys.includes(property.getKey)))
}

return template;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,27 @@ export const cna_modeling_profile: TOSCA_File = {
},
"derived_from": "Root",
"properties": {
"kind": {
"type": "string",
"required": true,
"description": "The kind of endpoint which can be either \"query\", \"command\", or \"event\". A \"query\" is a synchronous request for data which the client needs for further processing. A \"command\" is a synchronous send of data for which the client needs a corresponding answer for further processing. An \"event\" is an asynchronous send of data for which the client does not expect data to be returned for further processing.",
"validation": {
"$valid_values": [
"$value",
[
"query",
"command",
"event"
]
]
},
"default": "query"
},
"method_name": {
"type": "string",
"required": false,
"description": "An optional name of the method/action used. For REST APIs it can for example be specified whether it is a GET or POST method. For message brokers it can be specified whether it is a publish or subscribe action."
},
"rate_limiting": {
"type": "string",
"required": true,
Expand Down Expand Up @@ -1270,6 +1291,9 @@ export const cna_modeling_profile: TOSCA_File = {
"feature": {
"type": "Node"
},
"endpoint": {
"type": "Endpoint"
},
"external_endpoint": {
"type": "Endpoint.Public"
}
Expand Down Expand Up @@ -1303,7 +1327,54 @@ export const cna_modeling_profile: TOSCA_File = {
"type": "Lifecycle.Standard"
}
},
"derived_from": "Root"
"derived_from": "cna-modeling.entities.Endpoint",
"properties": {
"kind": {
"type": "string",
"required": true,
"description": "The kind of endpoint which can be either \"query\", \"command\", or \"event\". A \"query\" is a synchronous request for data which the client needs for further processing. A \"command\" is a synchronous send of data for which the client needs a corresponding answer for further processing. An \"event\" is an asynchronous send of data for which the client does not expect data to be returned for further processing.",
"validation": {
"$valid_values": [
"$value",
[
"query",
"command",
"event"
]
]
},
"default": "query"
},
"method_name": {
"type": "string",
"required": false,
"description": "An optional name of the method/action used. For REST APIs it can for example be specified whether it is a GET or POST method. For message brokers it can be specified whether it is a publish or subscribe action."
},
"rate_limiting": {
"type": "string",
"required": true,
"description": "If for this endpoint rate limiting is enforced, the limit can be stated here, otherwise it is \"none\".",
"default": "none"
},
"idempotent": {
"type": "boolean",
"required": true,
"description": "Flag to specify whether this endpoint is idempotent, meaning that the effect of a successful invocation is independent of the number of times it is invoked.",
"default": false
},
"readiness_check": {
"type": "boolean",
"required": true,
"description": "Flag to specify whether this endpoint is used as a readiness check",
"default": false
},
"health_check": {
"type": "boolean",
"required": true,
"description": "Flag to specify whether this endpoint is used as a health check",
"default": false
}
}
},
"cna-modeling.entities.BackingData": {
"description": "Node Type to model Backing Data entities",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,16 @@ node_types:
derived_from: Root
description: Endpoint type to explicitly model endpoints as entities
properties:
kind:
type: string
required: true
description: The kind of endpoint which can be either "query", "command", or "event". A "query" is a synchronous request for data which the client needs for further processing. A "command" is a synchronous send of data for which the client needs a corresponding answer for further processing. An "event" is an asynchronous send of data for which the client does not expect data to be returned for further processing.
validation: { $valid_values: [ $value, ["query", "command", "event"]]}
default: "query"
method_name:
type: string
required: false
description: An optional name of the method/action used. For REST APIs it can for example be specified whether it is a GET or POST method. For message brokers it can be specified whether it is a publish or subscribe action.
rate_limiting:
type: string
required: true
Expand Down Expand Up @@ -243,7 +253,7 @@ node_types:
count_range: [0, UNBOUNDED]

cna-modeling.entities.Endpoint.External:
derived_from: Root
derived_from: cna-modeling.entities.Endpoint
description: Endpoint type to explicitly model external endpoints as entities
capabilities:
# Allow assigning exactly one External Endpoint Capability
Expand Down

0 comments on commit 52d2deb

Please sign in to comment.