Commit e3395ca1 authored by Rostislav Dublin (EPAM)'s avatar Rostislav Dublin (EPAM)
Browse files

Merge branch 'gcp-logging-enhancements' into 'master'

Logging Enhancements for GCP modules (GONRG-1735, GONRG-1779)

See merge request !71
parents 8823f3f5 00322b98
Pipeline #27675 passed with stages
in 38 minutes and 43 seconds
......@@ -85,6 +85,9 @@ The following software have components provided under the terms of this license:
- Joda-Time (from http://www.joda.org/joda-time/)
- Joda-Time (from http://www.joda.org/joda-time/)
- Json Path (from https://github.com/jayway/JsonPath)
- Logback Contrib :: JSON :: Classic (from )
- Logback Contrib :: JSON :: Core (from )
- Logback Contrib :: Jackson (from )
- Lucene Common Analyzers (from )
- Lucene Core (from )
- Lucene Grouping (from )
......@@ -101,15 +104,18 @@ The following software have components provided under the terms of this license:
- Lucene Spatial Extras (from )
- Lucene Suggest (from )
- MapStruct Core (from )
- Mockito (from http://mockito.org)
- Mockito (from http://www.mockito.org)
- Mockito (from http://mockito.org)
- Netty/Buffer (from http://netty.io/)
- Netty/Codec (from )
- Netty/Common (from )
- Netty/Handler (from )
- Netty/Resolver (from )
- Netty/Transport (from http://netty.io/)
- Nimbus Content Type (from https://bitbucket.org/connect2id/nimbus-content-type)
- Nimbus JOSE+JWT (from https://bitbucket.org/connect2id/nimbus-jose-jwt)
- Nimbus LangTag (from https://bitbucket.org/connect2id/nimbus-language-tags)
- OAuth 2.0 SDK with OpenID Connect extensions (from https://bitbucket.org/connect2id/oauth-2.0-sdk-with-openid-connect-extensions)
- Objenesis (from http://objenesis.org)
- OpenCensus (from https://github.com/census-instrumentation/opencensus-java)
- OpenCensus (from https://github.com/census-instrumentation/opencensus-java)
......@@ -168,8 +174,8 @@ The following software have components provided under the terms of this license:
- jackson-databind (from http://github.com/FasterXML/jackson)
- jakarta.inject (from )
- javaparser-core (from )
- javax.inject (from http://code.google.com/p/atinject/)
- javax.inject (from )
- javax.inject (from http://code.google.com/p/atinject/)
- javax.ws.rs-api (from http://jax-rs-spec.java.net)
- jersey-container-servlet (from git://java.net/jersey~code/project/jersey-container-servlet)
- jersey-container-servlet-core (from git://java.net/jersey~code/project/jersey-container-servlet-core)
......@@ -345,6 +351,9 @@ The following software have components provided under the terms of this license:
- Eclipse Xtend Active Annotations Library (from https://www.eclipse.org/Xtext/)
- Eclipse Xtend Runtime Library (from https://www.eclipse.org/Xtext/)
- Logback Classic Module (from )
- Logback Contrib :: JSON :: Classic (from )
- Logback Contrib :: JSON :: Core (from )
- Logback Contrib :: Jackson (from )
- Logback Core Module (from )
- SnakeYAML (from http://www.snakeyaml.org)
- jakarta.annotation-api (from https://projects.eclipse.org/projects/ee4j.ca)
......@@ -465,6 +474,9 @@ The following software have components provided under the terms of this license:
- Elastic JNA Distribution (from https://github.com/java-native-access/jna)
- Javassist (from http://www.javassist.org/)
- Logback Classic Module (from )
- Logback Contrib :: JSON :: Classic (from )
- Logback Contrib :: JSON :: Core (from )
- Logback Contrib :: Jackson (from )
- Logback Core Module (from )
========================================================================
......@@ -569,4 +581,6 @@ The following software have components provided under the terms of this license:
- jersey-ext-entity-filtering (from )
- jersey-inject-hk2 (from )
- jersey-media-jaxb (from )
- jersey-spring4 (from )
\ No newline at end of file
- jersey-spring4 (from )
......@@ -31,11 +31,10 @@
</parent>
<dependencies>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>core-lib-gcp</artifactId>
<version>0.1.21</version>
<version>0.6.1-SNAPSHOT</version>
</dependency>
<dependency>
......@@ -54,6 +53,12 @@
<artifactId>spring-security-config</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback.contrib</groupId>
<artifactId>logback-json-classic</artifactId>
<version>0.1.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
......
......@@ -83,7 +83,7 @@ public class DatastoreActionRepo implements IActionRepo {
@Override
public Action get(String id) {
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
Key key = createkey(ds, id);
Entity entity = ds.get(key);
if (entity == null)
......@@ -101,7 +101,7 @@ public class DatastoreActionRepo implements IActionRepo {
}
private Action createActionInDatastore(Action action) {
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
Key key = createkey(ds, action.getId());
FullEntity<Key> entity = convertActionToEntity(action, key);
......@@ -134,7 +134,7 @@ public class DatastoreActionRepo implements IActionRepo {
}
private boolean deleteFromDatastore(String id) {
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
boolean output = false;
Key key = createkey(ds, id);
......@@ -166,7 +166,7 @@ public class DatastoreActionRepo implements IActionRepo {
@Override
public List<Action> getAllActions() {
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
Query<Entity> q = Query
.newGqlQueryBuilder(Query.ResultType.ENTITY, "Select * from ACTION")
......
......@@ -65,7 +65,7 @@ public class DatastoreDdmsRepository implements IDdmsRepository {
@Override
public Ddms create(Ddms ddms) {
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
Key key = createkey(ds, ddms.getId());
FullEntity<Key> entity = convertDmsToEntity(ddms, key);
......@@ -95,7 +95,7 @@ public class DatastoreDdmsRepository implements IDdmsRepository {
@Override
public Ddms get(String id) {
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
Key key = createkey(ds, id);
Entity entity = ds.get(key);
if (entity == null)
......@@ -106,7 +106,7 @@ public class DatastoreDdmsRepository implements IDdmsRepository {
@Override
public List<Ddms> query(String type) {
List<Ddms> output = new ArrayList<>();
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
Query<Entity> q = Query
.newGqlQueryBuilder(Query.ResultType.ENTITY, "SELECT * FROM DDMS WHERE interfaces.type=@t")
.setBinding("t", type)
......@@ -122,7 +122,7 @@ public class DatastoreDdmsRepository implements IDdmsRepository {
@Override
public boolean delete(String id) {
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
boolean output = false;
Key key = createkey(ds, id);
......
......@@ -16,47 +16,42 @@
package org.opengroup.osdu.register.provider.gcp.ddms.datastore;
import static java.util.Objects.isNull;
import com.google.cloud.datastore.Datastore;
import org.apache.commons.lang3.StringUtils;
import java.util.HashMap;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.gcp.multitenancy.DatastoreFactory;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.gcp.multitenancy.IDatastoreFactory;
import org.opengroup.osdu.core.gcp.multitenancy.TenantFactory;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
@Component
@RequiredArgsConstructor
public class DatastoreMultiTenantAccess {
private final IDatastoreFactory factory;
private final Map<String, Datastore> tenantRepositories = new HashMap<>();
public DatastoreMultiTenantAccess() {
this(new DatastoreFactory(new TenantFactory()));
}
DatastoreMultiTenantAccess(IDatastoreFactory factory) {
this.factory = factory;
}
public Datastore get(String tenantName) {
if (StringUtils.isBlank(tenantName))
throw invalidTenantGivenException(tenantName);
if (!tenantRepositories.containsKey(tenantName)) {
addRepository(tenantName);
public Datastore get(TenantInfo tenantInfo) {
if (isNull(tenantInfo)){
throw invalidTenantGivenException("null");
}
if (!tenantRepositories.containsKey(tenantInfo.getName())) {
addRepository(tenantInfo);
}
return tenantRepositories.get(tenantName);
return tenantRepositories.get(tenantInfo.getName());
}
private void addRepository(String tenantName) {
Datastore ds = factory.getDatastore(tenantName, tenantName);
if (ds == null)
throw invalidTenantGivenException(tenantName);
tenantRepositories.put(tenantName, ds);
private void addRepository(TenantInfo tenantInfo) {
Datastore ds = factory.getDatastore(tenantInfo);
if (ds == null) {
throw invalidTenantGivenException(tenantInfo.getName());
}
tenantRepositories.put(tenantInfo.getName(), ds);
}
private AppException invalidTenantGivenException(String tenantName) {
......
......@@ -66,7 +66,7 @@ public class DatastoreAccess implements IDatastoreAccess {
@Override
public Subscription get(String id) {
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
Key key = createKey(ds, id);
Entity entity = ds.get(key);
if (entity == null)
......@@ -83,7 +83,7 @@ public class DatastoreAccess implements IDatastoreAccess {
@Override
public List<Subscription> query(String notificationId) {
List<Subscription> output = new ArrayList<>();
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
Query<Entity> q = Query
.newGqlQueryBuilder(Query.ResultType.ENTITY, "SELECT * FROM SUBSCRIPTION WHERE notificationId=@t")
.setBinding("t", notificationId)
......@@ -114,7 +114,7 @@ public class DatastoreAccess implements IDatastoreAccess {
@Override
public List<Subscription> getAll() throws Exception {
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
Query<Entity> q = Query
.newGqlQueryBuilder(Query.ResultType.ENTITY, "Select * from SUBSCRIPTION")
.setNamespace(NAMESPACE).build();
......@@ -131,7 +131,7 @@ public class DatastoreAccess implements IDatastoreAccess {
}
private Subscription createSubscriberInDatastore(Subscription s) {
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
Key key = createKey(ds, s.getId());
Transaction txn = ds.newTransaction();
......@@ -162,7 +162,7 @@ public class DatastoreAccess implements IDatastoreAccess {
}
private boolean deleteFromDatastore(String id, boolean deleteSubscription) {
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
boolean output = false;
Key key = createKey(ds, id);
......@@ -198,7 +198,7 @@ public class DatastoreAccess implements IDatastoreAccess {
}
private boolean updateInDataStore(String id, Secret secret) {
Datastore ds = dataStoreTenants.get(tenantInfo.getName());
Datastore ds = dataStoreTenants.get(tenantInfo);
boolean output = false;
Key key = createKey(ds, id);
......
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<springProfile name="local">
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%yellow([%thread]) %highlight(| %-5level |) %green(%d) %cyan(| %logger{15} |) %highlight(%msg) %n</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="CONSOLE"/>
</root>
</springProfile>
<springProfile name="!local">
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="ch.qos.logback.contrib.json.classic.JsonLayout">
<timestampFormat>yyyy-MM-dd HH:mm:ss.SSS</timestampFormat>
<timestampFormatTimezoneId>Etc/UTC</timestampFormatTimezoneId>
<appendLineSeparator>true</appendLineSeparator>
<jsonFormatter class="org.opengroup.osdu.core.gcp.logging.formatter.GoogleJsonFormatter">
<prettyPrint>false</prettyPrint>
</jsonFormatter>
</layout>
</encoder>
</appender>
<root level="debug">
<appender-ref ref="stdout"/>
</root>
</springProfile>
</configuration>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment