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

Jbang profile #13458

Merged
merged 2 commits into from Mar 12, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -84,6 +84,7 @@
{ "name": "camel.main.modeline", "description": "Whether camel-k style modeline is also enabled when not using camel-k. Enabling this allows to use a camel-k like experience by being able to configure various settings using modeline directly in your route source code.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" },
{ "name": "camel.main.name", "description": "Sets the name of the CamelContext.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.main.producerTemplateCacheSize", "description": "Producer template endpoints cache size.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "integer", "javaType": "int", "defaultValue": 1000 },
{ "name": "camel.main.profile", "description": "Camel profile to use when running. The dev profile is for development, which enables a set of additional developer focus functionality, tracing, debugging, and gathering additional runtime statistics that are useful during development. However, those additional features has a slight overhead cost, and are not enabled for production profile. The default profile is prod.", "sourceType": "org.apache.camel.main.MainConfigurationProperties", "type": "string", "javaType": "java.lang.String", "enum": [ "dev", "test", "prod" ] },
{ "name": "camel.main.routeFilterExcludePattern", "description": "Used for filtering routes routes matching the given pattern, which follows the following rules: - Match by route id - Match by route input endpoint uri The matching is using exact match, by wildcard and regular expression as documented by PatternHelper#matchPattern(String,String) . For example to only include routes which starts with foo in their route id's, use: include=foo* And to exclude routes which starts from JMS endpoints, use: exclude=jms:* Multiple patterns can be separated by comma, for example to exclude both foo and bar routes, use: exclude=foo*,bar* Exclude takes precedence over include.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.main.routeFilterIncludePattern", "description": "Used for filtering routes matching the given pattern, which follows the following rules: - Match by route id - Match by route input endpoint uri The matching is using exact match, by wildcard and regular expression as documented by PatternHelper#matchPattern(String,String) . For example to only include routes which starts with foo in their route id's, use: include=foo* And to exclude routes which starts from JMS endpoints, use: exclude=jms:* Multiple patterns can be separated by comma, for example to exclude both foo and bar routes, use: exclude=foo*,bar* Exclude takes precedence over include.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.main.routesBuilderClasses", "description": "Sets classes names that implement RoutesBuilder .", "sourceType": "org.apache.camel.main.MainConfigurationProperties", "type": "string", "javaType": "java.lang.String" },
Expand Down
Expand Up @@ -151,6 +151,8 @@ public boolean configure(CamelContext camelContext, Object obj, String name, Obj
case "Name": target.setName(property(camelContext, java.lang.String.class, value)); return true;
case "producertemplatecachesize":
case "ProducerTemplateCacheSize": target.setProducerTemplateCacheSize(property(camelContext, int.class, value)); return true;
case "profile":
case "Profile": target.setProfile(property(camelContext, java.lang.String.class, value)); return true;
case "routefilterexcludepattern":
case "RouteFilterExcludePattern": target.setRouteFilterExcludePattern(property(camelContext, java.lang.String.class, value)); return true;
case "routefilterincludepattern":
Expand Down Expand Up @@ -390,6 +392,8 @@ public Class<?> getOptionType(String name, boolean ignoreCase) {
case "Name": return java.lang.String.class;
case "producertemplatecachesize":
case "ProducerTemplateCacheSize": return int.class;
case "profile":
case "Profile": return java.lang.String.class;
case "routefilterexcludepattern":
case "RouteFilterExcludePattern": return java.lang.String.class;
case "routefilterincludepattern":
Expand Down Expand Up @@ -630,6 +634,8 @@ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
case "Name": return target.getName();
case "producertemplatecachesize":
case "ProducerTemplateCacheSize": return target.getProducerTemplateCacheSize();
case "profile":
case "Profile": return target.getProfile();
case "routefilterexcludepattern":
case "RouteFilterExcludePattern": return target.getRouteFilterExcludePattern();
case "routefilterincludepattern":
Expand Down
Expand Up @@ -84,6 +84,7 @@
{ "name": "camel.main.modeline", "description": "Whether camel-k style modeline is also enabled when not using camel-k. Enabling this allows to use a camel-k like experience by being able to configure various settings using modeline directly in your route source code.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" },
{ "name": "camel.main.name", "description": "Sets the name of the CamelContext.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.main.producerTemplateCacheSize", "description": "Producer template endpoints cache size.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "integer", "javaType": "int", "defaultValue": 1000 },
{ "name": "camel.main.profile", "description": "Camel profile to use when running. The dev profile is for development, which enables a set of additional developer focus functionality, tracing, debugging, and gathering additional runtime statistics that are useful during development. However, those additional features has a slight overhead cost, and are not enabled for production profile. The default profile is prod.", "sourceType": "org.apache.camel.main.MainConfigurationProperties", "type": "string", "javaType": "java.lang.String", "enum": [ "dev", "test", "prod" ] },
{ "name": "camel.main.routeFilterExcludePattern", "description": "Used for filtering routes routes matching the given pattern, which follows the following rules: - Match by route id - Match by route input endpoint uri The matching is using exact match, by wildcard and regular expression as documented by PatternHelper#matchPattern(String,String) . For example to only include routes which starts with foo in their route id's, use: include=foo&#42; And to exclude routes which starts from JMS endpoints, use: exclude=jms:&#42; Multiple patterns can be separated by comma, for example to exclude both foo and bar routes, use: exclude=foo&#42;,bar&#42; Exclude takes precedence over include.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.main.routeFilterIncludePattern", "description": "Used for filtering routes matching the given pattern, which follows the following rules: - Match by route id - Match by route input endpoint uri The matching is using exact match, by wildcard and regular expression as documented by PatternHelper#matchPattern(String,String) . For example to only include routes which starts with foo in their route id's, use: include=foo&#42; And to exclude routes which starts from JMS endpoints, use: exclude=jms:&#42; Multiple patterns can be separated by comma, for example to exclude both foo and bar routes, use: exclude=foo&#42;,bar&#42; Exclude takes precedence over include.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.main.routesBuilderClasses", "description": "Sets classes names that implement RoutesBuilder .", "sourceType": "org.apache.camel.main.MainConfigurationProperties", "type": "string", "javaType": "java.lang.String" },
Expand Down
3 changes: 2 additions & 1 deletion core/camel-main/src/main/docs/main.adoc
Expand Up @@ -19,7 +19,7 @@ The following tables lists all the options:

// main options: START
=== Camel Main configurations
The camel.main supports 116 options, which are listed below.
The camel.main supports 117 options, which are listed below.

[width="100%",cols="2,5,^1,2",options="header"]
|===
Expand Down Expand Up @@ -89,6 +89,7 @@ The camel.main supports 116 options, which are listed below.
| *camel.main.modeline* | Whether camel-k style modeline is also enabled when not using camel-k. Enabling this allows to use a camel-k like experience by being able to configure various settings using modeline directly in your route source code. | false | boolean
| *camel.main.name* | Sets the name of the CamelContext. | | String
| *camel.main.producerTemplate{zwsp}CacheSize* | Producer template endpoints cache size. | 1000 | int
| *camel.main.profile* | Camel profile to use when running. The dev profile is for development, which enables a set of additional developer focus functionality, tracing, debugging, and gathering additional runtime statistics that are useful during development. However, those additional features has a slight overhead cost, and are not enabled for production profile. The default profile is prod. | | String
| *camel.main.routeFilterExclude{zwsp}Pattern* | Used for filtering routes routes matching the given pattern, which follows the following rules: - Match by route id - Match by route input endpoint uri The matching is using exact match, by wildcard and regular expression as documented by PatternHelper#matchPattern(String,String) . For example to only include routes which starts with foo in their route id's, use: include=foo&#42; And to exclude routes which starts from JMS endpoints, use: exclude=jms:&#42; Multiple patterns can be separated by comma, for example to exclude both foo and bar routes, use: exclude=foo&#42;,bar&#42; Exclude takes precedence over include. | | String
| *camel.main.routeFilterInclude{zwsp}Pattern* | Used for filtering routes matching the given pattern, which follows the following rules: - Match by route id - Match by route input endpoint uri The matching is using exact match, by wildcard and regular expression as documented by PatternHelper#matchPattern(String,String) . For example to only include routes which starts with foo in their route id's, use: include=foo&#42; And to exclude routes which starts from JMS endpoints, use: exclude=jms:&#42; Multiple patterns can be separated by comma, for example to exclude both foo and bar routes, use: exclude=foo&#42;,bar&#42; Exclude takes precedence over include. | | String
| *camel.main.routesBuilder{zwsp}Classes* | Sets classes names that implement RoutesBuilder . | | String
Expand Down
Expand Up @@ -432,6 +432,9 @@ protected void autoconfigure(CamelContext camelContext) throws Exception {
// gathers the properties (key=value) that was auto-configured
final OrderedLocationProperties autoConfiguredProperties = new OrderedLocationProperties();

// configure the profile with pre-configured settings
ProfileConfigurer.configure(camelContext, mainConfigurationProperties.getProfile(), mainConfigurationProperties);

// need to eager allow to auto-configure properties component
if (mainConfigurationProperties.isAutoConfigurationEnabled()) {
autoConfigurationFailFast(camelContext, autoConfiguredProperties);
Expand Down
Expand Up @@ -26,6 +26,7 @@
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.spi.BootstrapCloseable;
import org.apache.camel.spi.Configurer;
import org.apache.camel.spi.Metadata;

/**
* Global configuration for Camel Main to configure context name, stream caching and other global configurations.
Expand All @@ -34,6 +35,8 @@
public class MainConfigurationProperties extends DefaultConfigurationProperties<MainConfigurationProperties>
implements BootstrapCloseable {

@Metadata(enums = "dev,test,prod")
private String profile;
private boolean autoConfigurationEnabled = true;
private boolean autoConfigurationEnvironmentVariablesEnabled = true;
private boolean autoConfigurationSystemPropertiesEnabled = true;
Expand Down Expand Up @@ -382,6 +385,23 @@ public boolean hasVaultConfiguration() {
// getter and setters
// --------------------------------------------------------------

public String getProfile() {
return profile;
}

/**
* Camel profile to use when running.
*
* The dev profile is for development, which enables a set of additional developer focus functionality, tracing,
* debugging, and gathering additional runtime statistics that are useful during development. However, those
* additional features has a slight overhead cost, and are not enabled for production profile.
*
* The default profile is prod.
*/
public void setProfile(String profile) {
this.profile = profile;
}

public boolean isAutoConfigurationEnabled() {
return autoConfigurationEnabled;
}
Expand Down Expand Up @@ -636,6 +656,20 @@ public void configure() throws Exception {
// fluent builders
// --------------------------------------------------------------

/**
* Camel profile to use when running.
*
* The dev profile is for development, which enables a set of additional developer focus functionality, tracing,
* debugging, and gathering additional runtime statistics that are useful during development. However, those
* additional features has a slight overhead cost, and are not enabled for production profile.
*
* The default profile is prod.
*/
public MainConfigurationProperties withProfile(String profile) {
this.profile = profile;
return this;
}

/**
* Whether auto configuration of components/dataformats/languages is enabled or not. When enabled the configuration
* parameters are loaded from the properties component and configured as defaults (similar to spring-boot
Expand Down
@@ -0,0 +1,66 @@
/*
* 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.
*/
package org.apache.camel.main;

import org.apache.camel.CamelContext;
import org.apache.camel.ManagementStatisticsLevel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Configure Camel Main with the chosen profile.
*
* This is for Camel JBang and Standalone Camel, not Spring Boot or Quarkus; as they have their own profile concept.
*/
public class ProfileConfigurer {

protected static final Logger LOG = LoggerFactory.getLogger(ProfileConfigurer.class);

public static void configure(CamelContext camelContext, String profile, MainConfigurationProperties config)
throws Exception {
if (profile == null || "prod".equals(profile)) {
LOG.info("The application is starting with profile: production");
return; // no need to do special configuration
}
if ("test".equals(profile)) {
LOG.info("The application is starting with profile: test");
return; // current no special configuration
}
if ("dev".equals(profile)) {
LOG.info("The application is starting with profile: dev");
// always enable developer console as it is needed by camel-cli-connector
config.setDevConsoleEnabled(true);
// and enable a bunch of other stuff that gives more details for developers
config.setCamelEventsTimestampEnabled(true);
config.setLoadHealthChecks(true);
config.setSourceLocationEnabled(true);
config.setModeline(true);
config.setLoadStatisticsEnabled(true);
config.setMessageHistory(true);
config.setInflightRepositoryBrowseEnabled(true);
config.setEndpointRuntimeStatisticsEnabled(true);
config.setJmxManagementStatisticsLevel(ManagementStatisticsLevel.Extended);
config.setJmxUpdateRouteEnabled(true);
config.setShutdownLogInflightExchangesOnTimeout(false);
config.setShutdownTimeout(10);
config.setStartupRecorder("backlog");
// enable backlog tracing
config.tracerConfig().withEnabled(true);
}
}

}
Expand Up @@ -166,6 +166,14 @@ We also renamed the `route-curcuit-breaker` console to `circuit-breaker`.

=== camel-jbang

The `--profile` option on `export` command has been removed.

The `--profile` option on `run` command is now used by `camel-main` to choose profile mode when running Camel with JBang,
or standalone with Camel Main. The default mode is `dev` for development which comes with some additional features enabled
in Camel to gather more information that are relevant for development and the Camel JBang CLI.

You can run with `--profile=prod` to turn off all of this, which makes Camel run more similar to a production situation.

The command `camel generate rest` have removed all the shorthand arguments `such as `-i -o` instead use the long names `--input --output`.

=== camel-jsonpath
Expand Down