You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ma...@apache.org on 2023/10/31 21:02:44 UTC

(camel-karavan) branch main updated (8fb462ca -> 38236be3)

This is an automated email from the ASF dual-hosted git repository.

marat pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karavan.git


    from 8fb462ca Upgrade react types
     new bd007b53 Fix for #315
     new 09197e04 Log message in installer
     new 38236be3 Fix for properties  #931

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 karavan-core/src/core/api/CamelDefinitionYaml.ts   | 10 +++
 karavan-core/src/core/api/CamelUtil.ts             | 33 ++++++++--
 karavan-core/test/createKamelet.spec.ts            | 38 +++++++++++
 karavan-core/test/timer-source.kamelet.yaml        | 75 ++++++++++++++++++++++
 karavan-space/src/designer/KaravanDesigner.tsx     |  1 -
 .../designer/route/property/DslPropertyField.tsx   | 17 +++--
 .../main/webui/src/designer/KaravanDesigner.tsx    |  1 -
 .../designer/route/property/DslPropertyField.tsx   | 17 +++--
 .../route/property/KameletPropertyField.tsx        |  1 -
 .../camel/karavan/installer/CommandUtils.java      |  2 +-
 10 files changed, 172 insertions(+), 23 deletions(-)
 create mode 100644 karavan-core/test/createKamelet.spec.ts
 create mode 100644 karavan-core/test/timer-source.kamelet.yaml


(camel-karavan) 02/03: Log message in installer

Posted by ma...@apache.org.
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 09197e04c9f46c90c043ba973041590ec10cbc1b
Author: Marat Gubaidullin <ma...@talismancloud.io>
AuthorDate: Tue Oct 31 17:01:25 2023 -0400

    Log message in installer
---
 .../src/main/java/org/apache/camel/karavan/installer/CommandUtils.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/karavan-web/karavan-installer/src/main/java/org/apache/camel/karavan/installer/CommandUtils.java b/karavan-web/karavan-installer/src/main/java/org/apache/camel/karavan/installer/CommandUtils.java
index ed39a354..5f984b06 100644
--- a/karavan-web/karavan-installer/src/main/java/org/apache/camel/karavan/installer/CommandUtils.java
+++ b/karavan-web/karavan-installer/src/main/java/org/apache/camel/karavan/installer/CommandUtils.java
@@ -117,7 +117,7 @@ public class CommandUtils {
 
         }
         System.out.println();
-        log("Karavan is ready");
+        log("Karavan is started");
     }
 
     public static boolean checkKaravanSecrets(KaravanCommand config, KubernetesClient client) {


(camel-karavan) 03/03: Fix for properties #931

Posted by ma...@apache.org.
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 38236be3c0008b08bf5c593057dd67533e62786c
Author: Marat Gubaidullin <ma...@talismancloud.io>
AuthorDate: Tue Oct 31 17:02:37 2023 -0400

    Fix for properties  #931
---
 karavan-space/src/designer/KaravanDesigner.tsx          |  1 -
 .../src/designer/route/property/DslPropertyField.tsx    | 17 +++++++++++------
 .../src/main/webui/src/designer/KaravanDesigner.tsx     |  1 -
 .../src/designer/route/property/DslPropertyField.tsx    | 17 +++++++++++------
 .../designer/route/property/KameletPropertyField.tsx    |  1 -
 5 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/karavan-space/src/designer/KaravanDesigner.tsx b/karavan-space/src/designer/KaravanDesigner.tsx
index b1af73c5..eb967d0e 100644
--- a/karavan-space/src/designer/KaravanDesigner.tsx
+++ b/karavan-space/src/designer/KaravanDesigner.tsx
@@ -96,7 +96,6 @@ export function KaravanDesigner(props: Props) {
             EventBus.sendAlert("Error parsing YAML", (e as Error).message, 'danger')
             return Integration.createNew(filename, 'plain');
         }
-
     }
 
     function save(integration: Integration, propertyOnly: boolean): void {
diff --git a/karavan-space/src/designer/route/property/DslPropertyField.tsx b/karavan-space/src/designer/route/property/DslPropertyField.tsx
index 9ab39ce7..f42235dc 100644
--- a/karavan-space/src/designer/route/property/DslPropertyField.tsx
+++ b/karavan-space/src/designer/route/property/DslPropertyField.tsx
@@ -120,8 +120,9 @@ export function DslPropertyField(props: Props) {
 
     function arrayChanged(fieldId: string, value: string) {
         setArrayValues(prevState => {
-            prevState.set(fieldId, value);
-            return prevState;
+            const map: Map<string,string> = new Map<string, string>(prevState);
+            map.set(fieldId, value);
+            return map;
         })
     }
 
@@ -598,13 +599,16 @@ export function DslPropertyField(props: Props) {
     }
 
     function getMultiValueField(property: PropertyMeta, value: any) {
+        console.log(property)
         return (
             <div>
                 <TextInputGroup className="input-group">
                     <TextInputGroupMain value={arrayValues.get(property.name)}
-                                        onChange={(e, v) => arrayChanged(property.name, v)} onKeyUp={e => {
-                        if (e.key === 'Enter') arraySave(property.name)
-                    }}>
+                                        onChange={(e, v) => arrayChanged(property.name, v)}
+                                        onKeyUp={e => {
+                                            if (e.key === 'Enter') arraySave(property.name)
+                                        }}
+                    >
                         <ChipGroup>
                             {value && Array.from(value).map((v: any, index: number) => (
                                 <Chip key={"chip-" + index} className="chip"
@@ -654,6 +658,7 @@ export function DslPropertyField(props: Props) {
             </div>
         )
     }
+
     function getExpandableComponentParameters(properties: ComponentProperty[], label: string) {
         const element = props.element;
 
@@ -665,7 +670,7 @@ export function DslPropertyField(props: Props) {
                         if (isExpanded && !isShowAdvanced.includes(label)) {
                             prevState = [...prevState, label]
                         } else {
-                            prevState = prevState.filter(s => s!== label);
+                            prevState = prevState.filter(s => s !== label);
                         }
                         return prevState;
                     })
diff --git a/karavan-web/karavan-app/src/main/webui/src/designer/KaravanDesigner.tsx b/karavan-web/karavan-app/src/main/webui/src/designer/KaravanDesigner.tsx
index b1af73c5..eb967d0e 100644
--- a/karavan-web/karavan-app/src/main/webui/src/designer/KaravanDesigner.tsx
+++ b/karavan-web/karavan-app/src/main/webui/src/designer/KaravanDesigner.tsx
@@ -96,7 +96,6 @@ export function KaravanDesigner(props: Props) {
             EventBus.sendAlert("Error parsing YAML", (e as Error).message, 'danger')
             return Integration.createNew(filename, 'plain');
         }
-
     }
 
     function save(integration: Integration, propertyOnly: boolean): void {
diff --git a/karavan-web/karavan-app/src/main/webui/src/designer/route/property/DslPropertyField.tsx b/karavan-web/karavan-app/src/main/webui/src/designer/route/property/DslPropertyField.tsx
index 9ab39ce7..f42235dc 100644
--- a/karavan-web/karavan-app/src/main/webui/src/designer/route/property/DslPropertyField.tsx
+++ b/karavan-web/karavan-app/src/main/webui/src/designer/route/property/DslPropertyField.tsx
@@ -120,8 +120,9 @@ export function DslPropertyField(props: Props) {
 
     function arrayChanged(fieldId: string, value: string) {
         setArrayValues(prevState => {
-            prevState.set(fieldId, value);
-            return prevState;
+            const map: Map<string,string> = new Map<string, string>(prevState);
+            map.set(fieldId, value);
+            return map;
         })
     }
 
@@ -598,13 +599,16 @@ export function DslPropertyField(props: Props) {
     }
 
     function getMultiValueField(property: PropertyMeta, value: any) {
+        console.log(property)
         return (
             <div>
                 <TextInputGroup className="input-group">
                     <TextInputGroupMain value={arrayValues.get(property.name)}
-                                        onChange={(e, v) => arrayChanged(property.name, v)} onKeyUp={e => {
-                        if (e.key === 'Enter') arraySave(property.name)
-                    }}>
+                                        onChange={(e, v) => arrayChanged(property.name, v)}
+                                        onKeyUp={e => {
+                                            if (e.key === 'Enter') arraySave(property.name)
+                                        }}
+                    >
                         <ChipGroup>
                             {value && Array.from(value).map((v: any, index: number) => (
                                 <Chip key={"chip-" + index} className="chip"
@@ -654,6 +658,7 @@ export function DslPropertyField(props: Props) {
             </div>
         )
     }
+
     function getExpandableComponentParameters(properties: ComponentProperty[], label: string) {
         const element = props.element;
 
@@ -665,7 +670,7 @@ export function DslPropertyField(props: Props) {
                         if (isExpanded && !isShowAdvanced.includes(label)) {
                             prevState = [...prevState, label]
                         } else {
-                            prevState = prevState.filter(s => s!== label);
+                            prevState = prevState.filter(s => s !== label);
                         }
                         return prevState;
                     })
diff --git a/karavan-web/karavan-app/src/main/webui/src/designer/route/property/KameletPropertyField.tsx b/karavan-web/karavan-app/src/main/webui/src/designer/route/property/KameletPropertyField.tsx
index 0bac1c32..96b880c1 100644
--- a/karavan-web/karavan-app/src/main/webui/src/designer/route/property/KameletPropertyField.tsx
+++ b/karavan-web/karavan-app/src/main/webui/src/designer/route/property/KameletPropertyField.tsx
@@ -34,7 +34,6 @@ import ShowIcon from "@patternfly/react-icons/dist/js/icons/eye-icon";
 import HideIcon from "@patternfly/react-icons/dist/js/icons/eye-slash-icon";
 import DockerIcon from "@patternfly/react-icons/dist/js/icons/docker-icon";
 import {usePropertiesHook} from "../usePropertiesHook";
-import {CamelUi} from "../../utils/CamelUi";
 import {Select, SelectDirection, SelectOption, SelectVariant} from "@patternfly/react-core/deprecated";
 
 interface Props {


(camel-karavan) 01/03: Fix for #315

Posted by ma...@apache.org.
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 bd007b53bbb8161c1a1b488cfa2bd10fdcd21a45
Author: Marat Gubaidullin <ma...@talismancloud.io>
AuthorDate: Tue Oct 31 17:01:03 2023 -0400

    Fix for #315
---
 karavan-core/src/core/api/CamelDefinitionYaml.ts | 10 ++++
 karavan-core/src/core/api/CamelUtil.ts           | 33 ++++++++---
 karavan-core/test/createKamelet.spec.ts          | 38 ++++++++++++
 karavan-core/test/timer-source.kamelet.yaml      | 75 ++++++++++++++++++++++++
 4 files changed, 149 insertions(+), 7 deletions(-)

diff --git a/karavan-core/src/core/api/CamelDefinitionYaml.ts b/karavan-core/src/core/api/CamelDefinitionYaml.ts
index 7916801a..adc0cd3b 100644
--- a/karavan-core/src/core/api/CamelDefinitionYaml.ts
+++ b/karavan-core/src/core/api/CamelDefinitionYaml.ts
@@ -41,10 +41,20 @@ export class CamelDefinitionYaml {
             const route: RouteDefinition = clone.spec.flows.filter((f: any) => f.dslName === 'RouteDefinition')?.[0];
             if (route) {
                 template.route = Object.assign(template.route, route);
+            } else if (clone.spec.template?.route) {
+                template.route = clone.spec.template.route;
+            } else if (clone.spec.template?.from) {
+                template.route = {from: clone.spec.template?.from};
+            }
+            const from: RouteDefinition = clone.spec.flows.filter((f: any) => f.dslName === 'FromDefinition')?.[0];
+            if (from) {
+                template.from = {from: from};
             }
             const beans = clone.spec.flows.filter((f: any) => f.dslName === 'Beans')?.at(0)?.beans;
             if (beans) {
                 template.beans = beans;
+            } else if (clone.spec.template?.beans){
+                template.beans = clone.spec.template.beans;
             }
             clone.spec.template = template;
             delete clone.spec.flows;
diff --git a/karavan-core/src/core/api/CamelUtil.ts b/karavan-core/src/core/api/CamelUtil.ts
index 93544263..f98323e2 100644
--- a/karavan-core/src/core/api/CamelUtil.ts
+++ b/karavan-core/src/core/api/CamelUtil.ts
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-import { Integration, CamelElement, Beans } from '../model/IntegrationDefinition';
+import { Integration, CamelElement, Beans, MetadataLabels, KameletTypes } from '../model/IntegrationDefinition';
 import { CamelDefinitionApi } from './CamelDefinitionApi';
 import {
     KameletDefinition,
@@ -29,9 +29,11 @@ import { ComponentApi } from './ComponentApi';
 import { CamelMetadataApi } from '../model/CamelMetadata';
 import { CamelDefinitionApiExt } from './CamelDefinitionApiExt';
 import { v4 as uuidv4 } from 'uuid';
+import { CamelDefinitionYaml } from './CamelDefinitionYaml';
 
 export class CamelUtil {
-    private constructor() {}
+    private constructor() {
+    }
 
     static cloneIntegration = (integration: Integration): Integration => {
         const clone = JSON.parse(JSON.stringify(integration));
@@ -161,7 +163,7 @@ export class CamelUtil {
 
     static getKameletProperties = (element: any, requiredOnly: boolean = false): Property[] => {
         const kamelet = CamelUtil.getKamelet(element);
-        const props:Property[] = kamelet ? KameletApi.getKameletProperties(kamelet?.metadata.name) : [];
+        const props: Property[] = kamelet ? KameletApi.getKameletProperties(kamelet?.metadata.name) : [];
         if (requiredOnly) {
             const required = kamelet?.spec.definition.required;
             return props.filter(value => required?.includes(value.id));
@@ -188,9 +190,9 @@ export class CamelUtil {
                 const component = ComponentApi.findByName(name);
                 return component
                     ? ComponentApi.getComponentProperties(
-                          component?.component.name,
-                          element.dslName === 'FromDefinition' ? 'consumer' : 'producer',
-                      )
+                        component?.component.name,
+                        element.dslName === 'FromDefinition' ? 'consumer' : 'producer',
+                    )
                     : [];
             } else {
                 return [];
@@ -215,7 +217,7 @@ export class CamelUtil {
                     result[1].push(`${property.displayName} is required`);
                 } else if (property.type === 'ExpressionDefinition') {
                     const expressionMeta = CamelMetadataApi.getCamelModelMetadataByClassName('ExpressionDefinition');
-                    const expressionCheck = expressionMeta && value!== undefined && expressionMeta?.properties.some(ep => {
+                    const expressionCheck = expressionMeta && value !== undefined && expressionMeta?.properties.some(ep => {
                         const expValue = value[ep.name];
                         if (expValue) {
                             const checkedExpression = CamelUtil.checkRequired(expValue);
@@ -312,4 +314,21 @@ export class CamelUtil {
         const placeholder = val?.substring(start, end)?.trim();
         return [result, placeholder];
     };
+
+    static createNewKameletCode = (kameletName: string, kameletType: KameletTypes, copyFromKameletName?: string): string => {
+        const integration = Integration.createNew(kameletName, 'kamelet');
+        const meta: MetadataLabels = new MetadataLabels({ 'camel.apache.org/kamelet.type': kameletType });
+        integration.metadata.labels = meta;
+        if (copyFromKameletName !== undefined && copyFromKameletName !== '') {
+            const kamelet = KameletApi.getKamelets().filter(k => k.metadata.name === copyFromKameletName).at(0);
+            if (kamelet) {
+                (integration as any).spec = kamelet.spec;
+                (integration as any).metadata.labels = kamelet.metadata.labels;
+                (integration as any).metadata.annotations = kamelet.metadata.annotations;
+                const i = CamelUtil.cloneIntegration(integration);
+                return CamelDefinitionYaml.integrationToYaml(i);
+            }
+        }
+        return CamelDefinitionYaml.integrationToYaml(integration);
+    };
 }
diff --git a/karavan-core/test/createKamelet.spec.ts b/karavan-core/test/createKamelet.spec.ts
new file mode 100644
index 00000000..f675aa60
--- /dev/null
+++ b/karavan-core/test/createKamelet.spec.ts
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import { expect } from 'chai';
+import * as fs from 'fs';
+import 'mocha';
+import { CamelUtil } from '../src/core/api/CamelUtil';
+import { KameletApi } from '../src/core/api/KameletApi';
+
+
+describe('Create Kamelet', () => {
+
+    it('Create new Kamelet from existing', () => {
+        const kamelet = fs.readFileSync('test/timer-source.kamelet.yaml', { encoding: 'utf8', flag: 'r' });
+        KameletApi.saveKamelets([kamelet]);
+        const code = CamelUtil.createNewKameletCode("custom-timer-source.kamelet.yaml", 'source', "timer-source")
+        console.log(code);
+        // if (i.spec.flows) {
+        //     expect(i.spec.flows[2].beans[0].name).to.equal('myNested');
+        //     expect(i.spec.flows[2].beans[0].type).to.equal('${MyBean.class.name}');
+        //     expect(i.spec.flows[2].beans[0].properties['nested.foo']).to.equal('valueFoo');
+        //     expect(i.spec.flows[2].beans[1].name).to.equal('myProps');
+        // }
+    });
+});
diff --git a/karavan-core/test/timer-source.kamelet.yaml b/karavan-core/test/timer-source.kamelet.yaml
new file mode 100644
index 00000000..e72b6034
--- /dev/null
+++ b/karavan-core/test/timer-source.kamelet.yaml
@@ -0,0 +1,75 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+
+apiVersion: camel.apache.org/v1
+kind: Kamelet
+metadata:
+  name: timer-source
+  annotations:
+    camel.apache.org/kamelet.support.level: "Stable"
+    camel.apache.org/catalog.version: "4.2.0-SNAPSHOT"
+    camel.apache.org/kamelet.icon: data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gU3ZnIFZlY3RvciBJY29ucyA6IGh0dHA6Ly93d3cub25saW5ld2ViZm9udHMuY29tL2ljb24gLS0+DQo8IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPg0KPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm9 [...]
+    camel.apache.org/provider: "Apache Software Foundation"
+    camel.apache.org/kamelet.group: "Timer"
+    camel.apache.org/kamelet.namespace: "Scheduling"
+  labels:
+    camel.apache.org/kamelet.type: source
+    camel.apache.org/kamelet.verified: "true"
+spec:
+  definition:
+    title: Timer Source
+    description: Produces periodic messages with a custom payload.
+    required:
+      - message
+    type: object
+    properties:
+      period:
+        title: Period
+        description: "The interval (in milliseconds) to wait between producing the next message."
+        type: integer
+        default: 1000
+      message:
+        title: Message
+        description: The message to generate.
+        type: string
+        example: hello world
+      contentType:
+        title: Content Type
+        description: The content type of the generated message.
+        type: string
+        default: text/plain
+      repeatCount:
+        title: Repeat Count
+        description: Specifies a maximum limit of number of fires
+        type: integer
+  dependencies:
+    - "camel:core"
+    - "camel:timer"
+    - "camel:kamelet"
+  template:
+    from:
+      uri: timer:tick
+      parameters:
+        period: "{{period}}"
+        repeatCount: "{{?repeatCount}}"
+      steps:
+        - set-body:
+            constant: "{{message}}"
+        - set-header:
+            name: "Content-Type"
+            constant: "{{contentType}}"
+        - to: kamelet:sink
\ No newline at end of file