Skip to content

Commit

Permalink
Merge branch 'master' into evol/plume-file-integration
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/com/coreoz/db/QuerydslGenerator.java
  • Loading branch information
lucas-amiaud committed Dec 14, 2023
2 parents cc73732 + c0e51e5 commit 0bd33e9
Show file tree
Hide file tree
Showing 16 changed files with 269 additions and 122 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Java CI

on:
push:
branches: [ "master" ]
pull_request:
types: [opened, synchronize, reopened]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build & test with Maven
run: mvn -B clean test
- name: Sonar analysis
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=Coreoz_Plume-showcase -Dsonar.organization=coreoz
9 changes: 3 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<?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/maven-v4_0_0.xsd">
<project>
<modelVersion>4.0.0</modelVersion>

<groupId>com.coreoz</groupId>
<artifactId>plume-demo-admin</artifactId>
<artifactId>plume-showcase</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>plume-demo-admin</name>
<name>plume-showcase</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -225,5 +223,4 @@
</dependency>
</dependencies>
</dependencyManagement>

</project>
23 changes: 23 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
sonar.projectKey=plume-showcase
sonar.projectName=plume-showcase
sonar.projectVersion=1.0
sonar.sourceEncoding=UTF-8
sonar.sources=src

# Java
sonar.java.source=17
sonar.exclusions=src/main/java/com/coreoz/db/generated/*,\
src/main/java/com/coreoz/db/QuerydslGenerator.java

# Configure Lombok if needed
# sonar.java.libraries=/home/coreoz/lombok-1.18.30.jar

#Tests
# Disable some rules on some files
sonar.issue.ignore.multicriteria=j1,j2
#No literal duplication tests
sonar.issue.ignore.multicriteria.j1.ruleKey=squid:S1192
sonar.issue.ignore.multicriteria.j1.resourceKey=src/test/**/*
#No method name compliance for tests
sonar.issue.ignore.multicriteria.j2.ruleKey=squid:S00100
sonar.issue.ignore.multicriteria.j2.resourceKey=src/test/**/*
43 changes: 20 additions & 23 deletions src/main/java/com/coreoz/WebApplication.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
package com.coreoz;

import java.time.Duration;
import java.util.concurrent.TimeUnit;

import com.coreoz.plume.admin.services.scheduler.LogApiScheduledJobs;
import org.glassfish.grizzly.GrizzlyFuture;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.server.ResourceConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.coreoz.db.InitializeDatabase;
import com.coreoz.db.DatabaseInitializer;
import com.coreoz.guice.ApplicationModule;
import com.coreoz.jersey.GrizzlySetup;
import com.coreoz.plume.admin.services.scheduler.LogApiScheduledJobs;
import com.coreoz.plume.jersey.guice.JerseyGuiceFeature;
import com.coreoz.wisp.Scheduler;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Stage;
import lombok.extern.slf4j.Slf4j;
import org.glassfish.grizzly.GrizzlyFuture;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.server.ResourceConfig;

import java.time.Duration;
import java.util.concurrent.TimeUnit;

/**
* The application entry point, where it all begins.
*/
@Slf4j
public class WebApplication {
private static final Logger logger = LoggerFactory.getLogger(WebApplication.class);

// maximal waiting time for the last process to execute after the JVM received a kill signal
public static final Duration GRACEFUL_SHUTDOWN_TIMEOUT = Duration.ofSeconds(60);

Expand All @@ -36,7 +33,7 @@ public static void main(String[] args) {
Injector injector = Guice.createInjector(Stage.PRODUCTION, new ApplicationModule());

// initialize database
injector.getInstance(InitializeDatabase.class).setup();
injector.getInstance(DatabaseInitializer.class).setup();

// schedule jobs
// configure logApi
Expand Down Expand Up @@ -66,20 +63,20 @@ public static void main(String[] args) {
}
}


private static void addShutDownListener(HttpServer httpServer, Scheduler scheduler) {
Runtime.getRuntime().addShutdownHook(new Thread(
() -> {
logger.info("Stopping signal received, shutting down server and scheduler...");
GrizzlyFuture<HttpServer> grizzlyServerShutdownFuture = httpServer.shutdown(GRACEFUL_SHUTDOWN_TIMEOUT.toSeconds(), TimeUnit.SECONDS);
try {
logger.info("Waiting for server to shut down... Shutdown timeout is {} seconds", GRACEFUL_SHUTDOWN_TIMEOUT.toSeconds());
scheduler.gracefullyShutdown(GRACEFUL_SHUTDOWN_TIMEOUT);
grizzlyServerShutdownFuture.get();
} catch(Exception e) {
logger.error("Error while shutting down server.", e);
}
logger.info("Server and scheduler stopped.");
try {
logger.info("Waiting for server to shut down... Shutdown timeout is {} seconds", GRACEFUL_SHUTDOWN_TIMEOUT.toSeconds());
scheduler.gracefullyShutdown(GRACEFUL_SHUTDOWN_TIMEOUT);
grizzlyServerShutdownFuture.get();
logger.info("Server and scheduler stopped.");
} catch(Exception e) {
logger.error("Error while shutting down server.", e);
Thread.currentThread().interrupt();
}
},
"shutdownHook"
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
* Initialize the H2 database with SQL scripts placed in src/main/resources/db/migration
*/
@Singleton
public class InitializeDatabase {
public class DatabaseInitializer {

private final DataSource dataSource;

@Inject
public InitializeDatabase(DataSource dataSource) {
public DatabaseInitializer(DataSource dataSource) {
this.dataSource = dataSource;
}

Expand All @@ -27,5 +27,4 @@ public void setup() {
.load()
.migrate();
}

}
14 changes: 6 additions & 8 deletions src/main/java/com/coreoz/db/QuerydslGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@
import com.querydsl.sql.types.JSR310LocalTimeType;
import com.querydsl.sql.types.JSR310ZonedDateTimeType;
import com.querydsl.sql.types.Type;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

/**
* Generate Querydsl classes for the database layer.
*
* Run the {@link #main(String...)} method from your IDE to regenerate Querydsl classes.
*/
@Slf4j
public class QuerydslGenerator {

private static final String TABLES_PREFIX = "SWC_";

public static void main(String... args) {
Expand Down Expand Up @@ -77,17 +79,13 @@ public String getDefaultVariableName(EntityType entityType) {
try {
exporter.export(connection.getMetaData());
} catch (SQLException e) {
e.printStackTrace();
logger.error("Querydsl database objects generation failed", e);
}
});
}

@SneakyThrows
private static Type<?> classType(Class<?> classType) {
try {
return (Type<?>) classType.getConstructor().newInstance();
} catch (Exception e) {
throw new RuntimeException(e);
}
return (Type<?>) classType.getConstructor().newInstance();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

@Singleton
public class ConfigurationService {

private final Config config;

@Inject
Expand All @@ -19,13 +18,11 @@ public String hello() {
return config.getString("hello");
}

public String swaggerAccessUsername() {
return config.getString("swagger.access.username");
}

public String swaggerAccessPassword() {
return config.getString("swagger.access.password");
}
public String internalApiAuthUsername() {
return config.getString("internal-api.auth-username");
}

public String internalApiAuthPassword() {
return config.getString("internal-api.auth-password");
}
}

Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.coreoz.webservices.admin.permissions;

import java.util.Set;

import javax.inject.Inject;
import javax.inject.Singleton;

import com.coreoz.plume.admin.services.permission.LogApiAdminPermissions;
import com.coreoz.plume.admin.services.permission.SystemAdminPermissions;
import com.coreoz.plume.admin.services.permissions.AdminPermissionService;
import com.coreoz.plume.admin.services.permissions.AdminPermissions;
import com.google.common.collect.ImmutableSet;

import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.Set;

@Singleton
public class ProjectAdminPermissionService implements AdminPermissionService {
Expand All @@ -18,7 +16,7 @@ public class ProjectAdminPermissionService implements AdminPermissionService {

@Inject
public ProjectAdminPermissionService() {
this.permissionsAvailable = ImmutableSet.of(
this.permissionsAvailable = Set.of(
AdminPermissions.MANAGE_USERS,
AdminPermissions.MANAGE_ROLES,
LogApiAdminPermissions.MANAGE_API_LOGS,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.coreoz.webservices.internal;

import javax.inject.Inject;
import javax.inject.Singleton;

import com.coreoz.plume.jersey.security.basic.BasicAuthenticator;
import com.coreoz.services.configuration.ConfigurationService;

@Singleton
public class InternalApiAuthenticator {
private final BasicAuthenticator<String> basicAuthenticator;

@Inject
public InternalApiAuthenticator(ConfigurationService configurationService) {
this.basicAuthenticator = BasicAuthenticator.fromSingleCredentials(
configurationService.internalApiAuthUsername(),
configurationService.internalApiAuthPassword(),
"API plume-showcase"
);
}

public BasicAuthenticator<String> get() {
return this.basicAuthenticator;
}
}
14 changes: 7 additions & 7 deletions src/main/java/com/coreoz/webservices/internal/MonitoringWs.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
import javax.ws.rs.core.MediaType;

import com.codahale.metrics.Metric;
import com.coreoz.plume.db.transaction.TransactionManager;
import com.coreoz.plume.jersey.monitoring.utils.health.HealthCheckBuilder;
import com.coreoz.plume.jersey.monitoring.utils.health.beans.HealthStatus;
import com.coreoz.plume.jersey.monitoring.utils.info.ApplicationInfoProvider;

import com.coreoz.plume.db.transaction.TransactionManager;
import com.coreoz.plume.jersey.monitoring.utils.info.beans.ApplicationInfo;
import com.coreoz.plume.jersey.monitoring.utils.metrics.MetricsCheckBuilder;
import com.coreoz.plume.jersey.security.basic.BasicAuthenticator;
Expand All @@ -36,7 +36,11 @@ public class MonitoringWs {
private final BasicAuthenticator<String> basicAuthenticator;

@Inject
public MonitoringWs(ApplicationInfoProvider applicationInfoProvider, TransactionManager transactionManager) {
public MonitoringWs(
ApplicationInfoProvider applicationInfoProvider,
TransactionManager transactionManager,
InternalApiAuthenticator apiAuthenticator
) {
this.applicationInfo = applicationInfoProvider.get();
// Registering health checks
this.healthStatusProvider = new HealthCheckBuilder()
Expand All @@ -49,11 +53,7 @@ public MonitoringWs(ApplicationInfoProvider applicationInfoProvider, Transaction
.build();

// Require authentication to access monitoring endpoints
this.basicAuthenticator = BasicAuthenticator.fromSingleCredentials(
"plume",
"rocks",
"Plume showcase"
);
this.basicAuthenticator = apiAuthenticator.get();
}

@GET
Expand Down
Loading

0 comments on commit 0bd33e9

Please sign in to comment.