From 269a74960b746efa5d36e114df5890a243ace5f0 Mon Sep 17 00:00:00 2001 From: AKurakin Date: Sat, 21 Oct 2023 16:58:37 +0300 Subject: [PATCH] =?UTF-8?q?test-api-clearing=20http://git.mfd.msk/mfd/clea?= =?UTF-8?q?ring/-/issues/31=20=D0=9F=D0=B5=D1=80=D0=B5=D0=BD=D1=91=D1=81?= =?UTF-8?q?=20=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B?= =?UTF-8?q?=D0=B9=20git-=D1=80=D0=B5=D0=BF=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clearing-parent/pom.xml | 1 - clearing-parent/test-api-clearing/pom.xml | 167 ----------- .../ru/spcex/clearing/test/ImdgService.java | 135 --------- .../ru/spcex/clearing/test/KafkaService.java | 48 ---- .../test/TestApiClearingApplication.java | 27 -- .../clearing/test/config/ImdgConfig.java | 265 ------------------ .../spcex/clearing/test/config/JsonUtil.java | 73 ----- .../clearing/test/config/KafkaConfig.java | 84 ------ .../config/settings/ControllerSettings.java | 25 -- .../config/settings/TestServiceSettings.java | 51 ---- .../clearing/test/controller/Controller.java | 103 ------- .../controller/HttpServerSimpleFramework.java | 197 ------------- .../kafka/AnyKafkaMessageAction.java | 59 ---- .../controller/kafka/KafkaApiController.java | 88 ------ .../src/main/resources/application.properties | 30 -- .../src/main/resources/logback.xml | 38 --- .../src/main/resources/pages/index.html | 32 --- .../src/main/resources/pages/message.html | 55 ---- .../test-api-clearing/test-api-clearing.sh | 10 - 19 files changed, 1488 deletions(-) delete mode 100644 clearing-parent/test-api-clearing/pom.xml delete mode 100644 clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/ImdgService.java delete mode 100644 clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/KafkaService.java delete mode 100644 clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/TestApiClearingApplication.java delete mode 100644 clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/config/ImdgConfig.java delete mode 100644 clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/config/JsonUtil.java delete mode 100644 clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/config/KafkaConfig.java delete mode 100644 clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/config/settings/ControllerSettings.java delete mode 100644 clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/config/settings/TestServiceSettings.java delete mode 100644 clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/Controller.java delete mode 100644 clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/HttpServerSimpleFramework.java delete mode 100644 clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/kafka/AnyKafkaMessageAction.java delete mode 100644 clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/kafka/KafkaApiController.java delete mode 100644 clearing-parent/test-api-clearing/src/main/resources/application.properties delete mode 100644 clearing-parent/test-api-clearing/src/main/resources/logback.xml delete mode 100644 clearing-parent/test-api-clearing/src/main/resources/pages/index.html delete mode 100644 clearing-parent/test-api-clearing/src/main/resources/pages/message.html delete mode 100644 clearing-parent/test-api-clearing/test-api-clearing.sh diff --git a/clearing-parent/pom.xml b/clearing-parent/pom.xml index 02a53252c..b90e0b71c 100644 --- a/clearing-parent/pom.xml +++ b/clearing-parent/pom.xml @@ -35,7 +35,6 @@ clearing-service registry-service test-clearing - test-api-clearing cleaning-builders trade-importer lim-exporter diff --git a/clearing-parent/test-api-clearing/pom.xml b/clearing-parent/test-api-clearing/pom.xml deleted file mode 100644 index 37e2fcdc0..000000000 --- a/clearing-parent/test-api-clearing/pom.xml +++ /dev/null @@ -1,167 +0,0 @@ - - 4.0.0 - - ru.spcex.clearing - clearing-parent - SPCEX-1.0.0.0 - - test-api-clearing - Test-api-clearing - SPCEX-1.0.0.0 - - Тестовые контроллеры для отладки клиринговой системы. - Только для разработчиков. - - - - - 17 - 17 - - 17.0.1 - - - - - ru.spcex.platform - platform-messaging - - - ru.spcex.platform - platform-enum - - - ru.spcex.platform - platform-enum - - - ru.spcex.clearing - classes - SPCEX-1.0.0.0 - - - - ru.spcex.clearing - dictionary - SPCEX-1.0.0.0 - - - - - ru.spcex.platform - platform-imdg-api - - - ru.spcex.platform - platform-imdg-api-hazelcast-impl - - - ru.spcex.clearing - classes - - - org.springframework.boot - spring-boot-starter - - - com.fasterxml.jackson.core - jackson-databind - - - com.fasterxml.jackson.datatype - jackson-datatype-jsr310 - - - - - - - - - - - - - - - - - - - - - - - - - - - - ru.spcex.platform - platform-imdg-api-hazelcast-impl - - - - org.apache.commons - commons-lang3 - 3.7 - - - - - - - - - - - - - - - - - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - src/main/resources - - application.properties - - false - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - repackage - - - - - ${project.artifactId} - - - - - - - diff --git a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/ImdgService.java b/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/ImdgService.java deleted file mode 100644 index d5eb9dff6..000000000 --- a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/ImdgService.java +++ /dev/null @@ -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 allMaps() { - return null; - } - - public int reloadMapFromDB(List warningMsgs) { - log.info("Reload all from DB..."); - long loadTime = System.currentTimeMillis(); - int count = 0; - - HashSet 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> tasks = new ArrayList<>(); - // На сервере так: Collection mapNames = hazelcastServerInstance.getConfig().getMapConfigs().keySet(); - // На клиенте: - List 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 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> results = executor.invokeAll(tasks); - for (Future 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; - } -} diff --git a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/KafkaService.java b/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/KafkaService.java deleted file mode 100644 index 089c9c024..000000000 --- a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/KafkaService.java +++ /dev/null @@ -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 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; - } - -} diff --git a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/TestApiClearingApplication.java b/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/TestApiClearingApplication.java deleted file mode 100644 index 130b48087..000000000 --- a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/TestApiClearingApplication.java +++ /dev/null @@ -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); - } -} diff --git a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/config/ImdgConfig.java b/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/config/ImdgConfig.java deleted file mode 100644 index e564bce32..000000000 --- a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/config/ImdgConfig.java +++ /dev/null @@ -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 Imdg getImdg(String key, Class clazz) { - ImdgDirectHazelcast 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 implements Imdg { - private final Logger log = LoggerFactory.getLogger(getClass()); - private IdGenerator idGenerator; - - private IMap 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> conditions) { - Predicate[] predicates = new Predicate[conditions.size()]; - final int[] i = {0}; - conditions.forEach((key, value) -> { - predicates[i[0]] = Predicates.equal(key, value); - i[0]++; - }); - Predicate and = Predicates.and(predicates); - Set ids = map.keySet(and); - Iterator 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 found = map.keySet(sqlPredicate); - Iterator 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 found = map.keySet(sqlPredicate); - if (found.size() > 1) { - throw new RuntimeException("More than one element found by predicate [" + paramString + "] - " + found.size()); - } - Iterator allFoundByCondition = found.iterator(); - if (allFoundByCondition.hasNext()) { - return map.get(allFoundByCondition.next()); - } else return null; - } - - @Override - public Collection getCollectionObjectsBySQL(String paramString) { - SqlPredicate sqlPredicate = new SqlPredicate(paramString); - Collection found = map.values(sqlPredicate); - List result = new ArrayList<>(found); // Hazelcast может вернуть proxy-коллекцию - return result; - } - - /** - * возвращает коллекцию объектов, удовлетворяющий условиям на поля - */ - @SuppressWarnings("unchecked") - @Override - public Collection getCollectionObjectsByFieldValues(Map> conditions) { - Predicate[] predicates = new Predicate[conditions.size()]; - final int[] i = {0}; - conditions.forEach((key, value) -> { - predicates[i[0]] = Predicates.equal(key, value); - i[0]++; - }); - Predicate or = Predicates.or(predicates); - Set ids = map.keySet(or); - Iterator idIterator = ids.iterator(); - Collection searchResult = new ArrayList<>(); - while (idIterator.hasNext()) { - T element = map.get(idIterator.next()); - if (element != null) { - searchResult.add(element); - } - } - return searchResult; - } - - public IMap getMap() { - return map; - } - - public void setMap(IMap 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(); - } - } - -} diff --git a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/config/JsonUtil.java b/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/config/JsonUtil.java deleted file mode 100644 index 92f524927..000000000 --- a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/config/JsonUtil.java +++ /dev/null @@ -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 List readValues(String json, Class clazz) { - ObjectReader reader = JacksonObjectMapper.getMapper().readerFor(clazz); - try { - return reader.readValues(json).readAll(); - } catch (IOException e) { - throw new IllegalArgumentException("Invalid read array from JSON:\n'" + json + "'", e); - } - } - - public static T readValue(String json, Class clazz) { - try { - return JacksonObjectMapper.getMapper().readValue(json, clazz); - } catch (IOException e) { - throw new IllegalArgumentException("Invalid read from JSON:\n'" + json + "'", e); - } - } - - public static 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 String writeIgnoreProps(T obj, String... ignoreProps) { - Map 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; - } - } -} \ No newline at end of file diff --git a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/config/KafkaConfig.java b/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/config/KafkaConfig.java deleted file mode 100644 index 953b8ecf0..000000000 --- a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/config/KafkaConfig.java +++ /dev/null @@ -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 createConsumer(TestServiceSettings settings) { -// return KafkaConsumerFactory.consumer(settings.getKafkaConsumer()); -//// return Mockito.mock(Consumer.class); -// } - - @Autowired - @Bean - public Producer createProducer(TestServiceSettings settings) { - return KafkaProducerFactory.producer(settings.getKafkaProducer()); -// return Mockito.mock(Producer.class); - } - - @Bean - public ProducerFactory 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 kafkaTemplate(ProducerFactory pf) { - if (pf == null) return null; - return new KafkaTemplate<>(pf); - } - - @Autowired(required = false) - @Bean - public KafkaSender kafkaSender(@Qualifier("kafkaTemplate") KafkaTemplate kafkaTemplate, - ImdgProvider imdgProvider - ) { - if (kafkaTemplate == null) { - return null; - } - ImdgId imdgIdGenerator = imdgProvider.getImdgIdGenerator(); - return KafkaSender - .setup() - .setKafkaTemplate(kafkaTemplate) - .idGenerator(imdgIdGenerator::nextId) - .imdgProvider(s -> { - Imdg imdg = imdgProvider.getImdg(IMDGDistributedNames.Map_RequestInfo, RequestInfo.class); - return imdg::insert; - }) - .build(); - -// return Mockito.mock(KafkaSender.class); - } -} diff --git a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/config/settings/ControllerSettings.java b/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/config/settings/ControllerSettings.java deleted file mode 100644 index 15a7adc6a..000000000 --- a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/config/settings/ControllerSettings.java +++ /dev/null @@ -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; - } -} diff --git a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/config/settings/TestServiceSettings.java b/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/config/settings/TestServiceSettings.java deleted file mode 100644 index 8a001f244..000000000 --- a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/config/settings/TestServiceSettings.java +++ /dev/null @@ -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; - } -} diff --git a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/Controller.java b/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/Controller.java deleted file mode 100644 index 0170ecf63..000000000 --- a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/Controller.java +++ /dev/null @@ -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 parsed = parsePostBody(exchange); - - String fullCLass = parsed.get("field0"); - String qName = parsed.get("field1"); - String msg = parsed.get("field2"); - writeLine(os, "

Sending message to" + qName + "

"); - try { - Long n = kafkaService.putMessage(fullCLass, qName, msg); - writeLine(os, "Message #" + n + " success send: "); - } catch (Exception er) { - String errMsg = ExceptionUtils.getStackTrace(er); - errMsg = errMsg.replace("\n", "
\n"); - writeLine(os, "

Message error:" + errMsg + "

"); - } - writeLine(os, "

" + msg + "

"); - } else { - writeLine(os, "

HTTP method " + exchange.getRequestMethod() + ". Use POST method.

"); - } - } - } - - class ImdgHandler extends CustomHtmlHandler { - @Override - public void makePage(HttpExchange t, OutputStream os) throws IOException { - writeLine(os, "Wait, reload all maps from DB...
"); - synchronized (this) { - os.flush(); - try { - long clock = System.currentTimeMillis(); - List warnMsg=new ArrayList<>(); - int count = imdgService.reloadMapFromDB(warnMsg); - clock = System.currentTimeMillis() - clock; - writeLine(os, count + " map per " + clock + " ms
"); - if (!warnMsg.isEmpty()) { - for (String msg : warnMsg) - writeLine(os, "Warning: " + msg + "
"); - } - } catch (Throwable e) { - String msg = "Error reload: " + ExceptionUtils.getStackTrace(e); - log.error(msg); - writeLine(os, msg); - } - } - writeLine(os, "Done. " + LocalDateTime.now() + "
"); - writeLine(os, " Reload again. "); - } - } - -} \ No newline at end of file diff --git a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/HttpServerSimpleFramework.java b/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/HttpServerSimpleFramework.java deleted file mode 100644 index 66a89d0f3..000000000 --- a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/HttpServerSimpleFramework.java +++ /dev/null @@ -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 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 parsePostBody(String data) { - String[] elems = data.split("&"); - Map 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, "\n\n"); - writeLine(os, "
"); - makePage(he, os); - writeLine(os, "
"); - writeLine(os, ""); - } 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)); - } - } - } -} diff --git a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/kafka/AnyKafkaMessageAction.java b/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/kafka/AnyKafkaMessageAction.java deleted file mode 100644 index 146cc7246..000000000 --- a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/kafka/AnyKafkaMessageAction.java +++ /dev/null @@ -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*/ { -// @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; -// } -//} diff --git a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/kafka/KafkaApiController.java b/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/kafka/KafkaApiController.java deleted file mode 100644 index 3d930fd85..000000000 --- a/clearing-parent/test-api-clearing/src/main/java/ru/spcex/clearing/test/controller/kafka/KafkaApiController.java +++ /dev/null @@ -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")); -// } -// } -// -//} diff --git a/clearing-parent/test-api-clearing/src/main/resources/application.properties b/clearing-parent/test-api-clearing/src/main/resources/application.properties deleted file mode 100644 index 6eda6ea43..000000000 --- a/clearing-parent/test-api-clearing/src/main/resources/application.properties +++ /dev/null @@ -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 diff --git a/clearing-parent/test-api-clearing/src/main/resources/logback.xml b/clearing-parent/test-api-clearing/src/main/resources/logback.xml deleted file mode 100644 index c4c3640d0..000000000 --- a/clearing-parent/test-api-clearing/src/main/resources/logback.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - %date{HH:mm:ss.SSS} [%thread] %-5level %class{0}:%line - %message%n - utf-8 - - - - ./logs/test-api-clearing.log - - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %class{0}:%msg%n - utf8 - - - - ./logs/test-api-clearing.%i.log - - 1 - 10 - - - 500MB - - - - - - - - - - - - - diff --git a/clearing-parent/test-api-clearing/src/main/resources/pages/index.html b/clearing-parent/test-api-clearing/src/main/resources/pages/index.html deleted file mode 100644 index 3e506c67b..000000000 --- a/clearing-parent/test-api-clearing/src/main/resources/pages/index.html +++ /dev/null @@ -1,32 +0,0 @@ - - - - - -
-

Debug control panel

-

Action:

- -
-

Sending message dialog

-
- Send Message to queue -
-
-
- Do -
-
-
- - -
- diff --git a/clearing-parent/test-api-clearing/src/main/resources/pages/message.html b/clearing-parent/test-api-clearing/src/main/resources/pages/message.html deleted file mode 100644 index 656b9a85d..000000000 --- a/clearing-parent/test-api-clearing/src/main/resources/pages/message.html +++ /dev/null @@ -1,55 +0,0 @@ - - - - - -
- -
-

Sending message dialog

-
-
- - -
-
- -       - -
-
- -    - -
-
- -
-
-
- -
- Enter Kafka debug message... -
- \message> CD .. -
- -
- diff --git a/clearing-parent/test-api-clearing/test-api-clearing.sh b/clearing-parent/test-api-clearing/test-api-clearing.sh deleted file mode 100644 index e5db2091a..000000000 --- a/clearing-parent/test-api-clearing/test-api-clearing.sh +++ /dev/null @@ -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 & -