This is an automated email from the ASF dual-hosted git repository. marat pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-karavan.git
commit 7fa9c0a74bcffdf1098f753793ff63296d9085cb Author: Marat Gubaidullin <ma...@talismancloud.io> AuthorDate: Thu May 1 16:54:31 2025 -0400 Karavan Core improvements --- karavan-core/src/core/api/CamelDefinitionApiExt.ts | 6 ++-- karavan-core/src/core/api/CamelUtil.ts | 32 ++++++++++++++++++++-- karavan-core/src/core/api/TopologyUtils.ts | 29 +++++++++++++++++--- .../src/core/model/IntegrationDefinition.ts | 2 +- karavan-core/src/core/model/TopologyDefinition.ts | 12 ++++++++ 5 files changed, 70 insertions(+), 11 deletions(-) diff --git a/karavan-core/src/core/api/CamelDefinitionApiExt.ts b/karavan-core/src/core/api/CamelDefinitionApiExt.ts index 81818259..38ea6d19 100644 --- a/karavan-core/src/core/api/CamelDefinitionApiExt.ts +++ b/karavan-core/src/core/api/CamelDefinitionApiExt.ts @@ -36,15 +36,15 @@ export class CamelDefinitionApiExt { private constructor() {} // additional helper functions for more readability - private static getFlowsOfType(integration: Integration, type: string): CamelElement[] { + static getFlowsOfType(integration: Integration, type: string): CamelElement[] { return integration.spec.flows?.filter(flow => flow.dslName === type) ?? []; } - private static getFlowsOfTypes(integration: Integration, types: string[]): CamelElement[] { + static getFlowsOfTypes(integration: Integration, types: string[]): CamelElement[] { return integration.spec.flows?.filter(flow => types.includes(flow.dslName)) ?? []; } - private static getFlowsNotOfTypes(integration: Integration, types: string[]): any[] { + static getFlowsNotOfTypes(integration: Integration, types: string[]): any[] { return integration.spec.flows?.filter(flow => !types.includes(flow.dslName)) ?? []; } diff --git a/karavan-core/src/core/api/CamelUtil.ts b/karavan-core/src/core/api/CamelUtil.ts index 691e8b83..23bd6fd9 100644 --- a/karavan-core/src/core/api/CamelUtil.ts +++ b/karavan-core/src/core/api/CamelUtil.ts @@ -20,7 +20,7 @@ import { KameletDefinition, BeanFactoryDefinition, RouteConfigurationDefinition, - ToDefinition, RouteTemplateDefinition, + ToDefinition, RouteTemplateDefinition, SetVariableDefinition, SetHeaderDefinition, } from '../model/CamelDefinition'; import { KameletApi } from './KameletApi'; import { KameletModel, Property } from '../model/KameletModels'; @@ -207,15 +207,42 @@ export class CamelUtil { static checkRequired = (element: CamelElement): [boolean, string[]] => { const result: [boolean, string[]] = [true, []]; const className = element.dslName; + const elementAsAny = (element as any); let elementMeta = CamelMetadataApi.getCamelModelMetadataByClassName(className); if (elementMeta === undefined && className.endsWith('Expression')) { elementMeta = CamelMetadataApi.getCamelLanguageMetadataByClassName(className); } + if (className === 'SetVariablesDefinition') { + if (elementAsAny.variables === undefined || elementAsAny.variables?.length === 0) { + result[0] = false; + result[1].push(`Variables not set`); + } else { + elementAsAny.variables.forEach((v: SetVariableDefinition) => { + const r = CamelUtil.checkRequired(v); + if (!r[0]){ + result[1].push(...r[1]); + } + }) + } + } else if (className.includes('SetHeadersDefinition')) { + if (elementAsAny.headers === undefined || elementAsAny.headers?.length === 0) { + result[0] = false; + result[1].push(`Headers not set`); + } else { + elementAsAny.headers.forEach((v: SetHeaderDefinition) => { + const r = CamelUtil.checkRequired(v); + if (!r[0]){ + result[1].push(...r[1]); + } + }) + } + } + if (elementMeta) { for (const property of elementMeta.properties.filter(p => p.required)) { - const value = (element as any)[property.name]; + const value = elementAsAny[property.name]; if (property.type === 'string' && !property.isArray && (value === undefined || !value.toString().trim())) { result[0] = false; result[1].push(`${property.displayName} is required`); @@ -259,7 +286,6 @@ export class CamelUtil { } else { const kamelet = CamelUtil.getKamelet(element); let allSet = true; - const elementAsAny = (element as any); const filledParameters = elementAsAny ? Object.keys(elementAsAny.parameters) : []; const missingParameters = kamelet?.spec.definition.required?.filter(name => !filledParameters.includes(name)) || []; diff --git a/karavan-core/src/core/api/TopologyUtils.ts b/karavan-core/src/core/api/TopologyUtils.ts index 45cebfa2..51df7a7f 100644 --- a/karavan-core/src/core/api/TopologyUtils.ts +++ b/karavan-core/src/core/api/TopologyUtils.ts @@ -15,6 +15,7 @@ * limitations under the License. */ import { + BeanFactoryDefinition, DeleteDefinition, FromDefinition, GetDefinition, @@ -29,6 +30,7 @@ import { Integration, } from '../model/IntegrationDefinition'; import { + TopologyBeanNode, TopologyIncomingNode, TopologyOutgoingNode, TopologyRestNode, TopologyRouteConfigurationNode, @@ -227,7 +229,7 @@ export class TopologyUtils { const routes = i.spec.flows?.filter(flow => flow.dslName === 'RouteConfigurationDefinition'); const routeElements = routes?.map(r => { const id = 'route-' + r.id; - const title = '' + (r.description ? r.description : r.id); + const title = '' + (r.description ? r.description : (r.id || 'default')); return new TopologyRouteConfigurationNode(id, r.id, title, filename, r); }) || []; result.push(...routeElements); @@ -333,6 +335,25 @@ export class TopologyUtils { return result; }; + static findTopologyBeanNodes = (integrations: Integration[]): TopologyBeanNode[] => { + const result: TopologyBeanNode[] = []; + integrations.forEach(integration => { + const beans = TopologyUtils.getBeans(integration); + const topologyBeans = beans.map((bean) => new TopologyBeanNode(bean.name, bean.name, integration.metadata.name)); + result.push(...topologyBeans); + }) + return result; + } + + static getBeans = (integration: Integration): BeanFactoryDefinition[] => { + const result: BeanFactoryDefinition[] = []; + const beans = integration.spec.flows?.filter((e: any) => e.dslName === 'Beans'); + if (beans && beans.length > 0 && beans[0].beans) { + result.push(...beans[0].beans); + } + return result; + } + static findOutgoingInStep = (step: CamelElement, result: CamelElement[]): CamelElement[] => { if (step !== undefined) { const el = (step as any); @@ -396,10 +417,10 @@ export class TopologyUtils { } } - static getNodeIdByUniqueUri(tins: TopologyIncomingNode[], uniqueUri: string): string [] { - const result: string[] = []; + static getNodeIdByUniqueUri(tins: TopologyIncomingNode[], uniqueUri: string): TopologyIncomingNode [] { + const result: TopologyIncomingNode[] = []; tins.filter(r => r.uniqueUri === uniqueUri) - ?.forEach(node => result.push(node.id)); + ?.forEach(node => result.push(node)); return result; } diff --git a/karavan-core/src/core/model/IntegrationDefinition.ts b/karavan-core/src/core/model/IntegrationDefinition.ts index 4f424584..cecc5b49 100644 --- a/karavan-core/src/core/model/IntegrationDefinition.ts +++ b/karavan-core/src/core/model/IntegrationDefinition.ts @@ -118,7 +118,7 @@ export class Metadata { export class Integration { apiVersion: string = 'camel.apache.org/v1'; - kind: string = 'Integration' || 'Kamelet'; + kind: 'Integration' | 'Kamelet' = 'Integration'; metadata: Metadata = new Metadata(); spec: Spec = new Spec(); type: 'crd' | 'plain' | 'kamelet' = 'plain'; diff --git a/karavan-core/src/core/model/TopologyDefinition.ts b/karavan-core/src/core/model/TopologyDefinition.ts index 3c3742eb..da7bf3ce 100644 --- a/karavan-core/src/core/model/TopologyDefinition.ts +++ b/karavan-core/src/core/model/TopologyDefinition.ts @@ -118,4 +118,16 @@ export class TopologyOutgoingNode { this.step = step; this.uniqueUri = uniqueUri; } +} + +export class TopologyBeanNode { + id: string; + name: string; + fileName: string; + + constructor(id: string, name: string, fileName: string) { + this.id = id; + this.name = name; + this.fileName = fileName; + } } \ No newline at end of file