Skip to content

Commit

Permalink
Merge pull request Azure-Samples#4 from majguo/azure-storage-blob
Browse files Browse the repository at this point in the history
Quarkus Azure storage blob extension - Dev Services and native executable
  • Loading branch information
majguo authored Oct 31, 2022
2 parents 805e58c + 0deb3d5 commit f193bf1
Show file tree
Hide file tree
Showing 18 changed files with 718 additions and 51 deletions.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
# quarkus-azure-services
# Quarkiverse - Quarkus Azure Services

This repository hosts Quarkus extensions for different Azure Services.

The following services are implemented:

- [StorageBlob](storage-blob): Support Dev Services.

## Example applications

Example applications can be found inside the integration-tests folder:

- [integration-tests](integration-tests): RESTEasy endpoints using all the Azure Services extensions, to be deployed as
a standalone JAR and a native executable.

## Contributing

Contributions are always welcome, but better create an issue to discuss them prior to any contributions.
75 changes: 75 additions & 0 deletions integration-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Quarkus Azure Services - Integration Tests

This is the integration test for testing all Quarkus Azure services extensions from REST endpoints.

## Running the test with Dev services

Some Quarkus Azure services extensions support Dev Services, it allows to test easily.
Launch these tests with:

```
mvn test
```

## Running the test with Azure services

If you want to run all the test with real Azure services in the native mode, you need to create the dependent services
on Azure after logging into Azure.

### Logging into Azure

Log into Azure and create a resource group for hosting different Azure services to be created.

```
az login
RESOURCE_GROUP_NAME=<resource-group-name>
az group create \
--name ${RESOURCE_GROUP_NAME} \
--location eastus
```

### Creating Azure Storage Account

Run the following commands to create an Azure Storage Account and retrieve its connection string:

```
STORAGE_ACCOUNT_NAME=<unique-storage-account-name>
az storage account create \
--name ${STORAGE_ACCOUNT_NAME} \
--resource-group ${RESOURCE_GROUP_NAME} \
--location eastus \
--sku Standard_LRS \
--kind StorageV2
STORAGE_ACCOUNT_CONNECTION_STRING=$(az storage account show-connection-string \
--resource-group ${RESOURCE_GROUP_NAME} \
--name ${STORAGE_ACCOUNT_NAME} \
--query connectionString -o tsv)
echo "The value of 'quarkus.azure.storage.blob.connection-string' is: ${STORAGE_ACCOUNT_CONNECTION_STRING}"
```

### Running the test

Copy the output of the following variables from previous steps:

* **quarkus.azure.storage.blob.connection-string**

Then update [application.properties](src/main/resources/application.properties) by uncommenting the relevant properties
and setting copied values.

Finally, build the native executable and launch the test with:

```
mvn integration-test -Dnative
```

### Cleaning up Azure resources

Once you complete the test, run the following command to clean up the Azure resources used in the test:

```
az group delete \
--name ${RESOURCE_GROUP_NAME} \
--yes --no-wait
```
111 changes: 111 additions & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkiverse.azureservices</groupId>
<artifactId>quarkus-azure-services-parent</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>quarkus-azure-services-integration-tests</artifactId>
<name>Quarkus Azure Services - Integration Tests</name>

<properties>
<skipITs>true</skipITs>
</properties>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.azureservices</groupId>
<artifactId>quarkus-azure-storage-blob</artifactId>
<version>${project.version}</version>
</dependency>
<!-- See https://github.com/quarkusio/quarkus/issues/26879
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-aot-graalvm-support</artifactId>
<version>1.0.0-beta.3</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-aot-graalvm-support-netty</artifactId>
<version>1.0.0-beta.3</version>
</dependency>
-->

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemPropertyVariables>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native-image</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${native.surefire.skip}</skipTests>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<skipITs>false</skipITs>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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 io.quarkiverse.azureservices.azure.storage.blob.it;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;

import com.azure.core.util.BinaryData;
import com.azure.storage.blob.BlobClient;
import com.azure.storage.blob.BlobContainerClient;
import com.azure.storage.blob.BlobServiceClient;

@Path("/azure-storage-blob")
@ApplicationScoped
public class StorageBlobResource {

@Inject
BlobServiceClient blobServiceClient;

@GET
public String hello() {
BlobContainerClient blobContainerClient = blobServiceClient.createBlobContainerIfNotExists("mycontainer");
BlobClient blobClient = blobContainerClient.getBlobClient("myblob");
blobClient.upload(BinaryData.fromString("Hello azure-storage-blob"), true);

return blobClient.downloadContent().toString();
}
}
2 changes: 2 additions & 0 deletions integration-tests/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Uncomment and set a valid connection string of an Azure Storage Account if you want to connect Azure. Otherwise, leave it to use Dev Services of Azure Storage Blob extension for development and testing purpose.
#quarkus.azure.storage.blob.connection-string=
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.quarkiverse.azureservices.azure.storage.blob.it;

import io.quarkus.test.junit.QuarkusIntegrationTest;

@QuarkusIntegrationTest
public class StorageBlobResourceIT extends StorageBlobResourceTest {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.quarkiverse.azureservices.azure.storage.blob.it;

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.is;

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
public class StorageBlobResourceTest {

@Test
public void testHelloEndpoint() {
given()
.when().get("/azure-storage-blob")
.then()
.statusCode(200)
.body(is("Hello azure-storage-blob"));
}
}
22 changes: 21 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand All @@ -21,13 +22,16 @@
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.parameters>true</maven.compiler.parameters>
<quarkus.version>2.13.1.Final</quarkus.version>
<azure.core.http.client.vertx.version>2.13.0</azure.core.http.client.vertx.version>
<netty.tcnative.version>2.0.54.Final</netty.tcnative.version>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<enforcer-plugin.version>3.0.0-M3</enforcer-plugin.version>
</properties>

<modules>
<module>bom</module>
<module>storage-blob</module>
<module>integration-tests</module>
</modules>

<dependencyManagement>
Expand All @@ -46,6 +50,22 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- See https://github.com/quarkusio/quarkus/issues/26879 -->
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-support-azure-core-http-client-vertx</artifactId>
<version>${azure.core.http.client.vertx.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-support-azure-core-http-client-vertx-deployment</artifactId>
<version>${azure.core.http.client.vertx.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative</artifactId>
<version>${netty.tcnative.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
24 changes: 1 addition & 23 deletions storage-blob/README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@
# Quarkus Azure Storage Blob

[![Version](https://img.shields.io/maven-central/v/io.quarkiverse.azureservices/quarkus-azure-storage-blob?logo=apache-maven&style=flat-square)](https://search.maven.org/artifact/io.quarkiverse.azureservices/quarkus-azure-storage-blob)

## Welcome to Quarkiverse!

Congratulations and thank you for creating a new Quarkus extension project in Quarkiverse!

Feel free to replace this content with the proper description of your new project and necessary instructions how to use and contribute to it.

You can find the basic info, Quarkiverse policies and conventions in [the Quarkiverse wiki](https://github.com/quarkiverse/quarkiverse/wiki).

In case you are creating a Quarkus extension project for the first time, please follow [Building My First Extension](https://quarkus.io/guides/building-my-first-extension) guide.

Other useful articles related to Quarkus extension development can be found under the [Writing Extensions](https://quarkus.io/guides/#writing-extensions) guide category on the [Quarkus.io](https://quarkus.io) website.

Thanks again, good luck and have fun!

## Documentation

The documentation for this extension should be maintained as part of this repository and it is stored in the `docs/` directory.

The layout should follow the [Antora's Standard File and Directory Set](https://docs.antora.org/antora/2.3/standard-directories/).

Once the docs are ready to be published, please open a PR including this repository in the [Quarkiverse Docs Antora playbook](https://github.com/quarkiverse/quarkiverse-docs/blob/main/antora-playbook.yml#L7). See an example [here](https://github.com/quarkiverse/quarkiverse-docs/pull/1).
This extension allows to inject a `com.azure.storage.blob.BlobServiceClient` object inside your Quarkus application.
Loading

0 comments on commit f193bf1

Please sign in to comment.