Skip to content

Commit

Permalink
Upgrade to Quarkus 2.8 and use default DevServices (#225)
Browse files Browse the repository at this point in the history
* Upgrade to Quarkus 2.8

* Fix compilation

* Fix ES Inject

* Change Optional

* Rename classes

* Rename classes
  • Loading branch information
carlosthe19916 authored Apr 15, 2022
1 parent 90c8a26 commit d30b240
Show file tree
Hide file tree
Showing 36 changed files with 167 additions and 335 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
distribution: temurin
cache: maven
- name: Build with Maven
run: mvn verify -Dquarkus.native.container-build=true -P native,ui,${{ matrix.flavor }}
run: mvn verify -Dquarkus.native.container-build=true -P native,${{ matrix.flavor }}

ui-tests:
name: UI Tests
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Microservicio que expone los datos provenientes del `padrón reducido` de la SUN
Puedes ejecutar la aplicación en modo desarrollo con:

```shell script
./mvnw compile quarkus:dev -Pstandalone-dev
./mvnw compile quarkus:dev
```

### Iniciar UI
Expand Down
115 changes: 11 additions & 104 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>2.7.5.Final</quarkus.platform.version>
<quarkus.platform.version>2.8.0.Final</quarkus.platform.version>

<maven.compiler.parameters>true</maven.compiler.parameters>
<surefire-plugin.version>3.0.0-M6</surefire-plugin.version>
Expand Down Expand Up @@ -110,11 +110,11 @@

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
<artifactId>quarkus-resteasy-reactive</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jsonb</artifactId>
<artifactId>quarkus-resteasy-reactive-jsonb</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand Down Expand Up @@ -186,7 +186,13 @@

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-qute</artifactId>
<artifactId>quarkus-resteasy-reactive-qute</artifactId>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -325,6 +331,7 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<executions>
Expand Down Expand Up @@ -445,31 +452,6 @@
</build>
</profile>

<profile>
<id>standalone</id>
<properties>
<quarkus.profile>standalone</quarkus.profile>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<includes>
<include>**/*StandaloneIT.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>standalone-dev</id>
<properties>
<quarkus.profile>standalone</quarkus.profile>
</properties>
</profile>
<profile>
<id>standalone-distribution</id>
<build>
Expand Down Expand Up @@ -535,81 +517,6 @@
</build>
</profile>

<profile>
<id>enterprise</id>
<properties>
<quarkus.profile>enterprise</quarkus.profile>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<includes>
<include>**/*EnterpriseIT.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>enterprise-dev</id>
<properties>
<quarkus.profile>enterprise,dev</quarkus.profile>
</properties>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.39.1</version>
<configuration>
<skip>${skipTests}</skip>
<images>
<image>
<name>docker.elastic.co/elasticsearch/elasticsearch:7.10.2</name>
<alias>elasticsearch</alias>
<run>
<env>
<discovery.type>single-node</discovery.type>
</env>
<ports>
<port>9200:9200</port>
</ports>
<log>
<enabled>false</enabled>
<prefix>Elasticsearch:</prefix>
<date>default</date>
<color>cyan</color>
</log>
<wait>
<http>
<url>http://localhost:9200</url>
<method>GET</method>
<status>200</status>
</http>
<time>60000</time>
</wait>
</run>
</image>
</images>
</configuration>
<executions>
<execution>
<id>docker-start</id>
<phase>compile</phase>
<goals>
<goal>stop</goal>
<goal>start</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>enterprise-distribution</id>
<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,22 @@
*/
package io.github.project.openubl.searchpe.bootstrap;

import io.github.project.openubl.searchpe.models.jpa.entity.VersionEntity;
import io.github.project.openubl.searchpe.models.jpa.search.SearchpeNoneIndexer;
import io.github.project.openubl.searchpe.resources.BasicUserResource;
import io.quarkus.runtime.StartupEvent;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.hibernate.search.mapper.orm.session.SearchSession;
import org.jboss.logging.Logger;

import javax.enterprise.event.Observes;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.transaction.Transactional;

@Singleton
public class SearchpeBootstrap {

@ConfigProperty(name = "quarkus.hibernate-search-orm.automatic-indexing.synchronization.strategy")
String searchOrmIndexSyncStrategy;
private static final Logger LOGGER = Logger.getLogger(BasicUserResource.class);

@Inject
SearchSession searchSession;

/**
* If there is an upgrade of Version, the indexes in Elasticsearch should be deleted.
* This will work under the assumption that on upgrades the DB will delete all data before.
*/
@Transactional
void reindexSearchIndexes(@Observes StartupEvent ev) throws InterruptedException {
if (!searchOrmIndexSyncStrategy.equals(SearchpeNoneIndexer.BEAN_FULL_NAME)) {
if (VersionEntity.count() == 0) {
searchSession.massIndexer().startAndWait();
}
}
LOGGER.info("SearchPE started");
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import io.github.project.openubl.searchpe.models.jpa.entity.ContribuyenteEntity;
import io.github.project.openubl.searchpe.models.jpa.entity.ContribuyenteId;
import io.github.project.openubl.searchpe.models.jpa.entity.VersionEntity;
import io.github.project.openubl.searchpe.models.jpa.search.SearchpeNoneIndexer;
import io.github.project.openubl.searchpe.security.Permission;
import io.github.project.openubl.searchpe.utils.ResourceUtils;
import org.eclipse.microprofile.config.inject.ConfigProperty;
Expand All @@ -44,6 +43,7 @@

import javax.annotation.security.RolesAllowed;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import javax.transaction.Transactional;
import javax.validation.constraints.Max;
Expand All @@ -57,8 +57,8 @@
@Path("/contribuyentes")
public class ContribuyenteResource {

@ConfigProperty(name = "quarkus.hibernate-search-orm.automatic-indexing.synchronization.strategy")
String searchOrmIndexSyncStrategy;
@ConfigProperty(name = "quarkus.hibernate-search-orm.enabled")
Optional<Boolean> isESEnabled;

@Inject
VersionRepository versionRepository;
Expand All @@ -67,7 +67,14 @@ public class ContribuyenteResource {
ContribuyenteRepository contribuyenteRepository;

@Inject
SearchSession searchSession;
Instance<SearchSession> searchSession;

private Optional<SearchSession> getSearchSession() {
for (SearchSession session : searchSession) {
return Optional.of(session);
}
return Optional.empty();
}

@RolesAllowed({Permission.admin, Permission.search})
@Operation(summary = "Search contribuyentes", description = "Get contribuyentes in a page")
Expand All @@ -83,10 +90,12 @@ public PageRepresentation<ContribuyenteEntity> getContribuyentes(
@QueryParam("limit") @DefaultValue("10") @Max(1_000) Integer limit,
@QueryParam("sort_by") @DefaultValue("name") List<String> sortBy
) {
if (searchOrmIndexSyncStrategy.equals(SearchpeNoneIndexer.BEAN_FULL_NAME)) {
if (isESEnabled.isEmpty() || !isESEnabled.get()) {
throw new NotFoundException();
}

SearchSession searchSession = getSearchSession().orElseThrow(() -> new IllegalStateException("Could not find a SearchSession available"));

Optional<VersionEntity> versionOptional = versionRepository.findActive();
if (versionOptional.isEmpty()) {
PageRepresentation<ContribuyenteEntity> result = new PageRepresentation<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package io.github.project.openubl.searchpe.resources;

import io.github.project.openubl.searchpe.models.jpa.search.SearchpeNoneIndexer;
import io.quarkus.qute.Location;
import io.quarkus.qute.Template;
import io.quarkus.qute.TemplateInstance;
Expand All @@ -40,15 +39,15 @@ public class FrontendResource {
@ConfigProperty(name = "quarkus.oidc.enabled")
Optional<Boolean> isOidcEnabled;

@ConfigProperty(name = "quarkus.hibernate-search-orm.enabled")
Optional<Boolean> isESEnabled;

@ConfigProperty(name = "quarkus.http.auth.form.cookie-name")
Optional<String> formCookieName;

@ConfigProperty(name = "quarkus.oidc.logout.path")
Optional<String> oidcLogoutPath;

@ConfigProperty(name = "quarkus.hibernate-search-orm.automatic-indexing.synchronization.strategy")
Optional<String> esSyncStrategy;

@Authenticated
@GET
@Path("/settings.js")
Expand All @@ -58,7 +57,7 @@ public TemplateInstance getSettingsJS() {
.data("defaultAuthMethod", isOidcEnabled.isPresent() && isOidcEnabled.get() ? "oidc" : "basic")
.data("formCookieName", formCookieName.orElse(""))
.data("oidcLogoutPath", oidcLogoutPath.orElse(""))
.data("isElasticsearchEnabled", !Objects.equals(esSyncStrategy.orElse(""), SearchpeNoneIndexer.BEAN_FULL_NAME));
.data("isElasticsearchEnabled", isESEnabled.isPresent() && isESEnabled.get());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public List<VersionEntity> getVersions(@QueryParam("active") Boolean active) {
@Transactional(Transactional.TxType.NEVER)
@POST
@Path("/")
@Consumes()
public VersionEntity createVersion() {
try {
tx.begin();
Expand Down
12 changes: 7 additions & 5 deletions src/main/resources/application-enterprise.properties
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# Elasticsearch
quarkus.hibernate-search-orm.elasticsearch.version-check.enabled=true
quarkus.hibernate-search-orm.enabled=true

quarkus.hibernate-search-orm.elasticsearch.username=es_username
quarkus.hibernate-search-orm.elasticsearch.password=es_password
quarkus.hibernate-search-orm.elasticsearch.hosts=localhost:9200
quarkus.hibernate-search-orm.elasticsearch.analysis.configurer=bean:searchpeAnalysisConfigurer
quarkus.hibernate-search-orm.elasticsearch.version-check.enabled=true
quarkus.hibernate-search-orm.elasticsearch.protocol=HTTP
quarkus.hibernate-search-orm.elasticsearch.version=7
quarkus.hibernate-search-orm.schema-management.strategy=CREATE_OR_VALIDATE
quarkus.hibernate-search-orm.automatic-indexing.synchronization.strategy=write-sync
%test.quarkus.hibernate-search-orm.automatic-indexing.synchronization.strategy=sync

quarkus.elasticsearch.devservices.enabled=true

# Basic HTTP Authentication
quarkus.http.auth.basic=false
Expand Down Expand Up @@ -37,5 +39,5 @@ quarkus.oidc.roles.source=accesstoken
quarkus.oidc.logout.path=/oidc/logout
quarkus.oidc.logout.post-logout-path=/

quarkus.keycloak.devservices.enabled=true
quarkus.keycloak.devservices.realm-path=openubl-realm.json
%dev.quarkus.keycloak.devservices.enabled=true
Loading

0 comments on commit d30b240

Please sign in to comment.