From f54a10df0aa13f8faea9fd1547ec93562434c308 Mon Sep 17 00:00:00 2001 From: Ebrahim Hosseiny Fadaee Date: Sat, 19 Feb 2022 17:07:12 +0330 Subject: [PATCH 1/2] Deploy demo version (#207) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * remove payment from enginx config * Add storage module's volume * Fix storage volume address * close #175: Fix matching-engine's trade counter * 174 upgrade versions (#179) * remove payment from enginx config (#170) * #174: All modules except keycloak-gateway upgraded. Co-authored-by: Peyman <46522754+Marchosiax@users.noreply.github.com> * Close #171 and #177: Kafka improvement (#180) * Clean up engine's event models * Clean up accountant * Adding new events for richorder topic * Add OrderStatus model * Separate order and trade processing in API * Set all kafka configs * close #177: Fix websocket issue * Add kafka ui monitoring tool * Fix new topic beans * Change kafka image * Fix kafka config * Fix bean name error * Remove kafka exposed ports * Remove root user grant * Optimize imports * Change java version to 11 (#185) * #189: Add Hashicorp Vault as db credential source, smtp password is a… (#190) * #189: Add Hashicorp Vault as db credential source, smtp password is also now supports Vault * #189: A bit cleaning in the configs to remove useless files/redundant variables * #199: move vault host config from docker to main profile (#192) * Close #181, Remove nginx (#194) * Remove nginx service and config file * Remove redundant network aliases * Refactor jenkins configs and docker compose * Set all app ports to 8080 * Add fallback value to network config * Rename network * Refactor docker-compose configs * Add remove orphans to docker-compose startup script * Refactor jenkins configuration files * Resolve docker-compose config issues * Update jvm target version in kotlin-maven-plugin * Remove anonymous volumes in docker files * Update Jenkins file * Cleanup docker-compose configs * Fix typo in server port * Change chain scan gateway addresses * Update java version in git flows * Rename compose project name in Jenkinsfile * Update DATA value in Jenkins * Update maven compiler version in keycloak * Fix maven version * Add clean up codes after deliver * Fix local port expose * Update Jenkins stages title * Close #195, Fix maven build issues (#196) * Fix matching-engine test package names * Change vault config address * Fix docker-compose command in jenkins * Fix bc-gateway VAULT_HOST * Security issues resolved (#197) * Add auth endpoint extensions * Add admin module * close #172: Brute force * close #182: Token and clients * Add auth admin services * Add keycloak extension * Add profile services * Resolve merge conflicts * Add opex realm configs * Close #172: Brute force protection * Close #182: Token organization * Close #186: Keycloak and security improvements * Remove .env gitignore rule * Revert keycloak's admin and frontend url * Remove client secret variable * Add .env gitignore rule * Update gitignore * Hostfix keycloak * Remove application-docker.yml and application-local.yml profiles * Extract keycloak frontend url configs * Remove mvnw and mvnw.cmd in all modules * Fix postgres version * Add resources folder * Fix vault config * Fix env variables in application.yml * Add migration config to keycloak * Update keycloak url configs * Close #200, Refactor deployment configs (#206) * Remove application-docker.yml and application-local.yml profiles * Extract keycloak frontend url configs * Remove mvnw and mvnw.cmd in all modules * Fix postgres version * Add resources folder * Fix vault config * Fix env variables in application.yml * Add migration config to keycloak * Update keycloak url configs * Fix opex-master-realm.json path in keycloak * Fix cert-url in websocket * Remove ; from end of postgres sql commands * Add bitcoin reserved addresses Co-authored-by: Peyman Co-authored-by: maryarm <45322329+maryarm@users.noreply.github.com> Co-authored-by: Peyman <46522754+Marchosiax@users.noreply.github.com> --- .github/workflows/pr.yml | 2 +- .gitignore | 7 + Deployment/.gitignore | 3 - Deployment/docker-compose.dev.yml | 120 ---- Deployment/docker-compose.override.yml | 142 ---- Deployment/docker-compose.yml | 286 -------- Deployment/nginx.conf | 107 --- ...nkinsfile.deploy.dev.groovy => Jenkinsfile | 21 +- accountant/accountant-app/Dockerfile | 3 +- accountant/accountant-app/pom.xml | 4 + .../opex/accountant/app/config/AppConfig.kt | 111 +-- .../app/listener/AccountantEventListener.kt | 28 + .../listener/AccountantTempEventListener.kt | 34 + .../app/listener/AccountantTradeListener.kt | 19 + .../accountant/app/listener/OrderListener.kt | 33 + .../accountant/app/scheduler/TempEventsJob.kt | 4 +- .../opex/util/vault/VaultUserIdMechanism.kt | 9 + .../src/main/resources/application-docker.yml | 14 - .../src/main/resources/application.yml | 31 +- accountant/accountant-core/mvnw | 310 --------- accountant/accountant-core/mvnw.cmd | 182 ----- .../opex/accountant/core/inout/OrderStatus.kt | 2 +- .../opex/accountant/core/inout/RichOrder.kt | 80 +-- .../accountant/core/inout/RichOrderEvent.kt | 3 + .../accountant/core/inout/RichOrderUpdate.kt | 17 + .../opex/accountant/core/inout/RichTrade.kt | 105 +-- .../service/FinancialActionJobManagerImpl.kt | 6 +- .../core/service/OrderManagerImpl.kt | 18 +- .../core/service/TradeManagerImpl.kt | 46 +- .../accountant/core/spi/RichOrderPublisher.kt | 4 +- .../core/service/TradeManagerImplTest.kt | 1 + .../accountant-eventlistener-kafka/mvnw | 310 --------- .../accountant-eventlistener-kafka/mvnw.cmd | 182 ----- .../listener/config/AccountantKafkaConfig.kt | 47 +- .../listener/consumer/EventKafkaListener.kt | 2 +- .../listener/consumer/OrderKafkaListener.kt | 2 +- .../consumer/TempEventKafkaListener.kt | 2 +- .../listener/consumer/TradeKafkaListener.kt | 2 +- .../accountant-persister-postgres/mvnw | 310 --------- .../accountant-persister-postgres/mvnw.cmd | 182 ----- .../postgres/dao/PairFeeConfigRepository.kt | 2 +- .../postgres/impl/PairConfigLoaderImpl.kt | 2 +- .../postgres/impl/TempEventPersisterImpl.kt | 2 +- .../src/main/resources/data.sql | 34 +- .../src/main/resources/schema.sql | 141 ++-- .../accountant-submitter-kafka/mvnw | 310 --------- .../accountant-submitter-kafka/mvnw.cmd | 182 ----- .../submitter/config/SubmitterKafkaConfig.kt | 50 +- .../submitter/service/RichOrderSubmitter.kt | 7 +- .../accountant-wallet-proxy/mvnw | 310 --------- .../accountant-wallet-proxy/mvnw.cmd | 182 ----- .../accountant-wallet-proxy/pom.xml | 16 - accountant/pom.xml | 7 + admin/admin-app/.gitignore | 33 + admin/admin-app/Dockerfile | 5 + admin/admin-app/pom.xml | 107 +++ .../nilin/opex/admin/app/AdminApplication.kt | 15 + .../opex/admin/app/config/SecurityConfig.kt | 38 ++ .../opex/admin/app/config/WebClientConfig.kt | 20 + .../nilin/opex/admin/app/utils/Extensions.kt | 20 + .../src/main/resources/application.yml | 22 +- admin/admin-core/.gitignore | 33 + admin/admin-core/pom.xml | 39 ++ .../opex/admin/core/AdminCoreApplication.kt | 11 + .../admin-ports/admin-service-auth/.gitignore | 33 + admin/admin-ports/admin-service-auth/pom.xml | 61 ++ .../ports/auth/config/KeycloakAdminConfig.kt | 42 ++ .../auth/controller/AuthAdminController.kt | 38 ++ .../admin/ports/auth/data/KeycloakUser.kt | 17 + .../opex/admin/ports/auth/data/KycGroup.kt | 9 + .../ports/auth/service/AuthAdminService.kt | 61 ++ .../opex/admin/ports/auth/utils/Extensions.kt | 17 + admin/pom.xml | 56 ++ api/api-app/Dockerfile | 3 +- api/api-app/pom.xml | 4 + .../co/nilin/opex/api/app/config/AppConfig.kt | 45 +- .../opex/api/app/listener/ApiListenerImpl.kt | 38 ++ .../opex/util/vault/VaultUserIdMechanism.kt | 9 + .../src/main/resources/application-docker.yml | 27 - .../src/main/resources/application.yml | 32 +- api/api-core/mvnw | 322 --------- api/api-core/mvnw.cmd | 182 ----- .../api/core/spi/BlockchainGatewayProxy.kt | 2 +- .../nilin/opex/api/core/spi/OrderPersister.kt | 4 + api/api-ports/api-binance-rest/mvnw | 322 --------- api/api-ports/api-binance-rest/mvnw.cmd | 182 ----- api/api-ports/api-binance-rest/pom.xml | 16 +- .../binance/controller/WalletController.kt | 2 +- .../proxy/BlockchainGatewayProxyImpl.kt | 4 +- api/api-ports/api-eventlistener-kafka/mvnw | 322 --------- .../api-eventlistener-kafka/mvnw.cmd | 182 ----- .../kafka/listener/config/ApiKafkaConfig.kt | 51 +- .../listener/consumer/EventKafkaListener.kt | 2 +- .../listener/consumer/OrderKafkaListener.kt | 9 +- .../kafka/listener/spi/RichOrderListener.kt | 7 +- api/api-ports/api-persister-postgres/mvnw | 322 --------- api/api-ports/api-persister-postgres/mvnw.cmd | 182 ----- .../api/ports/postgres/dao/OrderRepository.kt | 27 +- .../postgres/dao/OrderStatusRepository.kt | 24 + .../api/ports/postgres/dao/TradeRepository.kt | 76 ++- .../postgres/impl/MarketQueryHandlerImpl.kt | 20 +- .../ports/postgres/impl/OrderPersisterImpl.kt | 132 ++-- .../ports/postgres/impl/TradePersisterImpl.kt | 117 +--- .../postgres/impl/UserQueryHandlerImpl.kt | 58 +- .../api/ports/postgres/model/OrderModel.kt | 4 - .../ports/postgres/model/OrderStatusModel.kt | 17 + .../src/main/resources/data.sql | 15 +- .../src/main/resources/schema.sql | 137 ++-- api/pom.xml | 7 + bc-gateway/bc-gateway-app/Dockerfile | 3 +- bc-gateway/bc-gateway-app/mvnw | 310 --------- bc-gateway/bc-gateway-app/mvnw.cmd | 182 ----- bc-gateway/bc-gateway-app/pom.xml | 8 +- .../opex/util/vault/VaultUserIdMechanism.kt | 9 + .../src/main/resources/application-docker.yml | 24 - .../src/main/resources/application.yml | 33 +- bc-gateway/bc-gateway-core/mvnw | 310 --------- bc-gateway/bc-gateway-core/mvnw.cmd | 182 ----- bc-gateway/bc-gateway-core/pom.xml | 3 +- .../core/service/ChainSyncServiceImpl.kt | 1 - .../core/spi/ChainSyncRetryHandler.kt | 2 +- .../core/spi/ChainSyncSchedulerHandler.kt | 2 +- .../core/service/ChainSyncServiceImplTest.kt | 8 +- .../bc-gateway-persister-postgres/mvnw | 310 --------- .../bc-gateway-persister-postgres/mvnw.cmd | 182 ----- .../postgres/dao/ChainSyncRecordRepository.kt | 2 +- .../src/main/resources/data.sql | 404 ++++++----- .../src/main/resources/schema.sql | 187 ++--- ...nkinsfile.deploy.groovy => dev.Jenkinsfile | 21 +- docker-compose.dev.yml | 28 + docker-compose.override.yml | 28 + docker-compose.yml | 450 ++++++++++++ eventlog/eventlog-app/Dockerfile | 3 +- eventlog/eventlog-app/pom.xml | 16 + .../opex/eventlog/app/config/AppConfig.kt | 4 +- .../opex/util/vault/VaultUserIdMechanism.kt | 9 + .../src/main/resources/application-docker.yml | 11 - .../src/main/resources/application.yml | 32 +- .../eventlog-eventlistener-kafka/mvnw | 310 --------- .../eventlog-eventlistener-kafka/mvnw.cmd | 182 ----- ...gKafkaConfig.kt => EventLogKafkaConfig.kt} | 55 +- .../listener/consumer/EventKafkaListener.kt | 2 +- .../listener/consumer/OrderKafkaListener.kt | 2 +- .../listener/consumer/TradeKafkaListener.kt | 2 +- .../eventlog-persister-postgres/mvnw | 310 --------- .../eventlog-persister-postgres/mvnw.cmd | 182 ----- .../ports/postgres/impl/EventPersisterImpl.kt | 4 +- .../ports/postgres/impl/OrderPersisterImpl.kt | 2 +- .../ports/postgres/impl/TradePersisterImpl.kt | 2 +- .../src/main/resources/schema.sql | 114 ++-- .../matching-engine-app/Dockerfile | 3 +- .../opex/matching/engine/app/bl/OrderBooks.kt | 3 +- .../matching/engine/app/config/AppConfig.kt | 81 +-- .../listener/MatchingEngineEventListener.kt | 51 ++ .../engine/app/listener/OrderListener.kt | 32 + .../src/main/resources/application-docker.yml | 13 - .../src/main/resources/application.yml | 7 +- .../engine/app/OrderBookEventEmitsUnitTest.kt | 11 +- matching-engine/matching-engine-core/mvnw | 310 --------- matching-engine/matching-engine-core/mvnw.cmd | 182 ----- .../engine/core/engine/SimpleOrderBook.kt | 143 ++-- .../core/eventh/events/CancelOrderEvent.kt | 46 +- .../engine/core/eventh/events/CoreEvent.kt | 6 +- .../core/eventh/events/CreateOrderEvent.kt | 46 +- .../eventh/events/EditOrderRequestEvent.kt | 31 +- .../eventh/events/OrderBookPublishedEvent.kt | 3 +- .../core/eventh/events/RejectOrderEvent.kt | 74 +- .../core/eventh/events/SubmitOrderEvent.kt | 46 +- .../engine/core/eventh/events/TradeEvent.kt | 70 +- .../core/eventh/events/UpdatedOrderEvent.kt | 54 +- .../opex/matching/engine/core/model/Bucket.kt | 3 + .../engine/core/model/PersistentOrderBook.kt | 1 + .../matching/engine/core/model/SimpleOrder.kt | 39 ++ .../core}/SimpleOrderBookUnitTest.kt | 91 +-- .../matching-engine-eventlistener-kafka/mvnw | 310 --------- .../mvnw.cmd | 182 ----- .../kafka/listener/config/OrderKafkaConfig.kt | 23 +- .../matching-engine-snapshots-redis/mvnw | 310 --------- .../matching-engine-snapshots-redis/mvnw.cmd | 182 ----- .../matching-engine-submitter-kafka/mvnw | 310 --------- .../matching-engine-submitter-kafka/mvnw.cmd | 182 ----- .../submitter/config/EventsKafkaConfig.kt | 43 +- .../matching-gateway-app/Dockerfile | 3 +- matching-gateway/matching-gateway-app/pom.xml | 4 - .../matching/gateway/app/config/AppConfig.kt | 2 +- .../gateway/app/proxy/AccountantProxyImpl.kt | 2 +- .../gateway/app/service/OrderService.kt | 13 +- .../gateway/app/spi/AccountantApiProxy.kt | 2 +- .../gateway/app/spi/PairConfigLoader.kt | 2 +- .../src/main/resources/application.yml | 10 +- .../matching-gateway-submitter-kafka/mvnw | 310 --------- .../matching-gateway-submitter-kafka/mvnw.cmd | 182 ----- .../submitter/config/OrderKafkaConfig.kt | 15 +- pom.xml | 15 +- resources/vault/backend-policy.hcl | 26 + resources/vault/panel-policy.hcl | 27 + resources/vault/vault.json | 16 + resources/vault/workflow-vault.sh | 87 +++ storage/storage-app/Dockerfile | 3 +- storage/storage-app/pom.xml | 9 +- .../opex/storage/app/config/SecurityConfig.kt | 14 +- .../storage/app/controller/FileController.kt | 13 +- .../opex/storage/app/utils/Extensions.kt | 19 + .../src/main/resources/application-docker.yml | 13 - .../src/main/resources/application.yml | 7 +- user-management/keycloak-gateway/Dockerfile | 3 +- user-management/keycloak-gateway/pom.xml | 29 +- .../auth/gateway/config/ErrorHandlerConfig.kt | 18 + .../opex/auth/gateway/config/KafkaConfig.kt | 25 +- .../auth/gateway/data/RegisterUserRequest.kt | 22 + .../auth/gateway/data/RegisterUserResponse.kt | 13 + .../opex/auth/gateway/data/UserProfileInfo.kt | 50 ++ .../extension/HashicorpVaultProvider.java | 52 ++ .../HashicorpVaultProviderFactory.java | 76 +++ .../extension/UserManagementResource.kt | 177 +++++ .../UserManagementResourceFactory.kt | 30 + .../auth/gateway/extension/VaultService.java | 60 ++ .../opex/auth/gateway/utils/ErrorHandler.kt | 18 + .../gateway/utils/ResourceAuthenticator.kt | 34 + .../opex/util/vault/VaultUserIdMechanism.kt | 9 + .../resources/META-INF/keycloak-server.json | 12 +- ...ices.resource.RealmResourceProviderFactory | 1 + .../org.keycloak.vault.VaultProviderFactory | 1 + .../src/main/resources/application-docker.yml | 17 - .../src/main/resources/application.yml | 32 +- .../src/main/resources/opex-master-realm.json | 2 +- .../src/main/resources/opex-realm.json | 644 ++++++++++++++++-- user-management/pom.xml | 16 + .../opex/utility/error/data/OpexError.kt | 1 + wallet/wallet-app/Dockerfile | 3 +- wallet/wallet-app/mvnw | 310 --------- wallet/wallet-app/mvnw.cmd | 182 ----- wallet/wallet-app/pom.xml | 15 +- .../opex/util/vault/VaultUserIdMechanism.kt | 9 + .../opex/wallet/app/config/SecurityConfig.kt | 11 +- .../nilin/opex/wallet/app/utils/Extensions.kt | 19 + .../src/main/resources/application-docker.yml | 18 - .../src/main/resources/application.yml | 29 +- wallet/wallet-core/mvnw | 310 --------- wallet/wallet-core/mvnw.cmd | 182 ----- .../wallet-eventlistener-kafka/mvnw | 310 --------- .../wallet-eventlistener-kafka/mvnw.cmd | 182 ----- .../listener/config/WalletKafkaConfig.kt | 41 +- .../wallet-persister-postgres/mvnw | 310 --------- .../wallet-persister-postgres/mvnw.cmd | 182 ----- .../src/main/resources/data.sql | 81 +-- .../src/main/resources/schema.sql | 165 ++--- websocket/websocket-app/Dockerfile | 3 +- websocket/websocket-app/pom.xml | 8 +- .../opex/util/vault/VaultUserIdMechanism.kt | 9 + .../nilin/opex/websocket/app/dto/Interval.kt | 2 +- .../opex/websocket/app/dto/OrderResponse.kt | 15 +- .../app/listener/WebSocketKafkaListener.kt | 23 +- .../app/service/EventStreamHandlerImpl.kt | 31 +- .../service/stream/IntervalStreamHandler.kt | 2 +- .../websocket/app/utils/EnumExtensions.kt | 6 +- .../src/main/resources/application-docker.yml | 18 - .../src/main/resources/application.yml | 29 +- .../websocket/core/spi/EventStreamHandler.kt | 3 + .../listener/config/WebSocketKafkaConfig.kt | 59 +- .../listener/consumer/OrderKafkaListener.kt | 6 +- .../kafka/listener/spi/RichOrderListener.kt | 7 +- .../ports/postgres/dao/OrderRepository.kt | 24 +- .../postgres/dao/OrderStatusRepository.kt | 24 + .../ports/postgres/dao/TradeRepository.kt | 76 ++- .../postgres/impl/MarketQueryHandlerImpl.kt | 20 +- .../postgres/impl/UserQueryHandlerImpl.kt | 58 +- .../ports/postgres/model/OrderModel.kt | 3 - .../ports/postgres/model/OrderStatusModel.kt | 17 + 269 files changed, 5019 insertions(+), 14356 deletions(-) delete mode 100644 Deployment/.gitignore delete mode 100644 Deployment/docker-compose.dev.yml delete mode 100644 Deployment/docker-compose.override.yml delete mode 100644 Deployment/docker-compose.yml delete mode 100644 Deployment/nginx.conf rename Jenkins/Jenkinsfile.deploy.dev.groovy => Jenkinsfile (65%) create mode 100644 accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/listener/AccountantEventListener.kt create mode 100644 accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/listener/AccountantTempEventListener.kt create mode 100644 accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/listener/AccountantTradeListener.kt create mode 100644 accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/listener/OrderListener.kt create mode 100644 accountant/accountant-app/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt delete mode 100644 accountant/accountant-app/src/main/resources/application-docker.yml delete mode 100644 accountant/accountant-core/mvnw delete mode 100644 accountant/accountant-core/mvnw.cmd create mode 100644 accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/inout/RichOrderEvent.kt create mode 100644 accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/inout/RichOrderUpdate.kt delete mode 100644 accountant/accountant-ports/accountant-eventlistener-kafka/mvnw delete mode 100644 accountant/accountant-ports/accountant-eventlistener-kafka/mvnw.cmd delete mode 100644 accountant/accountant-ports/accountant-persister-postgres/mvnw delete mode 100644 accountant/accountant-ports/accountant-persister-postgres/mvnw.cmd delete mode 100644 accountant/accountant-ports/accountant-submitter-kafka/mvnw delete mode 100644 accountant/accountant-ports/accountant-submitter-kafka/mvnw.cmd delete mode 100644 accountant/accountant-ports/accountant-wallet-proxy/mvnw delete mode 100644 accountant/accountant-ports/accountant-wallet-proxy/mvnw.cmd create mode 100644 admin/admin-app/.gitignore create mode 100644 admin/admin-app/Dockerfile create mode 100644 admin/admin-app/pom.xml create mode 100644 admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/AdminApplication.kt create mode 100644 admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/config/SecurityConfig.kt create mode 100644 admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/config/WebClientConfig.kt create mode 100644 admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/utils/Extensions.kt rename matching-gateway/matching-gateway-app/src/main/resources/application-docker.yml => admin/admin-app/src/main/resources/application.yml (57%) create mode 100644 admin/admin-core/.gitignore create mode 100644 admin/admin-core/pom.xml create mode 100644 admin/admin-core/src/main/kotlin/co/nilin/opex/admin/core/AdminCoreApplication.kt create mode 100644 admin/admin-ports/admin-service-auth/.gitignore create mode 100644 admin/admin-ports/admin-service-auth/pom.xml create mode 100644 admin/admin-ports/admin-service-auth/src/main/kotlin/co/nilin/opex/admin/ports/auth/config/KeycloakAdminConfig.kt create mode 100644 admin/admin-ports/admin-service-auth/src/main/kotlin/co/nilin/opex/admin/ports/auth/controller/AuthAdminController.kt create mode 100644 admin/admin-ports/admin-service-auth/src/main/kotlin/co/nilin/opex/admin/ports/auth/data/KeycloakUser.kt create mode 100644 admin/admin-ports/admin-service-auth/src/main/kotlin/co/nilin/opex/admin/ports/auth/data/KycGroup.kt create mode 100644 admin/admin-ports/admin-service-auth/src/main/kotlin/co/nilin/opex/admin/ports/auth/service/AuthAdminService.kt create mode 100644 admin/admin-ports/admin-service-auth/src/main/kotlin/co/nilin/opex/admin/ports/auth/utils/Extensions.kt create mode 100644 admin/pom.xml create mode 100644 api/api-app/src/main/kotlin/co/nilin/opex/api/app/listener/ApiListenerImpl.kt create mode 100644 api/api-app/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt delete mode 100644 api/api-app/src/main/resources/application-docker.yml delete mode 100644 api/api-core/mvnw delete mode 100644 api/api-core/mvnw.cmd delete mode 100644 api/api-ports/api-binance-rest/mvnw delete mode 100644 api/api-ports/api-binance-rest/mvnw.cmd delete mode 100644 api/api-ports/api-eventlistener-kafka/mvnw delete mode 100644 api/api-ports/api-eventlistener-kafka/mvnw.cmd delete mode 100644 api/api-ports/api-persister-postgres/mvnw delete mode 100644 api/api-ports/api-persister-postgres/mvnw.cmd create mode 100644 api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/dao/OrderStatusRepository.kt create mode 100644 api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/model/OrderStatusModel.kt delete mode 100644 bc-gateway/bc-gateway-app/mvnw delete mode 100644 bc-gateway/bc-gateway-app/mvnw.cmd create mode 100644 bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt delete mode 100644 bc-gateway/bc-gateway-app/src/main/resources/application-docker.yml delete mode 100644 bc-gateway/bc-gateway-core/mvnw delete mode 100644 bc-gateway/bc-gateway-core/mvnw.cmd delete mode 100644 bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/mvnw delete mode 100644 bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/mvnw.cmd rename Jenkins/Jenkinsfile.deploy.groovy => dev.Jenkinsfile (63%) create mode 100644 docker-compose.dev.yml create mode 100644 docker-compose.override.yml create mode 100644 docker-compose.yml create mode 100644 eventlog/eventlog-app/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt delete mode 100644 eventlog/eventlog-app/src/main/resources/application-docker.yml delete mode 100644 eventlog/eventlog-ports/eventlog-eventlistener-kafka/mvnw delete mode 100644 eventlog/eventlog-ports/eventlog-eventlistener-kafka/mvnw.cmd rename eventlog/eventlog-ports/eventlog-eventlistener-kafka/src/main/kotlin/co/nilin/opex/eventlog/ports/kafka/listener/config/{EventlogKafkaConfig.kt => EventLogKafkaConfig.kt} (70%) delete mode 100644 eventlog/eventlog-ports/eventlog-persister-postgres/mvnw delete mode 100644 eventlog/eventlog-ports/eventlog-persister-postgres/mvnw.cmd create mode 100644 matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/listener/MatchingEngineEventListener.kt create mode 100644 matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/listener/OrderListener.kt delete mode 100644 matching-engine/matching-engine-app/src/main/resources/application-docker.yml rename "matching-engine/matching-engine-app/src/test/kotlin/co/nilin/opex/matching/core/engine/OrderBook\331\215EventEmitsUnitTest.kt" => matching-engine/matching-engine-app/src/test/kotlin/co/nilin/opex/matching/engine/app/OrderBookEventEmitsUnitTest.kt (93%) delete mode 100644 matching-engine/matching-engine-core/mvnw delete mode 100644 matching-engine/matching-engine-core/mvnw.cmd create mode 100644 matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/model/Bucket.kt create mode 100644 matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/model/SimpleOrder.kt rename matching-engine/matching-engine-core/src/test/kotlin/co/nilin/opex/matching/{core/engine => engine/core}/SimpleOrderBookUnitTest.kt (87%) delete mode 100644 matching-engine/matching-engine-ports/matching-engine-eventlistener-kafka/mvnw delete mode 100644 matching-engine/matching-engine-ports/matching-engine-eventlistener-kafka/mvnw.cmd delete mode 100644 matching-engine/matching-engine-ports/matching-engine-snapshots-redis/mvnw delete mode 100644 matching-engine/matching-engine-ports/matching-engine-snapshots-redis/mvnw.cmd delete mode 100644 matching-engine/matching-engine-ports/matching-engine-submitter-kafka/mvnw delete mode 100644 matching-engine/matching-engine-ports/matching-engine-submitter-kafka/mvnw.cmd delete mode 100644 matching-gateway/matching-gateway-port/matching-gateway-submitter-kafka/mvnw delete mode 100644 matching-gateway/matching-gateway-port/matching-gateway-submitter-kafka/mvnw.cmd create mode 100644 resources/vault/backend-policy.hcl create mode 100644 resources/vault/panel-policy.hcl create mode 100644 resources/vault/vault.json create mode 100755 resources/vault/workflow-vault.sh create mode 100644 storage/storage-app/src/main/kotlin/co/nilin/opex/storage/app/utils/Extensions.kt delete mode 100644 storage/storage-app/src/main/resources/application-docker.yml create mode 100644 user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/config/ErrorHandlerConfig.kt create mode 100644 user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/data/RegisterUserRequest.kt create mode 100644 user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/data/RegisterUserResponse.kt create mode 100644 user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/data/UserProfileInfo.kt create mode 100644 user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/extension/HashicorpVaultProvider.java create mode 100644 user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/extension/HashicorpVaultProviderFactory.java create mode 100644 user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/extension/UserManagementResource.kt create mode 100644 user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/extension/UserManagementResourceFactory.kt create mode 100644 user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/extension/VaultService.java create mode 100644 user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/utils/ErrorHandler.kt create mode 100644 user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/utils/ResourceAuthenticator.kt create mode 100644 user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt create mode 100644 user-management/keycloak-gateway/src/main/resources/META-INF/services/org.keycloak.services.resource.RealmResourceProviderFactory create mode 100644 user-management/keycloak-gateway/src/main/resources/META-INF/services/org.keycloak.vault.VaultProviderFactory delete mode 100644 user-management/keycloak-gateway/src/main/resources/application-docker.yml delete mode 100644 wallet/wallet-app/mvnw delete mode 100644 wallet/wallet-app/mvnw.cmd create mode 100644 wallet/wallet-app/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt create mode 100644 wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/utils/Extensions.kt delete mode 100644 wallet/wallet-app/src/main/resources/application-docker.yml delete mode 100644 wallet/wallet-core/mvnw delete mode 100644 wallet/wallet-core/mvnw.cmd delete mode 100644 wallet/wallet-ports/wallet-eventlistener-kafka/mvnw delete mode 100644 wallet/wallet-ports/wallet-eventlistener-kafka/mvnw.cmd delete mode 100644 wallet/wallet-ports/wallet-persister-postgres/mvnw delete mode 100644 wallet/wallet-ports/wallet-persister-postgres/mvnw.cmd create mode 100644 websocket/websocket-app/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt delete mode 100644 websocket/websocket-app/src/main/resources/application-docker.yml create mode 100644 websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/dao/OrderStatusRepository.kt create mode 100644 websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/model/OrderStatusModel.kt diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index f29f64684..5d69ee53d 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - java: [ 13 ] + java: [ 11 ] name: Opex with java ${{ matrix.java }} build steps: - name: Checkout Source Code diff --git a/.gitignore b/.gitignore index f4e066ca5..8ccbd2f56 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,13 @@ target/ *.iml *.ipr +### Other files ### +.env +docker-compose.local.yml +application-local.yml +mvnw +mvnw.cmd + ### NetBeans ### /nbproject/private/ /nbbuild/ diff --git a/Deployment/.gitignore b/Deployment/.gitignore deleted file mode 100644 index eaddd784f..000000000 --- a/Deployment/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -runtime/ -*.iml - diff --git a/Deployment/docker-compose.dev.yml b/Deployment/docker-compose.dev.yml deleted file mode 100644 index c1d0b27c0..000000000 --- a/Deployment/docker-compose.dev.yml +++ /dev/null @@ -1,120 +0,0 @@ -services: - zookeeper: - ports: - - '127.0.0.1:2182:2181' - networks: - - opex-dev - kafka: - ports: - - '127.0.0.1:9093:9092' - networks: - - opex-dev - consul: - ports: - - '127.0.0.1:8501:8500' - - '127.0.0.1:8302:8300' - - '127.0.0.1:8603:8600' - networks: - - opex-dev - redis: - ports: - - "127.0.0.1:6380:6379" - networks: - - opex-dev - postgres-accountant: - ports: - - 127.0.0.1:5633:5432 - networks: - - opex-dev - postgres-eventlog: - ports: - - 127.0.0.1:5634:5432 - networks: - - opex-dev - postgres-auth: - ports: - - 127.0.0.1:5635:5432 - networks: - - opex-dev - postgres-wallet: - ports: - - 127.0.0.1:5636:5432 - networks: - - opex-dev - postgres-api: - ports: - - 127.0.0.1:5637:5432 - networks: - - opex-dev - postgres-bc-gateway: - ports: - - 127.0.0.1:5638:5432 - networks: - - opex-dev - accountant: - ports: - - 127.0.0.1:8289:8089 - - 127.0.0.1:1146:1044 - networks: - - opex-dev - eventlog: - ports: - - 127.0.0.1:8290:8090 - networks: - - opex-dev - matching-engine: - ports: - - 127.0.0.1:8292:8092 - - 127.0.0.1:1246:1044 - networks: - - opex-dev - matching-gateway: - ports: - - 127.0.0.1:8293:8093 - - 127.0.0.1:1147:1044 - networks: - - opex-dev - auth: - ports: - - 127.0.0.1:8283:8083 - - 127.0.0.1:1148:1044 - networks: - - opex-dev - wallet: - ports: - - 127.0.0.1:8291:8091 - - 127.0.0.1:1149:1044 - networks: - - opex-dev - api: - ports: - - 127.0.0.1:8294:8094 - - 127.0.0.1:1150:1044 - networks: - - opex-dev - websocket: - ports: - - 127.0.0.1:8297:8097 - - 127.0.0.1:1154:1044 - networks: - - opex-dev - bc-gateway: - ports: - - 127.0.0.1:8295:8095 - - 127.0.0.1:1152:1044 - networks: - - opex-dev - storage: - ports: - - 127.0.0.1:8296:8096 - - 127.0.0.1:1153:1044 - networks: - - opex-dev - nginx: - ports: - - 8086:80 - networks: - - opex-dev -networks: - opex-dev: - driver: bridge diff --git a/Deployment/docker-compose.override.yml b/Deployment/docker-compose.override.yml deleted file mode 100644 index 27cfb9eeb..000000000 --- a/Deployment/docker-compose.override.yml +++ /dev/null @@ -1,142 +0,0 @@ -services: - zookeeper: - ports: - - '127.0.0.1:2181:2181' - networks: - - opex - kafka: - ports: - - '127.0.0.1:9092:9092' - networks: - - opex - consul: - ports: - - '127.0.0.1:8500:8500' - - '127.0.0.1:8300:8300' - - '127.0.0.1:8600:8600' - networks: - - opex - redis: - ports: - - "127.0.0.1:6379:6379" - networks: - - opex - postgres-accountant: - ports: - - 127.0.0.1:5433:5432 - networks: - - opex - postgres-eventlog: - ports: - - 127.0.0.1:5434:5432 - networks: - - opex - postgres-auth: - ports: - - 127.0.0.1:5435:5432 - networks: - - opex - postgres-wallet: - ports: - - 127.0.0.1:5436:5432 - networks: - - opex - postgres-api: - ports: - - 127.0.0.1:5437:5432 - networks: - - opex - postgres-bc-gateway: - ports: - - 127.0.0.1:5438:5432 - networks: - - opex - accountant: - ports: - - 127.0.0.1:8089:8089 - - 127.0.0.1:1045:1044 - networks: - opex: - aliases: - - accountant - eventlog: - ports: - - 127.0.0.1:8090:8090 - networks: - opex: - aliases: - - eventlog - matching-engine: - ports: - - 127.0.0.1:8092:8092 - - 127.0.0.1:1046:1044 - networks: - opex: - aliases: - - matching-engine - matching-gateway: - ports: - - 127.0.0.1:8093:8093 - - 127.0.0.1:1047:1044 - networks: - opex: - aliases: - - matching-gateway - auth: - ports: - - 127.0.0.1:8083:8083 - - 127.0.0.1:1048:1044 - networks: - opex: - aliases: - - auth - wallet: - ports: - - 127.0.0.1:8091:8091 - - 127.0.0.1:1049:1044 - networks: - opex: - aliases: - - wallet - api: - ports: - - 127.0.0.1:8094:8094 - - 127.0.0.1:1050:1044 - networks: - opex: - aliases: - - api - websocket: - ports: - - 127.0.0.1:8097:8097 - - 127.0.0.1:1054:1044 - networks: - opex: - aliases: - - websocket - bc-gateway: - ports: - - 127.0.0.1:8095:8095 - - 127.0.0.1:1052:1044 - networks: - opex: - aliases: - - bc-gateway - storage: - ports: - - 127.0.0.1:8096:8096 - - 127.0.0.1:1053:1044 - networks: - opex: - aliases: - - storage - nginx: - ports: - - 80:80 - networks: - opex: - aliases: - - opex_nginx -networks: - opex: - driver: bridge diff --git a/Deployment/docker-compose.yml b/Deployment/docker-compose.yml deleted file mode 100644 index 56da1276c..000000000 --- a/Deployment/docker-compose.yml +++ /dev/null @@ -1,286 +0,0 @@ -version: '3.8' -services: - zookeeper: - image: 'docker.io/bitnami/zookeeper:3-debian-10' - volumes: - - $DATA/zookeeper_data:/bitnami - environment: - - ALLOW_ANONYMOUS_LOGIN=yes - deploy: - restart_policy: - condition: on-failure - kafka: - image: 'docker.io/bitnami/kafka:2-debian-10' - volumes: - - $DATA/kafka-data:/bitnami - environment: - - KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181 - - ALLOW_PLAINTEXT_LISTENER=yes - - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092 - depends_on: - - zookeeper - deploy: - restart_policy: - condition: on-failure - consul: - image: 'consul' - environment: - - CONSUL_BIND_INTERFACE=eth0 - deploy: - restart_policy: - condition: on-failure - redis: - image: "redis:alpine" - command: redis-server - volumes: - - $DATA/redis-data:/var/lib/redis - - $DATA/redis.conf:/usr/local/etc/redis/redis.conf - environment: - - REDIS_REPLICATION_MODE=master - deploy: - restart_policy: - condition: on-failure - postgres-accountant: - image: "postgres" - environment: - - POSTGRES_USER=opex - - POSTGRES_PASSWORD=hiopex - - POSTGRES_DB=opex_accountant - volumes: - - $DATA/accountant-data:/var/lib/postgresql/data/ - postgres-eventlog: - image: "postgres" - environment: - - POSTGRES_USER=opex - - POSTGRES_PASSWORD=hiopex - - POSTGRES_DB=opex_eventlog - volumes: - - $DATA/eventlog-data:/var/lib/postgresql/data/ - postgres-auth: - image: "postgres" - environment: - - POSTGRES_USER=opex - - POSTGRES_PASSWORD=hiopex - - POSTGRES_DB=opex_auth - volumes: - - $DATA/auth-data:/var/lib/postgresql/data/ - deploy: - restart_policy: - condition: on-failure - postgres-wallet: - image: "postgres" - environment: - - POSTGRES_USER=opex - - POSTGRES_PASSWORD=hiopex - - POSTGRES_DB=opex_wallet - volumes: - - $DATA/wallet-data:/var/lib/postgresql/data/ - deploy: - restart_policy: - condition: on-failure - postgres-api: - image: "postgres" - environment: - - POSTGRES_USER=opex - - POSTGRES_PASSWORD=hiopex - - POSTGRES_DB=opex_api - volumes: - - $DATA/api-data:/var/lib/postgresql/data/ - deploy: - restart_policy: - condition: on-failure - postgres-bc-gateway: - image: "postgres" - environment: - - POSTGRES_USER=opex - - POSTGRES_PASSWORD=hiopex - - POSTGRES_DB=opex_bc_gateway - volumes: - - $DATA/bc-gateway-data:/var/lib/postgresql/data/ - deploy: - restart_policy: - condition: on-failure - accountant: - build: - context: ../accountant/accountant-app - dockerfile: Dockerfile - environment: - - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044 - - SPRING_PROFILES_ACTIVE=docker,demo,scheduled - - KAFKA_IP_PORT=kafka:9092 - - REDIS_HOST=redis - - CONSUL_HOST=consul - - DB_IP_PORT=postgres-accountant - depends_on: - - zookeeper - - kafka - - redis - - consul - - postgres-accountant - eventlog: - build: - context: ../eventlog/eventlog-app - dockerfile: Dockerfile - environment: - - JAVA_OPTS=-Xmx256m - - SPRING_PROFILES_ACTIVE=docker,demo - - KAFKA_IP_PORT=kafka:9092 - - REDIS_HOST=redis - - CONSUL_HOST=consul - - DB_IP_PORT=postgres-eventlog - depends_on: - - zookeeper - - kafka - - redis - - consul - - postgres-eventlog - matching-engine: - build: - context: ../matching-engine/matching-engine-app - dockerfile: Dockerfile - environment: - - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044 - - SPRING_PROFILES_ACTIVE=docker,demo - - KAFKA_IP_PORT=kafka:9092 - - REDIS_HOST=redis - depends_on: - - zookeeper - - kafka - - redis - matching-gateway: - build: - context: ../matching-gateway/matching-gateway-app - dockerfile: Dockerfile - environment: - - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044 - - SPRING_PROFILES_DEFAULT=docker,demo - - KAFKA_IP_PORT=kafka:9092 - - REDIS_HOST=redis - - CONSUL_HOST=consul - depends_on: - - zookeeper - - kafka - - consul - auth: - build: - context: ../user-management/keycloak-gateway - dockerfile: Dockerfile - environment: - - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044 - - SPRING_PROFILES_ACTIVE=docker,demo - - KAFKA_IP_PORT=kafka:9092 - - REDIS_HOST=redis - - CONSUL_HOST=consul - - DB_IP_PORT=postgres-auth - - PROXY_ADDRESS_FORWARDING=true - - WORKING_DIR=$DATA - depends_on: - - zookeeper - - kafka - - redis - - consul - - postgres-auth - deploy: - restart_policy: - condition: on-failure - wallet: - build: - context: ../wallet/wallet-app - dockerfile: Dockerfile - environment: - - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044 - - SPRING_PROFILES_DEFAULT=docker,demo - - KAFKA_IP_PORT=kafka:9092 - - REDIS_HOST=redis - - CONSUL_HOST=consul - - DB_IP_PORT=postgres-wallet - depends_on: - - zookeeper - - kafka - - redis - - consul - - postgres-wallet - deploy: - restart_policy: - condition: on-failure - api: - build: - context: ../api/api-app - dockerfile: Dockerfile - environment: - - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044 - - SPRING_PROFILES_DEFAULT=docker,demo - - KAFKA_IP_PORT=kafka:9092 - - REDIS_HOST=redis - - CONSUL_HOST=consul - - DB_IP_PORT=postgres-api - depends_on: - - zookeeper - - kafka - - redis - - consul - - postgres-api - deploy: - restart_policy: - condition: on-failure - websocket: - build: - context: ../websocket/websocket-app - dockerfile: Dockerfile - environment: - - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044 - - SPRING_PROFILES_DEFAULT=docker - - KAFKA_IP_PORT=kafka:9092 - - CONSUL_HOST=consul - - DB_IP_PORT=postgres-api - depends_on: - - zookeeper - - kafka - - consul - - postgres-api - deploy: - restart_policy: - condition: on-failure - bc-gateway: - build: - context: ../bc-gateway/bc-gateway-app - dockerfile: Dockerfile - environment: - - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044 - - SPRING_PROFILES_DEFAULT=docker,demo,scheduled - - KAFKA_IP_PORT=kafka:9092 - - REDIS_HOST=redis - - CONSUL_HOST=consul - - DB_IP_PORT=postgres-bc-gateway - depends_on: - - zookeeper - - kafka - - redis - - consul - - postgres-bc-gateway - deploy: - restart_policy: - condition: on-failure - storage: - build: - context: ../storage/storage-app - dockerfile: Dockerfile - environment: - - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044 - - SPRING_PROFILES_DEFAULT=docker - - CONSUL_HOST=consul - depends_on: - - consul - deploy: - restart_policy: - condition: on-failure - nginx: - image: jboesl/docker-nginx-headers-more - volumes: - - ./nginx.conf:/etc/nginx/nginx.conf - - $DATA/www:/data/www - depends_on: - - wallet - - auth - - matching-gateway - - api diff --git a/Deployment/nginx.conf b/Deployment/nginx.conf deleted file mode 100644 index ef1e81ebe..000000000 --- a/Deployment/nginx.conf +++ /dev/null @@ -1,107 +0,0 @@ -worker_processes 1; - -events { - worker_connections 1024; -} - -http { - sendfile on; - - upstream docker-wallet { - server wallet:8091; - } - - upstream docker-auth { - server auth:8083; - } - - upstream docker-matching-gateway { - server matching-gateway:8093; - } - - upstream docker-api { - server api:8094; - } - - upstream docker-storage { - server storage:8096; - } - - upstream docker-websocket { - server websocket:8097; - } - - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Host $server_name; - - server { - server_name api.opex.dev; - - more_set_headers 'Access-Control-Allow-Origin: *'; - more_set_headers 'Access-Control-Allow-Headers: *'; - more_set_headers 'Access-Control-Allow-Methods: POST, PUT, PATCH, GET, DELETE, OPTIONS, HEAD'; - - if ($request_method = 'OPTIONS') { - return 204; - } - - location /auth { - proxy_pass http://docker-auth; - } - - location /wallet/transfer { - return 403; - } - - location /wallet/deposit { - return 403; - } - - location /wallet/payment/internal { - return 403; - } - - location /wallet { - proxy_pass http://docker-wallet; - rewrite ^/wallet(.*)$ $1 break; - } - - location /gateway { - proxy_pass http://docker-matching-gateway; - rewrite ^/gateway(.*)$ $1 break; - } - - location /storage { - proxy_pass http://docker-storage; - rewrite ^/storage/(.*)$ /$1 break; - } - - location /stream { - proxy_pass http://docker-websocket; - # WS config - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - ########### - rewrite ^/stream(.*)$ $1 break; - } - - location /api { - proxy_pass http://docker-api; - rewrite ^/api(.*)$ $1 break; - } - - location /sapi { - proxy_pass http://docker-api; - rewrite ^/sapi(.*)$ $1 break; - } - - location /binance { - proxy_set_header Host api.binance.com; - proxy_pass https://api.binance.com; - rewrite ^/binance/(.*)$ /$1 break; - } - } -} diff --git a/Jenkins/Jenkinsfile.deploy.dev.groovy b/Jenkinsfile similarity index 65% rename from Jenkins/Jenkinsfile.deploy.dev.groovy rename to Jenkinsfile index 4c78c89b0..050395f92 100644 --- a/Jenkins/Jenkinsfile.deploy.dev.groovy +++ b/Jenkinsfile @@ -1,12 +1,12 @@ pipeline { agent any - stages('Deploy - Stage') { + stages('Deploy') { stage('Build') { steps { setBuildStatus("?", "PENDING") withMaven( - maven: 'maven-latest' + maven: 'maven-3.6.3' ) { sh 'mvn -B clean install' } @@ -14,12 +14,21 @@ pipeline { } stage('Deliver') { environment { - DATA = '/var/opex/runtime-dev' + DATA = '/var/opex/demo-core' + PANEL_PASS = credentials("v-panel-secret") + BACKEND_USER = credentials("v-backend-secret") + SMTP_PASS = credentials("smtp-secret") + DB_USER = 'opex' + DB_PASS = credentials("db-secret") + KEYCLOAK_ADMIN_URL = 'https://demo.opex.dev/auth' + KEYCLOAK_FRONTEND_URL = 'https://demo.opex.dev/auth' + COMPOSE_PROJECT_NAME = 'demo-core' + DEFAULT_NETWORK_NAME = 'demo-opex' } steps { - dir("Deployment") { - sh 'COMPOSE_PROJECT_NAME=dev docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d --build' - } + sh 'docker-compose up -d --build --remove-orphans' + sh 'docker image prune -f' + sh 'docker network prune -f' } } } diff --git a/accountant/accountant-app/Dockerfile b/accountant/accountant-app/Dockerfile index f2cbd4c26..7c71f9447 100644 --- a/accountant/accountant-app/Dockerfile +++ b/accountant/accountant-app/Dockerfile @@ -1,5 +1,4 @@ -FROM openjdk:8-jdk-alpine -VOLUME /tmp +FROM openjdk:11 ARG JAR_FILE=target/*.jar COPY ${JAR_FILE} app.jar ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -jar /app.jar"] \ No newline at end of file diff --git a/accountant/accountant-app/pom.xml b/accountant/accountant-app/pom.xml index aeb891bef..7f6034024 100644 --- a/accountant/accountant-app/pom.xml +++ b/accountant/accountant-app/pom.xml @@ -55,6 +55,10 @@ co.nilin.opex.utility.log logging-handler + + org.springframework.cloud + spring-cloud-starter-vault-config + diff --git a/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/AppConfig.kt b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/AppConfig.kt index cdd6f954c..d8a8791c2 100644 --- a/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/AppConfig.kt +++ b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/AppConfig.kt @@ -1,5 +1,9 @@ package co.nilin.opex.accountant.app.config +import co.nilin.opex.accountant.app.listener.AccountantEventListener +import co.nilin.opex.accountant.app.listener.AccountantTempEventListener +import co.nilin.opex.accountant.app.listener.AccountantTradeListener +import co.nilin.opex.accountant.app.listener.OrderListener import co.nilin.opex.accountant.core.api.FinancialActionJobManager import co.nilin.opex.accountant.core.api.OrderManager import co.nilin.opex.accountant.core.api.TradeManager @@ -7,17 +11,10 @@ import co.nilin.opex.accountant.core.service.FinancialActionJobManagerImpl import co.nilin.opex.accountant.core.service.OrderManagerImpl import co.nilin.opex.accountant.core.service.TradeManagerImpl import co.nilin.opex.accountant.core.spi.* -import co.nilin.opex.matching.engine.core.eventh.events.* import co.nilin.opex.accountant.ports.kafka.listener.consumer.EventKafkaListener import co.nilin.opex.accountant.ports.kafka.listener.consumer.OrderKafkaListener import co.nilin.opex.accountant.ports.kafka.listener.consumer.TempEventKafkaListener import co.nilin.opex.accountant.ports.kafka.listener.consumer.TradeKafkaListener -import co.nilin.opex.accountant.ports.kafka.listener.spi.EventListener -import co.nilin.opex.accountant.ports.kafka.listener.spi.OrderSubmitRequestListener -import co.nilin.opex.accountant.ports.kafka.listener.spi.TempEventListener -import co.nilin.opex.accountant.ports.kafka.listener.spi.TradeListener -import co.nilin.opex.accountant.ports.kafka.listener.inout.OrderSubmitRequest -import kotlinx.coroutines.runBlocking import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Value import org.springframework.context.annotation.Bean @@ -70,6 +67,7 @@ class AppConfig { orderPersister: OrderPersister, tempEventPersister: TempEventPersister, richTradePublisher: RichTradePublisher, + richOrderPublisher: RichOrderPublisher, walletProxy: WalletProxy, @Value("\${app.coin}") platformCoin: String, @Value("\${app.address}") platformAddress: String @@ -81,6 +79,7 @@ class AppConfig { orderPersister, tempEventPersister, richTradePublisher, + richOrderPublisher, walletProxy, platformCoin, platformAddress @@ -98,9 +97,7 @@ class AppConfig { } @Bean - fun accountantEventListener( - orderManager: OrderManager - ): AccountantEventListener { + fun accountantEventListener(orderManager: OrderManager): AccountantEventListener { return AccountantEventListener(orderManager) } @@ -141,98 +138,4 @@ class AppConfig { tempEventKafkaListener.addEventListener(accountantTempEventListener) } - class OrderListener(val orderManager: OrderManager) : OrderSubmitRequestListener { - - override fun id(): String { - return "OrderListener" - } - - override fun onOrder(order: OrderSubmitRequest, partition: Int, offset: Long, timestamp: Long) { - runBlocking(AppDispatchers.kafkaExecutor) { - orderManager.handleRequestOrder( - SubmitOrderEvent( - order.ouid, - order.uuid, - order.orderId, - order.pair, - order.price, - order.quantity, - order.quantity, - order.direction, - order.matchConstraint, - order.orderType - ) - ) - } - } - } - - class AccountantTradeListener(val tradeManager: TradeManager) : TradeListener { - - override fun id(): String { - return "TradeListener" - } - - override fun onTrade(tradeEvent: TradeEvent, partition: Int, offset: Long, timestamp: Long) { - runBlocking(AppDispatchers.kafkaExecutor) { - tradeManager.handleTrade(tradeEvent) - } - } - } - - class AccountantEventListener( - val orderManager: OrderManager - ) : EventListener { - - override fun id(): String { - return "EventListener" - } - - override fun onEvent(coreEvent: CoreEvent, partition: Int, offset: Long, timestamp: Long) { - runBlocking(AppDispatchers.kafkaExecutor) { - if (coreEvent is CreateOrderEvent) - orderManager.handleNewOrder(coreEvent) - else if (coreEvent is RejectOrderEvent) - orderManager.handleRejectOrder(coreEvent) - else if (coreEvent is UpdatedOrderEvent) - orderManager.handleUpdateOrder(coreEvent) - else if (coreEvent is CancelOrderEvent) - orderManager.handleCancelOrder(coreEvent) - else { - println("Event is not accepted ${coreEvent::class.java}") - } - } - println("onEvent") - } - } - - class AccountantTempEventListener( - val orderManager: OrderManager, - val tradeManager: TradeManager - ) : TempEventListener { - - override fun id(): String { - return "TempEventListener" - } - - override fun onEvent(coreEvent: CoreEvent, partition: Int, offset: Long, timestamp: Long) { - println("TempEvent " + coreEvent) - runBlocking(AppDispatchers.kafkaExecutor) { - if (coreEvent is CreateOrderEvent) - orderManager.handleNewOrder(coreEvent) - else if (coreEvent is RejectOrderEvent) - orderManager.handleRejectOrder(coreEvent) - else if (coreEvent is UpdatedOrderEvent) - orderManager.handleUpdateOrder(coreEvent) - else if (coreEvent is CancelOrderEvent) - orderManager.handleCancelOrder(coreEvent) - else if (coreEvent is TradeEvent) - tradeManager.handleTrade(coreEvent) - else { - throw IllegalArgumentException("Event is not accepted ${coreEvent::class.java}") - } - } - println("onEvent") - } - } } \ No newline at end of file diff --git a/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/listener/AccountantEventListener.kt b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/listener/AccountantEventListener.kt new file mode 100644 index 000000000..e1de3e767 --- /dev/null +++ b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/listener/AccountantEventListener.kt @@ -0,0 +1,28 @@ +package co.nilin.opex.accountant.app.listener + +import co.nilin.opex.accountant.core.api.OrderManager +import co.nilin.opex.accountant.ports.kafka.listener.spi.EventListener +import co.nilin.opex.matching.engine.core.eventh.events.* +import kotlinx.coroutines.runBlocking + +class AccountantEventListener(private val orderManager: OrderManager) : EventListener { + + override fun id(): String { + return "EventListener" + } + + override fun onEvent(coreEvent: CoreEvent, partition: Int, offset: Long, timestamp: Long) { + runBlocking { + when (coreEvent) { + is CreateOrderEvent -> orderManager.handleNewOrder(coreEvent) + is RejectOrderEvent -> orderManager.handleRejectOrder(coreEvent) + is UpdatedOrderEvent -> orderManager.handleUpdateOrder(coreEvent) + is CancelOrderEvent -> orderManager.handleCancelOrder(coreEvent) + else -> { + println("Event is not accepted ${coreEvent::class.java}") + } + } + } + println("onEvent") + } +} \ No newline at end of file diff --git a/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/listener/AccountantTempEventListener.kt b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/listener/AccountantTempEventListener.kt new file mode 100644 index 000000000..c5056fcb7 --- /dev/null +++ b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/listener/AccountantTempEventListener.kt @@ -0,0 +1,34 @@ +package co.nilin.opex.accountant.app.listener + +import co.nilin.opex.accountant.core.api.OrderManager +import co.nilin.opex.accountant.core.api.TradeManager +import co.nilin.opex.accountant.ports.kafka.listener.spi.TempEventListener +import co.nilin.opex.matching.engine.core.eventh.events.* +import kotlinx.coroutines.runBlocking + +class AccountantTempEventListener( + private val orderManager: OrderManager, + private val tradeManager: TradeManager +) : TempEventListener { + + override fun id(): String { + return "TempEventListener" + } + + override fun onEvent(coreEvent: CoreEvent, partition: Int, offset: Long, timestamp: Long) { + println("TempEvent $coreEvent") + runBlocking { + when (coreEvent) { + is CreateOrderEvent -> orderManager.handleNewOrder(coreEvent) + is RejectOrderEvent -> orderManager.handleRejectOrder(coreEvent) + is UpdatedOrderEvent -> orderManager.handleUpdateOrder(coreEvent) + is CancelOrderEvent -> orderManager.handleCancelOrder(coreEvent) + is TradeEvent -> tradeManager.handleTrade(coreEvent) + else -> { + throw IllegalArgumentException("Event is not accepted ${coreEvent::class.java}") + } + } + } + println("onEvent") + } +} \ No newline at end of file diff --git a/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/listener/AccountantTradeListener.kt b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/listener/AccountantTradeListener.kt new file mode 100644 index 000000000..829e6c88d --- /dev/null +++ b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/listener/AccountantTradeListener.kt @@ -0,0 +1,19 @@ +package co.nilin.opex.accountant.app.listener + +import co.nilin.opex.accountant.core.api.TradeManager +import co.nilin.opex.accountant.ports.kafka.listener.spi.TradeListener +import co.nilin.opex.matching.engine.core.eventh.events.TradeEvent +import kotlinx.coroutines.runBlocking + +class AccountantTradeListener(private val tradeManager: TradeManager) : TradeListener { + + override fun id(): String { + return "TradeListener" + } + + override fun onTrade(tradeEvent: TradeEvent, partition: Int, offset: Long, timestamp: Long) { + runBlocking { + tradeManager.handleTrade(tradeEvent) + } + } +} \ No newline at end of file diff --git a/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/listener/OrderListener.kt b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/listener/OrderListener.kt new file mode 100644 index 000000000..16278a928 --- /dev/null +++ b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/listener/OrderListener.kt @@ -0,0 +1,33 @@ +package co.nilin.opex.accountant.app.listener + +import co.nilin.opex.accountant.core.api.OrderManager +import co.nilin.opex.accountant.ports.kafka.listener.inout.OrderSubmitRequest +import co.nilin.opex.accountant.ports.kafka.listener.spi.OrderSubmitRequestListener +import co.nilin.opex.matching.engine.core.eventh.events.SubmitOrderEvent +import kotlinx.coroutines.runBlocking + +class OrderListener(private val orderManager: OrderManager) : OrderSubmitRequestListener { + + override fun id(): String { + return "OrderListener" + } + + override fun onOrder(order: OrderSubmitRequest, partition: Int, offset: Long, timestamp: Long) { + runBlocking { + orderManager.handleRequestOrder( + SubmitOrderEvent( + order.ouid, + order.uuid, + order.orderId, + order.pair, + order.price, + order.quantity, + order.quantity, + order.direction, + order.matchConstraint, + order.orderType + ) + ) + } + } +} \ No newline at end of file diff --git a/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/scheduler/TempEventsJob.kt b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/scheduler/TempEventsJob.kt index 26964877a..67972009d 100644 --- a/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/scheduler/TempEventsJob.kt +++ b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/scheduler/TempEventsJob.kt @@ -11,8 +11,8 @@ import org.springframework.stereotype.Service @Service @Profile("scheduled") class TempEventsJob( - val tempEventPersister: TempEventPersister, - val tempEventRepublisher: TempEventRepublisher, + private val tempEventPersister: TempEventPersister, + private val tempEventRepublisher: TempEventRepublisher, ) { private val log = LoggerFactory.getLogger(TempEventsJob::class.java) diff --git a/accountant/accountant-app/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt new file mode 100644 index 000000000..e9efaf92a --- /dev/null +++ b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt @@ -0,0 +1,9 @@ +package co.nilin.opex.util.vault + +import org.springframework.vault.authentication.AppIdUserIdMechanism + +class VaultUserIdMechanism() : AppIdUserIdMechanism { + override fun createUserId(): String { + return System.getenv("BACKEND_USER") + } +} \ No newline at end of file diff --git a/accountant/accountant-app/src/main/resources/application-docker.yml b/accountant/accountant-app/src/main/resources/application-docker.yml deleted file mode 100644 index 09d0ed7da..000000000 --- a/accountant/accountant-app/src/main/resources/application-docker.yml +++ /dev/null @@ -1,14 +0,0 @@ -spring: - kafka: - bootstrap-servers: ${KAFKA_IP_PORT} - redis: - host: ${REDIS_HOST} - r2dbc: - url: r2dbc:postgresql://${DB_IP_PORT}/opex_accountant - username: opex - password: hiopex - cloud: - consul: - host: ${CONSUL_HOST} - main: - allow-bean-definition-overriding: true \ No newline at end of file diff --git a/accountant/accountant-app/src/main/resources/application.yml b/accountant/accountant-app/src/main/resources/application.yml index eb96dcbd9..0107e6aaa 100644 --- a/accountant/accountant-app/src/main/resources/application.yml +++ b/accountant/accountant-app/src/main/resources/application.yml @@ -1,4 +1,4 @@ -server.port: 8089 +server.port: 8080 logging: level: co.nilin: DEBUG @@ -7,29 +7,46 @@ spring: application: name: opex-accountant main: - allow-bean-definition-overriding: false + allow-bean-definition-overriding: true + allow-circular-references: true kafka: - bootstrap-servers: 192.168.178.29:9092 + bootstrap-servers: ${KAFKA_IP_PORT:localhost:9092} consumer: group-id: accountant redis: - hostname: 127.0.0.1 + hostname: ${REDIS_HOST:localhost} port: 6379 r2dbc: - url: r2dbc:postgresql://localhost/opex_accountant - username: opex - password: hiopex + url: r2dbc:postgresql://${DB_IP_PORT:localhost}/opex_accountant + username: ${dbusername:opex} + password: ${dbpassword:hiopex} initialization-mode: always cloud: bootstrap: enabled: true + vault: + host: ${VAULT_HOST} + port: 8200 + scheme: http + authentication: APPID + app-id: + user-id: co.nilin.opex.util.vault.VaultUserIdMechanism + fail-fast: true + kv: + enabled: true + backend: secret + profile-separator: '/' + application-name: ${spring.application.name} consul: + host: ${CONSUL_HOST:localhost} port: 8500 discovery: #healthCheckPath: ${management.context-path}/health instance-id: ${spring.application.name}:${server.port} healthCheckInterval: 20s prefer-ip-address: true + config: + import: vault://secret/${spring.application.name} app: coin: nln address: 1 diff --git a/accountant/accountant-core/mvnw b/accountant/accountant-core/mvnw deleted file mode 100644 index a16b5431b..000000000 --- a/accountant/accountant-core/mvnw +++ /dev/null @@ -1,310 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` - fi - - if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=`cygpath --path --windows "$javaClass"` - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/accountant/accountant-core/mvnw.cmd b/accountant/accountant-core/mvnw.cmd deleted file mode 100644 index c8d43372c..000000000 --- a/accountant/accountant-core/mvnw.cmd +++ /dev/null @@ -1,182 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/inout/OrderStatus.kt b/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/inout/OrderStatus.kt index b4c0f47dc..3b9fa9b69 100644 --- a/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/inout/OrderStatus.kt +++ b/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/inout/OrderStatus.kt @@ -1,6 +1,6 @@ package co.nilin.opex.accountant.core.inout -enum class OrderStatus(val code: Int, private val orderOfAppearance: Int) { +enum class OrderStatus(val code: Int, val orderOfAppearance: Int) { REQUESTED(0, 0), NEW(1, 1), //The order has been accepted by the engine. diff --git a/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/inout/RichOrder.kt b/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/inout/RichOrder.kt index 569d890ca..85f13c547 100644 --- a/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/inout/RichOrder.kt +++ b/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/inout/RichOrder.kt @@ -5,63 +5,23 @@ import co.nilin.opex.matching.engine.core.model.OrderDirection import co.nilin.opex.matching.engine.core.model.OrderType import java.math.BigDecimal -class RichOrder() { - var orderId: Long? = 0 - lateinit var pair: String - lateinit var ouid: String - lateinit var uuid: String - lateinit var userLevel: String - lateinit var makerFee: BigDecimal - lateinit var takerFee: BigDecimal - lateinit var leftSideFraction: BigDecimal - lateinit var rightSideFraction: BigDecimal - lateinit var direction: OrderDirection - lateinit var constraint: MatchConstraint - lateinit var type: OrderType - lateinit var price: BigDecimal; - lateinit var quantity: BigDecimal; - lateinit var executedQuantity: BigDecimal; - lateinit var accumulativeQuoteQty: BigDecimal; - lateinit var quoteQuantity: BigDecimal; - var status: Int = 0; - - constructor( - orderId: Long?, - pair: String, - ouid: String, - uuid: String, - userLevel: String, - makerFee: BigDecimal, - takerFee: BigDecimal, - leftSideFraction: BigDecimal, - rightSideFraction: BigDecimal, - direction: OrderDirection, - constraint: MatchConstraint, - type: OrderType, - price: BigDecimal, - quantity: BigDecimal, - quoteQuantity: BigDecimal, - executedQuantity: BigDecimal, - accumulativeQuoteQty: BigDecimal, - status: Int - ) : this() { - this.orderId = orderId - this.pair = pair - this.ouid = ouid - this.uuid = uuid - this.userLevel = userLevel - this.makerFee = makerFee - this.takerFee = takerFee - this.leftSideFraction = leftSideFraction - this.rightSideFraction = rightSideFraction - this.direction = direction - this.constraint = constraint - this.type = type - this.price = price - this.quantity = quantity - this.executedQuantity = executedQuantity - this.accumulativeQuoteQty = accumulativeQuoteQty - this.quoteQuantity = quoteQuantity - this.status = status - } -} +data class RichOrder( + val orderId: Long? = 0, + val pair: String, + val ouid: String, + val uuid: String, + val userLevel: String, + val makerFee: BigDecimal, + val takerFee: BigDecimal, + val leftSideFraction: BigDecimal, + val rightSideFraction: BigDecimal, + val direction: OrderDirection, + val constraint: MatchConstraint, + val type: OrderType, + val price: BigDecimal, + val quantity: BigDecimal, + val quoteQuantity: BigDecimal, + val executedQuantity: BigDecimal, + val accumulativeQuoteQty: BigDecimal, + val status: Int = 0 +) : RichOrderEvent diff --git a/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/inout/RichOrderEvent.kt b/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/inout/RichOrderEvent.kt new file mode 100644 index 000000000..62eb04faa --- /dev/null +++ b/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/inout/RichOrderEvent.kt @@ -0,0 +1,3 @@ +package co.nilin.opex.accountant.core.inout + +interface RichOrderEvent \ No newline at end of file diff --git a/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/inout/RichOrderUpdate.kt b/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/inout/RichOrderUpdate.kt new file mode 100644 index 000000000..81f515e26 --- /dev/null +++ b/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/inout/RichOrderUpdate.kt @@ -0,0 +1,17 @@ +package co.nilin.opex.accountant.core.inout + +import java.math.BigDecimal + +data class RichOrderUpdate( + val ouid: String, + val price: BigDecimal, + val quantity: BigDecimal, + val remainedQuantity: BigDecimal, + val status: OrderStatus = OrderStatus.NEW +) : RichOrderEvent { + + fun executedQuantity(): BigDecimal = quantity.minus(remainedQuantity) + + fun accumulativeQuoteQuantity(): BigDecimal = price.multiply((quantity.minus(remainedQuantity))) + +} \ No newline at end of file diff --git a/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/inout/RichTrade.kt b/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/inout/RichTrade.kt index 60626f0a5..069c2cd0a 100644 --- a/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/inout/RichTrade.kt +++ b/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/inout/RichTrade.kt @@ -4,82 +4,29 @@ import co.nilin.opex.matching.engine.core.model.OrderDirection import java.math.BigDecimal import java.time.LocalDateTime -class RichTrade() { - var id: Long = 0 - lateinit var pair: String - lateinit var takerOuid: String - lateinit var takerUuid: String - var takerOrderId: Long = 0 - lateinit var takerDirection: OrderDirection - lateinit var takerPrice: BigDecimal - lateinit var takerQuantity: BigDecimal - lateinit var takerQuoteQuantity: BigDecimal - lateinit var takerRemainedQuantity: BigDecimal - lateinit var takerCommision: BigDecimal - lateinit var takerCommisionAsset: String - lateinit var makerOuid: String - lateinit var makerUuid: String - var makerOrderId: Long = 0 - lateinit var makerDirection: OrderDirection - lateinit var makerPrice: BigDecimal - lateinit var makerQuantity: BigDecimal - lateinit var makerQuoteQuantity: BigDecimal - lateinit var makerRemainedQuantity: BigDecimal - lateinit var matchedQuantity: BigDecimal - lateinit var makerCommision: BigDecimal - lateinit var makerCommisionAsset: String - - lateinit var tradeDateTime: LocalDateTime - - constructor( - id: Long, - pair: String, - takerOuid: String, - takerUuid: String, - takerOrderId: Long, - takerDirection: OrderDirection, - takerPrice: BigDecimal, - takerQuantity: BigDecimal, - takerQuoteQuantity: BigDecimal, - takerRemainedQuantity: BigDecimal, - takerCommision: BigDecimal, - takerCommisionAsset: String, - makerOuid: String, - makerUuid: String, - makerOrderId: Long, - makerDirection: OrderDirection, - makerPrice: BigDecimal, - makerQuantity: BigDecimal, - makerQuoteQuantity: BigDecimal, - makerRemainedQuantity: BigDecimal, - makerCommision: BigDecimal, - makerCommisionAsset: String, - matchedQuantity: BigDecimal, - tradeDateTime: LocalDateTime - ) : this() { - this.id = id - this.pair = pair - this.takerOuid = takerOuid - this.takerUuid = takerUuid - this.takerOrderId = takerOrderId - this.takerDirection = takerDirection - this.takerPrice = takerPrice - this.takerQuantity = takerQuantity - this.takerQuoteQuantity = takerQuoteQuantity - this.takerRemainedQuantity = takerRemainedQuantity - this.takerCommision = takerCommision - this.takerCommisionAsset = takerCommisionAsset - this.makerOuid = makerOuid - this.makerUuid = makerUuid - this.makerOrderId = makerOrderId - this.makerDirection = makerDirection - this.makerPrice = makerPrice - this.makerQuantity = makerQuantity - this.makerQuoteQuantity = makerQuoteQuantity - this.makerRemainedQuantity = makerRemainedQuantity - this.matchedQuantity = matchedQuantity - this.makerCommision = makerCommision - this.makerCommisionAsset = makerCommisionAsset - this.tradeDateTime = tradeDateTime - } -} \ No newline at end of file +class RichTrade( + val id: Long, + val pair: String, + val takerOuid: String, + val takerUuid: String, + val takerOrderId: Long, + val takerDirection: OrderDirection, + val takerPrice: BigDecimal, + val takerQuantity: BigDecimal, + val takerQuoteQuantity: BigDecimal, + val takerRemainedQuantity: BigDecimal, + val takerCommision: BigDecimal, + val takerCommisionAsset: String, + val makerOuid: String, + val makerUuid: String, + val makerOrderId: Long, + val makerDirection: OrderDirection, + val makerPrice: BigDecimal, + val makerQuantity: BigDecimal, + val makerQuoteQuantity: BigDecimal, + val makerRemainedQuantity: BigDecimal, + val makerCommision: BigDecimal, + val makerCommisionAsset: String, + val matchedQuantity: BigDecimal, + val tradeDateTime: LocalDateTime +) \ No newline at end of file diff --git a/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/service/FinancialActionJobManagerImpl.kt b/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/service/FinancialActionJobManagerImpl.kt index b2c9faf6c..7ebcc5ea5 100644 --- a/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/service/FinancialActionJobManagerImpl.kt +++ b/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/service/FinancialActionJobManagerImpl.kt @@ -8,9 +8,9 @@ import co.nilin.opex.accountant.core.spi.WalletProxy import org.slf4j.LoggerFactory class FinancialActionJobManagerImpl( - val financialActionLoader: FinancialActionLoader, - val financialActionPersister: FinancialActionPersister, - val walletProxy: WalletProxy + private val financialActionLoader: FinancialActionLoader, + private val financialActionPersister: FinancialActionPersister, + private val walletProxy: WalletProxy ) : FinancialActionJobManager { private val log = LoggerFactory.getLogger(FinancialActionJobManagerImpl::class.java) diff --git a/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/service/OrderManagerImpl.kt b/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/service/OrderManagerImpl.kt index 30b08dfb3..3527b2a7a 100644 --- a/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/service/OrderManagerImpl.kt +++ b/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/service/OrderManagerImpl.kt @@ -13,13 +13,13 @@ import java.math.BigDecimal import java.time.LocalDateTime open class OrderManagerImpl( - val pairConfigLoader: PairConfigLoader, - val financialActionPersister: FinancialActionPersister, - val financeActionLoader: FinancialActionLoader, - val orderPersister: OrderPersister, - val tempEventPersister: TempEventPersister, - val tempEventRepublisher: TempEventRepublisher, - val richOrderPublisher: RichOrderPublisher + private val pairConfigLoader: PairConfigLoader, + private val financialActionPersister: FinancialActionPersister, + private val financeActionLoader: FinancialActionLoader, + private val orderPersister: OrderPersister, + private val tempEventPersister: TempEventPersister, + private val tempEventRepublisher: TempEventRepublisher, + private val richOrderPublisher: RichOrderPublisher ) : OrderManager { @Transactional @@ -106,9 +106,7 @@ open class OrderManagerImpl( return emptyList() } - private suspend fun publishRichOrder( - order: Order, remainedQuantity: BigDecimal, status: OrderStatus? = null - ) { + private suspend fun publishRichOrder(order: Order, remainedQuantity: BigDecimal, status: OrderStatus? = null) { richOrderPublisher.publish( RichOrder( order.id, diff --git a/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/service/TradeManagerImpl.kt b/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/service/TradeManagerImpl.kt index e407b3adb..9f237d7ca 100644 --- a/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/service/TradeManagerImpl.kt +++ b/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/service/TradeManagerImpl.kt @@ -1,8 +1,11 @@ package co.nilin.opex.accountant.core.service import co.nilin.opex.accountant.core.api.TradeManager +import co.nilin.opex.accountant.core.inout.OrderStatus +import co.nilin.opex.accountant.core.inout.RichOrderUpdate import co.nilin.opex.accountant.core.inout.RichTrade import co.nilin.opex.accountant.core.model.FinancialAction +import co.nilin.opex.accountant.core.model.Order import co.nilin.opex.accountant.core.spi.* import co.nilin.opex.matching.engine.core.eventh.events.TradeEvent import co.nilin.opex.matching.engine.core.model.OrderDirection @@ -12,15 +15,16 @@ import java.math.BigDecimal import java.time.LocalDateTime open class TradeManagerImpl( - val pairStaticRateLoader: PairStaticRateLoader, - val financeActionPersister: FinancialActionPersister, - val financeActionLoader: FinancialActionLoader, - val orderPersister: OrderPersister, - val tempEventPersister: TempEventPersister, - val richTradePublisher: RichTradePublisher, - val walletProxy: WalletProxy, - val platformCoin: String, - val platformAddress: String + private val pairStaticRateLoader: PairStaticRateLoader, + private val financeActionPersister: FinancialActionPersister, + private val financeActionLoader: FinancialActionLoader, + private val orderPersister: OrderPersister, + private val tempEventPersister: TempEventPersister, + private val richTradePublisher: RichTradePublisher, + private val richOrderPublisher: RichOrderPublisher, + private val walletProxy: WalletProxy, + private val platformCoin: String, + private val platformAddress: String ) : TradeManager { private val log = LoggerFactory.getLogger(TradeManagerImpl::class.java) @@ -154,6 +158,7 @@ open class TradeManagerImpl( } orderPersister.save(takerOrder) log.info("taker order saved {}", takerOrder) + publishTakerRichOrderUpdate(takerOrder, trade) //calculate taker fee val takerFee = takerOrder.takerFee @@ -232,6 +237,8 @@ open class TradeManagerImpl( } orderPersister.save(makerOrder) log.info("maker order saved {}", makerOrder) + publishMakerRichOrderUpdate(makerOrder, trade) + richTradePublisher.publish( RichTrade( trade.tradeId, @@ -263,4 +270,25 @@ open class TradeManagerImpl( ) return financeActionPersister.persist(financialActions) } + + private suspend fun publishTakerRichOrderUpdate(takerOrder: Order, trade: TradeEvent) { + val price = trade.takerPrice.toBigDecimal().multiply(takerOrder.rightSideFraction.toBigDecimal()) + val remained = trade.takerRemainedQuantity.toBigDecimal().multiply(takerOrder.leftSideFraction.toBigDecimal()) + publishRichOrderUpdate(takerOrder, price, remained) + } + + private suspend fun publishMakerRichOrderUpdate(makerOrder: Order, trade: TradeEvent) { + val price = trade.makerPrice.toBigDecimal().multiply(makerOrder.rightSideFraction.toBigDecimal()) + val remained = trade.makerRemainedQuantity.toBigDecimal().multiply(makerOrder.leftSideFraction.toBigDecimal()) + publishRichOrderUpdate(makerOrder, price, remained) + } + + private suspend fun publishRichOrderUpdate(order: Order, price: BigDecimal, remainedQty: BigDecimal) { + val status = if (remainedQty.compareTo(BigDecimal.ZERO) == 0) + OrderStatus.FILLED + else + OrderStatus.PARTIALLY_FILLED + + richOrderPublisher.publish(RichOrderUpdate(order.ouid, price, order.origQuantity, remainedQty, status)) + } } \ No newline at end of file diff --git a/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/spi/RichOrderPublisher.kt b/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/spi/RichOrderPublisher.kt index ae6866675..77a0f48c4 100644 --- a/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/spi/RichOrderPublisher.kt +++ b/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/spi/RichOrderPublisher.kt @@ -1,7 +1,7 @@ package co.nilin.opex.accountant.core.spi -import co.nilin.opex.accountant.core.inout.RichOrder +import co.nilin.opex.accountant.core.inout.RichOrderEvent interface RichOrderPublisher { - suspend fun publish(order: RichOrder) + suspend fun publish(order: RichOrderEvent) } \ No newline at end of file diff --git a/accountant/accountant-core/src/test/kotlin/co/nilin/opex/accountant/core/service/TradeManagerImplTest.kt b/accountant/accountant-core/src/test/kotlin/co/nilin/opex/accountant/core/service/TradeManagerImplTest.kt index 4f963d8b3..e9d638ece 100644 --- a/accountant/accountant-core/src/test/kotlin/co/nilin/opex/accountant/core/service/TradeManagerImplTest.kt +++ b/accountant/accountant-core/src/test/kotlin/co/nilin/opex/accountant/core/service/TradeManagerImplTest.kt @@ -75,6 +75,7 @@ internal class TradeManagerImplTest() { orderPersister, tempEventPersister, richTradePublisher, + richOrderPublisher, walletProxy, "pcoin", "0x0" diff --git a/accountant/accountant-ports/accountant-eventlistener-kafka/mvnw b/accountant/accountant-ports/accountant-eventlistener-kafka/mvnw deleted file mode 100644 index a16b5431b..000000000 --- a/accountant/accountant-ports/accountant-eventlistener-kafka/mvnw +++ /dev/null @@ -1,310 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` - fi - - if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=`cygpath --path --windows "$javaClass"` - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/accountant/accountant-ports/accountant-eventlistener-kafka/mvnw.cmd b/accountant/accountant-ports/accountant-eventlistener-kafka/mvnw.cmd deleted file mode 100644 index c8d43372c..000000000 --- a/accountant/accountant-ports/accountant-eventlistener-kafka/mvnw.cmd +++ /dev/null @@ -1,182 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/accountant/accountant-ports/accountant-eventlistener-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/listener/config/AccountantKafkaConfig.kt b/accountant/accountant-ports/accountant-eventlistener-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/listener/config/AccountantKafkaConfig.kt index aa4dffb59..eb89d875a 100644 --- a/accountant/accountant-ports/accountant-eventlistener-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/listener/config/AccountantKafkaConfig.kt +++ b/accountant/accountant-ports/accountant-eventlistener-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/listener/config/AccountantKafkaConfig.kt @@ -1,16 +1,14 @@ package co.nilin.opex.accountant.ports.kafka.listener.config -import co.nilin.opex.matching.engine.core.eventh.events.CoreEvent import co.nilin.opex.accountant.ports.kafka.listener.consumer.EventKafkaListener import co.nilin.opex.accountant.ports.kafka.listener.consumer.OrderKafkaListener import co.nilin.opex.accountant.ports.kafka.listener.consumer.TempEventKafkaListener import co.nilin.opex.accountant.ports.kafka.listener.consumer.TradeKafkaListener +import co.nilin.opex.matching.engine.core.eventh.events.CoreEvent import org.apache.kafka.clients.admin.NewTopic import org.apache.kafka.clients.consumer.ConsumerConfig -import org.apache.kafka.clients.producer.ProducerConfig import org.apache.kafka.common.serialization.StringDeserializer -import org.apache.kafka.common.serialization.StringSerializer import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Qualifier import org.springframework.beans.factory.annotation.Value @@ -18,15 +16,16 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration import org.springframework.context.support.GenericApplicationContext -import org.springframework.kafka.core.* +import org.springframework.kafka.core.ConsumerFactory +import org.springframework.kafka.core.DefaultKafkaConsumerFactory import org.springframework.kafka.listener.ConcurrentMessageListenerContainer import org.springframework.kafka.listener.ContainerProperties import org.springframework.kafka.support.serializer.JsonDeserializer -import org.springframework.kafka.support.serializer.JsonSerializer import java.util.regex.Pattern @Configuration class AccountantKafkaConfig { + @Value("\${spring.kafka.bootstrap-servers}") private val bootstrapServers: String? = null @@ -34,15 +33,15 @@ class AccountantKafkaConfig { private val groupId: String? = null @Bean("accountantConsumerConfig") - fun consumerConfigs(): Map? { - val props: MutableMap = HashMap() - props[ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG] = bootstrapServers - props[ConsumerConfig.GROUP_ID_CONFIG] = groupId - props[ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG] = StringDeserializer::class.java - props[ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG] = JsonDeserializer::class.java - props[JsonDeserializer.TRUSTED_PACKAGES] = "co.nilin.opex.*" - props[JsonDeserializer.TYPE_MAPPINGS] = "order_request:co.nilin.opex.accountant.ports.kafka.listener.inout.OrderSubmitRequest" - return props + fun consumerConfigs(): Map { + return mapOf( + ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG to bootstrapServers, + ConsumerConfig.GROUP_ID_CONFIG to groupId, + ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG to StringDeserializer::class.java, + ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG to JsonDeserializer::class.java, + JsonDeserializer.TRUSTED_PACKAGES to "co.nilin.opex.*", + JsonDeserializer.TYPE_MAPPINGS to "order_request:co.nilin.opex.accountant.ports.kafka.listener.inout.OrderSubmitRequest" + ) } @Bean("accountantConsumerFactory") @@ -50,26 +49,6 @@ class AccountantKafkaConfig { return DefaultKafkaConsumerFactory(consumerConfigs) } - @Bean("accountantProducerConfig") - fun producerConfigs(): Map { - val props: MutableMap = HashMap() - props[ProducerConfig.BOOTSTRAP_SERVERS_CONFIG] = bootstrapServers - props[ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG] = StringSerializer::class.java - props[ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG] = JsonSerializer::class.java - return props - } - - @Bean("accountantProducerFactory") - fun producerFactory(@Qualifier("accountantProducerConfig") producerConfigs: Map): ProducerFactory { - return DefaultKafkaProducerFactory(producerConfigs) - } - - @Bean("accountantKafkaTemplate") - fun kafkaTemplate(@Qualifier("accountantProducerFactory") producerFactory: ProducerFactory): KafkaTemplate { - return KafkaTemplate(producerFactory) - } - - @Autowired @ConditionalOnBean(TradeKafkaListener::class) fun configureTradeListener( diff --git a/accountant/accountant-ports/accountant-eventlistener-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/listener/consumer/EventKafkaListener.kt b/accountant/accountant-ports/accountant-eventlistener-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/listener/consumer/EventKafkaListener.kt index 773a7a0ba..3c8a58bb3 100644 --- a/accountant/accountant-ports/accountant-eventlistener-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/listener/consumer/EventKafkaListener.kt +++ b/accountant/accountant-ports/accountant-eventlistener-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/listener/consumer/EventKafkaListener.kt @@ -1,7 +1,7 @@ package co.nilin.opex.accountant.ports.kafka.listener.consumer -import co.nilin.opex.matching.engine.core.eventh.events.CoreEvent import co.nilin.opex.accountant.ports.kafka.listener.spi.EventListener +import co.nilin.opex.matching.engine.core.eventh.events.CoreEvent import org.apache.kafka.clients.consumer.ConsumerRecord import org.springframework.kafka.listener.MessageListener import org.springframework.stereotype.Component diff --git a/accountant/accountant-ports/accountant-eventlistener-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/listener/consumer/OrderKafkaListener.kt b/accountant/accountant-ports/accountant-eventlistener-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/listener/consumer/OrderKafkaListener.kt index 53a52f16b..fe0ab8f0d 100644 --- a/accountant/accountant-ports/accountant-eventlistener-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/listener/consumer/OrderKafkaListener.kt +++ b/accountant/accountant-ports/accountant-eventlistener-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/listener/consumer/OrderKafkaListener.kt @@ -1,7 +1,7 @@ package co.nilin.opex.accountant.ports.kafka.listener.consumer -import co.nilin.opex.accountant.ports.kafka.listener.spi.OrderSubmitRequestListener import co.nilin.opex.accountant.ports.kafka.listener.inout.OrderSubmitRequest +import co.nilin.opex.accountant.ports.kafka.listener.spi.OrderSubmitRequestListener import org.apache.kafka.clients.consumer.ConsumerRecord import org.springframework.kafka.listener.MessageListener import org.springframework.stereotype.Component diff --git a/accountant/accountant-ports/accountant-eventlistener-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/listener/consumer/TempEventKafkaListener.kt b/accountant/accountant-ports/accountant-eventlistener-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/listener/consumer/TempEventKafkaListener.kt index f9fe310b0..485f99a2b 100644 --- a/accountant/accountant-ports/accountant-eventlistener-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/listener/consumer/TempEventKafkaListener.kt +++ b/accountant/accountant-ports/accountant-eventlistener-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/listener/consumer/TempEventKafkaListener.kt @@ -1,8 +1,8 @@ package co.nilin.opex.accountant.ports.kafka.listener.consumer -import co.nilin.opex.matching.engine.core.eventh.events.CoreEvent import co.nilin.opex.accountant.ports.kafka.listener.spi.TempEventListener +import co.nilin.opex.matching.engine.core.eventh.events.CoreEvent import org.apache.kafka.clients.consumer.ConsumerRecord import org.springframework.kafka.listener.MessageListener import org.springframework.stereotype.Component diff --git a/accountant/accountant-ports/accountant-eventlistener-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/listener/consumer/TradeKafkaListener.kt b/accountant/accountant-ports/accountant-eventlistener-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/listener/consumer/TradeKafkaListener.kt index 70116cebb..4f10f4b17 100644 --- a/accountant/accountant-ports/accountant-eventlistener-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/listener/consumer/TradeKafkaListener.kt +++ b/accountant/accountant-ports/accountant-eventlistener-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/listener/consumer/TradeKafkaListener.kt @@ -1,7 +1,7 @@ package co.nilin.opex.accountant.ports.kafka.listener.consumer -import co.nilin.opex.matching.engine.core.eventh.events.TradeEvent import co.nilin.opex.accountant.ports.kafka.listener.spi.TradeListener +import co.nilin.opex.matching.engine.core.eventh.events.TradeEvent import org.apache.kafka.clients.consumer.ConsumerRecord import org.springframework.kafka.listener.MessageListener import org.springframework.stereotype.Component diff --git a/accountant/accountant-ports/accountant-persister-postgres/mvnw b/accountant/accountant-ports/accountant-persister-postgres/mvnw deleted file mode 100644 index a16b5431b..000000000 --- a/accountant/accountant-ports/accountant-persister-postgres/mvnw +++ /dev/null @@ -1,310 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` - fi - - if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=`cygpath --path --windows "$javaClass"` - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/accountant/accountant-ports/accountant-persister-postgres/mvnw.cmd b/accountant/accountant-ports/accountant-persister-postgres/mvnw.cmd deleted file mode 100644 index c8d43372c..000000000 --- a/accountant/accountant-ports/accountant-persister-postgres/mvnw.cmd +++ /dev/null @@ -1,182 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/dao/PairFeeConfigRepository.kt b/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/dao/PairFeeConfigRepository.kt index 8e964c318..dd1bcf4df 100644 --- a/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/dao/PairFeeConfigRepository.kt +++ b/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/dao/PairFeeConfigRepository.kt @@ -1,7 +1,7 @@ package co.nilin.opex.accountant.ports.postgres.dao -import co.nilin.opex.matching.engine.core.model.OrderDirection import co.nilin.opex.accountant.ports.postgres.model.PairFeeConfigModel +import co.nilin.opex.matching.engine.core.model.OrderDirection import org.springframework.data.r2dbc.repository.Query import org.springframework.data.repository.query.Param import org.springframework.data.repository.reactive.ReactiveCrudRepository diff --git a/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/impl/PairConfigLoaderImpl.kt b/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/impl/PairConfigLoaderImpl.kt index 39366acfd..947d8f898 100644 --- a/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/impl/PairConfigLoaderImpl.kt +++ b/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/impl/PairConfigLoaderImpl.kt @@ -3,10 +3,10 @@ package co.nilin.opex.accountant.ports.postgres.impl import co.nilin.opex.accountant.core.model.PairConfig import co.nilin.opex.accountant.core.model.PairFeeConfig import co.nilin.opex.accountant.core.spi.PairConfigLoader -import co.nilin.opex.matching.engine.core.model.OrderDirection import co.nilin.opex.accountant.ports.postgres.dao.PairConfigRepository import co.nilin.opex.accountant.ports.postgres.dao.PairFeeConfigRepository import co.nilin.opex.accountant.ports.postgres.model.PairFeeConfigModel +import co.nilin.opex.matching.engine.core.model.OrderDirection import co.nilin.opex.utility.error.data.OpexError import co.nilin.opex.utility.error.data.OpexException import kotlinx.coroutines.reactive.awaitFirstOrElse diff --git a/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/impl/TempEventPersisterImpl.kt b/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/impl/TempEventPersisterImpl.kt index 8a43f4a34..2dbd04b47 100644 --- a/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/impl/TempEventPersisterImpl.kt +++ b/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/impl/TempEventPersisterImpl.kt @@ -2,9 +2,9 @@ package co.nilin.opex.accountant.ports.postgres.impl import co.nilin.opex.accountant.core.model.TempEvent import co.nilin.opex.accountant.core.spi.TempEventPersister -import co.nilin.opex.matching.engine.core.eventh.events.CoreEvent import co.nilin.opex.accountant.ports.postgres.dao.TempEventRepository import co.nilin.opex.accountant.ports.postgres.model.TempEventModel +import co.nilin.opex.matching.engine.core.eventh.events.CoreEvent import com.google.gson.Gson import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.toList diff --git a/accountant/accountant-ports/accountant-persister-postgres/src/main/resources/data.sql b/accountant/accountant-ports/accountant-persister-postgres/src/main/resources/data.sql index e40d7515a..d535fcc0c 100644 --- a/accountant/accountant-ports/accountant-persister-postgres/src/main/resources/data.sql +++ b/accountant/accountant-ports/accountant-persister-postgres/src/main/resources/data.sql @@ -1,22 +1,20 @@ -INSERT INTO - pair_config -VALUES - ('btc_usdt', 'btc', 'usdt', 0.000001, 0.01, 55000), - ('eth_usdt', 'eth', 'usdt', 0.00001, 0.01, 3800), - ('nln_usdt', 'nln', 'usdt', 1.0, 0.01, 0.01), - ('nln_btc', 'nln', 'btc', 1.0, 0.000001, 1 / 5500000) ON CONFLICT DO NOTHING; +INSERT INTO pair_config +VALUES ('btc_usdt', 'btc', 'usdt', 0.000001, 0.01, 55000), + ('eth_usdt', 'eth', 'usdt', 0.00001, 0.01, 3800), + ('nln_usdt', 'nln', 'usdt', 1.0, 0.01, 0.01), + ('nln_btc', 'nln', 'btc', 1.0, 0.000001, 1 / 5500000) +ON CONFLICT DO NOTHING; -INSERT INTO - pair_fee_config -VALUES - (1, 'btc_usdt', 'ASK', '*', 0.01, 0.01), - (2, 'btc_usdt', 'BID', '*', 0.01, 0.01), - (3, 'nln_usdt', 'ASK', '*', 0.01, 0.01), - (4, 'nln_usdt', 'BID', '*', 0.01, 0.01), - (5, 'nln_btc', 'ASK', '*', 0.01, 0.01), - (6, 'nln_btc', 'BID', '*', 0.01, 0.01), - (7, 'eth_usdt', 'ASK', '*', 0.01, 0.01), - (8, 'eth_usdt', 'BID', '*', 0.01, 0.01) ON CONFLICT DO NOTHING; +INSERT INTO pair_fee_config +VALUES (1, 'btc_usdt', 'ASK', '*', 0.01, 0.01), + (2, 'btc_usdt', 'BID', '*', 0.01, 0.01), + (3, 'nln_usdt', 'ASK', '*', 0.01, 0.01), + (4, 'nln_usdt', 'BID', '*', 0.01, 0.01), + (5, 'nln_btc', 'ASK', '*', 0.01, 0.01), + (6, 'nln_btc', 'BID', '*', 0.01, 0.01), + (7, 'eth_usdt', 'ASK', '*', 0.01, 0.01), + (8, 'eth_usdt', 'BID', '*', 0.01, 0.01) +ON CONFLICT DO NOTHING; SELECT setval(pg_get_serial_sequence('pair_fee_config', 'id'), (SELECT MAX(id) FROM pair_fee_config)); diff --git a/accountant/accountant-ports/accountant-persister-postgres/src/main/resources/schema.sql b/accountant/accountant-ports/accountant-persister-postgres/src/main/resources/schema.sql index 502bc3cc3..c87930e62 100644 --- a/accountant/accountant-ports/accountant-persister-postgres/src/main/resources/schema.sql +++ b/accountant/accountant-ports/accountant-persister-postgres/src/main/resources/schema.sql @@ -1,79 +1,84 @@ -CREATE TABLE IF NOT EXISTS orders ( - id SERIAL PRIMARY KEY, - ouid VARCHAR(72) NOT NULL UNIQUE, - uuid VARCHAR(72) NOT NULL, - pair VARCHAR(72) NOT NULL, - matching_engine_id INTEGER, - maker_fee DECIMAL NOT NULL, - taker_fee DECIMAL NOT NULL, - left_side_fraction DECIMAL NOT NULL, - right_side_fraction DECIMAL NOT NULL, - user_level VARCHAR(20) NOT NULL, - direction VARCHAR(20) NOT NULL, - match_constraint VARCHAR(30) NOT NULL, - order_type VARCHAR(30) NOT NULL, - price DECIMAL NOT NULL, - quantity DECIMAL NOT NULL, - filled_quantity DECIMAL NOT NULL, - orig_price DECIMAL NOT NULL, - orig_quantity DECIMAL NOT NULL, - filled_orig_quantity DECIMAL NOT NULL, - first_transfer_amount DECIMAL NOT NULL, - remained_transfer_amount DECIMAL NOT NULL, - status INTEGER NOT NULL, - agent VARCHAR(20), - ip VARCHAR(11), - create_date TIMESTAMP NOT NULL +CREATE TABLE IF NOT EXISTS orders +( + id SERIAL PRIMARY KEY, + ouid VARCHAR(72) NOT NULL UNIQUE, + uuid VARCHAR(72) NOT NULL, + pair VARCHAR(72) NOT NULL, + matching_engine_id INTEGER, + maker_fee DECIMAL NOT NULL, + taker_fee DECIMAL NOT NULL, + left_side_fraction DECIMAL NOT NULL, + right_side_fraction DECIMAL NOT NULL, + user_level VARCHAR(20) NOT NULL, + direction VARCHAR(20) NOT NULL, + match_constraint VARCHAR(30) NOT NULL, + order_type VARCHAR(30) NOT NULL, + price DECIMAL NOT NULL, + quantity DECIMAL NOT NULL, + filled_quantity DECIMAL NOT NULL, + orig_price DECIMAL NOT NULL, + orig_quantity DECIMAL NOT NULL, + filled_orig_quantity DECIMAL NOT NULL, + first_transfer_amount DECIMAL NOT NULL, + remained_transfer_amount DECIMAL NOT NULL, + status INTEGER NOT NULL, + agent VARCHAR(20), + ip VARCHAR(11), + create_date TIMESTAMP NOT NULL ); -CREATE TABLE IF NOT EXISTS fi_actions ( - id SERIAL PRIMARY KEY, - parent_id INTEGER, - event_type VARCHAR(72) NOT NULL, - pointer VARCHAR(72) NOT NULL, - symbol VARCHAR(36) NOT NULL, - amount DECIMAL NOT NULL, - sender VARCHAR(36) NOT NULL, - sender_wallet_type VARCHAR(36) NOT NULL, - receiver VARCHAR(36) NOT NULL, - receiver_wallet_type VARCHAR(36) NOT NULL, - agent VARCHAR(20), - ip VARCHAR(11), - create_date TIMESTAMP NOT NULL, - status VARCHAR(20), - retry_count DECIMAL, - last_try_date TIMESTAMP +CREATE TABLE IF NOT EXISTS fi_actions +( + id SERIAL PRIMARY KEY, + parent_id INTEGER, + event_type VARCHAR(72) NOT NULL, + pointer VARCHAR(72) NOT NULL, + symbol VARCHAR(36) NOT NULL, + amount DECIMAL NOT NULL, + sender VARCHAR(36) NOT NULL, + sender_wallet_type VARCHAR(36) NOT NULL, + receiver VARCHAR(36) NOT NULL, + receiver_wallet_type VARCHAR(36) NOT NULL, + agent VARCHAR(20), + ip VARCHAR(11), + create_date TIMESTAMP NOT NULL, + status VARCHAR(20), + retry_count DECIMAL, + last_try_date TIMESTAMP ); -CREATE TABLE IF NOT EXISTS pair_config ( - pair VARCHAR(72) PRIMARY KEY, - left_side_wallet_symbol VARCHAR(36) NOT NULL, - right_side_wallet_symbol VARCHAR(36) NOT NULL, - left_side_fraction DECIMAL NOT NULL, - right_side_fraction DECIMAL NOT NULL, - rate DECIMAL NOT NULL, - UNIQUE( - left_side_wallet_symbol, - right_side_wallet_symbol - ) +CREATE TABLE IF NOT EXISTS pair_config +( + pair VARCHAR(72) PRIMARY KEY, + left_side_wallet_symbol VARCHAR(36) NOT NULL, + right_side_wallet_symbol VARCHAR(36) NOT NULL, + left_side_fraction DECIMAL NOT NULL, + right_side_fraction DECIMAL NOT NULL, + rate DECIMAL NOT NULL, + UNIQUE ( + left_side_wallet_symbol, + right_side_wallet_symbol + ) ); -CREATE TABLE IF NOT EXISTS pair_fee_config ( - id SERIAL PRIMARY KEY, - pair_config_id VARCHAR(72) NOT NULL REFERENCES pair_config (pair), - direction VARCHAR(36) NOT NULL, - user_level VARCHAR(36) NOT NULL, - maker_fee DECIMAL NOT NULL, - taker_fee DECIMAL NOT NULL, - UNIQUE(direction, user_level, pair_config_id) +CREATE TABLE IF NOT EXISTS pair_fee_config +( + id SERIAL PRIMARY KEY, + pair_config_id VARCHAR(72) NOT NULL REFERENCES pair_config (pair), + direction VARCHAR(36) NOT NULL, + user_level VARCHAR(36) NOT NULL, + maker_fee DECIMAL NOT NULL, + taker_fee DECIMAL NOT NULL, + UNIQUE (direction, user_level, pair_config_id) ); -CREATE TABLE IF NOT EXISTS temp_events ( - id SERIAL PRIMARY KEY, - ouid VARCHAR(72) NOT NULL, - event_type VARCHAR(72) NOT NULL, - event_body TEXT NOT NULL, - event_date TIMESTAMP NOT NULL +CREATE TABLE IF NOT EXISTS temp_events +( + id SERIAL PRIMARY KEY, + ouid VARCHAR(72) NOT NULL, + event_type VARCHAR(72) NOT NULL, + event_body TEXT NOT NULL, + event_date TIMESTAMP NOT NULL ); COMMIT; diff --git a/accountant/accountant-ports/accountant-submitter-kafka/mvnw b/accountant/accountant-ports/accountant-submitter-kafka/mvnw deleted file mode 100644 index a16b5431b..000000000 --- a/accountant/accountant-ports/accountant-submitter-kafka/mvnw +++ /dev/null @@ -1,310 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` - fi - - if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=`cygpath --path --windows "$javaClass"` - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/accountant/accountant-ports/accountant-submitter-kafka/mvnw.cmd b/accountant/accountant-ports/accountant-submitter-kafka/mvnw.cmd deleted file mode 100644 index c8d43372c..000000000 --- a/accountant/accountant-ports/accountant-submitter-kafka/mvnw.cmd +++ /dev/null @@ -1,182 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/accountant/accountant-ports/accountant-submitter-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/submitter/config/SubmitterKafkaConfig.kt b/accountant/accountant-ports/accountant-submitter-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/submitter/config/SubmitterKafkaConfig.kt index 27098e88a..f0b2bdfc0 100644 --- a/accountant/accountant-ports/accountant-submitter-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/submitter/config/SubmitterKafkaConfig.kt +++ b/accountant/accountant-ports/accountant-submitter-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/submitter/config/SubmitterKafkaConfig.kt @@ -1,10 +1,11 @@ package co.nilin.opex.accountant.ports.kafka.submitter.config -import co.nilin.opex.accountant.core.inout.RichOrder +import co.nilin.opex.accountant.core.inout.RichOrderEvent import co.nilin.opex.accountant.core.inout.RichTrade import co.nilin.opex.matching.engine.core.eventh.events.CoreEvent import org.apache.kafka.clients.admin.NewTopic import org.apache.kafka.clients.producer.ProducerConfig +import org.apache.kafka.common.config.TopicConfig import org.apache.kafka.common.serialization.StringSerializer import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Qualifier @@ -12,30 +13,28 @@ import org.springframework.beans.factory.annotation.Value import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration import org.springframework.context.support.GenericApplicationContext +import org.springframework.kafka.config.TopicBuilder import org.springframework.kafka.core.DefaultKafkaProducerFactory import org.springframework.kafka.core.KafkaTemplate import org.springframework.kafka.core.ProducerFactory import org.springframework.kafka.support.serializer.JsonSerializer +import java.util.function.Supplier @Configuration -class SubmitterKafkaConfig() { +class SubmitterKafkaConfig { + @Value("\${spring.kafka.bootstrap-servers}") private lateinit var bootstrapServers: String - @Value("\${spring.kafka.consumer.group-id}") - private val groupId: String? = null - - @Autowired - private val applicationContext: GenericApplicationContext? = null - - @Bean("accountantProducerConfigs") - fun producerConfigs(): Map? { - val props: MutableMap = HashMap() - props[ProducerConfig.BOOTSTRAP_SERVERS_CONFIG] = bootstrapServers - props[ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG] = StringSerializer::class.java - props[ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG] = JsonSerializer::class.java - return props + fun producerConfigs(): Map { + return mapOf( + ProducerConfig.BOOTSTRAP_SERVERS_CONFIG to bootstrapServers, + ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG to StringSerializer::class.java, + ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG to JsonSerializer::class.java, + ProducerConfig.ACKS_CONFIG to "all", + //ProducerConfig.CLIENT_ID_CONFIG to "", omitting this option as it produces InstanceAlreadyExistsException + ) } @Bean("accountantEventProducerFactory") @@ -59,18 +58,31 @@ class SubmitterKafkaConfig() { } @Bean("richOrderProducerFactory") - fun richOrderProducerFactory(@Qualifier("accountantProducerConfigs") producerConfigs: Map): ProducerFactory { + fun richOrderProducerFactory(@Qualifier("accountantProducerConfigs") producerConfigs: Map): ProducerFactory { return DefaultKafkaProducerFactory(producerConfigs) } @Bean("richOrderKafkaTemplate") - fun richOrderKafkaTemplate(@Qualifier("richOrderProducerFactory") producerFactory: ProducerFactory): KafkaTemplate { + fun richOrderKafkaTemplate(@Qualifier("richOrderProducerFactory") producerFactory: ProducerFactory): KafkaTemplate { return KafkaTemplate(producerFactory) } @Autowired fun createTopics(applicationContext: GenericApplicationContext) { - applicationContext.registerBean("topic_richOrder", NewTopic::class.java, "richOrder", 10, 1) - applicationContext.registerBean("topic_richTrade", NewTopic::class.java, "richTrade", 10, 1) + applicationContext.registerBean("topic_richOrder", NewTopic::class.java, Supplier { + TopicBuilder.name("richOrder") + .partitions(10) + .replicas(3) + .config(TopicConfig.MIN_IN_SYNC_REPLICAS_CONFIG, "2") + .build() + }) + + applicationContext.registerBean("topic_richTrade", NewTopic::class.java, Supplier { + TopicBuilder.name("richTrade") + .partitions(10) + .replicas(3) + .config(TopicConfig.MIN_IN_SYNC_REPLICAS_CONFIG, "2") + .build() + }) } } \ No newline at end of file diff --git a/accountant/accountant-ports/accountant-submitter-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/submitter/service/RichOrderSubmitter.kt b/accountant/accountant-ports/accountant-submitter-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/submitter/service/RichOrderSubmitter.kt index a06b7b0a5..b8893c862 100644 --- a/accountant/accountant-ports/accountant-submitter-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/submitter/service/RichOrderSubmitter.kt +++ b/accountant/accountant-ports/accountant-submitter-kafka/src/main/kotlin/co/nilin/opex/accountant/ports/kafka/submitter/service/RichOrderSubmitter.kt @@ -1,6 +1,6 @@ package co.nilin.opex.accountant.ports.kafka.submitter.service -import co.nilin.opex.accountant.core.inout.RichOrder +import co.nilin.opex.accountant.core.inout.RichOrderEvent import co.nilin.opex.accountant.core.spi.RichOrderPublisher import org.springframework.beans.factory.annotation.Qualifier import org.springframework.kafka.core.KafkaTemplate @@ -10,9 +10,10 @@ import kotlin.coroutines.resumeWithException import kotlin.coroutines.suspendCoroutine @Component -class RichOrderSubmitter(@Qualifier("richOrderKafkaTemplate") val kafkaTemplate: KafkaTemplate) : +class RichOrderSubmitter(@Qualifier("richOrderKafkaTemplate") val kafkaTemplate: KafkaTemplate) : RichOrderPublisher { - override suspend fun publish(order: RichOrder): Unit = suspendCoroutine { cont -> + + override suspend fun publish(order: RichOrderEvent): Unit = suspendCoroutine { cont -> println("richOrderSubmit!") val sendFuture = kafkaTemplate.send("richOrder", order) sendFuture.addCallback({ sendResult -> diff --git a/accountant/accountant-ports/accountant-wallet-proxy/mvnw b/accountant/accountant-ports/accountant-wallet-proxy/mvnw deleted file mode 100644 index a16b5431b..000000000 --- a/accountant/accountant-ports/accountant-wallet-proxy/mvnw +++ /dev/null @@ -1,310 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` - fi - - if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=`cygpath --path --windows "$javaClass"` - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/accountant/accountant-ports/accountant-wallet-proxy/mvnw.cmd b/accountant/accountant-ports/accountant-wallet-proxy/mvnw.cmd deleted file mode 100644 index c8d43372c..000000000 --- a/accountant/accountant-ports/accountant-wallet-proxy/mvnw.cmd +++ /dev/null @@ -1,182 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/accountant/accountant-ports/accountant-wallet-proxy/pom.xml b/accountant/accountant-ports/accountant-wallet-proxy/pom.xml index 14c9cf7ea..b6018c730 100644 --- a/accountant/accountant-ports/accountant-wallet-proxy/pom.xml +++ b/accountant/accountant-ports/accountant-wallet-proxy/pom.xml @@ -15,10 +15,6 @@ accountant-wallet-proxy Opex wallet proxy - - 2020.0.2 - - org.jetbrains.kotlin @@ -88,16 +84,4 @@ https://repo.spring.io/milestone - - - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - diff --git a/accountant/pom.xml b/accountant/pom.xml index 7714383c5..c60d9c6c1 100644 --- a/accountant/pom.xml +++ b/accountant/pom.xml @@ -73,6 +73,13 @@ logging-handler ${project.version} + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + diff --git a/admin/admin-app/.gitignore b/admin/admin-app/.gitignore new file mode 100644 index 000000000..549e00a2a --- /dev/null +++ b/admin/admin-app/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/admin/admin-app/Dockerfile b/admin/admin-app/Dockerfile new file mode 100644 index 000000000..6916b628a --- /dev/null +++ b/admin/admin-app/Dockerfile @@ -0,0 +1,5 @@ +FROM openjdk:11 +VOLUME /tmp +ARG JAR_FILE=target/*.jar +COPY ${JAR_FILE} app.jar +ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -jar /app.jar"] \ No newline at end of file diff --git a/admin/admin-app/pom.xml b/admin/admin-app/pom.xml new file mode 100644 index 000000000..8be7250ad --- /dev/null +++ b/admin/admin-app/pom.xml @@ -0,0 +1,107 @@ + + + + 4.0.0 + + + co.nilin.opex.admin + admin + 1.0-SNAPSHOT + + + co.nilin.opex.admin.gateway + admin-app + admin-app + Opex admin app module + + + + org.springframework.boot + spring-boot-starter-webflux + + + org.springframework.cloud + spring-cloud-starter-consul-all + + + org.springframework.boot + spring-boot-starter-actuator + + + org.jetbrains.kotlin + kotlin-reflect + + + io.projectreactor.kotlin + reactor-kotlin-extensions + + + org.jetbrains.kotlinx + kotlinx-coroutines-reactor + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-oauth2-resource-server + + + org.jetbrains.kotlinx + kotlinx-coroutines-core + + + com.fasterxml.jackson.module + jackson-module-kotlin + + + co.nilin.opex.admin + admin-core + + + co.nilin.opex.admin + admin-service-auth + + + co.nilin.opex.utility.error + error-handler + + + co.nilin.opex.utility.log + logging-handler + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/AdminApplication.kt b/admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/AdminApplication.kt new file mode 100644 index 000000000..0ca671f2e --- /dev/null +++ b/admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/AdminApplication.kt @@ -0,0 +1,15 @@ +package co.nilin.opex.admin.app + +import co.nilin.opex.utility.error.EnableOpexErrorHandler +import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.runApplication +import org.springframework.context.annotation.ComponentScan + +@SpringBootApplication +@ComponentScan("co.nilin.opex") +@EnableOpexErrorHandler +class AdminApplication + +fun main(args: Array) { + runApplication(*args) +} diff --git a/admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/config/SecurityConfig.kt b/admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/config/SecurityConfig.kt new file mode 100644 index 000000000..3f7785757 --- /dev/null +++ b/admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/config/SecurityConfig.kt @@ -0,0 +1,38 @@ +package co.nilin.opex.admin.app.config + +import co.nilin.opex.admin.app.utils.hasRealmRole +import org.springframework.beans.factory.annotation.Value +import org.springframework.context.annotation.Bean +import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity +import org.springframework.security.config.web.server.ServerHttpSecurity +import org.springframework.security.oauth2.jwt.NimbusReactiveJwtDecoder +import org.springframework.security.oauth2.jwt.ReactiveJwtDecoder +import org.springframework.security.web.server.SecurityWebFilterChain +import org.springframework.web.reactive.function.client.WebClient + +@EnableWebFluxSecurity +class SecurityConfig(private val webClient: WebClient) { + + @Value("\${app.auth.cert-url}") + private lateinit var jwkUrl: String + + @Bean + fun springSecurityFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain? { + http.csrf().disable() + .authorizeExchange() + .pathMatchers("/auth/**").hasRealmRole("SCOPE_trust", "finance-admin") + .anyExchange().authenticated() + .and() + .oauth2ResourceServer() + .jwt() + return http.build() + } + + @Bean + @Throws(Exception::class) + fun reactiveJwtDecoder(): ReactiveJwtDecoder? { + return NimbusReactiveJwtDecoder.withJwkSetUri(jwkUrl) + .webClient(webClient) + .build() + } +} diff --git a/admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/config/WebClientConfig.kt b/admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/config/WebClientConfig.kt new file mode 100644 index 000000000..c36afd50f --- /dev/null +++ b/admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/config/WebClientConfig.kt @@ -0,0 +1,20 @@ +package co.nilin.opex.admin.app.config + +import org.springframework.cloud.client.ServiceInstance +import org.springframework.cloud.client.loadbalancer.reactive.ReactiveLoadBalancer +import org.springframework.cloud.client.loadbalancer.reactive.ReactorLoadBalancerExchangeFilterFunction +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.web.reactive.function.client.WebClient + +@Configuration +class WebClientConfig { + + @Bean + fun webClient(loadBalancerFactory: ReactiveLoadBalancer.Factory): WebClient { + return WebClient.builder() + .filter(ReactorLoadBalancerExchangeFilterFunction(loadBalancerFactory, emptyList())) + .build() + } + +} diff --git a/admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/utils/Extensions.kt b/admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/utils/Extensions.kt new file mode 100644 index 000000000..824c3f3c8 --- /dev/null +++ b/admin/admin-app/src/main/kotlin/co/nilin/opex/admin/app/utils/Extensions.kt @@ -0,0 +1,20 @@ +package co.nilin.opex.admin.app.utils + +import com.nimbusds.jose.shaded.json.JSONArray +import com.nimbusds.jose.shaded.json.JSONObject +import org.springframework.security.authorization.AuthorizationDecision +import org.springframework.security.config.web.server.ServerHttpSecurity +import org.springframework.security.oauth2.jwt.Jwt + +fun ServerHttpSecurity.AuthorizeExchangeSpec.Access.hasRealmRole( + authority: String, + role: String +): ServerHttpSecurity.AuthorizeExchangeSpec = access { mono, _ -> + mono.map { auth -> + auth.authorities.any { it.authority == authority } + && (((auth.principal as Jwt).claims["realm_access"] as JSONObject?)?.get("roles") as JSONArray?) + ?.contains(role) == true + }.map { granted -> + AuthorizationDecision(granted) + } +} \ No newline at end of file diff --git a/matching-gateway/matching-gateway-app/src/main/resources/application-docker.yml b/admin/admin-app/src/main/resources/application.yml similarity index 57% rename from matching-gateway/matching-gateway-app/src/main/resources/application-docker.yml rename to admin/admin-app/src/main/resources/application.yml index 2d59b2e9c..f47cab0d4 100644 --- a/matching-gateway/matching-gateway-app/src/main/resources/application-docker.yml +++ b/admin/admin-app/src/main/resources/application.yml @@ -1,18 +1,15 @@ -server.port: 8093 +server: + port: 8080 spring: application: - name: opex-gateway + name: opex-admin main: - allow-bean-definition-overriding: false - kafka: - bootstrap-servers: ${KAFKA_IP_PORT} - consumer: - group-id: gateway + allow-bean-definition-overriding: true cloud: bootstrap: enabled: true consul: - host: ${CONSUL_HOST} + host: ${CONSUL_HOST:localhost} port: 8500 discovery: #healthCheckPath: ${management.context-path}/health @@ -20,7 +17,10 @@ spring: healthCheckInterval: 20s prefer-ip-address: true app: - accountant: - url: lb://opex-accountant auth: - cert-url: lb://opex-auth/auth/realms/opex/protocol/openid-connect/certs \ No newline at end of file + cert-url: lb://opex-auth/auth/realms/opex/protocol/openid-connect/certs + keycloak: + url: http://auth:8080/auth + realm: opex + client-id: opex-admin + client-secret: ${KEYCLOAK_CLIENT_SECRET:secret} \ No newline at end of file diff --git a/admin/admin-core/.gitignore b/admin/admin-core/.gitignore new file mode 100644 index 000000000..549e00a2a --- /dev/null +++ b/admin/admin-core/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/admin/admin-core/pom.xml b/admin/admin-core/pom.xml new file mode 100644 index 000000000..cb4af1256 --- /dev/null +++ b/admin/admin-core/pom.xml @@ -0,0 +1,39 @@ + + + 4.0.0 + + + co.nilin.opex.admin + admin + 1.0-SNAPSHOT + + + admin-core + admin-core + Admin core module + + + + org.jetbrains.kotlin + kotlin-reflect + + + org.springframework.boot + spring-boot-starter + + + io.projectreactor.kotlin + reactor-kotlin-extensions + + + org.jetbrains.kotlinx + kotlinx-coroutines-reactor + + + org.jetbrains.kotlinx + kotlinx-coroutines-core + + + + diff --git a/admin/admin-core/src/main/kotlin/co/nilin/opex/admin/core/AdminCoreApplication.kt b/admin/admin-core/src/main/kotlin/co/nilin/opex/admin/core/AdminCoreApplication.kt new file mode 100644 index 000000000..f84b92478 --- /dev/null +++ b/admin/admin-core/src/main/kotlin/co/nilin/opex/admin/core/AdminCoreApplication.kt @@ -0,0 +1,11 @@ +package co.nilin.opex.admin.core + +import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.runApplication + +@SpringBootApplication +class AdminCoreApplication + +fun main(args: Array) { + runApplication(*args) +} diff --git a/admin/admin-ports/admin-service-auth/.gitignore b/admin/admin-ports/admin-service-auth/.gitignore new file mode 100644 index 000000000..549e00a2a --- /dev/null +++ b/admin/admin-ports/admin-service-auth/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/admin/admin-ports/admin-service-auth/pom.xml b/admin/admin-ports/admin-service-auth/pom.xml new file mode 100644 index 000000000..4d9db2128 --- /dev/null +++ b/admin/admin-ports/admin-service-auth/pom.xml @@ -0,0 +1,61 @@ + + + 4.0.0 + + + co.nilin.opex.admin + admin + 1.0-SNAPSHOT + ../../pom.xml + + + admin-service-auth + admin-service-auth + Manage admin operation for auth service + + + 12.0.4 + + + + + org.keycloak + keycloak-admin-client + ${keycloak.version} + + + co.nilin.opex.admin + admin-core + + + co.nilin.opex.utility.error + error-handler + + + org.jetbrains.kotlin + kotlin-reflect + + + io.projectreactor.kotlin + reactor-kotlin-extensions + + + org.jetbrains.kotlinx + kotlinx-coroutines-reactor + + + org.jetbrains.kotlinx + kotlinx-coroutines-core + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + + + diff --git a/admin/admin-ports/admin-service-auth/src/main/kotlin/co/nilin/opex/admin/ports/auth/config/KeycloakAdminConfig.kt b/admin/admin-ports/admin-service-auth/src/main/kotlin/co/nilin/opex/admin/ports/auth/config/KeycloakAdminConfig.kt new file mode 100644 index 000000000..6d363d60f --- /dev/null +++ b/admin/admin-ports/admin-service-auth/src/main/kotlin/co/nilin/opex/admin/ports/auth/config/KeycloakAdminConfig.kt @@ -0,0 +1,42 @@ +package co.nilin.opex.admin.ports.auth.config + +import org.keycloak.OAuth2Constants +import org.keycloak.admin.client.Keycloak +import org.keycloak.admin.client.KeycloakBuilder +import org.keycloak.admin.client.resource.RealmResource +import org.springframework.beans.factory.annotation.Value +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +@Configuration +class KeycloakAdminConfig { + + @Value("\${app.auth.keycloak.url}") + private lateinit var url: String + + @Value("\${app.auth.keycloak.realm}") + private lateinit var realm: String + + @Value("\${app.auth.keycloak.client-id}") + private lateinit var clientId: String + + @Value("\${app.auth.keycloak.client-secret}") + private lateinit var clientSecret: String + + @Bean + fun keycloak(): Keycloak { + return KeycloakBuilder.builder() + .grantType(OAuth2Constants.CLIENT_CREDENTIALS) + .serverUrl(url) + .realm(realm) + .clientId(clientId) + .clientSecret(clientSecret) + .build() + } + + @Bean + fun opexRealm(keycloak: Keycloak): RealmResource { + return keycloak.realm(realm) + } + +} \ No newline at end of file diff --git a/admin/admin-ports/admin-service-auth/src/main/kotlin/co/nilin/opex/admin/ports/auth/controller/AuthAdminController.kt b/admin/admin-ports/admin-service-auth/src/main/kotlin/co/nilin/opex/admin/ports/auth/controller/AuthAdminController.kt new file mode 100644 index 000000000..0cd8e399b --- /dev/null +++ b/admin/admin-ports/admin-service-auth/src/main/kotlin/co/nilin/opex/admin/ports/auth/controller/AuthAdminController.kt @@ -0,0 +1,38 @@ +package co.nilin.opex.admin.ports.auth.controller + +import co.nilin.opex.admin.ports.auth.data.KeycloakUser +import co.nilin.opex.admin.ports.auth.data.KycGroup +import co.nilin.opex.admin.ports.auth.service.AuthAdminService +import co.nilin.opex.admin.ports.auth.utils.asKeycloakUser +import org.springframework.web.bind.annotation.* + +@RestController +@RequestMapping("/auth/v1") +class AuthAdminController(private val service: AuthAdminService) { + + @GetMapping("/user") + suspend fun getAllKeycloakUsers(): List { + return service.findAllUsers().map { it.asKeycloakUser() } + } + + @PostMapping("/user/{userId}/join-kyc") + fun switchKYCGroup(@PathVariable userId: String, @RequestParam kycGroup: KycGroup) { + service.switchKYCGroup(userId, kycGroup) + } + + @PostMapping("/user/{userId}/kyc/accept") + fun acceptKYC(@PathVariable userId: String) { + service.switchKYCGroup(userId, KycGroup.ACCEPTED) + } + + @PostMapping("/user/{userId}/kyc/reject") + fun rejectKYC(@PathVariable userId: String) { + service.switchKYCGroup(userId, KycGroup.REJECTED) + } + + @GetMapping("/group/{groupName}/members") + fun getMembersOfGroup(@PathVariable groupName: String): List { + return service.findUsersInGroupByName(groupName).map { it.asKeycloakUser() } + } + +} \ No newline at end of file diff --git a/admin/admin-ports/admin-service-auth/src/main/kotlin/co/nilin/opex/admin/ports/auth/data/KeycloakUser.kt b/admin/admin-ports/admin-service-auth/src/main/kotlin/co/nilin/opex/admin/ports/auth/data/KeycloakUser.kt new file mode 100644 index 000000000..88a9d0983 --- /dev/null +++ b/admin/admin-ports/admin-service-auth/src/main/kotlin/co/nilin/opex/admin/ports/auth/data/KeycloakUser.kt @@ -0,0 +1,17 @@ +package co.nilin.opex.admin.ports.auth.data + +import com.fasterxml.jackson.annotation.JsonInclude + +@JsonInclude(JsonInclude.Include.NON_NULL) +data class KeycloakUser( + val id: String, + val email: String, + val username: String, + val firstName: String?, + val lastName: String?, + val isEnabled: Boolean, + val isEmailVerified: Boolean, + val groups:List?, + val requiredActions: List?, + val attributes: Map>? +) \ No newline at end of file diff --git a/admin/admin-ports/admin-service-auth/src/main/kotlin/co/nilin/opex/admin/ports/auth/data/KycGroup.kt b/admin/admin-ports/admin-service-auth/src/main/kotlin/co/nilin/opex/admin/ports/auth/data/KycGroup.kt new file mode 100644 index 000000000..b6c1d27ba --- /dev/null +++ b/admin/admin-ports/admin-service-auth/src/main/kotlin/co/nilin/opex/admin/ports/auth/data/KycGroup.kt @@ -0,0 +1,9 @@ +package co.nilin.opex.admin.ports.auth.data + +enum class KycGroup(val groupName: String) { + + REQUESTED("kyc-requested"), + ACCEPTED("kyc-accepted"), + REJECTED("kyc-rejected") + +} \ No newline at end of file diff --git a/admin/admin-ports/admin-service-auth/src/main/kotlin/co/nilin/opex/admin/ports/auth/service/AuthAdminService.kt b/admin/admin-ports/admin-service-auth/src/main/kotlin/co/nilin/opex/admin/ports/auth/service/AuthAdminService.kt new file mode 100644 index 000000000..26411d709 --- /dev/null +++ b/admin/admin-ports/admin-service-auth/src/main/kotlin/co/nilin/opex/admin/ports/auth/service/AuthAdminService.kt @@ -0,0 +1,61 @@ +package co.nilin.opex.admin.ports.auth.service + +import co.nilin.opex.admin.ports.auth.data.KycGroup +import co.nilin.opex.utility.error.data.OpexError +import co.nilin.opex.utility.error.data.OpexException +import org.keycloak.admin.client.Keycloak +import org.keycloak.admin.client.resource.GroupResource +import org.keycloak.admin.client.resource.RealmResource +import org.keycloak.representations.idm.UserRepresentation +import org.springframework.stereotype.Service + +@Service +class AuthAdminService(private val keycloak: Keycloak, private val opexRealm: RealmResource) { + + fun findAllUsers(): List { + return opexRealm.users().list() + } + + fun findGroupById(groupId: String): GroupResource { + return opexRealm.groups().group(groupId) ?: throw OpexException(OpexError.NotFound, "Group not found") + } + + fun findGroupByName(groupName: String): GroupResource { + val groupRep = opexRealm.groups() + .groups() + .find { it.name == groupName } + ?: throw OpexException(OpexError.NotFound, "Group not found") + + return opexRealm.groups().group(groupRep.id) + } + + fun findUsersInGroupById(groupId: String): List { + val group = findGroupById(groupId) + return group.members() + } + + fun findUsersInGroupByName(groupName: String): List { + val group = findGroupByName(groupName) + return group.members() + } + + fun addUserToGroup(userId: String, groupId: String) { + val user = opexRealm.users().get(userId) ?: throw OpexException(OpexError.NotFound, "User not found") + user.joinGroup(groupId) + } + + fun removeUserFromGroup(userId: String, groupId: String) { + val user = opexRealm.users().get(userId) ?: throw OpexException(OpexError.NotFound, "User not found") + user.leaveGroup(groupId) + } + + fun switchKYCGroup(userId: String, kycGroup: KycGroup) { + val group = findGroupByName(kycGroup.groupName) + val user = opexRealm.users().get(userId) ?: throw OpexException(OpexError.NotFound, "User not found") + with(user) { + groups().forEach { leaveGroup(it.id) } + joinGroup(group.toRepresentation().id) + } + } + +} \ No newline at end of file diff --git a/admin/admin-ports/admin-service-auth/src/main/kotlin/co/nilin/opex/admin/ports/auth/utils/Extensions.kt b/admin/admin-ports/admin-service-auth/src/main/kotlin/co/nilin/opex/admin/ports/auth/utils/Extensions.kt new file mode 100644 index 000000000..16f548eef --- /dev/null +++ b/admin/admin-ports/admin-service-auth/src/main/kotlin/co/nilin/opex/admin/ports/auth/utils/Extensions.kt @@ -0,0 +1,17 @@ +package co.nilin.opex.admin.ports.auth.utils + +import co.nilin.opex.admin.ports.auth.data.KeycloakUser +import org.keycloak.representations.idm.UserRepresentation + +fun UserRepresentation.asKeycloakUser(): KeycloakUser = KeycloakUser( + id, + email, + username, + firstName, + lastName, + isEnabled, + isEmailVerified, + groups, + requiredActions, + attributes +) \ No newline at end of file diff --git a/admin/pom.xml b/admin/pom.xml new file mode 100644 index 000000000..82bc9acd7 --- /dev/null +++ b/admin/pom.xml @@ -0,0 +1,56 @@ + + + 4.0.0 + + + OPEX-Core + co.nilin.opex + 1.0-SNAPSHOT + + + co.nilin.opex.admin + admin + admin + pom + Admin root of Opex + + + admin-app + admin-core + admin-ports/admin-service-auth + + + + + org.springframework.boot + spring-boot-starter-test + + + + + + + co.nilin.opex.admin + admin-service-auth + ${project.version} + + + co.nilin.opex.admin + admin-core + ${project.version} + + + co.nilin.opex.utility.error + error-handler + ${project.version} + + + co.nilin.opex.utility.log + logging-handler + ${project.version} + + + + + diff --git a/api/api-app/Dockerfile b/api/api-app/Dockerfile index f2cbd4c26..7c71f9447 100644 --- a/api/api-app/Dockerfile +++ b/api/api-app/Dockerfile @@ -1,5 +1,4 @@ -FROM openjdk:8-jdk-alpine -VOLUME /tmp +FROM openjdk:11 ARG JAR_FILE=target/*.jar COPY ${JAR_FILE} app.jar ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -jar /app.jar"] \ No newline at end of file diff --git a/api/api-app/pom.xml b/api/api-app/pom.xml index e60b9784b..00529ca01 100644 --- a/api/api-app/pom.xml +++ b/api/api-app/pom.xml @@ -64,6 +64,10 @@ springfox-boot-starter 3.0.0 + + org.springframework.cloud + spring-cloud-starter-vault-config + diff --git a/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/AppConfig.kt b/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/AppConfig.kt index f54a029b0..f24c6dfe5 100644 --- a/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/AppConfig.kt +++ b/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/AppConfig.kt @@ -1,14 +1,10 @@ package co.nilin.opex.api.app.config -import co.nilin.opex.accountant.core.inout.RichOrder -import co.nilin.opex.accountant.core.inout.RichTrade +import co.nilin.opex.api.app.listener.ApiListenerImpl import co.nilin.opex.api.core.spi.OrderPersister import co.nilin.opex.api.core.spi.TradePersister import co.nilin.opex.api.ports.kafka.listener.consumer.OrderKafkaListener import co.nilin.opex.api.ports.kafka.listener.consumer.TradeKafkaListener -import co.nilin.opex.api.ports.kafka.listener.spi.RichOrderListener -import co.nilin.opex.api.ports.kafka.listener.spi.RichTradeListener -import kotlinx.coroutines.runBlocking import org.springframework.beans.factory.annotation.Autowired import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration @@ -17,10 +13,7 @@ import org.springframework.context.annotation.Configuration class AppConfig { @Bean - fun apiListener( - richOrderPersister: OrderPersister, - richTradePersister: TradePersister - ): ApiListenerImpl { + fun apiListener(richOrderPersister: OrderPersister, richTradePersister: TradePersister): ApiListenerImpl { return ApiListenerImpl(richOrderPersister, richTradePersister) } @@ -34,38 +27,4 @@ class AppConfig { tradeKafkaListener.addTradeListener(appListener) } - class ApiListenerImpl( - val richOrderPersister: OrderPersister, - val richTradePersister: TradePersister - ) : RichTradeListener, RichOrderListener { - - override fun id(): String { - return "AppListener" - } - - override fun onTrade( - trade: RichTrade, - partition: Int, - offset: Long, - timestamp: Long - ) { - println("RichTrade received") - runBlocking(AppDispatchers.kafkaExecutor) { - richTradePersister.save(trade) - } - } - - override fun onOrder( - order: RichOrder, - partition: Int, - offset: Long, - timestamp: Long - ) { - runBlocking(AppDispatchers.kafkaExecutor) { - richOrderPersister.save(order) - } - } - } - - } \ No newline at end of file diff --git a/api/api-app/src/main/kotlin/co/nilin/opex/api/app/listener/ApiListenerImpl.kt b/api/api-app/src/main/kotlin/co/nilin/opex/api/app/listener/ApiListenerImpl.kt new file mode 100644 index 000000000..231209348 --- /dev/null +++ b/api/api-app/src/main/kotlin/co/nilin/opex/api/app/listener/ApiListenerImpl.kt @@ -0,0 +1,38 @@ +package co.nilin.opex.api.app.listener + +import co.nilin.opex.accountant.core.inout.RichOrder +import co.nilin.opex.accountant.core.inout.RichOrderEvent +import co.nilin.opex.accountant.core.inout.RichOrderUpdate +import co.nilin.opex.accountant.core.inout.RichTrade +import co.nilin.opex.api.app.config.AppDispatchers +import co.nilin.opex.api.core.spi.OrderPersister +import co.nilin.opex.api.core.spi.TradePersister +import co.nilin.opex.api.ports.kafka.listener.spi.RichOrderListener +import co.nilin.opex.api.ports.kafka.listener.spi.RichTradeListener +import kotlinx.coroutines.runBlocking + +class ApiListenerImpl( + private val richOrderPersister: OrderPersister, + private val richTradePersister: TradePersister +) : RichTradeListener, RichOrderListener { + + override fun id(): String { + return "AppListener" + } + + override fun onTrade(trade: RichTrade, partition: Int, offset: Long, timestamp: Long) { + println("RichTrade received") + runBlocking(AppDispatchers.kafkaExecutor) { + richTradePersister.save(trade) + } + } + + override fun onOrder(order: RichOrderEvent, partition: Int, offset: Long, timestamp: Long) { + runBlocking(AppDispatchers.kafkaExecutor) { + when (order) { + is RichOrder -> richOrderPersister.save(order) + is RichOrderUpdate -> richOrderPersister.update(order) + } + } + } +} \ No newline at end of file diff --git a/api/api-app/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt b/api/api-app/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt new file mode 100644 index 000000000..e9efaf92a --- /dev/null +++ b/api/api-app/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt @@ -0,0 +1,9 @@ +package co.nilin.opex.util.vault + +import org.springframework.vault.authentication.AppIdUserIdMechanism + +class VaultUserIdMechanism() : AppIdUserIdMechanism { + override fun createUserId(): String { + return System.getenv("BACKEND_USER") + } +} \ No newline at end of file diff --git a/api/api-app/src/main/resources/application-docker.yml b/api/api-app/src/main/resources/application-docker.yml deleted file mode 100644 index f44d7c4f5..000000000 --- a/api/api-app/src/main/resources/application-docker.yml +++ /dev/null @@ -1,27 +0,0 @@ -spring: - kafka: - bootstrap-servers: ${KAFKA_IP_PORT} - redis: - host: ${REDIS_HOST} - r2dbc: - url: r2dbc:postgresql://${DB_IP_PORT}/opex_api - username: opex - password: hiopex - cloud: - consul: - host: ${CONSUL_HOST} - port: 8500 - main: - allow-bean-definition-overriding: true - -app: - accountant: - url: lb://opex-accountant - matching-gateway: - url: lb://opex-gateway - wallet: - url: lb://opex-wallet - opex-bc-gateway: - url: lb://opex-bc-gateway - auth: - cert-url: lb://opex-auth/auth/realms/opex/protocol/openid-connect/certs \ No newline at end of file diff --git a/api/api-app/src/main/resources/application.yml b/api/api-app/src/main/resources/application.yml index d2e031949..cf33eb4c5 100644 --- a/api/api-app/src/main/resources/application.yml +++ b/api/api-app/src/main/resources/application.yml @@ -1,4 +1,4 @@ -server.port: 8094 +server.port: 8080 logging: level: co.nilin: DEBUG @@ -7,30 +7,46 @@ spring: application: name: opex-api main: - allow-bean-definition-overriding: false + allow-bean-definition-overriding: true + allow-circular-references: true kafka: - bootstrap-servers: 192.168.178.29:9092 + bootstrap-servers: ${KAFKA_IP_PORT:localhost:9092} consumer: group-id: api redis: - host: 127.0.0.1 + host: ${REDIS_HOST:localhost} port: 6379 r2dbc: - url: r2dbc:postgresql://localhost/opex_api - username: opex - password: hiopex + url: r2dbc:postgresql://${DB_IP_PORT:localhost}/opex_api + username: ${dbusername:opex} + password: ${dbpassword:hiopex} initialization-mode: always cloud: bootstrap: enabled: true + vault: + host: ${VAULT_HOST} + port: 8200 + scheme: http + authentication: APPID + app-id: + user-id: co.nilin.opex.util.vault.VaultUserIdMechanism + fail-fast: true + kv: + enabled: true + backend: secret + profile-separator: '/' + application-name: ${spring.application.name} consul: + host: ${CONSUL_HOST:localhost} port: 8500 discovery: #healthCheckPath: ${management.context-path}/health instance-id: ${spring.application.name}:${server.port} healthCheckInterval: 20s prefer-ip-address: true - + config: + import: vault://secret/${spring.application.name} app: accountant: url: lb://opex-accountant diff --git a/api/api-core/mvnw b/api/api-core/mvnw deleted file mode 100644 index 3c8a55373..000000000 --- a/api/api-core/mvnw +++ /dev/null @@ -1,322 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ]; then - - if [ -f /etc/mavenrc ]; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ]; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false -darwin=false -mingw=false -case "$(uname)" in -CYGWIN*) cygwin=true ;; -MINGW*) mingw=true ;; -Darwin*) - darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="$(/usr/libexec/java_home)" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ]; then - if [ -r /etc/gentoo-release ]; then - JAVA_HOME=$(java-config --jre-home) - fi -fi - -if [ -z "$M2_HOME" ]; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ]; do - ls=$(ls -ld "$PRG") - link=$(expr "$ls" : '.*-> \(.*\)$') - if expr "$link" : '/.*' >/dev/null; then - PRG="$link" - else - PRG="$(dirname "$PRG")/$link" - fi - done - - saveddir=$(pwd) - - M2_HOME=$(dirname "$PRG")/.. - - # make it fully qualified - M2_HOME=$(cd "$M2_HOME" && pwd) - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=$(cygpath --unix "$M2_HOME") - [ -n "$JAVA_HOME" ] && - JAVA_HOME=$(cygpath --unix "$JAVA_HOME") - [ -n "$CLASSPATH" ] && - CLASSPATH=$(cygpath --path --unix "$CLASSPATH") -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw; then - [ -n "$M2_HOME" ] && - M2_HOME="$( ( - cd "$M2_HOME" - pwd - ))" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="$( ( - cd "$JAVA_HOME" - pwd - ))" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="$(which javac)" - if [ -n "$javaExecutable" ] && ! [ "$(expr \"$javaExecutable\" : '\([^ ]*\)')" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=$(which readlink) - if [ ! $(expr "$readLink" : '\([^ ]*\)') = "no" ]; then - if $darwin; then - javaHome="$(dirname \"$javaExecutable\")" - javaExecutable="$(cd \"$javaHome\" && pwd -P)/javac" - else - javaExecutable="$(readlink -f \"$javaExecutable\")" - fi - javaHome="$(dirname \"$javaExecutable\")" - javaHome=$(expr "$javaHome" : '\(.*\)/bin') - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ]; then - if [ -n "$JAVA_HOME" ]; then - if [ -x "$JAVA_HOME/jre/sh/java" ]; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="$(which java)" - fi -fi - -if [ ! -x "$JAVACMD" ]; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ]; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ]; then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ]; do - if [ -d "$wdir"/.mvn ]; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=$( - cd "$wdir/.." - pwd - ) - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' <"$1")" - fi -} - -BASE_DIR=$(find_maven_basedir "$(pwd)") -if [ -z "$BASE_DIR" ]; then - exit 1 -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in wrapperUrl) - jarUrl="$value" - break - ;; - esac - done <"$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath") - fi - - if command -v wget >/dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl >/dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=$(cygpath --path --windows "$javaClass") - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=$(cygpath --path --windows "$M2_HOME") - [ -n "$JAVA_HOME" ] && - JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME") - [ -n "$CLASSPATH" ] && - CLASSPATH=$(cygpath --path --windows "$CLASSPATH") - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR") -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/api/api-core/mvnw.cmd b/api/api-core/mvnw.cmd deleted file mode 100644 index c8d43372c..000000000 --- a/api/api-core/mvnw.cmd +++ /dev/null @@ -1,182 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/api/api-core/src/main/kotlin/co/nilin/opex/api/core/spi/BlockchainGatewayProxy.kt b/api/api-core/src/main/kotlin/co/nilin/opex/api/core/spi/BlockchainGatewayProxy.kt index 540da6e05..e131492a3 100644 --- a/api/api-core/src/main/kotlin/co/nilin/opex/api/core/spi/BlockchainGatewayProxy.kt +++ b/api/api-core/src/main/kotlin/co/nilin/opex/api/core/spi/BlockchainGatewayProxy.kt @@ -5,7 +5,7 @@ import co.nilin.opex.api.core.inout.DepositDetails interface BlockchainGatewayProxy { - suspend fun assignAddress(uuid: String, currency: String): AssignResponse + suspend fun assignAddress(uuid: String, currency: String): AssignResponse? suspend fun getDepositDetails(refs: List): List diff --git a/api/api-core/src/main/kotlin/co/nilin/opex/api/core/spi/OrderPersister.kt b/api/api-core/src/main/kotlin/co/nilin/opex/api/core/spi/OrderPersister.kt index a8a128d04..dc621f72b 100644 --- a/api/api-core/src/main/kotlin/co/nilin/opex/api/core/spi/OrderPersister.kt +++ b/api/api-core/src/main/kotlin/co/nilin/opex/api/core/spi/OrderPersister.kt @@ -1,7 +1,11 @@ package co.nilin.opex.api.core.spi import co.nilin.opex.accountant.core.inout.RichOrder +import co.nilin.opex.accountant.core.inout.RichOrderUpdate interface OrderPersister { + suspend fun save(order: RichOrder) + + suspend fun update(orderUpdate: RichOrderUpdate) } \ No newline at end of file diff --git a/api/api-ports/api-binance-rest/mvnw b/api/api-ports/api-binance-rest/mvnw deleted file mode 100644 index 3c8a55373..000000000 --- a/api/api-ports/api-binance-rest/mvnw +++ /dev/null @@ -1,322 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ]; then - - if [ -f /etc/mavenrc ]; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ]; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false -darwin=false -mingw=false -case "$(uname)" in -CYGWIN*) cygwin=true ;; -MINGW*) mingw=true ;; -Darwin*) - darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="$(/usr/libexec/java_home)" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ]; then - if [ -r /etc/gentoo-release ]; then - JAVA_HOME=$(java-config --jre-home) - fi -fi - -if [ -z "$M2_HOME" ]; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ]; do - ls=$(ls -ld "$PRG") - link=$(expr "$ls" : '.*-> \(.*\)$') - if expr "$link" : '/.*' >/dev/null; then - PRG="$link" - else - PRG="$(dirname "$PRG")/$link" - fi - done - - saveddir=$(pwd) - - M2_HOME=$(dirname "$PRG")/.. - - # make it fully qualified - M2_HOME=$(cd "$M2_HOME" && pwd) - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=$(cygpath --unix "$M2_HOME") - [ -n "$JAVA_HOME" ] && - JAVA_HOME=$(cygpath --unix "$JAVA_HOME") - [ -n "$CLASSPATH" ] && - CLASSPATH=$(cygpath --path --unix "$CLASSPATH") -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw; then - [ -n "$M2_HOME" ] && - M2_HOME="$( ( - cd "$M2_HOME" - pwd - ))" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="$( ( - cd "$JAVA_HOME" - pwd - ))" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="$(which javac)" - if [ -n "$javaExecutable" ] && ! [ "$(expr \"$javaExecutable\" : '\([^ ]*\)')" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=$(which readlink) - if [ ! $(expr "$readLink" : '\([^ ]*\)') = "no" ]; then - if $darwin; then - javaHome="$(dirname \"$javaExecutable\")" - javaExecutable="$(cd \"$javaHome\" && pwd -P)/javac" - else - javaExecutable="$(readlink -f \"$javaExecutable\")" - fi - javaHome="$(dirname \"$javaExecutable\")" - javaHome=$(expr "$javaHome" : '\(.*\)/bin') - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ]; then - if [ -n "$JAVA_HOME" ]; then - if [ -x "$JAVA_HOME/jre/sh/java" ]; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="$(which java)" - fi -fi - -if [ ! -x "$JAVACMD" ]; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ]; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ]; then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ]; do - if [ -d "$wdir"/.mvn ]; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=$( - cd "$wdir/.." - pwd - ) - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' <"$1")" - fi -} - -BASE_DIR=$(find_maven_basedir "$(pwd)") -if [ -z "$BASE_DIR" ]; then - exit 1 -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in wrapperUrl) - jarUrl="$value" - break - ;; - esac - done <"$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath") - fi - - if command -v wget >/dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl >/dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=$(cygpath --path --windows "$javaClass") - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=$(cygpath --path --windows "$M2_HOME") - [ -n "$JAVA_HOME" ] && - JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME") - [ -n "$CLASSPATH" ] && - CLASSPATH=$(cygpath --path --windows "$CLASSPATH") - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR") -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/api/api-ports/api-binance-rest/mvnw.cmd b/api/api-ports/api-binance-rest/mvnw.cmd deleted file mode 100644 index c8d43372c..000000000 --- a/api/api-ports/api-binance-rest/mvnw.cmd +++ /dev/null @@ -1,182 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/api/api-ports/api-binance-rest/pom.xml b/api/api-ports/api-binance-rest/pom.xml index 31a7cd2ec..ccd19b414 100644 --- a/api/api-ports/api-binance-rest/pom.xml +++ b/api/api-ports/api-binance-rest/pom.xml @@ -15,10 +15,6 @@ api-binance-rest Api Binance Rest - - 2020.0.2 - - org.jetbrains.kotlin @@ -115,15 +111,5 @@ - - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - + diff --git a/api/api-ports/api-binance-rest/src/main/kotlin/co/nilin/opex/api/ports/binance/controller/WalletController.kt b/api/api-ports/api-binance-rest/src/main/kotlin/co/nilin/opex/api/ports/binance/controller/WalletController.kt index 38c8b6dbe..7fe60516e 100644 --- a/api/api-ports/api-binance-rest/src/main/kotlin/co/nilin/opex/api/ports/binance/controller/WalletController.kt +++ b/api/api-ports/api-binance-rest/src/main/kotlin/co/nilin/opex/api/ports/binance/controller/WalletController.kt @@ -39,7 +39,7 @@ class WalletController( @CurrentSecurityContext securityContext: SecurityContext ): AssignAddressResponse { val response = bcGatewayProxy.assignAddress(securityContext.jwtAuthentication().name, coin) - val address = if (response.addresses.isNotEmpty()) response.addresses[0] else null + val address = if (response?.addresses?.isNotEmpty() == true) response.addresses[0] else null return AssignAddressResponse(address?.address ?: "", coin, "", "") } diff --git a/api/api-ports/api-binance-rest/src/main/kotlin/co/nilin/opex/api/ports/binance/proxy/BlockchainGatewayProxyImpl.kt b/api/api-ports/api-binance-rest/src/main/kotlin/co/nilin/opex/api/ports/binance/proxy/BlockchainGatewayProxyImpl.kt index b6f9c5ca4..aa19bd4ac 100644 --- a/api/api-ports/api-binance-rest/src/main/kotlin/co/nilin/opex/api/ports/binance/proxy/BlockchainGatewayProxyImpl.kt +++ b/api/api-ports/api-binance-rest/src/main/kotlin/co/nilin/opex/api/ports/binance/proxy/BlockchainGatewayProxyImpl.kt @@ -33,7 +33,7 @@ class BlockchainGatewayProxyImpl(private val client: WebClient) : BlockchainGate @Value("\${app.opex-bc-gateway.url}") private lateinit var baseUrl: String - override suspend fun assignAddress(uuid: String, currency: String): AssignResponse { + override suspend fun assignAddress(uuid: String, currency: String): AssignResponse? { logger.info("calling bc-gateway assign") return client.post() .uri(URI.create("$baseUrl/address/assign")) @@ -42,7 +42,7 @@ class BlockchainGatewayProxyImpl(private val client: WebClient) : BlockchainGate .body(Mono.just(AssignAddressRequest(uuid, currency))) .retrieve() .onStatus({ t -> t.isError }, { it.createException() }) - .bodyToMono(typeRef()) + .bodyToMono(AssignResponse::class.java) .awaitSingleOrNull() } diff --git a/api/api-ports/api-eventlistener-kafka/mvnw b/api/api-ports/api-eventlistener-kafka/mvnw deleted file mode 100644 index 3c8a55373..000000000 --- a/api/api-ports/api-eventlistener-kafka/mvnw +++ /dev/null @@ -1,322 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ]; then - - if [ -f /etc/mavenrc ]; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ]; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false -darwin=false -mingw=false -case "$(uname)" in -CYGWIN*) cygwin=true ;; -MINGW*) mingw=true ;; -Darwin*) - darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="$(/usr/libexec/java_home)" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ]; then - if [ -r /etc/gentoo-release ]; then - JAVA_HOME=$(java-config --jre-home) - fi -fi - -if [ -z "$M2_HOME" ]; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ]; do - ls=$(ls -ld "$PRG") - link=$(expr "$ls" : '.*-> \(.*\)$') - if expr "$link" : '/.*' >/dev/null; then - PRG="$link" - else - PRG="$(dirname "$PRG")/$link" - fi - done - - saveddir=$(pwd) - - M2_HOME=$(dirname "$PRG")/.. - - # make it fully qualified - M2_HOME=$(cd "$M2_HOME" && pwd) - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=$(cygpath --unix "$M2_HOME") - [ -n "$JAVA_HOME" ] && - JAVA_HOME=$(cygpath --unix "$JAVA_HOME") - [ -n "$CLASSPATH" ] && - CLASSPATH=$(cygpath --path --unix "$CLASSPATH") -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw; then - [ -n "$M2_HOME" ] && - M2_HOME="$( ( - cd "$M2_HOME" - pwd - ))" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="$( ( - cd "$JAVA_HOME" - pwd - ))" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="$(which javac)" - if [ -n "$javaExecutable" ] && ! [ "$(expr \"$javaExecutable\" : '\([^ ]*\)')" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=$(which readlink) - if [ ! $(expr "$readLink" : '\([^ ]*\)') = "no" ]; then - if $darwin; then - javaHome="$(dirname \"$javaExecutable\")" - javaExecutable="$(cd \"$javaHome\" && pwd -P)/javac" - else - javaExecutable="$(readlink -f \"$javaExecutable\")" - fi - javaHome="$(dirname \"$javaExecutable\")" - javaHome=$(expr "$javaHome" : '\(.*\)/bin') - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ]; then - if [ -n "$JAVA_HOME" ]; then - if [ -x "$JAVA_HOME/jre/sh/java" ]; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="$(which java)" - fi -fi - -if [ ! -x "$JAVACMD" ]; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ]; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ]; then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ]; do - if [ -d "$wdir"/.mvn ]; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=$( - cd "$wdir/.." - pwd - ) - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' <"$1")" - fi -} - -BASE_DIR=$(find_maven_basedir "$(pwd)") -if [ -z "$BASE_DIR" ]; then - exit 1 -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in wrapperUrl) - jarUrl="$value" - break - ;; - esac - done <"$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath") - fi - - if command -v wget >/dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl >/dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=$(cygpath --path --windows "$javaClass") - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=$(cygpath --path --windows "$M2_HOME") - [ -n "$JAVA_HOME" ] && - JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME") - [ -n "$CLASSPATH" ] && - CLASSPATH=$(cygpath --path --windows "$CLASSPATH") - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR") -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/api/api-ports/api-eventlistener-kafka/mvnw.cmd b/api/api-ports/api-eventlistener-kafka/mvnw.cmd deleted file mode 100644 index c8d43372c..000000000 --- a/api/api-ports/api-eventlistener-kafka/mvnw.cmd +++ /dev/null @@ -1,182 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/api/api-ports/api-eventlistener-kafka/src/main/kotlin/co/nilin/opex/api/ports/kafka/listener/config/ApiKafkaConfig.kt b/api/api-ports/api-eventlistener-kafka/src/main/kotlin/co/nilin/opex/api/ports/kafka/listener/config/ApiKafkaConfig.kt index a8bf6a06e..30b6b1f05 100644 --- a/api/api-ports/api-eventlistener-kafka/src/main/kotlin/co/nilin/opex/api/ports/kafka/listener/config/ApiKafkaConfig.kt +++ b/api/api-ports/api-eventlistener-kafka/src/main/kotlin/co/nilin/opex/api/ports/kafka/listener/config/ApiKafkaConfig.kt @@ -1,12 +1,13 @@ package co.nilin.opex.api.ports.kafka.listener.config -import co.nilin.opex.matching.engine.core.eventh.events.CoreEvent import co.nilin.opex.api.ports.kafka.listener.consumer.EventKafkaListener import co.nilin.opex.api.ports.kafka.listener.consumer.OrderKafkaListener import co.nilin.opex.api.ports.kafka.listener.consumer.TradeKafkaListener +import co.nilin.opex.matching.engine.core.eventh.events.CoreEvent import org.apache.kafka.clients.admin.NewTopic import org.apache.kafka.clients.consumer.ConsumerConfig import org.apache.kafka.clients.producer.ProducerConfig +import org.apache.kafka.common.config.TopicConfig import org.apache.kafka.common.serialization.StringDeserializer import org.apache.kafka.common.serialization.StringSerializer import org.springframework.beans.factory.annotation.Autowired @@ -16,15 +17,18 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration import org.springframework.context.support.GenericApplicationContext +import org.springframework.kafka.config.TopicBuilder import org.springframework.kafka.core.* import org.springframework.kafka.listener.ConcurrentMessageListenerContainer import org.springframework.kafka.listener.ContainerProperties import org.springframework.kafka.support.serializer.JsonDeserializer import org.springframework.kafka.support.serializer.JsonSerializer +import java.util.function.Supplier import java.util.regex.Pattern @Configuration class ApiKafkaConfig { + @Value("\${spring.kafka.bootstrap-servers}") private val bootstrapServers: String? = null @@ -32,14 +36,14 @@ class ApiKafkaConfig { private val groupId: String? = null @Bean("apiConsumerConfig") - fun consumerConfigs(): Map? { - val props: MutableMap = HashMap() - props[ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG] = bootstrapServers - props[ConsumerConfig.GROUP_ID_CONFIG] = groupId - props[ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG] = StringDeserializer::class.java - props[ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG] = JsonDeserializer::class.java - props[JsonDeserializer.TRUSTED_PACKAGES] = "co.nilin.opex.*" - return props + fun consumerConfigs(): Map { + return mapOf( + ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG to bootstrapServers, + ConsumerConfig.GROUP_ID_CONFIG to groupId, + ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG to StringDeserializer::class.java, + ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG to JsonDeserializer::class.java, + JsonDeserializer.TRUSTED_PACKAGES to "co.nilin.opex.*", + ) } @Bean("apiConsumerFactory") @@ -49,11 +53,12 @@ class ApiKafkaConfig { @Bean("apiProducerConfig") fun producerConfigs(): Map { - val props: MutableMap = HashMap() - props[ProducerConfig.BOOTSTRAP_SERVERS_CONFIG] = bootstrapServers - props[ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG] = StringSerializer::class.java - props[ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG] = JsonSerializer::class.java - return props + return mapOf( + ProducerConfig.BOOTSTRAP_SERVERS_CONFIG to bootstrapServers, + ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG to StringSerializer::class.java, + ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG to JsonSerializer::class.java, + ProducerConfig.ACKS_CONFIG to "all" + ) } @Bean("apiProducerFactory") @@ -66,7 +71,6 @@ class ApiKafkaConfig { return KafkaTemplate(producerFactory) } - @Autowired @ConditionalOnBean(TradeKafkaListener::class) fun configureTradeListener( @@ -108,8 +112,21 @@ class ApiKafkaConfig { @Autowired fun createTopics(applicationContext: GenericApplicationContext) { - applicationContext.registerBean("topic_richOrder", NewTopic::class.java, "richOrder", 10, 1) - applicationContext.registerBean("topic_richTrade", NewTopic::class.java, "richTrade", 10, 1) + applicationContext.registerBean("topic_richOrder", NewTopic::class.java, Supplier { + TopicBuilder.name("richOrder") + .partitions(10) + .replicas(3) + .config(TopicConfig.MIN_IN_SYNC_REPLICAS_CONFIG, "2") + .build() + }) + + applicationContext.registerBean("topic_richTrade", NewTopic::class.java, Supplier { + TopicBuilder.name("richTrade") + .partitions(10) + .replicas(3) + .config(TopicConfig.MIN_IN_SYNC_REPLICAS_CONFIG, "2") + .build() + }) } diff --git a/api/api-ports/api-eventlistener-kafka/src/main/kotlin/co/nilin/opex/api/ports/kafka/listener/consumer/EventKafkaListener.kt b/api/api-ports/api-eventlistener-kafka/src/main/kotlin/co/nilin/opex/api/ports/kafka/listener/consumer/EventKafkaListener.kt index 8c4320ed6..6c01fa606 100644 --- a/api/api-ports/api-eventlistener-kafka/src/main/kotlin/co/nilin/opex/api/ports/kafka/listener/consumer/EventKafkaListener.kt +++ b/api/api-ports/api-eventlistener-kafka/src/main/kotlin/co/nilin/opex/api/ports/kafka/listener/consumer/EventKafkaListener.kt @@ -1,8 +1,8 @@ package co.nilin.opex.api.ports.kafka.listener.consumer -import co.nilin.opex.matching.engine.core.eventh.events.CoreEvent import co.nilin.opex.api.ports.kafka.listener.spi.EventListener +import co.nilin.opex.matching.engine.core.eventh.events.CoreEvent import org.apache.kafka.clients.consumer.ConsumerRecord import org.springframework.kafka.listener.MessageListener import org.springframework.stereotype.Component diff --git a/api/api-ports/api-eventlistener-kafka/src/main/kotlin/co/nilin/opex/api/ports/kafka/listener/consumer/OrderKafkaListener.kt b/api/api-ports/api-eventlistener-kafka/src/main/kotlin/co/nilin/opex/api/ports/kafka/listener/consumer/OrderKafkaListener.kt index 212dc6afb..e9492a732 100644 --- a/api/api-ports/api-eventlistener-kafka/src/main/kotlin/co/nilin/opex/api/ports/kafka/listener/consumer/OrderKafkaListener.kt +++ b/api/api-ports/api-eventlistener-kafka/src/main/kotlin/co/nilin/opex/api/ports/kafka/listener/consumer/OrderKafkaListener.kt @@ -1,19 +1,20 @@ package co.nilin.opex.api.ports.kafka.listener.consumer -import co.nilin.opex.accountant.core.inout.RichOrder +import co.nilin.opex.accountant.core.inout.RichOrderEvent import co.nilin.opex.api.ports.kafka.listener.spi.RichOrderListener import org.apache.kafka.clients.consumer.ConsumerRecord import org.springframework.kafka.listener.MessageListener import org.springframework.stereotype.Component @Component -class OrderKafkaListener : MessageListener { +class OrderKafkaListener : MessageListener { + val orderListeners = arrayListOf() - override fun onMessage(data: ConsumerRecord) { + + override fun onMessage(data: ConsumerRecord) { orderListeners.forEach { tl -> tl.onOrder(data.value(), data.partition(), data.offset(), data.timestamp()) } - } fun addOrderListener(tl: RichOrderListener) { diff --git a/api/api-ports/api-eventlistener-kafka/src/main/kotlin/co/nilin/opex/api/ports/kafka/listener/spi/RichOrderListener.kt b/api/api-ports/api-eventlistener-kafka/src/main/kotlin/co/nilin/opex/api/ports/kafka/listener/spi/RichOrderListener.kt index 31bf82954..a87a85c5b 100644 --- a/api/api-ports/api-eventlistener-kafka/src/main/kotlin/co/nilin/opex/api/ports/kafka/listener/spi/RichOrderListener.kt +++ b/api/api-ports/api-eventlistener-kafka/src/main/kotlin/co/nilin/opex/api/ports/kafka/listener/spi/RichOrderListener.kt @@ -1,8 +1,11 @@ package co.nilin.opex.api.ports.kafka.listener.spi -import co.nilin.opex.accountant.core.inout.RichOrder +import co.nilin.opex.accountant.core.inout.RichOrderEvent interface RichOrderListener { + fun id(): String - fun onOrder(order: RichOrder, partition: Int, offset: Long, timestamp: Long) + + fun onOrder(order: RichOrderEvent, partition: Int, offset: Long, timestamp: Long) + } \ No newline at end of file diff --git a/api/api-ports/api-persister-postgres/mvnw b/api/api-ports/api-persister-postgres/mvnw deleted file mode 100644 index 3c8a55373..000000000 --- a/api/api-ports/api-persister-postgres/mvnw +++ /dev/null @@ -1,322 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ]; then - - if [ -f /etc/mavenrc ]; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ]; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false -darwin=false -mingw=false -case "$(uname)" in -CYGWIN*) cygwin=true ;; -MINGW*) mingw=true ;; -Darwin*) - darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="$(/usr/libexec/java_home)" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ]; then - if [ -r /etc/gentoo-release ]; then - JAVA_HOME=$(java-config --jre-home) - fi -fi - -if [ -z "$M2_HOME" ]; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ]; do - ls=$(ls -ld "$PRG") - link=$(expr "$ls" : '.*-> \(.*\)$') - if expr "$link" : '/.*' >/dev/null; then - PRG="$link" - else - PRG="$(dirname "$PRG")/$link" - fi - done - - saveddir=$(pwd) - - M2_HOME=$(dirname "$PRG")/.. - - # make it fully qualified - M2_HOME=$(cd "$M2_HOME" && pwd) - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=$(cygpath --unix "$M2_HOME") - [ -n "$JAVA_HOME" ] && - JAVA_HOME=$(cygpath --unix "$JAVA_HOME") - [ -n "$CLASSPATH" ] && - CLASSPATH=$(cygpath --path --unix "$CLASSPATH") -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw; then - [ -n "$M2_HOME" ] && - M2_HOME="$( ( - cd "$M2_HOME" - pwd - ))" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="$( ( - cd "$JAVA_HOME" - pwd - ))" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="$(which javac)" - if [ -n "$javaExecutable" ] && ! [ "$(expr \"$javaExecutable\" : '\([^ ]*\)')" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=$(which readlink) - if [ ! $(expr "$readLink" : '\([^ ]*\)') = "no" ]; then - if $darwin; then - javaHome="$(dirname \"$javaExecutable\")" - javaExecutable="$(cd \"$javaHome\" && pwd -P)/javac" - else - javaExecutable="$(readlink -f \"$javaExecutable\")" - fi - javaHome="$(dirname \"$javaExecutable\")" - javaHome=$(expr "$javaHome" : '\(.*\)/bin') - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ]; then - if [ -n "$JAVA_HOME" ]; then - if [ -x "$JAVA_HOME/jre/sh/java" ]; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="$(which java)" - fi -fi - -if [ ! -x "$JAVACMD" ]; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ]; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ]; then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ]; do - if [ -d "$wdir"/.mvn ]; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=$( - cd "$wdir/.." - pwd - ) - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' <"$1")" - fi -} - -BASE_DIR=$(find_maven_basedir "$(pwd)") -if [ -z "$BASE_DIR" ]; then - exit 1 -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in wrapperUrl) - jarUrl="$value" - break - ;; - esac - done <"$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath") - fi - - if command -v wget >/dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl >/dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=$(cygpath --path --windows "$javaClass") - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=$(cygpath --path --windows "$M2_HOME") - [ -n "$JAVA_HOME" ] && - JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME") - [ -n "$CLASSPATH" ] && - CLASSPATH=$(cygpath --path --windows "$CLASSPATH") - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR") -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/api/api-ports/api-persister-postgres/mvnw.cmd b/api/api-ports/api-persister-postgres/mvnw.cmd deleted file mode 100644 index c8d43372c..000000000 --- a/api/api-ports/api-persister-postgres/mvnw.cmd +++ /dev/null @@ -1,182 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/dao/OrderRepository.kt b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/dao/OrderRepository.kt index b8c6b7cb7..6dd73ce68 100644 --- a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/dao/OrderRepository.kt +++ b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/dao/OrderRepository.kt @@ -1,8 +1,8 @@ package co.nilin.opex.api.ports.postgres.dao import co.nilin.opex.api.core.inout.AggregatedOrderPriceModel -import co.nilin.opex.matching.engine.core.model.OrderDirection import co.nilin.opex.api.ports.postgres.model.OrderModel +import co.nilin.opex.matching.engine.core.model.OrderDirection import kotlinx.coroutines.flow.Flow import org.springframework.data.r2dbc.repository.Query import org.springframework.data.repository.query.Param @@ -28,11 +28,20 @@ interface OrderRepository : ReactiveCrudRepository { @Query("select * from orders where symbol = :symbol and client_order_id = :origClientOrderId") fun findBySymbolAndClientOrderId( @Param("symbol") - symbol: String, @Param("origClientOrderId") + symbol: String, + @Param("origClientOrderId") origClientOrderId: String ): Mono - @Query("select * from orders where uuid = :uuid and (:symbol is null or symbol = :symbol) and status in (:statuses)") + @Query( + """ + select * from orders + join order_status os on orders.ouid = os.ouid + where uuid = :uuid and (:symbol is null or symbol = :symbol) and status in (:statuses) + and appearance = (select max(appearance) from order_status where ouid = orders.ouid) + and executed_quantity = (select max(executed_quantity) from order_status where ouid = orders.ouid) + """ + ) fun findByUuidAndSymbolAndStatus( @Param("uuid") uuid: String, @@ -60,8 +69,11 @@ interface OrderRepository : ReactiveCrudRepository { @Query( """ - select price, (sum(quantity) - sum(executed_qty)) as quantity from orders - where symbol = :symbol and side = :direction and status in (:statuses) + select price, (sum(quantity) - sum(os.executed_quantity)) as quantity from orders + join order_status os on orders.ouid = os.ouid + where symbol = :symbol and side = :direction and os.status in (:statuses) + and appearance = (select max(appearance) from order_status where ouid = orders.ouid) + and executed_quantity = (select max(executed_quantity) from order_status where ouid = orders.ouid) group by price order by price asc limit :limit @@ -80,8 +92,11 @@ interface OrderRepository : ReactiveCrudRepository { @Query( """ - select price, (sum(quantity) - sum(executed_qty)) as quantity from orders + select price, (sum(quantity) - sum(executed_quantity)) as quantity from orders + join order_status os on orders.ouid = os.ouid where symbol = :symbol and side = :direction and status in (:statuses) + and appearance = (select max(appearance) from order_status where ouid = orders.ouid) + and executed_quantity = (select max(executed_quantity) from order_status where ouid = orders.ouid) group by price order by price desc limit :limit diff --git a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/dao/OrderStatusRepository.kt b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/dao/OrderStatusRepository.kt new file mode 100644 index 000000000..b984c5e43 --- /dev/null +++ b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/dao/OrderStatusRepository.kt @@ -0,0 +1,24 @@ +package co.nilin.opex.api.ports.postgres.dao + +import co.nilin.opex.api.ports.postgres.model.OrderStatusModel +import org.springframework.data.r2dbc.repository.Query +import org.springframework.data.repository.reactive.ReactiveCrudRepository +import org.springframework.stereotype.Repository +import reactor.core.publisher.Mono + +@Repository +interface OrderStatusRepository : ReactiveCrudRepository { + + @Query( + """ + with max_appearance as (select max(appearance) as max_app from order_status where ouid = :ouid) + select * from order_status + where ouid = :ouid + and appearance = (select max_app from max_appearance) + order by executed_quantity desc + limit 1 + """ + ) + fun findMostRecentByOUID(ouid: String): Mono + +} \ No newline at end of file diff --git a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/dao/TradeRepository.kt b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/dao/TradeRepository.kt index 7ec090bf4..06656e428 100644 --- a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/dao/TradeRepository.kt +++ b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/dao/TradeRepository.kt @@ -52,18 +52,39 @@ interface TradeRepository : ReactiveCrudRepository { @Query( """ select symbol, - (select taker_price from trades where create_date > :date and symbol=t.symbol order by create_date desc limit 1) - (select taker_price from trades where create_date > :date and symbol=t.symbol order by create_date asc limit 1) as price_change, - ((((select taker_price from trades where create_date > :date and symbol=t.symbol order by create_date desc limit 1) - (select taker_price from trades where create_date > :date and symbol=t.symbol order by create_date asc limit 1))/(select taker_price from trades where create_date > :date and symbol=t.symbol order by create_date asc limit 1))*100) as price_change_percent, + (select taker_price from trades where create_date > :date and symbol=t.symbol order by create_date desc limit 1) - (select taker_price from trades where create_date > :date and symbol=t.symbol order by create_date limit 1) as price_change, + ((((select taker_price from trades where create_date > :date and symbol=t.symbol order by create_date desc limit 1) - (select taker_price from trades where create_date > :date and symbol=t.symbol order by create_date limit 1))/(select taker_price from trades where create_date > :date and symbol=t.symbol order by create_date limit 1))*100) as price_change_percent, (sum(matched_quantity)/sum(taker_price)) as weighted_avg_price, - (select taker_price from trades where create_date > :date and symbol=t.symbol order by create_date asc limit 1) as last_price, - (select matched_quantity from trades where create_date > :date and symbol=t.symbol order by create_date asc limit 1) as last_qty, - (select price from orders where create_date > :date and symbol=t.symbol and (status=1 or status=4) and side='BID' order by create_date desc limit 1) as bid_price, - (select price from orders where create_date > :date and symbol=t.symbol and (status=1 or status=4) and side='ASK' order by create_date asc limit 1) as ask_price, - (select price from orders where create_date > :date and symbol=t.symbol and (status=1 or status=4) order by create_date desc limit 1) as open_price, + (select taker_price from trades where create_date > :date and symbol=t.symbol order by create_date limit 1) as last_price, + (select matched_quantity from trades where create_date > :date and symbol=t.symbol order by create_date limit 1) as last_qty, + ( + select price from orders + join order_status os on orders.ouid = os.ouid + where create_date > :date and symbol=t.symbol and status in (1, 4) and side='BID' + and appearance = (select max(appearance) from order_status where ouid = orders.ouid) + and executed_quantity = (select max(executed_quantity) from order_status where ouid = orders.ouid) + order by create_date desc limit 1 + ) as bid_price, + ( + select price from orders + join order_status os on orders.ouid = os.ouid + where create_date > :date and symbol=t.symbol and status in (1, 4) and side='ASK' + and appearance = (select max(appearance) from order_status where ouid = orders.ouid) + and executed_quantity = (select max(executed_quantity) from order_status where ouid = orders.ouid) + order by create_date limit 1 + ) as ask_price, + ( + select price from orders + join order_status os on orders.ouid = os.ouid + where create_date > :date and symbol=t.symbol and status in (1, 4) + and appearance = (select max(appearance) from order_status where ouid = orders.ouid) + and executed_quantity = (select max(executed_quantity) from order_status where ouid = orders.ouid) + order by create_date desc limit 1 + ) as open_price, max(taker_price) as high_price, min(taker_price) as low_price, sum(matched_quantity) as volume, - (select id from trades where create_date > :date and symbol=t.symbol order by create_date asc limit 1) as first_id, + (select id from trades where create_date > :date and symbol=t.symbol order by create_date limit 1) as first_id, (select id from trades where create_date > :date and symbol=t.symbol order by create_date desc limit 1) as last_id, count(id) as count from trades as t @@ -76,18 +97,39 @@ interface TradeRepository : ReactiveCrudRepository { @Query( """ select symbol, - (select taker_price from trades where create_date > :date and symbol=:symbol order by create_date desc limit 1) - (select taker_price from trades where create_date > :date and symbol=:symbol order by create_date asc limit 1) as price_change, - ((((select taker_price from trades where create_date > :date and symbol=:symbol order by create_date desc limit 1) - (select taker_price from trades where create_date > :date and symbol=:symbol order by create_date asc limit 1))/(select taker_price from trades where create_date > :date and symbol=:symbol order by create_date asc limit 1))*100) as price_change_percent, + (select taker_price from trades where create_date > :date and symbol=:symbol order by create_date desc limit 1) - (select taker_price from trades where create_date > :date and symbol=:symbol order by create_date limit 1) as price_change, + ((((select taker_price from trades where create_date > :date and symbol=:symbol order by create_date desc limit 1) - (select taker_price from trades where create_date > :date and symbol=:symbol order by create_date limit 1))/(select taker_price from trades where create_date > :date and symbol=:symbol order by create_date limit 1))*100) as price_change_percent, (sum(matched_quantity)/sum(taker_price)) as weighted_avg_price, - (select taker_price from trades where create_date > :date and symbol=:symbol order by create_date asc limit 1) as last_price, - (select matched_quantity from trades where create_date > :date and symbol=:symbol order by create_date asc limit 1) as last_qty, - (select price from orders where create_date > :date and symbol=t.symbol and (status=1 or status=4) and side='BID' order by create_date desc limit 1) as bid_price, - (select price from orders where create_date > :date and symbol=t.symbol and (status=1 or status=4) and side='ASK' order by create_date asc limit 1) as ask_price, - (select price from orders where create_date > :date and symbol=t.symbol and (status=1 or status=4) order by create_date desc limit 1) as open_price, + (select taker_price from trades where create_date > :date and symbol=:symbol order by create_date limit 1) as last_price, + (select matched_quantity from trades where create_date > :date and symbol=:symbol order by create_date limit 1) as last_qty, + ( + select price from orders + join order_status os on orders.ouid = os.ouid + where create_date > :date and symbol=t.symbol and status in (1, 4) and side='BID' + and appearance = (select max(appearance) from order_status where ouid = orders.ouid) + and executed_quantity = (select max(executed_quantity) from order_status where ouid = orders.ouid) + order by create_date desc limit 1 + ) as bid_price, + ( + select price from orders + join order_status os on orders.ouid = os.ouid + where create_date > :date and symbol=t.symbol and status in (1, 4) and side='ASK' + and appearance = (select max(appearance) from order_status where ouid = orders.ouid) + and executed_quantity = (select max(executed_quantity) from order_status where ouid = orders.ouid) + order by create_date limit 1 + ) as ask_price, + ( + select price from orders + join order_status os on orders.ouid = os.ouid + where create_date > :date and symbol=t.symbol and status in (1, 4) + and appearance = (select max(appearance) from order_status where ouid = orders.ouid) + and executed_quantity = (select max(executed_quantity) from order_status where ouid = orders.ouid) + order by create_date desc limit 1 + ) as open_price, max(taker_price) as high_price, min(taker_price) as low_price, sum(matched_quantity) as volume, - (select id from trades where create_date > :date and symbol=:symbol order by create_date asc limit 1) as first_id, + (select id from trades where create_date > :date and symbol=:symbol order by create_date limit 1) as first_id, (select id from trades where create_date > :date and symbol=:symbol order by create_date desc limit 1) as last_id, count(id) as count from trades as t @@ -114,7 +156,7 @@ interface TradeRepository : ReactiveCrudRepository { select f.start_time as open_time, f.end_time as close_time, - (select taker_price from trades tt where symbol = :symbol and tt.create_date >= f.start_time and tt.create_date < f.end_time order by tt.create_date asc limit 1) as open, + (select taker_price from trades tt where symbol = :symbol and tt.create_date >= f.start_time and tt.create_date < f.end_time order by tt.create_date limit 1) as open, max(t.taker_price) as high, min(t.taker_price) as low, (select taker_price from trades tt where symbol = :symbol and tt.create_date >= f.start_time and tt.create_date < f.end_time order by tt.create_date desc limit 1) as close, diff --git a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/impl/MarketQueryHandlerImpl.kt b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/impl/MarketQueryHandlerImpl.kt index 3949cac00..4f87631b7 100644 --- a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/impl/MarketQueryHandlerImpl.kt +++ b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/impl/MarketQueryHandlerImpl.kt @@ -4,8 +4,10 @@ import co.nilin.opex.api.core.inout.* import co.nilin.opex.api.core.spi.MarketQueryHandler import co.nilin.opex.api.core.spi.SymbolMapper import co.nilin.opex.api.ports.postgres.dao.OrderRepository +import co.nilin.opex.api.ports.postgres.dao.OrderStatusRepository import co.nilin.opex.api.ports.postgres.dao.TradeRepository import co.nilin.opex.api.ports.postgres.model.OrderModel +import co.nilin.opex.api.ports.postgres.model.OrderStatusModel import co.nilin.opex.api.ports.postgres.model.TradeTickerData import co.nilin.opex.api.ports.postgres.util.* import co.nilin.opex.matching.engine.core.model.OrderDirection @@ -15,6 +17,7 @@ import kotlinx.coroutines.reactive.awaitFirst import kotlinx.coroutines.reactive.awaitFirstOrElse import kotlinx.coroutines.reactive.awaitFirstOrNull import org.springframework.stereotype.Component +import java.math.BigDecimal import java.time.Instant import java.time.LocalDateTime import java.time.ZoneId @@ -27,6 +30,7 @@ import kotlin.math.min class MarketQueryHandlerImpl( private val orderRepository: OrderRepository, private val tradeRepository: TradeRepository, + private val orderStatusRepository: OrderStatusRepository, private val symbolMapper: SymbolMapper, ) : MarketQueryHandler { @@ -72,9 +76,9 @@ class MarketQueryHandlerImpl( } override suspend fun lastOrder(symbol: String): QueryOrderResponse? { - return orderRepository.findLastOrderBySymbol(symbol) - .awaitFirstOrNull() - ?.asQueryOrderResponse() + val order = orderRepository.findLastOrderBySymbol(symbol).awaitFirstOrNull() ?: return null + val status = orderStatusRepository.findMostRecentByOUID(order.ouid).awaitFirstOrNull() + return order.asQueryOrderResponse(status) } override suspend fun recentTrades(symbol: String, limit: Int): Flow { @@ -168,7 +172,7 @@ class MarketQueryHandlerImpl( } } - private fun OrderModel.asQueryOrderResponse() = QueryOrderResponse( + private fun OrderModel.asQueryOrderResponse(orderStatusModel: OrderStatusModel?) = QueryOrderResponse( symbol, ouid, orderId ?: -1, @@ -176,9 +180,9 @@ class MarketQueryHandlerImpl( clientOrderId ?: "", price!!.toBigDecimal(), quantity!!.toBigDecimal(), - executedQuantity!!.toBigDecimal(), - (accumulativeQuoteQty ?: 0.0).toBigDecimal(), - status!!.toOrderStatus(), + orderStatusModel?.executedQuantity?.toBigDecimal() ?: BigDecimal.ZERO, + orderStatusModel?.accumulativeQuoteQty?.toBigDecimal() ?: BigDecimal.ZERO, + orderStatusModel?.status?.toOrderStatus() ?: OrderStatus.NEW, constraint!!.toTimeInForce(), type!!.toApiOrderType(), direction!!.toOrderSide(), @@ -186,7 +190,7 @@ class MarketQueryHandlerImpl( null, Date.from(createDate!!.atZone(ZoneId.systemDefault()).toInstant()), Date.from(updateDate.atZone(ZoneId.systemDefault()).toInstant()), - status.toOrderStatus().isWorking(), + (orderStatusModel?.status?.toOrderStatus() ?: OrderStatus.NEW).isWorking(), quoteQuantity!!.toBigDecimal() ) diff --git a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/impl/OrderPersisterImpl.kt b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/impl/OrderPersisterImpl.kt index 2cac898de..45b7f1049 100644 --- a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/impl/OrderPersisterImpl.kt +++ b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/impl/OrderPersisterImpl.kt @@ -1,88 +1,74 @@ package co.nilin.opex.api.ports.postgres.impl +import co.nilin.opex.accountant.core.inout.OrderStatus import co.nilin.opex.accountant.core.inout.RichOrder -import co.nilin.opex.accountant.core.inout.comesAfter +import co.nilin.opex.accountant.core.inout.RichOrderUpdate import co.nilin.opex.api.core.spi.OrderPersister import co.nilin.opex.api.ports.postgres.dao.OrderRepository +import co.nilin.opex.api.ports.postgres.dao.OrderStatusRepository import co.nilin.opex.api.ports.postgres.model.OrderModel +import co.nilin.opex.api.ports.postgres.model.OrderStatusModel import kotlinx.coroutines.reactive.awaitFirstOrNull +import org.slf4j.LoggerFactory import org.springframework.stereotype.Component import java.time.LocalDateTime @Component -class OrderPersisterImpl(val orderRepository: OrderRepository) : OrderPersister { +class OrderPersisterImpl( + private val orderRepository: OrderRepository, + private val orderStatusRepository: OrderStatusRepository +) : OrderPersister { + + private val logger = LoggerFactory.getLogger(OrderPersisterImpl::class.java) + override suspend fun save(order: RichOrder) { - var alreadySaved = false - val existingOrder = orderRepository - .findByOuid(order.ouid) - .awaitFirstOrNull() - if (existingOrder == null - || existingOrder.executedQuantity?.compareTo(order.executedQuantity.toDouble()) == -1 - || order.status.comesAfter(existingOrder.status) - ) { - alreadySaved = true - orderRepository.save( - OrderModel( - existingOrder?.id, - order.ouid, - order.uuid, - null, - order.pair, - order.orderId, - order.makerFee.toDouble(), - order.takerFee.toDouble(), - order.leftSideFraction.toDouble(), - order.rightSideFraction.toDouble(), - order.userLevel, - order.direction, - order.constraint, - order.type, - existingOrder?.price ?: order.price.toDouble(), - existingOrder?.quantity ?: order.quantity.toDouble(), - existingOrder?.quoteQuantity ?: order.quoteQuantity.toDouble(), - existingOrder?.executedQuantity ?: order.executedQuantity.toDouble(), - existingOrder?.accumulativeQuoteQty ?: order.accumulativeQuoteQty.toDouble(), - order.status, - existingOrder?.createDate ?: LocalDateTime.now(), - LocalDateTime.now() - ) - ).awaitFirstOrNull() - } + orderRepository.save( + OrderModel( + null, + order.ouid, + order.uuid, + null, + order.pair, + order.orderId, + order.makerFee.toDouble(), + order.takerFee.toDouble(), + order.leftSideFraction.toDouble(), + order.rightSideFraction.toDouble(), + order.userLevel, + order.direction, + order.constraint, + order.type, + order.price.toDouble(), + order.quantity.toDouble(), + order.quoteQuantity.toDouble(), + LocalDateTime.now(), + LocalDateTime.now() + ) + ).awaitFirstOrNull() + logger.info("order ${order.ouid} saved") + + orderStatusRepository.save( + OrderStatusModel( + order.ouid, + order.executedQuantity.toDouble(), + order.accumulativeQuoteQty.toDouble(), + OrderStatus.NEW.code, + OrderStatus.NEW.orderOfAppearance + ) + ).awaitFirstOrNull() + logger.info("OrderStatus ${order.ouid} saved with status of 'NEW'") + } - existingOrder?.apply { - if ( - !alreadySaved && - (makerFee == null || takerFee == null || leftSideFraction == null - || rightSideFraction == null || constraint == null || type == null) - ) { - orderRepository.save( - OrderModel( - existingOrder.id, - existingOrder.ouid, - existingOrder.uuid, - null, - existingOrder.symbol, - existingOrder.orderId, - order.makerFee.toDouble(), - order.takerFee.toDouble(), - order.leftSideFraction.toDouble(), - order.rightSideFraction.toDouble(), - order.userLevel, - order.direction, - order.constraint, - order.type, - existingOrder.price, - existingOrder.quantity, - existingOrder.quoteQuantity, - existingOrder.executedQuantity, - existingOrder.accumulativeQuoteQty, - existingOrder.status, - existingOrder.createDate ?: LocalDateTime.now(), - existingOrder.updateDate, - existingOrder.version - ) - ).awaitFirstOrNull() - } - } + override suspend fun update(orderUpdate: RichOrderUpdate) { + orderStatusRepository.save( + OrderStatusModel( + orderUpdate.ouid, + orderUpdate.executedQuantity().toDouble(), + orderUpdate.accumulativeQuoteQuantity().toDouble(), + orderUpdate.status.code, + orderUpdate.status.orderOfAppearance + ) + ).awaitFirstOrNull() + logger.info("OrderStatus ${orderUpdate.ouid} updated with status of ${orderUpdate.status}") } } \ No newline at end of file diff --git a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/impl/TradePersisterImpl.kt b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/impl/TradePersisterImpl.kt index f4c34149e..309cf9488 100644 --- a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/impl/TradePersisterImpl.kt +++ b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/impl/TradePersisterImpl.kt @@ -1,25 +1,22 @@ package co.nilin.opex.api.ports.postgres.impl -import co.nilin.opex.accountant.core.inout.OrderStatus import co.nilin.opex.accountant.core.inout.RichTrade -import co.nilin.opex.accountant.core.inout.comesBefore import co.nilin.opex.api.core.spi.TradePersister -import co.nilin.opex.api.ports.postgres.dao.OrderRepository import co.nilin.opex.api.ports.postgres.dao.TradeRepository -import co.nilin.opex.api.ports.postgres.model.OrderModel import co.nilin.opex.api.ports.postgres.model.TradeModel import kotlinx.coroutines.reactive.awaitFirstOrNull +import org.slf4j.LoggerFactory import org.springframework.stereotype.Component import org.springframework.transaction.annotation.Transactional -import java.math.BigDecimal import java.time.LocalDateTime @Component -class TradePersisterImpl(val tradeRepository: TradeRepository, val orderRepository: OrderRepository) : TradePersister { +class TradePersisterImpl(private val tradeRepository: TradeRepository) : TradePersister { + + private val logger = LoggerFactory.getLogger(TradePersisterImpl::class.java) @Transactional override suspend fun save(trade: RichTrade) { - println("RichTrade save") tradeRepository.save( TradeModel( null, @@ -40,110 +37,6 @@ class TradePersisterImpl(val tradeRepository: TradeRepository, val orderReposito LocalDateTime.now() ) ).awaitFirstOrNull() - println("RichTrade save/update maker order") - saveMakerOrder(trade) - println("RichTrade save/update taker order") - saveTakerOrder(trade) - - } - - private suspend fun saveTakerOrder(trade: RichTrade) { - val existingOrder = orderRepository - .findByOuid(trade.takerOuid) - .awaitFirstOrNull() - - val executedQuantity = (trade.takerQuantity.minus(trade.takerRemainedQuantity)).toDouble() - val status = if (trade.takerRemainedQuantity.compareTo(BigDecimal.ZERO) == 0) { - OrderStatus.FILLED.code - } else { - OrderStatus.PARTIALLY_FILLED.code - } - - if (existingOrder == null || existingOrder.status.comesBefore(status) || (existingOrder.executedQuantity - ?: 0.0) < executedQuantity - ) - orderRepository.save( - OrderModel( - existingOrder?.id, - trade.takerOuid, - trade.takerUuid, - null, - trade.pair, - trade.takerOrderId, - existingOrder?.makerFee, - existingOrder?.takerFee, - existingOrder?.leftSideFraction, - existingOrder?.rightSideFraction, - existingOrder?.userLevel, - trade.takerDirection, - existingOrder?.constraint, - existingOrder?.type, - trade.takerPrice.toDouble(), - trade.takerQuantity.toDouble(), - trade.takerQuoteQuantity.toDouble(), - (trade.takerQuantity.minus(trade.takerRemainedQuantity)).toDouble(), - trade.takerPrice.multiply( - (trade.takerQuantity.minus(trade.takerRemainedQuantity)) - ).toDouble(), - if (trade.takerRemainedQuantity.compareTo(BigDecimal.ZERO) == 0) { - OrderStatus.FILLED.code - } else { - OrderStatus.PARTIALLY_FILLED.code - }, - existingOrder?.createDate, - LocalDateTime.now(), - existingOrder?.version - ) - ).awaitFirstOrNull() - } - - private suspend fun saveMakerOrder(trade: RichTrade) { - val existingOrder = orderRepository - .findByOuid(trade.makerOuid) - .awaitFirstOrNull() - - val executedQuantity = (trade.makerQuantity.minus(trade.makerRemainedQuantity)).toDouble() - val status = if (trade.makerRemainedQuantity.compareTo(BigDecimal.ZERO) == 0) { - OrderStatus.FILLED.code - } else { - OrderStatus.PARTIALLY_FILLED.code - } - - if (existingOrder == null || existingOrder.status.comesBefore(status) || (existingOrder.executedQuantity - ?: 0.0) < executedQuantity - ) - orderRepository.save( - OrderModel( - existingOrder?.id, - trade.makerOuid, - trade.makerUuid, - null, - trade.pair, - trade.makerOrderId, - existingOrder?.makerFee, - existingOrder?.takerFee, - existingOrder?.leftSideFraction, - existingOrder?.rightSideFraction, - existingOrder?.userLevel, - trade.makerDirection, - existingOrder?.constraint, - existingOrder?.type, - trade.makerPrice.toDouble(), - trade.makerQuantity.toDouble(), - trade.makerQuoteQuantity.toDouble(), - (trade.makerQuantity.minus(trade.makerRemainedQuantity)).toDouble(), - trade.makerPrice.multiply( - (trade.makerQuantity.minus(trade.makerRemainedQuantity)) - ).toDouble(), - if (trade.makerRemainedQuantity.compareTo(BigDecimal.ZERO) == 0) { - OrderStatus.FILLED.code - } else { - OrderStatus.PARTIALLY_FILLED.code - }, - existingOrder?.createDate ?: LocalDateTime.now(), - LocalDateTime.now(), - existingOrder?.version - ) - ).awaitFirstOrNull() + logger.info("RichTrade ${trade.id} saved") } } \ No newline at end of file diff --git a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/impl/UserQueryHandlerImpl.kt b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/impl/UserQueryHandlerImpl.kt index 36cd34eaa..8088bc2fc 100644 --- a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/impl/UserQueryHandlerImpl.kt +++ b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/impl/UserQueryHandlerImpl.kt @@ -3,8 +3,10 @@ package co.nilin.opex.api.ports.postgres.impl import co.nilin.opex.api.core.inout.* import co.nilin.opex.api.core.spi.UserQueryHandler import co.nilin.opex.api.ports.postgres.dao.OrderRepository +import co.nilin.opex.api.ports.postgres.dao.OrderStatusRepository import co.nilin.opex.api.ports.postgres.dao.TradeRepository import co.nilin.opex.api.ports.postgres.model.OrderModel +import co.nilin.opex.api.ports.postgres.model.OrderStatusModel import co.nilin.opex.api.ports.postgres.util.* import co.nilin.opex.matching.engine.core.model.OrderDirection import co.nilin.opex.utility.error.data.OpexError @@ -15,14 +17,16 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.reactive.awaitFirst import kotlinx.coroutines.reactive.awaitFirstOrNull import org.springframework.stereotype.Component +import java.math.BigDecimal import java.security.Principal import java.time.ZoneId import java.util.* @Component class UserQueryHandlerImpl( - val orderRepository: OrderRepository, - val tradeRepository: TradeRepository + private val orderRepository: OrderRepository, + private val tradeRepository: TradeRepository, + private val orderStatusRepository: OrderStatusRepository ) : UserQueryHandler { override suspend fun queryOrder(principal: Principal, request: QueryOrderRequest): QueryOrderResponse? { @@ -31,13 +35,12 @@ class UserQueryHandlerImpl( } else { orderRepository.findBySymbolAndOrderId(request.symbol, request.orderId!!) - }).awaitFirstOrNull() - if (order?.constraint != null) { - if (order.uuid != principal.name) - throw OpexException(OpexError.Forbidden) - return orderToQueryResponse(order) - } - return null + }).awaitFirstOrNull() ?: return null + + if (order.uuid != principal.name) + throw OpexException(OpexError.Forbidden) + + return order.asQueryResponse(orderStatusRepository.findMostRecentByOUID(order.ouid).awaitFirstOrNull()) } override suspend fun openOrders(principal: Principal, symbol: String?): Flow { @@ -46,7 +49,7 @@ class UserQueryHandlerImpl( symbol, listOf(OrderStatus.NEW.code, OrderStatus.PARTIALLY_FILLED.code) ).filter { orderModel -> orderModel.constraint != null } - .map { order -> orderToQueryResponse(order) } + .map { it.asQueryResponse(orderStatusRepository.findMostRecentByOUID(it.ouid).awaitFirstOrNull()) } } override suspend fun allOrders(principal: Principal, allOrderRequest: AllOrderRequest): Flow { @@ -56,7 +59,7 @@ class UserQueryHandlerImpl( allOrderRequest.startTime, allOrderRequest.endTime ).filter { orderModel -> orderModel.constraint != null } - .map { order -> orderToQueryResponse(order) } + .map { it.asQueryResponse(orderStatusRepository.findMostRecentByOUID(it.ouid).awaitFirstOrNull()) } } override suspend fun allTrades(principal: Principal, request: TradeRequest): Flow { @@ -112,24 +115,25 @@ class UserQueryHandlerImpl( } - private fun orderToQueryResponse(order: OrderModel) = QueryOrderResponse( - order.symbol, - order.ouid, - order.orderId ?: -1, + private fun OrderModel.asQueryResponse(orderStatusModel: OrderStatusModel?) = QueryOrderResponse( + symbol, + ouid, + orderId ?: -1, -1, - order.clientOrderId ?: "", - order.price!!.toBigDecimal(), - order.quantity!!.toBigDecimal(), - order.executedQuantity!!.toBigDecimal(), - (order.accumulativeQuoteQty ?: 0.0).toBigDecimal(), - order.status!!.toOrderStatus(), - order.constraint!!.toTimeInForce(), - order.type!!.toApiOrderType(), - order.direction!!.toOrderSide(), + clientOrderId ?: "", + price!!.toBigDecimal(), + quantity!!.toBigDecimal(), + orderStatusModel?.executedQuantity?.toBigDecimal() ?: BigDecimal.ZERO, + orderStatusModel?.accumulativeQuoteQty?.toBigDecimal() ?: BigDecimal.ZERO, + orderStatusModel?.status?.toOrderStatus() ?: OrderStatus.NEW, + constraint!!.toTimeInForce(), + type!!.toApiOrderType(), + direction!!.toOrderSide(), null, null, - Date.from(order.createDate!!.atZone(ZoneId.systemDefault()).toInstant()), - Date.from(order.updateDate.atZone(ZoneId.systemDefault()).toInstant()), - order.status.toOrderStatus().isWorking(), order.quoteQuantity!!.toBigDecimal() + Date.from(createDate!!.atZone(ZoneId.systemDefault()).toInstant()), + Date.from(updateDate.atZone(ZoneId.systemDefault()).toInstant()), + (orderStatusModel?.status?.toOrderStatus() ?: OrderStatus.NEW).isWorking(), + quoteQuantity!!.toBigDecimal() ) } \ No newline at end of file diff --git a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/model/OrderModel.kt b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/model/OrderModel.kt index 987a9e264..b0a44a50b 100644 --- a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/model/OrderModel.kt +++ b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/model/OrderModel.kt @@ -1,6 +1,5 @@ package co.nilin.opex.api.ports.postgres.model - import co.nilin.opex.matching.engine.core.model.MatchConstraint import co.nilin.opex.matching.engine.core.model.OrderDirection import co.nilin.opex.matching.engine.core.model.OrderType @@ -31,9 +30,6 @@ class OrderModel( @Column("price") val price: Double?, @Column("quantity") val quantity: Double?, @Column("quote_quantity") val quoteQuantity: Double?, - @Column("executed_qty") val executedQuantity: Double?, - @Column("accumulative_quote_qty") val accumulativeQuoteQty: Double?, - @Column("status") val status: Int?, @Column("create_date") val createDate: LocalDateTime?, @Column("update_date") val updateDate: LocalDateTime, @Version diff --git a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/model/OrderStatusModel.kt b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/model/OrderStatusModel.kt new file mode 100644 index 000000000..7f8aee3b0 --- /dev/null +++ b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/model/OrderStatusModel.kt @@ -0,0 +1,17 @@ +package co.nilin.opex.api.ports.postgres.model + +import org.springframework.data.annotation.Id +import org.springframework.data.relational.core.mapping.Table +import java.time.LocalDateTime + +@Table("order_status") +data class OrderStatusModel( + val ouid: String, + val executedQuantity: Double?, + val accumulativeQuoteQty: Double?, + val status: Int, + val appearance: Int, + val date: LocalDateTime = LocalDateTime.now(), + @Id + var id: Long? = null +) \ No newline at end of file diff --git a/api/api-ports/api-persister-postgres/src/main/resources/data.sql b/api/api-ports/api-persister-postgres/src/main/resources/data.sql index db62b7fed..5039b0d01 100644 --- a/api/api-ports/api-persister-postgres/src/main/resources/data.sql +++ b/api/api-ports/api-persister-postgres/src/main/resources/data.sql @@ -1,8 +1,7 @@ -INSERT INTO - symbol_maps(symbol, value) -VALUES - ('btc_usdt', 'BTCUSDT'), - ('eth_usdt', 'ETHUSDT'), - ('eth_btc', 'ETHBTC'), - ('nln_usdt', 'NLNUSDT'), - ('nln_btc', 'NLNBTC') ON CONFLICT DO NOTHING; +INSERT INTO symbol_maps(symbol, value) +VALUES ('btc_usdt', 'BTCUSDT'), + ('eth_usdt', 'ETHUSDT'), + ('eth_btc', 'ETHBTC'), + ('nln_usdt', 'NLNUSDT'), + ('nln_btc', 'NLNBTC') +ON CONFLICT DO NOTHING; diff --git a/api/api-ports/api-persister-postgres/src/main/resources/schema.sql b/api/api-ports/api-persister-postgres/src/main/resources/schema.sql index a3b1c4491..497ccb398 100644 --- a/api/api-ports/api-persister-postgres/src/main/resources/schema.sql +++ b/api/api-ports/api-persister-postgres/src/main/resources/schema.sql @@ -1,71 +1,86 @@ -CREATE TABLE IF NOT EXISTS orders ( - id SERIAL PRIMARY KEY, - ouid VARCHAR(72) NOT NULL UNIQUE, - uuid VARCHAR(72) NOT NULL, - client_order_id VARCHAR(72), - symbol VARCHAR(20) NOT NULL, - order_id INTEGER, - maker_fee DECIMAL, - taker_fee DECIMAL, - left_side_fraction DECIMAL, - right_side_fraction DECIMAL, - user_level VARCHAR(20), - side VARCHAR(20), - match_constraint VARCHAR(20), - order_type VARCHAR(20), - price DECIMAL, - quantity DECIMAL, - quote_quantity DECIMAL, - executed_qty DECIMAL, - accumulative_quote_qty DECIMAL, - status INTEGER, - create_date TIMESTAMP, - update_date TIMESTAMP NOT NULL, - version INTEGER +CREATE TABLE IF NOT EXISTS orders +( + id SERIAL PRIMARY KEY, + ouid VARCHAR(72) NOT NULL UNIQUE, + uuid VARCHAR(72) NOT NULL, + client_order_id VARCHAR(72), + symbol VARCHAR(20) NOT NULL, + order_id INTEGER, + maker_fee DECIMAL, + taker_fee DECIMAL, + left_side_fraction DECIMAL, + right_side_fraction DECIMAL, + user_level VARCHAR(20), + side VARCHAR(20), + match_constraint VARCHAR(20), + order_type VARCHAR(20), + price DECIMAL, + quantity DECIMAL, + quote_quantity DECIMAL, + create_date TIMESTAMP, + update_date TIMESTAMP NOT NULL, + version INTEGER ); -CREATE TABLE IF NOT EXISTS trades ( - id SERIAL PRIMARY KEY, - trade_id INTEGER NOT NULL, - symbol VARCHAR(20) NOT NULL, - matched_quantity DECIMAL NOT NULL, - taker_price DECIMAL NOT NULL, - maker_price DECIMAL NOT NULL, - taker_commision DECIMAL, - maker_commision DECIMAL, - taker_commision_asset VARCHAR(20), - maker_commision_asset VARCHAR(20), - trade_date TIMESTAMP NOT NULL, - maker_ouid VARCHAR(72) NOT NULL, - taker_ouid VARCHAR(72) NOT NULL, - maker_uuid VARCHAR(72) NOT NULL, - taker_uuid VARCHAR(72) NOT NULL, - create_date TIMESTAMP +CREATE TABLE IF NOT EXISTS order_status +( + id SERIAL PRIMARY KEY, + ouid VARCHAR(72) NOT NULL, + executed_quantity DECIMAL, + accumulative_quote_qty DECIMAL, + status INTEGER NOT NULL, + appearance INTEGER NOT NULL, + date TIMESTAMP NOT NULL, + UNIQUE (ouid, status, appearance, executed_quantity) ); -CREATE TABLE IF NOT EXISTS symbol_maps ( - symbol VARCHAR(72) PRIMARY KEY, - value VARCHAR(72) UNIQUE NOT NULL +CREATE TABLE IF NOT EXISTS trades +( + id SERIAL PRIMARY KEY, + trade_id INTEGER NOT NULL, + symbol VARCHAR(20) NOT NULL, + matched_quantity DECIMAL NOT NULL, + taker_price DECIMAL NOT NULL, + maker_price DECIMAL NOT NULL, + taker_commision DECIMAL, + maker_commision DECIMAL, + taker_commision_asset VARCHAR(20), + maker_commision_asset VARCHAR(20), + trade_date TIMESTAMP NOT NULL, + maker_ouid VARCHAR(72) NOT NULL, + taker_ouid VARCHAR(72) NOT NULL, + maker_uuid VARCHAR(72) NOT NULL, + taker_uuid VARCHAR(72) NOT NULL, + create_date TIMESTAMP +); + +CREATE TABLE IF NOT EXISTS symbol_maps +( + symbol VARCHAR(72) PRIMARY KEY, + value VARCHAR(72) UNIQUE NOT NULL ); CREATE OR REPLACE FUNCTION interval_generator( - start_ts TIMESTAMP without TIME ZONE, - end_ts TIMESTAMP without TIME ZONE, - round_interval INTERVAL -) RETURNS TABLE( - start_time TIMESTAMP without TIME ZONE, - end_time TIMESTAMP without TIME ZONE -) as $$ BEGIN - RETURN QUERY - SELECT - (n) start_time, - (n + round_interval) end_time - FROM - generate_series( - date_trunc('minute', start_ts), - end_ts, - round_interval - ) n; + start_ts TIMESTAMP without TIME ZONE, + end_ts TIMESTAMP without TIME ZONE, + round_interval INTERVAL +) + RETURNS TABLE + ( + start_time TIMESTAMP without TIME ZONE, + end_time TIMESTAMP without TIME ZONE + ) +as +$$ +BEGIN + RETURN QUERY + SELECT (n) start_time, + (n + round_interval) end_time + FROM generate_series( + date_trunc('minute', start_ts), + end_ts, + round_interval + ) n; END; $$ LANGUAGE 'plpgsql'; diff --git a/api/pom.xml b/api/pom.xml index d5b6f4589..baf80f4cb 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -77,6 +77,13 @@ interceptors ${project.version} + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + diff --git a/bc-gateway/bc-gateway-app/Dockerfile b/bc-gateway/bc-gateway-app/Dockerfile index f2cbd4c26..7c71f9447 100644 --- a/bc-gateway/bc-gateway-app/Dockerfile +++ b/bc-gateway/bc-gateway-app/Dockerfile @@ -1,5 +1,4 @@ -FROM openjdk:8-jdk-alpine -VOLUME /tmp +FROM openjdk:11 ARG JAR_FILE=target/*.jar COPY ${JAR_FILE} app.jar ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -jar /app.jar"] \ No newline at end of file diff --git a/bc-gateway/bc-gateway-app/mvnw b/bc-gateway/bc-gateway-app/mvnw deleted file mode 100644 index a16b5431b..000000000 --- a/bc-gateway/bc-gateway-app/mvnw +++ /dev/null @@ -1,310 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` - fi - - if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=`cygpath --path --windows "$javaClass"` - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/bc-gateway/bc-gateway-app/mvnw.cmd b/bc-gateway/bc-gateway-app/mvnw.cmd deleted file mode 100644 index c8d43372c..000000000 --- a/bc-gateway/bc-gateway-app/mvnw.cmd +++ /dev/null @@ -1,182 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/bc-gateway/bc-gateway-app/pom.xml b/bc-gateway/bc-gateway-app/pom.xml index 3bbcc3e7c..33b85f648 100644 --- a/bc-gateway/bc-gateway-app/pom.xml +++ b/bc-gateway/bc-gateway-app/pom.xml @@ -14,10 +14,6 @@ bc-gateway-app Blockchain gateway app of Opex - - 2020.0.2 - - org.jetbrains.kotlin @@ -91,6 +87,10 @@ springfox-boot-starter 3.0.0 + + org.springframework.cloud + spring-cloud-starter-vault-config + diff --git a/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt new file mode 100644 index 000000000..f39bf4a89 --- /dev/null +++ b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt @@ -0,0 +1,9 @@ +package co.nilin.opex.util.vault + +import org.springframework.vault.authentication.AppIdUserIdMechanism + +class VaultUserIdMechanism() : AppIdUserIdMechanism { + override fun createUserId(): String { + return System.getenv("BACKEND_USER"); + } +} \ No newline at end of file diff --git a/bc-gateway/bc-gateway-app/src/main/resources/application-docker.yml b/bc-gateway/bc-gateway-app/src/main/resources/application-docker.yml deleted file mode 100644 index bfc84f3bb..000000000 --- a/bc-gateway/bc-gateway-app/src/main/resources/application-docker.yml +++ /dev/null @@ -1,24 +0,0 @@ -server.port: 8095 -spring: - application: - name: opex-bc-gateway - kafka: - bootstrap-servers: ${KAFKA_IP_PORT} - redis: - host: ${REDIS_HOST} - port: 6379 - r2dbc: - url: r2dbc:postgresql://${DB_IP_PORT}/opex_bc_gateway - username: opex - password: hiopex - initialization-mode: always - cloud: - consul: - host: ${CONSUL_HOST} - port: 8500 - -app: - auth: - cert-url: lb://opex-auth/auth/realms/opex/protocol/openid-connect/certs - wallet: - url: lb://opex-wallet diff --git a/bc-gateway/bc-gateway-app/src/main/resources/application.yml b/bc-gateway/bc-gateway-app/src/main/resources/application.yml index c1698dc75..6c13ce0e2 100644 --- a/bc-gateway/bc-gateway-app/src/main/resources/application.yml +++ b/bc-gateway/bc-gateway-app/src/main/resources/application.yml @@ -1,33 +1,54 @@ -server.port: 8095 +server.port: 8080 spring: application: name: opex-bc-gateway main: allow-bean-definition-overriding: false kafka: - bootstrap-servers: localhost:2181 + bootstrap-servers: ${KAFKA_IP_PORT:localhost:9092} consumer: group-id: opex-bc-gateway redis: - host: 127.0.0.1 + host: ${REDIS_HOST:localhost} port: 6379 r2dbc: - url: r2dbc:postgresql://localhost/opex_bc_gateway - username: opex - password: hiopex + url: r2dbc:postgresql://${DB_IP_PORT:localhost}/opex_bc_gateway + username: ${dbusername:opex} + password: ${dbpassword:hiopex} initialization-mode: always cloud: bootstrap: enabled: true + vault: + host: ${VAULT_HOST} + port: 8200 + scheme: http + authentication: APPID + app-id: + user-id: co.nilin.opex.util.vault.VaultUserIdMechanism + fail-fast: true + kv: + enabled: true + backend: secret + profile-separator: '/' + application-name: ${spring.application.name} consul: + host: ${CONSUL_HOST:localhost} port: 8500 discovery: #healthCheckPath: ${management.context-path}/health instance-id: ${spring.application.name}:${server.port} healthCheckInterval: 20s prefer-ip-address: true + config: + import: vault://secret/${spring.application.name} logging: level: org.apache.kafka: DEBUG swagger.authUrl: https://api.opex.dev +app: + auth: + cert-url: lb://opex-auth/auth/realms/opex/protocol/openid-connect/certs + wallet: + url: lb://opex-wallet \ No newline at end of file diff --git a/bc-gateway/bc-gateway-core/mvnw b/bc-gateway/bc-gateway-core/mvnw deleted file mode 100644 index a16b5431b..000000000 --- a/bc-gateway/bc-gateway-core/mvnw +++ /dev/null @@ -1,310 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` - fi - - if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=`cygpath --path --windows "$javaClass"` - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/bc-gateway/bc-gateway-core/mvnw.cmd b/bc-gateway/bc-gateway-core/mvnw.cmd deleted file mode 100644 index c8d43372c..000000000 --- a/bc-gateway/bc-gateway-core/mvnw.cmd +++ /dev/null @@ -1,182 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/bc-gateway/bc-gateway-core/pom.xml b/bc-gateway/bc-gateway-core/pom.xml index fa6b76aa0..619be8c6d 100644 --- a/bc-gateway/bc-gateway-core/pom.xml +++ b/bc-gateway/bc-gateway-core/pom.xml @@ -15,7 +15,7 @@ Blockchain gateway core of Opex - 3.2.0 + 4.0.0 @@ -48,6 +48,7 @@ org.mockito.kotlin mockito-kotlin ${mockito-kotlin.version} + test co.nilin.opex.utility.error diff --git a/bc-gateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/service/ChainSyncServiceImpl.kt b/bc-gateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/service/ChainSyncServiceImpl.kt index d51df1618..2d81c6c0e 100644 --- a/bc-gateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/service/ChainSyncServiceImpl.kt +++ b/bc-gateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/service/ChainSyncServiceImpl.kt @@ -9,7 +9,6 @@ import org.slf4j.LoggerFactory import org.springframework.transaction.reactive.TransactionalOperator import org.springframework.transaction.reactive.executeAndAwait import java.time.LocalDateTime -import java.time.temporal.ChronoUnit import kotlin.coroutines.coroutineContext open class ChainSyncServiceImpl( diff --git a/bc-gateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/ChainSyncRetryHandler.kt b/bc-gateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/ChainSyncRetryHandler.kt index fe13da718..bd5e9d938 100644 --- a/bc-gateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/ChainSyncRetryHandler.kt +++ b/bc-gateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/ChainSyncRetryHandler.kt @@ -5,6 +5,6 @@ import co.nilin.opex.bcgateway.core.model.ChainSyncSchedule interface ChainSyncRetryHandler { - suspend fun handleNextTry(syncSchedule: ChainSyncSchedule, records: ChainSyncRecord, sentBlock:Long) + suspend fun handleNextTry(syncSchedule: ChainSyncSchedule, records: ChainSyncRecord, sentBlock: Long) } \ No newline at end of file diff --git a/bc-gateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/ChainSyncSchedulerHandler.kt b/bc-gateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/ChainSyncSchedulerHandler.kt index b798d037b..223702b6c 100644 --- a/bc-gateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/ChainSyncSchedulerHandler.kt +++ b/bc-gateway/bc-gateway-core/src/main/kotlin/co/nilin/opex/bcgateway/core/spi/ChainSyncSchedulerHandler.kt @@ -5,5 +5,5 @@ import java.time.LocalDateTime interface ChainSyncSchedulerHandler { suspend fun fetchActiveSchedules(time: LocalDateTime): List - suspend fun prepareScheduleForNextTry(syncSchedule: ChainSyncSchedule, success:Boolean) + suspend fun prepareScheduleForNextTry(syncSchedule: ChainSyncSchedule, success: Boolean) } diff --git a/bc-gateway/bc-gateway-core/src/test/kotlin/co/nilin/opex/bcgateway/core/service/ChainSyncServiceImplTest.kt b/bc-gateway/bc-gateway-core/src/test/kotlin/co/nilin/opex/bcgateway/core/service/ChainSyncServiceImplTest.kt index 258080a8e..c7b60af47 100644 --- a/bc-gateway/bc-gateway-core/src/test/kotlin/co/nilin/opex/bcgateway/core/service/ChainSyncServiceImplTest.kt +++ b/bc-gateway/bc-gateway-core/src/test/kotlin/co/nilin/opex/bcgateway/core/service/ChainSyncServiceImplTest.kt @@ -11,9 +11,11 @@ import org.junit.jupiter.api.Test import org.mockito.Mock import org.mockito.Mockito import org.mockito.MockitoAnnotations -import org.mockito.kotlin.* +import org.mockito.kotlin.any +import org.mockito.kotlin.mock +import org.mockito.kotlin.verify +import org.mockito.kotlin.verifyNoMoreInteractions import java.time.LocalDateTime -import java.time.temporal.ChronoUnit import java.util.concurrent.Executors internal class ChainSyncServiceImplTest { @@ -75,7 +77,7 @@ internal class ChainSyncServiceImplTest { syncService.startSyncWithChain() //then - verifyZeroInteractions( + verifyNoMoreInteractions( chainEndpointProxyFinder, chainSyncRecordHandler, walletSyncRecordHandler, diff --git a/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/mvnw b/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/mvnw deleted file mode 100644 index a16b5431b..000000000 --- a/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/mvnw +++ /dev/null @@ -1,310 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` - fi - - if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=`cygpath --path --windows "$javaClass"` - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/mvnw.cmd b/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/mvnw.cmd deleted file mode 100644 index c8d43372c..000000000 --- a/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/mvnw.cmd +++ /dev/null @@ -1,182 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/bcgateway/ports/postgres/dao/ChainSyncRecordRepository.kt b/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/bcgateway/ports/postgres/dao/ChainSyncRecordRepository.kt index 12da446f5..c3fef63e4 100644 --- a/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/bcgateway/ports/postgres/dao/ChainSyncRecordRepository.kt +++ b/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/bcgateway/ports/postgres/dao/ChainSyncRecordRepository.kt @@ -18,7 +18,7 @@ interface ChainSyncRecordRepository : ReactiveCrudRepository + ): Mono fun findByChain(chain: String): Mono } diff --git a/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/resources/data.sql b/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/resources/data.sql index 21208c2da..8f4e93d4b 100644 --- a/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/resources/data.sql +++ b/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/resources/data.sql @@ -1,170 +1,262 @@ -INSERT INTO - currency -VALUES - ('BTC', 'Bitcoin'), - ('ETH', 'Ethereum'), - ('USDT', 'Tether') ON CONFLICT DO NOTHING; +INSERT INTO currency +VALUES ('BTC', 'Bitcoin'), + ('ETH', 'Ethereum'), + ('USDT', 'Tether') +ON CONFLICT DO NOTHING; -INSERT INTO - chains -VALUES - ('bitcoin'), - ('ethereum'), - ('bsc') ON CONFLICT DO NOTHING; +INSERT INTO chains +VALUES ('bitcoin'), + ('ethereum'), + ('bsc') +ON CONFLICT DO NOTHING; -INSERT INTO - address_types(id, address_type, address_regex) -VALUES - (1, 'bitcoin', '.*'), - (2, 'ethereum', '.*') ON CONFLICT DO NOTHING; +INSERT INTO address_types(id, address_type, address_regex) +VALUES (1, 'bitcoin', '.*'), + (2, 'ethereum', '.*') +ON CONFLICT DO NOTHING; SELECT setval(pg_get_serial_sequence('address_types', 'id'), (SELECT MAX(id) FROM address_types)); -INSERT INTO - chain_address_types(chain_name, addr_type_id) -VALUES - ('bitcoin', 1), - ('ethereum', 2) ON CONFLICT DO NOTHING; +INSERT INTO chain_address_types(chain_name, addr_type_id) +VALUES ('bitcoin', 1), + ('ethereum', 2) +ON CONFLICT DO NOTHING; -INSERT INTO - currency_implementations( - id, - symbol, - chain, - token, - token_address, - token_name, - withdraw_enabled, - withdraw_fee, - withdraw_min, - decimal - ) -VALUES - (1, 'BTC', 'bitcoin', false, null, null, true, 0.0001, 0.0001, 0), - (2, 'ETH', 'ethereum', false, null, null, true, 0.00001, 0.000001, 18), - (3, 'USDT', 'ethereum', true, '0x110a13fc3efe6a245b50102d2d79b3e76125ae83', 'USDT', true, 0.01, 0.01, 6) ON CONFLICT DO NOTHING; +INSERT INTO currency_implementations(id, + symbol, + chain, + token, + token_address, + token_name, + withdraw_enabled, + withdraw_fee, + withdraw_min, + decimal) +VALUES (1, 'BTC', 'bitcoin', false, null, null, true, 0.0001, 0.0001, 0), + (2, 'ETH', 'ethereum', false, null, null, true, 0.00001, 0.000001, 18), + (3, 'USDT', 'ethereum', true, '0x110a13fc3efe6a245b50102d2d79b3e76125ae83', 'USDT', true, 0.01, 0.01, 6) +ON CONFLICT DO NOTHING; SELECT setval(pg_get_serial_sequence('currency_implementations', 'id'), (SELECT MAX(id) FROM currency_implementations)); -INSERT INTO - chain_endpoints(id, chain_name, endpoint_url) -VALUES - (1, 'bitcoin', 'http://host.docker.internal:9990/bitcoin/transfers'), - (2, 'ethereum', 'http://host.docker.internal:9990/eth/transfers') ON CONFLICT DO NOTHING; +INSERT INTO chain_endpoints(id, chain_name, endpoint_url) +VALUES (1, 'bitcoin', 'lb://gateway/bitcoin/transfers'), + (2, 'ethereum', 'lb://gateway/eth/transfers') +ON CONFLICT DO NOTHING; -INSERT INTO - chain_sync_schedules -VALUES - ('bitcoin', CURRENT_DATE, 600, 60), - ('ethereum', CURRENT_DATE, 90, 60) ON CONFLICT DO NOTHING; +INSERT INTO chain_sync_schedules +VALUES ('bitcoin', CURRENT_DATE, 600, 60), + ('ethereum', CURRENT_DATE, 90, 60) +ON CONFLICT DO NOTHING; -INSERT INTO - wallet_sync_schedules -VALUES - (1, CURRENT_DATE, 30, 10000) ON CONFLICT DO NOTHING; +INSERT INTO wallet_sync_schedules +VALUES (1, CURRENT_DATE, 30, 10000) +ON CONFLICT DO NOTHING; -INSERT INTO - reserved_addresses -VALUES - (1, '0x9915b2B115C7061e19292FE6C6e63909448ACbdD', '', 2), - (2, '0x35a55e21f7f62c5ed7d8ab0d6a1ca7d636aa4068', '', 2), - (3, '0x31a45ea63421104e484436bda180ed396381d4c6', '', 2), - (4, '0x726808b2cdc23ee50c698aea978e06c04be1be1d', '', 2), - (5, '0x0b7543bf76f550d3e70fbac3f964d43fb6ce203a', '', 2), - (6, '0x5fe284474b3b52f2fd693da5b5260a4572f90a56', '', 2), - (7, '0x8593659960260335d82376a9fb4b88a3c49593ab', '', 2), - (8, '0x597ea3bff601a9872978ee77d9e005427fc44396', '', 2), - (9, '0x8c3e95eb46e25bd1fdefec295cbb424d20e93552', '', 2), - (10, '0x5057f69595a93fd90be91478b0a6dfbf56df31c0', '', 2), - (11, '0x974046c4ea7779e66b4e74581ed4e03565da2b44', '', 2), - (12, '0xb1f81300b7d9e2f8df54bd8c369256e761a30ea5', '', 2), - (13, '0xc486ba1a7a54c3d10fdbb049d50c9d7ba6e9d8f2', '', 2), - (14, '0x23b23ee63de28993bdd80275465e82f580ba2458', '', 2), - (15, '0x3b729f061057854198cced6c94a91bea92e76510', '', 2), - (16, '0xf524e92481b91dd6a5db112241d93417ac9d7c41', '', 2), - (17, '0xd7350aaf9bf051bc783cb77008d5dea5824ee3d1', '', 2), - (18, '0xe5d9fb6a2881ad30f9911acd3c4afda94bc7261e', '', 2), - (19, '0x7fc8630872e0fd392767008b91bfe3a5fe623ef9', '', 2), - (20, '0xb254ece0214fbef616bc84855261bc9e54fe23e7', '', 2), - (21, '0x9d2f4f5229d4bdb27c6e191198b500d827b80d31', '', 2), - (22, '0xe50a8ebc5ced25289e0f4efaa934597b4c56336e', '', 2), - (23, '0xa3bf7214bf5ab7a0dabb1a1ea78d6ae4a4270c6f', '', 2), - (24, '0x18fdff00ead80e43224e59a85a2bc4c6259a88a3', '', 2), - (25, '0x7200e5bbc596f4f6f4e29e9ba6954a11e40954cd', '', 2), - (26, '0xcf6ee0077cf538e97b29b0667e96ff720dcacef3', '', 2), - (27, '0xaa37606c560f2af28c01f3de838a771f262bc2cc', '', 2), - (28, '0x5a664d1369e7eb5096ad57cb53c58047aad6f376', '', 2), - (29, '0x3e53908e0f035ed1d471b61b5cc4074143dcefab', '', 2), - (30, '0x50e25d825dc955783867d3d3510d20dcac4f905f', '', 2), - (31, '0xae826d35823686e2c3a6cddd446c43da16ff3070', '', 2), - (32, '0xdf934cf7f6455a5620f9de737daa82d4f5bf8f5b', '', 2), - (33, '0x19669c309ccaa6b1afed0701b8e94ae7e6ecd3e1', '', 2), - (34, '0x1506495ae195c96f5f56b79b4baa56a219189538', '', 2), - (35, '0x855fb40e11de5a27061a1f6dc8cc18e4524fa8bf', '', 2), - (36, '0x62e2b44b1e5a2ba4ffe2b4f9e5d067ef5d85f565', '', 2), - (37, '0xe384f167cf7f59449a5b85160b1e9353da1d5470', '', 2), - (38, '0xa51a98ed3ee695a0921767c920a71fbb371c572c', '', 2), - (39, '0x8e6a769df4ececdcc26ce55265ce118f9edb5fa2', '', 2), - (40, '0xde7cce5eb81a961aa7d789a719eb0a56cbd8c218', '', 2), - (41, '0x20832a4bebe768eef9cbda0789b298d29ec11084', '', 2), - (42, '0x32139bcb3a20adbfd60b8f69c06cf0e15304ecdc', '', 2), - (43, '0x3d593222db1e9b18ba9fdd70f7bd380850dd5a3c', '', 2), - (44, '0x3b99f972764765ac85bc65dae7f96206c0b20a02', '', 2), - (45, '0xe4134fa19f3b798b44de09783b2004f6e1143717', '', 2), - (46, '0xc76978e7d6fba69b2f980b36d24b53790fec6dc4', '', 2), - (47, '0x8668bcfc22741d84241da064204d10b3a2616503', '', 2), - (48, '0xf9510e1846206e18484742cb1a6c99c0e3fe745f', '', 2), - (49, '0x5d5581d06f762ec296338cbea4d56b0eba8f7c03', '', 2), - (50, '0x2d84a57ee481c9c7c1caf5dc151fa6205f9af319', '', 2), - (51, '0xcc13def9292bcc6f41bd585c06325343c4eae0da', '', 2), - (52, '0xa082667282fa333612cea74ccc69c70716dc3a86', '', 2), - (53, '0xb640f1ac183453dc12c4bcbe446ecd7016881cdb', '', 2), - (54, '0x68eacdc4f1ea5e722f69b05e736c6fab8163f37a', '', 2), - (55, '0x142b062e66577c16f5e3959b4195cae78e7bec5a', '', 2), - (56, '0x8999dd812ae8ad2b2cf70d46a6acbb59422bc531', '', 2), - (57, '0x1a5fc4a430f40dcff19729cb80f4bb90d5286e88', '', 2), - (58, '0xa36620eb16d699ea2d1e606d2cabaf67b41eba5b', '', 2), - (59, '0xb626afc6f9dee216af119f02fed5d774b185ed1c', '', 2), - (60, '0x3d3f936b6eca5670591609bee2cbe808ef789e7c', '', 2), - (61, '0xcc12704fd2570ef08dc5ed3a4f5147da08f2866f', '', 2), - (62, '0xf8b87807b34e4536bbf7a68653b06175a1673646', '', 2), - (63, '0x03a49b796b3a0cca0de7a0e027895af0eb2103f0', '', 2), - (64, '0xddabe826e1e2e7c0b9c1a4c61f3b3a45630595f7', '', 2), - (65, '0x1782c18709139b16d91143f2f5f9b65f39e9165c', '', 2), - (66, '0x40bae95ec1c3df040abb4d12b6536807ae04d46b', '', 2), - (67, '0xac6bfcc5fe5c4c6bdaff2e7d71f013809896f98b', '', 2), - (68, '0xdeee2d05ac3566efac90b7ee5403ba7e5332c2fe', '', 2), - (69, '0xfe53059bf5cbf35a18f8e5705bd870e5e92b3387', '', 2), - (70, '0x335815f17fc5cba2979c3f135ffb1dcdc2e94228', '', 2), - (71, '0xa62cecf4650bd713c23f15b500fdd0933c9f8aac', '', 2), - (72, '0xa954078b626c49ba1b17f1bff7f5bb0954792758', '', 2), - (73, '0x997260c29aa2eddf3304ed5c0e440ac8e5cacde7', '', 2), - (74, '0x046e80bd6af93389cdc2bed2336f464b3da7c0b7', '', 2), - (75, '0xbb126abc010a53e5b0fd090a90a10cb4003720b5', '', 2), - (76, '0xe720f50c1d16d574946d4090e0510f529a3c9bc5', '', 2), - (77, '0x456cf66467a2f4713356c0a496c263d9e74a8105', '', 2), - (78, '0x29ef6b2b52778cb7792bd0e5d7680b4982c020fc', '', 2), - (79, '0x0cbd9032f92673ccc33ccf7da0a291a267380332', '', 2), - (80, '0x65e9e60636aa7bc000332714e3d67ebe239ad110', '', 2), - (81, '0x211c89ae3077c2ec7ed0fe4c0948f807713ffc56', '', 2), - (82, '0x5efbcc7920453b9ecdc4983ea55d2d25d9ee6b37', '', 2), - (83, '0xc2634f656a99c2b73a96a86a501f999a9cf02566', '', 2), - (84, '0x55e1dbe468ec30e6736313bdbb3a36d1674c1989', '', 2), - (85, '0x6bbf7d9a0dd3eea7458ea0adc70ff4d902091647', '', 2), - (86, '0x549288e51f3d8723c2e7fb43dc0f92ec146a0ee8', '', 2), - (87, '0x21b01a19c0357e4c70eedf82b8f76c31e3f6f325', '', 2), - (88, '0xf56ba97281ff966c30b9a66bd6a4c7a50c286020', '', 2), - (89, '0x0a4b3b72ef9a66b10d6e93e894de1c0fb0bb8eb6', '', 2), - (90, '0xced6c8176da9bba6d6811c55723b1cfbde02fdf1', '', 2), - (91, '0x73657fb131852187d8f2068616de14f449dd5c4b', '', 2), - (92, '0xed8070518c219ddf89b2bbffd7c5d6cd72df1470', '', 2), - (93, '0x8efddeaca85c72580f54aaa00df8f8ae59ce5633', '', 2), - (94, '0x2b6b34f70a3c762e406aa1d55902665747c3b7e0', '', 2), - (95, '0x533bcb1fa7eedc83bd11771c60aca12632899af1', '', 2), - (96, '0xd5d79c3410c6bc6ae1c27329c93e0a943e7efc72', '', 2), - (97, '0x2307fdc11547091b67b36508b680399da508825a', '', 2), - (98, '0x2858f7b3e21f08dce6530ecb68dd3c1756fcba01', '', 2), - (99, '0xa2edce267a43e1cf3b58d62f5da75f4ffcec85df', '', 2), - (100, '0xf6e1ec3f817c8b76b860588dad74354e1772c98c', '', 2) ON CONFLICT DO NOTHING; +INSERT INTO reserved_addresses +VALUES (1, '0x9915b2B115C7061e19292FE6C6e63909448ACbdD', '', 2), + (2, '0x35a55e21f7f62c5ed7d8ab0d6a1ca7d636aa4068', '', 2), + (3, '0x31a45ea63421104e484436bda180ed396381d4c6', '', 2), + (4, '0x726808b2cdc23ee50c698aea978e06c04be1be1d', '', 2), + (5, '0x0b7543bf76f550d3e70fbac3f964d43fb6ce203a', '', 2), + (6, '0x5fe284474b3b52f2fd693da5b5260a4572f90a56', '', 2), + (7, '0x8593659960260335d82376a9fb4b88a3c49593ab', '', 2), + (8, '0x597ea3bff601a9872978ee77d9e005427fc44396', '', 2), + (9, '0x8c3e95eb46e25bd1fdefec295cbb424d20e93552', '', 2), + (10, '0x5057f69595a93fd90be91478b0a6dfbf56df31c0', '', 2), + (11, '0x974046c4ea7779e66b4e74581ed4e03565da2b44', '', 2), + (12, '0xb1f81300b7d9e2f8df54bd8c369256e761a30ea5', '', 2), + (13, '0xc486ba1a7a54c3d10fdbb049d50c9d7ba6e9d8f2', '', 2), + (14, '0x23b23ee63de28993bdd80275465e82f580ba2458', '', 2), + (15, '0x3b729f061057854198cced6c94a91bea92e76510', '', 2), + (16, '0xf524e92481b91dd6a5db112241d93417ac9d7c41', '', 2), + (17, '0xd7350aaf9bf051bc783cb77008d5dea5824ee3d1', '', 2), + (18, '0xe5d9fb6a2881ad30f9911acd3c4afda94bc7261e', '', 2), + (19, '0x7fc8630872e0fd392767008b91bfe3a5fe623ef9', '', 2), + (20, '0xb254ece0214fbef616bc84855261bc9e54fe23e7', '', 2), + (21, '0x9d2f4f5229d4bdb27c6e191198b500d827b80d31', '', 2), + (22, '0xe50a8ebc5ced25289e0f4efaa934597b4c56336e', '', 2), + (23, '0xa3bf7214bf5ab7a0dabb1a1ea78d6ae4a4270c6f', '', 2), + (24, '0x18fdff00ead80e43224e59a85a2bc4c6259a88a3', '', 2), + (25, '0x7200e5bbc596f4f6f4e29e9ba6954a11e40954cd', '', 2), + (26, '0xcf6ee0077cf538e97b29b0667e96ff720dcacef3', '', 2), + (27, '0xaa37606c560f2af28c01f3de838a771f262bc2cc', '', 2), + (28, '0x5a664d1369e7eb5096ad57cb53c58047aad6f376', '', 2), + (29, '0x3e53908e0f035ed1d471b61b5cc4074143dcefab', '', 2), + (30, '0x50e25d825dc955783867d3d3510d20dcac4f905f', '', 2), + (31, '0xae826d35823686e2c3a6cddd446c43da16ff3070', '', 2), + (32, '0xdf934cf7f6455a5620f9de737daa82d4f5bf8f5b', '', 2), + (33, '0x19669c309ccaa6b1afed0701b8e94ae7e6ecd3e1', '', 2), + (34, '0x1506495ae195c96f5f56b79b4baa56a219189538', '', 2), + (35, '0x855fb40e11de5a27061a1f6dc8cc18e4524fa8bf', '', 2), + (36, '0x62e2b44b1e5a2ba4ffe2b4f9e5d067ef5d85f565', '', 2), + (37, '0xe384f167cf7f59449a5b85160b1e9353da1d5470', '', 2), + (38, '0xa51a98ed3ee695a0921767c920a71fbb371c572c', '', 2), + (39, '0x8e6a769df4ececdcc26ce55265ce118f9edb5fa2', '', 2), + (40, '0xde7cce5eb81a961aa7d789a719eb0a56cbd8c218', '', 2), + (41, '0x20832a4bebe768eef9cbda0789b298d29ec11084', '', 2), + (42, '0x32139bcb3a20adbfd60b8f69c06cf0e15304ecdc', '', 2), + (43, '0x3d593222db1e9b18ba9fdd70f7bd380850dd5a3c', '', 2), + (44, '0x3b99f972764765ac85bc65dae7f96206c0b20a02', '', 2), + (45, '0xe4134fa19f3b798b44de09783b2004f6e1143717', '', 2), + (46, '0xc76978e7d6fba69b2f980b36d24b53790fec6dc4', '', 2), + (47, '0x8668bcfc22741d84241da064204d10b3a2616503', '', 2), + (48, '0xf9510e1846206e18484742cb1a6c99c0e3fe745f', '', 2), + (49, '0x5d5581d06f762ec296338cbea4d56b0eba8f7c03', '', 2), + (50, '0x2d84a57ee481c9c7c1caf5dc151fa6205f9af319', '', 2), + (51, '0xcc13def9292bcc6f41bd585c06325343c4eae0da', '', 2), + (52, '0xa082667282fa333612cea74ccc69c70716dc3a86', '', 2), + (53, '0xb640f1ac183453dc12c4bcbe446ecd7016881cdb', '', 2), + (54, '0x68eacdc4f1ea5e722f69b05e736c6fab8163f37a', '', 2), + (55, '0x142b062e66577c16f5e3959b4195cae78e7bec5a', '', 2), + (56, '0x8999dd812ae8ad2b2cf70d46a6acbb59422bc531', '', 2), + (57, '0x1a5fc4a430f40dcff19729cb80f4bb90d5286e88', '', 2), + (58, '0xa36620eb16d699ea2d1e606d2cabaf67b41eba5b', '', 2), + (59, '0xb626afc6f9dee216af119f02fed5d774b185ed1c', '', 2), + (60, '0x3d3f936b6eca5670591609bee2cbe808ef789e7c', '', 2), + (61, '0xcc12704fd2570ef08dc5ed3a4f5147da08f2866f', '', 2), + (62, '0xf8b87807b34e4536bbf7a68653b06175a1673646', '', 2), + (63, '0x03a49b796b3a0cca0de7a0e027895af0eb2103f0', '', 2), + (64, '0xddabe826e1e2e7c0b9c1a4c61f3b3a45630595f7', '', 2), + (65, '0x1782c18709139b16d91143f2f5f9b65f39e9165c', '', 2), + (66, '0x40bae95ec1c3df040abb4d12b6536807ae04d46b', '', 2), + (67, '0xac6bfcc5fe5c4c6bdaff2e7d71f013809896f98b', '', 2), + (68, '0xdeee2d05ac3566efac90b7ee5403ba7e5332c2fe', '', 2), + (69, '0xfe53059bf5cbf35a18f8e5705bd870e5e92b3387', '', 2), + (70, '0x335815f17fc5cba2979c3f135ffb1dcdc2e94228', '', 2), + (71, '0xa62cecf4650bd713c23f15b500fdd0933c9f8aac', '', 2), + (72, '0xa954078b626c49ba1b17f1bff7f5bb0954792758', '', 2), + (73, '0x997260c29aa2eddf3304ed5c0e440ac8e5cacde7', '', 2), + (74, '0x046e80bd6af93389cdc2bed2336f464b3da7c0b7', '', 2), + (75, '0xbb126abc010a53e5b0fd090a90a10cb4003720b5', '', 2), + (76, '0xe720f50c1d16d574946d4090e0510f529a3c9bc5', '', 2), + (77, '0x456cf66467a2f4713356c0a496c263d9e74a8105', '', 2), + (78, '0x29ef6b2b52778cb7792bd0e5d7680b4982c020fc', '', 2), + (79, '0x0cbd9032f92673ccc33ccf7da0a291a267380332', '', 2), + (80, '0x65e9e60636aa7bc000332714e3d67ebe239ad110', '', 2), + (81, '0x211c89ae3077c2ec7ed0fe4c0948f807713ffc56', '', 2), + (82, '0x5efbcc7920453b9ecdc4983ea55d2d25d9ee6b37', '', 2), + (83, '0xc2634f656a99c2b73a96a86a501f999a9cf02566', '', 2), + (84, '0x55e1dbe468ec30e6736313bdbb3a36d1674c1989', '', 2), + (85, '0x6bbf7d9a0dd3eea7458ea0adc70ff4d902091647', '', 2), + (86, '0x549288e51f3d8723c2e7fb43dc0f92ec146a0ee8', '', 2), + (87, '0x21b01a19c0357e4c70eedf82b8f76c31e3f6f325', '', 2), + (88, '0xf56ba97281ff966c30b9a66bd6a4c7a50c286020', '', 2), + (89, '0x0a4b3b72ef9a66b10d6e93e894de1c0fb0bb8eb6', '', 2), + (90, '0xced6c8176da9bba6d6811c55723b1cfbde02fdf1', '', 2), + (91, '0x73657fb131852187d8f2068616de14f449dd5c4b', '', 2), + (92, '0xed8070518c219ddf89b2bbffd7c5d6cd72df1470', '', 2), + (93, '0x8efddeaca85c72580f54aaa00df8f8ae59ce5633', '', 2), + (94, '0x2b6b34f70a3c762e406aa1d55902665747c3b7e0', '', 2), + (95, '0x533bcb1fa7eedc83bd11771c60aca12632899af1', '', 2), + (96, '0xd5d79c3410c6bc6ae1c27329c93e0a943e7efc72', '', 2), + (97, '0x2307fdc11547091b67b36508b680399da508825a', '', 2), + (98, '0x2858f7b3e21f08dce6530ecb68dd3c1756fcba01', '', 2), + (99, '0xa2edce267a43e1cf3b58d62f5da75f4ffcec85df', '', 2), + (100, '0xf6e1ec3f817c8b76b860588dad74354e1772c98c', '', 2) +ON CONFLICT DO NOTHING; + +INSERT INTO reserved_addresses +VALUES (101, '1LJYygirSoWPY8J9g3mTHgfvzuiSc57Jrh', '', 1), + (102, '132dj2K7wwgFULAogws2c7XYeuXzE48WC3', '', 1), + (103, '1LGCvMfzExf2HiYj5Ly3yA28LSZdAxNDKa', '', 1), + (104, '1HRo7b4MqP13vujQNB3sS1L2r2NPdo677z', '', 1), + (105, '1168eG75WRESkQhC2Ga3fG1uQgFjwj17ky', '', 1), + (106, '1QDryfkK8U62LVtCjEn8LKaJj8FptW6ZY6', '', 1), + (107, '13NiXcRQ464xnu1C5KdB9JUserxWA7JqY6', '', 1), + (108, '1NhxrxHP3rc21j4SzFa4aFcsGV3H3hd7Af', '', 1), + (109, '1DxWqdHjAtJZrDLCA86mu8KsuXDLKMyni7', '', 1), + (110, '19d9whtZkAb7YKyjKnNvhNicwVVMGP4BwE', '', 1), + (111, '1KUp7G6nqhMMdmU3Bwvv2DJsmvjisYBTeK', '', 1), + (112, '1PobNJKQFYMGwwsUG6FPny8oZNFfq5UMVd', '', 1), + (113, '16EKdwQ6KtA28jY1ywDRAvk7Wc1fQ7yq8L', '', 1), + (114, '13t3QwEAdMLkktkHF8EMDpvyvs4zeYnNXd', '', 1), + (115, '1CU8Czx8tvBS6B7VwrU6NSZqziyHbbNwf9', '', 1), + (116, '1QKUuge5y1ytscAp9yhyBZcHoqVKz43F5Q', '', 1), + (117, '19Cg2X89XWaovVkHYDi85u9NPtnDvXZjJ7', '', 1), + (118, '1EdZcRGM7xDUxDzrX5pjXwdfG6yGPpUZ3S', '', 1), + (119, '1GaqchuAkHLpMFgYd1wqoJqWk87XNoYjMn', '', 1), + (120, '1Kvx81iqL5qnFYQeX7gEwiqH4UrcnM18Gj', '', 1), + (121, '1BS3gGLk4KtekfkGSG42DVHnDtepMoY2cq', '', 1), + (122, '16vEWVnBcweUM37CKcWaaSupz8ut551Lq7', '', 1), + (123, '14UKNcy6m7dt16ZStuUmyGqwM1tMUh1qsr', '', 1), + (124, '1DfRspiCrgrSYQf83tJRg9KcCYcWVwST5o', '', 1), + (125, '1FCnYfFL8DxCh669WtcZyZuW6p8K1QWtSo', '', 1), + (126, '1GUjY5SEDYHnCW81HXTM1Y3CYdsDWE2qhj', '', 1), + (127, '18uzbGz9Cz7FggQjobKQSHA6RnLjuNZg6E', '', 1), + (128, '149rR1qEzimPGCqTCj598Q9dJMW6RM2KLB', '', 1), + (129, '125uE2an6pDpWnWvyGW53WTWZjHacMQrKq', '', 1), + (130, '1LKz6kCKTSfe1yqxWFq3QQSYf9S4MFAtf3', '', 1), + (131, '12UaDY8ZgRjHiEcxDJx47Y9yN87GXkiNx4', '', 1), + (132, '113JaxwoSV5UzfbkEof3SuMKKatuYx17Vc', '', 1), + (133, '114XL5acj1qeshMUcovETDR2Lhe8xv5kTE', '', 1), + (134, '1MPDF2B4ayPiWbLbWMUw9qWX8eouQoEKVw', '', 1), + (135, '1HuL4EpVMQ3V1P9qqRzsVMaJVBbUqenMJk', '', 1), + (136, '15MZdya9t8VQfBVDinMJACxbTjMo9LfU3R', '', 1), + (137, '1DuCvPagYRk767VpMbbXbZbTGFDMMfrU1H', '', 1), + (138, '12RjdTFtgUMxWLsnis6dAkEuMdUucms61R', '', 1), + (139, '1Gp5MLUCM6ZxpWpEDuFfDnjkLoosu5F5TV', '', 1), + (140, '14JbHWzF1RTZ5gpu9Eea54kVPU8og12AnC', '', 1), + (141, '1Drs6n497mKVag7edjqTRoqeqxrcLtG2Xg', '', 1), + (142, '19A6XzVRazZVFBsYQ5VZSVmTqDGqa7pFMg', '', 1), + (143, '18iktsmhDTAVoMnghQy4xJwjem5uo55EdN', '', 1), + (144, '19RoW9t7JLdoRDaiweQBdq2XSK27ZjpNQ6', '', 1), + (145, '19kr8uYCxx8iShkBn1zTtS6LcYg4bJNysz', '', 1), + (146, '15EDpSeBKvAQxQ1yGHBxvi1YoVzxikhXj1', '', 1), + (147, '1DHB5gTPX6ZKx2mQh1V1VFA73A57P16gV9', '', 1), + (148, '1E4L3ybAkTvNdsDvvwLhxsFq8UEdD7xync', '', 1), + (149, '1G2ody9cDKin2Xkki6cgYX1LacNeo2zSiW', '', 1), + (150, '1KcCXHKBRJbjYC9CzKTxfTUNahYKUk5ryA', '', 1), + (151, '1J3TfJCViebfeTpMc6wSFPeLtVhPS1GaCo', '', 1), + (152, '18LRcPPAvqdwwD5TakN1miVYtbj3Pjk5SL', '', 1), + (153, '16L8Zdjzc778uQ5tyHYDcTFZahBchdXc7C', '', 1), + (154, '1NBE5ibxUnqayzRgb6dJ2uJgSuhz2r4dFa', '', 1), + (155, '1PyMb84JF2ubdTzp3cAQhcaSizK9F3dHop', '', 1), + (156, '1NcE7uEMVH1Y3eJecFdeLbRomYreFUENQm', '', 1), + (157, '1FUY9d4qUjxDg1u3fXpRZAzdvbm5eXMMRZ', '', 1), + (158, '13K15T5xD6Fr2qMAp4R4KvRSDg7HiZB4WN', '', 1), + (159, '1H9v62ZMdHkeu3v789LDSqTiQTYzedS1gC', '', 1), + (160, '1PLZRKohtHTzqGtK1RwxEyPBxGKPRENtpv', '', 1), + (161, '1DuwfU8q4XXWhBUGqzTa9SgYLPsB3JVmKW', '', 1), + (162, '17kEbJrtASWMx87pAnk4uCywsFDinGdkw8', '', 1), + (163, '15exk8y46uXjwtjET7PxGuzWDCXiFWP5hp', '', 1), + (164, '1DcJ4ttvM3cUmzX98fhAdDfDUXnyBt5cxD', '', 1), + (165, '1696g2zqx3Rgjhe29ttsfeDJyBTu2y51Bg', '', 1), + (166, '1AVivVBFn8tUsxMTyk3xe1s4iHm5fWEF49', '', 1), + (167, '1NA2RdYoQpvCrd4mhQ5K5JmRaR3hsWc7Qv', '', 1), + (168, '1Ke9MAahF7c5pmAdKmqnvBEBbT9RSCe2VP', '', 1), + (169, '1KLiGb3mfV4tHnQ4DxbLHMToPfTUbUdF9u', '', 1), + (170, '1HyEGsHStEYZD7SCnPw6j3b7GF5DziXUo7', '', 1), + (171, '1P3QuxqY3FmUPbPeWWGuEqFMHgrBfuUPRL', '', 1), + (172, '1LBMh5h6Vb5JTYFFJHQypgCwgZv7RGwHqh', '', 1), + (173, '1AWHxdEdPnMSTYEzFCjYWrFKCez3MVPcFz', '', 1), + (174, '1enZSZB542hbG3ZqsUkivTp7UE6dZCnjE', '', 1), + (175, '15Shw1FbcNbeVG1rfeoTwQ5EgsdWmyWcoQ', '', 1), + (176, '1LkrRmzuZ1VHGbTZB1tmMCtWHE6G7WreQu', '', 1), + (177, '13usV4iE83KbucaRFHnVssd7EpzMppRGDB', '', 1), + (178, '1DVah1wKDwNkgEVvmWeZ1hT9aD3yrFadVw', '', 1), + (179, '1Cmjbvt7apgF3X5kXg2auRifzNLAC4jyFV', '', 1), + (180, '1piZ99DiJHyhFDoNJQLbmHeEUG574LZ15', '', 1), + (181, '14C9n8My12fCN8btrMRxyUjzdjXXHyXnQX', '', 1), + (182, '12xCuk297QyFKD2637N8wdKVMzmrGvLjdm', '', 1), + (183, '14j9d9bc5rvYzSe2NxDpcQrUKbRU7Dh1gk', '', 1), + (184, '16rqNnnJNCNF9yJVmownYfFbwW2fMC784V', '', 1), + (185, '1FxaP1svexAuqDm5TMkNVYmXw8uXwpHCYh', '', 1), + (186, '1ES2ZHNkswLthMQfggj6TMpXF3tHDgfUBP', '', 1), + (187, '1AEF3YQP7mgXTfYksmthY4WzYx7JCKUe9P', '', 1), + (188, '145szc1LzhVrCZ84N6sd2oAv5CvCGfwewd', '', 1), + (189, '1DT8YS7FcJQF1QAeRYSCeTjNhhsFyww3DP', '', 1), + (190, '19Brny4zVtbcJ3C2PDbQKbdfCnzkWxraAX', '', 1), + (191, '1ErTiL8BaXu4vdhWTgzaUhC5iEzwuJSf3f', '', 1), + (192, '1YZX7cfxPVxSiKC8Bo2T6tkNSGvTfEM71', '', 1), + (193, '19rJVBmCqFWvPd8fKs5ED4XKbAeKqFQYnk', '', 1), + (194, '12byWnQxuHSuAamoyX3KMvjopnAmyA72Zn', '', 1), + (195, '14JGYTGnvWjtKR4sSN847dxw1qroFmQUjX', '', 1), + (196, '16qNWZvUeBMrVPNUBq4pqZTHsQx5wBA8ZR', '', 1), + (197, '1MEQqWEDpsACauQhaGnvQmryQL7dhgHKhW', '', 1), + (198, '13AdmWSaHRv39GLaydy26vkxrNX4DaNARK', '', 1), + (199, '14ZX6BThX8rSay3qNHx1Uc753FmnTWk1ZR', '', 1), + (200, '14BeB612pSr9pjmAh5sa3vMJ33YvLiGdvb', '', 1) +ON CONFLICT DO NOTHING; SELECT setval(pg_get_serial_sequence('reserved_addresses', 'id'), (SELECT MAX(id) FROM reserved_addresses)); diff --git a/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/resources/schema.sql b/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/resources/schema.sql index 6f445565f..ce91edf34 100644 --- a/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/resources/schema.sql +++ b/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/resources/schema.sql @@ -1,116 +1,133 @@ -CREATE TABLE IF NOT EXISTS address_types ( - id SERIAL PRIMARY KEY, - address_type VARCHAR(20) NOT NULL, - address_regex VARCHAR(72) NOT NULL, - memo_regex VARCHAR(72) +CREATE TABLE IF NOT EXISTS address_types +( + id SERIAL PRIMARY KEY, + address_type VARCHAR(20) NOT NULL, + address_regex VARCHAR(72) NOT NULL, + memo_regex VARCHAR(72) ); -CREATE TABLE IF NOT EXISTS assigned_addresses ( - id SERIAL PRIMARY KEY, - uuid VARCHAR(72) NOT NULL, - address VARCHAR(72) NOT NULL, - memo VARCHAR(72) NOT NULL, - addr_type_id INTEGER NOT NULL REFERENCES address_types (id), - UNIQUE (address, memo) +CREATE TABLE IF NOT EXISTS assigned_addresses +( + id SERIAL PRIMARY KEY, + uuid VARCHAR(72) NOT NULL, + address VARCHAR(72) NOT NULL, + memo VARCHAR(72) NOT NULL, + addr_type_id INTEGER NOT NULL REFERENCES address_types (id), + UNIQUE (address, memo) ); -CREATE TABLE IF NOT EXISTS reserved_addresses ( - id SERIAL PRIMARY KEY, - address VARCHAR(72) NOT NULL, - memo VARCHAR(72) NOT NULL, - address_type INTEGER NOT NULL REFERENCES address_types (id), - UNIQUE (address, memo) +CREATE TABLE IF NOT EXISTS reserved_addresses +( + id SERIAL PRIMARY KEY, + address VARCHAR(72) NOT NULL, + memo VARCHAR(72) NOT NULL, + address_type INTEGER NOT NULL REFERENCES address_types (id), + UNIQUE (address, memo) ); -CREATE TABLE IF NOT EXISTS chains (name VARCHAR(72) PRIMARY KEY); +CREATE TABLE IF NOT EXISTS chains +( + name VARCHAR(72) PRIMARY KEY +); -CREATE TABLE IF NOT EXISTS assigned_address_chains ( - id SERIAL PRIMARY KEY, - assigned_address_id INTEGER NOT NULL REFERENCES assigned_addresses (id), - chain VARCHAR(72) NOT NULL REFERENCES chains (name) +CREATE TABLE IF NOT EXISTS assigned_address_chains +( + id SERIAL PRIMARY KEY, + assigned_address_id INTEGER NOT NULL REFERENCES assigned_addresses (id), + chain VARCHAR(72) NOT NULL REFERENCES chains (name) ); -CREATE TABLE IF NOT EXISTS chain_address_types ( - id SERIAL PRIMARY KEY, - chain_name VARCHAR(72) NOT NULL REFERENCES chains (name), - addr_type_id INTEGER NOT NULL REFERENCES address_types (id) +CREATE TABLE IF NOT EXISTS chain_address_types +( + id SERIAL PRIMARY KEY, + chain_name VARCHAR(72) NOT NULL REFERENCES chains (name), + addr_type_id INTEGER NOT NULL REFERENCES address_types (id) ); -CREATE TABLE IF NOT EXISTS chain_endpoints ( - id SERIAL PRIMARY KEY, - chain_name VARCHAR(72) NOT NULL REFERENCES chains (name), - endpoint_url VARCHAR(255) NOT NULL, - endpoint_user VARCHAR(72), - endpoint_password VARCHAR(72) +CREATE TABLE IF NOT EXISTS chain_endpoints +( + id SERIAL PRIMARY KEY, + chain_name VARCHAR(72) NOT NULL REFERENCES chains (name), + endpoint_url VARCHAR(255) NOT NULL, + endpoint_user VARCHAR(72), + endpoint_password VARCHAR(72) ); -CREATE TABLE IF NOT EXISTS chain_sync_schedules ( - chain VARCHAR(72) PRIMARY KEY REFERENCES chains (name), - retry_time TIMESTAMP NOT NULL, - delay INTEGER NOT NULL, - error_delay INTEGER NOT NULL +CREATE TABLE IF NOT EXISTS chain_sync_schedules +( + chain VARCHAR(72) PRIMARY KEY REFERENCES chains (name), + retry_time TIMESTAMP NOT NULL, + delay INTEGER NOT NULL, + error_delay INTEGER NOT NULL ); -CREATE TABLE IF NOT EXISTS chain_sync_retry ( - id SERIAL PRIMARY KEY, - chain VARCHAR(72) REFERENCES chains (name), - block INTEGER NOT NULL, +CREATE TABLE IF NOT EXISTS chain_sync_retry +( + id SERIAL PRIMARY KEY, + chain VARCHAR(72) REFERENCES chains (name), + block INTEGER NOT NULL, retries INTEGER NOT NULL DEFAULT 1, - synced BOOLEAN NOT NULL DEFAULT false, + synced BOOLEAN NOT NULL DEFAULT false, give_up BOOLEAN NOT NULL DEFAULT false, - error TEXT, + error TEXT, UNIQUE (chain, block) ); -CREATE TABLE IF NOT EXISTS chain_sync_records ( - chain VARCHAR(72) PRIMARY KEY REFERENCES chains (name), - time TIMESTAMP NOT NULL, - endpoint_url VARCHAR(72) NOT NULL, - latest_block INTEGER, - success BOOLEAN NOT NULL, - error VARCHAR(100) +CREATE TABLE IF NOT EXISTS chain_sync_records +( + chain VARCHAR(72) PRIMARY KEY REFERENCES chains (name), + time TIMESTAMP NOT NULL, + endpoint_url VARCHAR(72) NOT NULL, + latest_block INTEGER, + success BOOLEAN NOT NULL, + error VARCHAR(100) ); -CREATE TABLE IF NOT EXISTS wallet_sync_schedules ( - id INTEGER PRIMARY KEY DEFAULT(1) CHECK(id = 1), - retry_time TIMESTAMP NOT NULL, - delay INTEGER NOT NULL, - batch_size INTEGER +CREATE TABLE IF NOT EXISTS wallet_sync_schedules +( + id INTEGER PRIMARY KEY DEFAULT (1) CHECK (id = 1), + retry_time TIMESTAMP NOT NULL, + delay INTEGER NOT NULL, + batch_size INTEGER ); -CREATE TABLE IF NOT EXISTS wallet_sync_records ( - id SERIAL PRIMARY KEY, - time TIMESTAMP NOT NULL, - success BOOLEAN NOT NULL, - error TEXT +CREATE TABLE IF NOT EXISTS wallet_sync_records +( + id SERIAL PRIMARY KEY, + time TIMESTAMP NOT NULL, + success BOOLEAN NOT NULL, + error TEXT ); -CREATE TABLE IF NOT EXISTS deposits ( - id SERIAL PRIMARY KEY, - hash TEXT UNIQUE NOT NULL, - wallet_record_id INTEGER REFERENCES wallet_sync_records (id), - chain VARCHAR(72) NOT NULL REFERENCES chains (name), - token BOOLEAN NOT NULL, - token_address VARCHAR(72), - amount DECIMAL NOT NULL, - depositor VARCHAR(72) NOT NULL, - depositor_memo VARCHAR(72) +CREATE TABLE IF NOT EXISTS deposits +( + id SERIAL PRIMARY KEY, + hash TEXT UNIQUE NOT NULL, + wallet_record_id INTEGER REFERENCES wallet_sync_records (id), + chain VARCHAR(72) NOT NULL REFERENCES chains (name), + token BOOLEAN NOT NULL, + token_address VARCHAR(72), + amount DECIMAL NOT NULL, + depositor VARCHAR(72) NOT NULL, + depositor_memo VARCHAR(72) ); -CREATE TABLE IF NOT EXISTS currency ( - symbol VARCHAR(72) PRIMARY KEY, - name VARCHAR(72) NOT NULL +CREATE TABLE IF NOT EXISTS currency +( + symbol VARCHAR(72) PRIMARY KEY, + name VARCHAR(72) NOT NULL ); -CREATE TABLE IF NOT EXISTS currency_implementations ( - id SERIAL PRIMARY KEY, - symbol VARCHAR(72) NOT NULL, - chain VARCHAR(72) NOT NULL REFERENCES chains (name), - token BOOLEAN NOT NULL, - token_address VARCHAR(72), - token_name VARCHAR(72), - withdraw_enabled BOOLEAN NOT NULL, - withdraw_fee DECIMAL NOT NULL, - withdraw_min DECIMAL NOT NULL, - decimal INTEGER NOT NULL +CREATE TABLE IF NOT EXISTS currency_implementations +( + id SERIAL PRIMARY KEY, + symbol VARCHAR(72) NOT NULL, + chain VARCHAR(72) NOT NULL REFERENCES chains (name), + token BOOLEAN NOT NULL, + token_address VARCHAR(72), + token_name VARCHAR(72), + withdraw_enabled BOOLEAN NOT NULL, + withdraw_fee DECIMAL NOT NULL, + withdraw_min DECIMAL NOT NULL, + decimal INTEGER NOT NULL ); diff --git a/Jenkins/Jenkinsfile.deploy.groovy b/dev.Jenkinsfile similarity index 63% rename from Jenkins/Jenkinsfile.deploy.groovy rename to dev.Jenkinsfile index f4ce7d7fb..d0134e6b5 100644 --- a/Jenkins/Jenkinsfile.deploy.groovy +++ b/dev.Jenkinsfile @@ -1,12 +1,12 @@ pipeline { agent any - stages('Deploy - Demo') { + stages('Deploy') { stage('Build') { steps { setBuildStatus("?", "PENDING") withMaven( - maven: 'maven-latest' + maven: 'maven-3.6.3' ) { sh 'mvn -B clean install' } @@ -14,12 +14,21 @@ pipeline { } stage('Deliver') { environment { - DATA = '/var/opex/runtime' + DATA = '/var/opex/dev-core' + PANEL_PASS = credentials("v-panel-secret-dev") + BACKEND_USER = credentials("v-backend-secret-dev") + SMTP_PASS = credentials("smtp-secret-dev") + DB_USER = 'opex' + DB_PASS = credentials("db-secret-dev") + KEYCLOAK_ADMIN_URL = 'https://demo.opex.dev:8443/auth' + KEYCLOAK_FRONTEND_URL = 'https://demo.opex.dev:8443/auth' + COMPOSE_PROJECT_NAME = 'dev-core' + DEFAULT_NETWORK_NAME = 'dev-opex' } steps { - dir("Deployment") { - sh 'COMPOSE_PROJECT_NAME=demo docker-compose up -d --build' - } + sh 'docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d --build --remove-orphans' + sh 'docker image prune -f' + sh 'docker network prune -f' } } } diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 000000000..80ab2c255 --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,28 @@ +version: '3.8' +services: + vault-ui: + ports: + - "8001:8000" + consul: + ports: + - "8501:8500" + - "8301:8300" + - "8601:8600" + postgres-accountant: + ports: + - "5442:5432" + postgres-eventlog: + ports: + - "5443:5432" + postgres-auth: + ports: + - "5444:5432" + postgres-wallet: + ports: + - "5445:5432" + postgres-api: + ports: + - "5446:5432" + postgres-bc-gateway: + ports: + - "5447:5432" \ No newline at end of file diff --git a/docker-compose.override.yml b/docker-compose.override.yml new file mode 100644 index 000000000..8c374f16f --- /dev/null +++ b/docker-compose.override.yml @@ -0,0 +1,28 @@ +version: '3.8' +services: + vault-ui: + ports: + - "8000:8000" + consul: + ports: + - "8500:8500" + - "8300:8300" + - "8600:8600" + postgres-accountant: + ports: + - "5432:5432" + postgres-eventlog: + ports: + - "5433:5432" + postgres-auth: + ports: + - "5434:5432" + postgres-wallet: + ports: + - "5435:5432" + postgres-api: + ports: + - "5436:5432" + postgres-bc-gateway: + ports: + - "5437:5432" \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..94384cf99 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,450 @@ +version: '3.8' +services: + zookeeper: + image: confluentinc/cp-zookeeper:latest + hostname: zookeeper + volumes: + - $DATA/zookeeper-data/data:/var/lib/zookeeper/data + - $DATA/zookeeper-data/tx-logs:/var/lib/zookeeper/log + environment: + - ALLOW_ANONYMOUS_LOGIN=yes + - ZOOKEEPER_CLIENT_PORT=2181 + networks: + - default + deploy: + restart_policy: + condition: on-failure + kafka-1: + image: confluentinc/cp-kafka:latest + hostname: kafka-1 + volumes: + - $DATA/kafka-data/kafka-1:/var/lib/kafka/data + environment: + - KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 + - ALLOW_PLAINTEXT_LISTENER=yes + - KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=CLIENT:PLAINTEXT,EXTERNAL:PLAINTEXT + - KAFKA_LISTENERS=CLIENT://kafka-1:29092,EXTERNAL://kafka-1:9092 + - KAFKA_ADVERTISED_LISTENERS=CLIENT://kafka-1:29092,EXTERNAL://kafka-1:9092 + - KAFKA_INTER_BROKER_LISTENER_NAME=CLIENT + - KAKFA_MIN_INSYNC_REPLICAS=2 + - KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE=false + depends_on: + - zookeeper + networks: + - default + deploy: + restart_policy: + condition: on-failure + kafka-2: + image: confluentinc/cp-kafka:latest + hostname: kafka-2 + volumes: + - $DATA/kafka-data/kafka-2:/var/lib/kafka/data + environment: + - KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 + - ALLOW_PLAINTEXT_LISTENER=yes + - KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=CLIENT:PLAINTEXT,EXTERNAL:PLAINTEXT + - KAFKA_LISTENERS=CLIENT://kafka-2:29092,EXTERNAL://kafka-2:9092 + - KAFKA_ADVERTISED_LISTENERS=CLIENT://kafka-2:29092,EXTERNAL://kafka-2:9092 + - KAFKA_INTER_BROKER_LISTENER_NAME=CLIENT + - KAKFA_MIN_INSYNC_REPLICAS=2 + - KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE=false + depends_on: + - zookeeper + networks: + - default + deploy: + restart_policy: + condition: on-failure + kafka-3: + image: confluentinc/cp-kafka:latest + hostname: kafka-3 + volumes: + - $DATA/kafka-data/kafka-3:/var/lib/kafka/data + environment: + - KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 + - ALLOW_PLAINTEXT_LISTENER=yes + - KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=CLIENT:PLAINTEXT,EXTERNAL:PLAINTEXT + - KAFKA_LISTENERS=CLIENT://kafka-3:29092,EXTERNAL://kafka-3:9092 + - KAFKA_ADVERTISED_LISTENERS=CLIENT://kafka-3:29092,EXTERNAL://kafka-3:9092 + - KAFKA_INTER_BROKER_LISTENER_NAME=CLIENT + - KAKFA_MIN_INSYNC_REPLICAS=2 + - KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE=false + depends_on: + - zookeeper + networks: + - default + deploy: + restart_policy: + condition: on-failure + vault: + image: vault + volumes: + - $DATA/vault:/vault/file:rw + - ./resources/vault:/vault/config:rw + environment: + - VAULT_ADDRESS=http://0.0.0.0:8200 + - PANEL_PASS=${PANEL_PASS} + - BACKEND_USER=${BACKEND_USER} + - SMTP_PASS=${SMTP_PASS} + - DB_USER=${DB_USER} + - DB_PASS=${DB_PASS} + healthcheck: + retries: 5 + cap_add: + - IPC_LOCK + entrypoint: /vault/config/workflow-vault.sh + vault-ui: + image: djenriquez/vault-ui + environment: + - VAULT_URL_DEFAULT=http://vault:8200 + - VAULT_AUTH_DEFAULT=USERNAMEPASSWORD + consul: + image: consul + environment: + - CONSUL_BIND_INTERFACE=eth0 + networks: + - default + deploy: + restart_policy: + condition: on-failure + redis: + image: redis:alpine + command: redis-server + volumes: + - $DATA/redis-data:/var/lib/redis + - $DATA/redis.conf:/usr/local/etc/redis/redis.conf + environment: + - REDIS_REPLICATION_MODE=master + networks: + - default + deploy: + restart_policy: + condition: on-failure + postgres-accountant: + image: postgres:14-alpine + environment: + - POSTGRES_USER=opex + - POSTGRES_PASSWORD=hiopex + - POSTGRES_DB=opex_accountant + volumes: + - $DATA/accountant-data:/var/lib/postgresql/data/ + networks: + - default + akhq: + image: tchiotludo/akhq + environment: + AKHQ_CONFIGURATION: | + akhq: + connections: + docker-kafka-server: + properties: + bootstrap.servers: "kafka-1:29092,kafka-2:29092,kafka-3:29092" + networks: + - default + depends_on: + - kafka-1 + - kafka-2 + - kafka-3 + postgres-eventlog: + image: postgres:14-alpine + environment: + - POSTGRES_USER=opex + - POSTGRES_PASSWORD=hiopex + - POSTGRES_DB=opex_eventlog + volumes: + - $DATA/eventlog-data:/var/lib/postgresql/data/ + networks: + - default + postgres-auth: + image: postgres:14-alpine + environment: + - POSTGRES_USER=opex + - POSTGRES_PASSWORD=hiopex + - POSTGRES_DB=opex_auth + volumes: + - $DATA/auth-data:/var/lib/postgresql/data/ + networks: + - default + deploy: + restart_policy: + condition: on-failure + postgres-wallet: + image: postgres:14-alpine + environment: + - POSTGRES_USER=opex + - POSTGRES_PASSWORD=hiopex + - POSTGRES_DB=opex_wallet + volumes: + - $DATA/wallet-data:/var/lib/postgresql/data/ + networks: + - default + deploy: + restart_policy: + condition: on-failure + postgres-api: + image: postgres:14-alpine + environment: + - POSTGRES_USER=opex + - POSTGRES_PASSWORD=hiopex + - POSTGRES_DB=opex_api + volumes: + - $DATA/api-data:/var/lib/postgresql/data/ + networks: + - default + deploy: + restart_policy: + condition: on-failure + postgres-bc-gateway: + image: postgres:14-alpine + environment: + - POSTGRES_USER=opex + - POSTGRES_PASSWORD=hiopex + - POSTGRES_DB=opex_bc_gateway + volumes: + - $DATA/bc-gateway-data:/var/lib/postgresql/data/ + networks: + - default + deploy: + restart_policy: + condition: on-failure + accountant: + build: + context: accountant/accountant-app + environment: + - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 + - SPRING_PROFILES_ACTIVE=scheduled + - KAFKA_IP_PORT=kafka-1:29092,kafka-2:29092,kafka-3:29092 + - REDIS_HOST=redis + - CONSUL_HOST=consul + - DB_IP_PORT=postgres-accountant + - BACKEND_USER=${BACKEND_USER} + - VAULT_HOST=vault + networks: + - default + depends_on: + - zookeeper + - kafka-1 + - kafka-2 + - kafka-3 + - redis + - consul + - vault + - postgres-accountant + eventlog: + build: + context: eventlog/eventlog-app + environment: + - JAVA_OPTS=-Xmx256m + - KAFKA_IP_PORT=kafka-1:29092,kafka-2:29092,kafka-3:29092 + - REDIS_HOST=redis + - CONSUL_HOST=consul + - DB_IP_PORT=postgres-eventlog + - BACKEND_USER=${BACKEND_USER} + - VAULT_HOST=vault + networks: + - default + depends_on: + - zookeeper + - kafka-1 + - kafka-2 + - kafka-3 + - redis + - consul + - vault + - postgres-eventlog + matching-engine: + build: + context: matching-engine/matching-engine-app + environment: + - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 + - KAFKA_IP_PORT=kafka-1:29092,kafka-2:29092,kafka-3:29092 + - REDIS_HOST=redis + networks: + - default + depends_on: + - zookeeper + - kafka-1 + - kafka-2 + - kafka-3 + - redis + matching-gateway: + build: + context: matching-gateway/matching-gateway-app + environment: + - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 + - KAFKA_IP_PORT=kafka-1:29092,kafka-2:29092,kafka-3:29092 + - REDIS_HOST=redis + - CONSUL_HOST=consul + networks: + - default + depends_on: + - zookeeper + - kafka-1 + - kafka-2 + - kafka-3 + - consul + auth: + build: + context: user-management/keycloak-gateway + environment: + - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 + - KAFKA_IP_PORT=kafka-1:29092,kafka-2:29092,kafka-3:29092 + - REDIS_HOST=redis + - CONSUL_HOST=consul + - DB_IP_PORT=postgres-auth + - PROXY_ADDRESS_FORWARDING=true + - WORKING_DIR=$DATA + - BACKEND_USER=$BACKEND_USER + - ADMIN_URL=$KEYCLOAK_ADMIN_URL + - FRONTEND_URL=$KEYCLOAK_FRONTEND_URL + - VAULT_URL=http://vault:8200 + - VAULT_HOST=vault + depends_on: + - zookeeper + - kafka-1 + - kafka-2 + - kafka-3 + - redis + - consul + - vault + - postgres-auth + networks: + - default + deploy: + restart_policy: + condition: on-failure + wallet: + build: + context: wallet/wallet-app + environment: + - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 + - KAFKA_IP_PORT=kafka-1:29092,kafka-2:29092,kafka-3:29092 + - REDIS_HOST=redis + - CONSUL_HOST=consul + - DB_IP_PORT=postgres-wallet + - BACKEND_USER=${BACKEND_USER} + - VAULT_HOST=vault + depends_on: + - zookeeper + - kafka-1 + - kafka-2 + - kafka-3 + - redis + - consul + - vault + - postgres-wallet + networks: + - default + deploy: + restart_policy: + condition: on-failure + api: + build: + context: api/api-app + environment: + - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 + - KAFKA_IP_PORT=kafka-1:29092,kafka-2:29092,kafka-3:29092 + - REDIS_HOST=redis + - CONSUL_HOST=consul + - DB_IP_PORT=postgres-api + - BACKEND_USER=${BACKEND_USER} + - VAULT_HOST=vault + depends_on: + - zookeeper + - kafka-1 + - kafka-2 + - kafka-3 + - redis + - consul + - vault + - postgres-api + networks: + - default + deploy: + restart_policy: + condition: on-failure + websocket: + build: + context: websocket/websocket-app + environment: + - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 + - KAFKA_IP_PORT=kafka-1:29092,kafka-2:29092,kafka-3:29092 + - CONSUL_HOST=consul + - DB_IP_PORT=postgres-api + - BACKEND_USER=${BACKEND_USER} + - VAULT_HOST=vault + depends_on: + - zookeeper + - kafka-1 + - kafka-2 + - kafka-3 + - consul + - vault + - postgres-api + networks: + - default + deploy: + restart_policy: + condition: on-failure + bc-gateway: + build: + context: bc-gateway/bc-gateway-app + environment: + - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 + - SPRING_PROFILES_DEFAULT=scheduled + - CONSUL_HOST=consul + - DB_IP_PORT=postgres-bc-gateway + - BACKEND_USER=${BACKEND_USER} + - VAULT_HOST=vault + depends_on: + - redis + - consul + - vault + - postgres-bc-gateway + networks: + - default + deploy: + restart_policy: + condition: on-failure + storage: + build: + context: storage/storage-app + environment: + - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 + - CONSUL_HOST=consul + - ROOT_DIR=/storage + volumes: + - $DATA/storage-data:/storage + depends_on: + - consul + networks: + - default + deploy: + restart_policy: + condition: on-failure + admin: + build: + context: admin/admin-app + environment: + - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 + - KAFKA_IP_PORT=kafka-1:29092,kafka-2:29092,kafka-3:29092 + - CONSUL_HOST=consul + - KEYCLOAK_CLIENT_SECRET=${ADMIN_KEYCLOAK_CLIENT_SECRET} # transfer to vault + volumes: + - $DATA/admin-data:/admin + depends_on: + - zookeeper + - kafka-1 + - kafka-2 + - kafka-3 + - consul + networks: + - default + deploy: + restart_policy: + condition: on-failure +networks: + default: + name: ${DEFAULT_NETWORK_NAME:-opex} + driver: bridge diff --git a/eventlog/eventlog-app/Dockerfile b/eventlog/eventlog-app/Dockerfile index f2cbd4c26..7c71f9447 100644 --- a/eventlog/eventlog-app/Dockerfile +++ b/eventlog/eventlog-app/Dockerfile @@ -1,5 +1,4 @@ -FROM openjdk:8-jdk-alpine -VOLUME /tmp +FROM openjdk:11 ARG JAR_FILE=target/*.jar COPY ${JAR_FILE} app.jar ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -jar /app.jar"] \ No newline at end of file diff --git a/eventlog/eventlog-app/pom.xml b/eventlog/eventlog-app/pom.xml index 88084c14c..8d35db91e 100644 --- a/eventlog/eventlog-app/pom.xml +++ b/eventlog/eventlog-app/pom.xml @@ -47,8 +47,24 @@ co.nilin.opex.eventlog.ports.postgres eventlog-persister-postgres + + org.springframework.cloud + spring-cloud-starter-vault-config + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + diff --git a/eventlog/eventlog-app/src/main/kotlin/co/nilin/opex/eventlog/app/config/AppConfig.kt b/eventlog/eventlog-app/src/main/kotlin/co/nilin/opex/eventlog/app/config/AppConfig.kt index 320f6601e..a786f65fd 100644 --- a/eventlog/eventlog-app/src/main/kotlin/co/nilin/opex/eventlog/app/config/AppConfig.kt +++ b/eventlog/eventlog-app/src/main/kotlin/co/nilin/opex/eventlog/app/config/AppConfig.kt @@ -3,14 +3,14 @@ package co.nilin.opex.eventlog.app.config import co.nilin.opex.eventlog.core.spi.EventPersister import co.nilin.opex.eventlog.core.spi.OrderPersister import co.nilin.opex.eventlog.core.spi.TradePersister -import co.nilin.opex.matching.engine.core.eventh.events.* import co.nilin.opex.eventlog.ports.kafka.listener.consumer.EventKafkaListener import co.nilin.opex.eventlog.ports.kafka.listener.consumer.OrderKafkaListener import co.nilin.opex.eventlog.ports.kafka.listener.consumer.TradeKafkaListener +import co.nilin.opex.eventlog.ports.kafka.listener.inout.OrderSubmitRequest import co.nilin.opex.eventlog.ports.kafka.listener.spi.EventListener import co.nilin.opex.eventlog.ports.kafka.listener.spi.OrderSubmitRequestListener import co.nilin.opex.eventlog.ports.kafka.listener.spi.TradeListener -import co.nilin.opex.eventlog.ports.kafka.listener.inout.OrderSubmitRequest +import co.nilin.opex.matching.engine.core.eventh.events.* import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.runBlocking import org.slf4j.LoggerFactory diff --git a/eventlog/eventlog-app/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt b/eventlog/eventlog-app/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt new file mode 100644 index 000000000..e9efaf92a --- /dev/null +++ b/eventlog/eventlog-app/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt @@ -0,0 +1,9 @@ +package co.nilin.opex.util.vault + +import org.springframework.vault.authentication.AppIdUserIdMechanism + +class VaultUserIdMechanism() : AppIdUserIdMechanism { + override fun createUserId(): String { + return System.getenv("BACKEND_USER") + } +} \ No newline at end of file diff --git a/eventlog/eventlog-app/src/main/resources/application-docker.yml b/eventlog/eventlog-app/src/main/resources/application-docker.yml deleted file mode 100644 index 5055b1c51..000000000 --- a/eventlog/eventlog-app/src/main/resources/application-docker.yml +++ /dev/null @@ -1,11 +0,0 @@ -server.port: 8090 -spring: - kafka: - bootstrap-servers: ${KAFKA_IP_PORT} - consumer: - group-id: eventlog - r2dbc: - url: r2dbc:postgresql://${DB_IP_PORT}/opex_eventlog - username: opex - password: hiopex - initialization-mode: always \ No newline at end of file diff --git a/eventlog/eventlog-app/src/main/resources/application.yml b/eventlog/eventlog-app/src/main/resources/application.yml index 51929e3d6..a083afcd6 100644 --- a/eventlog/eventlog-app/src/main/resources/application.yml +++ b/eventlog/eventlog-app/src/main/resources/application.yml @@ -1,11 +1,31 @@ -server.port: 8090 +server.port: 8080 spring: + application: + name: opex-eventlog + main: + allow-circular-references: true kafka: - bootstrap-servers: localhost:9092 + bootstrap-servers: ${KAFKA_IP_PORT:localhost:9092} consumer: group-id: eventlog r2dbc: - url: r2dbc:postgresql://localhost/opex_eventlog - username: opex - password: hiopex - initialization-mode: always \ No newline at end of file + url: r2dbc:postgresql://${DB_IP_PORT:localhost}/opex_eventlog + username: ${dbusername:opex} + password: ${dbpassword:hiopex} + initialization-mode: always + cloud: + vault: + host: ${VAULT_HOST} + port: 8200 + scheme: http + authentication: APPID + app-id: + user-id: co.nilin.opex.util.vault.VaultUserIdMechanism + fail-fast: true + kv: + enabled: true + backend: secret + profile-separator: '/' + application-name: ${spring.application.name} + config: + import: vault://secret/${spring.application.name} \ No newline at end of file diff --git a/eventlog/eventlog-ports/eventlog-eventlistener-kafka/mvnw b/eventlog/eventlog-ports/eventlog-eventlistener-kafka/mvnw deleted file mode 100644 index a16b5431b..000000000 --- a/eventlog/eventlog-ports/eventlog-eventlistener-kafka/mvnw +++ /dev/null @@ -1,310 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` - fi - - if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=`cygpath --path --windows "$javaClass"` - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/eventlog/eventlog-ports/eventlog-eventlistener-kafka/mvnw.cmd b/eventlog/eventlog-ports/eventlog-eventlistener-kafka/mvnw.cmd deleted file mode 100644 index c8d43372c..000000000 --- a/eventlog/eventlog-ports/eventlog-eventlistener-kafka/mvnw.cmd +++ /dev/null @@ -1,182 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/eventlog/eventlog-ports/eventlog-eventlistener-kafka/src/main/kotlin/co/nilin/opex/eventlog/ports/kafka/listener/config/EventlogKafkaConfig.kt b/eventlog/eventlog-ports/eventlog-eventlistener-kafka/src/main/kotlin/co/nilin/opex/eventlog/ports/kafka/listener/config/EventLogKafkaConfig.kt similarity index 70% rename from eventlog/eventlog-ports/eventlog-eventlistener-kafka/src/main/kotlin/co/nilin/opex/eventlog/ports/kafka/listener/config/EventlogKafkaConfig.kt rename to eventlog/eventlog-ports/eventlog-eventlistener-kafka/src/main/kotlin/co/nilin/opex/eventlog/ports/kafka/listener/config/EventLogKafkaConfig.kt index d149a2fb0..b4f56cf3e 100644 --- a/eventlog/eventlog-ports/eventlog-eventlistener-kafka/src/main/kotlin/co/nilin/opex/eventlog/ports/kafka/listener/config/EventlogKafkaConfig.kt +++ b/eventlog/eventlog-ports/eventlog-eventlistener-kafka/src/main/kotlin/co/nilin/opex/eventlog/ports/kafka/listener/config/EventLogKafkaConfig.kt @@ -1,10 +1,10 @@ package co.nilin.opex.eventlog.ports.kafka.listener.config -import co.nilin.opex.matching.engine.core.eventh.events.CoreEvent import co.nilin.opex.eventlog.ports.kafka.listener.consumer.EventKafkaListener import co.nilin.opex.eventlog.ports.kafka.listener.consumer.OrderKafkaListener import co.nilin.opex.eventlog.ports.kafka.listener.consumer.TradeKafkaListener +import co.nilin.opex.matching.engine.core.eventh.events.CoreEvent import org.apache.kafka.clients.consumer.ConsumerConfig import org.apache.kafka.clients.producer.ProducerConfig import org.apache.kafka.common.serialization.StringDeserializer @@ -24,55 +24,56 @@ import java.util.regex.Pattern @Configuration -class EventlogKafkaConfig { +class EventLogKafkaConfig { + @Value("\${spring.kafka.bootstrap-servers}") private val bootstrapServers: String? = null @Value("\${spring.kafka.consumer.group-id}") private val groupId: String? = null - @Bean("eventlogConsumerConfig") + @Bean("eventLogConsumerConfig") fun consumerConfigs(): Map? { - val props: MutableMap = HashMap() - props[ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG] = bootstrapServers - props[ConsumerConfig.GROUP_ID_CONFIG] = groupId - props[ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG] = StringDeserializer::class.java - props[ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG] = JsonDeserializer::class.java - props[JsonDeserializer.TRUSTED_PACKAGES] = "co.nilin.opex.*" - props[JsonDeserializer.TYPE_MAPPINGS] = "order_request:co.nilin.opex.eventlog.ports.kafka.listener.inout.OrderSubmitRequest" - return props + return mapOf( + ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG to bootstrapServers, + ConsumerConfig.GROUP_ID_CONFIG to groupId, + ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG to StringDeserializer::class.java, + ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG to JsonDeserializer::class.java, + JsonDeserializer.TRUSTED_PACKAGES to "co.nilin.opex.*", + JsonDeserializer.TYPE_MAPPINGS to "order_request:co.nilin.opex.eventlog.ports.kafka.listener.inout.OrderSubmitRequest" + ) } - @Bean("eventlogConsumerFactory") - fun consumerFactory(@Qualifier("eventlogConsumerConfig") consumerConfigs: Map): ConsumerFactory { + @Bean("eventLogConsumerFactory") + fun consumerFactory(@Qualifier("eventLogConsumerConfig") consumerConfigs: Map): ConsumerFactory { return DefaultKafkaConsumerFactory(consumerConfigs) } - @Bean("eventlogProducerConfig") + @Bean("eventLogProducerConfig") fun producerConfigs(): Map { - val props: MutableMap = HashMap() - props[ProducerConfig.BOOTSTRAP_SERVERS_CONFIG] = bootstrapServers - props[ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG] = StringSerializer::class.java - props[ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG] = JsonSerializer::class.java - return props + return mapOf( + ProducerConfig.BOOTSTRAP_SERVERS_CONFIG to bootstrapServers, + ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG to StringSerializer::class.java, + ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG to JsonSerializer::class.java, + ProducerConfig.ACKS_CONFIG to "all" + ) } - @Bean("eventlogProducerFactory") - fun producerFactory(@Qualifier("eventlogProducerConfig") producerConfigs: Map): ProducerFactory { + @Bean("eventLogProducerFactory") + fun producerFactory(@Qualifier("eventLogProducerConfig") producerConfigs: Map): ProducerFactory { return DefaultKafkaProducerFactory(producerConfigs) } - @Bean("eventlogKafkaTemplate") - fun kafkaTemplate(@Qualifier("eventlogProducerFactory") producerFactory: ProducerFactory): KafkaTemplate { + @Bean("eventLogKafkaTemplate") + fun kafkaTemplate(@Qualifier("eventLogProducerFactory") producerFactory: ProducerFactory): KafkaTemplate { return KafkaTemplate(producerFactory) } - @Autowired @ConditionalOnBean(TradeKafkaListener::class) fun configureTradeListener( tradeListener: TradeKafkaListener, - @Qualifier("eventlogConsumerFactory") consumerFactory: ConsumerFactory + @Qualifier("eventLogConsumerFactory") consumerFactory: ConsumerFactory ) { val containerProps = ContainerProperties(Pattern.compile("trades_.*")) containerProps.messageListener = tradeListener @@ -85,7 +86,7 @@ class EventlogKafkaConfig { @ConditionalOnBean(EventKafkaListener::class) fun configureEventListener( eventListener: EventKafkaListener, - @Qualifier("eventlogConsumerFactory") consumerFactory: ConsumerFactory + @Qualifier("eventLogConsumerFactory") consumerFactory: ConsumerFactory ) { val containerProps = ContainerProperties(Pattern.compile("events_.*")) containerProps.messageListener = eventListener @@ -98,7 +99,7 @@ class EventlogKafkaConfig { @ConditionalOnBean(OrderKafkaListener::class) fun configureOrderListener( orderListener: OrderKafkaListener, - @Qualifier("eventlogConsumerFactory") consumerFactory: ConsumerFactory + @Qualifier("eventLogConsumerFactory") consumerFactory: ConsumerFactory ) { val containerProps = ContainerProperties(Pattern.compile("orders_.*")) containerProps.messageListener = orderListener diff --git a/eventlog/eventlog-ports/eventlog-eventlistener-kafka/src/main/kotlin/co/nilin/opex/eventlog/ports/kafka/listener/consumer/EventKafkaListener.kt b/eventlog/eventlog-ports/eventlog-eventlistener-kafka/src/main/kotlin/co/nilin/opex/eventlog/ports/kafka/listener/consumer/EventKafkaListener.kt index 755720cd9..ef6409bc4 100644 --- a/eventlog/eventlog-ports/eventlog-eventlistener-kafka/src/main/kotlin/co/nilin/opex/eventlog/ports/kafka/listener/consumer/EventKafkaListener.kt +++ b/eventlog/eventlog-ports/eventlog-eventlistener-kafka/src/main/kotlin/co/nilin/opex/eventlog/ports/kafka/listener/consumer/EventKafkaListener.kt @@ -1,8 +1,8 @@ package co.nilin.opex.eventlog.ports.kafka.listener.consumer -import co.nilin.opex.matching.engine.core.eventh.events.CoreEvent import co.nilin.opex.eventlog.ports.kafka.listener.spi.EventListener +import co.nilin.opex.matching.engine.core.eventh.events.CoreEvent import org.apache.kafka.clients.consumer.ConsumerRecord import org.springframework.kafka.listener.MessageListener import org.springframework.stereotype.Component diff --git a/eventlog/eventlog-ports/eventlog-eventlistener-kafka/src/main/kotlin/co/nilin/opex/eventlog/ports/kafka/listener/consumer/OrderKafkaListener.kt b/eventlog/eventlog-ports/eventlog-eventlistener-kafka/src/main/kotlin/co/nilin/opex/eventlog/ports/kafka/listener/consumer/OrderKafkaListener.kt index 52ee41459..58ffa6310 100644 --- a/eventlog/eventlog-ports/eventlog-eventlistener-kafka/src/main/kotlin/co/nilin/opex/eventlog/ports/kafka/listener/consumer/OrderKafkaListener.kt +++ b/eventlog/eventlog-ports/eventlog-eventlistener-kafka/src/main/kotlin/co/nilin/opex/eventlog/ports/kafka/listener/consumer/OrderKafkaListener.kt @@ -1,7 +1,7 @@ package co.nilin.opex.eventlog.ports.kafka.listener.consumer -import co.nilin.opex.eventlog.ports.kafka.listener.spi.OrderSubmitRequestListener import co.nilin.opex.eventlog.ports.kafka.listener.inout.OrderSubmitRequest +import co.nilin.opex.eventlog.ports.kafka.listener.spi.OrderSubmitRequestListener import kotlinx.coroutines.ExecutorCoroutineDispatcher import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext diff --git a/eventlog/eventlog-ports/eventlog-eventlistener-kafka/src/main/kotlin/co/nilin/opex/eventlog/ports/kafka/listener/consumer/TradeKafkaListener.kt b/eventlog/eventlog-ports/eventlog-eventlistener-kafka/src/main/kotlin/co/nilin/opex/eventlog/ports/kafka/listener/consumer/TradeKafkaListener.kt index 2f2b7c388..127e304d6 100644 --- a/eventlog/eventlog-ports/eventlog-eventlistener-kafka/src/main/kotlin/co/nilin/opex/eventlog/ports/kafka/listener/consumer/TradeKafkaListener.kt +++ b/eventlog/eventlog-ports/eventlog-eventlistener-kafka/src/main/kotlin/co/nilin/opex/eventlog/ports/kafka/listener/consumer/TradeKafkaListener.kt @@ -1,8 +1,8 @@ package co.nilin.opex.eventlog.ports.kafka.listener.consumer -import co.nilin.opex.matching.engine.core.eventh.events.TradeEvent import co.nilin.opex.eventlog.ports.kafka.listener.spi.TradeListener +import co.nilin.opex.matching.engine.core.eventh.events.TradeEvent import org.apache.kafka.clients.consumer.ConsumerRecord import org.springframework.kafka.listener.MessageListener import org.springframework.stereotype.Component diff --git a/eventlog/eventlog-ports/eventlog-persister-postgres/mvnw b/eventlog/eventlog-ports/eventlog-persister-postgres/mvnw deleted file mode 100644 index a16b5431b..000000000 --- a/eventlog/eventlog-ports/eventlog-persister-postgres/mvnw +++ /dev/null @@ -1,310 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` - fi - - if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=`cygpath --path --windows "$javaClass"` - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/eventlog/eventlog-ports/eventlog-persister-postgres/mvnw.cmd b/eventlog/eventlog-ports/eventlog-persister-postgres/mvnw.cmd deleted file mode 100644 index c8d43372c..000000000 --- a/eventlog/eventlog-ports/eventlog-persister-postgres/mvnw.cmd +++ /dev/null @@ -1,182 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/eventlog/eventlog-ports/eventlog-persister-postgres/src/main/kotlin/co/nilin/opex/eventlog/ports/postgres/impl/EventPersisterImpl.kt b/eventlog/eventlog-ports/eventlog-persister-postgres/src/main/kotlin/co/nilin/opex/eventlog/ports/postgres/impl/EventPersisterImpl.kt index f788a1030..0b4d3eb4e 100644 --- a/eventlog/eventlog-ports/eventlog-persister-postgres/src/main/kotlin/co/nilin/opex/eventlog/ports/postgres/impl/EventPersisterImpl.kt +++ b/eventlog/eventlog-ports/eventlog-persister-postgres/src/main/kotlin/co/nilin/opex/eventlog/ports/postgres/impl/EventPersisterImpl.kt @@ -2,11 +2,11 @@ package co.nilin.opex.eventlog.ports.postgres.impl import co.nilin.opex.eventlog.core.spi.Event import co.nilin.opex.eventlog.core.spi.EventPersister +import co.nilin.opex.eventlog.ports.postgres.dao.EventRepository +import co.nilin.opex.eventlog.ports.postgres.model.EventModel import co.nilin.opex.matching.engine.core.eventh.events.CoreEvent import co.nilin.opex.matching.engine.core.eventh.events.OneOrderEvent import co.nilin.opex.matching.engine.core.eventh.events.TradeEvent -import co.nilin.opex.eventlog.ports.postgres.dao.EventRepository -import co.nilin.opex.eventlog.ports.postgres.model.EventModel import kotlinx.coroutines.reactive.awaitFirst import org.springframework.stereotype.Component import java.time.LocalDateTime diff --git a/eventlog/eventlog-ports/eventlog-persister-postgres/src/main/kotlin/co/nilin/opex/eventlog/ports/postgres/impl/OrderPersisterImpl.kt b/eventlog/eventlog-ports/eventlog-persister-postgres/src/main/kotlin/co/nilin/opex/eventlog/ports/postgres/impl/OrderPersisterImpl.kt index 3837743f5..62cb63760 100644 --- a/eventlog/eventlog-ports/eventlog-persister-postgres/src/main/kotlin/co/nilin/opex/eventlog/ports/postgres/impl/OrderPersisterImpl.kt +++ b/eventlog/eventlog-ports/eventlog-persister-postgres/src/main/kotlin/co/nilin/opex/eventlog/ports/postgres/impl/OrderPersisterImpl.kt @@ -1,11 +1,11 @@ package co.nilin.opex.eventlog.ports.postgres.impl import co.nilin.opex.eventlog.core.spi.OrderPersister -import co.nilin.opex.matching.engine.core.eventh.events.* import co.nilin.opex.eventlog.ports.postgres.dao.OrderEventRepository import co.nilin.opex.eventlog.ports.postgres.dao.OrderRepository import co.nilin.opex.eventlog.ports.postgres.model.OrderEventsModel import co.nilin.opex.eventlog.ports.postgres.model.OrderModel +import co.nilin.opex.matching.engine.core.eventh.events.* import kotlinx.coroutines.reactive.awaitFirst import kotlinx.coroutines.reactive.awaitFirstOrNull import org.springframework.stereotype.Component diff --git a/eventlog/eventlog-ports/eventlog-persister-postgres/src/main/kotlin/co/nilin/opex/eventlog/ports/postgres/impl/TradePersisterImpl.kt b/eventlog/eventlog-ports/eventlog-persister-postgres/src/main/kotlin/co/nilin/opex/eventlog/ports/postgres/impl/TradePersisterImpl.kt index 12672fc02..62b904754 100644 --- a/eventlog/eventlog-ports/eventlog-persister-postgres/src/main/kotlin/co/nilin/opex/eventlog/ports/postgres/impl/TradePersisterImpl.kt +++ b/eventlog/eventlog-ports/eventlog-persister-postgres/src/main/kotlin/co/nilin/opex/eventlog/ports/postgres/impl/TradePersisterImpl.kt @@ -2,9 +2,9 @@ package co.nilin.opex.eventlog.ports.postgres.impl import co.nilin.opex.eventlog.core.spi.Trade import co.nilin.opex.eventlog.core.spi.TradePersister -import co.nilin.opex.matching.engine.core.eventh.events.TradeEvent import co.nilin.opex.eventlog.ports.postgres.dao.TradeRepository import co.nilin.opex.eventlog.ports.postgres.model.TradeModel +import co.nilin.opex.matching.engine.core.eventh.events.TradeEvent import kotlinx.coroutines.reactive.awaitFirst import org.springframework.stereotype.Component import java.time.LocalDateTime diff --git a/eventlog/eventlog-ports/eventlog-persister-postgres/src/main/resources/schema.sql b/eventlog/eventlog-ports/eventlog-persister-postgres/src/main/resources/schema.sql index 04e9bc1c6..8c5be4314 100644 --- a/eventlog/eventlog-ports/eventlog-persister-postgres/src/main/resources/schema.sql +++ b/eventlog/eventlog-ports/eventlog-persister-postgres/src/main/resources/schema.sql @@ -1,62 +1,66 @@ -CREATE TABLE IF NOT EXISTS opex_orders ( - id SERIAL PRIMARY KEY, - ouid VARCHAR(72) NOT NULL UNIQUE, - symbol VARCHAR(20) NOT NULL, - direction VARCHAR(20) NOT NULL, - match_constraint VARCHAR(20) NOT NULL, - order_type VARCHAR(20) NOT NULL, - uuid VARCHAR(72) NOT NULL, - agent VARCHAR(20), - ip VARCHAR(11), - order_date TIMESTAMP NOT NULL, - create_date TIMESTAMP NOT NULL +CREATE TABLE IF NOT EXISTS opex_orders +( + id SERIAL PRIMARY KEY, + ouid VARCHAR(72) NOT NULL UNIQUE, + symbol VARCHAR(20) NOT NULL, + direction VARCHAR(20) NOT NULL, + match_constraint VARCHAR(20) NOT NULL, + order_type VARCHAR(20) NOT NULL, + uuid VARCHAR(72) NOT NULL, + agent VARCHAR(20), + ip VARCHAR(11), + order_date TIMESTAMP NOT NULL, + create_date TIMESTAMP NOT NULL ); -CREATE TABLE IF NOT EXISTS opex_order_events ( - id SERIAL PRIMARY KEY, - ouid VARCHAR(72) NOT NULL, - matching_orderid BIGINT, - price BIGINT, - quantity BIGINT, - filled_quantity BIGINT, - uuid VARCHAR(72) NOT NULL, - event VARCHAR(30) NOT NULL, - agent VARCHAR(20), - ip VARCHAR(11), - event_date TIMESTAMP NOT NULL, - create_date TIMESTAMP NOT NULL +CREATE TABLE IF NOT EXISTS opex_order_events +( + id SERIAL PRIMARY KEY, + ouid VARCHAR(72) NOT NULL, + matching_orderid BIGINT, + price BIGINT, + quantity BIGINT, + filled_quantity BIGINT, + uuid VARCHAR(72) NOT NULL, + event VARCHAR(30) NOT NULL, + agent VARCHAR(20), + ip VARCHAR(11), + event_date TIMESTAMP NOT NULL, + create_date TIMESTAMP NOT NULL ); -CREATE TABLE IF NOT EXISTS opex_events ( - id SERIAL PRIMARY KEY, - correlation_id VARCHAR(72) NOT NULL, - ouid VARCHAR(72) NOT NULL, - uuid VARCHAR(72) NOT NULL, - symbol VARCHAR(20) NOT NULL, - event VARCHAR(30) NOT NULL, - event_json TEXT NOT NULL, - agent VARCHAR(20), - ip VARCHAR(11), - event_date TIMESTAMP NOT NULL, - create_date TIMESTAMP NOT NULL +CREATE TABLE IF NOT EXISTS opex_events +( + id SERIAL PRIMARY KEY, + correlation_id VARCHAR(72) NOT NULL, + ouid VARCHAR(72) NOT NULL, + uuid VARCHAR(72) NOT NULL, + symbol VARCHAR(20) NOT NULL, + event VARCHAR(30) NOT NULL, + event_json TEXT NOT NULL, + agent VARCHAR(20), + ip VARCHAR(11), + event_date TIMESTAMP NOT NULL, + create_date TIMESTAMP NOT NULL ); -CREATE TABLE IF NOT EXISTS opex_trades ( - id SERIAL PRIMARY KEY, - symbol VARCHAR(20) NOT NULL, - taker_ouid VARCHAR(72) NOT NULL, - taker_uuid VARCHAR(72) NOT NULL, - taker_matching_orderid BIGINT NOT NULL, - taker_direction VARCHAR(20) NOT NULL, - taker_price BIGINT NOT NULL, - taker_remained_quantity BIGINT NOT NULL, - maker_ouid VARCHAR(72) NOT NULL, - maker_uuid VARCHAR(72) NOT NULL, - maker_matching_orderid BIGINT NOT NULL, - maker_direction VARCHAR(20) NOT NULL, - maker_price BIGINT NOT NULL, - maker_remained_quantity BIGINT NOT NULL, - matched_quantity BIGINT NOT NULL, - trade_date TIMESTAMP NOT NULL, - create_date TIMESTAMP NOT NULL +CREATE TABLE IF NOT EXISTS opex_trades +( + id SERIAL PRIMARY KEY, + symbol VARCHAR(20) NOT NULL, + taker_ouid VARCHAR(72) NOT NULL, + taker_uuid VARCHAR(72) NOT NULL, + taker_matching_orderid BIGINT NOT NULL, + taker_direction VARCHAR(20) NOT NULL, + taker_price BIGINT NOT NULL, + taker_remained_quantity BIGINT NOT NULL, + maker_ouid VARCHAR(72) NOT NULL, + maker_uuid VARCHAR(72) NOT NULL, + maker_matching_orderid BIGINT NOT NULL, + maker_direction VARCHAR(20) NOT NULL, + maker_price BIGINT NOT NULL, + maker_remained_quantity BIGINT NOT NULL, + matched_quantity BIGINT NOT NULL, + trade_date TIMESTAMP NOT NULL, + create_date TIMESTAMP NOT NULL ); diff --git a/matching-engine/matching-engine-app/Dockerfile b/matching-engine/matching-engine-app/Dockerfile index f2cbd4c26..7c71f9447 100644 --- a/matching-engine/matching-engine-app/Dockerfile +++ b/matching-engine/matching-engine-app/Dockerfile @@ -1,5 +1,4 @@ -FROM openjdk:8-jdk-alpine -VOLUME /tmp +FROM openjdk:11 ARG JAR_FILE=target/*.jar COPY ${JAR_FILE} app.jar ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -jar /app.jar"] \ No newline at end of file diff --git a/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/bl/OrderBooks.kt b/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/bl/OrderBooks.kt index 45be41247..af298bbf8 100644 --- a/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/bl/OrderBooks.kt +++ b/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/bl/OrderBooks.kt @@ -2,6 +2,7 @@ package co.nilin.opex.matching.engine.app.bl import co.nilin.opex.matching.engine.core.factory.OrderBookFactory import co.nilin.opex.matching.engine.core.model.OrderBook +import co.nilin.opex.matching.engine.core.model.Pair import co.nilin.opex.matching.engine.core.model.PersistentOrderBook object OrderBooks { @@ -12,7 +13,7 @@ object OrderBooks { if (orderBooks.containsKey(pair)) throw IllegalArgumentException("${pair} has an order book right now!") val pairs = pair.split("_") - orderBooks[pair] = OrderBookFactory.createOrderBook(co.nilin.opex.matching.engine.core.model.Pair(pairs[0], pairs[1])) + orderBooks[pair] = OrderBookFactory.createOrderBook(Pair(pairs[0], pairs[1])) println("order book:" + pair + " added, current order books#" + orderBooks.size) } diff --git a/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/AppConfig.kt b/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/AppConfig.kt index c8751c699..ef535cba3 100644 --- a/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/AppConfig.kt +++ b/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/AppConfig.kt @@ -2,24 +2,15 @@ package co.nilin.opex.matching.engine.app.config import co.nilin.opex.matching.engine.app.bl.ExchangeEventHandler import co.nilin.opex.matching.engine.app.bl.OrderBooks -import co.nilin.opex.matching.engine.core.eventh.events.CancelOrderEvent -import co.nilin.opex.matching.engine.core.eventh.events.CoreEvent -import co.nilin.opex.matching.engine.core.eventh.events.EditOrderRequestEvent -import co.nilin.opex.matching.engine.core.inout.OrderCancelCommand -import co.nilin.opex.matching.engine.core.inout.OrderCreateCommand -import co.nilin.opex.matching.engine.core.inout.OrderEditCommand +import co.nilin.opex.matching.engine.app.listener.MatchingEngineEventListener +import co.nilin.opex.matching.engine.app.listener.OrderListener import co.nilin.opex.matching.engine.core.model.PersistentOrderBook import co.nilin.opex.matching.engine.core.spi.OrderBookPersister import co.nilin.opex.matching.engine.ports.kafka.listener.consumer.EventKafkaListener import co.nilin.opex.matching.engine.ports.kafka.listener.consumer.OrderKafkaListener -import co.nilin.opex.matching.engine.ports.kafka.listener.inout.OrderSubmitRequest -import co.nilin.opex.matching.engine.ports.kafka.listener.spi.EventListener -import co.nilin.opex.matching.engine.ports.kafka.listener.spi.OrderSubmitRequestListener import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch -import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext -import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Value import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean @@ -45,7 +36,6 @@ class AppConfig { } } - @Autowired fun configureOrderBooks(orderBookPersister: OrderBookPersister) { symbols!!.split(",") @@ -66,7 +56,6 @@ class AppConfig { } } - @Bean fun orderListener(): OrderListener { return OrderListener() @@ -92,70 +81,4 @@ class AppConfig { exchangeEventHandler.register() } - class OrderListener() : OrderSubmitRequestListener { - - override fun id(): String { - return "OrderListener" - } - - override suspend fun onOrder(order: OrderSubmitRequest, partition: Int, offset: Long, timestamp: Long) { - val orderBook = OrderBooks.lookupOrderBook( - order.pair.leftSideName + "_" - + order.pair.rightSideName - ) - orderBook.handleNewOrderCommand( - OrderCreateCommand( - order.ouid, - order.uuid, - order.pair, - order.price, - order.quantity, - order.direction, - order.matchConstraint, - order.orderType - ) - ) - } - } - - class MatchingEngineEventListener() : EventListener { - - private val logger = LoggerFactory.getLogger(MatchingEngineEventListener::class.java) - - override fun id(): String { - return "EventListener" - } - - override fun onEvent(event: CoreEvent, partition: Int, offset: Long, timestamp: Long) { - logger.info("Received CoreEvent: ${event::class.java}") - - runBlocking(AppSchedulers.kafkaExecutor) { - val orderBook = OrderBooks.lookupOrderBook("${event.pair.leftSideName}_${event.pair.rightSideName}") - - when (event) { - is EditOrderRequestEvent -> orderBook.handleEditCommand( - OrderEditCommand( - event.ouid, - event.uuid, - event.orderId, - event.pair, - event.price, - event.quantity - ) - ) - - is CancelOrderEvent -> orderBook.handleCancelCommand( - OrderCancelCommand( - event.ouid, - event.uuid, - event.orderId, - event.pair - ) - ) - else -> null - } - } - } - } - } \ No newline at end of file diff --git a/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/listener/MatchingEngineEventListener.kt b/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/listener/MatchingEngineEventListener.kt new file mode 100644 index 000000000..0725120d0 --- /dev/null +++ b/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/listener/MatchingEngineEventListener.kt @@ -0,0 +1,51 @@ +package co.nilin.opex.matching.engine.app.listener + +import co.nilin.opex.matching.engine.app.bl.OrderBooks +import co.nilin.opex.matching.engine.core.eventh.events.CancelOrderEvent +import co.nilin.opex.matching.engine.core.eventh.events.CoreEvent +import co.nilin.opex.matching.engine.core.eventh.events.EditOrderRequestEvent +import co.nilin.opex.matching.engine.core.inout.OrderCancelCommand +import co.nilin.opex.matching.engine.core.inout.OrderEditCommand +import co.nilin.opex.matching.engine.ports.kafka.listener.spi.EventListener +import kotlinx.coroutines.runBlocking +import org.slf4j.LoggerFactory + +class MatchingEngineEventListener : EventListener { + + private val logger = LoggerFactory.getLogger(MatchingEngineEventListener::class.java) + + override fun id(): String { + return "EventListener" + } + + override fun onEvent(event: CoreEvent, partition: Int, offset: Long, timestamp: Long) { + logger.info("Received CoreEvent: ${event::class.java}") + + runBlocking { + val orderBook = OrderBooks.lookupOrderBook("${event.pair.leftSideName}_${event.pair.rightSideName}") + + when (event) { + is EditOrderRequestEvent -> orderBook.handleEditCommand( + OrderEditCommand( + event.ouid, + event.uuid, + event.orderId, + event.pair, + event.price, + event.quantity + ) + ) + + is CancelOrderEvent -> orderBook.handleCancelCommand( + OrderCancelCommand( + event.ouid, + event.uuid, + event.orderId, + event.pair + ) + ) + else -> null + } + } + } +} \ No newline at end of file diff --git a/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/listener/OrderListener.kt b/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/listener/OrderListener.kt new file mode 100644 index 000000000..b452fcbdd --- /dev/null +++ b/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/listener/OrderListener.kt @@ -0,0 +1,32 @@ +package co.nilin.opex.matching.engine.app.listener + +import co.nilin.opex.matching.engine.app.bl.OrderBooks +import co.nilin.opex.matching.engine.core.inout.OrderCreateCommand +import co.nilin.opex.matching.engine.ports.kafka.listener.inout.OrderSubmitRequest +import co.nilin.opex.matching.engine.ports.kafka.listener.spi.OrderSubmitRequestListener + +class OrderListener : OrderSubmitRequestListener { + + override fun id(): String { + return "OrderListener" + } + + override suspend fun onOrder(order: OrderSubmitRequest, partition: Int, offset: Long, timestamp: Long) { + val orderBook = OrderBooks.lookupOrderBook( + order.pair.leftSideName + "_" + + order.pair.rightSideName + ) + orderBook.handleNewOrderCommand( + OrderCreateCommand( + order.ouid, + order.uuid, + order.pair, + order.price, + order.quantity, + order.direction, + order.matchConstraint, + order.orderType + ) + ) + } +} \ No newline at end of file diff --git a/matching-engine/matching-engine-app/src/main/resources/application-docker.yml b/matching-engine/matching-engine-app/src/main/resources/application-docker.yml deleted file mode 100644 index d2bddd8e0..000000000 --- a/matching-engine/matching-engine-app/src/main/resources/application-docker.yml +++ /dev/null @@ -1,13 +0,0 @@ -server.port: 8092 -spring: - main: - allow-bean-definition-overriding: false - kafka: - bootstrap-servers: ${KAFKA_IP_PORT} - consumer: - group-id: engine - redis: - host: ${REDIS_HOST} - port: 6379 - app: - symbols: btc_usdt,eth_usdt,eth_btc \ No newline at end of file diff --git a/matching-engine/matching-engine-app/src/main/resources/application.yml b/matching-engine/matching-engine-app/src/main/resources/application.yml index bfb7b297e..7c4d889f3 100644 --- a/matching-engine/matching-engine-app/src/main/resources/application.yml +++ b/matching-engine/matching-engine-app/src/main/resources/application.yml @@ -1,13 +1,14 @@ -server.port: 8092 +server.port: 8080 spring: main: allow-bean-definition-overriding: false + allow-circular-references: true kafka: - bootstrap-servers: localhost:9092 + bootstrap-servers: ${KAFKA_IP_PORT:localhost:9092} consumer: group-id: engine redis: - host: 127.0.0.1 + host: ${REDIS_HOST:localhost} port: 6379 app: symbols: btc_usdt,eth_usdt,eth_btc \ No newline at end of file diff --git "a/matching-engine/matching-engine-app/src/test/kotlin/co/nilin/opex/matching/core/engine/OrderBook\331\215EventEmitsUnitTest.kt" b/matching-engine/matching-engine-app/src/test/kotlin/co/nilin/opex/matching/engine/app/OrderBookEventEmitsUnitTest.kt similarity index 93% rename from "matching-engine/matching-engine-app/src/test/kotlin/co/nilin/opex/matching/core/engine/OrderBook\331\215EventEmitsUnitTest.kt" rename to matching-engine/matching-engine-app/src/test/kotlin/co/nilin/opex/matching/engine/app/OrderBookEventEmitsUnitTest.kt index cc6ac51c9..dad59e359 100644 --- "a/matching-engine/matching-engine-app/src/test/kotlin/co/nilin/opex/matching/core/engine/OrderBook\331\215EventEmitsUnitTest.kt" +++ b/matching-engine/matching-engine-app/src/test/kotlin/co/nilin/opex/matching/engine/app/OrderBookEventEmitsUnitTest.kt @@ -1,5 +1,6 @@ -package co.nilin.opex.matching.engine.core.engine +package co.nilin.opex.matching.engine.app +import co.nilin.opex.matching.engine.core.engine.SimpleOrderBook import co.nilin.opex.matching.engine.core.eventh.EventDispatcher import co.nilin.opex.matching.engine.core.eventh.events.OrderBookPublishedEvent import co.nilin.opex.matching.engine.core.inout.OrderCancelCommand @@ -15,10 +16,10 @@ import org.junit.jupiter.api.Test import java.util.* class OrderBookEventEmitsUnitTest { - val pair = co.nilin.opex.matching.engine.core.model.Pair("BTC", "USDT") - val uuid = UUID.randomUUID().toString() + private val pair = co.nilin.opex.matching.engine.core.model.Pair("BTC", "USDT") + private val uuid = UUID.randomUUID().toString() - var persistentOrderBook: PersistentOrderBook? = null + private var persistentOrderBook: PersistentOrderBook? = null @BeforeEach fun setup() { @@ -144,6 +145,4 @@ class OrderBookEventEmitsUnitTest { //then Assertions.assertNotNull(persistentOrderBook) } - - } \ No newline at end of file diff --git a/matching-engine/matching-engine-core/mvnw b/matching-engine/matching-engine-core/mvnw deleted file mode 100644 index a16b5431b..000000000 --- a/matching-engine/matching-engine-core/mvnw +++ /dev/null @@ -1,310 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` - fi - - if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=`cygpath --path --windows "$javaClass"` - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/matching-engine/matching-engine-core/mvnw.cmd b/matching-engine/matching-engine-core/mvnw.cmd deleted file mode 100644 index c8d43372c..000000000 --- a/matching-engine/matching-engine-core/mvnw.cmd +++ /dev/null @@ -1,182 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/engine/SimpleOrderBook.kt b/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/engine/SimpleOrderBook.kt index c11e22e76..7b01bac7b 100644 --- a/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/engine/SimpleOrderBook.kt +++ b/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/engine/SimpleOrderBook.kt @@ -11,66 +11,22 @@ import java.util.concurrent.atomic.AtomicLong class SimpleOrderBook(val pair: Pair, var replayMode: Boolean) : OrderBook { - private val logger = LoggerFactory.getLogger(co.nilin.opex.matching.engine.core.engine.SimpleOrderBook::class.java) + private val logger = LoggerFactory.getLogger(SimpleOrderBook::class.java) - val askOrders = LongAdaptiveRadixTreeMap() - val bidOrders = LongAdaptiveRadixTreeMap() - val orders = TreeMap() + val askOrders = LongAdaptiveRadixTreeMap() + val bidOrders = LongAdaptiveRadixTreeMap() + val orders = TreeMap() - var bestAskOrder: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder? = null - var bestBidOrder: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder? = null + var bestAskOrder: SimpleOrder? = null + var bestBidOrder: SimpleOrder? = null val orderCounter = AtomicLong() val tradeCounter = AtomicLong() - var lastOrder: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder? = null - - data class SimpleOrder( - var id: Long?, - val ouid: String, - val uuid: String, - val price: Long, - val quantity: Long, - val matchConstraint: MatchConstraint, - val orderType: OrderType, - val direction: OrderDirection, - var filledQuantity: Long, - var worse: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder?, - var better: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder?, - var bucket: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.Bucket? - ) : Order { - fun remainedQuantity() = quantity - filledQuantity - override fun id(): Long? = id - override fun toString(): String { - return "SimpleOrder(id=$id, price=$price, quantity=$quantity, matchConstraint=$matchConstraint, orderType=$orderType, filledQuantity=$filledQuantity, worse=${worse?.id}, better=${better?.id}, bucket=${bucket?.totalQuantity})" - } - - override fun persistent(): PersistentOrder { - return PersistentOrder( - id!!, - ouid, - uuid, - price, - quantity, - matchConstraint, - orderType, - direction, - filledQuantity - ) - } - } - - data class Bucket(val price: Long, var totalQuantity: Long, var ordersCount: Long, var lastOrder: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder) + var lastOrder: SimpleOrder? = null override fun handleNewOrderCommand(orderCommand: OrderCreateCommand): Order? { - logger.info("****************** new order received *******************") - logger.info("** order id: ${orderCommand.ouid}") - logger.info("** price: ${orderCommand.price}") - logger.info("** quantity: ${orderCommand.quantity}") - logger.info("** direction: ${orderCommand.direction}") - logger.info("*********************************************************") - println() - + logNewOrder(orderCommand) val order = when (orderCommand.matchConstraint) { MatchConstraint.GTC -> { if (orderCommand.orderType == OrderType.MARKET_ORDER) { @@ -92,7 +48,7 @@ class SimpleOrderBook(val pair: Pair, var replayMode: Boolean) : OrderBook { } return null } - val order = co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder( + val order = SimpleOrder( orderCounter.incrementAndGet(), orderCommand.ouid, orderCommand.uuid, @@ -131,7 +87,7 @@ class SimpleOrderBook(val pair: Pair, var replayMode: Boolean) : OrderBook { queueOrder } MatchConstraint.IOC -> { - val order = co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder( + val order = SimpleOrder( orderCounter.incrementAndGet(), orderCommand.ouid, orderCommand.uuid, @@ -230,11 +186,11 @@ class SimpleOrderBook(val pair: Pair, var replayMode: Boolean) : OrderBook { } if (order.direction == OrderDirection.BID) { - handleCancelOrder(order, bidOrders, bestBidOrder) { newBestOrder: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder? -> + handleCancelOrder(order, bidOrders, bestBidOrder) { newBestOrder: SimpleOrder? -> bestBidOrder = newBestOrder } } else { - handleCancelOrder(order, askOrders, bestAskOrder) { newBestOrder: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder? -> + handleCancelOrder(order, askOrders, bestAskOrder) { newBestOrder: SimpleOrder? -> bestAskOrder = newBestOrder } } @@ -271,15 +227,15 @@ class SimpleOrderBook(val pair: Pair, var replayMode: Boolean) : OrderBook { return order } if (order.direction == OrderDirection.BID) { - handleCancelOrder(order, bidOrders, bestBidOrder) { newBestOrder: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder? -> + handleCancelOrder(order, bidOrders, bestBidOrder) { newBestOrder: SimpleOrder? -> bestBidOrder = newBestOrder } } else { - handleCancelOrder(order, askOrders, bestAskOrder) { newBestOrder: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder? -> + handleCancelOrder(order, askOrders, bestAskOrder) { newBestOrder: SimpleOrder? -> bestAskOrder = newBestOrder } } - val newOrder = co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder( + val newOrder = SimpleOrder( order.id, orderCommand.ouid, orderCommand.uuid, @@ -382,10 +338,10 @@ class SimpleOrderBook(val pair: Pair, var replayMode: Boolean) : OrderBook { } private fun handleCancelOrder( - order: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder, - bucketQueue: LongAdaptiveRadixTreeMap, - bestOrder: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder?, - setBestOrder: (co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder?) -> Unit + order: SimpleOrder, + bucketQueue: LongAdaptiveRadixTreeMap, + bestOrder: SimpleOrder?, + setBestOrder: (SimpleOrder?) -> Unit ) { val bucket = order.bucket!! bucket.ordersCount-- @@ -402,62 +358,62 @@ class SimpleOrderBook(val pair: Pair, var replayMode: Boolean) : OrderBook { setBestOrder(bestOrder.worse) } - private fun matchInstantly(order: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder): co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder { + private fun matchInstantly(order: SimpleOrder): SimpleOrder { if (order.direction == OrderDirection.BID) { return matchInstantly(order, bestAskOrder, askOrders, { makerPrice: Long -> makerPrice <= order.price - }) { newMakerOrder: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder? -> + }) { newMakerOrder: SimpleOrder? -> bestAskOrder = newMakerOrder } } else { return matchInstantly(order, bestBidOrder, bidOrders, { makerPrice: Long -> makerPrice >= order.price - }) { newMakerOrder: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder? -> + }) { newMakerOrder: SimpleOrder? -> bestBidOrder = newMakerOrder } } } - private fun matchIocInstantly(order: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder): co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder { + private fun matchIocInstantly(order: SimpleOrder): SimpleOrder { if (order.direction == OrderDirection.BID) { return matchInstantly(order, bestAskOrder, askOrders, { makerPrice: Long -> order.orderType == OrderType.MARKET_ORDER || makerPrice <= order.price - }) { newMakerOrder: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder? -> + }) { newMakerOrder: SimpleOrder? -> bestAskOrder = newMakerOrder } } else { return matchInstantly(order, bestBidOrder, bidOrders, { makerPrice: Long -> order.orderType == OrderType.MARKET_ORDER || makerPrice >= order.price - }) { newMakerOrder: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder? -> + }) { newMakerOrder: SimpleOrder? -> bestBidOrder = newMakerOrder } } } - private fun putGtcInQueue(order: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder): co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder { + private fun putGtcInQueue(order: SimpleOrder): SimpleOrder { if (order.direction == OrderDirection.BID) { return putGtcInQueue(order, bidOrders, bestBidOrder, { price, queue -> queue.getHigherValue(price) - }) { newMakerOrder: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder? -> + }) { newMakerOrder: SimpleOrder? -> bestBidOrder = newMakerOrder } } else { return putGtcInQueue(order, askOrders, bestAskOrder, { price, queue -> queue.getLowerValue(price) - }) { newMakerOrder: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder? -> + }) { newMakerOrder: SimpleOrder? -> bestAskOrder = newMakerOrder } } } private fun matchInstantly( - order: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder, - makerOrder: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder?, - queue: LongAdaptiveRadixTreeMap, + order: SimpleOrder, + makerOrder: SimpleOrder?, + queue: LongAdaptiveRadixTreeMap, isPriceMatched: (makerPrice: Long) -> Boolean, - setNewMarkerOrder: (co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder?) -> Unit - ): co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder { + setNewMarkerOrder: (SimpleOrder?) -> Unit + ): SimpleOrder { //the best sell price is higher the requested buy price, so no instant match if (makerOrder == null || !isPriceMatched(makerOrder.price)) { return order @@ -519,14 +475,13 @@ class SimpleOrderBook(val pair: Pair, var replayMode: Boolean) : OrderBook { } - private fun putGtcInQueue( - order: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder, - queue: LongAdaptiveRadixTreeMap, - bestOrder: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder?, - betterBucketSelector: (price: Long, queue: LongAdaptiveRadixTreeMap) -> co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.Bucket?, - setNewMarkerOrder: (co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder?) -> Unit - ): co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder { + order: SimpleOrder, + queue: LongAdaptiveRadixTreeMap, + bestOrder: SimpleOrder?, + betterBucketSelector: (price: Long, queue: LongAdaptiveRadixTreeMap) -> Bucket?, + setNewMarkerOrder: (SimpleOrder?) -> Unit + ): SimpleOrder { if (order.id == null) order.id = orderCounter.incrementAndGet() orders[order.id!!] = order @@ -545,7 +500,7 @@ class SimpleOrderBook(val pair: Pair, var replayMode: Boolean) : OrderBook { order.better = bucketLastOrder order.worse = worseOfBucketLastOrder } else { - bucket = co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.Bucket( + bucket = Bucket( order.price, order.remainedQuantity(), 1, @@ -592,14 +547,14 @@ class SimpleOrderBook(val pair: Pair, var replayMode: Boolean) : OrderBook { private fun persistent(): PersistentOrderBook { val persistent = PersistentOrderBook(pair) persistent.lastOrder = lastOrder?.persistent() - persistent.orders = orders.values - .map { order -> order.persistent() } + persistent.orders = orders.values.map { order -> order.persistent() } + persistent.tradeCounter = tradeCounter.get() return persistent } fun rebuild(persistentOrderBook: PersistentOrderBook) { persistentOrderBook.orders?.map { order -> - co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder( + SimpleOrder( order.id, order.ouid, order.uuid, @@ -616,7 +571,19 @@ class SimpleOrderBook(val pair: Pair, var replayMode: Boolean) : OrderBook { }?.filter { order -> order.matchConstraint == MatchConstraint.GTC }?.forEach { order -> putGtcInQueue(order) } + orderCounter.set(persistentOrderBook.lastOrder?.id ?: 0) + tradeCounter.set(persistentOrderBook.tradeCounter) + } + + private fun logNewOrder(orderCommand: OrderCreateCommand) { + logger.info("****************** new order received *******************") + logger.info("** order id: ${orderCommand.ouid}") + logger.info("** price: ${orderCommand.price}") + logger.info("** quantity: ${orderCommand.quantity}") + logger.info("** direction: ${orderCommand.direction}") + logger.info("*********************************************************") + println() } private fun logCurrentState() { diff --git a/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/CancelOrderEvent.kt b/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/CancelOrderEvent.kt index 708bfa6c4..1a1ba2fde 100644 --- a/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/CancelOrderEvent.kt +++ b/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/CancelOrderEvent.kt @@ -3,42 +3,20 @@ package co.nilin.opex.matching.engine.core.eventh.events import co.nilin.opex.matching.engine.core.model.MatchConstraint import co.nilin.opex.matching.engine.core.model.OrderDirection import co.nilin.opex.matching.engine.core.model.OrderType +import co.nilin.opex.matching.engine.core.model.Pair -class CancelOrderEvent() : CoreEvent(), OneOrderEvent { - var ouid: String = "" - var uuid: String = "" - var orderId: Long = 0 - var price: Long = 0 - var quantity: Long = 0 - var remainedQuantity: Long = 0 - var direction: OrderDirection = OrderDirection.ASK - var matchConstraint: MatchConstraint = MatchConstraint.GTC +class CancelOrderEvent( + var ouid: String = "", + var uuid: String = "", + var orderId: Long = 0, + pair: Pair, + var price: Long = 0, + var quantity: Long = 0, + var remainedQuantity: Long = 0, + var direction: OrderDirection = OrderDirection.ASK, + var matchConstraint: MatchConstraint = MatchConstraint.GTC, var orderType: OrderType = OrderType.LIMIT_ORDER - - constructor( - ouid: String, - uuid: String, - orderId: Long, - pair: co.nilin.opex.matching.engine.core.model.Pair, - price: Long, - quantity: Long, - remainedQuantity: Long, - direction: OrderDirection, - matchConstraint: MatchConstraint, - orderType: OrderType - ) - : this() { - this.ouid = ouid - this.uuid = uuid - this.orderId = orderId - this.pair = pair - this.price = price - this.quantity = quantity - this.remainedQuantity = remainedQuantity - this.direction = direction - this.matchConstraint = matchConstraint - this.orderType = orderType - } +) : CoreEvent(pair), OneOrderEvent { override fun ouid(): String { return ouid diff --git a/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/CoreEvent.kt b/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/CoreEvent.kt index 24039f538..e895819e8 100644 --- a/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/CoreEvent.kt +++ b/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/CoreEvent.kt @@ -3,7 +3,7 @@ package co.nilin.opex.matching.engine.core.eventh.events import co.nilin.opex.matching.engine.core.model.Pair import java.time.LocalDateTime -open class CoreEvent { - lateinit var pair: Pair +open class CoreEvent( + var pair: Pair, var eventDate: LocalDateTime = LocalDateTime.now() -} \ No newline at end of file +) \ No newline at end of file diff --git a/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/CreateOrderEvent.kt b/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/CreateOrderEvent.kt index d05823d7f..6399feedd 100644 --- a/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/CreateOrderEvent.kt +++ b/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/CreateOrderEvent.kt @@ -3,42 +3,20 @@ package co.nilin.opex.matching.engine.core.eventh.events import co.nilin.opex.matching.engine.core.model.MatchConstraint import co.nilin.opex.matching.engine.core.model.OrderDirection import co.nilin.opex.matching.engine.core.model.OrderType +import co.nilin.opex.matching.engine.core.model.Pair -class CreateOrderEvent() : CoreEvent(), OneOrderEvent { - var ouid: String = "" - var uuid: String = "" - var orderId: Long = 0 - var price: Long = 0 - var quantity: Long = 0 - var remainedQuantity: Long = 0 - var direction: OrderDirection = OrderDirection.ASK - var matchConstraint: MatchConstraint = MatchConstraint.GTC +class CreateOrderEvent( + var ouid: String = "", + var uuid: String = "", + var orderId: Long = 0, + pair: Pair, + var price: Long = 0, + var quantity: Long = 0, + var remainedQuantity: Long = 0, + var direction: OrderDirection = OrderDirection.ASK, + var matchConstraint: MatchConstraint = MatchConstraint.GTC, var orderType: OrderType = OrderType.LIMIT_ORDER - - constructor( - ouid: String, - uuid: String, - orderId: Long, - pair: co.nilin.opex.matching.engine.core.model.Pair, - price: Long, - quantity: Long, - remainedQuantity: Long, - direction: OrderDirection, - matchConstraint: MatchConstraint, - orderType: OrderType - ) - : this() { - this.ouid = ouid - this.uuid = uuid - this.orderId = orderId - this.pair = pair - this.price = price - this.quantity = quantity - this.remainedQuantity = remainedQuantity - this.direction = direction - this.matchConstraint = matchConstraint - this.orderType = orderType - } +) : CoreEvent(pair), OneOrderEvent { override fun ouid(): String { return ouid diff --git a/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/EditOrderRequestEvent.kt b/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/EditOrderRequestEvent.kt index b8a86f403..749bff9e9 100644 --- a/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/EditOrderRequestEvent.kt +++ b/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/EditOrderRequestEvent.kt @@ -1,28 +1,15 @@ package co.nilin.opex.matching.engine.core.eventh.events -class EditOrderRequestEvent() : CoreEvent(), OneOrderEvent { - var ouid: String = "" - var uuid: String = "" - var orderId: Long = 0 - var price: Long = 0 - var quantity: Long = 0 +import co.nilin.opex.matching.engine.core.model.Pair - constructor( - ouid: String, - uuid: String, - orderId: Long, - pair: co.nilin.opex.matching.engine.core.model.Pair, - price: Long, - quantity: Long, - ) - : this() { - this.ouid = ouid - this.uuid = uuid - this.orderId = orderId - this.pair = pair - this.price = price - this.quantity = quantity - } +class EditOrderRequestEvent( + var ouid: String = "", + var uuid: String = "", + var orderId: Long = 0, + pair: Pair, + var price: Long = 0, + var quantity: Long = 0 +) : CoreEvent(pair), OneOrderEvent { override fun ouid(): String { return ouid diff --git a/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/OrderBookPublishedEvent.kt b/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/OrderBookPublishedEvent.kt index 2aa2b016b..44a13db13 100644 --- a/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/OrderBookPublishedEvent.kt +++ b/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/OrderBookPublishedEvent.kt @@ -1,5 +1,6 @@ package co.nilin.opex.matching.engine.core.eventh.events +import co.nilin.opex.matching.engine.core.model.Pair import co.nilin.opex.matching.engine.core.model.PersistentOrderBook -data class OrderBookPublishedEvent(val persistentOrderBook: PersistentOrderBook) : CoreEvent() \ No newline at end of file +data class OrderBookPublishedEvent(val persistentOrderBook: PersistentOrderBook) : CoreEvent(Pair()) \ No newline at end of file diff --git a/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/RejectOrderEvent.kt b/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/RejectOrderEvent.kt index ae8b6a45d..e27ad37cc 100644 --- a/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/RejectOrderEvent.kt +++ b/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/RejectOrderEvent.kt @@ -5,23 +5,26 @@ import co.nilin.opex.matching.engine.core.inout.RequestedOperation import co.nilin.opex.matching.engine.core.model.MatchConstraint import co.nilin.opex.matching.engine.core.model.OrderDirection import co.nilin.opex.matching.engine.core.model.OrderType +import co.nilin.opex.matching.engine.core.model.Pair -class RejectOrderEvent() : CoreEvent(), OneOrderEvent { - var ouid: String = "" - var uuid: String = "" - var orderId: Long? = null - var price: Long? = null - var quantity: Long? = null - var direction: OrderDirection? = null - var matchConstraint: MatchConstraint? = null - var orderType: OrderType? = null - var requestedOperation: RequestedOperation = RequestedOperation.PLACE_ORDER - var reason: RejectReason? = null +class RejectOrderEvent( + var ouid: String = "", + var uuid: String = "", + var orderId: Long? = null, + pair: Pair, + var price: Long? = null, + var quantity: Long? = null, + var direction: OrderDirection? = null, + var matchConstraint: MatchConstraint? = null, + var orderType: OrderType? = null, + var requestedOperation: RequestedOperation = RequestedOperation.PLACE_ORDER, + var reason: RejectReason? = null, +) : CoreEvent(pair), OneOrderEvent { constructor( ouid: String, uuid: String, - pair: co.nilin.opex.matching.engine.core.model.Pair, + pair: Pair, price: Long, quantity: Long, direction: OrderDirection, @@ -29,57 +32,16 @@ class RejectOrderEvent() : CoreEvent(), OneOrderEvent { orderType: OrderType, requestedOperation: RequestedOperation, reason: RejectReason? - ) - : this( - ouid, - uuid, - null, - pair, - price, - quantity, - direction, - matchConstraint, - orderType, - requestedOperation, - reason - ) + ) : this(ouid, uuid, null, pair, price, quantity, direction, matchConstraint, orderType, requestedOperation, reason) constructor( ouid: String, uuid: String, orderId: Long, - pair: co.nilin.opex.matching.engine.core.model.Pair, + pair: Pair, requestedOperation: RequestedOperation, reason: RejectReason? - ) - : this(ouid, uuid, orderId, pair, null, null, null, null, null, requestedOperation, reason) - - constructor( - ouid: String, - uuid: String, - orderId: Long?, - pair: co.nilin.opex.matching.engine.core.model.Pair, - price: Long?, - quantity: Long?, - direction: OrderDirection?, - matchConstraint: MatchConstraint?, - orderType: OrderType?, - requestedOperation: RequestedOperation, - reason: RejectReason? - ) - : this() { - this.ouid = ouid - this.uuid = uuid - this.orderId = orderId - this.pair = pair - this.price = price - this.quantity = quantity - this.direction = direction - this.matchConstraint = matchConstraint - this.orderType = orderType - this.requestedOperation = requestedOperation - this.reason = reason - } + ) : this(ouid, uuid, orderId, pair, null, null, null, null, null, requestedOperation, reason) override fun ouid(): String { return ouid diff --git a/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/SubmitOrderEvent.kt b/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/SubmitOrderEvent.kt index eef8b3417..71b2e1a17 100644 --- a/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/SubmitOrderEvent.kt +++ b/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/SubmitOrderEvent.kt @@ -3,42 +3,20 @@ package co.nilin.opex.matching.engine.core.eventh.events import co.nilin.opex.matching.engine.core.model.MatchConstraint import co.nilin.opex.matching.engine.core.model.OrderDirection import co.nilin.opex.matching.engine.core.model.OrderType +import co.nilin.opex.matching.engine.core.model.Pair -class SubmitOrderEvent() : CoreEvent(), OneOrderEvent { - var ouid: String = "" - var uuid: String = "" - var orderId: Long? = null - var price: Long = 0 - var quantity: Long = 0 - var remainedQuantity: Long = 0 - var direction: OrderDirection = OrderDirection.ASK - var matchConstraint: MatchConstraint = MatchConstraint.GTC +class SubmitOrderEvent( + var ouid: String = "", + var uuid: String = "", + var orderId: Long? = null, + pair: Pair, + var price: Long = 0, + var quantity: Long = 0, + var remainedQuantity: Long = 0, + var direction: OrderDirection = OrderDirection.ASK, + var matchConstraint: MatchConstraint = MatchConstraint.GTC, var orderType: OrderType = OrderType.LIMIT_ORDER - - constructor( - ouid: String, - uuid: String, - orderId: Long?, - pair: co.nilin.opex.matching.engine.core.model.Pair, - price: Long, - quantity: Long, - remainedQuantity: Long, - direction: OrderDirection, - matchConstraint: MatchConstraint, - orderType: OrderType - ) - : this() { - this.ouid = ouid - this.uuid = uuid - this.orderId = orderId - this.pair = pair - this.price = price - this.quantity = quantity - this.remainedQuantity = remainedQuantity - this.direction = direction - this.matchConstraint = matchConstraint - this.orderType = orderType - } +) : CoreEvent(pair), OneOrderEvent { override fun ouid(): String { return ouid diff --git a/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/TradeEvent.kt b/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/TradeEvent.kt index a451b6378..034c9c695 100644 --- a/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/TradeEvent.kt +++ b/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/TradeEvent.kt @@ -1,58 +1,22 @@ package co.nilin.opex.matching.engine.core.eventh.events import co.nilin.opex.matching.engine.core.model.OrderDirection +import co.nilin.opex.matching.engine.core.model.Pair -class TradeEvent() : CoreEvent() { - var tradeId: Long = 0 - var takerOuid: String = "" - var takerUuid: String = "" - var takerOrderId: Long = 0 - var takerDirection: OrderDirection = OrderDirection.ASK - var takerPrice: Long = 0 - var takerRemainedQuantity: Long = 0 - var makerOuid: String = "" - var makerUuid: String = "" - var makerOrderId: Long = 0 - var makerDirection: OrderDirection = OrderDirection.BID - var makerPrice: Long = 0 - var makerRemainedQuantity: Long = 0 +class TradeEvent( + var tradeId: Long = 0, + pair: Pair, + var takerOuid: String = "", + var takerUuid: String = "", + var takerOrderId: Long = 0, + var takerDirection: OrderDirection = OrderDirection.ASK, + var takerPrice: Long = 0, + var takerRemainedQuantity: Long = 0, + var makerOuid: String = "", + var makerUuid: String = "", + var makerOrderId: Long = 0, + var makerDirection: OrderDirection = OrderDirection.BID, + var makerPrice: Long = 0, + var makerRemainedQuantity: Long = 0, var matchedQuantity: Long = 0 - - - constructor( - tradeId: Long, - pair: co.nilin.opex.matching.engine.core.model.Pair, - takerOuid: String, - takerUuid: String, - takerOrderId: Long, - takerDirection: OrderDirection, - takerPrice: Long, - takerRemainedQuantity: Long, - makerOuid: String, - makerUuid: String, - makerOrderId: Long, - makerDirection: OrderDirection, - makerPrice: Long, - makerRemainedQuantity: Long, - matchedQuantity: Long - ) - : this() { - this.tradeId = tradeId - this.takerOuid = takerOuid - this.takerUuid = takerUuid - this.pair = pair - this.takerOrderId = takerOrderId - this.takerPrice = takerPrice - this.takerDirection = takerDirection - this.takerRemainedQuantity = takerRemainedQuantity - - this.makerOuid = makerOuid - this.makerUuid = makerUuid - this.makerOrderId = makerOrderId - this.makerPrice = makerPrice - this.makerDirection = makerDirection - this.makerRemainedQuantity = makerRemainedQuantity - - this.matchedQuantity = matchedQuantity - } -} \ No newline at end of file +) : CoreEvent(pair) \ No newline at end of file diff --git a/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/UpdatedOrderEvent.kt b/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/UpdatedOrderEvent.kt index 0d6528a5f..dd5b91f42 100644 --- a/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/UpdatedOrderEvent.kt +++ b/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/eventh/events/UpdatedOrderEvent.kt @@ -3,48 +3,22 @@ package co.nilin.opex.matching.engine.core.eventh.events import co.nilin.opex.matching.engine.core.model.MatchConstraint import co.nilin.opex.matching.engine.core.model.OrderDirection import co.nilin.opex.matching.engine.core.model.OrderType +import co.nilin.opex.matching.engine.core.model.Pair -class UpdatedOrderEvent() : CoreEvent(), OneOrderEvent { - var ouid: String = "" - var uuid: String = "" - var orderId: Long = 0 - var oldPrice: Long = 0 - var oldQuantity: Long = 0 - var price: Long = 0 - var quantity: Long = 0 - var remainedQuantity: Long = 0 - var direction: OrderDirection = OrderDirection.ASK - var matchConstraint: MatchConstraint = MatchConstraint.GTC +class UpdatedOrderEvent( + var ouid: String = "", + var uuid: String = "", + var orderId: Long = 0, + pair: Pair, + var oldPrice: Long = 0, + var oldQuantity: Long = 0, + var price: Long = 0, + var quantity: Long = 0, + var remainedQuantity: Long = 0, + var direction: OrderDirection = OrderDirection.ASK, + var matchConstraint: MatchConstraint = MatchConstraint.GTC, var orderType: OrderType = OrderType.LIMIT_ORDER - - constructor( - ouid: String, - uuid: String, - orderId: Long, - pair: co.nilin.opex.matching.engine.core.model.Pair, - oldPrice: Long, - oldQuantity: Long, - price: Long, - quantity: Long, - remainedQuantity: Long, - direction: OrderDirection, - matchConstraint: MatchConstraint, - orderType: OrderType - ) - : this() { - this.ouid = ouid - this.uuid = uuid - this.orderId = orderId - this.pair = pair - this.oldPrice = oldPrice - this.oldQuantity = oldQuantity - this.price = price - this.quantity = quantity - this.remainedQuantity = remainedQuantity - this.direction = direction - this.matchConstraint = matchConstraint - this.orderType = orderType - } +) : CoreEvent(pair), OneOrderEvent { override fun ouid(): String { return ouid diff --git a/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/model/Bucket.kt b/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/model/Bucket.kt new file mode 100644 index 000000000..90e6144b2 --- /dev/null +++ b/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/model/Bucket.kt @@ -0,0 +1,3 @@ +package co.nilin.opex.matching.engine.core.model + +data class Bucket(val price: Long, var totalQuantity: Long, var ordersCount: Long, var lastOrder: SimpleOrder) \ No newline at end of file diff --git a/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/model/PersistentOrderBook.kt b/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/model/PersistentOrderBook.kt index 4807125d6..49a7758be 100644 --- a/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/model/PersistentOrderBook.kt +++ b/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/model/PersistentOrderBook.kt @@ -5,6 +5,7 @@ class PersistentOrderBook { lateinit var pair: Pair var lastOrder: PersistentOrder? = null var orders: List? = emptyList() + var tradeCounter: Long = 0 constructor() { } diff --git a/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/model/SimpleOrder.kt b/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/model/SimpleOrder.kt new file mode 100644 index 000000000..24f52b819 --- /dev/null +++ b/matching-engine/matching-engine-core/src/main/kotlin/co/nilin/opex/matching/engine/core/model/SimpleOrder.kt @@ -0,0 +1,39 @@ +package co.nilin.opex.matching.engine.core.model + +data class SimpleOrder( + var id: Long?, + val ouid: String, + val uuid: String, + val price: Long, + val quantity: Long, + val matchConstraint: MatchConstraint, + val orderType: OrderType, + val direction: OrderDirection, + var filledQuantity: Long, + var worse: SimpleOrder?, + var better: SimpleOrder?, + var bucket: Bucket? +) : Order { + + fun remainedQuantity() = quantity - filledQuantity + + override fun id(): Long? = id + + override fun toString(): String { + return "SimpleOrder(id=$id, price=$price, quantity=$quantity, matchConstraint=$matchConstraint, orderType=$orderType, filledQuantity=$filledQuantity, worse=${worse?.id}, better=${better?.id}, bucket=${bucket?.totalQuantity})" + } + + override fun persistent(): PersistentOrder { + return PersistentOrder( + id!!, + ouid, + uuid, + price, + quantity, + matchConstraint, + orderType, + direction, + filledQuantity + ) + } +} \ No newline at end of file diff --git a/matching-engine/matching-engine-core/src/test/kotlin/co/nilin/opex/matching/core/engine/SimpleOrderBookUnitTest.kt b/matching-engine/matching-engine-core/src/test/kotlin/co/nilin/opex/matching/engine/core/SimpleOrderBookUnitTest.kt similarity index 87% rename from matching-engine/matching-engine-core/src/test/kotlin/co/nilin/opex/matching/core/engine/SimpleOrderBookUnitTest.kt rename to matching-engine/matching-engine-core/src/test/kotlin/co/nilin/opex/matching/engine/core/SimpleOrderBookUnitTest.kt index 8cdbcf9a4..8b67edf10 100644 --- a/matching-engine/matching-engine-core/src/test/kotlin/co/nilin/opex/matching/core/engine/SimpleOrderBookUnitTest.kt +++ b/matching-engine/matching-engine-core/src/test/kotlin/co/nilin/opex/matching/engine/core/SimpleOrderBookUnitTest.kt @@ -1,25 +1,27 @@ -package co.nilin.opex.matching.engine.core.engine +package co.nilin.opex.matching.engine.core +import co.nilin.opex.matching.engine.core.engine.SimpleOrderBook import co.nilin.opex.matching.engine.core.inout.OrderCancelCommand import co.nilin.opex.matching.engine.core.inout.OrderCreateCommand import co.nilin.opex.matching.engine.core.inout.OrderEditCommand import co.nilin.opex.matching.engine.core.model.MatchConstraint import co.nilin.opex.matching.engine.core.model.OrderDirection import co.nilin.opex.matching.engine.core.model.OrderType +import co.nilin.opex.matching.engine.core.model.SimpleOrder import kotlinx.coroutines.Dispatchers import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test import java.util.* class SimpleOrderBookUnitTest { - val pair = co.nilin.opex.matching.engine.core.model.Pair("BTC", "USDT") - val ETH_BTC_PAIR = co.nilin.opex.matching.engine.core.model.Pair("ETH", "BTC") - val uuid = UUID.randomUUID().toString() + private val pair = co.nilin.opex.matching.engine.core.model.Pair("BTC", "USDT") + private val ETH_BTC_PAIR = co.nilin.opex.matching.engine.core.model.Pair("ETH", "BTC") + private val uuid = UUID.randomUUID().toString() @Test fun givenEmptyOrderBook_whenGtcBidLimitOrderCreated_then1BucketWithSize1() { //given - val orderBook = co.nilin.opex.matching.engine.core.engine.SimpleOrderBook(pair, false) + val orderBook = SimpleOrderBook(pair, false) //when val order = orderBook.handleNewOrderCommand( OrderCreateCommand( @@ -42,7 +44,7 @@ class SimpleOrderBookUnitTest { @Test fun givenOrderBookWithBidOrders_whenGtcBidLimitOrderWithSamePriceCreated_then() { //given - val orderBook = co.nilin.opex.matching.engine.core.engine.SimpleOrderBook(pair, false) + val orderBook = SimpleOrderBook(pair, false) orderBook.handleNewOrderCommand( OrderCreateCommand( UUID.randomUUID().toString(), @@ -57,7 +59,7 @@ class SimpleOrderBookUnitTest { ) val bestBidOrder = orderBook.bestBidOrder //when - val order: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder = + val order: SimpleOrder = orderBook.handleNewOrderCommand( OrderCreateCommand( UUID.randomUUID().toString(), @@ -69,7 +71,7 @@ class SimpleOrderBookUnitTest { MatchConstraint.GTC, OrderType.LIMIT_ORDER ) - ) as co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder + ) as SimpleOrder //then Assertions.assertEquals(orderBook.bidOrders.entriesList().size, 1) Assertions.assertEquals(orderBook.bestBidOrder, bestBidOrder) @@ -83,7 +85,7 @@ class SimpleOrderBookUnitTest { @Test fun givenOrderBookWithBidOrders_whenGtcBidLimitOrderWithLowerPriceCreated_thenBestOrderNotChange() { //given - val orderBook = co.nilin.opex.matching.engine.core.engine.SimpleOrderBook(pair, false) + val orderBook = SimpleOrderBook(pair, false) orderBook.handleNewOrderCommand( OrderCreateCommand( UUID.randomUUID().toString(), @@ -98,7 +100,7 @@ class SimpleOrderBookUnitTest { ) val bestBidOrder = orderBook.bestBidOrder //when - val order: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder = + val order: SimpleOrder = orderBook.handleNewOrderCommand( OrderCreateCommand( UUID.randomUUID().toString(), @@ -110,7 +112,7 @@ class SimpleOrderBookUnitTest { MatchConstraint.GTC, OrderType.LIMIT_ORDER ) - ) as co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder + ) as SimpleOrder //then Assertions.assertEquals(orderBook.bidOrders.entriesList().size, 2) Assertions.assertEquals(orderBook.bestBidOrder, bestBidOrder) @@ -124,7 +126,7 @@ class SimpleOrderBookUnitTest { @Test fun givenOrderBookWithBidOrders_whenGtcBidLimitOrderWithHigherPriceCreated_thenBestOrderChanged() { //given - val orderBook = co.nilin.opex.matching.engine.core.engine.SimpleOrderBook(pair, false) + val orderBook = SimpleOrderBook(pair, false) orderBook.handleNewOrderCommand( OrderCreateCommand( UUID.randomUUID().toString(), @@ -139,7 +141,7 @@ class SimpleOrderBookUnitTest { ) val bestBidOrder = orderBook.bestBidOrder //when - val order: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder = + val order: SimpleOrder = orderBook.handleNewOrderCommand( OrderCreateCommand( UUID.randomUUID().toString(), @@ -151,7 +153,7 @@ class SimpleOrderBookUnitTest { MatchConstraint.GTC, OrderType.LIMIT_ORDER ) - ) as co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder + ) as SimpleOrder //then Assertions.assertEquals(orderBook.bidOrders.entriesList().size, 2) Assertions.assertEquals(orderBook.bestBidOrder, order) @@ -165,7 +167,7 @@ class SimpleOrderBookUnitTest { @Test fun givenOrderBookWithBidOrders_whenGtcAskLimitOrderWithSamePriceCreated_thenInstantMatch() { //given - val orderBook = co.nilin.opex.matching.engine.core.engine.SimpleOrderBook(pair, false) + val orderBook = SimpleOrderBook(pair, false) orderBook.handleNewOrderCommand( OrderCreateCommand( UUID.randomUUID().toString(), @@ -190,7 +192,7 @@ class SimpleOrderBookUnitTest { MatchConstraint.GTC, OrderType.LIMIT_ORDER ) - ) as co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder + ) as SimpleOrder //then Assertions.assertEquals(orderBook.bidOrders.entriesList().size, 0) Assertions.assertEquals(orderBook.askOrders.entriesList().size, 0) @@ -201,7 +203,7 @@ class SimpleOrderBookUnitTest { @Test fun givenOrderBookWithBidOrders_whenGtcAskLimitOrderWithNotMatchPriceCreated_thenAddToQueue() { //given - val orderBook = co.nilin.opex.matching.engine.core.engine.SimpleOrderBook(pair, false) + val orderBook = SimpleOrderBook(pair, false) orderBook.handleNewOrderCommand( OrderCreateCommand( UUID.randomUUID().toString(), @@ -227,7 +229,7 @@ class SimpleOrderBookUnitTest { ) ) //when - val order: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder = + val order: SimpleOrder = orderBook.handleNewOrderCommand( OrderCreateCommand( UUID.randomUUID().toString(), @@ -239,7 +241,7 @@ class SimpleOrderBookUnitTest { MatchConstraint.GTC, OrderType.LIMIT_ORDER ) - ) as co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder + ) as SimpleOrder //then Assertions.assertEquals(orderBook.bidOrders.entriesList().size, 2) Assertions.assertEquals(orderBook.askOrders.entriesList().size, 1) @@ -250,7 +252,7 @@ class SimpleOrderBookUnitTest { @Test fun givenOrderBookWithBidAndAskOrders_whenGtcAskLimitOrderWithMatchPriceGreaterQuantityCreated_thenAddToQueue() { //given - val orderBook = co.nilin.opex.matching.engine.core.engine.SimpleOrderBook(pair, false) + val orderBook = SimpleOrderBook(pair, false) orderBook.handleNewOrderCommand( OrderCreateCommand( UUID.randomUUID().toString(), @@ -288,7 +290,7 @@ class SimpleOrderBookUnitTest { ) ) //when - val order: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder = + val order: SimpleOrder = orderBook.handleNewOrderCommand( OrderCreateCommand( UUID.randomUUID().toString(), @@ -300,7 +302,7 @@ class SimpleOrderBookUnitTest { MatchConstraint.GTC, OrderType.LIMIT_ORDER ) - ) as co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder + ) as SimpleOrder //then Assertions.assertEquals(orderBook.bidOrders.entriesList().size, 0) Assertions.assertEquals(orderBook.askOrders.entriesList().size, 2) @@ -311,7 +313,7 @@ class SimpleOrderBookUnitTest { @Test fun givenOrderBook_whenCancelBestBidOrder_thenBestBidOrderChange() { //given - val orderBook = co.nilin.opex.matching.engine.core.engine.SimpleOrderBook(pair, false) + val orderBook = SimpleOrderBook(pair, false) val firstOrderId = UUID.randomUUID().toString() val secondOrderId = UUID.randomUUID().toString() @@ -349,7 +351,7 @@ class SimpleOrderBookUnitTest { @Test fun givenOrderBookWithMoreBids_whenCancelBestBidOrder_thenBestBidOrderChange() { //given - val orderBook = co.nilin.opex.matching.engine.core.engine.SimpleOrderBook(pair, false) + val orderBook = SimpleOrderBook(pair, false) val firstOrderId = UUID.randomUUID().toString() val secondOrderId = UUID.randomUUID().toString() @@ -399,7 +401,7 @@ class SimpleOrderBookUnitTest { @Test fun givenOrderBookWithMoreBids_whenCancelABidOrder_thenBestBidOrderNotChange() { //given - val orderBook = co.nilin.opex.matching.engine.core.engine.SimpleOrderBook(pair, false) + val orderBook = SimpleOrderBook(pair, false) val firstOrderId = UUID.randomUUID().toString() val secondOrderId = UUID.randomUUID().toString() @@ -450,7 +452,7 @@ class SimpleOrderBookUnitTest { @Test fun givenOrderBookWithMoreBids_whenEditABidOrder_thenBestBidOrderChange() { //given - val orderBook = co.nilin.opex.matching.engine.core.engine.SimpleOrderBook(pair, false) + val orderBook = SimpleOrderBook(pair, false) orderBook.handleNewOrderCommand( OrderCreateCommand( UUID.randomUUID().toString(), @@ -507,7 +509,7 @@ class SimpleOrderBookUnitTest { @Test fun givenOrderBookWithBidAndAskOrders_whenEditABidOrder_thenRefill() { //given - val orderBook = co.nilin.opex.matching.engine.core.engine.SimpleOrderBook(pair, false) + val orderBook = SimpleOrderBook(pair, false) orderBook.handleNewOrderCommand( OrderCreateCommand( UUID.randomUUID().toString(), @@ -545,7 +547,7 @@ class SimpleOrderBookUnitTest { ) ) //when - val order: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder = orderBook.handleEditCommand( + val order: SimpleOrder = orderBook.handleEditCommand( OrderEditCommand( UUID.randomUUID().toString(), uuid, @@ -554,7 +556,7 @@ class SimpleOrderBookUnitTest { 3, 3 ) - ) as co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder + ) as SimpleOrder //then Assertions.assertEquals(2, orderBook.bidOrders.entriesList().size) Assertions.assertEquals(0, orderBook.askOrders.entriesList().size) @@ -565,7 +567,7 @@ class SimpleOrderBookUnitTest { @Test fun givenEmptyOrderBook_whenGtcBidMarketOrderCreated_thenRejected() { //given - val orderBook = co.nilin.opex.matching.engine.core.engine.SimpleOrderBook(pair, false) + val orderBook = SimpleOrderBook(pair, false) //when val order = orderBook.handleNewOrderCommand( @@ -589,7 +591,7 @@ class SimpleOrderBookUnitTest { @Test fun givenEmptyOrderBook_whenIocBidMarketOrderCreated_thenNoOrderCreated() { //given - val orderBook = co.nilin.opex.matching.engine.core.engine.SimpleOrderBook(pair, false) + val orderBook = SimpleOrderBook(pair, false) //when val order = orderBook.handleNewOrderCommand( @@ -613,7 +615,7 @@ class SimpleOrderBookUnitTest { @Test fun givenOrderBookWithBidAndAskOrders_whenIocAskMarketOrderWithGreaterQuantityCreated_thenPartiallyFilled() { //given - val orderBook = co.nilin.opex.matching.engine.core.engine.SimpleOrderBook(pair, false) + val orderBook = SimpleOrderBook(pair, false) orderBook.handleNewOrderCommand( OrderCreateCommand( UUID.randomUUID().toString(), @@ -652,7 +654,7 @@ class SimpleOrderBookUnitTest { ) val bestAskOrder = orderBook.bestAskOrder //when - val order: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder = + val order: SimpleOrder = orderBook.handleNewOrderCommand( OrderCreateCommand( UUID.randomUUID().toString(), @@ -664,7 +666,7 @@ class SimpleOrderBookUnitTest { MatchConstraint.IOC, OrderType.MARKET_ORDER ) - ) as co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder + ) as SimpleOrder //then Assertions.assertEquals(2, order.filledQuantity) Assertions.assertEquals(orderBook.bidOrders.entriesList().size, 0) @@ -676,7 +678,7 @@ class SimpleOrderBookUnitTest { @Test fun givenOrderBookWithBidAndAskOrders_whenIocAskLimitOrderWithHigherPriceAndGreaterQuantityCreated_thenNotFilled() { //given - val orderBook = co.nilin.opex.matching.engine.core.engine.SimpleOrderBook(pair, false) + val orderBook = SimpleOrderBook(pair, false) orderBook.handleNewOrderCommand( OrderCreateCommand( UUID.randomUUID().toString(), @@ -716,7 +718,7 @@ class SimpleOrderBookUnitTest { val bestAskOrder = orderBook.bestAskOrder val bestBidOrder = orderBook.bestBidOrder //when - val order: co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder = + val order: SimpleOrder = orderBook.handleNewOrderCommand( OrderCreateCommand( UUID.randomUUID().toString(), @@ -728,7 +730,7 @@ class SimpleOrderBookUnitTest { MatchConstraint.IOC, OrderType.LIMIT_ORDER ) - ) as co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder + ) as SimpleOrder //then Assertions.assertEquals(0, order.filledQuantity) Assertions.assertEquals(orderBook.bidOrders.entriesList().size, 2) @@ -740,7 +742,7 @@ class SimpleOrderBookUnitTest { @Test fun whenSample1SequenceOfOrdersOccurs_thenAllSuccess() { - val orderBook = co.nilin.opex.matching.engine.core.engine.SimpleOrderBook(ETH_BTC_PAIR, false) + val orderBook = SimpleOrderBook(ETH_BTC_PAIR, false) orderBook.handleNewOrderCommand( OrderCreateCommand( UUID.randomUUID().toString(), @@ -752,7 +754,7 @@ class SimpleOrderBookUnitTest { MatchConstraint.GTC, OrderType.LIMIT_ORDER ) - ) as co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder + ) as SimpleOrder Assertions.assertNotNull(orderBook.bestBidOrder) Assertions.assertEquals(1, orderBook.bidOrders.entriesList().size) Assertions.assertEquals(1, orderBook.orders.size) @@ -768,7 +770,7 @@ class SimpleOrderBookUnitTest { MatchConstraint.GTC, OrderType.LIMIT_ORDER ) - ) as co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder + ) as SimpleOrder Assertions.assertNull(orderBook.bestBidOrder) Assertions.assertNotNull(orderBook.bestAskOrder) Assertions.assertEquals(0, orderBook.bidOrders.entriesList().size) @@ -786,7 +788,7 @@ class SimpleOrderBookUnitTest { MatchConstraint.GTC, OrderType.LIMIT_ORDER ) - ) as co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder + ) as SimpleOrder Assertions.assertNull(orderBook.bestBidOrder) Assertions.assertNotNull(orderBook.bestAskOrder) Assertions.assertEquals(0, orderBook.bidOrders.entriesList().size) @@ -804,7 +806,7 @@ class SimpleOrderBookUnitTest { MatchConstraint.GTC, OrderType.LIMIT_ORDER ) - ) as co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder + ) as SimpleOrder Assertions.assertEquals(1, orderBook.bidOrders.entriesList().size) Assertions.assertEquals(1, orderBook.askOrders.entriesList().size) Assertions.assertEquals(2, orderBook.orders.size) @@ -822,7 +824,7 @@ class SimpleOrderBookUnitTest { MatchConstraint.GTC, OrderType.LIMIT_ORDER ) - ) as co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder + ) as SimpleOrder Assertions.assertEquals(1, orderBook.bidOrders.entriesList().size) Assertions.assertEquals(2, orderBook.askOrders.entriesList().size) Assertions.assertEquals(3, orderBook.orders.size) @@ -840,12 +842,11 @@ class SimpleOrderBookUnitTest { MatchConstraint.GTC, OrderType.LIMIT_ORDER ) - ) as co.nilin.opex.matching.engine.core.engine.SimpleOrderBook.SimpleOrder + ) as SimpleOrder Assertions.assertEquals(2, orderBook.bidOrders.entriesList().size) Assertions.assertEquals(2, orderBook.askOrders.entriesList().size) Assertions.assertEquals(4, orderBook.orders.size) Assertions.assertNotNull(orderBook.bestBidOrder) Assertions.assertNotNull(orderBook.bestAskOrder) } - } \ No newline at end of file diff --git a/matching-engine/matching-engine-ports/matching-engine-eventlistener-kafka/mvnw b/matching-engine/matching-engine-ports/matching-engine-eventlistener-kafka/mvnw deleted file mode 100644 index a16b5431b..000000000 --- a/matching-engine/matching-engine-ports/matching-engine-eventlistener-kafka/mvnw +++ /dev/null @@ -1,310 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` - fi - - if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=`cygpath --path --windows "$javaClass"` - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/matching-engine/matching-engine-ports/matching-engine-eventlistener-kafka/mvnw.cmd b/matching-engine/matching-engine-ports/matching-engine-eventlistener-kafka/mvnw.cmd deleted file mode 100644 index c8d43372c..000000000 --- a/matching-engine/matching-engine-ports/matching-engine-eventlistener-kafka/mvnw.cmd +++ /dev/null @@ -1,182 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/matching-engine/matching-engine-ports/matching-engine-eventlistener-kafka/src/main/kotlin/co/nilin/opex/matching/engine/ports/kafka/listener/config/OrderKafkaConfig.kt b/matching-engine/matching-engine-ports/matching-engine-eventlistener-kafka/src/main/kotlin/co/nilin/opex/matching/engine/ports/kafka/listener/config/OrderKafkaConfig.kt index 02ff6d11f..a09a0b2a4 100644 --- a/matching-engine/matching-engine-ports/matching-engine-eventlistener-kafka/src/main/kotlin/co/nilin/opex/matching/engine/ports/kafka/listener/config/OrderKafkaConfig.kt +++ b/matching-engine/matching-engine-ports/matching-engine-eventlistener-kafka/src/main/kotlin/co/nilin/opex/matching/engine/ports/kafka/listener/config/OrderKafkaConfig.kt @@ -7,6 +7,7 @@ import co.nilin.opex.matching.engine.ports.kafka.listener.inout.OrderSubmitReque import org.apache.kafka.clients.admin.NewTopic import org.apache.kafka.clients.consumer.ConsumerConfig import org.apache.kafka.clients.producer.ProducerConfig +import org.apache.kafka.common.config.TopicConfig import org.apache.kafka.common.serialization.StringDeserializer import org.apache.kafka.common.serialization.StringSerializer import org.springframework.beans.factory.annotation.Autowired @@ -15,12 +16,14 @@ import org.springframework.beans.factory.annotation.Value import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration import org.springframework.context.support.GenericApplicationContext +import org.springframework.kafka.config.TopicBuilder import org.springframework.kafka.core.* import org.springframework.kafka.listener.ConcurrentMessageListenerContainer import org.springframework.kafka.listener.ContainerProperties import org.springframework.kafka.listener.KafkaMessageListenerContainer import org.springframework.kafka.support.serializer.JsonDeserializer import org.springframework.kafka.support.serializer.JsonSerializer +import java.util.function.Supplier import java.util.regex.Pattern @Configuration @@ -40,9 +43,16 @@ class OrderKafkaConfig { @Autowired fun createTopics() { - symbols!!.split(",").map { s -> "orders_$s" } - .map { topic -> - applicationContext?.registerBean("topic_${topic}", NewTopic::class.java, topic, 1, 1) + symbols!!.split(",") + .map { s -> "orders_$s" } + .forEach { topic -> + applicationContext?.registerBean("topic_${topic}", NewTopic::class.java, Supplier { + TopicBuilder.name(topic) + .partitions(10) + .replicas(3) + .config(TopicConfig.MIN_IN_SYNC_REPLICAS_CONFIG, "2") + .build() + }) } } @@ -73,7 +83,8 @@ class OrderKafkaConfig { props[ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG] = StringDeserializer::class.java props[ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG] = JsonDeserializer::class.java props[JsonDeserializer.TRUSTED_PACKAGES] = "co.nilin.opex.*" - props[JsonDeserializer.TYPE_MAPPINGS] = "order_request:co.nilin.opex.matching.engine.ports.kafka.listener.inout.OrderSubmitRequest" + props[JsonDeserializer.TYPE_MAPPINGS] = + "order_request:co.nilin.opex.matching.engine.ports.kafka.listener.inout.OrderSubmitRequest" return props } @@ -97,7 +108,7 @@ class OrderKafkaConfig { val containerProps = ContainerProperties(*topics) containerProps.messageListener = orderKafkaListener val container = KafkaMessageListenerContainer(consumerFactory, containerProps) - container.beanName = "OrderKafkaListenerContainer" + container.setBeanName("OrderKafkaListenerContainer") container.start() } @@ -109,7 +120,7 @@ class OrderKafkaConfig { val containerProps = ContainerProperties(Pattern.compile("events_.*")) containerProps.messageListener = eventListener val container = ConcurrentMessageListenerContainer(consumerFactory, containerProps) - container.beanName = "EventKafkaListenerContainer" + container.setBeanName("EventKafkaListenerContainer") container.start() } diff --git a/matching-engine/matching-engine-ports/matching-engine-snapshots-redis/mvnw b/matching-engine/matching-engine-ports/matching-engine-snapshots-redis/mvnw deleted file mode 100644 index a16b5431b..000000000 --- a/matching-engine/matching-engine-ports/matching-engine-snapshots-redis/mvnw +++ /dev/null @@ -1,310 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` - fi - - if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=`cygpath --path --windows "$javaClass"` - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/matching-engine/matching-engine-ports/matching-engine-snapshots-redis/mvnw.cmd b/matching-engine/matching-engine-ports/matching-engine-snapshots-redis/mvnw.cmd deleted file mode 100644 index c8d43372c..000000000 --- a/matching-engine/matching-engine-ports/matching-engine-snapshots-redis/mvnw.cmd +++ /dev/null @@ -1,182 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/matching-engine/matching-engine-ports/matching-engine-submitter-kafka/mvnw b/matching-engine/matching-engine-ports/matching-engine-submitter-kafka/mvnw deleted file mode 100644 index a16b5431b..000000000 --- a/matching-engine/matching-engine-ports/matching-engine-submitter-kafka/mvnw +++ /dev/null @@ -1,310 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` - fi - - if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=`cygpath --path --windows "$javaClass"` - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/matching-engine/matching-engine-ports/matching-engine-submitter-kafka/mvnw.cmd b/matching-engine/matching-engine-ports/matching-engine-submitter-kafka/mvnw.cmd deleted file mode 100644 index c8d43372c..000000000 --- a/matching-engine/matching-engine-ports/matching-engine-submitter-kafka/mvnw.cmd +++ /dev/null @@ -1,182 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/matching-engine/matching-engine-ports/matching-engine-submitter-kafka/src/main/kotlin/co/nilin/opex/matching/engine/ports/kafka/submitter/config/EventsKafkaConfig.kt b/matching-engine/matching-engine-ports/matching-engine-submitter-kafka/src/main/kotlin/co/nilin/opex/matching/engine/ports/kafka/submitter/config/EventsKafkaConfig.kt index 844629ffa..40b2f51bd 100644 --- a/matching-engine/matching-engine-ports/matching-engine-submitter-kafka/src/main/kotlin/co/nilin/opex/matching/engine/ports/kafka/submitter/config/EventsKafkaConfig.kt +++ b/matching-engine/matching-engine-ports/matching-engine-submitter-kafka/src/main/kotlin/co/nilin/opex/matching/engine/ports/kafka/submitter/config/EventsKafkaConfig.kt @@ -1,10 +1,10 @@ package co.nilin.opex.matching.engine.ports.kafka.submitter.config - import co.nilin.opex.matching.engine.core.eventh.events.CoreEvent import org.apache.kafka.clients.admin.AdminClientConfig import org.apache.kafka.clients.admin.NewTopic import org.apache.kafka.clients.producer.ProducerConfig +import org.apache.kafka.common.config.TopicConfig import org.apache.kafka.common.serialization.StringSerializer import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Qualifier @@ -12,15 +12,17 @@ import org.springframework.beans.factory.annotation.Value import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration import org.springframework.context.support.GenericApplicationContext +import org.springframework.kafka.config.TopicBuilder import org.springframework.kafka.core.DefaultKafkaProducerFactory import org.springframework.kafka.core.KafkaAdmin import org.springframework.kafka.core.KafkaTemplate import org.springframework.kafka.core.ProducerFactory import org.springframework.kafka.support.serializer.JsonSerializer - +import java.util.function.Supplier @Configuration -class EventsKafkaConfig() { +class EventsKafkaConfig { + @Value("\${spring.kafka.bootstrap-servers}") private lateinit var bootstrapServers: String @@ -31,12 +33,13 @@ class EventsKafkaConfig() { private val applicationContext: GenericApplicationContext? = null @Bean("eventsProducerConfigs") - fun producerConfigs(): Map? { - val props: MutableMap = HashMap() - props[ProducerConfig.BOOTSTRAP_SERVERS_CONFIG] = bootstrapServers - props[ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG] = StringSerializer::class.java - props[ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG] = JsonSerializer::class.java - return props + fun producerConfigs(): Map { + return mapOf( + ProducerConfig.BOOTSTRAP_SERVERS_CONFIG to bootstrapServers, + ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG to StringSerializer::class.java, + ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG to JsonSerializer::class.java, + ProducerConfig.ACKS_CONFIG to "all" + ) } @Bean("eventsProducerFactory") @@ -49,7 +52,6 @@ class EventsKafkaConfig() { return KafkaTemplate(producerFactory) } - @Bean fun admin(): KafkaAdmin? { val configs: MutableMap = HashMap() @@ -61,14 +63,25 @@ class EventsKafkaConfig() { fun createTopics() { symbols!!.split(",") .map { s -> "events_$s" } - .map { topic -> - applicationContext?.registerBean("topic_${topic}", NewTopic::class.java, topic, 10, 1) + .forEach { topic -> + applicationContext?.registerBean("topic_${topic}", NewTopic::class.java, Supplier { + TopicBuilder.name(topic) + .partitions(10) + .replicas(3) + .config(TopicConfig.MIN_IN_SYNC_REPLICAS_CONFIG, "2") + .build() + }) } symbols.split(",") .map { s -> "trades_$s" } - .map { topic -> - applicationContext?.registerBean("topic_${topic}", NewTopic::class.java, topic, 10, 1) + .forEach { topic -> + applicationContext?.registerBean("topic_${topic}", NewTopic::class.java, Supplier { + TopicBuilder.name(topic) + .partitions(10) + .replicas(3) + .config(TopicConfig.MIN_IN_SYNC_REPLICAS_CONFIG, "2") + .build() + }) } } - } \ No newline at end of file diff --git a/matching-gateway/matching-gateway-app/Dockerfile b/matching-gateway/matching-gateway-app/Dockerfile index f2cbd4c26..7c71f9447 100644 --- a/matching-gateway/matching-gateway-app/Dockerfile +++ b/matching-gateway/matching-gateway-app/Dockerfile @@ -1,5 +1,4 @@ -FROM openjdk:8-jdk-alpine -VOLUME /tmp +FROM openjdk:11 ARG JAR_FILE=target/*.jar COPY ${JAR_FILE} app.jar ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -jar /app.jar"] \ No newline at end of file diff --git a/matching-gateway/matching-gateway-app/pom.xml b/matching-gateway/matching-gateway-app/pom.xml index 95b96c395..583fe0d38 100644 --- a/matching-gateway/matching-gateway-app/pom.xml +++ b/matching-gateway/matching-gateway-app/pom.xml @@ -14,10 +14,6 @@ matching-gateway-app Matching gateway running app Opex - - 2020.0.2 - - org.jetbrains.kotlin diff --git a/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/config/AppConfig.kt b/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/config/AppConfig.kt index 89bc71514..1492fea70 100644 --- a/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/config/AppConfig.kt +++ b/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/config/AppConfig.kt @@ -1,10 +1,10 @@ package co.nilin.opex.matching.gateway.app.config +import co.nilin.opex.matching.engine.core.model.OrderDirection import co.nilin.opex.matching.gateway.app.inout.PairConfig import co.nilin.opex.matching.gateway.app.inout.PairFeeConfig import co.nilin.opex.matching.gateway.app.spi.AccountantApiProxy import co.nilin.opex.matching.gateway.app.spi.PairConfigLoader -import co.nilin.opex.matching.engine.core.model.OrderDirection import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration diff --git a/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/proxy/AccountantProxyImpl.kt b/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/proxy/AccountantProxyImpl.kt index 6a7305f78..1e129e44f 100644 --- a/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/proxy/AccountantProxyImpl.kt +++ b/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/proxy/AccountantProxyImpl.kt @@ -1,8 +1,8 @@ package co.nilin.opex.matching.gateway.app.proxy +import co.nilin.opex.matching.engine.core.model.OrderDirection import co.nilin.opex.matching.gateway.app.inout.PairFeeConfig import co.nilin.opex.matching.gateway.app.spi.AccountantApiProxy -import co.nilin.opex.matching.engine.core.model.OrderDirection import kotlinx.coroutines.reactive.awaitFirst import org.springframework.beans.factory.annotation.Value import org.springframework.core.ParameterizedTypeReference diff --git a/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/service/OrderService.kt b/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/service/OrderService.kt index 8d3f02c1e..f78ec858d 100644 --- a/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/service/OrderService.kt +++ b/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/service/OrderService.kt @@ -1,12 +1,12 @@ package co.nilin.opex.matching.gateway.app.service +import co.nilin.opex.matching.engine.core.eventh.events.CancelOrderEvent +import co.nilin.opex.matching.engine.core.model.OrderDirection +import co.nilin.opex.matching.engine.core.model.Pair import co.nilin.opex.matching.gateway.app.inout.CancelOrderRequest import co.nilin.opex.matching.gateway.app.inout.CreateOrderRequest import co.nilin.opex.matching.gateway.app.spi.AccountantApiProxy import co.nilin.opex.matching.gateway.app.spi.PairConfigLoader -import co.nilin.opex.matching.engine.core.eventh.events.CancelOrderEvent -import co.nilin.opex.matching.engine.core.model.OrderDirection -import co.nilin.opex.matching.engine.core.model.Pair import co.nilin.opex.matching.gateway.ports.kafka.submitter.inout.OrderSubmitRequest import co.nilin.opex.matching.gateway.ports.kafka.submitter.inout.OrderSubmitResult import co.nilin.opex.matching.gateway.ports.kafka.submitter.service.EventSubmitter @@ -67,12 +67,7 @@ class OrderService( suspend fun cancelOrder(request: CancelOrderRequest): OrderSubmitResult { val symbols = request.symbol.split("_") - val event = CancelOrderEvent().apply { - ouid = request.ouid - uuid = request.uuid - orderId = request.orderId - pair = Pair(symbols[0], symbols[1]) - } + val event = CancelOrderEvent(request.ouid, request.uuid, request.orderId, Pair(symbols[0], symbols[1])) return eventSubmitter.submit(event) } } \ No newline at end of file diff --git a/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/spi/AccountantApiProxy.kt b/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/spi/AccountantApiProxy.kt index 7bf097191..3cb715f92 100644 --- a/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/spi/AccountantApiProxy.kt +++ b/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/spi/AccountantApiProxy.kt @@ -1,7 +1,7 @@ package co.nilin.opex.matching.gateway.app.spi -import co.nilin.opex.matching.gateway.app.inout.PairFeeConfig import co.nilin.opex.matching.engine.core.model.OrderDirection +import co.nilin.opex.matching.gateway.app.inout.PairFeeConfig import java.math.BigDecimal diff --git a/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/spi/PairConfigLoader.kt b/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/spi/PairConfigLoader.kt index 19ccf9323..a28c3f2c9 100644 --- a/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/spi/PairConfigLoader.kt +++ b/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/spi/PairConfigLoader.kt @@ -1,7 +1,7 @@ package co.nilin.opex.matching.gateway.app.spi -import co.nilin.opex.matching.gateway.app.inout.PairFeeConfig import co.nilin.opex.matching.engine.core.model.OrderDirection +import co.nilin.opex.matching.gateway.app.inout.PairFeeConfig interface PairConfigLoader { suspend fun load(pair: String, direction: OrderDirection, userLevel: String): PairFeeConfig diff --git a/matching-gateway/matching-gateway-app/src/main/resources/application.yml b/matching-gateway/matching-gateway-app/src/main/resources/application.yml index 79c864f43..e544263a4 100644 --- a/matching-gateway/matching-gateway-app/src/main/resources/application.yml +++ b/matching-gateway/matching-gateway-app/src/main/resources/application.yml @@ -1,4 +1,4 @@ -server.port: 8093 +server.port: 8080 logging: level: co.nilin: DEBUG @@ -9,21 +9,23 @@ spring: main: allow-bean-definition-overriding: false kafka: - bootstrap-servers: localhost:9092 + bootstrap-servers: ${KAFKA_IP_PORT:localhost:9092} consumer: group-id: gateway cloud: bootstrap: enabled: true consul: + host: ${CONSUL_HOST:localhost} port: 8500 discovery: #healthCheckPath: ${management.context-path}/health instance-id: ${spring.application.name}:${server.port} healthCheckInterval: 20s prefer-ip-address: true +swagger.authUrl: https://api.opex.dev app: accountant: url: lb://opex-accountant - -swagger.authUrl: https://api.opex.dev \ No newline at end of file + auth: + cert-url: lb://opex-auth/auth/realms/opex/protocol/openid-connect/certs \ No newline at end of file diff --git a/matching-gateway/matching-gateway-port/matching-gateway-submitter-kafka/mvnw b/matching-gateway/matching-gateway-port/matching-gateway-submitter-kafka/mvnw deleted file mode 100644 index a16b5431b..000000000 --- a/matching-gateway/matching-gateway-port/matching-gateway-submitter-kafka/mvnw +++ /dev/null @@ -1,310 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` - fi - - if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=`cygpath --path --windows "$javaClass"` - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/matching-gateway/matching-gateway-port/matching-gateway-submitter-kafka/mvnw.cmd b/matching-gateway/matching-gateway-port/matching-gateway-submitter-kafka/mvnw.cmd deleted file mode 100644 index c8d43372c..000000000 --- a/matching-gateway/matching-gateway-port/matching-gateway-submitter-kafka/mvnw.cmd +++ /dev/null @@ -1,182 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/matching-gateway/matching-gateway-port/matching-gateway-submitter-kafka/src/main/kotlin/co/nilin/opex/matching/gateway/ports/kafka/submitter/config/OrderKafkaConfig.kt b/matching-gateway/matching-gateway-port/matching-gateway-submitter-kafka/src/main/kotlin/co/nilin/opex/matching/gateway/ports/kafka/submitter/config/OrderKafkaConfig.kt index cf8c3e9f7..a8dab0441 100644 --- a/matching-gateway/matching-gateway-port/matching-gateway-submitter-kafka/src/main/kotlin/co/nilin/opex/matching/gateway/ports/kafka/submitter/config/OrderKafkaConfig.kt +++ b/matching-gateway/matching-gateway-port/matching-gateway-submitter-kafka/src/main/kotlin/co/nilin/opex/matching/gateway/ports/kafka/submitter/config/OrderKafkaConfig.kt @@ -20,13 +20,14 @@ class OrderKafkaConfig { private lateinit var bootstrapServers: String @Bean("orderProducerConfigs") - fun producerConfigs(): Map? { - val props: MutableMap = HashMap() - props[ProducerConfig.BOOTSTRAP_SERVERS_CONFIG] = bootstrapServers - props[ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG] = StringSerializer::class.java - props[ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG] = JsonSerializer::class.java - props[JsonSerializer.TYPE_MAPPINGS] = "order_request:co.nilin.opex.matching.gateway.ports.kafka.submitter.inout.OrderSubmitRequest" - return props + fun producerConfigs(): Map { + return mapOf( + ProducerConfig.BOOTSTRAP_SERVERS_CONFIG to bootstrapServers, + ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG to StringSerializer::class.java, + ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG to JsonSerializer::class.java, + ProducerConfig.ACKS_CONFIG to "all", + JsonSerializer.TYPE_MAPPINGS to "order_request:co.nilin.opex.matching.gateway.ports.kafka.submitter.inout.OrderSubmitRequest" + ) } @Bean("orderProducerFactory") diff --git a/pom.xml b/pom.xml index f0d2fef1a..8830788b1 100644 --- a/pom.xml +++ b/pom.xml @@ -10,9 +10,10 @@ 1.0-SNAPSHOT - 1.8 - 1.4.31 - 2.4.4 + 11 + 1.6.0 + 2.6.2 + 2021.0.0 false @@ -28,6 +29,7 @@ utility wallet websocket + admin @@ -59,11 +61,6 @@ - - org.springframework.cloud - spring-cloud-starter-consul-all - 3.0.4 - @@ -98,7 +95,7 @@ spring - 1.8 + ${java.version} diff --git a/resources/vault/backend-policy.hcl b/resources/vault/backend-policy.hcl new file mode 100644 index 000000000..5c0140529 --- /dev/null +++ b/resources/vault/backend-policy.hcl @@ -0,0 +1,26 @@ +path "kv/*" { + capabilities = ["read"] +} + +path "secret/*" { + capabilities = ["read"] +} + +path "secret/opex/" { + capabilities = ["read"] +} + +path "secret/opex-wallet/" { + capabilities = ["read"] +} + +path "sys/mounts" { + capabilities = ["read"] +} + +path "sys/auth" { + capabilities = ["read"] +} + + + diff --git a/resources/vault/panel-policy.hcl b/resources/vault/panel-policy.hcl new file mode 100644 index 000000000..c37b73eef --- /dev/null +++ b/resources/vault/panel-policy.hcl @@ -0,0 +1,27 @@ +path "kv/*" { + capabilities = ["create", "read", "update", "delete", "list"] +} + +path "secret/*" { + capabilities = ["create", "read", "update", "delete", "list"] +} + +path "secret/opex/" { + capabilities = ["create", "read", "update", "delete", "list"] +} + +path "secret/opex-wallet/" { + capabilities = ["create", "read", "update", "delete", "list"] +} + + +path "sys/mounts" { + capabilities = ["create", "read", "update", "delete", "list"] +} + +path "sys/auth" { + capabilities = ["create", "read", "update", "delete", "list"] +} + + + diff --git a/resources/vault/vault.json b/resources/vault/vault.json new file mode 100644 index 000000000..105035688 --- /dev/null +++ b/resources/vault/vault.json @@ -0,0 +1,16 @@ +{ + "listener": { + "tcp": { + "address": "0.0.0.0:8200", + "tls_disable": "true" + } + }, + "backend": { + "file": { + "path": "/vault/file" + } + }, + "default_lease_ttl": "168h", + "max_lease_ttl": "0h", + "api_addr": "http://0.0.0.0:8200" +} \ No newline at end of file diff --git a/resources/vault/workflow-vault.sh b/resources/vault/workflow-vault.sh new file mode 100755 index 000000000..b877919dd --- /dev/null +++ b/resources/vault/workflow-vault.sh @@ -0,0 +1,87 @@ +#!/bin/sh +vault server -config /vault/config/vault.json & + +## Export values +export VAULT_ADDR='http://0.0.0.0:8200' +export VAULT_SKIP_VERIFY='true' + +# +sleep 10 + +if [ ! -f /vault/file/generated_keys.txt ]; then + echo "Vault init" + vault operator init > /vault/file/generated_keys.txt +fi +echo "Generated Keys:" +cat /vault/file/generated_keys.txt +## Parse unsealed keys +(grep "Unseal Key " < /vault/file/generated_keys.txt | cut -c15-) > /vault/file/keys.txt + +echo "Keys:" +cat /vault/file/keys.txt + +while IFS= read -r line; do + echo "Key read from file: $line" + vault operator unseal $line +done < /vault/file/keys.txt +# +## Get root token +(grep "Initial Root Token: " < /vault/file/generated_keys.txt | cut -c21-) > /vault/file/tokens.txt +while IFS= read -r line; do + echo "Root token read from file: $line" + export VAULT_TOKEN=${line} +done < /vault/file/tokens.txt +## Enable kv +echo 'enable kv' +vault secrets enable -path=secret -version=1 kv +## Enable userpass and add default user +echo 'enable userpass and add default user' +vault auth enable userpass +echo 'enable panel policies' +vault policy write panel-policy /vault/config/panel-policy.hcl +echo 'set password ' +echo ${PANEL_PASS} +vault write auth/userpass/users/admin password=${PANEL_PASS} policies=panel-policy +echo 'check login user/pass' +vault login -method=userpass username=admin password=${PANEL_PASS} + +echo 'enable appid and add default user-id' +vault auth enable app-id +echo 'enable backend policies' +vault policy write backend-policy /vault/config/backend-policy.hcl +echo 'enable backend apps' +vault write auth/app-id/map/app-id/opex-accountant value=backend-policy display_name=opex-accountant +vault write auth/app-id/map/app-id/opex-api value=backend-policy display_name=opex-api +vault write auth/app-id/map/app-id/opex-bc-gateway value=backend-policy display_name=opex-bc-gateway +vault write auth/app-id/map/app-id/opex-eventlog value=backend-policy display_name=opex-eventlog +vault write auth/app-id/map/app-id/opex-auth value=backend-policy display_name=opex-auth +vault write auth/app-id/map/app-id/opex-wallet value=backend-policy display_name=opex-wallet +vault write auth/app-id/map/app-id/opex-websocket value=backend-policy display_name=opex-websocket +echo 'enable user-id' +vault write auth/app-id/map/user-id/${BACKEND_USER} value=opex-wallet,opex-websocket,opex-eventlog,opex-auth,opex-accountant,opex-api,opex-bc-gateway +echo 'check login appid' +vault write auth/app-id/login/opex-accountant user_id=${BACKEND_USER} +vault write auth/app-id/login/opex-api user_id=${BACKEND_USER} +vault write auth/app-id/login/opex-bc-gateway user_id=${BACKEND_USER} +vault write auth/app-id/login/opex-eventlog user_id=${BACKEND_USER} +vault write auth/app-id/login/opex-auth user_id=${BACKEND_USER} +vault write auth/app-id/login/opex-wallet user_id=${BACKEND_USER} +vault write auth/app-id/login/opex-websocket user_id=${BACKEND_USER} + +# +## Add secret values +echo 'put key/value' +vault kv put secret/opex smtppass=${SMTP_PASS} +vault kv put secret/opex-accountant dbusername=${DB_USER} dbpassword=${DB_PASS} +vault kv put secret/opex-api dbusername=${DB_USER} dbpassword=${DB_PASS} +vault kv put secret/opex-bc-gateway dbusername=${DB_USER} dbpassword=${DB_PASS} +vault kv put secret/opex-eventlog dbusername=${DB_USER} dbpassword=${DB_PASS} +vault kv put secret/opex-auth dbusername=${DB_USER} dbpassword=${DB_PASS} +vault kv put secret/opex-wallet dbusername=${DB_USER} dbpassword=${DB_PASS} +vault kv put secret/opex-websocket dbusername=${DB_USER} dbpassword=${DB_PASS} + + +# Keep alive +while pidof vault >/dev/null; do + sleep 10 +done diff --git a/storage/storage-app/Dockerfile b/storage/storage-app/Dockerfile index f2cbd4c26..7c71f9447 100644 --- a/storage/storage-app/Dockerfile +++ b/storage/storage-app/Dockerfile @@ -1,5 +1,4 @@ -FROM openjdk:8-jdk-alpine -VOLUME /tmp +FROM openjdk:11 ARG JAR_FILE=target/*.jar COPY ${JAR_FILE} app.jar ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -jar /app.jar"] \ No newline at end of file diff --git a/storage/storage-app/pom.xml b/storage/storage-app/pom.xml index 05d842ec2..dfe70c472 100644 --- a/storage/storage-app/pom.xml +++ b/storage/storage-app/pom.xml @@ -13,10 +13,6 @@ storage-app storage-app - - 2020.0.2 - - org.jetbrains.kotlinx @@ -62,6 +58,11 @@ org.springframework.boot spring-boot-starter-oauth2-resource-server + + net.minidev + json-smart + 2.4.7 + diff --git a/storage/storage-app/src/main/kotlin/co/nilin/opex/storage/app/config/SecurityConfig.kt b/storage/storage-app/src/main/kotlin/co/nilin/opex/storage/app/config/SecurityConfig.kt index 99f6317e5..0b1e5b33e 100644 --- a/storage/storage-app/src/main/kotlin/co/nilin/opex/storage/app/config/SecurityConfig.kt +++ b/storage/storage-app/src/main/kotlin/co/nilin/opex/storage/app/config/SecurityConfig.kt @@ -1,12 +1,10 @@ package co.nilin.opex.storage.app.config -import net.minidev.json.JSONArray +import co.nilin.opex.storage.app.utils.hasRealmRole import org.springframework.beans.factory.annotation.Value import org.springframework.context.annotation.Bean -import org.springframework.security.authorization.AuthorizationDecision import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity import org.springframework.security.config.web.server.ServerHttpSecurity -import org.springframework.security.oauth2.jwt.Jwt import org.springframework.security.oauth2.jwt.NimbusReactiveJwtDecoder import org.springframework.security.oauth2.jwt.ReactiveJwtDecoder import org.springframework.security.web.server.SecurityWebFilterChain @@ -26,15 +24,7 @@ class SecurityConfig(private val webClient: WebClient) { .pathMatchers("/actuator/**").permitAll() .pathMatchers("/swagger-ui/**").permitAll() .pathMatchers("/swagger-resources/**").permitAll() - .pathMatchers("/admin/**").access { mono, authorizationContext -> - mono.map { auth -> - auth.authorities.any { authority -> authority.authority == "SCOPE_trust" } - && ((auth.principal as Jwt) - .claims.get("groups") as JSONArray).contains("finance-admin") - }.map { granted -> - AuthorizationDecision(granted) - } - } + .pathMatchers("/admin/**").hasRealmRole("SCOPE_trust", "finance-admin") .pathMatchers("/**").hasAuthority("SCOPE_trust") .anyExchange().authenticated() .and() diff --git a/storage/storage-app/src/main/kotlin/co/nilin/opex/storage/app/controller/FileController.kt b/storage/storage-app/src/main/kotlin/co/nilin/opex/storage/app/controller/FileController.kt index a8216d35d..8fbc29995 100644 --- a/storage/storage-app/src/main/kotlin/co/nilin/opex/storage/app/controller/FileController.kt +++ b/storage/storage-app/src/main/kotlin/co/nilin/opex/storage/app/controller/FileController.kt @@ -5,6 +5,7 @@ import co.nilin.opex.storage.app.service.StringToHashService import co.nilin.opex.utility.error.data.OpexError import co.nilin.opex.utility.error.data.OpexException import kotlinx.coroutines.reactive.awaitFirstOrNull +import org.springframework.beans.factory.annotation.Value import org.springframework.http.MediaType import org.springframework.http.ResponseEntity import org.springframework.http.codec.multipart.FilePart @@ -17,27 +18,31 @@ import java.nio.file.Paths import java.util.* @RestController -class FileController(private val storageService: StorageService, private val stringToHashService: StringToHashService) { +class FileController( + private val storageService: StorageService, + private val stringToHashService: StringToHashService, + @Value("\${app.root-dir}") private val rootDir: String +) { data class FileUploadResponse(val path: String) private suspend fun upload(uid: String, file: FilePart?, nameWithoutExtension: String? = null): FileUploadResponse { if (file == null) throw OpexException(OpexError.BadRequest, "File Not Provided") val filename = file.filename() val ext = filename.replace(Regex(".+(?<=\\.)"), "") - if (ext.toLowerCase() !in listOf("jpg", "jpeg", "png", "mp4", "mov", "pdf", "gif")) + if (ext.toLowerCase() !in listOf("jpg", "jpeg", "png", "mp4", "mov")) throw OpexException(OpexError.BadRequest, "Invalid File Format") val uri = if (nameWithoutExtension == null) { "$uid/$filename" } else { "$uid/$nameWithoutExtension.$ext" } - val path = Paths.get("").resolve("/opex-storage/$uri").toString() + val path = Paths.get("").resolve("$rootDir/$uri").toString() storageService.store(path, file) return FileUploadResponse("/$uri") } private suspend fun download(uid: String, filename: String? = null): ResponseEntity { - val path = Paths.get("").resolve("/opex-storage/$uid/$filename") + val path = Paths.get("").resolve("$rootDir/$uid/$filename") if (!storageService.exists(path.toString())) throw OpexException(OpexError.NotFound) val file = storageService.load(path.toString()) val mimeType = URLConnection.getFileNameMap().getContentTypeFor(path.fileName.toString()) diff --git a/storage/storage-app/src/main/kotlin/co/nilin/opex/storage/app/utils/Extensions.kt b/storage/storage-app/src/main/kotlin/co/nilin/opex/storage/app/utils/Extensions.kt new file mode 100644 index 000000000..7f2866eaf --- /dev/null +++ b/storage/storage-app/src/main/kotlin/co/nilin/opex/storage/app/utils/Extensions.kt @@ -0,0 +1,19 @@ +package co.nilin.opex.storage.app.utils + +import com.nimbusds.jose.shaded.json.JSONArray +import com.nimbusds.jose.shaded.json.JSONObject +import org.springframework.security.authorization.AuthorizationDecision +import org.springframework.security.config.web.server.ServerHttpSecurity +import org.springframework.security.oauth2.jwt.Jwt + +fun ServerHttpSecurity.AuthorizeExchangeSpec.Access.hasRealmRole( + authority: String, + role: String +): ServerHttpSecurity.AuthorizeExchangeSpec = access { mono, _ -> + mono.map { auth -> + auth.authorities.any { it.authority == authority } + && (((auth.principal as Jwt).claims["realm_access"] as JSONObject)["roles"] as JSONArray).contains(role) + }.map { granted -> + AuthorizationDecision(granted) + } +} \ No newline at end of file diff --git a/storage/storage-app/src/main/resources/application-docker.yml b/storage/storage-app/src/main/resources/application-docker.yml deleted file mode 100644 index 53df2e9b4..000000000 --- a/storage/storage-app/src/main/resources/application-docker.yml +++ /dev/null @@ -1,13 +0,0 @@ -spring: - cloud: - consul: - host: ${CONSUL_HOST} - main: - allow-bean-definition-overriding: true - -app: - cors: - allowed-hosts: https://opex.dev, http://localhost:3000 - allowed-patterns: http://192.168.* - auth: - cert-url: lb://opex-auth/auth/realms/opex/protocol/openid-connect/certs diff --git a/storage/storage-app/src/main/resources/application.yml b/storage/storage-app/src/main/resources/application.yml index 4b6ce48e6..d2669ffe3 100644 --- a/storage/storage-app/src/main/resources/application.yml +++ b/storage/storage-app/src/main/resources/application.yml @@ -1,4 +1,4 @@ -server.port: 8096 +server.port: 8080 logging: level: @@ -14,6 +14,7 @@ spring: bootstrap: enabled: true consul: + host: ${CONSUL_HOST:localhost} port: 8500 discovery: #healthCheckPath: ${management.context-path}/health @@ -22,8 +23,6 @@ spring: prefer-ip-address: true app: - cors: - allowed-hosts: https://opex.dev, http://localhost:3000 - allowed-patterns: http://192.168.* + root-dir: ${ROOT_DIR} auth: cert-url: lb://opex-auth/auth/realms/opex/protocol/openid-connect/certs diff --git a/user-management/keycloak-gateway/Dockerfile b/user-management/keycloak-gateway/Dockerfile index 99b369c3c..155436997 100644 --- a/user-management/keycloak-gateway/Dockerfile +++ b/user-management/keycloak-gateway/Dockerfile @@ -1,5 +1,4 @@ -FROM openjdk:8-jdk-alpine -VOLUME /tmp +FROM openjdk:11 ARG JAR_FILE=target/*.jar COPY ${JAR_FILE} app.jar COPY target/classes/opex-master-realm.json opex-master-realm.json diff --git a/user-management/keycloak-gateway/pom.xml b/user-management/keycloak-gateway/pom.xml index 45ce3817c..1d3880028 100644 --- a/user-management/keycloak-gateway/pom.xml +++ b/user-management/keycloak-gateway/pom.xml @@ -15,13 +15,11 @@ Keycloak gateway app Opex - 13 - 13 - 13 + 11 + 11 12.0.4 3.13.2.Final 11.0.10.Final - 2020.0.2 @@ -74,6 +72,15 @@ ${keycloak.version} pom + + org.keycloak + keycloak-admin-client + ${keycloak.version} + + + co.nilin.opex.utility.error + error-handler + org.postgresql postgresql @@ -87,6 +94,20 @@ org.springframework.kafka spring-kafka + + org.springframework.cloud + spring-cloud-starter-vault-config + + org.springframework.kafka spring-kafka-test diff --git a/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/config/ErrorHandlerConfig.kt b/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/config/ErrorHandlerConfig.kt new file mode 100644 index 000000000..cbb6fe5cc --- /dev/null +++ b/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/config/ErrorHandlerConfig.kt @@ -0,0 +1,18 @@ +package co.nilin.opex.auth.gateway.config + +import co.nilin.opex.utility.error.DefaultErrorTranslator +import co.nilin.opex.utility.error.EnableOpexErrorHandler +import co.nilin.opex.utility.error.spi.ErrorTranslator +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +@Configuration +@EnableOpexErrorHandler +class ErrorHandlerConfig { + + @Bean + fun errorTranslator(): ErrorTranslator { + return DefaultErrorTranslator() + } + +} \ No newline at end of file diff --git a/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/config/KafkaConfig.kt b/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/config/KafkaConfig.kt index f7c43d672..ca65ac73c 100644 --- a/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/config/KafkaConfig.kt +++ b/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/config/KafkaConfig.kt @@ -10,24 +10,28 @@ import org.springframework.beans.factory.annotation.Value import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration import org.springframework.context.support.GenericApplicationContext +import org.springframework.kafka.config.TopicBuilder import org.springframework.kafka.core.DefaultKafkaProducerFactory import org.springframework.kafka.core.KafkaTemplate import org.springframework.kafka.core.ProducerFactory import org.springframework.kafka.support.serializer.JsonSerializer +import java.util.function.Supplier @Configuration class KafkaConfig { + @Value("\${spring.kafka.bootstrap-servers}") private lateinit var bootstrapServers: String @Bean("authProducerConfigs") - fun producerConfigs(): Map? { - val props: MutableMap = HashMap() - props[ProducerConfig.BOOTSTRAP_SERVERS_CONFIG] = bootstrapServers - props[ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG] = StringSerializer::class.java - props[ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG] = JsonSerializer::class.java - props[JsonSerializer.TYPE_MAPPINGS] = "user_created_event:co.nilin.opex.auth.gateway.model.UserCreatedEvent" - return props + fun producerConfigs(): Map { + return mapOf( + ProducerConfig.BOOTSTRAP_SERVERS_CONFIG to bootstrapServers, + ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG to StringSerializer::class.java, + ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG to JsonSerializer::class.java, + ProducerConfig.ACKS_CONFIG to "all", + JsonSerializer.TYPE_MAPPINGS to "user_created_event:co.nilin.opex.auth.gateway.model.UserCreatedEvent" + ) } @Bean("authProducerFactory") @@ -42,6 +46,11 @@ class KafkaConfig { @Autowired fun createUserCreatedTopics(applicationContext: GenericApplicationContext) { - applicationContext.registerBean("topic_auth_user_created", NewTopic::class.java, "auth_user_created", 1, 1) + applicationContext.registerBean("topic_auth_user_created", NewTopic::class.java, Supplier { + TopicBuilder.name("auth_user_created") + .partitions(1) + .replicas(1) + .build() + }) } } \ No newline at end of file diff --git a/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/data/RegisterUserRequest.kt b/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/data/RegisterUserRequest.kt new file mode 100644 index 000000000..3a16c4785 --- /dev/null +++ b/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/data/RegisterUserRequest.kt @@ -0,0 +1,22 @@ +package co.nilin.opex.auth.gateway.data + +class RegisterUserRequest { + + var firstName: String? = null + var lastName: String? = null + var email: String? = null + var username: String? = null + + constructor() + + constructor(firstName: String?, lastName: String?, email: String?, username: String?) { + this.firstName = firstName + this.lastName = lastName + this.email = email + this.username = username + } + + fun isValid(): Boolean { + return !firstName.isNullOrEmpty() && !lastName.isNullOrEmpty() && !email.isNullOrEmpty() && !username.isNullOrEmpty() + } +} \ No newline at end of file diff --git a/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/data/RegisterUserResponse.kt b/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/data/RegisterUserResponse.kt new file mode 100644 index 000000000..fc9964e72 --- /dev/null +++ b/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/data/RegisterUserResponse.kt @@ -0,0 +1,13 @@ +package co.nilin.opex.auth.gateway.data + +class RegisterUserResponse { + + var id: String? = null + + constructor() + + constructor(id: String?) { + this.id = id + } + +} \ No newline at end of file diff --git a/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/data/UserProfileInfo.kt b/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/data/UserProfileInfo.kt new file mode 100644 index 000000000..538cdfb46 --- /dev/null +++ b/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/data/UserProfileInfo.kt @@ -0,0 +1,50 @@ +package co.nilin.opex.auth.gateway.data + +class UserProfileInfo { + + var firstNameEn: String? = null + var lastNameEn: String? = null + var firstNameFa: String? = null + var lastNameFa: String? = null + var birthday: String? = null + var birthdayJalali: String? = null + var nationalID: String? = null + var passport: String? = null + var phoneNumber: String? = null + var homeNumber: String? = null + var email: String? = null + var postalCode: String? = null + var address: String? = null + + constructor() + + constructor( + firstNameEn: String?, + lastNameEn: String?, + firstNameFa: String?, + lastNameFa: String?, + birthday: String?, + birthdayJalali: String?, + nationalID: String?, + passport: String?, + phoneNumber: String?, + homeNumber: String?, + email: String?, + postalCode: String?, + address: String? + ) { + this.firstNameEn = firstNameEn + this.lastNameEn = lastNameEn + this.firstNameFa = firstNameFa + this.lastNameFa = lastNameFa + this.birthday = birthday + this.birthdayJalali = birthdayJalali + this.nationalID = nationalID + this.passport = passport + this.phoneNumber = phoneNumber + this.homeNumber = homeNumber + this.email = email + this.postalCode = postalCode + this.address = address + } +} \ No newline at end of file diff --git a/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/extension/HashicorpVaultProvider.java b/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/extension/HashicorpVaultProvider.java new file mode 100644 index 000000000..735858fef --- /dev/null +++ b/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/extension/HashicorpVaultProvider.java @@ -0,0 +1,52 @@ +package co.nilin.opex.auth.gateway.extension; + +import org.jboss.logging.Logger; +import org.keycloak.vault.DefaultVaultRawSecret; +import org.keycloak.vault.VaultProvider; +import org.keycloak.vault.VaultRawSecret; + +import java.util.Optional; + +/** + * HashicorpVaultProviderFactory + */ +public class HashicorpVaultProvider implements VaultProvider { + private static final Logger logger = Logger.getLogger(HashicorpVaultProviderFactory.class); + + private String vaultUrl; + private String vaultAppId; + private String vaultUserId; + private String realmName; + private String vaultSecretEngineName; + private VaultService service; + + @Override + public VaultRawSecret obtainSecret(String vaultSecretId) { + int secretVersion = 0; + String vaultSecretName = vaultSecretId; + if (vaultSecretId.contains(":")) { + try { + secretVersion = Integer.parseInt(vaultSecretId.substring(vaultSecretId.lastIndexOf(":") + 1)); + vaultSecretName = vaultSecretId.substring(0, vaultSecretId.lastIndexOf(":")); + } catch (NumberFormatException e) { + logger.error("last string after : is expected to be the version number"); + } + } + + return DefaultVaultRawSecret.forBuffer(Optional.of(service.getSecretFromVault(vaultUrl, realmName, vaultSecretEngineName, vaultSecretName, vaultAppId, vaultUserId, secretVersion))); + } + + @Override + public void close() { + } + + public HashicorpVaultProvider(String vaultUrl, String vaultAppId, String vaultUserId, String realmName, String vaultSecretEngineName, VaultService service) { + this.vaultUrl = vaultUrl; + this.vaultAppId = vaultAppId; + this.vaultUserId = vaultUserId; + this.realmName = realmName; + this.vaultSecretEngineName = vaultSecretEngineName; + this.service = service; + } + +} \ No newline at end of file diff --git a/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/extension/HashicorpVaultProviderFactory.java b/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/extension/HashicorpVaultProviderFactory.java new file mode 100644 index 000000000..c546f1646 --- /dev/null +++ b/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/extension/HashicorpVaultProviderFactory.java @@ -0,0 +1,76 @@ +package co.nilin.opex.auth.gateway.extension; + +import org.jboss.logging.Logger; +import org.keycloak.Config.Scope; +import org.keycloak.models.KeycloakSession; +import org.keycloak.models.KeycloakSessionFactory; +import org.keycloak.vault.VaultNotFoundException; +import org.keycloak.vault.VaultProvider; +import org.keycloak.vault.VaultProviderFactory; + +public class HashicorpVaultProviderFactory implements VaultProviderFactory { + private static final Logger logger = Logger.getLogger(HashicorpVaultProviderFactory.class); + + public static final String PROVIDER_ID = "hachicorp-vault"; + + private String vaultAppId; + private String vaultUserId; + private String vaultUrl; + private String vaultSecretEngineName; + + @Override + public VaultProvider create(KeycloakSession session) { + VaultService service = new VaultService(session); + if (!service.isVaultAvailable(vaultUrl, vaultAppId, vaultUserId)) { + logger.error("Vault unavailable : " + vaultUrl); + throw new VaultNotFoundException("Vault unavailable : " + vaultUrl); + } else { + logger.info("Vault available : " + vaultUrl); + } + return new HashicorpVaultProvider(vaultUrl, vaultAppId, vaultUserId, session.getContext().getRealm().getName(), vaultSecretEngineName, service); + + } + + private static String format(String url) { + if (!(url.charAt(url.length() - 1) == '/')) { + return url.concat("/"); + } else { + return url; + } + } + + @Override + public void init(Scope config) { + if (System.getenv("BACKEND_APP") != null) { + vaultAppId = System.getenv("BACKEND_APP"); + } else { + vaultAppId = config.get("appId"); + } + if (System.getenv("BACKEND_USER") != null) { + vaultUserId = System.getenv("BACKEND_USER"); + } else { + vaultUserId = config.get("userId"); + } + vaultUrl = config.get("url") != null ? format(config.get("url")) : null; + vaultSecretEngineName = config.get("engine-name"); + logger.info("Init Hashicorp: " + vaultUrl); + } + + @Override + public void postInit(KeycloakSessionFactory factory) { + // TODO Auto-generated method stub + + } + + @Override + public void close() { + // TODO Auto-generated method stub + + } + + @Override + public String getId() { + return PROVIDER_ID; + } + +} diff --git a/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/extension/UserManagementResource.kt b/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/extension/UserManagementResource.kt new file mode 100644 index 000000000..d6aa62861 --- /dev/null +++ b/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/extension/UserManagementResource.kt @@ -0,0 +1,177 @@ +package co.nilin.opex.auth.gateway.extension + +import co.nilin.opex.auth.gateway.data.RegisterUserRequest +import co.nilin.opex.auth.gateway.data.RegisterUserResponse +import co.nilin.opex.auth.gateway.data.UserProfileInfo +import co.nilin.opex.auth.gateway.utils.ErrorHandler +import co.nilin.opex.auth.gateway.utils.ResourceAuthenticator +import co.nilin.opex.utility.error.data.OpexError +import co.nilin.opex.utility.error.data.OpexException +import org.keycloak.authentication.actiontoken.execactions.ExecuteActionsActionToken +import org.keycloak.common.util.Time +import org.keycloak.email.EmailTemplateProvider +import org.keycloak.models.Constants +import org.keycloak.models.KeycloakSession +import org.keycloak.models.UserModel +import org.keycloak.services.resource.RealmResourceProvider +import org.keycloak.services.resources.LoginActionsService +import org.slf4j.LoggerFactory +import java.util.concurrent.TimeUnit +import javax.ws.rs.* +import javax.ws.rs.core.MediaType +import javax.ws.rs.core.Response +import kotlin.streams.toList + +class UserManagementResource(private val session: KeycloakSession) : RealmResourceProvider { + + private val logger = LoggerFactory.getLogger(UserManagementResource::class.java) + private val opexRealm = session.realms().getRealm("opex") + + @POST + @Path("user") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + fun registerUser(request: RegisterUserRequest): Response { + val auth = ResourceAuthenticator.bearerAuth(session) + if (!auth.hasScopeAccess("trust")) + return ErrorHandler.forbidden() + + if (!request.isValid()) + return ErrorHandler.response(Response.Status.BAD_REQUEST, OpexException(OpexError.BadRequest)) + + val user = session.users().addUser(opexRealm, request.username).apply { + email = request.email + firstName = request.firstName + lastName = request.lastName + isEnabled = true + isEmailVerified = false + + addRequiredAction(UserModel.RequiredAction.VERIFY_EMAIL) + addRequiredAction(UserModel.RequiredAction.UPDATE_PASSWORD) + sendEmail(this, requiredActionsStream.toList()) + } + + logger.info("User create response ${user.id}") + return Response.ok(RegisterUserResponse(user.id)).build() + } + + @POST + @Path("user/forgot") + @Produces(MediaType.APPLICATION_JSON) + fun forgotPassword(@QueryParam("email") email: String?): Response { + val auth = ResourceAuthenticator.bearerAuth(session) + if (!auth.hasScopeAccess("trust")) + return ErrorHandler.forbidden() + + val user = session.users().getUserByEmail(email, opexRealm) + if (user != null) { + sendEmail(user, listOf(UserModel.RequiredAction.UPDATE_PASSWORD.name)) + } + return Response.noContent().build() + } + + @POST + @Path("user/verify-email") + @Produces(MediaType.APPLICATION_JSON) + fun sendVerifyEmail(@QueryParam("email") email: String?): Response { + val auth = ResourceAuthenticator.bearerAuth(session) + if (!auth.hasScopeAccess("trust")) + return ErrorHandler.forbidden() + + val user = session.users().getUserByEmail(email, opexRealm) + if (user != null) { + if (!auth.hasUserAccess(user.id)) + return ErrorHandler.forbidden() + + sendEmail(user, listOf(UserModel.RequiredAction.VERIFY_EMAIL.name)) + } + return Response.noContent().build() + } + + @GET + @Path("user/profile") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + fun getAttributes(): Response { + val auth = ResourceAuthenticator.bearerAuth(session) + if (!auth.hasScopeAccess("trust")) + return ErrorHandler.forbidden() + + val user = session.users().getUserById(auth.getUserId(), opexRealm) + ?: return ErrorHandler.response( + Response.Status.NOT_FOUND, + OpexException(OpexError.NotFound, "User not found") + ) + + return Response.ok(user.attributes).build() + } + + @POST + @Path("user/profile") + @Consumes(MediaType.APPLICATION_JSON) + fun updateAttributes(request: UserProfileInfo): Response { + val auth = ResourceAuthenticator.bearerAuth(session) + if (!auth.hasScopeAccess("trust")) + return ErrorHandler.forbidden() + + val user = session.users().getUserById(auth.getUserId(), opexRealm) + ?: return ErrorHandler.response( + Response.Status.NOT_FOUND, + OpexException(OpexError.NotFound, "User not found") + ) + + with(request) { + user.setSingleAttribute("firstNameFa", firstNameFa) + user.setSingleAttribute("lastNameEn", lastNameEn) + user.setSingleAttribute("firstNameFa", firstNameFa) + user.setSingleAttribute("lastNameFa", lastNameFa) + user.setSingleAttribute("birthday", birthday) + user.setSingleAttribute("birthdayJalali", birthdayJalali) + user.setSingleAttribute("nationalID", nationalID) + user.setSingleAttribute("passport", passport) + user.setSingleAttribute("phoneNumber", phoneNumber) + user.setSingleAttribute("homeNumber", homeNumber) + user.setSingleAttribute("email", email) + user.setSingleAttribute("postalCode", postalCode) + user.setSingleAttribute("address", address) + } + + return Response.noContent().build() + } + + private fun sendEmail(user: UserModel, actions: List) { + if (!user.isEnabled) + throw OpexException(OpexError.BadRequest, "User is disabled") + + val clientId = Constants.ACCOUNT_MANAGEMENT_CLIENT_ID + val client = session.clients().getClientByClientId(opexRealm, clientId) + if (client == null || !client.isEnabled) + throw OpexException(OpexError.BadRequest, "Client error") + + val lifespan = opexRealm.actionTokenGeneratedByAdminLifespan + val expiration = Time.currentTime() + lifespan + val token = ExecuteActionsActionToken(user.id, expiration, actions, null, clientId) + + try { + val provider = session.getProvider(EmailTemplateProvider::class.java) + val builder = LoginActionsService.actionTokenProcessor(session.context.uri).apply { + queryParam("key", token.serialize(session, opexRealm, session.context.uri)) + } + val link = builder.build(opexRealm.name).toString() + provider.setRealm(opexRealm) + .setUser(user) + .sendVerifyEmail(link, TimeUnit.SECONDS.toMinutes(lifespan.toLong())) + } catch (e: Exception) { + logger.error("Unable to send verification email") + e.printStackTrace() + } + } + + override fun close() { + + } + + override fun getResource(): Any { + return this + } +} \ No newline at end of file diff --git a/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/extension/UserManagementResourceFactory.kt b/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/extension/UserManagementResourceFactory.kt new file mode 100644 index 000000000..31f0a2942 --- /dev/null +++ b/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/extension/UserManagementResourceFactory.kt @@ -0,0 +1,30 @@ +package co.nilin.opex.auth.gateway.extension + +import org.keycloak.Config +import org.keycloak.models.KeycloakSession +import org.keycloak.models.KeycloakSessionFactory +import org.keycloak.services.resource.RealmResourceProvider +import org.keycloak.services.resource.RealmResourceProviderFactory + +class UserManagementResourceFactory : RealmResourceProviderFactory { + + override fun create(session: KeycloakSession): RealmResourceProvider { + return UserManagementResource(session) + } + + override fun init(config: Config.Scope) { + + } + + override fun postInit(factory: KeycloakSessionFactory?) { + + } + + override fun close() { + + } + + override fun getId(): String { + return "user-management" + } +} \ No newline at end of file diff --git a/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/extension/VaultService.java b/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/extension/VaultService.java new file mode 100644 index 000000000..d6fe61a78 --- /dev/null +++ b/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/extension/VaultService.java @@ -0,0 +1,60 @@ +package co.nilin.opex.auth.gateway.extension; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.JsonNode; +import org.jboss.logging.Logger; +import org.keycloak.broker.provider.util.SimpleHttp; +import org.keycloak.models.KeycloakSession; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; + +/** + * VaultService + */ +public class VaultService { + + private final KeycloakSession session; + private static final Logger logger = Logger.getLogger(VaultService.class); + + public VaultService(KeycloakSession session) { + this.session = session; + } + + static class UserId { + @JsonProperty("user_id") + public String userId; + + public UserId(String userId) { + this.userId = userId; + } + } + + public ByteBuffer getSecretFromVault(String vaultUrl, String realm, String vaultSecretEngineName, String secretName, String vaultAppId, String vaultUserId, int secretVersion) { + try { + //curl \ --method POST \ --data '{"user_id": ":user_id"}' \ http://127.0.0.1:8200/v1/auth/app-id/login/:app_id + String vaultToken = SimpleHttp.doPost(vaultUrl + "v1//auth/app-id/login/" + vaultAppId, session).json(new UserId(vaultUserId)).asJson().get("auth").get("client_token").textValue(); + JsonNode node = SimpleHttp.doGet(vaultUrl + "v1/" + vaultSecretEngineName + "/" + realm + "?version=" + secretVersion, session).header("X-Vault-Token", vaultToken).asJson(); + byte[] secretBytes = node.get("data").get(secretName).textValue().getBytes(StandardCharsets.UTF_8); + return ByteBuffer.wrap(secretBytes); + } catch (IOException e) { + logger.error("secret not available", e); + return null; + } + } + + public boolean isVaultAvailable(String vaultUrl, String vaultAppId, String vaultUserId) { + String healthVaultUrl = vaultUrl + "v1/sys/health"; + try { + JsonNode vaultHealthResponseNode = SimpleHttp.doGet(healthVaultUrl, session).asJson(); + boolean vaultIsInitialized = vaultHealthResponseNode.get("initialized").asBoolean(); + boolean vaultIsSealed = vaultHealthResponseNode.get("sealed").asBoolean(); + return (vaultIsInitialized && !vaultIsSealed); + } catch (IOException e) { + logger.error("vault service unavailable", e); + return false; + } + } + +} \ No newline at end of file diff --git a/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/utils/ErrorHandler.kt b/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/utils/ErrorHandler.kt new file mode 100644 index 000000000..2f00fcc5e --- /dev/null +++ b/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/utils/ErrorHandler.kt @@ -0,0 +1,18 @@ +package co.nilin.opex.auth.gateway.utils + +import co.nilin.opex.utility.error.DefaultErrorTranslator +import co.nilin.opex.utility.error.data.OpexError +import co.nilin.opex.utility.error.data.OpexException +import javax.ws.rs.core.Response + +object ErrorHandler { + + private val translator = DefaultErrorTranslator() + + fun response(status: Response.Status, ex: OpexException): Response { + return Response.status(status).entity(translator.translate(ex)).build() + } + + fun forbidden() = response(Response.Status.FORBIDDEN, OpexException(OpexError.Forbidden)) + +} \ No newline at end of file diff --git a/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/utils/ResourceAuthenticator.kt b/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/utils/ResourceAuthenticator.kt new file mode 100644 index 000000000..01dfbf212 --- /dev/null +++ b/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/auth/gateway/utils/ResourceAuthenticator.kt @@ -0,0 +1,34 @@ +package co.nilin.opex.auth.gateway.utils + +import org.keycloak.models.KeycloakSession +import org.keycloak.models.UserModel +import org.keycloak.representations.AccessToken +import org.keycloak.services.managers.AppAuthManager +import org.keycloak.services.managers.AuthenticationManager + +class ResourceAuthenticator(private val result: AuthenticationManager.AuthResult) { + + private val user: UserModel? = result.user + private val token: AccessToken = result.token + + fun getUserId() = user?.id + + fun hasAccess(scope: String, userId: String? = null): Boolean { + return hasScopeAccess(scope) && hasUserAccess(userId) + } + + fun hasScopeAccess(scope: String): Boolean { + return token.scope.split(" ").contains(scope) + } + + fun hasUserAccess(userId: String? = null): Boolean { + return userId != null && user?.id == userId + } + + companion object { + fun bearerAuth(session: KeycloakSession): ResourceAuthenticator { + return ResourceAuthenticator(AppAuthManager.BearerTokenAuthenticator(session).authenticate()) + } + } + +} \ No newline at end of file diff --git a/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt b/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt new file mode 100644 index 000000000..e9efaf92a --- /dev/null +++ b/user-management/keycloak-gateway/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt @@ -0,0 +1,9 @@ +package co.nilin.opex.util.vault + +import org.springframework.vault.authentication.AppIdUserIdMechanism + +class VaultUserIdMechanism() : AppIdUserIdMechanism { + override fun createUserId(): String { + return System.getenv("BACKEND_USER") + } +} \ No newline at end of file diff --git a/user-management/keycloak-gateway/src/main/resources/META-INF/keycloak-server.json b/user-management/keycloak-gateway/src/main/resources/META-INF/keycloak-server.json index 1058fe841..6c6b39cc1 100644 --- a/user-management/keycloak-gateway/src/main/resources/META-INF/keycloak-server.json +++ b/user-management/keycloak-gateway/src/main/resources/META-INF/keycloak-server.json @@ -198,9 +198,15 @@ } }, "vault": { - "files-plaintext": { - "dir": "target/dependency/vault", - "enabled": "${keycloak.vault.files-plaintext.provider.enabled:false}" + "provider": "hachicorp-vault", + "default": { + "enabled": true + }, + "hachicorp-vault": { + "url": "${keycloak.hashicorp.url}", + "appId": "${spring.application.name}", + "engine-name": "secret", + "enabled": "${keycloak.vault.files-plaintext.provider.enabled:true}" } }, "saml-artifact-resolver": { diff --git a/user-management/keycloak-gateway/src/main/resources/META-INF/services/org.keycloak.services.resource.RealmResourceProviderFactory b/user-management/keycloak-gateway/src/main/resources/META-INF/services/org.keycloak.services.resource.RealmResourceProviderFactory new file mode 100644 index 000000000..9ed020e09 --- /dev/null +++ b/user-management/keycloak-gateway/src/main/resources/META-INF/services/org.keycloak.services.resource.RealmResourceProviderFactory @@ -0,0 +1 @@ +co.nilin.opex.auth.gateway.extension.UserManagementResourceFactory \ No newline at end of file diff --git a/user-management/keycloak-gateway/src/main/resources/META-INF/services/org.keycloak.vault.VaultProviderFactory b/user-management/keycloak-gateway/src/main/resources/META-INF/services/org.keycloak.vault.VaultProviderFactory new file mode 100644 index 000000000..38186ba6e --- /dev/null +++ b/user-management/keycloak-gateway/src/main/resources/META-INF/services/org.keycloak.vault.VaultProviderFactory @@ -0,0 +1 @@ +co.nilin.opex.auth.gateway.extension.HashicorpVaultProviderFactory \ No newline at end of file diff --git a/user-management/keycloak-gateway/src/main/resources/application-docker.yml b/user-management/keycloak-gateway/src/main/resources/application-docker.yml deleted file mode 100644 index f52df428b..000000000 --- a/user-management/keycloak-gateway/src/main/resources/application-docker.yml +++ /dev/null @@ -1,17 +0,0 @@ -spring: - kafka: - bootstrap-servers: ${KAFKA_IP_PORT} - datasource: - url: jdbc:postgresql://${DB_IP_PORT}/opex_auth - username: opex - password: hiopex - cloud: - consul: - host: ${CONSUL_HOST} - port: 8500 - -keycloak: - migration: - file: /opex-master-realm.json - adminUrl: https://api.opex.dev/auth - frontendUrl: https://api.opex.dev/auth diff --git a/user-management/keycloak-gateway/src/main/resources/application.yml b/user-management/keycloak-gateway/src/main/resources/application.yml index db3942635..fca91b09f 100644 --- a/user-management/keycloak-gateway/src/main/resources/application.yml +++ b/user-management/keycloak-gateway/src/main/resources/application.yml @@ -1,19 +1,19 @@ -server.port: 8083 +server.port: 8080 spring: application: name: opex-auth main: allow-bean-definition-overriding: false kafka: - bootstrap-servers: localhost:9092 + bootstrap-servers: ${KAFKA_IP_PORT:localhost:9092} consumer: group-id: auth datasource: platform: postgres driver-class-name: org.postgresql.Driver - url: jdbc:postgresql://localhost/opex_auth - username: opex - password: hiopex + url: jdbc:postgresql://${DB_IP_PORT:localhost}/opex_auth + username: ${dbusername:opex} + password: ${dbpassword:hiopex} initialization-mode: always jpa: hibernate: @@ -25,14 +25,32 @@ spring: cloud: bootstrap: enabled: true + vault: + host: ${VAULT_HOST} + port: 8200 + scheme: http + authentication: APPID + app-id: + user-id: co.nilin.opex.util.vault.VaultUserIdMechanism + fail-fast: true + kv: + enabled: true + backend: secret + profile-separator: '/' + application-name: ${spring.application.name} consul: + host: ${CONSUL_HOST:localhost} port: 8500 discovery: #healthCheckPath: ${management.context-path}/health instance-id: ${spring.application.name}:${server.port} healthCheckInterval: 20s prefer-ip-address: true + config: + import: vault://secret/${spring.application.name} keycloak: + adminUrl: ${ADMIN_URL:http://localhost:8080/auth} + frontendUrl: ${FRONTEND_URL:http://localhost:8080/auth} server: contextPath: /auth adminUser: @@ -42,9 +60,11 @@ keycloak: migration: action: import provider: singleFile - file: classpath:/opex-master-realm.json + file: /opex-master-realm.json strategy: OVERWRITE_EXISTING profile: feature: admin_fine_grained_authz: enabled token_exchange: enabled + hashicorp: + url: ${VAULT_URL} \ No newline at end of file diff --git a/user-management/keycloak-gateway/src/main/resources/opex-master-realm.json b/user-management/keycloak-gateway/src/main/resources/opex-master-realm.json index 259df44ab..146a5976d 100644 --- a/user-management/keycloak-gateway/src/main/resources/opex-master-realm.json +++ b/user-management/keycloak-gateway/src/main/resources/opex-master-realm.json @@ -42,6 +42,6 @@ "from": "for.demo.purpose.only@opex.dev", "auth": true, "user": "for.demo.purpose.only@opex.dev", - "password": "642467973026C6F093FB1E39C4BFC0D15042" + "password": "${vault.smtppass}" } } \ No newline at end of file diff --git a/user-management/keycloak-gateway/src/main/resources/opex-realm.json b/user-management/keycloak-gateway/src/main/resources/opex-realm.json index 791115d4b..d5913497e 100644 --- a/user-management/keycloak-gateway/src/main/resources/opex-realm.json +++ b/user-management/keycloak-gateway/src/main/resources/opex-realm.json @@ -32,7 +32,7 @@ "duplicateEmailsAllowed": false, "resetPasswordAllowed": true, "editUsernameAllowed": false, - "bruteForceProtected": false, + "bruteForceProtected": true, "permanentLockout": false, "maxFailureWaitSeconds": 900, "minimumQuickLoginWaitSeconds": 60, @@ -87,6 +87,8 @@ ], "client": { "newClient": [], + "ipg": [], + "web-app": [], "realm-management": [ { "id": "5d00243f-ceec-4b0c-995e-d86d5b8a0ae6", @@ -104,6 +106,14 @@ "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", "attributes": {} }, + { + "id": "7df58488-6470-4f4e-962d-2900019e9906", + "name": "uma_protection", + "composite": false, + "clientRole": true, + "containerId": "6a4bfbd0-576d-4778-af56-56f876647355", + "attributes": {} + }, { "id": "941612de-bd85-47a5-8dfa-37c270dde28c", "name": "view-authorization", @@ -313,6 +323,7 @@ "attributes": {} } ], + "opex-admin": [], "account": [ { "id": "8daa8096-d14e-4d1c-ad1f-83f822016aa1", @@ -403,6 +414,33 @@ "realmRoles": [], "clientRoles": {}, "subGroups": [] + }, + { + "id": "8307c787-473d-41a1-ad57-f31bd32119e8", + "name": "kyc-accepted", + "path": "/kyc-accepted", + "attributes": {}, + "realmRoles": [], + "clientRoles": {}, + "subGroups": [] + }, + { + "id": "abf74cdd-09c9-473f-9438-f6e545571c68", + "name": "kyc-rejected", + "path": "/kyc-rejected", + "attributes": {}, + "realmRoles": [], + "clientRoles": {}, + "subGroups": [] + }, + { + "id": "24200655-dfef-4ed0-a8b8-925918793552", + "name": "kyc-requested", + "path": "/kyc-requested", + "attributes": {}, + "realmRoles": [], + "clientRoles": {}, + "subGroups": [] } ], "defaultRoles": [ @@ -472,6 +510,81 @@ }, "notBefore": 0, "groups": [] + }, + { + "id": "2cda7f75-c5d9-4b64-b90e-58b381689a9d", + "createdTimestamp": 1643624421752, + "username": "service-account-opex-admin", + "enabled": true, + "totp": false, + "emailVerified": false, + "serviceAccountClientId": "opex-admin", + "disableableCredentialTypes": [], + "requiredActions": [], + "realmRoles": [ + "offline_access", + "uma_authorization" + ], + "clientRoles": { + "realm-management": [ + "manage-users" + ], + "account": [ + "manage-account", + "view-profile" + ] + }, + "notBefore": 0, + "groups": [] + }, + { + "id": "854a5e2b-1e45-4ff7-bd1c-d9764d41a5bd", + "createdTimestamp": 1634844207750, + "username": "service-account-realm-management", + "enabled": true, + "totp": false, + "emailVerified": false, + "serviceAccountClientId": "realm-management", + "disableableCredentialTypes": [], + "requiredActions": [], + "realmRoles": [ + "offline_access", + "uma_authorization" + ], + "clientRoles": { + "realm-management": [ + "uma_protection" + ], + "account": [ + "manage-account", + "view-profile" + ] + }, + "notBefore": 0, + "groups": [] + }, + { + "id": "aeca81d9-c866-443c-9900-bec13168ab86", + "createdTimestamp": 1644315164607, + "username": "service-account-web-app", + "enabled": true, + "totp": false, + "emailVerified": false, + "serviceAccountClientId": "web-app", + "disableableCredentialTypes": [], + "requiredActions": [], + "realmRoles": [ + "offline_access", + "uma_authorization" + ], + "clientRoles": { + "account": [ + "manage-account", + "view-profile" + ] + }, + "notBefore": 0, + "groups": [] } ], "scopeMappings": [ @@ -489,6 +602,14 @@ "finance-admin" ] }, + { + "client": "opex-admin", + "roles": [ + "offline_access", + "uma_authorization", + "user" + ] + }, { "clientScope": "offline_access", "roles": [ @@ -511,6 +632,12 @@ "roles": [ "impersonation" ] + }, + { + "client": "opex-admin", + "roles": [ + "realm-admin" + ] } ], "account": [ @@ -519,6 +646,12 @@ "roles": [ "manage-account" ] + }, + { + "client": "opex-admin", + "roles": [ + "manage-account" + ] } ] }, @@ -533,7 +666,7 @@ "enabled": true, "alwaysDisplayInConsole": false, "clientAuthenticatorType": "client-secret", - "secret": "fae6f87e-5b66-435c-b5aa-fd42c7641604", + "secret": "**********", "defaultRoles": [ "manage-account", "view-profile" @@ -601,7 +734,7 @@ "enabled": true, "alwaysDisplayInConsole": false, "clientAuthenticatorType": "client-secret", - "secret": "fae6f87e-5b66-435c-b5aa-fd42c7641604", + "secret": "**********", "redirectUris": [ "/realms/opex/account/*", "http://localhost:3000/*", @@ -720,7 +853,7 @@ "enabled": true, "alwaysDisplayInConsole": false, "clientAuthenticatorType": "client-secret", - "secret": "fae6f87e-5b66-435c-b5aa-fd42c7641604", + "secret": "**********", "redirectUris": [], "webOrigins": [ "*" @@ -758,6 +891,21 @@ "fullScopeAllowed": false, "nodeReRegistrationTimeout": 0, "protocolMappers": [ + { + "id": "c652a15d-6b9d-4f11-af40-ed451f30589c", + "name": "groups", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-realm-role-mapper", + "consentRequired": false, + "config": { + "multivalued": "true", + "user.attribute": "foo", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "groups", + "jsonType.label": "String" + } + }, { "id": "0cede09c-fee1-4e60-85fa-7067180bbae5", "name": "Group Mapper", @@ -786,6 +934,20 @@ "multivalued": "true" } }, + { + "id": "f53d8370-145f-4123-a680-abe4e7ef5d39", + "name": "client roles", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-client-role-mapper", + "consentRequired": false, + "config": { + "user.attribute": "foo", + "access.token.claim": "true", + "claim.name": "resource_access.${client_id}.roles", + "jsonType.label": "String", + "multivalued": "true" + } + }, { "id": "a74e3676-91f1-4897-830c-14a2fad94c73", "name": "UserLeveL", @@ -826,7 +988,7 @@ "enabled": true, "alwaysDisplayInConsole": false, "clientAuthenticatorType": "client-secret", - "secret": "fae6f87e-5b66-435c-b5aa-fd42c7641604", + "secret": "**********", "redirectUris": [ "http://localhost:3000/*", "https://opex.dev/*" @@ -880,6 +1042,64 @@ "microprofile-jwt" ] }, + { + "id": "ab6eace7-409f-4dc2-93ed-3f451795c362", + "clientId": "ipg", + "name": "IPG client", + "description": "Internet payment gateway client", + "surrogateAuthRequired": false, + "enabled": true, + "alwaysDisplayInConsole": false, + "clientAuthenticatorType": "client-secret", + "secret": "**********", + "redirectUris": [], + "webOrigins": [], + "notBefore": 0, + "bearerOnly": false, + "consentRequired": false, + "standardFlowEnabled": false, + "implicitFlowEnabled": false, + "directAccessGrantsEnabled": true, + "serviceAccountsEnabled": false, + "publicClient": true, + "frontchannelLogout": false, + "protocol": "openid-connect", + "attributes": { + "saml.assertion.signature": "false", + "saml.multivalued.roles": "false", + "saml.force.post.binding": "false", + "saml.encrypt": "false", + "backchannel.logout.revoke.offline.tokens": "false", + "saml.server.signature": "false", + "saml.server.signature.keyinfo.ext": "false", + "exclude.session.state.from.auth.response": "false", + "backchannel.logout.session.required": "true", + "client_credentials.use_refresh_token": "false", + "saml_force_name_id_format": "false", + "saml.client.signature": "false", + "tls.client.certificate.bound.access.tokens": "false", + "saml.authnstatement": "false", + "display.on.consent.screen": "false", + "saml.onetimeuse.condition": "false" + }, + "authenticationFlowBindingOverrides": {}, + "fullScopeAllowed": true, + "nodeReRegistrationTimeout": -1, + "defaultClientScopes": [ + "trust", + "web-origins", + "ipg", + "role_list", + "profile", + "email" + ], + "optionalClientScopes": [ + "address", + "phone", + "offline_access", + "microprofile-jwt" + ] + }, { "id": "b88ce206-63d6-43b6-87c9-ea09d8c02f32", "clientId": "newClient", @@ -887,7 +1107,7 @@ "enabled": true, "alwaysDisplayInConsole": false, "clientAuthenticatorType": "client-secret", - "secret": "fae6f87e-5b66-435c-b5aa-fd42c7641604", + "secret": "**********", "redirectUris": [ "http://localhost:8082/new-client/login/oauth2/code/custom", "http://localhost:3000/*", @@ -945,6 +1165,122 @@ "email" ] }, + { + "id": "fb5f91c4-42fa-4769-b45d-febef22b4976", + "clientId": "opex-admin", + "name": "${client_opex-admin}", + "rootUrl": "${authBaseUrl}", + "surrogateAuthRequired": false, + "enabled": true, + "alwaysDisplayInConsole": false, + "clientAuthenticatorType": "client-secret", + "secret": "**********", + "redirectUris": [ + "*" + ], + "webOrigins": [], + "notBefore": 0, + "bearerOnly": false, + "consentRequired": false, + "standardFlowEnabled": true, + "implicitFlowEnabled": false, + "directAccessGrantsEnabled": true, + "serviceAccountsEnabled": true, + "publicClient": false, + "frontchannelLogout": false, + "protocol": "openid-connect", + "attributes": { + "saml.assertion.signature": "false", + "access.token.lifespan": "86400", + "saml.multivalued.roles": "false", + "saml.force.post.binding": "false", + "saml.encrypt": "false", + "backchannel.logout.revoke.offline.tokens": "false", + "saml.server.signature": "false", + "saml.server.signature.keyinfo.ext": "false", + "exclude.session.state.from.auth.response": "false", + "backchannel.logout.session.required": "false", + "client_credentials.use_refresh_token": "false", + "saml_force_name_id_format": "false", + "saml.client.signature": "false", + "tls.client.certificate.bound.access.tokens": "false", + "saml.authnstatement": "false", + "display.on.consent.screen": "false", + "saml.onetimeuse.condition": "false" + }, + "authenticationFlowBindingOverrides": {}, + "fullScopeAllowed": false, + "nodeReRegistrationTimeout": -1, + "protocolMappers": [ + { + "id": "1543d277-d4f0-4498-89a3-8fe488eb8d87", + "name": "audience resolve", + "protocol": "openid-connect", + "protocolMapper": "oidc-audience-resolve-mapper", + "consentRequired": false, + "config": {} + }, + { + "id": "4ca1806c-d230-40e4-8aeb-7be48ec9a1ef", + "name": "Client ID", + "protocol": "openid-connect", + "protocolMapper": "oidc-usersessionmodel-note-mapper", + "consentRequired": false, + "config": { + "user.session.note": "clientId", + "userinfo.token.claim": "true", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "clientId", + "jsonType.label": "String" + } + }, + { + "id": "ec94a143-2a78-4275-a4fc-aa246c1c6628", + "name": "Client Host", + "protocol": "openid-connect", + "protocolMapper": "oidc-usersessionmodel-note-mapper", + "consentRequired": false, + "config": { + "user.session.note": "clientHost", + "userinfo.token.claim": "true", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "clientHost", + "jsonType.label": "String" + } + }, + { + "id": "f7258787-d1d7-4a41-82c6-8e9e00008b27", + "name": "Client IP Address", + "protocol": "openid-connect", + "protocolMapper": "oidc-usersessionmodel-note-mapper", + "consentRequired": false, + "config": { + "user.session.note": "clientAddress", + "userinfo.token.claim": "true", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "clientAddress", + "jsonType.label": "String" + } + } + ], + "defaultClientScopes": [ + "trust", + "web-origins", + "role_list", + "roles", + "profile", + "email" + ], + "optionalClientScopes": [ + "address", + "phone", + "offline_access", + "microprofile-jwt" + ] + }, { "id": "6a4bfbd0-576d-4778-af56-56f876647355", "clientId": "realm-management", @@ -953,16 +1289,16 @@ "enabled": true, "alwaysDisplayInConsole": false, "clientAuthenticatorType": "client-secret", - "secret": "fae6f87e-5b66-435c-b5aa-fd42c7641604", + "secret": "**********", "redirectUris": [], "webOrigins": [], "notBefore": 0, - "bearerOnly": true, + "bearerOnly": false, "consentRequired": false, "standardFlowEnabled": true, "implicitFlowEnabled": false, "directAccessGrantsEnabled": false, - "serviceAccountsEnabled": false, + "serviceAccountsEnabled": true, "authorizationServicesEnabled": true, "publicClient": false, "frontchannelLogout": false, @@ -971,6 +1307,53 @@ "authenticationFlowBindingOverrides": {}, "fullScopeAllowed": false, "nodeReRegistrationTimeout": 0, + "protocolMappers": [ + { + "id": "14ccedf9-e008-4fe5-901a-98663b937712", + "name": "Client Host", + "protocol": "openid-connect", + "protocolMapper": "oidc-usersessionmodel-note-mapper", + "consentRequired": false, + "config": { + "user.session.note": "clientHost", + "userinfo.token.claim": "true", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "clientHost", + "jsonType.label": "String" + } + }, + { + "id": "f82db182-9fba-4ffe-8138-65060d603dba", + "name": "Client ID", + "protocol": "openid-connect", + "protocolMapper": "oidc-usersessionmodel-note-mapper", + "consentRequired": false, + "config": { + "user.session.note": "clientId", + "userinfo.token.claim": "true", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "clientId", + "jsonType.label": "String" + } + }, + { + "id": "0f723243-8327-4640-861a-ee940cd18de9", + "name": "Client IP Address", + "protocol": "openid-connect", + "protocolMapper": "oidc-usersessionmodel-note-mapper", + "consentRequired": false, + "config": { + "user.session.note": "clientAddress", + "userinfo.token.claim": "true", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "clientAddress", + "jsonType.label": "String" + } + } + ], "defaultClientScopes": [ "web-origins", "role_list", @@ -1351,6 +1734,18 @@ { "id": "79856db3-1217-4f57-a5ce-61cbeb4867ca", "name": "manage-group-membership" + }, + { + "id": "3c1ee858-b6c7-43b5-9917-7dbf3302c276", + "name": "map-role" + }, + { + "id": "8fdfb34e-2c0b-4c12-bb77-cc9497890a86", + "name": "map-role-client-scope" + }, + { + "id": "afe4e610-835a-4f95-a270-0fb2fdd275c4", + "name": "map-role-composite" } ], "decisionStrategy": "UNANIMOUS" @@ -1366,7 +1761,7 @@ "enabled": true, "alwaysDisplayInConsole": false, "clientAuthenticatorType": "client-secret", - "secret": "fae6f87e-5b66-435c-b5aa-fd42c7641604", + "secret": "**********", "redirectUris": [ "/admin/opex/console/*" ], @@ -1435,9 +1830,174 @@ "offline_access", "microprofile-jwt" ] + }, + { + "id": "991d178f-2fd7-4f31-abf0-9ae8e97d7475", + "clientId": "web-app", + "name": "${client_web-app}", + "surrogateAuthRequired": false, + "enabled": true, + "alwaysDisplayInConsole": false, + "clientAuthenticatorType": "client-secret", + "secret": "**********", + "redirectUris": [ + "*" + ], + "webOrigins": [ + "*" + ], + "notBefore": 0, + "bearerOnly": false, + "consentRequired": false, + "standardFlowEnabled": false, + "implicitFlowEnabled": false, + "directAccessGrantsEnabled": true, + "serviceAccountsEnabled": true, + "publicClient": false, + "frontchannelLogout": false, + "protocol": "openid-connect", + "attributes": { + "saml.assertion.signature": "false", + "access.token.lifespan": "86400", + "saml.multivalued.roles": "false", + "saml.force.post.binding": "false", + "saml.encrypt": "false", + "backchannel.logout.revoke.offline.tokens": "false", + "saml.server.signature": "false", + "saml.server.signature.keyinfo.ext": "false", + "exclude.session.state.from.auth.response": "false", + "backchannel.logout.session.required": "false", + "client_credentials.use_refresh_token": "false", + "saml_force_name_id_format": "false", + "saml.client.signature": "false", + "tls.client.certificate.bound.access.tokens": "false", + "saml.authnstatement": "false", + "display.on.consent.screen": "false", + "saml.onetimeuse.condition": "false" + }, + "authenticationFlowBindingOverrides": {}, + "fullScopeAllowed": false, + "nodeReRegistrationTimeout": -1, + "protocolMappers": [ + { + "id": "2795ec8f-b7f7-4a7e-8f1c-e95e8faa2c95", + "name": "Client Host", + "protocol": "openid-connect", + "protocolMapper": "oidc-usersessionmodel-note-mapper", + "consentRequired": false, + "config": { + "user.session.note": "clientHost", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "clientHost", + "jsonType.label": "String" + } + }, + { + "id": "7bc922d8-f6e9-44d3-9b5f-2f4c92a98611", + "name": "Client IP Address", + "protocol": "openid-connect", + "protocolMapper": "oidc-usersessionmodel-note-mapper", + "consentRequired": false, + "config": { + "user.session.note": "clientAddress", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "clientAddress", + "jsonType.label": "String" + } + }, + { + "id": "9a2addac-3651-4579-9ecd-06ba41d2f8ba", + "name": "Client ID", + "protocol": "openid-connect", + "protocolMapper": "oidc-usersessionmodel-note-mapper", + "consentRequired": false, + "config": { + "user.session.note": "clientId", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "clientId", + "jsonType.label": "String" + } + } + ], + "defaultClientScopes": [ + "trust", + "web-origins", + "role_list", + "roles", + "profile", + "email" + ], + "optionalClientScopes": [ + "ipg", + "address", + "phone", + "offline_access", + "microprofile-jwt" + ] } ], "clientScopes": [ + { + "id": "411c3e3b-b6ef-4c8d-9c62-6331d7d37bc4", + "name": "ipg", + "description": "IPG scope", + "protocol": "openid-connect", + "attributes": { + "include.in.token.scope": "true", + "display.on.consent.screen": "true" + }, + "protocolMappers": [ + { + "id": "a8f6b8c3-5956-48a1-9875-ae7552bf8830", + "name": "national-code", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-attribute-mapper", + "consentRequired": false, + "config": { + "userinfo.token.claim": "true", + "user.attribute": "nationalID", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "national_code", + "jsonType.label": "String" + } + }, + { + "id": "b37503b8-80c3-45da-b075-a127281b1486", + "name": "bank-card", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-attribute-mapper", + "consentRequired": false, + "config": { + "userinfo.token.claim": "true", + "multivalued": "false", + "user.attribute": "card-number", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "bank_card", + "jsonType.label": "String" + } + }, + { + "id": "e198cc21-bc70-40ef-ae06-6b31ab1ec45a", + "name": "phone number", + "protocol": "openid-connect", + "protocolMapper": "oidc-usermodel-attribute-mapper", + "consentRequired": false, + "config": { + "userinfo.token.claim": "true", + "user.attribute": "phoneNumber", + "id.token.claim": "true", + "access.token.claim": "true", + "claim.name": "phone_number", + "jsonType.label": "String" + } + } + ] + }, { "id": "77c7e29d-1a22-4419-bbfb-4a62bb033449", "name": "address", @@ -1974,7 +2534,7 @@ "strictTransportSecurity": "max-age=31536000; includeSubDomains" }, "smtpServer": { - "password": "642467973026C6F093FB1E39C4BFC0D15042", + "password": "${vault.smtppass}", "auth": "true", "port": "2525", "host": "smtp.elasticemail.com", @@ -2063,14 +2623,14 @@ "subComponents": {}, "config": { "allowed-protocol-mapper-types": [ - "saml-user-property-mapper", - "oidc-full-name-mapper", - "saml-role-list-mapper", - "saml-user-attribute-mapper", - "oidc-address-mapper", + "oidc-usermodel-property-mapper", "oidc-usermodel-attribute-mapper", "oidc-sha256-pairwise-sub-mapper", - "oidc-usermodel-property-mapper" + "saml-user-attribute-mapper", + "saml-user-property-mapper", + "saml-role-list-mapper", + "oidc-full-name-mapper", + "oidc-address-mapper" ] } }, @@ -2090,14 +2650,14 @@ "subComponents": {}, "config": { "allowed-protocol-mapper-types": [ + "saml-user-property-mapper", + "oidc-address-mapper", "oidc-sha256-pairwise-sub-mapper", + "oidc-usermodel-property-mapper", "oidc-full-name-mapper", "oidc-usermodel-attribute-mapper", "saml-role-list-mapper", - "saml-user-attribute-mapper", - "oidc-address-mapper", - "oidc-usermodel-property-mapper", - "saml-user-property-mapper" + "saml-user-attribute-mapper" ] } } @@ -2145,7 +2705,7 @@ "supportedLocales": [], "authenticationFlows": [ { - "id": "eb8e6043-debc-4176-be88-31517d27aea1", + "id": "3e12576c-0b03-48b7-aaae-7ab0c4cb12f0", "alias": "Handle Existing Account", "description": "Handle what to do if there is existing account with same email/username like authenticated identity provider", "providerId": "basic-flow", @@ -2169,7 +2729,7 @@ ] }, { - "id": "1e16fd42-310c-4d33-9b7b-5fa88750d3f0", + "id": "7e8c7ced-44fa-4e17-aad8-8885dfa08e58", "alias": "Handle Existing Account - Alternatives - 0", "description": "Subflow of Handle Existing Account with alternative executions", "providerId": "basic-flow", @@ -2193,7 +2753,7 @@ ] }, { - "id": "59da038e-f925-4bf4-8a27-d76d56863086", + "id": "33aa9360-de0a-4ee5-9b6b-47e147b278a4", "alias": "Verify Existing Account by Re-authentication", "description": "Reauthentication of existing account", "providerId": "basic-flow", @@ -2217,7 +2777,7 @@ ] }, { - "id": "0c99cecc-8265-4246-a8fe-b5e213bf4e7f", + "id": "52598267-c3d0-4a1c-a5b9-29f08be7c4ad", "alias": "Verify Existing Account by Re-authentication - auth-otp-form - Conditional", "description": "Flow to determine if the auth-otp-form authenticator should be used or not.", "providerId": "basic-flow", @@ -2241,7 +2801,7 @@ ] }, { - "id": "6d062c21-4aca-41c9-9412-3ad172f436e2", + "id": "0cbc122b-febb-475b-a2f7-d82640760356", "alias": "browser", "description": "browser based authentication", "providerId": "basic-flow", @@ -2279,7 +2839,7 @@ ] }, { - "id": "6fa3e563-116e-4a06-b190-8ee74ba02bed", + "id": "ac7ea42f-841e-4ffb-b1f2-068a59802bf9", "alias": "clients", "description": "Base authentication for clients", "providerId": "client-flow", @@ -2317,7 +2877,7 @@ ] }, { - "id": "10a001de-9ae4-4c9a-9704-5396974b9e40", + "id": "de7fc6df-dacb-4b70-84f9-c69782286465", "alias": "direct grant", "description": "OpenID Connect Resource Owner Grant", "providerId": "basic-flow", @@ -2348,7 +2908,7 @@ ] }, { - "id": "ebb6a33e-99cc-4a50-8745-754adb3bfdfc", + "id": "54090557-650d-4884-93c8-52798b4bf27a", "alias": "direct grant - direct-grant-validate-otp - Conditional", "description": "Flow to determine if the direct-grant-validate-otp authenticator should be used or not.", "providerId": "basic-flow", @@ -2372,7 +2932,7 @@ ] }, { - "id": "1d9bcbd9-606d-499f-99f2-8bbc7db198ab", + "id": "3fec75f5-c0e8-40df-a37a-b0c741fcdd57", "alias": "docker auth", "description": "Used by Docker clients to authenticate against the IDP", "providerId": "basic-flow", @@ -2389,7 +2949,7 @@ ] }, { - "id": "67092d1f-0afb-4a5c-ab88-ad90cf9c33ae", + "id": "121573b7-e1d5-498e-bfd7-c46fde0f347a", "alias": "first broker login", "description": "Actions taken after first broker login with identity provider account, which is not yet linked to any Keycloak account", "providerId": "basic-flow", @@ -2414,7 +2974,7 @@ ] }, { - "id": "074f1df7-c555-4e41-99c7-cc0a56933f8a", + "id": "e3fc1203-b4d2-4b21-9294-9a30e9429d58", "alias": "first broker login - Alternatives - 0", "description": "Subflow of first broker login with alternative executions", "providerId": "basic-flow", @@ -2439,7 +2999,7 @@ ] }, { - "id": "fd40bca4-f31f-4d2b-9a5a-947e547917b6", + "id": "a6d1e8b2-ad8c-4387-b2cc-6f9252d3e1c4", "alias": "forms", "description": "Username, password, otp and other auth forms.", "providerId": "basic-flow", @@ -2463,7 +3023,7 @@ ] }, { - "id": "75b0e3fa-1fd5-48f6-9cb1-6a22785c7bd1", + "id": "a13840ea-7259-4ef9-9206-3848791ad17d", "alias": "forms - auth-otp-form - Conditional", "description": "Flow to determine if the auth-otp-form authenticator should be used or not.", "providerId": "basic-flow", @@ -2487,7 +3047,7 @@ ] }, { - "id": "03b9560e-7b0c-4804-b656-30d9079e95af", + "id": "1927c1df-bb74-4061-9349-27870f173f86", "alias": "http challenge", "description": "An authentication flow based on challenge-response HTTP Authentication Schemes", "providerId": "basic-flow", @@ -2525,7 +3085,7 @@ ] }, { - "id": "30845835-0272-4aba-afc2-30526f3a60e5", + "id": "3fdf2297-5a26-4166-9c28-7e0a259dc297", "alias": "registration", "description": "registration flow", "providerId": "basic-flow", @@ -2543,7 +3103,7 @@ ] }, { - "id": "c26b49a8-350d-4305-933c-22a97b707290", + "id": "fa5cd56a-b3da-47cb-b45b-1a42bf4315b0", "alias": "registration form", "description": "registration form", "providerId": "form-flow", @@ -2581,7 +3141,7 @@ ] }, { - "id": "2b31a58a-6269-4dcd-a43f-dc24f7050d0e", + "id": "bb41ce37-569e-429f-adce-d499d6d7b9f2", "alias": "reset credentials", "description": "Reset credentials for a user if they forgot their password or something", "providerId": "basic-flow", @@ -2619,7 +3179,7 @@ ] }, { - "id": "2b813ce7-3c11-4691-b425-9600638b36be", + "id": "a780f161-e80e-4181-a753-34a3de1c37bf", "alias": "reset credentials - reset-otp - Conditional", "description": "Flow to determine if the reset-otp authenticator should be used or not.", "providerId": "basic-flow", @@ -2643,7 +3203,7 @@ ] }, { - "id": "48c065af-38c4-41e3-aa5b-695d396ec529", + "id": "b5d18f36-d638-4ee2-b5f9-b33ae562c94b", "alias": "saml ecp", "description": "SAML ECP Profile Authentication Flow", "providerId": "basic-flow", @@ -2662,14 +3222,14 @@ ], "authenticatorConfig": [ { - "id": "b7f1f8b6-87ff-49f9-b4ae-0a9a59fa0e1d", + "id": "0127740a-f965-47d3-964d-a2454d3bf45c", "alias": "create unique user config", "config": { "require.password.update.after.registration": "false" } }, { - "id": "f4f89751-ae4b-4e1f-8722-70ac4e07ff72", + "id": "003b7330-d1c0-47f1-9b05-276e8a020cbe", "alias": "review profile config", "config": { "update.profile.on.first.login": "missing" diff --git a/user-management/pom.xml b/user-management/pom.xml index 9e4906fdf..42c810b3a 100644 --- a/user-management/pom.xml +++ b/user-management/pom.xml @@ -9,6 +9,11 @@ 1.0-SNAPSHOT + + 2.4.5 + 2020.0.3 + + co.nilin.opex.auth user-management user-management @@ -25,4 +30,15 @@ spring-boot-starter-test + + + + + co.nilin.opex.utility.error + error-handler + ${project.version} + + + + diff --git a/utility/error-handler/src/main/kotlin/co/nilin/opex/utility/error/data/OpexError.kt b/utility/error-handler/src/main/kotlin/co/nilin/opex/utility/error/data/OpexError.kt index 1372ad8fe..abcfdc46f 100644 --- a/utility/error-handler/src/main/kotlin/co/nilin/opex/utility/error/data/OpexError.kt +++ b/utility/error-handler/src/main/kotlin/co/nilin/opex/utility/error/data/OpexError.kt @@ -23,6 +23,7 @@ enum class OpexError(val code: Int, val message: String?, val status: HttpStatus SubmitOrderForbiddenByAccountant(4001, null, HttpStatus.BAD_REQUEST), // code 5000: user-management + EmailAlreadyVerified(5001, "Email is already verified", HttpStatus.BAD_REQUEST), // code 6000: wallet WalletOwnerNotFound(6001, null, HttpStatus.NOT_FOUND), diff --git a/wallet/wallet-app/Dockerfile b/wallet/wallet-app/Dockerfile index f2cbd4c26..7c71f9447 100644 --- a/wallet/wallet-app/Dockerfile +++ b/wallet/wallet-app/Dockerfile @@ -1,5 +1,4 @@ -FROM openjdk:8-jdk-alpine -VOLUME /tmp +FROM openjdk:11 ARG JAR_FILE=target/*.jar COPY ${JAR_FILE} app.jar ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -jar /app.jar"] \ No newline at end of file diff --git a/wallet/wallet-app/mvnw b/wallet/wallet-app/mvnw deleted file mode 100644 index a16b5431b..000000000 --- a/wallet/wallet-app/mvnw +++ /dev/null @@ -1,310 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` - fi - - if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=`cygpath --path --windows "$javaClass"` - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/wallet/wallet-app/mvnw.cmd b/wallet/wallet-app/mvnw.cmd deleted file mode 100644 index c8d43372c..000000000 --- a/wallet/wallet-app/mvnw.cmd +++ /dev/null @@ -1,182 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/wallet/wallet-app/pom.xml b/wallet/wallet-app/pom.xml index d0e6d1f50..15350d553 100644 --- a/wallet/wallet-app/pom.xml +++ b/wallet/wallet-app/pom.xml @@ -14,12 +14,6 @@ wallet-app Wallet management app of Opex - - 1.8 - 1.4.31 - 2020.0.2 - - org.springframework.boot @@ -100,6 +94,15 @@ co.nilin.opex.utility.interceptors interceptors + + net.minidev + json-smart + 2.4.7 + + + org.springframework.cloud + spring-cloud-starter-vault-config + diff --git a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt new file mode 100644 index 000000000..e9efaf92a --- /dev/null +++ b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt @@ -0,0 +1,9 @@ +package co.nilin.opex.util.vault + +import org.springframework.vault.authentication.AppIdUserIdMechanism + +class VaultUserIdMechanism() : AppIdUserIdMechanism { + override fun createUserId(): String { + return System.getenv("BACKEND_USER") + } +} \ No newline at end of file diff --git a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SecurityConfig.kt b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SecurityConfig.kt index a92bc17ab..d5f49240a 100644 --- a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SecurityConfig.kt +++ b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SecurityConfig.kt @@ -1,5 +1,6 @@ package co.nilin.opex.wallet.app.config +import co.nilin.opex.wallet.app.utils.hasRealmRole import net.minidev.json.JSONArray import org.springframework.beans.factory.annotation.Value import org.springframework.context.annotation.Bean @@ -28,15 +29,7 @@ class SecurityConfig(private val webClient: WebClient) { .pathMatchers("/withdraw").hasAuthority("SCOPE_trust") .pathMatchers("/withdraw/**").hasAuthority("SCOPE_trust") .pathMatchers("/transaction/**").hasAuthority("SCOPE_trust") - .pathMatchers("/admin/**").access { mono, authorizationContext -> - mono.map { auth -> - auth.authorities.any { authority -> authority.authority == "SCOPE_trust" } - && ((auth.principal as Jwt) - .claims.get("groups") as JSONArray).contains("finance-admin") - }.map { granted -> - AuthorizationDecision(granted) - } - } + .pathMatchers("/admin/**").hasRealmRole("SCOPE_trust","finance-admin") .pathMatchers("/payment/internal/**").permitAll() .pathMatchers("/**").permitAll() .anyExchange().authenticated() diff --git a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/utils/Extensions.kt b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/utils/Extensions.kt new file mode 100644 index 000000000..31218d1dd --- /dev/null +++ b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/utils/Extensions.kt @@ -0,0 +1,19 @@ +package co.nilin.opex.wallet.app.utils + +import com.nimbusds.jose.shaded.json.JSONArray +import com.nimbusds.jose.shaded.json.JSONObject +import org.springframework.security.authorization.AuthorizationDecision +import org.springframework.security.config.web.server.ServerHttpSecurity +import org.springframework.security.oauth2.jwt.Jwt + +fun ServerHttpSecurity.AuthorizeExchangeSpec.Access.hasRealmRole( + authority: String, + role: String +): ServerHttpSecurity.AuthorizeExchangeSpec = access { mono, _ -> + mono.map { auth -> + auth.authorities.any { it.authority == authority } + && (((auth.principal as Jwt).claims["realm_access"] as JSONObject)["roles"] as JSONArray).contains(role) + }.map { granted -> + AuthorizationDecision(granted) + } +} \ No newline at end of file diff --git a/wallet/wallet-app/src/main/resources/application-docker.yml b/wallet/wallet-app/src/main/resources/application-docker.yml deleted file mode 100644 index 72129f214..000000000 --- a/wallet/wallet-app/src/main/resources/application-docker.yml +++ /dev/null @@ -1,18 +0,0 @@ -server.port: 8091 -spring: - application: - name: opex-wallet - kafka: - bootstrap-servers: ${KAFKA_IP_PORT} - redis: - host: ${REDIS_HOST} - port: 6379 - r2dbc: - url: r2dbc:postgresql://${DB_IP_PORT}/opex_wallet - username: opex - password: hiopex - initialization-mode: always - cloud: - consul: - host: ${CONSUL_HOST} - port: 8500 diff --git a/wallet/wallet-app/src/main/resources/application.yml b/wallet/wallet-app/src/main/resources/application.yml index 4fba204a6..ac2eff360 100644 --- a/wallet/wallet-app/src/main/resources/application.yml +++ b/wallet/wallet-app/src/main/resources/application.yml @@ -1,31 +1,48 @@ -server.port: 8091 +server.port: 8080 spring: application: name: opex-wallet main: allow-bean-definition-overriding: false + allow-circular-references: true kafka: - bootstrap-servers: localhost:2181 + bootstrap-servers: ${KAFKA_IP_PORT:localhost:9092} consumer: group-id: wallet redis: - host: 127.0.0.1 + host: ${REDIS_HOST:localhost} port: 6379 r2dbc: - url: r2dbc:postgresql://localhost/opex_wallet - username: opex - password: hiopex + url: r2dbc:postgresql://${DB_IP_PORT:localhost}/opex_wallet + username: ${dbusername:opex} + password: ${dbpassword:hiopex} initialization-mode: always cloud: bootstrap: enabled: true + vault: + host: ${VAULT_HOST} + port: 8200 + scheme: http + authentication: APPID + app-id: + user-id: co.nilin.opex.util.vault.VaultUserIdMechanism + fail-fast: true + kv: + enabled: true + backend: secret + profile-separator: '/' + application-name: ${spring.application.name} consul: + host: ${CONSUL_HOST:localhost} port: 8500 discovery: #healthCheckPath: ${management.context-path}/health instance-id: ${spring.application.name}:${server.port} healthCheckInterval: 20s prefer-ip-address: true + config: + import: vault://secret/${spring.application.name} app: gift: symbol: usdt diff --git a/wallet/wallet-core/mvnw b/wallet/wallet-core/mvnw deleted file mode 100644 index a16b5431b..000000000 --- a/wallet/wallet-core/mvnw +++ /dev/null @@ -1,310 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` - fi - - if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=`cygpath --path --windows "$javaClass"` - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/wallet/wallet-core/mvnw.cmd b/wallet/wallet-core/mvnw.cmd deleted file mode 100644 index c8d43372c..000000000 --- a/wallet/wallet-core/mvnw.cmd +++ /dev/null @@ -1,182 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/wallet/wallet-ports/wallet-eventlistener-kafka/mvnw b/wallet/wallet-ports/wallet-eventlistener-kafka/mvnw deleted file mode 100644 index a16b5431b..000000000 --- a/wallet/wallet-ports/wallet-eventlistener-kafka/mvnw +++ /dev/null @@ -1,310 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` - fi - - if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=`cygpath --path --windows "$javaClass"` - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/wallet/wallet-ports/wallet-eventlistener-kafka/mvnw.cmd b/wallet/wallet-ports/wallet-eventlistener-kafka/mvnw.cmd deleted file mode 100644 index c8d43372c..000000000 --- a/wallet/wallet-ports/wallet-eventlistener-kafka/mvnw.cmd +++ /dev/null @@ -1,182 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/wallet/wallet-ports/wallet-eventlistener-kafka/src/main/kotlin/co/nilin/opex/wallet/ports/kafka/listener/config/WalletKafkaConfig.kt b/wallet/wallet-ports/wallet-eventlistener-kafka/src/main/kotlin/co/nilin/opex/wallet/ports/kafka/listener/config/WalletKafkaConfig.kt index 39d363755..96e5e0e46 100644 --- a/wallet/wallet-ports/wallet-eventlistener-kafka/src/main/kotlin/co/nilin/opex/wallet/ports/kafka/listener/config/WalletKafkaConfig.kt +++ b/wallet/wallet-ports/wallet-eventlistener-kafka/src/main/kotlin/co/nilin/opex/wallet/ports/kafka/listener/config/WalletKafkaConfig.kt @@ -14,15 +14,18 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration import org.springframework.context.support.GenericApplicationContext +import org.springframework.kafka.config.TopicBuilder import org.springframework.kafka.core.* import org.springframework.kafka.listener.ConcurrentMessageListenerContainer import org.springframework.kafka.listener.ContainerProperties import org.springframework.kafka.support.serializer.JsonDeserializer import org.springframework.kafka.support.serializer.JsonSerializer +import java.util.function.Supplier import java.util.regex.Pattern @Configuration class WalletKafkaConfig { + @Value("\${spring.kafka.bootstrap-servers}") private val bootstrapServers: String? = null @@ -30,15 +33,15 @@ class WalletKafkaConfig { private val groupId: String? = null @Bean("walletConsumerConfig") - fun consumerConfigs(): Map? { - val props: MutableMap = HashMap() - props[ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG] = bootstrapServers - props[ConsumerConfig.GROUP_ID_CONFIG] = groupId - props[ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG] = StringDeserializer::class.java - props[ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG] = JsonDeserializer::class.java - props[JsonDeserializer.TRUSTED_PACKAGES] = "co.nilin.opex.*" - props[JsonDeserializer.TYPE_MAPPINGS] = "user_created_event:co.nilin.opex.wallet.ports.kafka.listener.model.UserCreatedEvent" - return props + fun consumerConfigs(): Map { + return mapOf( + ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG to bootstrapServers, + ConsumerConfig.GROUP_ID_CONFIG to groupId, + ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG to StringDeserializer::class.java, + ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG to JsonDeserializer::class.java, + JsonDeserializer.TRUSTED_PACKAGES to "co.nilin.opex.*", + JsonDeserializer.TYPE_MAPPINGS to "user_created_event:co.nilin.opex.wallet.ports.kafka.listener.model.UserCreatedEvent" + ) } @Bean("walletConsumerFactory") @@ -48,11 +51,12 @@ class WalletKafkaConfig { @Bean("walletProducerConfig") fun producerConfigs(): Map { - val props: MutableMap = HashMap() - props[ProducerConfig.BOOTSTRAP_SERVERS_CONFIG] = bootstrapServers - props[ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG] = StringSerializer::class.java - props[ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG] = JsonSerializer::class.java - return props + return mapOf( + ProducerConfig.BOOTSTRAP_SERVERS_CONFIG to bootstrapServers, + ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG to StringSerializer::class.java, + ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG to JsonSerializer::class.java, + ProducerConfig.ACKS_CONFIG to "all" + ) } @Bean("walletProducerFactory") @@ -65,7 +69,6 @@ class WalletKafkaConfig { return KafkaTemplate(producerFactory) } - @Autowired @ConditionalOnBean(UserCreatedKafkaListener::class) fun configureUserCreatedListener( @@ -79,10 +82,14 @@ class WalletKafkaConfig { container.start() } - @Autowired fun createUserCreatedTopics(applicationContext: GenericApplicationContext) { - applicationContext.registerBean("topic_auth_user_created", NewTopic::class.java, "auth_user_created", 1, 1) + applicationContext.registerBean("topic_auth_user_created", NewTopic::class.java, Supplier { + TopicBuilder.name("auth_user_created") + .partitions(1) + .replicas(1) + .build() + }) } } \ No newline at end of file diff --git a/wallet/wallet-ports/wallet-persister-postgres/mvnw b/wallet/wallet-ports/wallet-persister-postgres/mvnw deleted file mode 100644 index a16b5431b..000000000 --- a/wallet/wallet-ports/wallet-persister-postgres/mvnw +++ /dev/null @@ -1,310 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` - fi - - if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=`cygpath --path --windows "$javaClass"` - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/wallet/wallet-ports/wallet-persister-postgres/mvnw.cmd b/wallet/wallet-ports/wallet-persister-postgres/mvnw.cmd deleted file mode 100644 index c8d43372c..000000000 --- a/wallet/wallet-ports/wallet-persister-postgres/mvnw.cmd +++ /dev/null @@ -1,182 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/data.sql b/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/data.sql index f02aa8e08..cf1b991e3 100644 --- a/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/data.sql +++ b/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/data.sql @@ -1,55 +1,48 @@ -INSERT INTO - wallet_owner(id, uuid, title, level) -VALUES - (1, '1', 'system', 'basic') ON CONFLICT DO NOTHING; +INSERT INTO wallet_owner(id, uuid, title, level) +VALUES (1, '1', 'system', 'basic') +ON CONFLICT DO NOTHING; SELECT setval(pg_get_serial_sequence('wallet_owner', 'id'), (SELECT MAX(id) FROM wallet_owner)); -INSERT INTO - currency(name, symbol, precision) -VALUES - ('btc', 'btc', 0.000001), - ('eth', 'eth', 0.00001), - ('usdt', 'usdt', 0.01), - ('nln', 'nln', 1) ON CONFLICT DO NOTHING; - -INSERT INTO - currency_rate(id, source_currency, dest_currency, rate) -VALUES - (1, 'btc', 'nln', 5500000), - (2, 'usdt', 'nln', 100), - (3, 'btc', 'usdt', 55000), - (4, 'eth', 'usdt', 3800) ON CONFLICT DO NOTHING; +INSERT INTO currency(name, symbol, precision) +VALUES ('btc', 'btc', 0.000001), + ('eth', 'eth', 0.00001), + ('usdt', 'usdt', 0.01), + ('nln', 'nln', 1) +ON CONFLICT DO NOTHING; + +INSERT INTO currency_rate(id, source_currency, dest_currency, rate) +VALUES (1, 'btc', 'nln', 5500000), + (2, 'usdt', 'nln', 100), + (3, 'btc', 'usdt', 55000), + (4, 'eth', 'usdt', 3800) +ON CONFLICT DO NOTHING; SELECT setval(pg_get_serial_sequence('currency_rate', 'id'), (SELECT MAX(id) FROM currency_rate)); -INSERT INTO - wallet(id, owner, wallet_type, currency, balance) -VALUES - (1, 1, 'main', 'btc', 10), - (2, 1, 'exchange', 'btc', 0), - (3, 1, 'main', 'usdt', 550000), - (4, 1, 'exchange', 'usdt', 0), - (5, 1, 'main', 'nln', 100000000), - (6, 1, 'exchange', 'nln', 0), - (7, 1, 'main', 'eth', 10000), - (8, 1, 'exchange', 'eth', 0) ON CONFLICT DO NOTHING; +INSERT INTO wallet(id, owner, wallet_type, currency, balance) +VALUES (1, 1, 'main', 'btc', 10), + (2, 1, 'exchange', 'btc', 0), + (3, 1, 'main', 'usdt', 550000), + (4, 1, 'exchange', 'usdt', 0), + (5, 1, 'main', 'nln', 100000000), + (6, 1, 'exchange', 'nln', 0), + (7, 1, 'main', 'eth', 10000), + (8, 1, 'exchange', 'eth', 0) +ON CONFLICT DO NOTHING; SELECT setval(pg_get_serial_sequence('wallet', 'id'), (SELECT MAX(id) FROM wallet)); -INSERT INTO - user_limits( - id, - level, - owner, - action, - wallet_type, - daily_total, - daily_count, - monthly_total, - monthly_count - ) -VALUES - (1, null, 1, 'withdraw', 'main', 1000, 100, 10000, 1000) ON CONFLICT DO NOTHING; +INSERT INTO user_limits(id, + level, + owner, + action, + wallet_type, + daily_total, + daily_count, + monthly_total, + monthly_count) +VALUES (1, null, 1, 'withdraw', 'main', 1000, 100, 10000, 1000) +ON CONFLICT DO NOTHING; SELECT setval(pg_get_serial_sequence('user_limits', 'id'), (SELECT MAX(id) FROM user_limits)); diff --git a/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/schema.sql b/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/schema.sql index a2750ca74..fd9462799 100644 --- a/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/schema.sql +++ b/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/schema.sql @@ -1,95 +1,104 @@ -CREATE TABLE IF NOT EXISTS currency ( - symbol VARCHAR(25) PRIMARY KEY, - name VARCHAR(25), - precision DECIMAL NOT NULL +CREATE TABLE IF NOT EXISTS currency +( + symbol VARCHAR(25) PRIMARY KEY, + name VARCHAR(25), + precision DECIMAL NOT NULL ); -CREATE TABLE IF NOT EXISTS currency_rate ( - id SERIAL PRIMARY KEY, - source_currency VARCHAR(25) NOT NULL REFERENCES currency (symbol), - dest_currency VARCHAR(25) NOT NULL REFERENCES currency (symbol), - rate DECIMAL NOT NULL, - UNIQUE(source_currency, dest_currency) +CREATE TABLE IF NOT EXISTS currency_rate +( + id SERIAL PRIMARY KEY, + source_currency VARCHAR(25) NOT NULL REFERENCES currency (symbol), + dest_currency VARCHAR(25) NOT NULL REFERENCES currency (symbol), + rate DECIMAL NOT NULL, + UNIQUE (source_currency, dest_currency) ); -CREATE TABLE IF NOT EXISTS wallet_owner ( - id SERIAL PRIMARY KEY, - uuid VARCHAR(36) NOT NULL UNIQUE, - title VARCHAR(70) NOT NULL, - level VARCHAR(10) NOT NULL, - trade_allowed BOOLEAN NOT NULL DEFAULT TRUE, - withdraw_allowed BOOLEAN NOT NULL DEFAULT TRUE, - deposit_allowed BOOLEAN NOT NULL DEFAULT TRUE +CREATE TABLE IF NOT EXISTS wallet_owner +( + id SERIAL PRIMARY KEY, + uuid VARCHAR(36) NOT NULL UNIQUE, + title VARCHAR(70) NOT NULL, + level VARCHAR(10) NOT NULL, + trade_allowed BOOLEAN NOT NULL DEFAULT TRUE, + withdraw_allowed BOOLEAN NOT NULL DEFAULT TRUE, + deposit_allowed BOOLEAN NOT NULL DEFAULT TRUE ); -CREATE TABLE IF NOT EXISTS wallet ( - id SERIAL PRIMARY KEY, - owner INTEGER NOT NULL REFERENCES wallet_owner (id), - wallet_type VARCHAR(10) NOT NULL, - currency VARCHAR(25) NOT NULL REFERENCES currency (symbol), - balance DECIMAL NOT NULL +CREATE TABLE IF NOT EXISTS wallet +( + id SERIAL PRIMARY KEY, + owner INTEGER NOT NULL REFERENCES wallet_owner (id), + wallet_type VARCHAR(10) NOT NULL, + currency VARCHAR(25) NOT NULL REFERENCES currency (symbol), + balance DECIMAL NOT NULL ); -CREATE TABLE IF NOT EXISTS transaction ( - id SERIAL PRIMARY KEY, - source_wallet INTEGER NOT NULL REFERENCES wallet (id), - dest_wallet INTEGER NOT NULL REFERENCES wallet (id), - source_amount DECIMAL NOT NULL, - dest_amount DECIMAL NOT NULL, - description TEXT, - transfer_ref TEXT UNIQUE, - transaction_date TIMESTAMP NOT NULL DEFAULT CURRENT_DATE +CREATE TABLE IF NOT EXISTS transaction +( + id SERIAL PRIMARY KEY, + source_wallet INTEGER NOT NULL REFERENCES wallet (id), + dest_wallet INTEGER NOT NULL REFERENCES wallet (id), + source_amount DECIMAL NOT NULL, + dest_amount DECIMAL NOT NULL, + description TEXT, + transfer_ref TEXT UNIQUE, + transaction_date TIMESTAMP NOT NULL DEFAULT CURRENT_DATE ); -CREATE TABLE IF NOT EXISTS user_limits ( - id SERIAL PRIMARY KEY, - level VARCHAR(10), - owner INTEGER REFERENCES wallet_owner (id), - action VARCHAR(25) NOT NULL, - wallet_type VARCHAR(10) NOT NULL, - daily_total DECIMAL, - daily_count INTEGER, - monthly_total DECIMAL, - monthly_count INTEGER +CREATE TABLE IF NOT EXISTS user_limits +( + id SERIAL PRIMARY KEY, + level VARCHAR(10), + owner INTEGER REFERENCES wallet_owner (id), + action VARCHAR(25) NOT NULL, + wallet_type VARCHAR(10) NOT NULL, + daily_total DECIMAL, + daily_count INTEGER, + monthly_total DECIMAL, + monthly_count INTEGER ); -CREATE TABLE IF NOT EXISTS wallet_limits ( - id SERIAL PRIMARY KEY, - level VARCHAR(10), - owner INTEGER REFERENCES wallet_owner (id), - action VARCHAR(25) NOT NULL, - currency VARCHAR(25) NOT NULL REFERENCES currency (symbol), - wallet_type VARCHAR(10) NOT NULL, - wallet_id INTEGER REFERENCES wallet (id), - daily_total DECIMAL, - daily_count INTEGER, - monthly_total DECIMAL, - monthly_count INTEGER +CREATE TABLE IF NOT EXISTS wallet_limits +( + id SERIAL PRIMARY KEY, + level VARCHAR(10), + owner INTEGER REFERENCES wallet_owner (id), + action VARCHAR(25) NOT NULL, + currency VARCHAR(25) NOT NULL REFERENCES currency (symbol), + wallet_type VARCHAR(10) NOT NULL, + wallet_id INTEGER REFERENCES wallet (id), + daily_total DECIMAL, + daily_count INTEGER, + monthly_total DECIMAL, + monthly_count INTEGER ); -CREATE TABLE IF NOT EXISTS wallet_config ( - name VARCHAR(20) PRIMARY KEY, - main_currency VARCHAR(25) NOT NULL REFERENCES currency (symbol) +CREATE TABLE IF NOT EXISTS wallet_config +( + name VARCHAR(20) PRIMARY KEY, + main_currency VARCHAR(25) NOT NULL REFERENCES currency (symbol) ); -CREATE TABLE IF NOT EXISTS withdraws ( - id SERIAL PRIMARY KEY, - uuid VARCHAR(36) NOT NULL, - req_transaction_id VARCHAR(20) NOT NULL UNIQUE, - final_transaction_id VARCHAR(20) UNIQUE, - wallet INTEGER REFERENCES wallet (id), - amount DECIMAL NOT NULL, - accepted_fee DECIMAL, - applied_fee DECIMAL, - dest_amount DECIMAL, - dest_currency VARCHAR(20) REFERENCES currency (symbol), - dest_network VARCHAR(20), - dest_address VARCHAR(80), - dest_notes TEXT, - dest_transaction_ref VARCHAR(100), - description TEXT, - status_reason TEXT, - status VARCHAR(20), - create_date TIMESTAMP NOT NULL, - accept_date TIMESTAMP +CREATE TABLE IF NOT EXISTS withdraws +( + id SERIAL PRIMARY KEY, + uuid VARCHAR(36) NOT NULL, + req_transaction_id VARCHAR(20) NOT NULL UNIQUE, + final_transaction_id VARCHAR(20) UNIQUE, + wallet INTEGER REFERENCES wallet (id), + amount DECIMAL NOT NULL, + accepted_fee DECIMAL, + applied_fee DECIMAL, + dest_amount DECIMAL, + dest_currency VARCHAR(20) REFERENCES currency (symbol), + dest_network VARCHAR(20), + dest_address VARCHAR(80), + dest_notes TEXT, + dest_transaction_ref VARCHAR(100), + description TEXT, + status_reason TEXT, + status VARCHAR(20), + create_date TIMESTAMP NOT NULL, + accept_date TIMESTAMP ); diff --git a/websocket/websocket-app/Dockerfile b/websocket/websocket-app/Dockerfile index f2cbd4c26..7c71f9447 100644 --- a/websocket/websocket-app/Dockerfile +++ b/websocket/websocket-app/Dockerfile @@ -1,5 +1,4 @@ -FROM openjdk:8-jdk-alpine -VOLUME /tmp +FROM openjdk:11 ARG JAR_FILE=target/*.jar COPY ${JAR_FILE} app.jar ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -jar /app.jar"] \ No newline at end of file diff --git a/websocket/websocket-app/pom.xml b/websocket/websocket-app/pom.xml index c0cc7950e..e64616340 100644 --- a/websocket/websocket-app/pom.xml +++ b/websocket/websocket-app/pom.xml @@ -14,10 +14,6 @@ websocket-app Websocket app - - 2020.0.2 - - org.springframework.boot @@ -75,6 +71,10 @@ co.nilin.opex.websocket.ports.postgres websocket-persister-postgres + + org.springframework.cloud + spring-cloud-starter-vault-config + io.projectreactor reactor-test diff --git a/websocket/websocket-app/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt b/websocket/websocket-app/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt new file mode 100644 index 000000000..e9efaf92a --- /dev/null +++ b/websocket/websocket-app/src/main/kotlin/co/nilin/opex/util/vault/VaultUserIdMechanism.kt @@ -0,0 +1,9 @@ +package co.nilin.opex.util.vault + +import org.springframework.vault.authentication.AppIdUserIdMechanism + +class VaultUserIdMechanism() : AppIdUserIdMechanism { + override fun createUserId(): String { + return System.getenv("BACKEND_USER") + } +} \ No newline at end of file diff --git a/websocket/websocket-app/src/main/kotlin/co/nilin/opex/websocket/app/dto/Interval.kt b/websocket/websocket-app/src/main/kotlin/co/nilin/opex/websocket/app/dto/Interval.kt index 8d22e7bc0..0b593dc54 100644 --- a/websocket/websocket-app/src/main/kotlin/co/nilin/opex/websocket/app/dto/Interval.kt +++ b/websocket/websocket-app/src/main/kotlin/co/nilin/opex/websocket/app/dto/Interval.kt @@ -24,7 +24,7 @@ enum class Interval(val label: String, val unit: TimeUnit, val duration: Long) { ThreeDays("3d", TimeUnit.DAYS, 3), Week("1w", TimeUnit.DAYS, 7), Month("1M", TimeUnit.DAYS, 31), - ThreeMonth("3M",TimeUnit.DAYS, 90); + ThreeMonth("3M", TimeUnit.DAYS, 90); private fun getOffsetTime() = unit.toMillis(duration) diff --git a/websocket/websocket-app/src/main/kotlin/co/nilin/opex/websocket/app/dto/OrderResponse.kt b/websocket/websocket-app/src/main/kotlin/co/nilin/opex/websocket/app/dto/OrderResponse.kt index d981e15f3..616123230 100644 --- a/websocket/websocket-app/src/main/kotlin/co/nilin/opex/websocket/app/dto/OrderResponse.kt +++ b/websocket/websocket-app/src/main/kotlin/co/nilin/opex/websocket/app/dto/OrderResponse.kt @@ -8,20 +8,19 @@ import java.math.BigDecimal import java.util.* data class OrderResponse( + val ouid: String, val symbol: String, val orderId: Long, - val orderListId: Long, //Unless part of an OCO, the value will always be -1. + val orderListId: Long, val clientOrderId: String?, val price: BigDecimal, val origQty: BigDecimal, val executedQty: BigDecimal, - val cummulativeQuoteQty: BigDecimal, - val status: OrderStatus, - val timeInForce: TimeInForce, - val type: OrderType, - val side: OrderSide, - val stopPrice: BigDecimal?, - val icebergQty: BigDecimal?, + val accumulativeQuoteQty: BigDecimal, + val status: OrderStatus?, + val timeInForce: TimeInForce?, + val type: OrderType?, + val side: OrderSide?, val time: Date, val updateTime: Date, val isWorking: Boolean, diff --git a/websocket/websocket-app/src/main/kotlin/co/nilin/opex/websocket/app/listener/WebSocketKafkaListener.kt b/websocket/websocket-app/src/main/kotlin/co/nilin/opex/websocket/app/listener/WebSocketKafkaListener.kt index 888f0c84a..2c0009928 100644 --- a/websocket/websocket-app/src/main/kotlin/co/nilin/opex/websocket/app/listener/WebSocketKafkaListener.kt +++ b/websocket/websocket-app/src/main/kotlin/co/nilin/opex/websocket/app/listener/WebSocketKafkaListener.kt @@ -1,10 +1,12 @@ package co.nilin.opex.websocket.app.listener import co.nilin.opex.accountant.core.inout.RichOrder +import co.nilin.opex.accountant.core.inout.RichOrderEvent +import co.nilin.opex.accountant.core.inout.RichOrderUpdate import co.nilin.opex.accountant.core.inout.RichTrade +import co.nilin.opex.websocket.core.spi.EventStreamHandler import co.nilin.opex.websocket.ports.kafka.listener.spi.RichOrderListener import co.nilin.opex.websocket.ports.kafka.listener.spi.RichTradeListener -import co.nilin.opex.websocket.core.spi.EventStreamHandler class WebSocketKafkaListener(private val handler: EventStreamHandler) : RichTradeListener, RichOrderListener { @@ -12,21 +14,14 @@ class WebSocketKafkaListener(private val handler: EventStreamHandler) : RichTrad return "WebSocketKafkaListener" } - override fun onTrade( - trade: RichTrade, - partition: Int, - offset: Long, - timestamp: Long - ) { + override fun onTrade(trade: RichTrade, partition: Int, offset: Long, timestamp: Long) { handler.handleTrade(trade) } - override fun onOrder( - order: RichOrder, - partition: Int, - offset: Long, - timestamp: Long - ) { - handler.handleOrder(order) + override fun onOrder(order: RichOrderEvent, partition: Int, offset: Long, timestamp: Long) { + when (order) { + is RichOrder -> handler.handleOrder(order) + is RichOrderUpdate -> handler.handleOrderUpdate(order) + } } } \ No newline at end of file diff --git a/websocket/websocket-app/src/main/kotlin/co/nilin/opex/websocket/app/service/EventStreamHandlerImpl.kt b/websocket/websocket-app/src/main/kotlin/co/nilin/opex/websocket/app/service/EventStreamHandlerImpl.kt index a2dce1cb1..a1e6c19a6 100644 --- a/websocket/websocket-app/src/main/kotlin/co/nilin/opex/websocket/app/service/EventStreamHandlerImpl.kt +++ b/websocket/websocket-app/src/main/kotlin/co/nilin/opex/websocket/app/service/EventStreamHandlerImpl.kt @@ -1,6 +1,7 @@ package co.nilin.opex.websocket.app.service import co.nilin.opex.accountant.core.inout.RichOrder +import co.nilin.opex.accountant.core.inout.RichOrderUpdate import co.nilin.opex.accountant.core.inout.RichTrade import co.nilin.opex.matching.engine.core.model.OrderDirection import co.nilin.opex.websocket.app.config.AppDispatchers @@ -27,6 +28,7 @@ class EventStreamHandlerImpl( override fun handleOrder(order: RichOrder) { val response = OrderResponse( + order.ouid, order.pair, order.orderId ?: -1, -1, @@ -39,8 +41,6 @@ class EventStreamHandlerImpl( order.constraint.toTimeInForce(), order.type.toWebsocketOrderType(), order.direction.toOrderSide(), - null, - null, Date(), Date(), order.status.toOrderStatus().isWorking(), @@ -49,6 +49,33 @@ class EventStreamHandlerImpl( run { template.convertAndSendToUser(order.uuid, EventDestinations.Order.path, response) } } + override fun handleOrderUpdate(orderUpdate: RichOrderUpdate) { + run { + val status = orderUpdate.status.code.toOrderStatus() + val order = orderRepository.findByOuid(orderUpdate.ouid).awaitFirstOrNull() ?: return@run + val response = OrderResponse( + order.ouid, + order.symbol, + order.orderId ?: -1, + -1, + null, + order.price?.toBigDecimal() ?: BigDecimal.ZERO, + orderUpdate.quantity, + orderUpdate.executedQuantity(), + orderUpdate.accumulativeQuoteQuantity(), + status, + order.constraint?.toTimeInForce(), + order.type?.toWebsocketOrderType(), + order.direction?.toOrderSide(), + Date(), + Date(), + status.isWorking(), + order.quoteQuantity?.toBigDecimal() ?: BigDecimal.ZERO + ) + template.convertAndSendToUser(order.uuid, EventDestinations.Order.path, response) + } + } + override fun handleTrade(trade: RichTrade) { run { val takerOrder = orderRepository.findByOuid(trade.takerOuid).awaitFirstOrNull() diff --git a/websocket/websocket-app/src/main/kotlin/co/nilin/opex/websocket/app/service/stream/IntervalStreamHandler.kt b/websocket/websocket-app/src/main/kotlin/co/nilin/opex/websocket/app/service/stream/IntervalStreamHandler.kt index 0a5e1a560..52379fac3 100644 --- a/websocket/websocket-app/src/main/kotlin/co/nilin/opex/websocket/app/service/stream/IntervalStreamHandler.kt +++ b/websocket/websocket-app/src/main/kotlin/co/nilin/opex/websocket/app/service/stream/IntervalStreamHandler.kt @@ -73,7 +73,7 @@ abstract class IntervalStreamHandler( val count = userRegistry.findSubscriptions { it.destination == getPath(j.key) }.count() val sJob = streamJobs[j.key] if (count == 0) { - if (sJob?.isRunAllowed == true){ + if (sJob?.isRunAllowed == true) { logger.info("No subscriber for ${j.key}. stopping task") sJob.isRunAllowed = false } diff --git a/websocket/websocket-app/src/main/kotlin/co/nilin/opex/websocket/app/utils/EnumExtensions.kt b/websocket/websocket-app/src/main/kotlin/co/nilin/opex/websocket/app/utils/EnumExtensions.kt index e4e13eb4f..227b0f44c 100644 --- a/websocket/websocket-app/src/main/kotlin/co/nilin/opex/websocket/app/utils/EnumExtensions.kt +++ b/websocket/websocket-app/src/main/kotlin/co/nilin/opex/websocket/app/utils/EnumExtensions.kt @@ -1,11 +1,11 @@ package co.nilin.opex.websocket.app.utils -import co.nilin.opex.websocket.core.inout.OrderSide -import co.nilin.opex.websocket.core.inout.OrderStatus -import co.nilin.opex.websocket.core.inout.TimeInForce import co.nilin.opex.matching.engine.core.model.MatchConstraint import co.nilin.opex.matching.engine.core.model.OrderDirection import co.nilin.opex.matching.engine.core.model.OrderType +import co.nilin.opex.websocket.core.inout.OrderSide +import co.nilin.opex.websocket.core.inout.OrderStatus +import co.nilin.opex.websocket.core.inout.TimeInForce fun MatchConstraint.toTimeInForce(): TimeInForce { if (this == MatchConstraint.FOK_BUDGET) diff --git a/websocket/websocket-app/src/main/resources/application-docker.yml b/websocket/websocket-app/src/main/resources/application-docker.yml deleted file mode 100644 index 81262acea..000000000 --- a/websocket/websocket-app/src/main/resources/application-docker.yml +++ /dev/null @@ -1,18 +0,0 @@ -spring: - kafka: - bootstrap-servers: ${KAFKA_IP_PORT} - redis: - host: ${REDIS_HOST} - r2dbc: - url: r2dbc:postgresql://${DB_IP_PORT}/opex_api - username: opex - password: hiopex - cloud: - consul: - host: ${CONSUL_HOST} - port: 8500 - main: - allow-bean-definition-overriding: true -app: - auth: - cert-url: http://auth:8083/auth/realms/opex/protocol/openid-connect/certs \ No newline at end of file diff --git a/websocket/websocket-app/src/main/resources/application.yml b/websocket/websocket-app/src/main/resources/application.yml index e7df088d6..fddd85018 100644 --- a/websocket/websocket-app/src/main/resources/application.yml +++ b/websocket/websocket-app/src/main/resources/application.yml @@ -1,28 +1,45 @@ server: - port: 8097 + port: 8080 spring: application: name: opex-websocket main: allow-bean-definition-overriding: false + allow-circular-references: true kafka: - bootstrap-servers: 192.168.178.29:9092 + bootstrap-servers: ${KAFKA_IP_PORT:localhost:9092} consumer: group-id: websocket r2dbc: - url: r2dbc:postgresql://localhost/opex_api - username: opex - password: hiopex + url: r2dbc:postgresql://${DB_IP_PORT:localhost}/opex_api + username: ${dbusername:opex} + password: ${dbpassword:hiopex} initialization-mode: always cloud: bootstrap: enabled: true + vault: + host: ${VAULT_HOST} + port: 8200 + scheme: http + authentication: APPID + app-id: + user-id: co.nilin.opex.util.vault.VaultUserIdMechanism + fail-fast: true + kv: + enabled: true + backend: secret + profile-separator: '/' + application-name: ${spring.application.name} consul: + host: ${CONSUL_HOST:localhost} port: 8500 discovery: instance-id: ${spring.application.name}:${server.port} healthCheckInterval: 20s prefer-ip-address: true + config: + import: vault://secret/${spring.application.name} app: auth: - cert-url: http://localhost:8083/auth/realms/opex/protocol/openid-connect/certs \ No newline at end of file + cert-url: http://auth:8080/auth/realms/opex/protocol/openid-connect/certs \ No newline at end of file diff --git a/websocket/websocket-core/src/main/kotlin/co/nilin/opex/websocket/core/spi/EventStreamHandler.kt b/websocket/websocket-core/src/main/kotlin/co/nilin/opex/websocket/core/spi/EventStreamHandler.kt index d4002ba70..b75e40f6e 100644 --- a/websocket/websocket-core/src/main/kotlin/co/nilin/opex/websocket/core/spi/EventStreamHandler.kt +++ b/websocket/websocket-core/src/main/kotlin/co/nilin/opex/websocket/core/spi/EventStreamHandler.kt @@ -1,12 +1,15 @@ package co.nilin.opex.websocket.core.spi import co.nilin.opex.accountant.core.inout.RichOrder +import co.nilin.opex.accountant.core.inout.RichOrderUpdate import co.nilin.opex.accountant.core.inout.RichTrade interface EventStreamHandler { fun handleOrder(order: RichOrder) + fun handleOrderUpdate(orderUpdate: RichOrderUpdate) + fun handleTrade(trade: RichTrade) } \ No newline at end of file diff --git a/websocket/websocket-ports/websocket-eventlistener-kafka/src/main/kotlin/co/nilin/opex/websocket/ports/kafka/listener/config/WebSocketKafkaConfig.kt b/websocket/websocket-ports/websocket-eventlistener-kafka/src/main/kotlin/co/nilin/opex/websocket/ports/kafka/listener/config/WebSocketKafkaConfig.kt index cd49327c8..d7b4cd49c 100644 --- a/websocket/websocket-ports/websocket-eventlistener-kafka/src/main/kotlin/co/nilin/opex/websocket/ports/kafka/listener/config/WebSocketKafkaConfig.kt +++ b/websocket/websocket-ports/websocket-eventlistener-kafka/src/main/kotlin/co/nilin/opex/websocket/ports/kafka/listener/config/WebSocketKafkaConfig.kt @@ -6,6 +6,7 @@ import co.nilin.opex.websocket.ports.kafka.listener.consumer.TradeKafkaListener import org.apache.kafka.clients.admin.NewTopic import org.apache.kafka.clients.consumer.ConsumerConfig import org.apache.kafka.clients.producer.ProducerConfig +import org.apache.kafka.common.config.TopicConfig import org.apache.kafka.common.serialization.StringDeserializer import org.apache.kafka.common.serialization.StringSerializer import org.springframework.beans.factory.annotation.Autowired @@ -15,11 +16,13 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration import org.springframework.context.support.GenericApplicationContext +import org.springframework.kafka.config.TopicBuilder import org.springframework.kafka.core.* import org.springframework.kafka.listener.ConcurrentMessageListenerContainer import org.springframework.kafka.listener.ContainerProperties import org.springframework.kafka.support.serializer.JsonDeserializer import org.springframework.kafka.support.serializer.JsonSerializer +import java.util.function.Supplier import java.util.regex.Pattern @Configuration @@ -33,13 +36,13 @@ class WebSocketKafkaConfig { @Bean("websocketConsumerConfig") fun consumerConfigs(): Map? { - val props: MutableMap = HashMap() - props[ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG] = bootstrapServers - props[ConsumerConfig.GROUP_ID_CONFIG] = groupId - props[ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG] = StringDeserializer::class.java - props[ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG] = JsonDeserializer::class.java - props[JsonDeserializer.TRUSTED_PACKAGES] = "co.nilin.opex.*" - return props + return mapOf( + ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG to bootstrapServers, + ConsumerConfig.GROUP_ID_CONFIG to groupId, + ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG to StringDeserializer::class.java, + ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG to JsonDeserializer::class.java, + JsonDeserializer.TRUSTED_PACKAGES to "co.nilin.opex.*", + ) } @Bean("websocketConsumerFactory") @@ -49,11 +52,12 @@ class WebSocketKafkaConfig { @Bean("websocketProducerConfig") fun producerConfigs(): Map { - val props: MutableMap = HashMap() - props[ProducerConfig.BOOTSTRAP_SERVERS_CONFIG] = bootstrapServers - props[ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG] = StringSerializer::class.java - props[ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG] = JsonSerializer::class.java - return props + return mapOf( + ProducerConfig.BOOTSTRAP_SERVERS_CONFIG to bootstrapServers, + ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG to StringSerializer::class.java, + ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG to JsonSerializer::class.java, + ProducerConfig.ACKS_CONFIG to "all" + ) } @Bean("websocketProducerFactory") @@ -68,28 +72,47 @@ class WebSocketKafkaConfig { @Autowired @ConditionalOnBean(TradeKafkaListener::class) - fun configureTradeListener(tradeListener: TradeKafkaListener, @Qualifier("websocketConsumerFactory") consumerFactory: ConsumerFactory) { + fun configureTradeListener( + tradeListener: TradeKafkaListener, + @Qualifier("websocketConsumerFactory") consumerFactory: ConsumerFactory + ) { val containerProps = ContainerProperties(Pattern.compile("richTrade")) containerProps.messageListener = tradeListener val container = ConcurrentMessageListenerContainer(consumerFactory, containerProps) - container.beanName = "WebsocketTradeKafkaListenerContainer" + container.setBeanName("WebsocketTradeKafkaListenerContainer") container.start() } @Autowired @ConditionalOnBean(OrderKafkaListener::class) - fun configureOrderListener(orderListener: OrderKafkaListener, @Qualifier("websocketConsumerFactory") consumerFactory: ConsumerFactory) { + fun configureOrderListener( + orderListener: OrderKafkaListener, + @Qualifier("websocketConsumerFactory") consumerFactory: ConsumerFactory + ) { val containerProps = ContainerProperties(Pattern.compile("richOrder")) containerProps.messageListener = orderListener val container = ConcurrentMessageListenerContainer(consumerFactory, containerProps) - container.beanName = "WebsocketOrderKafkaListenerContainer" + container.setBeanName("WebsocketOrderKafkaListenerContainer") container.start() } @Autowired fun createTopics(applicationContext: GenericApplicationContext) { - applicationContext.registerBean("topic_richOrder", NewTopic::class.java, "richOrder", 10, 1) - applicationContext.registerBean("topic_richTrade", NewTopic::class.java, "richTrade", 10, 1) + applicationContext.registerBean("topic_richOrder", NewTopic::class.java, Supplier { + TopicBuilder.name("richOrder") + .partitions(10) + .replicas(3) + .config(TopicConfig.MIN_IN_SYNC_REPLICAS_CONFIG, "2") + .build() + }) + + applicationContext.registerBean("topic_richTrade", NewTopic::class.java, Supplier { + TopicBuilder.name("richTrade") + .partitions(10) + .replicas(3) + .config(TopicConfig.MIN_IN_SYNC_REPLICAS_CONFIG, "2") + .build() + }) } diff --git a/websocket/websocket-ports/websocket-eventlistener-kafka/src/main/kotlin/co/nilin/opex/websocket/ports/kafka/listener/consumer/OrderKafkaListener.kt b/websocket/websocket-ports/websocket-eventlistener-kafka/src/main/kotlin/co/nilin/opex/websocket/ports/kafka/listener/consumer/OrderKafkaListener.kt index e26e8a08c..dc7fe8a42 100644 --- a/websocket/websocket-ports/websocket-eventlistener-kafka/src/main/kotlin/co/nilin/opex/websocket/ports/kafka/listener/consumer/OrderKafkaListener.kt +++ b/websocket/websocket-ports/websocket-eventlistener-kafka/src/main/kotlin/co/nilin/opex/websocket/ports/kafka/listener/consumer/OrderKafkaListener.kt @@ -1,17 +1,17 @@ package co.nilin.opex.websocket.ports.kafka.listener.consumer -import co.nilin.opex.accountant.core.inout.RichOrder +import co.nilin.opex.accountant.core.inout.RichOrderEvent import co.nilin.opex.websocket.ports.kafka.listener.spi.RichOrderListener import org.apache.kafka.clients.consumer.ConsumerRecord import org.springframework.kafka.listener.MessageListener import org.springframework.stereotype.Component @Component -class OrderKafkaListener : MessageListener { +class OrderKafkaListener : MessageListener { val orderListeners = arrayListOf() - override fun onMessage(data: ConsumerRecord) { + override fun onMessage(data: ConsumerRecord) { orderListeners.forEach { tl -> tl.onOrder(data.value(), data.partition(), data.offset(), data.timestamp()) } diff --git a/websocket/websocket-ports/websocket-eventlistener-kafka/src/main/kotlin/co/nilin/opex/websocket/ports/kafka/listener/spi/RichOrderListener.kt b/websocket/websocket-ports/websocket-eventlistener-kafka/src/main/kotlin/co/nilin/opex/websocket/ports/kafka/listener/spi/RichOrderListener.kt index a9e3751a0..30d23b6f3 100644 --- a/websocket/websocket-ports/websocket-eventlistener-kafka/src/main/kotlin/co/nilin/opex/websocket/ports/kafka/listener/spi/RichOrderListener.kt +++ b/websocket/websocket-ports/websocket-eventlistener-kafka/src/main/kotlin/co/nilin/opex/websocket/ports/kafka/listener/spi/RichOrderListener.kt @@ -1,8 +1,11 @@ package co.nilin.opex.websocket.ports.kafka.listener.spi -import co.nilin.opex.accountant.core.inout.RichOrder +import co.nilin.opex.accountant.core.inout.RichOrderEvent interface RichOrderListener { + fun id(): String - fun onOrder(order: RichOrder, partition: Int, offset: Long, timestamp: Long) + + fun onOrder(order: RichOrderEvent, partition: Int, offset: Long, timestamp: Long) + } \ No newline at end of file diff --git a/websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/dao/OrderRepository.kt b/websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/dao/OrderRepository.kt index 45cfcc5e3..5f5c923a0 100644 --- a/websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/dao/OrderRepository.kt +++ b/websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/dao/OrderRepository.kt @@ -1,8 +1,8 @@ package co.nilin.opex.websocket.ports.postgres.dao import co.nilin.opex.matching.engine.core.model.OrderDirection -import co.nilin.opex.websocket.ports.postgres.model.OrderModel import co.nilin.opex.websocket.core.inout.AggregatedOrderPriceModel +import co.nilin.opex.websocket.ports.postgres.model.OrderModel import kotlinx.coroutines.flow.Flow import org.springframework.data.r2dbc.repository.Query import org.springframework.data.repository.query.Param @@ -34,7 +34,15 @@ interface OrderRepository : ReactiveCrudRepository { origClientOrderId: String ): Mono - @Query("select * from orders where uuid = :uuid and (:symbol is null or symbol = :symbol) and status in (:statuses)") + @Query( + """ + select * from orders + join order_status os on orders.ouid = os.ouid + where uuid = :uuid and (:symbol is null or symbol = :symbol) and status in (:statuses) + and appearance = (select max(appearance) from order_status where ouid = orders.ouid) + and executed_quantity = (select max(executed_quantity) from order_status where ouid = orders.ouid) + """ + ) fun findByUuidAndSymbolAndStatus( @Param("uuid") uuid: String, @@ -63,8 +71,11 @@ interface OrderRepository : ReactiveCrudRepository { @Query( """ - select price, (sum(quantity) - sum(executed_qty)) as quantity from orders - where symbol = :symbol and side = :direction and status in (:statuses) + select price, (sum(quantity) - sum(os.executed_quantity)) as quantity from orders + join order_status os on orders.ouid = os.ouid + where symbol = :symbol and side = :direction and os.status in (:statuses) + and appearance = (select max(appearance) from order_status where ouid = orders.ouid) + and executed_quantity = (select max(executed_quantity) from order_status where ouid = orders.ouid) group by price order by price asc limit :limit @@ -83,8 +94,11 @@ interface OrderRepository : ReactiveCrudRepository { @Query( """ - select price, (sum(quantity) - sum(executed_qty)) as quantity from orders + select price, (sum(quantity) - sum(executed_quantity)) as quantity from orders + join order_status os on orders.ouid = os.ouid where symbol = :symbol and side = :direction and status in (:statuses) + and appearance = (select max(appearance) from order_status where ouid = orders.ouid) + and executed_quantity = (select max(executed_quantity) from order_status where ouid = orders.ouid) group by price order by price desc limit :limit diff --git a/websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/dao/OrderStatusRepository.kt b/websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/dao/OrderStatusRepository.kt new file mode 100644 index 000000000..549619932 --- /dev/null +++ b/websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/dao/OrderStatusRepository.kt @@ -0,0 +1,24 @@ +package co.nilin.opex.websocket.ports.postgres.dao + +import co.nilin.opex.websocket.ports.postgres.model.OrderStatusModel +import org.springframework.data.r2dbc.repository.Query +import org.springframework.data.repository.reactive.ReactiveCrudRepository +import org.springframework.stereotype.Repository +import reactor.core.publisher.Mono + +@Repository +interface OrderStatusRepository : ReactiveCrudRepository { + + @Query( + """ + with max_appearance as (select max(appearance) as max_app from order_status where ouid = :ouid) + select * from order_status + where ouid = :ouid + and appearance = (select max_app from max_appearance) + order by executed_quantity desc + limit 1 + """ + ) + fun findMostRecentByOUID(ouid: String): Mono + +} \ No newline at end of file diff --git a/websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/dao/TradeRepository.kt b/websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/dao/TradeRepository.kt index 589ce0fe9..39eae57ff 100644 --- a/websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/dao/TradeRepository.kt +++ b/websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/dao/TradeRepository.kt @@ -52,18 +52,39 @@ interface TradeRepository : ReactiveCrudRepository { @Query( """ select symbol, - (select taker_price from trades where create_date > :date and symbol=t.symbol order by create_date desc limit 1) - (select taker_price from trades where create_date > :date and symbol=t.symbol order by create_date asc limit 1) as price_change, - ((((select taker_price from trades where create_date > :date and symbol=t.symbol order by create_date desc limit 1) - (select taker_price from trades where create_date > :date and symbol=t.symbol order by create_date asc limit 1))/(select taker_price from trades where create_date > :date and symbol=t.symbol order by create_date asc limit 1))*100) as price_change_percent, + (select taker_price from trades where create_date > :date and symbol=t.symbol order by create_date desc limit 1) - (select taker_price from trades where create_date > :date and symbol=t.symbol order by create_date limit 1) as price_change, + ((((select taker_price from trades where create_date > :date and symbol=t.symbol order by create_date desc limit 1) - (select taker_price from trades where create_date > :date and symbol=t.symbol order by create_date limit 1))/(select taker_price from trades where create_date > :date and symbol=t.symbol order by create_date limit 1))*100) as price_change_percent, (sum(matched_quantity)/sum(taker_price)) as weighted_avg_price, - (select taker_price from trades where create_date > :date and symbol=t.symbol order by create_date asc limit 1) as last_price, - (select matched_quantity from trades where create_date > :date and symbol=t.symbol order by create_date asc limit 1) as last_qty, - (select price from orders where create_date > :date and symbol=t.symbol and (status=1 or status=4) and side='BID' order by create_date desc limit 1) as bid_price, - (select price from orders where create_date > :date and symbol=t.symbol and (status=1 or status=4) and side='ASK' order by create_date asc limit 1) as ask_price, - (select price from orders where create_date > :date and symbol=t.symbol and (status=1 or status=4) order by create_date desc limit 1) as open_price, + (select taker_price from trades where create_date > :date and symbol=t.symbol order by create_date limit 1) as last_price, + (select matched_quantity from trades where create_date > :date and symbol=t.symbol order by create_date limit 1) as last_qty, + ( + select price from orders + join order_status os on orders.ouid = os.ouid + where create_date > :date and symbol=t.symbol and status in (1, 4) and side='BID' + and appearance = (select max(appearance) from order_status where ouid = orders.ouid) + and executed_quantity = (select max(executed_quantity) from order_status where ouid = orders.ouid) + order by create_date desc limit 1 + ) as bid_price, + ( + select price from orders + join order_status os on orders.ouid = os.ouid + where create_date > :date and symbol=t.symbol and status in (1, 4) and side='ASK' + and appearance = (select max(appearance) from order_status where ouid = orders.ouid) + and executed_quantity = (select max(executed_quantity) from order_status where ouid = orders.ouid) + order by create_date limit 1 + ) as ask_price, + ( + select price from orders + join order_status os on orders.ouid = os.ouid + where create_date > :date and symbol=t.symbol and status in (1, 4) + and appearance = (select max(appearance) from order_status where ouid = orders.ouid) + and executed_quantity = (select max(executed_quantity) from order_status where ouid = orders.ouid) + order by create_date desc limit 1 + ) as open_price, max(taker_price) as high_price, min(taker_price) as low_price, sum(matched_quantity) as volume, - (select id from trades where create_date > :date and symbol=t.symbol order by create_date asc limit 1) as first_id, + (select id from trades where create_date > :date and symbol=t.symbol order by create_date limit 1) as first_id, (select id from trades where create_date > :date and symbol=t.symbol order by create_date desc limit 1) as last_id, count(id) as count from trades as t @@ -76,18 +97,39 @@ interface TradeRepository : ReactiveCrudRepository { @Query( """ select symbol, - (select taker_price from trades where create_date > :date and symbol=:symbol order by create_date desc limit 1) - (select taker_price from trades where create_date > :date and symbol=:symbol order by create_date asc limit 1) as price_change, - ((((select taker_price from trades where create_date > :date and symbol=:symbol order by create_date desc limit 1) - (select taker_price from trades where create_date > :date and symbol=:symbol order by create_date asc limit 1))/(select taker_price from trades where create_date > :date and symbol=:symbol order by create_date asc limit 1))*100) as price_change_percent, + (select taker_price from trades where create_date > :date and symbol=:symbol order by create_date desc limit 1) - (select taker_price from trades where create_date > :date and symbol=:symbol order by create_date limit 1) as price_change, + ((((select taker_price from trades where create_date > :date and symbol=:symbol order by create_date desc limit 1) - (select taker_price from trades where create_date > :date and symbol=:symbol order by create_date limit 1))/(select taker_price from trades where create_date > :date and symbol=:symbol order by create_date limit 1))*100) as price_change_percent, (sum(matched_quantity)/sum(taker_price)) as weighted_avg_price, - (select taker_price from trades where create_date > :date and symbol=:symbol order by create_date asc limit 1) as last_price, - (select matched_quantity from trades where create_date > :date and symbol=:symbol order by create_date asc limit 1) as last_qty, - (select price from orders where create_date > :date and symbol=t.symbol and (status=1 or status=4) and side='BID' order by create_date desc limit 1) as bid_price, - (select price from orders where create_date > :date and symbol=t.symbol and (status=1 or status=4) and side='ASK' order by create_date asc limit 1) as ask_price, - (select price from orders where create_date > :date and symbol=t.symbol and (status=1 or status=4) order by create_date desc limit 1) as open_price, + (select taker_price from trades where create_date > :date and symbol=:symbol order by create_date limit 1) as last_price, + (select matched_quantity from trades where create_date > :date and symbol=:symbol order by create_date limit 1) as last_qty, + ( + select price from orders + join order_status os on orders.ouid = os.ouid + where create_date > :date and symbol=t.symbol and status in (1, 4) and side='BID' + and appearance = (select max(appearance) from order_status where ouid = orders.ouid) + and executed_quantity = (select max(executed_quantity) from order_status where ouid = orders.ouid) + order by create_date desc limit 1 + ) as bid_price, + ( + select price from orders + join order_status os on orders.ouid = os.ouid + where create_date > :date and symbol=t.symbol and status in (1, 4) and side='ASK' + and appearance = (select max(appearance) from order_status where ouid = orders.ouid) + and executed_quantity = (select max(executed_quantity) from order_status where ouid = orders.ouid) + order by create_date limit 1 + ) as ask_price, + ( + select price from orders + join order_status os on orders.ouid = os.ouid + where create_date > :date and symbol=t.symbol and status in (1, 4) + and appearance = (select max(appearance) from order_status where ouid = orders.ouid) + and executed_quantity = (select max(executed_quantity) from order_status where ouid = orders.ouid) + order by create_date desc limit 1 + ) as open_price, max(taker_price) as high_price, min(taker_price) as low_price, sum(matched_quantity) as volume, - (select id from trades where create_date > :date and symbol=:symbol order by create_date asc limit 1) as first_id, + (select id from trades where create_date > :date and symbol=:symbol order by create_date limit 1) as first_id, (select id from trades where create_date > :date and symbol=:symbol order by create_date desc limit 1) as last_id, count(id) as count from trades as t @@ -114,7 +156,7 @@ interface TradeRepository : ReactiveCrudRepository { select f.start_time as open_time, f.end_time as close_time, - (select taker_price from trades tt where symbol = :symbol and tt.create_date >= f.start_time and tt.create_date < f.end_time order by tt.create_date asc limit 1) as open, + (select taker_price from trades tt where symbol = :symbol and tt.create_date >= f.start_time and tt.create_date < f.end_time order by tt.create_date limit 1) as open, max(t.taker_price) as high, min(t.taker_price) as low, (select taker_price from trades tt where symbol = :symbol and tt.create_date >= f.start_time and tt.create_date < f.end_time order by tt.create_date desc limit 1) as close, diff --git a/websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/impl/MarketQueryHandlerImpl.kt b/websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/impl/MarketQueryHandlerImpl.kt index 0085befea..a3acf37c6 100644 --- a/websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/impl/MarketQueryHandlerImpl.kt +++ b/websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/impl/MarketQueryHandlerImpl.kt @@ -5,8 +5,10 @@ import co.nilin.opex.websocket.core.inout.* import co.nilin.opex.websocket.core.spi.MarketQueryHandler import co.nilin.opex.websocket.core.spi.SymbolMapper import co.nilin.opex.websocket.ports.postgres.dao.OrderRepository +import co.nilin.opex.websocket.ports.postgres.dao.OrderStatusRepository import co.nilin.opex.websocket.ports.postgres.dao.TradeRepository import co.nilin.opex.websocket.ports.postgres.model.OrderModel +import co.nilin.opex.websocket.ports.postgres.model.OrderStatusModel import co.nilin.opex.websocket.ports.postgres.model.TradeTickerData import co.nilin.opex.websocket.ports.postgres.util.* import kotlinx.coroutines.flow.Flow @@ -15,6 +17,7 @@ import kotlinx.coroutines.reactive.awaitFirst import kotlinx.coroutines.reactive.awaitFirstOrElse import kotlinx.coroutines.reactive.awaitFirstOrNull import org.springframework.stereotype.Component +import java.math.BigDecimal import java.time.Instant import java.time.LocalDateTime import java.time.ZoneId @@ -27,6 +30,7 @@ import kotlin.math.min class MarketQueryHandlerImpl( private val orderRepository: OrderRepository, private val tradeRepository: TradeRepository, + private val orderStatusRepository: OrderStatusRepository, private val symbolMapper: SymbolMapper, ) : MarketQueryHandler { @@ -64,9 +68,9 @@ class MarketQueryHandlerImpl( } override suspend fun lastOrder(symbol: String): QueryOrderResponse? { - return orderRepository.findLastOrderBySymbol(symbol) - .awaitFirstOrNull() - ?.asQueryOrderResponse() + val order = orderRepository.findLastOrderBySymbol(symbol).awaitFirstOrNull() ?: return null + val status = orderStatusRepository.findMostRecentByOUID(order.ouid).awaitFirstOrNull() + return order.asQueryOrderResponse(status) } override suspend fun recentTrades(symbol: String, limit: Int): Flow { @@ -160,7 +164,7 @@ class MarketQueryHandlerImpl( } } - private fun OrderModel.asQueryOrderResponse() = QueryOrderResponse( + private fun OrderModel.asQueryOrderResponse(orderStatusModel: OrderStatusModel?) = QueryOrderResponse( symbol, ouid, orderId ?: -1, @@ -168,9 +172,9 @@ class MarketQueryHandlerImpl( clientOrderId ?: "", price!!.toBigDecimal(), quantity!!.toBigDecimal(), - executedQuantity!!.toBigDecimal(), - (accumulativeQuoteQty ?: 0.0).toBigDecimal(), - status!!.toOrderStatus(), + orderStatusModel?.executedQuantity?.toBigDecimal() ?: BigDecimal.ZERO, + orderStatusModel?.accumulativeQuoteQty?.toBigDecimal() ?: BigDecimal.ZERO, + orderStatusModel?.status?.toOrderStatus() ?: OrderStatus.NEW, constraint!!.toTimeInForce(), type!!.toWebSocketOrderType(), direction!!.toOrderSide(), @@ -178,7 +182,7 @@ class MarketQueryHandlerImpl( null, Date.from(createDate!!.atZone(ZoneId.systemDefault()).toInstant()), Date.from(updateDate.atZone(ZoneId.systemDefault()).toInstant()), - status.toOrderStatus().isWorking(), + (orderStatusModel?.status?.toOrderStatus() ?: OrderStatus.NEW).isWorking(), quoteQuantity!!.toBigDecimal() ) diff --git a/websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/impl/UserQueryHandlerImpl.kt b/websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/impl/UserQueryHandlerImpl.kt index 5485d38ed..0bbe1d8da 100644 --- a/websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/impl/UserQueryHandlerImpl.kt +++ b/websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/impl/UserQueryHandlerImpl.kt @@ -6,8 +6,10 @@ import co.nilin.opex.utility.error.data.OpexException import co.nilin.opex.websocket.core.inout.* import co.nilin.opex.websocket.core.spi.UserQueryHandler import co.nilin.opex.websocket.ports.postgres.dao.OrderRepository +import co.nilin.opex.websocket.ports.postgres.dao.OrderStatusRepository import co.nilin.opex.websocket.ports.postgres.dao.TradeRepository import co.nilin.opex.websocket.ports.postgres.model.OrderModel +import co.nilin.opex.websocket.ports.postgres.model.OrderStatusModel import co.nilin.opex.websocket.ports.postgres.util.* import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.filter @@ -15,14 +17,16 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.reactive.awaitFirst import kotlinx.coroutines.reactive.awaitFirstOrNull import org.springframework.stereotype.Component +import java.math.BigDecimal import java.security.Principal import java.time.ZoneId import java.util.* @Component class UserQueryHandlerImpl( - val orderRepository: OrderRepository, - val tradeRepository: TradeRepository + private val orderRepository: OrderRepository, + private val tradeRepository: TradeRepository, + private val orderStatusRepository: OrderStatusRepository ) : UserQueryHandler { override suspend fun queryOrder(principal: Principal, request: QueryOrderRequest): QueryOrderResponse? { @@ -31,13 +35,12 @@ class UserQueryHandlerImpl( } else { orderRepository.findBySymbolAndOrderId(request.symbol, request.orderId!!) - }).awaitFirstOrNull() - if (order?.constraint != null) { - if (order.uuid != principal.name) - throw OpexException(OpexError.Forbidden) - return orderToQueryResponse(order) - } - return null + }).awaitFirstOrNull() ?: return null + + if (order.uuid != principal.name) + throw OpexException(OpexError.Forbidden) + + return order.asQueryResponse(orderStatusRepository.findMostRecentByOUID(order.ouid).awaitFirstOrNull()) } override suspend fun openOrders(principal: Principal, symbol: String?): Flow { @@ -46,7 +49,7 @@ class UserQueryHandlerImpl( symbol, listOf(OrderStatus.NEW.code, OrderStatus.PARTIALLY_FILLED.code) ).filter { orderModel -> orderModel.constraint != null } - .map { order -> orderToQueryResponse(order) } + .map { it.asQueryResponse(orderStatusRepository.findMostRecentByOUID(it.ouid).awaitFirstOrNull()) } } override suspend fun allOrders(principal: Principal, allOrderRequest: AllOrderRequest): Flow { @@ -56,7 +59,7 @@ class UserQueryHandlerImpl( allOrderRequest.startTime, allOrderRequest.endTime ).filter { orderModel -> orderModel.constraint != null } - .map { order -> orderToQueryResponse(order) } + .map { it.asQueryResponse(orderStatusRepository.findMostRecentByOUID(it.ouid).awaitFirstOrNull()) } } override suspend fun allTrades(principal: Principal, request: TradeRequest): Flow { @@ -112,24 +115,25 @@ class UserQueryHandlerImpl( } - private fun orderToQueryResponse(order: OrderModel) = QueryOrderResponse( - order.symbol, - order.ouid, - order.orderId ?: -1, + private fun OrderModel.asQueryResponse(orderStatusModel: OrderStatusModel?) = QueryOrderResponse( + symbol, + ouid, + orderId ?: -1, -1, - order.clientOrderId ?: "", - order.price!!.toBigDecimal(), - order.quantity!!.toBigDecimal(), - order.executedQuantity!!.toBigDecimal(), - (order.accumulativeQuoteQty ?: 0.0).toBigDecimal(), - order.status!!.toOrderStatus(), - order.constraint!!.toTimeInForce(), - order.type!!.toWebSocketOrderType(), - order.direction!!.toOrderSide(), + clientOrderId ?: "", + price!!.toBigDecimal(), + quantity!!.toBigDecimal(), + orderStatusModel?.executedQuantity?.toBigDecimal() ?: BigDecimal.ZERO, + orderStatusModel?.accumulativeQuoteQty?.toBigDecimal() ?: BigDecimal.ZERO, + orderStatusModel?.status?.toOrderStatus() ?: OrderStatus.NEW, + constraint!!.toTimeInForce(), + type!!.toWebSocketOrderType(), + direction!!.toOrderSide(), null, null, - Date.from(order.createDate!!.atZone(ZoneId.systemDefault()).toInstant()), - Date.from(order.updateDate.atZone(ZoneId.systemDefault()).toInstant()), - order.status.toOrderStatus().isWorking(), order.quoteQuantity!!.toBigDecimal() + Date.from(createDate!!.atZone(ZoneId.systemDefault()).toInstant()), + Date.from(updateDate.atZone(ZoneId.systemDefault()).toInstant()), + (orderStatusModel?.status?.toOrderStatus() ?: OrderStatus.NEW).isWorking(), + quoteQuantity!!.toBigDecimal() ) } \ No newline at end of file diff --git a/websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/model/OrderModel.kt b/websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/model/OrderModel.kt index f47097a78..9f8155acc 100644 --- a/websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/model/OrderModel.kt +++ b/websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/model/OrderModel.kt @@ -31,9 +31,6 @@ class OrderModel( @Column("price") val price: Double?, @Column("quantity") val quantity: Double?, @Column("quote_quantity") val quoteQuantity: Double?, - @Column("executed_qty") val executedQuantity: Double?, - @Column("accumulative_quote_qty") val accumulativeQuoteQty: Double?, - @Column("status") val status: Int?, @Column("create_date") val createDate: LocalDateTime?, @Column("update_date") val updateDate: LocalDateTime, @Version diff --git a/websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/model/OrderStatusModel.kt b/websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/model/OrderStatusModel.kt new file mode 100644 index 000000000..38774cf38 --- /dev/null +++ b/websocket/websocket-ports/websocket-persister-postgres/src/main/kotlin/co/nilin/opex/websocket/ports/postgres/model/OrderStatusModel.kt @@ -0,0 +1,17 @@ +package co.nilin.opex.websocket.ports.postgres.model + +import org.springframework.data.annotation.Id +import org.springframework.data.relational.core.mapping.Table +import java.time.LocalDateTime + +@Table("order_status") +data class OrderStatusModel( + val ouid: String, + val executedQuantity: Double?, + val accumulativeQuoteQty: Double?, + val status: Int, + val appearance: Int, + val date: LocalDateTime = LocalDateTime.now(), + @Id + var id: Long? = null +) \ No newline at end of file From 6f5c8e36a1c0f3c27850d8014587245a21e42941 Mon Sep 17 00:00:00 2001 From: metalicn20 Date: Sun, 20 Feb 2022 13:13:21 +0330 Subject: [PATCH 2/2] Inject database credentials as envs --- docker-compose.yml | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 94384cf99..b63803fdb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -87,8 +87,8 @@ services: - PANEL_PASS=${PANEL_PASS} - BACKEND_USER=${BACKEND_USER} - SMTP_PASS=${SMTP_PASS} - - DB_USER=${DB_USER} - - DB_PASS=${DB_PASS} + - DB_USER=${DB_USER:-opex} + - DB_PASS=${DB_PASS:-hiopex} healthcheck: retries: 5 cap_add: @@ -124,8 +124,8 @@ services: postgres-accountant: image: postgres:14-alpine environment: - - POSTGRES_USER=opex - - POSTGRES_PASSWORD=hiopex + - POSTGRES_USER=${DB_USER:-opex} + - POSTGRES_PASSWORD=${DB_PASS:-hiopex} - POSTGRES_DB=opex_accountant volumes: - $DATA/accountant-data:/var/lib/postgresql/data/ @@ -149,8 +149,8 @@ services: postgres-eventlog: image: postgres:14-alpine environment: - - POSTGRES_USER=opex - - POSTGRES_PASSWORD=hiopex + - POSTGRES_USER=${DB_USER:-opex} + - POSTGRES_PASSWORD=${DB_PASS:-hiopex} - POSTGRES_DB=opex_eventlog volumes: - $DATA/eventlog-data:/var/lib/postgresql/data/ @@ -159,8 +159,8 @@ services: postgres-auth: image: postgres:14-alpine environment: - - POSTGRES_USER=opex - - POSTGRES_PASSWORD=hiopex + - POSTGRES_USER=${DB_USER:-opex} + - POSTGRES_PASSWORD=${DB_PASS:-hiopex} - POSTGRES_DB=opex_auth volumes: - $DATA/auth-data:/var/lib/postgresql/data/ @@ -172,8 +172,8 @@ services: postgres-wallet: image: postgres:14-alpine environment: - - POSTGRES_USER=opex - - POSTGRES_PASSWORD=hiopex + - POSTGRES_USER=${DB_USER:-opex} + - POSTGRES_PASSWORD=${DB_PASS:-hiopex} - POSTGRES_DB=opex_wallet volumes: - $DATA/wallet-data:/var/lib/postgresql/data/ @@ -185,8 +185,8 @@ services: postgres-api: image: postgres:14-alpine environment: - - POSTGRES_USER=opex - - POSTGRES_PASSWORD=hiopex + - POSTGRES_USER=${DB_USER:-opex} + - POSTGRES_PASSWORD=${DB_PASS:-hiopex} - POSTGRES_DB=opex_api volumes: - $DATA/api-data:/var/lib/postgresql/data/ @@ -198,8 +198,8 @@ services: postgres-bc-gateway: image: postgres:14-alpine environment: - - POSTGRES_USER=opex - - POSTGRES_PASSWORD=hiopex + - POSTGRES_USER=${DB_USER:-opex} + - POSTGRES_PASSWORD=${DB_PASS:-hiopex} - POSTGRES_DB=opex_bc_gateway volumes: - $DATA/bc-gateway-data:/var/lib/postgresql/data/