Skip to content

Commit

Permalink
refactor: Cleaning build logs by removing unecessary debug info and f…
Browse files Browse the repository at this point in the history
…ixing non-blocking build errors

OpenSILEX/opensilex-dev!1267
  • Loading branch information
Crejak committed Aug 28, 2024
1 parent 21615b1 commit 443a64f
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 164 deletions.
9 changes: 9 additions & 0 deletions opensilex-core/src/main/resources/ontologies/oeso-core.owl
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ OESO</rdfs:label>
-->


<!-- http://www.w3.org/2002/07/owl#topObjectProperty -->

<owl:ObjectProperty rdf:about="http://www.w3.org/2002/07/owl#topObjectProperty">
<rdfs:label xml:lang="en">topObjectProperty</rdfs:label>
<rdfs:comment xml:lang="en">The object property that relates every two individuals.</rdfs:comment>
<rdfs:isDefinedBy rdf:resource="http://www.w3.org/2002/07/owl#"/>
</owl:ObjectProperty>


<!-- http://www.opensilex.org/vocabulary/oeso#hasGermplasm -->

<owl:ObjectProperty rdf:about="http://www.opensilex.org/vocabulary/oeso#hasGermplasm">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,18 @@
package org.opensilex.core;

import com.fasterxml.jackson.core.type.TypeReference;
import com.mongodb.BasicDBList;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import de.flapdoodle.embed.mongo.MongodExecutable;
import de.flapdoodle.embed.mongo.MongodProcess;
import de.flapdoodle.embed.mongo.MongodStarter;
import de.flapdoodle.embed.mongo.config.Defaults;
import de.flapdoodle.embed.mongo.config.MongoCmdOptions;
import de.flapdoodle.embed.mongo.config.MongodConfig;
import de.flapdoodle.embed.mongo.config.Net;
import de.flapdoodle.embed.mongo.distribution.Version;
import de.flapdoodle.embed.mongo.packageresolver.Command;
import de.flapdoodle.embed.process.config.RuntimeConfig;
import de.flapdoodle.embed.process.config.process.ProcessOutput;
import org.bson.Document;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.opensilex.integration.test.security.AbstractSecurityIntegrationTest;
import org.opensilex.nosql.EmbedMongoClient;
import org.opensilex.nosql.mongodb.MongoDBService;
import org.opensilex.server.response.ObjectUriResponse;

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import static org.awaitility.Awaitility.await;

/**
* @author vmigot
Expand All @@ -45,8 +26,7 @@
*/
public abstract class AbstractMongoIntegrationTest extends AbstractSecurityIntegrationTest {

private static MongodExecutable mongoExec;
private static MongodProcess mongod;
private static EmbedMongoClient embedMongoClient;
private static final int replicaCount = 0;

public static final int MONGO_PORT = 28018;
Expand All @@ -56,67 +36,20 @@ public abstract class AbstractMongoIntegrationTest extends AbstractSecurityInteg
/**
* Type reference for reading results from "create" queries
*/
protected static final TypeReference<ObjectUriResponse> objectUriResponseTypeReference = new TypeReference<ObjectUriResponse>() {};
protected static final TypeReference<ObjectUriResponse> objectUriResponseTypeReference = new TypeReference<ObjectUriResponse>() {
};

@BeforeClass
public static void initMongo() throws IOException {

RuntimeConfig runtimeConfig = Defaults.runtimeConfigFor(Command.MongoD)
.processOutput(ProcessOutput.silent())
.build();

MongodStarter runtime = MongodStarter.getInstance(runtimeConfig);
int nodePort = MONGO_PORT;
Map<String, String> args = new HashMap<>();
String replicaName = "rs0";
args.put("--replSet", replicaName);
mongoExec = runtime.prepare(MongodConfig.builder().version(Version.V6_0_2)
.args(args)
.cmdOptions(MongoCmdOptions.builder().useNoJournal(false).build())
.net(new Net("127.0.0.1", nodePort, false)).build());
mongod = mongoExec.start();

try (MongoClient mongo = MongoClients.create("mongodb://127.0.0.1:" + nodePort)) {
MongoDatabase adminDatabase = mongo.getDatabase(MONGO_DATABASE);

Document config = new Document("_id", replicaName);
BasicDBList members = new BasicDBList();
members.add(new Document("_id", 0)
.append("host", MONGO_HOST+":" + nodePort));
config.put("members", members);

adminDatabase.runCommand(new Document("replSetInitiate", config));

try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException ex) {
}
public static void initMongo() throws IOException, InterruptedException {
if (embedMongoClient == null) {
embedMongoClient = EmbedMongoClient.getInstance();
}
embedMongoClient.start();
}

@AfterClass
public static void stopMongo() {
if (mongod != null) {
try {
mongod.stopInternal();
} catch (IllegalStateException e) {

} finally {
try {
mongod.stop();
} catch (IllegalStateException e) {
if (mongod != null) {
await().atMost(1, TimeUnit.MINUTES).until(() -> !mongod.isProcessRunning());
} else {
throw new IllegalStateException(e);
}
}
}
}

if (mongoExec != null) {
mongoExec.stop();
}
embedMongoClient.stop();
}

@Override
Expand All @@ -125,30 +58,29 @@ public void afterEach() throws Exception {
}

/**
*
* @return
*/
protected List<String> getCollectionsToClearNames() {
return Collections.emptyList();
}

private void clearCollections(){
private void clearCollections() {

MongoDBService mongoDBService = getOpensilex().getServiceInstance(MongoDBService.DEFAULT_SERVICE, MongoDBService.class);
MongoDatabase mongoDb = mongoDBService.getDatabase();

try{
for(String collectionName : getCollectionsToClearNames()){
try {
for (String collectionName : getCollectionsToClearNames()) {
MongoCollection<?> collection = mongoDb.getCollection(collectionName);
collection.drop();
}
}catch (IllegalArgumentException e){
} catch (IllegalArgumentException e) {
e.printStackTrace();
}

}

protected static MongoDBService getMongoDBService(){
protected static MongoDBService getMongoDBService() {
return getOpensilex().getServiceInstance(MongoDBService.DEFAULT_SERVICE, MongoDBService.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;
import java.util.logging.Level;
import java.util.stream.Collectors;

import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -142,6 +143,8 @@ private static class CustomTestContainerFactory extends GrizzlyTestContainerFact
public TestContainer create(URI baseUri, DeploymentContext context) {
if (globalTestContainer == null) {
globalTestContainer = super.create(baseUri, context);
//@todo find a better way to configure this
java.util.logging.Logger.getLogger("org.glassfish").setLevel(Level.SEVERE);
}
return globalTestContainer;
}
Expand Down Expand Up @@ -402,7 +405,6 @@ protected Invocation.Builder buildRequestBuilder(WebTarget target) {
* @throws UnsupportedOperationException if the HTTP method is not supported
*/
protected Response executeRequest(Invocation.Builder requestBuilder) {
LOGGER.debug(String.valueOf(this));
if(Objects.equals(httpMethod, HttpMethod.GET)) {
return requestBuilder.get();
} else if(Objects.equals(httpMethod, HttpMethod.POST)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public Instant logOperationStart(String type) {
}

/**
* Write a log entry with INFO level with the following key/value :
* Write a log entry with DEBUG level with the following key/value :
*
* <ul>
* <li>type: the value of {@code type} param </li>
Expand All @@ -108,15 +108,15 @@ public Instant logOperationStart(String type) {
*/
public Instant logOperationStart(String type, String key, Object value) {
if (key != null) {
logger.info(DEFAULT_MESSAGE_FORMAT, kv(LOG_TYPE_KEY, type), STATUS_START_LOG_ARG, collectionLogArgument, kv(key, value));
logger.debug(DEFAULT_MESSAGE_FORMAT, kv(LOG_TYPE_KEY, type), STATUS_START_LOG_ARG, collectionLogArgument, kv(key, value));
} else {
logger.info(DEFAULT_MESSAGE_FORMAT, kv(LOG_TYPE_KEY, type), STATUS_START_LOG_ARG, collectionLogArgument);
logger.debug(DEFAULT_MESSAGE_FORMAT, kv(LOG_TYPE_KEY, type), STATUS_START_LOG_ARG, collectionLogArgument);
}
return Instant.now();
}

/**
* Write a log entry with INFO level with the following key/value :
* Write a log entry with DEBUG level with the following key/value :
*
* <ul>
* <li>type: the value of {@code type} param </li>
Expand All @@ -134,13 +134,13 @@ public Instant logOperationStart(String type, String key, Object value) {
* @return the current {@link Instant}, pass this one to {@link #logOperationOk(String, Instant, String, Object)} method, for duration compute and write inside log
*/
public Instant logOperationStart(String type, String key, Object value, String key2, Object value2) {
logger.info(DEFAULT_MESSAGE_FORMAT, kv(LOG_TYPE_KEY, type), STATUS_START_LOG_ARG, collectionLogArgument, kv(key, value), kv(key2, value2));
logger.debug(DEFAULT_MESSAGE_FORMAT, kv(LOG_TYPE_KEY, type), STATUS_START_LOG_ARG, collectionLogArgument, kv(key, value), kv(key2, value2));
return Instant.now();
}


/**
* Write a log entry with INFO level with the following key/value :
* Write a log entry with DEBUG level with the following key/value :
* <ul>
* <li>type: the value of {@code type} param </li>
* <li>status: OK</li>
Expand All @@ -157,15 +157,15 @@ public void logOperationOk(String type, Instant start, String key, Object value)
long durationMs = Duration.between(start, Instant.now()).toMillis();
if(key != null){
if(collectionLogArgument != null){
logger.info(DEFAULT_MESSAGE_FORMAT, kv(LOG_TYPE_KEY, type), STATUS_OK_LOG_ARG, collectionLogArgument, kv(LOG_DURATION_MS_KEY, durationMs), kv(key, value));
logger.debug(DEFAULT_MESSAGE_FORMAT, kv(LOG_TYPE_KEY, type), STATUS_OK_LOG_ARG, collectionLogArgument, kv(LOG_DURATION_MS_KEY, durationMs), kv(key, value));
}else{
logger.info(DEFAULT_MESSAGE_FORMAT, kv(LOG_TYPE_KEY, type), STATUS_OK_LOG_ARG, kv(LOG_DURATION_MS_KEY, durationMs), kv(key, value));
logger.debug(DEFAULT_MESSAGE_FORMAT, kv(LOG_TYPE_KEY, type), STATUS_OK_LOG_ARG, kv(LOG_DURATION_MS_KEY, durationMs), kv(key, value));
}
}else{
if(collectionLogArgument != null) {
logger.info(DEFAULT_MESSAGE_FORMAT, kv(LOG_TYPE_KEY, type), STATUS_OK_LOG_ARG, collectionLogArgument, kv(LOG_DURATION_MS_KEY, durationMs));
logger.debug(DEFAULT_MESSAGE_FORMAT, kv(LOG_TYPE_KEY, type), STATUS_OK_LOG_ARG, collectionLogArgument, kv(LOG_DURATION_MS_KEY, durationMs));
}else{
logger.info(DEFAULT_MESSAGE_FORMAT, kv(LOG_TYPE_KEY, type), STATUS_OK_LOG_ARG, kv(LOG_DURATION_MS_KEY, durationMs));
logger.debug(DEFAULT_MESSAGE_FORMAT, kv(LOG_TYPE_KEY, type), STATUS_OK_LOG_ARG, kv(LOG_DURATION_MS_KEY, durationMs));
}
}
}
Expand All @@ -186,7 +186,7 @@ public void logOperationOk(String type, Instant start){
}

/**
* Write a log entry with INFO level with the following key/value :
* Write a log entry with DEBUG level with the following key/value :
* <ul>
* <li>type: the value of {@code type} param </li>
* <li>status: OK</li>
Expand All @@ -205,9 +205,9 @@ public void logOperationOk(String type, Instant start){
public void logOperationOk(String type, Instant start, String key, Object value, String key2, Object value2) {
long durationMs = Duration.between(start, Instant.now()).toMillis();
if(collectionLogArgument != null){
logger.info(DEFAULT_MESSAGE_FORMAT, kv(LOG_TYPE_KEY, type), STATUS_OK_LOG_ARG, collectionLogArgument, kv(LOG_DURATION_MS_KEY, durationMs), kv(key, value), kv(key2, value2));
logger.debug(DEFAULT_MESSAGE_FORMAT, kv(LOG_TYPE_KEY, type), STATUS_OK_LOG_ARG, collectionLogArgument, kv(LOG_DURATION_MS_KEY, durationMs), kv(key, value), kv(key2, value2));
}else{
logger.info(DEFAULT_MESSAGE_FORMAT, kv(LOG_TYPE_KEY, type), STATUS_OK_LOG_ARG, kv(LOG_DURATION_MS_KEY, durationMs), kv(key, value), kv(key2, value2));
logger.debug(DEFAULT_MESSAGE_FORMAT, kv(LOG_TYPE_KEY, type), STATUS_OK_LOG_ARG, kv(LOG_DURATION_MS_KEY, durationMs), kv(key, value), kv(key2, value2));
}
}

Expand Down
Loading

0 comments on commit 443a64f

Please sign in to comment.