Common Library is designed to support common functionality used by other QSTP (Qubership Testing Platform) libraries and services. The functionality is:
- Requests/responses logging,
- Lock Mechanism for migration scripts running in multi-pod service architecture
- Undertow metrics collecting,
- Liveness/readyness probes,
- Some more specific functionality used internally.
In IntelliJ IDEA, one can select 'github' Profile in Maven Settings menu on the right, then expand Lifecycle dropdown of qubership-atp-common module, then select 'clean' and 'install' options and click 'Run Maven Build' green arrow button on the top.
Or, one can execute the command:
mvn -P github clean install<dependencies>
...
<dependency>
<groupId>org.qubership.atp.common</groupId>
<artifactId>qubership-atp-common-logging</artifactId>
<version>0.0.42</version>
</dependency>
...
</dependencies>atp.logging.resttemplate.headers=${ATP_HTTP_LOGGING_HEADERS:true}
atp.logging.resttemplate.headers.ignore=${ATP_HTTP_LOGGING_HEADERS_IGNORE:}
atp.logging.feignclient.headers=${ATP_HTTP_LOGGING_HEADERS:true}
atp.logging.feignclient.headers.ignore=${ATP_HTTP_LOGGING_HEADERS_IGNORE:}- By default, atp.logging.resttemplate.headers value is false.
- atp.logging.resttemplate.headers is used to log headers of requests/responses for RelayRestTemplate and M2MRestTemplate.
- atp.logging.resttemplate.headers.ignore is used to ignore specified headers while logging. Tokens should be separated with spaces.
- atp.logging.feignclient.headers is used to log headers of requests/responses for FeignClient.
- atp.logging.feignclient.headers.ignore is used to ignore specified headers while logging for FeignClient. Tokens should be separated with spaces.
- Parameters atp.logging.resttemplate.headers.ignore and atp.logging.feignclient.headers.ignore support regular expressions.
<if condition='${ATP_HTTP_LOGGING}'>
<then>
<logger name="org.qubership.atp.common.logging.interceptor.RestTemplateLogInterceptor" level="DEBUG" additivity="false">
<appender-ref ref="ASYNC_GELF"/>
</logger>
<logger name="org.qubership.atp.catalogue.service.client.feign.DatasetFeignClient" level="DEBUG" additivity="false">
<appender-ref ref="ASYNC_GELF"/>
</logger>
</then>
</if>To turn ON logging on local machine, one needs to add the following options to JVM:
-Dlogging.level.org.qubership.atp.common.logging.interceptor.RestTemplateLogInterceptor=debug
-Dlogging.level.org.qubership.atp.catalogue.service.client.feign.DatasetFeignClient=debugAdd dependency in pom
<dependency>
<groupId>org.qubership.atp.common</groupId>
<artifactId>qubership-atp-common-lock-manager</artifactId>
<version>0.0.42</version>
</dependency>In Main class or new Configuration class add annotation @EnableAtpLockManager
By default, it uses the InMemory provider. That is mean the LockManager stores the records about locks in memory of application. There is possible to change provider to keep this records in database for example. In order that, create Configuration class and define the LockProvider bean. Example for mongodb:
1. Add dependency
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-provider-mongo</artifactId>
<version>4.12.0</version>
</dependency>2. Add Configuration class
@Configuration
@EnableAtpLockManager
public class LockManagerConfig {
// some code
@Bean
public LockProvider lockProvider(MongoClient mongoClient) {
MongoDatabase mongoDatabase = mongoClient.getDatabase(getDatabaseName());
return new MongoLockProvider(mongoDatabase);
}
}If your application uses jdbc, then use appropriate dependency and rule for setting up the configuration.
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-provider-jdbc-template</artifactId>
<version>4.12.0</version>
</dependency>For all list of available implementation of provider see page ShedLock LockProviders page at GitHub (The LockManager is based on the ShedLock library)
In order to do something and make lock so that another thread is waiting completeness first one do the following :
1. add LockManager in your service
@Autowired
private LockManager lockManager;2. Call execute executeWithLock
lockManager.executeWithLock(lockName, () -> {<do something>});
##=============Lock Manager========================
atp.lock.default.duration.sec=${LOCK_DEFAULT_DURATION_SEC:60}
atp.lock.retry.timeout.sec=${LOCK_RETRY_TIMEOUT_SEC:10800}
atp.lock.retry.pace.sec=${LOCK_RETRY_PACE_SEC:3}- atp.lock.default.duration.sec - duration of retention an acquired lock in case it is not released.
- atp.lock.retry.timeout.sec - duration for the Lock Manager during which it is trying to acquire a lock.
- atp.lock.retry.pace.sec - pause between two retries of acquiring a lock.