test-api-clearing http://git.mfd.msk/mfd/clearing/-/issues/31 Перенёс в отдельный git-репо
This commit is contained in:
parent
0befdfab92
commit
269a74960b
19 changed files with 0 additions and 1488 deletions
|
|
@ -35,7 +35,6 @@
|
||||||
<module>clearing-service</module>
|
<module>clearing-service</module>
|
||||||
<module>registry-service</module>
|
<module>registry-service</module>
|
||||||
<module>test-clearing</module>
|
<module>test-clearing</module>
|
||||||
<module>test-api-clearing</module>
|
|
||||||
<module>cleaning-builders</module>
|
<module>cleaning-builders</module>
|
||||||
<module>trade-importer</module>
|
<module>trade-importer</module>
|
||||||
<module>lim-exporter</module>
|
<module>lim-exporter</module>
|
||||||
|
|
|
||||||
|
|
@ -1,167 +0,0 @@
|
||||||
<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">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>ru.spcex.clearing</groupId>
|
|
||||||
<artifactId>clearing-parent</artifactId>
|
|
||||||
<version>SPCEX-1.0.0.0</version>
|
|
||||||
</parent>
|
|
||||||
<artifactId>test-api-clearing</artifactId>
|
|
||||||
<name>Test-api-clearing</name>
|
|
||||||
<version>SPCEX-1.0.0.0</version>
|
|
||||||
<description>
|
|
||||||
Тестовые контроллеры для отладки клиринговой системы.
|
|
||||||
Только для разработчиков.
|
|
||||||
</description>
|
|
||||||
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
|
|
||||||
<keycloak-spring-boot-starter.version>17.0.1</keycloak-spring-boot-starter.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>ru.spcex.platform</groupId>
|
|
||||||
<artifactId>platform-messaging</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>ru.spcex.platform</groupId>
|
|
||||||
<artifactId>platform-enum</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>ru.spcex.platform</groupId>
|
|
||||||
<artifactId>platform-enum</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>ru.spcex.clearing</groupId>
|
|
||||||
<artifactId>classes</artifactId>
|
|
||||||
<version>SPCEX-1.0.0.0</version>
|
|
||||||
<!-- <scope>compile</scope>-->
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>ru.spcex.clearing</groupId>
|
|
||||||
<artifactId>dictionary</artifactId>
|
|
||||||
<version>SPCEX-1.0.0.0</version>
|
|
||||||
<!-- <scope>compile</scope>-->
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>ru.spcex.platform</groupId>
|
|
||||||
<artifactId>platform-imdg-api</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>ru.spcex.platform</groupId>
|
|
||||||
<artifactId>platform-imdg-api-hazelcast-impl</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>ru.spcex.clearing</groupId>
|
|
||||||
<artifactId>classes</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
|
||||||
<artifactId>jackson-databind</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
|
||||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- <dependency>-->
|
|
||||||
<!-- <groupId>ru.spcex.clearing</groupId>-->
|
|
||||||
<!-- <artifactId>test-clearing</artifactId>-->
|
|
||||||
<!-- <scope>test</scope>-->
|
|
||||||
<!-- </dependency>-->
|
|
||||||
|
|
||||||
<!-- <dependency>-->
|
|
||||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
|
||||||
<!-- <artifactId>spring-boot-starter-web</artifactId>-->
|
|
||||||
<!-- </dependency>-->
|
|
||||||
<!-- <dependency>-->
|
|
||||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
|
||||||
<!-- <artifactId>spring-boot-starter-security</artifactId>-->
|
|
||||||
<!-- </dependency>-->
|
|
||||||
<!-- <dependency>-->
|
|
||||||
<!-- <groupId>org.keycloak</groupId>-->
|
|
||||||
<!-- <artifactId>keycloak-spring-boot-starter</artifactId>-->
|
|
||||||
<!-- <version>${keycloak-spring-boot-starter.version}</version>-->
|
|
||||||
<!-- </dependency>-->
|
|
||||||
|
|
||||||
<!-- <dependency>-->
|
|
||||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
|
||||||
<!-- <artifactId>spring-security-config</artifactId>-->
|
|
||||||
<!-- </dependency>-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>ru.spcex.platform</groupId>
|
|
||||||
<artifactId>platform-imdg-api-hazelcast-impl</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-lang3</artifactId>
|
|
||||||
<version>3.7</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- <dependency>-->
|
|
||||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
|
||||||
<!-- <artifactId>spring-boot-starter-web</artifactId>-->
|
|
||||||
<!-- </dependency>-->
|
|
||||||
<!-- <dependency>-->
|
|
||||||
<!-- <groupId>io.springfox</groupId>-->
|
|
||||||
<!-- <artifactId>springfox-swagger2</artifactId>-->
|
|
||||||
<!-- </dependency>-->
|
|
||||||
<!-- <dependency>-->
|
|
||||||
<!-- <groupId>io.springfox</groupId>-->
|
|
||||||
<!-- <artifactId>springfox-swagger-ui</artifactId>-->
|
|
||||||
<!-- </dependency>-->
|
|
||||||
<!--<dependency>
|
|
||||||
<groupId>org.keycloak</groupId>
|
|
||||||
<artifactId>keycloak-spring-boot-starter</artifactId>
|
|
||||||
<version>${keycloak-spring-boot-starter.version}</version>
|
|
||||||
</dependency>-->
|
|
||||||
|
|
||||||
<!-- TEST -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<resources>
|
|
||||||
<resource>
|
|
||||||
<directory>src/main/resources</directory>
|
|
||||||
<excludes>
|
|
||||||
<exclude>application.properties</exclude>
|
|
||||||
</excludes>
|
|
||||||
<filtering>false</filtering>
|
|
||||||
</resource>
|
|
||||||
</resources>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>repackage</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
<configuration>
|
|
||||||
<finalName>${project.artifactId}</finalName>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
|
|
||||||
</build>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
|
|
@ -1,135 +0,0 @@
|
||||||
package ru.spcex.clearing.test;
|
|
||||||
|
|
||||||
import com.hazelcast.config.MapStoreConfig;
|
|
||||||
import com.hazelcast.core.DistributedObject;
|
|
||||||
import com.hazelcast.core.HazelcastInstance;
|
|
||||||
import com.hazelcast.core.IMap;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import ru.clearing.classes.objects.BusinessObject;
|
|
||||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
|
||||||
import ru.spcex.platform.imdg.iml.hazelcast.util.HazelcastHelper;
|
|
||||||
import ru.spcex.platform.utils.log.ExceptionUtils;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.*;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class ImdgService {
|
|
||||||
protected final Logger log = LoggerFactory.getLogger(getClass());
|
|
||||||
|
|
||||||
HazelcastInstance hazelcastServerInstance;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public ImdgService(HazelcastInstance hazelcastServerInstance) {
|
|
||||||
this.hazelcastServerInstance = hazelcastServerInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
Collection<String> allMaps() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int reloadMapFromDB(List<String> warningMsgs) {
|
|
||||||
log.info("Reload all from DB...");
|
|
||||||
long loadTime = System.currentTimeMillis();
|
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
HashSet<String> ignoreUpdateMap = new HashSet<>(); // Эти мапы не должны обновляться
|
|
||||||
ignoreUpdateMap.add(IMDGDistributedNames.Map_RequestInfo);
|
|
||||||
ignoreUpdateMap.add(HazelcastHelper.CLEARING_SYSTEM_MAP);
|
|
||||||
ignoreUpdateMap.add(HazelcastHelper.STATE_OF_IMDG_SERVER);
|
|
||||||
|
|
||||||
// no mapstore:
|
|
||||||
ignoreUpdateMap.add(IMDGDistributedNames.Map_LiabilitiesClaimsAssets);
|
|
||||||
ignoreUpdateMap.add(IMDGDistributedNames.Map_AccountBalance);
|
|
||||||
ignoreUpdateMap.add(IMDGDistributedNames.Map_KeyRate);
|
|
||||||
ignoreUpdateMap.add(IMDGDistributedNames.Map_LiabilitiesClaimsMoney);
|
|
||||||
ignoreUpdateMap.add("Map_TaskCodeDictionary");
|
|
||||||
ignoreUpdateMap.add("Map_TaskcodeDictionary");
|
|
||||||
|
|
||||||
try {
|
|
||||||
List<Callable<Long>> tasks = new ArrayList<>();
|
|
||||||
// На сервере так: Collection<String> mapNames = hazelcastServerInstance.getConfig().getMapConfigs().keySet();
|
|
||||||
// На клиенте:
|
|
||||||
List<String> mapNames = new ArrayList<>();
|
|
||||||
for (DistributedObject object : hazelcastServerInstance.getDistributedObjects()) {
|
|
||||||
if (object instanceof IMap) // MapProxyImpl
|
|
||||||
mapNames.add(((IMap) object).getName());
|
|
||||||
}
|
|
||||||
for (String mapName : mapNames) {
|
|
||||||
if (ignoreUpdateMap.contains(mapName)) {
|
|
||||||
log.debug("Ignore sync for map {}", mapName);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
AtomicInteger errorCount=new AtomicInteger(0);
|
|
||||||
tasks.add(() -> {
|
|
||||||
Long maxKey = null;
|
|
||||||
// MapStoreConfig mapStoreConfig = hazelcastServerInstance.getConfig().getMapConfig(mapName).getMapStoreConfig();
|
|
||||||
// if (mapStoreConfig != null && mapStoreConfig.isEnabled()) {
|
|
||||||
try {
|
|
||||||
long start = System.currentTimeMillis();
|
|
||||||
log.debug("evict map {}", mapName);
|
|
||||||
IMap<Long, BusinessObject> map = hazelcastServerInstance.getMap(mapName);
|
|
||||||
int size1 = map.size();
|
|
||||||
map.evictAll();
|
|
||||||
log.debug("Load map {}", mapName);
|
|
||||||
map.loadAll(false);
|
|
||||||
int size = map.size();
|
|
||||||
long time = System.currentTimeMillis() - start;
|
|
||||||
log.debug("{} {} rows reloaded in {}ms", mapName, size, time);
|
|
||||||
if (size1 != size)
|
|
||||||
log.warn("Map {} change size from {} to {}", mapName, size1, size);
|
|
||||||
|
|
||||||
maxKey = map.keySet().stream().max(Long::compareTo).orElse(null);
|
|
||||||
|
|
||||||
log.trace("{} max(id)={}", mapName, maxKey);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
// когда нет MapStore: java.lang.IllegalArgumentException: First you should configure a map store at com.hazelcast.util.Preconditions.checkTrue(Preconditions.java:327)
|
|
||||||
// Такая ошибка обычно возникает во время разработки при частичном перезапуске IMDG (без отключения тестового сервиса) при работе над мапами.
|
|
||||||
log.error("Can not reload map \"{}\" cause: {}", mapName, ExceptionUtils.getStackTrace(e));
|
|
||||||
if (warningMsgs != null)
|
|
||||||
warningMsgs.add("Can not load from map \"" + mapName + "\" " + e.getMessage());
|
|
||||||
if (errorCount.incrementAndGet() > 10) {
|
|
||||||
throw new RuntimeException("Can not reload map " + mapName+", too many errors", e);
|
|
||||||
}
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
throw new RuntimeException("Can not reload map " + mapName, e);
|
|
||||||
}
|
|
||||||
return maxKey;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
long maxKey = 0L;
|
|
||||||
int threadCount = 2; //Runtime.getRuntime().availableProcessors();
|
|
||||||
log.info("Initializing threads count = {}", threadCount);
|
|
||||||
ExecutorService executor = Executors.newWorkStealingPool(threadCount);
|
|
||||||
try {
|
|
||||||
List<Future<Long>> results = executor.invokeAll(tasks);
|
|
||||||
for (Future<Long> result : results) {
|
|
||||||
Long maxKeyResult = result.get();
|
|
||||||
if (maxKeyResult != null) {
|
|
||||||
maxKey = Math.max(maxKey, maxKeyResult);
|
|
||||||
}
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
executor.shutdown();
|
|
||||||
}
|
|
||||||
log.info("IDGenerator can not reinit. Max map ID {}", maxKey);
|
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
|
||||||
if (e instanceof InterruptedException) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
throw new RuntimeException("MapStore multithreaded reload not complete.", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
loadTime = System.currentTimeMillis() - loadTime;
|
|
||||||
log.info("All {} map reload time {} ms", count, loadTime);
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
package ru.spcex.clearing.test;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import com.fasterxml.jackson.databind.JavaType;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.util.ClassUtils;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class KafkaService {
|
|
||||||
private static final ObjectMapper json = new ObjectMapper();
|
|
||||||
protected final Logger log = LoggerFactory.getLogger(getClass());
|
|
||||||
private final KafkaSender kafkaSender;
|
|
||||||
|
|
||||||
@Autowired(required = false)
|
|
||||||
public KafkaService(KafkaSender kafkaSender) {
|
|
||||||
this.kafkaSender = kafkaSender;
|
|
||||||
}
|
|
||||||
|
|
||||||
Collection<String> allTopics() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long putMessage(String fullClassName, String topic, String jsonBody) throws ClassNotFoundException, JsonProcessingException {
|
|
||||||
if (kafkaSender == null) {
|
|
||||||
throw new IllegalStateException("Kafka action disabled");
|
|
||||||
}
|
|
||||||
log.info("Call test method for kafka, class=\"{}\"; topic=\"{}\"; message=\"{}\"", fullClassName, topic, jsonBody);
|
|
||||||
if (StringUtils.isEmpty(fullClassName)) throw new IllegalArgumentException("Class was emppty");
|
|
||||||
if (StringUtils.isEmpty(topic)) throw new IllegalArgumentException("Topic was emppty");
|
|
||||||
if (StringUtils.isEmpty(jsonBody)) throw new IllegalArgumentException("json was emppty");
|
|
||||||
|
|
||||||
Class<?> parameterType = ClassUtils.forName(fullClassName, ClassUtils.getDefaultClassLoader());
|
|
||||||
JavaType requestType = json.getTypeFactory().constructSimpleType(parameterType, null);
|
|
||||||
Object obj = json.readValue(jsonBody, requestType);
|
|
||||||
Long idOfBaseRequestMessage = kafkaSender.sendRequestToQueue(topic, obj);
|
|
||||||
log.debug("Test message to topic {} with request id={}", topic, idOfBaseRequestMessage);
|
|
||||||
return idOfBaseRequestMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
package ru.spcex.clearing.test;
|
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
|
||||||
public class TestApiClearingApplication {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
// ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(SpringEnableComponentScanConfig.class);
|
|
||||||
// StartupInfo startupInfo = context.getBean(StartupInfo.class);
|
|
||||||
// startupInfo.logStart();
|
|
||||||
// try {
|
|
||||||
// ProcessorService processorService = context.getBean(ProcessorService.class);
|
|
||||||
// processorService.process();
|
|
||||||
// } finally {
|
|
||||||
// startupInfo.logEnd();
|
|
||||||
// context.close();
|
|
||||||
// }
|
|
||||||
|
|
||||||
//todo not spring boot, please
|
|
||||||
SpringApplication springApplication = new SpringApplication(TestApiClearingApplication.class);
|
|
||||||
springApplication.run(args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,265 +0,0 @@
|
||||||
package ru.spcex.clearing.test.config;
|
|
||||||
|
|
||||||
import com.hazelcast.client.HazelcastClient;
|
|
||||||
import com.hazelcast.client.config.ClientConfig;
|
|
||||||
import com.hazelcast.core.*;
|
|
||||||
import com.hazelcast.query.Predicate;
|
|
||||||
import com.hazelcast.query.Predicates;
|
|
||||||
import com.hazelcast.query.SqlPredicate;
|
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
|
||||||
import ru.spcex.clearing.test.config.settings.TestServiceSettings;
|
|
||||||
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
|
||||||
import ru.spcex.platform.imdg.api.Imdg;
|
|
||||||
import ru.spcex.platform.imdg.api.ImdgId;
|
|
||||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
|
||||||
import ru.spcex.platform.imdg.api.ImdgTransaction;
|
|
||||||
import ru.spcex.platform.imdg.iml.hazelcast.adapter.ImdgIdGeneratorHazelcast;
|
|
||||||
import ru.spcex.platform.imdg.iml.hazelcast.adapter.ImdgTransactionalHazelcast;
|
|
||||||
import ru.spcex.platform.imdg.iml.hazelcast.config.HazelcastClientParams;
|
|
||||||
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
|
|
||||||
import ru.spcex.platform.imdg.iml.hazelcast.util.HazelcastHelper;
|
|
||||||
import ru.spcex.platform.utils.log.ExceptionUtils;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class ImdgConfig {
|
|
||||||
Logger log = LoggerFactory.getLogger(getClass());
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
@Bean
|
|
||||||
public ImdgProvider imdgProvider(
|
|
||||||
// @Qualifier("taskExecutorHazelcastClientInitializer") ThreadPoolTaskExecutor taskExecutorHazelcastClientInitializer,
|
|
||||||
// @Qualifier("taskExecutorIdGeneratorAwaiter") ThreadPoolTaskExecutor taskExecutorIdGeneratorAwaiter,
|
|
||||||
TestServiceSettings clientSetting, HazelcastInstance hcInstance
|
|
||||||
) {
|
|
||||||
// ImdgProvider imdg = new HazelcastService(taskExecutorHazelcastClientInitializer,
|
|
||||||
// taskExecutorIdGeneratorAwaiter,
|
|
||||||
// clientSetting.getHazelcast());
|
|
||||||
|
|
||||||
ImdgProvider imdg = new ImdgProvider() {
|
|
||||||
@Override
|
|
||||||
public <T extends SpcexObjectBase> Imdg<T> getImdg(String key, Class<T> clazz) {
|
|
||||||
ImdgDirectHazelcast<T> imdg = new ImdgDirectHazelcast<>();
|
|
||||||
imdg.setMap(hcInstance.getMap(key));
|
|
||||||
imdg.setHzInstance(hcInstance);
|
|
||||||
imdg.setMapName(key);
|
|
||||||
imdg.setIdGenerator(hcInstance.getIdGenerator(IMDGDistributedNames.MAP_SEQUENCE_NAME));
|
|
||||||
return imdg;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ImdgId getImdgIdGenerator() {
|
|
||||||
ImdgIdGeneratorHazelcast generator = new ImdgIdGeneratorHazelcast();
|
|
||||||
generator.setIdGenerator(hcInstance.getIdGenerator(IMDGDistributedNames.MAP_SEQUENCE_NAME));
|
|
||||||
return generator;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ImdgTransaction newTransaction() {
|
|
||||||
throw new UnsupportedOperationException("Stump has not implement high level function");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return imdg;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
@Bean("imdgNative")
|
|
||||||
public HazelcastInstance imdgNativeService(TestServiceSettings settings) {
|
|
||||||
HazelcastClientParams settingsElementHazelcastClient = settings.getHazelcast();
|
|
||||||
HazelcastInstance hazelcastInstance;
|
|
||||||
log.info("Hazelcast: client init");
|
|
||||||
ClientConfig clientConfig = HazelcastHelper.getClientConfig(
|
|
||||||
settingsElementHazelcastClient.getClusterMembers(),
|
|
||||||
settingsElementHazelcastClient.getLogin(),
|
|
||||||
settingsElementHazelcastClient.getPassword(),
|
|
||||||
settingsElementHazelcastClient.getInstanceName(),
|
|
||||||
settingsElementHazelcastClient.getNearCacheConfig()
|
|
||||||
);
|
|
||||||
// hazelcastInstance = Mockito.mock(HazelcastInstance.class); // debug
|
|
||||||
log.info("Hazelcast: client created, trying connect to server ({}) ...", settingsElementHazelcastClient.getClusterMembers());
|
|
||||||
hazelcastInstance = HazelcastClient.newHazelcastClient(clientConfig);
|
|
||||||
log.info("Hazelcast: client created and connected");
|
|
||||||
return hazelcastInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static class ImdgDirectHazelcast<T extends SpcexObjectBase> implements Imdg<T> {
|
|
||||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
|
||||||
private IdGenerator idGenerator;
|
|
||||||
|
|
||||||
private IMap<Long, T> map;
|
|
||||||
|
|
||||||
private String mapName;
|
|
||||||
|
|
||||||
private HazelcastInstance hzInstance;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Long insert(T paramT) {
|
|
||||||
if (paramT.getId() == null) {
|
|
||||||
paramT.setId(idGenerator.newId());
|
|
||||||
}
|
|
||||||
map.put(paramT.getId(), paramT);
|
|
||||||
return paramT.getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void lockAndPerform(Runnable operation) {
|
|
||||||
ILock hzLock = null;
|
|
||||||
try {
|
|
||||||
//в качестве альтернативы getCPSubsystem, поддерживается только при 3+ нодах хазелкаста
|
|
||||||
hzLock = hzInstance.getLock(mapName);
|
|
||||||
hzLock.lock();
|
|
||||||
operation.run();
|
|
||||||
} finally {
|
|
||||||
if (hzLock != null) {
|
|
||||||
try {
|
|
||||||
hzLock.unlock();
|
|
||||||
} catch (Throwable e) {
|
|
||||||
log.error("{} {}", mapName, ExceptionUtils.getStackTrace(e));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update(T paramT) {
|
|
||||||
map.put(paramT.getId(), paramT);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void delete(T paramT) {
|
|
||||||
map.remove(paramT.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public T getSingleObjectByID(Long paramLong) {
|
|
||||||
return map.get(paramLong);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* возвращает объект удовлетворяющий условиям
|
|
||||||
* не проверяет, если удовлетворяющих условиям > 1
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
|
||||||
public T getFirstObjectByFieldValues(Map<String, ? extends Comparable<?>> conditions) {
|
|
||||||
Predicate<Long, ?>[] predicates = new Predicate[conditions.size()];
|
|
||||||
final int[] i = {0};
|
|
||||||
conditions.forEach((key, value) -> {
|
|
||||||
predicates[i[0]] = Predicates.equal(key, value);
|
|
||||||
i[0]++;
|
|
||||||
});
|
|
||||||
Predicate<Long, T> and = Predicates.and(predicates);
|
|
||||||
Set<Long> ids = map.keySet(and);
|
|
||||||
Iterator<Long> idsIterator = ids.iterator();
|
|
||||||
if (idsIterator.hasNext()) {
|
|
||||||
return map.get(idsIterator.next());
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public T getFirstObjectBySQL(String paramString) {
|
|
||||||
SqlPredicate sqlPredicate = new SqlPredicate(paramString);
|
|
||||||
Set<Long> found = map.keySet(sqlPredicate);
|
|
||||||
Iterator<Long> allFoundByCondition = found.iterator();
|
|
||||||
if (allFoundByCondition.hasNext()) {
|
|
||||||
return map.get(allFoundByCondition.next());
|
|
||||||
} else return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public T getSingleObjectBySQL(String paramString) {
|
|
||||||
SqlPredicate sqlPredicate = new SqlPredicate(paramString);
|
|
||||||
Set<Long> found = map.keySet(sqlPredicate);
|
|
||||||
if (found.size() > 1) {
|
|
||||||
throw new RuntimeException("More than one element found by predicate [" + paramString + "] - " + found.size());
|
|
||||||
}
|
|
||||||
Iterator<Long> allFoundByCondition = found.iterator();
|
|
||||||
if (allFoundByCondition.hasNext()) {
|
|
||||||
return map.get(allFoundByCondition.next());
|
|
||||||
} else return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<T> getCollectionObjectsBySQL(String paramString) {
|
|
||||||
SqlPredicate sqlPredicate = new SqlPredicate(paramString);
|
|
||||||
Collection<T> found = map.values(sqlPredicate);
|
|
||||||
List<T> result = new ArrayList<>(found); // Hazelcast может вернуть proxy-коллекцию
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* возвращает коллекцию объектов, удовлетворяющий условиям на поля
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
|
||||||
public Collection<T> getCollectionObjectsByFieldValues(Map<String, ? extends Comparable<?>> conditions) {
|
|
||||||
Predicate<Long, ?>[] predicates = new Predicate[conditions.size()];
|
|
||||||
final int[] i = {0};
|
|
||||||
conditions.forEach((key, value) -> {
|
|
||||||
predicates[i[0]] = Predicates.equal(key, value);
|
|
||||||
i[0]++;
|
|
||||||
});
|
|
||||||
Predicate<Long, T> or = Predicates.or(predicates);
|
|
||||||
Set<Long> ids = map.keySet(or);
|
|
||||||
Iterator<Long> idIterator = ids.iterator();
|
|
||||||
Collection<T> searchResult = new ArrayList<>();
|
|
||||||
while (idIterator.hasNext()) {
|
|
||||||
T element = map.get(idIterator.next());
|
|
||||||
if (element != null) {
|
|
||||||
searchResult.add(element);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return searchResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IMap<Long, T> getMap() {
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMap(IMap<Long, T> map) {
|
|
||||||
this.map = map;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IdGenerator getIdGenerator() {
|
|
||||||
return idGenerator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIdGenerator(IdGenerator idGenerator) {
|
|
||||||
this.idGenerator = idGenerator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HazelcastInstance getHzInstance() {
|
|
||||||
return hzInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHzInstance(HazelcastInstance hzInstance) {
|
|
||||||
this.hzInstance = hzInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMapName() {
|
|
||||||
return mapName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMapName(String mapName) {
|
|
||||||
this.mapName = mapName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Long nextIDSequenceFor() {
|
|
||||||
return idGenerator.newId();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,73 +0,0 @@
|
||||||
package ru.spcex.clearing.test.config;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
|
||||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectReader;
|
|
||||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
|
||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
// todo it is copy-paste from test-clearing
|
|
||||||
public class JsonUtil {
|
|
||||||
|
|
||||||
public static <T> List<T> readValues(String json, Class<T> clazz) {
|
|
||||||
ObjectReader reader = JacksonObjectMapper.getMapper().readerFor(clazz);
|
|
||||||
try {
|
|
||||||
return reader.<T>readValues(json).readAll();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new IllegalArgumentException("Invalid read array from JSON:\n'" + json + "'", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> T readValue(String json, Class<T> clazz) {
|
|
||||||
try {
|
|
||||||
return JacksonObjectMapper.getMapper().readValue(json, clazz);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new IllegalArgumentException("Invalid read from JSON:\n'" + json + "'", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> String writeValue(T obj) {
|
|
||||||
try {
|
|
||||||
return JacksonObjectMapper.getMapper().writeValueAsString(obj);
|
|
||||||
} catch (JsonProcessingException e) {
|
|
||||||
throw new IllegalStateException("Invalid write to JSON:\n'" + obj + "'", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> String writeIgnoreProps(T obj, String... ignoreProps) {
|
|
||||||
Map<String, Object> map = JacksonObjectMapper.getMapper().convertValue(obj, new TypeReference<>() {
|
|
||||||
});
|
|
||||||
map.keySet().removeAll(Set.of(ignoreProps));
|
|
||||||
return writeValue(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class JacksonObjectMapper extends ObjectMapper {
|
|
||||||
private static final ObjectMapper MAPPER = new JacksonObjectMapper();
|
|
||||||
|
|
||||||
private JacksonObjectMapper() {
|
|
||||||
//настройки Ильи
|
|
||||||
configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
|
|
||||||
//модуль для корректной сериализации LocalDateTime в поля JSON - JavaTimeModule модуль библиотеки jackson-datatype-jsr310
|
|
||||||
registerModule(new JavaTimeModule());
|
|
||||||
configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
|
||||||
//запрещаем доступ ко всем полям и методам класса и потом разрешаем доступ только к полям, нужны чтобы не было лишних полей из-за методов как: public ActionType getActionType() у BankAccountNewAction
|
|
||||||
setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
|
|
||||||
setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
|
|
||||||
//не сериализуем null-поля
|
|
||||||
// setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ObjectMapper getMapper() {
|
|
||||||
return MAPPER;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,84 +0,0 @@
|
||||||
package ru.spcex.clearing.test.config;
|
|
||||||
|
|
||||||
import org.apache.kafka.clients.consumer.Consumer;
|
|
||||||
import org.apache.kafka.clients.producer.Producer;
|
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
||||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.context.annotation.Scope;
|
|
||||||
import org.springframework.kafka.core.KafkaTemplate;
|
|
||||||
import org.springframework.kafka.core.ProducerFactory;
|
|
||||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
|
||||||
import ru.spcex.clearing.platform.messaging.config.KafkaConsumerFactory;
|
|
||||||
import ru.spcex.clearing.platform.messaging.config.KafkaProducerFactory;
|
|
||||||
import ru.spcex.clearing.platform.messaging.config.element.KafkaProducerSettings;
|
|
||||||
import ru.spcex.clearing.platform.messaging.service.RequestInfo;
|
|
||||||
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
|
|
||||||
import ru.spcex.clearing.test.config.settings.TestServiceSettings;
|
|
||||||
import ru.spcex.platform.imdg.api.Imdg;
|
|
||||||
import ru.spcex.platform.imdg.api.ImdgId;
|
|
||||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class KafkaConfig {
|
|
||||||
Logger log = LoggerFactory.getLogger(getClass());
|
|
||||||
// @Autowired
|
|
||||||
// @Bean
|
|
||||||
// @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
|
||||||
// public Consumer<String, Object> createConsumer(TestServiceSettings settings) {
|
|
||||||
// return KafkaConsumerFactory.consumer(settings.getKafkaConsumer());
|
|
||||||
//// return Mockito.mock(Consumer.class);
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
@Bean
|
|
||||||
public Producer<String, Object> createProducer(TestServiceSettings settings) {
|
|
||||||
return KafkaProducerFactory.producer(settings.getKafkaProducer());
|
|
||||||
// return Mockito.mock(Producer.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public ProducerFactory<String, Object> pf(TestServiceSettings settings) {
|
|
||||||
KafkaProducerSettings kafkaSettings = settings.getKafkaProducer();
|
|
||||||
if (kafkaSettings == null) {
|
|
||||||
log.warn("Kafka config not set - disable kafca function");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return KafkaProducerFactory.producerFactory(kafkaSettings);
|
|
||||||
// return Mockito.mock(ProducerFactory.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Autowired(required = false)
|
|
||||||
@Bean("kafkaTemplate")
|
|
||||||
public KafkaTemplate<String, Object> kafkaTemplate(ProducerFactory<String, Object> pf) {
|
|
||||||
if (pf == null) return null;
|
|
||||||
return new KafkaTemplate<>(pf);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Autowired(required = false)
|
|
||||||
@Bean
|
|
||||||
public KafkaSender kafkaSender(@Qualifier("kafkaTemplate") KafkaTemplate<String, Object> kafkaTemplate,
|
|
||||||
ImdgProvider imdgProvider
|
|
||||||
) {
|
|
||||||
if (kafkaTemplate == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
ImdgId imdgIdGenerator = imdgProvider.getImdgIdGenerator();
|
|
||||||
return KafkaSender
|
|
||||||
.setup()
|
|
||||||
.setKafkaTemplate(kafkaTemplate)
|
|
||||||
.idGenerator(imdgIdGenerator::nextId)
|
|
||||||
.imdgProvider(s -> {
|
|
||||||
Imdg<RequestInfo> imdg = imdgProvider.getImdg(IMDGDistributedNames.Map_RequestInfo, RequestInfo.class);
|
|
||||||
return imdg::insert;
|
|
||||||
})
|
|
||||||
.build();
|
|
||||||
|
|
||||||
// return Mockito.mock(KafkaSender.class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
package ru.spcex.clearing.test.config.settings;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Debug config
|
|
||||||
*/
|
|
||||||
public class ControllerSettings {
|
|
||||||
private String port;
|
|
||||||
private String contextPath;
|
|
||||||
|
|
||||||
public String getPort() {
|
|
||||||
return port;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPort(String port) {
|
|
||||||
this.port = port;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getContextPath() {
|
|
||||||
return contextPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setContextPath(String contextPath) {
|
|
||||||
this.contextPath = contextPath;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
package ru.spcex.clearing.test.config.settings;
|
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.PropertySource;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import ru.spcex.clearing.platform.messaging.config.element.KafkaConsumerSettings;
|
|
||||||
import ru.spcex.clearing.platform.messaging.config.element.KafkaProducerSettings;
|
|
||||||
import ru.spcex.platform.imdg.iml.hazelcast.config.HazelcastClientParams;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@PropertySource("file:${spring.config.location}/application.properties")
|
|
||||||
@ConfigurationProperties("test-service")
|
|
||||||
public class TestServiceSettings {
|
|
||||||
private HazelcastClientParams hazelcast;
|
|
||||||
private KafkaConsumerSettings kafkaConsumer;
|
|
||||||
private KafkaProducerSettings kafkaProducer;
|
|
||||||
|
|
||||||
private ControllerSettings controllerSettings;
|
|
||||||
|
|
||||||
public ControllerSettings getControllerSettings() {
|
|
||||||
return controllerSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setControllerSettings(ControllerSettings controllerSettings) {
|
|
||||||
this.controllerSettings = controllerSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HazelcastClientParams getHazelcast() {
|
|
||||||
return hazelcast;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHazelcast(HazelcastClientParams hazelcast) {
|
|
||||||
this.hazelcast = hazelcast;
|
|
||||||
}
|
|
||||||
|
|
||||||
public KafkaConsumerSettings getKafkaConsumer() {
|
|
||||||
return kafkaConsumer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setKafkaConsumer(KafkaConsumerSettings kafkaConsumer) {
|
|
||||||
this.kafkaConsumer = kafkaConsumer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public KafkaProducerSettings getKafkaProducer() {
|
|
||||||
return kafkaProducer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setKafkaProducer(KafkaProducerSettings kafkaProducer) {
|
|
||||||
this.kafkaProducer = kafkaProducer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,103 +0,0 @@
|
||||||
package ru.spcex.clearing.test.controller;
|
|
||||||
|
|
||||||
import com.sun.net.httpserver.HttpExchange;
|
|
||||||
import com.sun.net.httpserver.HttpHandler;
|
|
||||||
import com.sun.net.httpserver.HttpServer;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import ru.spcex.clearing.test.ImdgService;
|
|
||||||
import ru.spcex.clearing.test.KafkaService;
|
|
||||||
import ru.spcex.clearing.test.config.settings.TestServiceSettings;
|
|
||||||
import ru.spcex.platform.utils.log.ExceptionUtils;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class Controller extends HttpServerSimpleFramework {
|
|
||||||
protected final ImdgService imdgService;
|
|
||||||
protected final KafkaService kafkaService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public Controller(ImdgService imdgService, KafkaService kafkaService,
|
|
||||||
TestServiceSettings settings) {
|
|
||||||
super(Integer.parseInt(settings.getControllerSettings().getPort()), settings.getControllerSettings().getContextPath());
|
|
||||||
if (settings.getControllerSettings() == null || settings.getControllerSettings().getPort() == null) {
|
|
||||||
log.warn("Debug HTTP port not set, can not init HTTP controller service.");
|
|
||||||
}
|
|
||||||
this.imdgService = imdgService;
|
|
||||||
this.kafkaService = kafkaService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void createContextPages(HttpServer server, String baseUrl) throws IOException {
|
|
||||||
server.createContext(baseUrl, new RedirectPage(baseUrl, baseUrl+"index.html"));
|
|
||||||
//server.createContext(baseUrl + "/favicon.ico", staticPageFromResource("pages/favicon.ico", null).contentType="image/icon");
|
|
||||||
server.createContext(baseUrl + "index.html", staticPageFromResource("pages/index.html", null));
|
|
||||||
|
|
||||||
// Database
|
|
||||||
server.createContext(baseUrl + "imdg/reload", new ImdgHandler());
|
|
||||||
//server.createContext(baseUrl+"db/info", new ImdgInfoHandler());
|
|
||||||
|
|
||||||
// Message
|
|
||||||
server.createContext(baseUrl + "message.html", staticPageFromResource("pages/message.html", null));
|
|
||||||
server.createContext(baseUrl + "message.do", new KafkaHandler());
|
|
||||||
}
|
|
||||||
|
|
||||||
class KafkaHandler extends CustomHtmlHandler {
|
|
||||||
@Override
|
|
||||||
public void makePage(HttpExchange exchange, OutputStream os) throws IOException {
|
|
||||||
if ("post".equalsIgnoreCase(exchange.getRequestMethod())) {
|
|
||||||
Map<String, String> parsed = parsePostBody(exchange);
|
|
||||||
|
|
||||||
String fullCLass = parsed.get("field0");
|
|
||||||
String qName = parsed.get("field1");
|
|
||||||
String msg = parsed.get("field2");
|
|
||||||
writeLine(os, "<p>Sending message to" + qName + "</p>");
|
|
||||||
try {
|
|
||||||
Long n = kafkaService.putMessage(fullCLass, qName, msg);
|
|
||||||
writeLine(os, "<b>Message #" + n + "</b> success send: ");
|
|
||||||
} catch (Exception er) {
|
|
||||||
String errMsg = ExceptionUtils.getStackTrace(er);
|
|
||||||
errMsg = errMsg.replace("\n", "</br>\n");
|
|
||||||
writeLine(os, "<p>Message error:" + errMsg + "</p>");
|
|
||||||
}
|
|
||||||
writeLine(os, "<p>" + msg + "</p>");
|
|
||||||
} else {
|
|
||||||
writeLine(os, "<p>HTTP method " + exchange.getRequestMethod() + ". Use POST method.</p>");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ImdgHandler extends CustomHtmlHandler {
|
|
||||||
@Override
|
|
||||||
public void makePage(HttpExchange t, OutputStream os) throws IOException {
|
|
||||||
writeLine(os, "Wait, reload all maps from DB... </br>");
|
|
||||||
synchronized (this) {
|
|
||||||
os.flush();
|
|
||||||
try {
|
|
||||||
long clock = System.currentTimeMillis();
|
|
||||||
List<String> warnMsg=new ArrayList<>();
|
|
||||||
int count = imdgService.reloadMapFromDB(warnMsg);
|
|
||||||
clock = System.currentTimeMillis() - clock;
|
|
||||||
writeLine(os, count + " map per " + clock + " ms</br>");
|
|
||||||
if (!warnMsg.isEmpty()) {
|
|
||||||
for (String msg : warnMsg)
|
|
||||||
writeLine(os, "Warning: " + msg + "</br>");
|
|
||||||
}
|
|
||||||
} catch (Throwable e) {
|
|
||||||
String msg = "Error reload: " + ExceptionUtils.getStackTrace(e);
|
|
||||||
log.error(msg);
|
|
||||||
writeLine(os, msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
writeLine(os, "<b title=\":)\">Done.</b> " + LocalDateTime.now() + "</br>");
|
|
||||||
writeLine(os, " <a href=\"\">Reload again.</a> ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,197 +0,0 @@
|
||||||
package ru.spcex.clearing.test.controller;
|
|
||||||
|
|
||||||
import com.sun.net.httpserver.Headers;
|
|
||||||
import com.sun.net.httpserver.HttpExchange;
|
|
||||||
import com.sun.net.httpserver.HttpHandler;
|
|
||||||
import com.sun.net.httpserver.HttpServer;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.net.URLDecoder;
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.DisposableBean;
|
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Простой HTTP server и фреимворк для HTML5 страниц.
|
|
||||||
* Только для отладки.
|
|
||||||
*/
|
|
||||||
public abstract class HttpServerSimpleFramework implements InitializingBean, DisposableBean {
|
|
||||||
protected final Logger log = LoggerFactory.getLogger(getClass());
|
|
||||||
protected HttpServer server;
|
|
||||||
protected Integer port;
|
|
||||||
protected String baseUrl;
|
|
||||||
|
|
||||||
|
|
||||||
public HttpServerSimpleFramework(Integer port, String baseUrl) {
|
|
||||||
this.port = port;
|
|
||||||
this.baseUrl = baseUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void createContextPages(HttpServer server, String baseUrl) throws IOException {
|
|
||||||
server.createContext(baseUrl, new RedirectPage(baseUrl, baseUrl + "index.html"));
|
|
||||||
server.createContext(baseUrl + "index.html", staticPageFromResource("pages/index.html", null));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterPropertiesSet() throws Exception {
|
|
||||||
try {
|
|
||||||
log.info("Server star at port {} with url \"{}\"", port, baseUrl);
|
|
||||||
this.server = HttpServer.create(new InetSocketAddress(port), 0);
|
|
||||||
server.setExecutor(null); // default
|
|
||||||
createContextPages(server, baseUrl);
|
|
||||||
server.start();
|
|
||||||
} catch (Throwable t) {
|
|
||||||
log.error("Can not start HTTP server in port {}: {}", port, ExceptionUtils.getStackTrace(t));
|
|
||||||
throw t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void destroy() throws Exception {
|
|
||||||
if (server != null) {
|
|
||||||
server.stop(6);
|
|
||||||
log.info("HTTP test controller stop.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<String, String> parsePostBody(HttpExchange exchange) throws IOException {
|
|
||||||
try (InputStreamReader isr = new InputStreamReader(exchange.getRequestBody(), "utf-8");
|
|
||||||
BufferedReader br = new BufferedReader(isr)) {
|
|
||||||
String query = br.readLine();
|
|
||||||
return parsePostBody(query);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<String, String> parsePostBody(String data) {
|
|
||||||
String[] elems = data.split("&");
|
|
||||||
Map<String, String> param = new LinkedHashMap<>();
|
|
||||||
for (String token : elems) {
|
|
||||||
int separator = token.indexOf("=");
|
|
||||||
if (separator == -1) throw new IllegalArgumentException("Separator '=' not found in: " + token);
|
|
||||||
String key = token.substring(0, separator);
|
|
||||||
String value = token.substring(separator + 1, token.length());
|
|
||||||
key = URLDecoder.decode(key);
|
|
||||||
value = URLDecoder.decode(value);
|
|
||||||
param.put(key, value);
|
|
||||||
}
|
|
||||||
return param;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract class CustomHtmlHandler implements HttpHandler {
|
|
||||||
protected final Logger log = LoggerFactory.getLogger(getClass());
|
|
||||||
protected final Charset encodung = Charset.forName("windows-1251");
|
|
||||||
|
|
||||||
public abstract void makePage(HttpExchange he, OutputStream os) throws IOException;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(HttpExchange he) throws IOException {
|
|
||||||
log.info("{} request by user \"{}\" {} url {}", getClass().getSimpleName(),
|
|
||||||
he.getRemoteAddress().getAddress(), he.getRequestMethod(), he.getRequestURI());
|
|
||||||
he.sendResponseHeaders(200, 0);
|
|
||||||
he.setAttribute("Content-Type", "text/html; charset=windows-1251"); // or "text/plain или text/html; charset=windows-1251"
|
|
||||||
try (OutputStream os = he.getResponseBody()) {
|
|
||||||
writeLine(os, "<!DOCTYPE html>\n<html><head></head>\n<body style=\"background-color:lightgray; font-size:14pt;color:black;\">");
|
|
||||||
writeLine(os, "<div>");
|
|
||||||
makePage(he, os);
|
|
||||||
writeLine(os, "</div>");
|
|
||||||
writeLine(os, "</body></html>");
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("Content build error at page \"{}\": {}",
|
|
||||||
he.getRequestURI(), ExceptionUtils.getStackTrace(e));
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
log.trace("HTTP Request done.");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void writeLine(OutputStream os, String text) throws IOException {
|
|
||||||
if (text != null)
|
|
||||||
os.write(text.getBytes(encodung));
|
|
||||||
os.write("\n".getBytes(encodung));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class RedirectPage implements HttpHandler {
|
|
||||||
protected final Logger log = LoggerFactory.getLogger(getClass());
|
|
||||||
protected String myUrl; // для редиректа с корня /
|
|
||||||
protected String toUrl;
|
|
||||||
|
|
||||||
public RedirectPage(String myUrl, String toUrl) {
|
|
||||||
this.myUrl = Objects.requireNonNull(myUrl);
|
|
||||||
this.toUrl = Objects.requireNonNull(toUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(HttpExchange he) throws IOException {
|
|
||||||
if (!myUrl.equalsIgnoreCase(he.getRequestURI().getPath()) &&
|
|
||||||
!myUrl.equalsIgnoreCase(he.getRequestURI().getPath() + "/") &&
|
|
||||||
!(myUrl + "/").equalsIgnoreCase(he.getRequestURI().getPath())) {
|
|
||||||
log.info("Access {} url \"{}\" IP {}; 404", he.getRequestMethod(),
|
|
||||||
he.getRequestURI(), he.getRemoteAddress().getAddress().getHostAddress());
|
|
||||||
he.sendResponseHeaders(404, 0);
|
|
||||||
try (OutputStream os = he.getResponseBody()) {
|
|
||||||
os.write("404 Page not found".getBytes("windows-1251"));
|
|
||||||
}
|
|
||||||
he.close();
|
|
||||||
}
|
|
||||||
log.info("Access {} url \"{}\" IP {}; redirect to \"{}\"", he.getRequestMethod(),
|
|
||||||
he.getRequestURI(), he.getRemoteAddress().getAddress().getHostAddress(), toUrl);
|
|
||||||
Headers responseHeaders = he.getResponseHeaders();
|
|
||||||
responseHeaders.set("Location", toUrl);
|
|
||||||
he.sendResponseHeaders(301, 0); // https://developer.mozilla.org/ru/docs/Web/HTTP/Redirections
|
|
||||||
he.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static StaticPage staticPageFromFile(File fromFile, String encoding) throws IOException {
|
|
||||||
if (encoding == null) encoding = "windows-1251";
|
|
||||||
String str = Files.readString(fromFile.toPath(), Charset.forName(encoding));
|
|
||||||
StaticPage page = new StaticPage(str);
|
|
||||||
page.encoding = Charset.forName(encoding);
|
|
||||||
page.contentType = "text/html; charset=" + page.encoding.name();
|
|
||||||
return page;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static StaticPage staticPageFromResource(String inRes, String encoding) throws IOException {
|
|
||||||
if (encoding == null) encoding = "windows-1251";
|
|
||||||
String str = new String(StaticPage.class.getClassLoader().getResourceAsStream(inRes).readAllBytes(), encoding);
|
|
||||||
StaticPage page = new StaticPage(str);
|
|
||||||
page.encoding = Charset.forName(encoding);
|
|
||||||
page.contentType = "text/html; charset=" + page.encoding.name();
|
|
||||||
return page;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class StaticPage implements HttpHandler {
|
|
||||||
protected final Logger log = LoggerFactory.getLogger(getClass());
|
|
||||||
protected Charset encoding = Charset.forName("windows-1251");
|
|
||||||
protected String contentType = "text/html; charset=" + encoding.name();
|
|
||||||
protected String content;
|
|
||||||
|
|
||||||
public StaticPage(String content) {
|
|
||||||
this.content = Objects.requireNonNull(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(HttpExchange he) throws IOException {
|
|
||||||
log.info("Access {} url \"{}\" IP {}", he.getRequestMethod(), he.getRequestURI(),
|
|
||||||
he.getRemoteAddress().getAddress().getHostAddress());
|
|
||||||
he.sendResponseHeaders(200, 0);
|
|
||||||
if (contentType != null)
|
|
||||||
he.setAttribute("Content-Type", contentType);
|
|
||||||
try (OutputStream os = he.getResponseBody()) {
|
|
||||||
os.write(content.getBytes(encoding));
|
|
||||||
} catch (Exception err) {
|
|
||||||
he.sendResponseHeaders(500, 0); // too late
|
|
||||||
log.error("StaticPage error {}", ExceptionUtils.getStackTrace(err));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,59 +0,0 @@
|
||||||
//package ru.spcex.clearing.test.controller.kafka;
|
|
||||||
//
|
|
||||||
//import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
//import com.fasterxml.jackson.annotation.JsonRawValue;
|
|
||||||
//import com.fasterxml.jackson.databind.JsonNode;
|
|
||||||
//import io.swagger.annotations.ApiModelProperty;
|
|
||||||
//import ru.spcex.clearing.platform.messaging.domain.ActionType;
|
|
||||||
//import ru.spcex.clearing.platform.messaging.domain.cud.registry.TradingClearingRegistryNewRequest;
|
|
||||||
//
|
|
||||||
//public class AnyKafkaMessageAction /*implements IAction<TradingClearingRegistryNewRequest>*/ {
|
|
||||||
// @ApiModelProperty(value = "полное имя класса payload для BaseRequest", example = "ru.spcex.clearing.platform.messaging.domain.cud.schedule.LauncherCommandRequest")
|
|
||||||
// @JsonProperty
|
|
||||||
// private String fullClassName;
|
|
||||||
// @JsonProperty
|
|
||||||
// private String topicName;
|
|
||||||
// @JsonRawValue
|
|
||||||
// public String json;
|
|
||||||
//
|
|
||||||
// @JsonProperty("json")
|
|
||||||
// private void unpackRawJson(JsonNode json) {
|
|
||||||
// this.json = json.toString();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//// @Override
|
|
||||||
// public TradingClearingRegistryNewRequest toRequest() {
|
|
||||||
// var req = new TradingClearingRegistryNewRequest();
|
|
||||||
// return req;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @ApiModelProperty(hidden = true)
|
|
||||||
//// @Override
|
|
||||||
// public ActionType getActionType() {
|
|
||||||
// return ActionType.SYSTEM;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public String getFullClassName() {
|
|
||||||
// return fullClassName;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void setFullClassName(String fullClassName) {
|
|
||||||
// this.fullClassName = fullClassName;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public String getTopicName() {
|
|
||||||
// return topicName;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void setTopicName(String topicName) {
|
|
||||||
// this.topicName = topicName;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public String getJson() {
|
|
||||||
// return json;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void setJson(String json) {
|
|
||||||
// this.json = json;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
@ -1,88 +0,0 @@
|
||||||
//package ru.spcex.clearing.test.controller.kafka;
|
|
||||||
//
|
|
||||||
//import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
//import com.fasterxml.jackson.databind.JavaType;
|
|
||||||
//import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
//import io.swagger.annotations.ApiOperation;
|
|
||||||
//import io.swagger.annotations.ApiParam;
|
|
||||||
//import io.swagger.annotations.ApiResponse;
|
|
||||||
//import io.swagger.annotations.ApiResponses;
|
|
||||||
//import org.slf4j.Logger;
|
|
||||||
//import org.slf4j.LoggerFactory;
|
|
||||||
//import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
//import org.springframework.http.MediaType;
|
|
||||||
//import org.springframework.stereotype.Controller;
|
|
||||||
//import org.springframework.util.ClassUtils;
|
|
||||||
//import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
//import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
//import org.springframework.web.bind.annotation.RequestMethod;
|
|
||||||
//import org.springframework.web.bind.annotation.ResponseBody;
|
|
||||||
//import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
|
|
||||||
//import ru.spcex.platform.utils.enumeration.EnumMessage;
|
|
||||||
//import ru.spcex.platform.utils.enumeration.IErrorEnumId;
|
|
||||||
//import ru.spcex.platform.utils.error.ValidationException;
|
|
||||||
//import ru.spcex.platform.utils.text.TextUtil;
|
|
||||||
//
|
|
||||||
//@Controller
|
|
||||||
//@RequestMapping("/anonymous/kafka-api")
|
|
||||||
//public class KafkaApiController {
|
|
||||||
// private final Logger log = LoggerFactory.getLogger(getClass());
|
|
||||||
// private final KafkaSender kafkaSender;
|
|
||||||
// private static final ObjectMapper json = new ObjectMapper();
|
|
||||||
// static {
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// enum BackEndError implements IErrorEnumId {
|
|
||||||
// ValidationError(9000L),
|
|
||||||
// UnknownJsonProperty(9001L),
|
|
||||||
// FailedToReadHttpMessage(9002L),
|
|
||||||
// KeycloakRepeatedRoles(9003L),
|
|
||||||
// DictionaryNotFound(9004L),
|
|
||||||
// ResourceNotFound(9005L)
|
|
||||||
// ;
|
|
||||||
// private final Long id;
|
|
||||||
//
|
|
||||||
// BackEndError(Long id) {
|
|
||||||
// this.id = id;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public Long getId() {
|
|
||||||
// return id;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Autowired
|
|
||||||
// public KafkaApiController(KafkaSender kafkaSender) {
|
|
||||||
// this.kafkaSender = kafkaSender;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @ApiOperation(value = "Test backend-api availability.")
|
|
||||||
// @ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = String.class)})
|
|
||||||
// @RequestMapping(method = RequestMethod.POST, path = "/any/message", produces = MediaType.TEXT_PLAIN_VALUE)
|
|
||||||
// @ResponseBody
|
|
||||||
// public String processGet(@ApiParam(value = "Параметры команды в JSON формате.", required = true)
|
|
||||||
// @RequestBody AnyKafkaMessageAction bankAccountNewAction) throws ClassNotFoundException, ValidationException, JsonProcessingException {
|
|
||||||
// log.info("Call test method for backend-api controller");
|
|
||||||
// validate(bankAccountNewAction);
|
|
||||||
// Class<?> parameterType = ClassUtils.forName(bankAccountNewAction.getFullClassName(), ClassUtils.getDefaultClassLoader());
|
|
||||||
// JavaType requestType = json.getTypeFactory().constructSimpleType(parameterType, null);
|
|
||||||
// Object obj = json.readValue(bankAccountNewAction.getJson(), requestType);
|
|
||||||
// Long idOfBaseRequestMessage = kafkaSender.sendRequestToQueue(bankAccountNewAction.getTopicName(), obj);
|
|
||||||
// log.debug("Test message to topic {} with request id={}", bankAccountNewAction.getTopicName(), idOfBaseRequestMessage);
|
|
||||||
// return "success: baseRequest.id = " + idOfBaseRequestMessage;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private void validate(AnyKafkaMessageAction bankAccountNewAction) throws ValidationException {
|
|
||||||
// if (TextUtil.isEmpty(bankAccountNewAction.getTopicName())) {
|
|
||||||
// throw new ValidationException(new EnumMessage(BackEndError.ValidationError, "topicName"));
|
|
||||||
// }
|
|
||||||
// if (TextUtil.isEmpty(bankAccountNewAction.getFullClassName())) {
|
|
||||||
// throw new ValidationException(new EnumMessage(BackEndError.ValidationError, "fullClassName"));
|
|
||||||
// }
|
|
||||||
// if (TextUtil.isEmpty(bankAccountNewAction.getJson())) {
|
|
||||||
// throw new ValidationException(new EnumMessage(BackEndError.ValidationError, "json"));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
#spring.main.web-application-type=none
|
|
||||||
|
|
||||||
#debug tester mode:
|
|
||||||
test-service.controller-settings.port=8701
|
|
||||||
test-service.controller-settings.context-path=/
|
|
||||||
|
|
||||||
# /clearing/test/ /imdg/reload
|
|
||||||
|
|
||||||
#server.port=8701
|
|
||||||
#server.servlet.context-path=/
|
|
||||||
|
|
||||||
|
|
||||||
test-service.hazelcast.cluster-members=127.0.0.1:5701
|
|
||||||
test-service.hazelcast.login=dev
|
|
||||||
test-service.hazelcast.password=dev-pass
|
|
||||||
|
|
||||||
#test-service.kafka-consumer.bootstrap-servers=localhost:9092
|
|
||||||
#test-service.kafka-consumer.group-id=dev-group-utility-service
|
|
||||||
#test-service.kafka-consumer.enable-auto-commit=true
|
|
||||||
#test-service.kafka-consumer.session-timeout-ms=30000
|
|
||||||
#test-service.kafka-consumer.auto-offset-reset=latest
|
|
||||||
#test-service.kafka-consumer.linger-ms=1
|
|
||||||
#test-service.kafka-consumer.buffer-memory=33554432
|
|
||||||
|
|
||||||
test-service.kafka-producer.bootstrap-servers=localhost:9092
|
|
||||||
test-service.kafka-producer.acks=all
|
|
||||||
test-service.kafka-producer.retries=0
|
|
||||||
test-service.kafka-producer.batch-size=16384
|
|
||||||
test-service.kafka-producer.linger-ms=1
|
|
||||||
test-service.kafka-producer.buffer-memory=33554432
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<configuration>
|
|
||||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
|
||||||
<encoder>
|
|
||||||
<!-- |%X{ru.nbch.scoring.web.logging.mdc_key}-->
|
|
||||||
<Pattern>%date{HH:mm:ss.SSS} [%thread] %-5level %class{0}:%line - %message%n</Pattern>
|
|
||||||
<charset>utf-8</charset>
|
|
||||||
</encoder>
|
|
||||||
</appender>
|
|
||||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
|
||||||
<file>./logs/test-api-clearing.log</file>
|
|
||||||
<encoder>
|
|
||||||
<!-- |%X{ru.nbch.scoring.web.logging.mdc_key}-->
|
|
||||||
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %class{0}:%msg%n</Pattern>
|
|
||||||
<charset>utf8</charset>
|
|
||||||
</encoder>
|
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
|
|
||||||
<fileNamePattern>
|
|
||||||
./logs/test-api-clearing.%i.log
|
|
||||||
</fileNamePattern>
|
|
||||||
<minIndex>1</minIndex>
|
|
||||||
<maxIndex>10</maxIndex>
|
|
||||||
</rollingPolicy>
|
|
||||||
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
|
|
||||||
<maxFileSize>500MB</maxFileSize>
|
|
||||||
</triggeringPolicy>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<root level="warn">
|
|
||||||
<appender-ref ref="CONSOLE"/>
|
|
||||||
<appender-ref ref="FILE"/>
|
|
||||||
</root>
|
|
||||||
|
|
||||||
<logger name="ru.spcex" level="debug" additivity="false">
|
|
||||||
<appender-ref ref="FILE"/>
|
|
||||||
<appender-ref ref="CONSOLE"/>
|
|
||||||
</logger>
|
|
||||||
</configuration>
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html><head>
|
|
||||||
<style type="text/css">
|
|
||||||
div.oldtab {background-color:darkblue;color:yellow;border:1pt double yellow; padding:2pt; margin:3pt;}
|
|
||||||
div.oldtab_line {margin:3pt;}
|
|
||||||
div.oldtab_line:hover {background-color:white;color:black;}
|
|
||||||
a{background-color:lightgray;color:black;border-bottom:2pt solid yellow;text-decoration: none;}
|
|
||||||
|
|
||||||
label{cursor:help;}
|
|
||||||
button {cursor:pointer;}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body style="background-color:lightgray; font-size:14pt;color:black;">
|
|
||||||
<div>
|
|
||||||
<h1>Debug control panel</h1>
|
|
||||||
<p>Action:</p>
|
|
||||||
|
|
||||||
<div class="oldtab">
|
|
||||||
<p style="text-align:center;cursor:default;">Sending message dialog</p>
|
|
||||||
<div class="oldtab_line">
|
|
||||||
Send <a href="message.html"/>Message to queue</a>
|
|
||||||
</div>
|
|
||||||
<div class="oldtab_line">
|
|
||||||
<form action="imdg/reload" method="POST">
|
|
||||||
Do <button>reload database</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div style="text-align:right;"><a href="">Reload page.</a> </div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</body></html>
|
|
||||||
|
|
@ -1,55 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html><head>
|
|
||||||
<style type="text/css">
|
|
||||||
div.oldtab {background-color:#000500;color:white;border:1pt double yellow; padding:2pt; margin:3pt;}
|
|
||||||
div.oldtab_line {margin:3pt;}
|
|
||||||
div.oldtab_line:hover {background-color:white;color:black;}
|
|
||||||
label{cursor:help;}
|
|
||||||
button {cursor:pointer;}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body style="background-color:lightgray; font-size:14pt;color:black;">
|
|
||||||
<div>
|
|
||||||
|
|
||||||
<div class="oldtab">
|
|
||||||
<p style="text-align:center;cursor:default;">Sending message dialog</p>
|
|
||||||
<form action="message.do" method="POST" style="background-color:light-gray;">
|
|
||||||
<div class="oldtab_line">
|
|
||||||
<label for="field0">Full class name</label>
|
|
||||||
<input name="field0" id="field0" style="width:60em;" value="ru.clearing.classes.statics.data.account.Account" />
|
|
||||||
</div>
|
|
||||||
<div class="oldtab_line">
|
|
||||||
<label for="field1">Topic name</label>
|
|
||||||
|
|
||||||
<input name="field1" id="field1" style="width:60em;" value="correspondent-account-new" />
|
|
||||||
</div>
|
|
||||||
<div class="oldtab_line">
|
|
||||||
<label for="field2">Json message</label>
|
|
||||||
|
|
||||||
<textArea name="field2" id="field2" rows="10" cols="120" >
|
|
||||||
{
|
|
||||||
"id":0,"actionType":"UPDATE",
|
|
||||||
"requestPayload":{
|
|
||||||
"id":3,
|
|
||||||
"companyId":0,
|
|
||||||
"account":"123456789123",
|
|
||||||
"status":"ACTV",
|
|
||||||
"accountType":"CORR"
|
|
||||||
},
|
|
||||||
"userId":1000}
|
|
||||||
</textArea>
|
|
||||||
</div>
|
|
||||||
<div style="text-align:center;">
|
|
||||||
<button>Send to kafka</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div style="text-align:left;background-color:black; font-size:14pt;color:lightgray;height: 20em;">
|
|
||||||
Enter Kafka debug message...
|
|
||||||
</br>
|
|
||||||
\message> <a style="color:white;border-bottom:1pt solid yellow;text-decoration: none;" href="/">CD ..</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</body></html>
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
CLEARING_HOME=/opt/mfd/clearing/
|
|
||||||
cd $CLEARING_HOME/bin
|
|
||||||
|
|
||||||
echo Warinig: start test module "test-api-clearing.jar". Do not use this on real system, please.
|
|
||||||
CMD="java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:7702 -jar test-api-clearing.jar --spring.config.location=$CLEARING_HOME/settings/test-api-clearing/"
|
|
||||||
|
|
||||||
$CMD >/dev/null 2>&1 &
|
|
||||||
|
|
||||||
Loading…
Add table
Reference in a new issue