Skip to content

Commit

Permalink
Fix #1262
Browse files Browse the repository at this point in the history
  • Loading branch information
mgubaidullin committed May 7, 2024
1 parent edb92d3 commit 719ade0
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 14 deletions.
1 change: 1 addition & 0 deletions karavan-app/src/main/webui/src/designer/utils/CamelUi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const StepElements: string[] = [
"FilterDefinition",
"IdempotentConsumerDefinition",
// "KameletDefinition",
"LoadBalanceDefinition",
"LogDefinition",
"LoopDefinition",
"MarshalDefinition",
Expand Down
26 changes: 13 additions & 13 deletions karavan-core/src/core/model/CamelDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3123,60 +3123,60 @@ export class CustomLoadBalancerDefinition extends CamelElement {
}

export class FailoverLoadBalancerDefinition extends CamelElement {
stepName?: string = 'failoverLoadBalancer';
stepName?: string = 'failover';
id?: string = 'failover-' + uuidv4().substring(0,4);
exception?: string[] = [];
id?: string = 'failoverLoadBalancer-' + uuidv4().substring(0,4);
maximumFailoverAttempts?: string;
roundRobin?: string;
sticky?: string;
maximumFailoverAttempts?: string;
public constructor(init?: Partial<FailoverLoadBalancerDefinition>) {
super('FailoverLoadBalancerDefinition');
Object.assign(this, init);
}
}

export class RandomLoadBalancerDefinition extends CamelElement {
stepName?: string = 'randomLoadBalancer';
id?: string = 'randomLoadBalancer-' + uuidv4().substring(0,4);
stepName?: string = 'random';
id?: string = 'random-' + uuidv4().substring(0,4);
public constructor(init?: Partial<RandomLoadBalancerDefinition>) {
super('RandomLoadBalancerDefinition');
Object.assign(this, init);
}
}

export class RoundRobinLoadBalancerDefinition extends CamelElement {
stepName?: string = 'roundRobinLoadBalancer';
id?: string = 'roundRobinLoadBalancer-' + uuidv4().substring(0,4);
stepName?: string = 'roundRobin';
id?: string = 'roundRobin-' + uuidv4().substring(0,4);
public constructor(init?: Partial<RoundRobinLoadBalancerDefinition>) {
super('RoundRobinLoadBalancerDefinition');
Object.assign(this, init);
}
}

export class StickyLoadBalancerDefinition extends CamelElement {
stepName?: string = 'stickyLoadBalancer';
stepName?: string = 'sticky';
id?: string = 'sticky-' + uuidv4().substring(0,4);
correlationExpression?: ExpressionSubElementDefinition;
id?: string = 'stickyLoadBalancer-' + uuidv4().substring(0,4);
public constructor(init?: Partial<StickyLoadBalancerDefinition>) {
super('StickyLoadBalancerDefinition');
Object.assign(this, init);
}
}

export class TopicLoadBalancerDefinition extends CamelElement {
stepName?: string = 'topicLoadBalancer';
id?: string = 'topicLoadBalancer-' + uuidv4().substring(0,4);
stepName?: string = 'topic';
id?: string = 'topic-' + uuidv4().substring(0,4);
public constructor(init?: Partial<TopicLoadBalancerDefinition>) {
super('TopicLoadBalancerDefinition');
Object.assign(this, init);
}
}

export class WeightedLoadBalancerDefinition extends CamelElement {
stepName?: string = 'weightedLoadBalancer';
stepName?: string = 'weighted';
id?: string = 'weighted-' + uuidv4().substring(0,4);
distributionRatio: string = '';
distributionRatioDelimiter?: string;
id?: string = 'weightedLoadBalancer-' + uuidv4().substring(0,4);
roundRobin?: boolean;
public constructor(init?: Partial<WeightedLoadBalancerDefinition>) {
super('WeightedLoadBalancerDefinition');
Expand Down
32 changes: 32 additions & 0 deletions karavan-core/src/core/model/CamelMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2312,6 +2312,38 @@ export const CamelModelMetadata: ElementMeta[] = [
new PropertyMeta('ref', 'Ref', "Refers to the custom load balancer to lookup from the registry", 'string', '', '', true, false, false, false, '', ''),
], [
]),
new ElementMeta('failover', 'FailoverLoadBalancerDefinition', 'Failover', "In case of failures the exchange will be tried on the next endpoint.", 'eip,routing', [
new PropertyMeta('id', 'Id', "The id of this node", 'string', '', '', false, false, false, false, '', ''),
new PropertyMeta('exception', 'Exception', "A list of class names for specific exceptions to monitor. If no exceptions are configured then all exceptions are monitored", 'string', '', '', false, false, true, true, '', ''),
new PropertyMeta('roundRobin', 'Round Robin', "Whether or not the failover load balancer should operate in round robin mode or not. If not, then it will always start from the first endpoint when a new message is to be processed. In other words it restart from the top for every message. If round robin is enabled, then it keeps state and will continue with the next endpoint in a round robin fashion. You can also enable sticky mode together with round robin, if so then it will pick the last known good endpoint to use when starting the load balancing (instead of using the next when starting).", 'string', '', '', false, false, false, false, '', ''),
new PropertyMeta('sticky', 'Sticky', "Whether or not the failover load balancer should operate in sticky mode or not. If not, then it will always start from the first endpoint when a new message is to be processed. In other words it restart from the top for every message. If sticky is enabled, then it keeps state and will continue with the last known good endpoint. You can also enable sticky mode together with round robin, if so then it will pick the last known good endpoint to use when starting the load balancing (instead of using the next when starting).", 'string', '', '', false, false, false, false, '', ''),
new PropertyMeta('maximumFailoverAttempts', 'Maximum Failover Attempts', "A value to indicate after X failover attempts we should exhaust (give up). Use -1 to indicate never give up and continuously try to failover. Use 0 to never failover. And use e.g. 3 to failover at most 3 times before giving up. his option can be used whether or not roundRobin is enabled or not.", 'string', '', '-1', false, false, false, false, '', ''),
], [
]),
new ElementMeta('random', 'RandomLoadBalancerDefinition', 'Random', "The destination endpoints are selected randomly.", 'eip,routing', [
new PropertyMeta('id', 'Id', "The id of this node", 'string', '', '', false, false, false, false, '', ''),
], [
]),
new ElementMeta('roundRobin', 'RoundRobinLoadBalancerDefinition', 'Round Robin', "The destination endpoints are selected in a round-robin fashion. This is a well-known and classic policy, which spreads the load evenly.", 'eip,routing', [
new PropertyMeta('id', 'Id', "The id of this node", 'string', '', '', false, false, false, false, '', ''),
], [
]),
new ElementMeta('sticky', 'StickyLoadBalancerDefinition', 'Sticky', "Sticky load balancing using an expression to calculate a correlation key to perform the sticky load balancing.", 'eip,routing', [
new PropertyMeta('id', 'Id', "The id of this node", 'string', '', '', false, false, false, false, '', ''),
new PropertyMeta('correlationExpression', 'Correlation Expression', "The correlation expression to use to calculate the correlation key", 'ExpressionSubElementDefinition', '', '', true, false, false, true, '', ''),
], [
]),
new ElementMeta('topic', 'TopicLoadBalancerDefinition', 'Topic', "Topic which sends to all destinations.", 'eip,routing', [
new PropertyMeta('id', 'Id', "The id of this node", 'string', '', '', false, false, false, false, '', ''),
], [
]),
new ElementMeta('weighted', 'WeightedLoadBalancerDefinition', 'Weighted', "Uses a weighted load distribution ratio for each server with respect to others.", 'eip,routing', [
new PropertyMeta('id', 'Id', "The id of this node", 'string', '', '', false, false, false, false, '', ''),
new PropertyMeta('distributionRatio', 'Distribution Ratio', "The distribution ratio is a delimited String consisting on integer weights separated by delimiters for example 2,3,5. The distributionRatio must match the number of endpoints and/or processors specified in the load balancer list.", 'string', '', '', true, false, false, false, '', ''),
new PropertyMeta('distributionRatioDelimiter', 'Distribution Ratio Delimiter', "Delimiter used to specify the distribution ratio. The default value is , (comma)", 'string', '', ',', false, false, false, false, 'advanced', ''),
new PropertyMeta('roundRobin', 'Round Robin', "To enable round robin mode. By default the weighted distribution mode is used. The default value is false.", 'boolean', '', 'false', false, false, false, false, 'advanced', ''),
], [
]),
new ElementMeta('apiKey', 'ApiKeyDefinition', 'Api Key', "Rest security basic auth definition", 'rest,security,configuration', [
new PropertyMeta('description', 'Description', "A short description for security scheme.", 'string', '', '', false, false, false, false, '', ''),
new PropertyMeta('name', 'Name', "The name of the header or query parameter to be used.", 'string', '', '', true, false, false, false, '', ''),
Expand Down
1 change: 1 addition & 0 deletions karavan-designer/src/designer/utils/CamelUi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const StepElements: string[] = [
"FilterDefinition",
"IdempotentConsumerDefinition",
// "KameletDefinition",
"LoadBalanceDefinition",
"LogDefinition",
"LoopDefinition",
"MarshalDefinition",
Expand Down
2 changes: 1 addition & 1 deletion karavan-generator/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.camel.karavan</groupId>
<artifactId>karavan-generator</artifactId>
<version>4.5.0</version>
<version>4.5.1</version>
<build>
<resources>
<resource>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ protected String getStepNameForClass(String className) {
className = "streamConfig";
} else if (className.equals("RestSecuritiesDefinition")) {
className = "securityDefinitions";
} else if (className.endsWith("LoadBalancerDefinition")) {
return getLoadBalancerDefinitionStepNameForClass(className);
} else if (className.endsWith("Definition")) {
className = className.substring(0, className.length() - 10);
} else if (className.endsWith("DataFormat")) {
Expand All @@ -100,6 +102,15 @@ protected String getStepNameForClass(String className) {
return deCapitalize(className);
}

protected String getLoadBalancerDefinitionStepNameForClass(String className) {
if (Objects.equals("CustomLoadBalancerDefinition", className)) {
className = className.substring(0, className.length() - 10);
} else {
className = className.substring(0, className.length() - 22);
}
return deCapitalize(className);
}

protected Map<String, String> getDataFormatStepNameForClass() {
Map<String, String> stepNames = new LinkedHashMap<>();
JsonObject definitions = getDefinitions();
Expand Down
1 change: 1 addition & 0 deletions karavan-space/src/designer/utils/CamelUi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const StepElements: string[] = [
"FilterDefinition",
"IdempotentConsumerDefinition",
// "KameletDefinition",
"LoadBalanceDefinition",
"LogDefinition",
"LoopDefinition",
"MarshalDefinition",
Expand Down

0 comments on commit 719ade0

Please sign in to comment.