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

IPFS native support #2159

Merged
merged 1 commit into from
Jan 22, 2021
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
8 changes: 4 additions & 4 deletions docs/modules/ROOT/pages/reference/extensions/ipfs.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
= IPFS
:cq-artifact-id: camel-quarkus-ipfs
:cq-native-supported: false
:cq-status: Preview
:cq-native-supported: true
:cq-status: Stable
:cq-description: Access the Interplanetary File System (IPFS).
:cq-deprecated: false
:cq-jvm-since: 1.1.0
:cq-native-since: n/a
:cq-native-since: 1.7.0

[.badges]
[.badge-key]##JVM since##[.badge-supported]##1.1.0## [.badge-key]##Native##[.badge-unsupported]##unsupported##
[.badge-key]##JVM since##[.badge-supported]##1.1.0## [.badge-key]##Native since##[.badge-supported]##1.7.0##

Access the Interplanetary File System (IPFS).

Expand Down
6 changes: 3 additions & 3 deletions docs/modules/ROOT/partials/reference/components/ipfs.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
:cq-artifact-id: camel-quarkus-ipfs
:cq-artifact-id-base: ipfs
:cq-native-supported: false
:cq-status: Preview
:cq-native-supported: true
:cq-status: Stable
:cq-deprecated: false
:cq-jvm-since: 1.1.0
:cq-native-since: n/a
:cq-native-since: 1.7.0
:cq-camel-part-name: ipfs
:cq-camel-part-title: IPFS
:cq-camel-part-description: Access the Interplanetary File System (IPFS).
Expand Down
1 change: 0 additions & 1 deletion extensions-jvm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
<module>iec60870</module>
<module>ignite</module>
<module>iota</module>
<module>ipfs</module>
<module>irc</module>
<module>jasypt</module>
<module>jbpm</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,14 @@
package org.apache.camel.quarkus.component.ipfs.deployment;

import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.pkg.steps.NativeBuild;
import org.apache.camel.quarkus.core.JvmOnlyRecorder;
import org.jboss.logging.Logger;

class IpfsProcessor {

private static final Logger LOG = Logger.getLogger(IpfsProcessor.class);
private static final String FEATURE = "camel-ipfs";

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

/**
* Remove this once this extension starts supporting the native mode.
*/
@BuildStep(onlyIf = NativeBuild.class)
@Record(value = ExecutionTime.RUNTIME_INIT)
void warnJvmInNative(JvmOnlyRecorder recorder) {
JvmOnlyRecorder.warnJvmInNative(LOG, FEATURE); // warn at build time
recorder.warnJvmInNative(FEATURE); // warn at runtime
}
}
1 change: 0 additions & 1 deletion extensions-jvm/ipfs/pom.xml → extensions/ipfs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@
<modules>
<module>deployment</module>
<module>runtime</module>
<module>integration-test</module>
</modules>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

<properties>
<camel.quarkus.jvmSince>1.1.0</camel.quarkus.jvmSince>
<camel.quarkus.nativeSince>1.7.0</camel.quarkus.nativeSince>
</properties>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
name: "Camel IPFS"
description: "Access the Interplanetary File System (IPFS)"
metadata:
unlisted: true
guide: "https://camel.apache.org/camel-quarkus/latest/reference/extensions/ipfs.html"
categories:
- "integration"
status:
- "preview"
- "stable"
1 change: 1 addition & 0 deletions extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
<module>ical</module>
<module>infinispan</module>
<module>influxdb</module>
<module>ipfs</module>
<module>jackson</module>
<module>jacksonxml</module>
<module>jaxb</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-build-parent-it</artifactId>
<artifactId>camel-quarkus-integration-tests</artifactId>
<version>1.7.0-SNAPSHOT</version>
<relativePath>../../../poms/build-parent-it/pom.xml</relativePath>
</parent>

<artifactId>camel-quarkus-ipfs-integration-test</artifactId>
<name>Camel Quarkus :: IPFS :: Integration Test</name>
<artifactId>camel-quarkus-integration-test-ipfs</artifactId>
<name>Camel Quarkus :: Integration Tests :: IPFS</name>
<description>Integration tests for Camel Quarkus IPFS extension</description>

<dependencyManagement>
Expand All @@ -43,6 +42,10 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-main</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-ipfs</artifactId>
Expand All @@ -51,6 +54,11 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-integration-testcontainers-support</artifactId>
<scope>test</scope>
</dependency>

<!-- test dependencies -->
<dependency>
Expand Down Expand Up @@ -78,6 +86,49 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-main-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<properties>
<quarkus.package.type>native</quarkus.package.type>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,43 @@
*/
package org.apache.camel.quarkus.component.ipfs.it;

import javax.enterprise.context.ApplicationScoped;
import java.nio.file.Paths;

import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.apache.camel.CamelContext;
import org.jboss.logging.Logger;
import org.apache.camel.ProducerTemplate;

@Path("/ipfs")
@ApplicationScoped
public class IpfsResource {

private static final Logger LOG = Logger.getLogger(IpfsResource.class);

private static final String COMPONENT_IPFS = "ipfs";
@Inject
CamelContext context;
ProducerTemplate producerTemplate;

@Path("/add")
@POST
@Consumes(MediaType.TEXT_PLAIN)
public String addFile(String path) {
return producerTemplate.requestBody("ipfs:add", Paths.get(path), String.class);
}

@Path("/cat")
@GET
@Produces(MediaType.TEXT_PLAIN)
public String catFile(@QueryParam("hash") String hash) {
return producerTemplate.requestBody("ipfs:cat", hash, String.class);
}

@Path("/load/component/ipfs")
@Path("/get")
@GET
@Produces(MediaType.TEXT_PLAIN)
public Response loadComponentIpfs() throws Exception {
/* This is an autogenerated test */
if (context.getComponent(COMPONENT_IPFS) != null) {
return Response.ok().build();
}
LOG.warnf("Could not load [%s] from the Camel context", COMPONENT_IPFS);
return Response.status(500, COMPONENT_IPFS + " could not be loaded from the Camel context").build();
public String getFilePath(@QueryParam("hash") String hash) throws Exception {
return producerTemplate.requestBody("ipfs:get?outdir=target", hash, String.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,9 @@
*/
package org.apache.camel.quarkus.component.ipfs.it;

import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import org.junit.jupiter.api.Test;
import io.quarkus.test.junit.NativeImageTest;

@QuarkusTest
class IpfsTest {

@Test
public void loadComponentIpfs() {
/* A simple autogenerated test */
RestAssured.get("/ipfs/load/component/ipfs")
.then()
.statusCode(200);
}
@NativeImageTest
class IpfsIT extends IpfsTest {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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.quarkus.component.ipfs.it;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.jupiter.api.Assertions.assertEquals;

@QuarkusTest
@QuarkusTestResource(IpfsTestResource.class)
class IpfsTest {

@Test
public void ipfsComponent() throws IOException {
String fileContent = "Hello Camel Quarkus IPFS";

Path tempFile = Files.createTempFile("ipfs", ".txt");
Files.write(tempFile, fileContent.getBytes(StandardCharsets.UTF_8));

try {
// Add file
String hash = RestAssured.given()
.body(tempFile.toString())
.post("/ipfs/add")
.then()
.statusCode(200)
.extract()
.body()
.asString();

// Cat file
RestAssured.given()
.queryParam("hash", hash)
.get("/ipfs/cat")
.then()
.statusCode(200)
.body(is(fileContent));

// Retrieve file path
String filePath = RestAssured.given()
.queryParam("hash", hash)
.get("/ipfs/get")
.then()
.statusCode(200)
.extract()
.body()
.asString();

byte[] bytes = Files.readAllBytes(Paths.get(filePath));
assertEquals(fileContent, new String(bytes, StandardCharsets.UTF_8));
} finally {
Files.delete(tempFile);
}
}
}