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

Fix #706 Improve RuntimeCatalogConfig docs #1009

Merged
merged 1 commit into from
Apr 4, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class CamelConfig {
public ServiceConfig service;

/**
* Build time configuration options for {@link RuntimeCatalogConfig}.
* Build time configuration options for {@link org.apache.camel.catalog.RuntimeCamelCatalog}.
*/
@ConfigItem
public RuntimeCatalogConfig runtimeCatalog;
Expand Down Expand Up @@ -290,41 +290,45 @@ public static class ReflectionConfig {
@ConfigGroup
public static class RuntimeCatalogConfig {
/**
* Used to control the resolution of components catalog info.
* If {@code true} the Runtime Camel Catalog embedded in the application will contain JSON schemas of Camel
* components available in the application; otherwise component JSON schemas will not be available in the
* Runtime Camel Catalog and any attempt to access those will result in a RuntimeException.
* <p>
* Note that when building native images, this flag determine if the json metadata files related to components
* discovered at build time have to be included in the final binary. In JVM mode there is no real benefit of
* setting this flag to {@code false} if not to make the behavior consistent with native mode.
* Setting this to {@code false} helps to reduce the size of the native image. In JVM mode, there is no real
* benefit of setting this flag to {@code false} except for making the behavior consistent with native mode.
*/
@ConfigItem(defaultValue = "true")
public boolean components;

/**
* Used to control the resolution of languages catalog info.
* If {@code true} the Runtime Camel Catalog embedded in the application will contain JSON schemas of Camel
* languages available in the application; otherwise language JSON schemas will not be available in the
* Runtime Camel Catalog and any attempt to access those will result in a RuntimeException.
* <p>
* Note that when building native images, this flag determine if the json metadata files related to languages
* discovered at build time have to be included in the final binary. In JVM mode there is no real benefit of
* setting this flag to {@code false} if not to make the behavior consistent with native mode.
* Setting this to {@code false} helps to reduce the size of the native image. In JVM mode, there is no real
* benefit of setting this flag to {@code false} except for making the behavior consistent with native mode.
*/
@ConfigItem(defaultValue = "true")
public boolean languages;

/**
* Used to control the resolution of dataformats catalog info.
* If {@code true} the Runtime Camel Catalog embedded in the application will contain JSON schemas of Camel
* data formats available in the application; otherwise data format JSON schemas will not be available in the
* Runtime Camel Catalog and any attempt to access those will result in a RuntimeException.
* <p>
* Note that when building native images, this flag determine if the json metadata files related to dataformats
* discovered at build time have to be included in the final binary. In JVM mode there is no real benefit of
* setting this flag to {@code false} if not to make the behavior consistent with native mode.
* Setting this to {@code false} helps to reduce the size of the native image. In JVM mode, there is no real
* benefit of setting this flag to {@code false} except for making the behavior consistent with native mode.
*/
@ConfigItem(defaultValue = "true")
public boolean dataformats;

/**
* Used to control the resolution of model catalog info.
* If {@code true} the Runtime Camel Catalog embedded in the application will contain JSON schemas of Camel
* EIP models available in the application; otherwise EIP model JSON schemas will not be available in the
* Runtime Camel Catalog and any attempt to access those will result in a RuntimeException.
* <p>
* Note that when building native images, this flag determine if the json metadata files related to models
* has to be included in the final binary. In JVM mode there is no real benefit of setting this flag to
* {@code false} if not to make the behavior consistent with native mode.
* Setting this to {@code false} helps to reduce the size of the native image. In JVM mode, there is no real
* benefit of setting this flag to {@code false} except for making the behavior consistent with native mode.
*/
@ConfigItem(defaultValue = "true")
public boolean models;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public CamelRuntimeCatalog(CamelConfig.RuntimeCatalogConfig config) {
@Override
public String modelJSonSchema(String name) {
if (!config.models) {
return null;
throw new RuntimeException(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to check if throwing an exception is the right thing, I do not remember if there is any assumption in the code path that invokes this method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a troll, I have put it there to see who and how is actually using it :) I have fixed the tests in fc0bdf6. Are you using it in Camel K?

"Accessing model JSON schemas was disabled via quarkus.camel.runtime-catalog.models = false");
}

return super.modelJSonSchema(name);
Expand All @@ -37,7 +38,8 @@ public String modelJSonSchema(String name) {
@Override
public String componentJSonSchema(String name) {
if (!config.components) {
return null;
throw new RuntimeException(
"Accessing component JSON schemas was disabled via quarkus.camel.runtime-catalog.components = false");
}

return super.componentJSonSchema(name);
Expand All @@ -46,7 +48,8 @@ public String componentJSonSchema(String name) {
@Override
public String dataFormatJSonSchema(String name) {
if (!config.dataformats) {
return null;
throw new RuntimeException(
"Accessing data format JSON schemas was disabled via quarkus.camel.runtime-catalog.dataformats = false");
}

return super.dataFormatJSonSchema(name);
Expand All @@ -55,7 +58,8 @@ public String dataFormatJSonSchema(String name) {
@Override
public String languageJSonSchema(String name) {
if (!config.languages) {
return null;
throw new RuntimeException(
"Accessing language JSON schemas was disabled via quarkus.camel.runtime-catalog.languages = false");
}

return super.languageJSonSchema(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,30 @@ public boolean adaptToExtendedCamelContext() {
@Path("/catalog/{type}/{name}")
@GET
@Produces(MediaType.APPLICATION_JSON)
public String catalog(@PathParam("type") String type, @PathParam("name") String name) throws IOException {
public Response catalog(@PathParam("type") String type, @PathParam("name") String name) throws IOException {
final CamelRuntimeCatalog catalog = (CamelRuntimeCatalog) context.getExtension(RuntimeCamelCatalog.class);

switch (type) {
case "component":
return catalog.componentJSonSchema(name);
case "language":
return catalog.languageJSonSchema(name);
case "dataformat":
return catalog.dataFormatJSonSchema(name);
case "model":
return catalog.modelJSonSchema(name);
default:
throw new IllegalArgumentException("Unknown type " + type);
try {
final String schema;
switch (type) {
case "component":
schema = catalog.componentJSonSchema(name);
break;
case "language":
schema = catalog.languageJSonSchema(name);
break;
case "dataformat":
schema = catalog.dataFormatJSonSchema(name);
break;
case "model":
schema = catalog.modelJSonSchema(name);
break;
default:
throw new IllegalArgumentException("Unknown type " + type);
}
return Response.ok(schema).build();
} catch (Exception e) {
return Response.serverError().entity(e.getClass().getSimpleName() + ": " + e.getMessage()).build();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public void testResolveLanguages() {
@Test
public void testCatalogComponent() throws IOException {
RestAssured.when().get("/test/catalog/component/timer").then().body(not(emptyOrNullString()));
RestAssured.when().get("/test/catalog/language/simple").then().body(emptyOrNullString());
RestAssured.when().get("/test/catalog/language/simple").then().statusCode(500).body(is(
"RuntimeException: Accessing language JSON schemas was disabled via quarkus.camel.runtime-catalog.languages = false"));
}

@Test
Expand Down