Skip to content

Commit

Permalink
Remove Capability capability
Browse files Browse the repository at this point in the history
  • Loading branch information
Croway committed Oct 2, 2024
1 parent 6da8e94 commit 1134f97
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.net.URISyntaxException;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import org.apache.camel.tooling.model.ArtifactModel;
Expand All @@ -30,7 +29,6 @@
import org.apache.camel.tooling.model.DataFormatModel;
import org.apache.camel.tooling.model.DevConsoleModel;
import org.apache.camel.tooling.model.EipModel;
import org.apache.camel.tooling.model.EntityRef;
import org.apache.camel.tooling.model.Kind;
import org.apache.camel.tooling.model.LanguageModel;
import org.apache.camel.tooling.model.MainModel;
Expand Down Expand Up @@ -224,11 +222,6 @@ public interface CamelCatalog {
*/
List<String> findBeansNames();

/**
* Find all the capability names from the Camel catalog
*/
List<String> findCapabilityNames();

/**
* @param kind the kind to look for
* @return the list of part names of the given {@link Kind} available in this {@link CamelCatalog}
Expand Down Expand Up @@ -645,8 +638,4 @@ default BaseModel<? extends BaseOptionModel> model(Kind kind, String name) {
*/
List<ReleaseModel> camelQuarkusReleases();

/**
* Find the entity the given capability maps to.
*/
Optional<EntityRef> findCapabilityRef(String capability);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
Expand All @@ -41,9 +40,7 @@
import org.apache.camel.tooling.model.DataFormatModel;
import org.apache.camel.tooling.model.DevConsoleModel;
import org.apache.camel.tooling.model.EipModel;
import org.apache.camel.tooling.model.EntityRef;
import org.apache.camel.tooling.model.JsonMapper;
import org.apache.camel.tooling.model.Kind;
import org.apache.camel.tooling.model.LanguageModel;
import org.apache.camel.tooling.model.MainModel;
import org.apache.camel.tooling.model.OtherModel;
Expand Down Expand Up @@ -312,11 +309,6 @@ public List<String> findOtherNames(String filter) {
return findNames(filter, this::findOtherNames, this::otherModel);
}

@Override
public List<String> findCapabilityNames() {
return List.copyOf(runtimeProvider.findCapabilities().keySet());
}

private List<String> findNames(
String filter, Supplier<List<String>> findNames, Function<String, ? extends BaseModel<?>> modelLoader) {
List<String> answer = new ArrayList<>();
Expand Down Expand Up @@ -645,23 +637,6 @@ public List<ReleaseModel> camelQuarkusReleases() {
return camelReleases("camel-quarkus-releases.json");
}

@Override
public Optional<EntityRef> findCapabilityRef(String capability) {
Map<String, String> capabilities = cache("capabilities", runtimeProvider::findCapabilities);

String ref = capabilities.get(capability);
if (ref == null) {
return Optional.empty();
}

String[] items = ref.split("/");
if (items.length != 2) {
return Optional.empty();
}

return Optional.of(new EntityRef(Kind.valueOf(items[0]), items[1]));
}

private List<ReleaseModel> camelReleases(String file) {
return cache(file, () -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;

import org.apache.camel.catalog.impl.CatalogHelper;

Expand All @@ -41,7 +38,6 @@ public class DefaultRuntimeProvider implements RuntimeProvider {
private static final String TRANSFORMER_CATALOG = "org/apache/camel/catalog/transformers.properties";
private static final String CONSOLE_CATALOG = "org/apache/camel/catalog/dev-consoles.properties";
private static final String OTHER_CATALOG = "org/apache/camel/catalog/others.properties";
private static final String CAPABILITIES_CATALOG = "org/apache/camel/catalog/capabilities.properties";
private static final String BEANS_CATALOG = "org/apache/camel/catalog/beans.properties";

private CamelCatalog camelCatalog;
Expand Down Expand Up @@ -137,10 +133,6 @@ protected String getOtherCatalog() {
return OTHER_CATALOG;
}

protected String getCapabilitiesCatalog() {
return CAPABILITIES_CATALOG;
}

protected String getBeansCatalog() {
return BEANS_CATALOG;
}
Expand Down Expand Up @@ -180,20 +172,6 @@ public List<String> findBeansNames() {
return find(getBeansCatalog());
}

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Map<String, String> findCapabilities() {
final Properties properties = new Properties();

try (InputStream is = getCamelCatalog().getVersionManager().getResourceAsStream(getCapabilitiesCatalog())) {
properties.load(is);
} catch (IOException e) {
// ignore
}

return new TreeMap<>((Map<String, String>) (Map) properties);
}

protected List<String> find(String resourceName) {
List<String> names = new ArrayList<>();
try (InputStream is = getCamelCatalog().getVersionManager().getResourceAsStream(resourceName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.apache.camel.catalog;

import java.util.List;
import java.util.Map;

/**
* A pluggable strategy for chosen runtime to run Camel such as default, karaf, spring-boot, etc. This allows third
Expand Down Expand Up @@ -121,9 +120,4 @@ public interface RuntimeProvider {
*/
List<String> findBeansNames();

/**
* Find all the capabilities from the Camel catalog supported by the provider
*/
Map<String, String> findCapabilities();

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.camel.tooling.model.ArtifactModel;
import org.apache.camel.tooling.model.ComponentModel;
import org.apache.camel.tooling.model.DataFormatModel;
import org.apache.camel.tooling.model.EntityRef;
import org.apache.camel.tooling.model.Kind;
import org.apache.camel.tooling.model.LanguageModel;
import org.apache.camel.tooling.model.PojoBeanModel;
Expand Down Expand Up @@ -1602,20 +1600,6 @@ public void camelQuarkusReleases() {
Assertions.assertEquals("11", rel.getJdk());
}

@Test
public void capabilities() {
List<String> list = catalog.findCapabilityNames();
Assertions.assertEquals(1, list.size());

Optional<EntityRef> ref = catalog.findCapabilityRef("platform-http");
Assertions.assertTrue(ref.isPresent());
Assertions.assertEquals(Kind.other, ref.get().kind());
Assertions.assertEquals("platform-http-main", ref.get().name());

Optional<EntityRef> ref2 = catalog.findCapabilityRef("not-implemented");
Assertions.assertFalse(ref2.isPresent());
}

@Test
public void testFindPojoBeanNames() {
List<String> names = catalog.findBeansNames();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.CountDownLatch;

Expand All @@ -41,7 +40,6 @@
import org.apache.camel.dsl.jbang.core.common.RuntimeType;
import org.apache.camel.dsl.jbang.core.common.RuntimeTypeConverter;
import org.apache.camel.tooling.model.BaseModel;
import org.apache.camel.tooling.model.EntityRef;
import org.apache.camel.tooling.model.Kind;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -128,10 +126,6 @@ CompletionStage<HttpServer> serve(Vertx vertx) {
.produces(MIME_TYPE_JSON)
.blockingHandler(this::handleCatalogModel);

router.route(HttpMethod.GET, "/catalog/capability/:name")
.produces(MIME_TYPE_JSON)
.blockingHandler(this::handleCatalogCapability);

router.route(HttpMethod.POST, "/inspect/:location")
.produces(MIME_TYPE_JSON)
.blockingHandler(this::handleInspect);
Expand All @@ -151,27 +145,6 @@ private void handleFailure(RoutingContext ctx) {
.end();
}

private void handleCatalogCapability(RoutingContext ctx) {
try {
final CamelCatalog catalog = CatalogHelper.loadCatalog(runtimeType, runtimeVersion, repos, quarkusGroupId);
final String name = ctx.pathParam("name");
final Optional<EntityRef> ref = catalog.findCapabilityRef(name);

if (ref.isPresent()) {
ctx.response()
.putHeader(CONTENT_TYPE_HEADER, MIME_TYPE_JSON)
.end(MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(ref.get()));
} else {
ctx.response()
.setStatusCode(204)
.putHeader(CONTENT_TYPE_HEADER, MIME_TYPE_JSON)
.end(MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(Map.of()));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}

private void handleCatalogModel(RoutingContext ctx) {
try {
final CamelCatalog catalog = CatalogHelper.loadCatalog(runtimeType, runtimeVersion, repos, quarkusGroupId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,58 +104,6 @@ public void testCatalog(String entityRef, int code) throws Exception {
}
}

@ParameterizedTest
@CsvSource({ "platform-http,200", "baz,204" })
public void testCapability(String name, int code) throws Exception {
Agent agent = cmd();
agent.port = 0;

Vertx vertx = Vertx.vertx();
HttpServer server = agent.serve(vertx).toCompletableFuture().get();

try {
int port = server.actualPort();
RestAssured.given()
.baseUri("http://localhost")
.port(port)
.when()
.get("/catalog/capability/" + name)
.then()
.statusCode(code);

} finally {
server.close();
vertx.close();
}
}

@ParameterizedTest
@CsvSource({ "platform-http,other,platform-http-main" })
public void testCapabilities(String name, String expectedKind, String expectedName) throws Exception {
Agent agent = cmd();
agent.port = 0;

Vertx vertx = Vertx.vertx();
HttpServer server = agent.serve(vertx).toCompletableFuture().get();

try {
int port = server.actualPort();
RestAssured.given()
.baseUri("http://localhost")
.port(port)
.when()
.get("/catalog/capability/" + name)
.then()
.statusCode(200)
.body("kind", is(expectedKind))
.body("name", is(expectedName));

} finally {
server.close();
vertx.close();
}
}

@Disabled
@Test
public void testCall() throws Exception {
Expand Down

This file was deleted.

0 comments on commit 1134f97

Please sign in to comment.