refactor/set the "api_instance_id" to Constant

This commit is contained in:
hongwei 2023-10-12 11:52:07 +02:00
parent 0c14666413
commit 0d29cfcb15
12 changed files with 27 additions and 9 deletions

View File

@ -121,7 +121,10 @@ long_endpoint_timeout = 55000
# WARNING: if this number does not match the partitions in Kafka config, you will SUFFER !
#kafka.partitions=3
#This is the api instance, we create kafka topic based on this number, each instance should have each own id. use it in load balancing + Kafka setup
#This is also used for scheduler.
OBP will concatenate the UUID string with the value. If we set the value to end with "final", obp will retain that value.
#api_instance_id=1
#api_instance_id=1_final
## DEPRECATED
## Enable user authentication via kafka

View File

@ -21,6 +21,17 @@ object Constant extends MdcLoggable {
final val h2DatabaseDefaultUrlValue = "jdbc:h2:mem:OBPTest_H2_v2.1.214;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=10"
final val HostName = APIUtil.getPropsValue("hostname").openOrThrowException(ErrorMessages.HostnameNotSpecified)
final val ApiInstanceId = {
val apiInstanceIdFromProps = APIUtil.getPropsValue("api_instance_id").openOrThrowException(ErrorMessages.HostnameNotSpecified)
if(apiInstanceIdFromProps.endsWith("final")){
apiInstanceIdFromProps
}else{
s"${apiInstanceIdFromProps}_${APIUtil.generateUUID()}"
}
}
def localIdentityProvider = APIUtil.getPropsValue("local_identity_provider", HostName)
// This is the part before the version. Do not change this default!

View File

@ -51,6 +51,7 @@ object ErrorMessages {
val MissingPropsValueAtThisInstance = "OBP-00010: Missing props value at this API instance - "
val NoValidElasticsearchIndicesConfigured = "OBP-00011: No elasticsearch indices are allowed on this instance. Please set es.warehouse.allowed.indices = index1,index2 (or = ALL for all). "
val CustomerFirehoseNotAllowedOnThisInstance = "OBP-00012: Customer firehose is not allowed on this instance. Please set allow_customer_firehose = true in props files. "
val ApiInstanceIdNotSpecified = "OBP-00013: 'api_instance_id' not specified. Please edit your props file."
// Exceptions (OBP-01XXX) ------------------------------------------------>
val requestTimeout = "OBP-01000: Request Timeout. The OBP API decided to return a timeout. This is probably because a backend service did not respond in time. "

View File

@ -1,5 +1,6 @@
package code.kafka
import code.api.Constant
import code.api.util.{APIUtil, ErrorMessages}
import scala.concurrent.duration.{FiniteDuration, MILLISECONDS}
@ -10,7 +11,7 @@ trait KafkaConfig {
val bootstrapServers = APIUtil.getPropsValue("kafka.bootstrap_hosts")openOr("localhost:9092")
val groupId = APIUtil.getPropsValue("kafka.group.id").openOr("obp-api")
val apiInstanceId = APIUtil.getPropsAsIntValue("api_instance_id").openOr("1")
val apiInstanceId = Constant.ApiInstanceId
val partitions = APIUtil.getPropsAsIntValue("kafka.partitions", 10)
val clientId = s"obp.api.$apiInstanceId"

View File

@ -1,6 +1,7 @@
package code.scheduler
import code.actorsystem.ObpLookupSystem
import code.api.Constant
import code.api.util.APIUtil.generateUUID
import code.api.util.APIUtil
import code.nonce.Nonces
@ -22,7 +23,7 @@ object DataBaseCleanerScheduler extends MdcLoggable {
private val oneDayInMillis: Long = 86400000
//in scala DataBaseCleanerScheduler.getClass.getSimpleName ==> DataBaseCleanerScheduler$
private val jobName = DataBaseCleanerScheduler.getClass.getSimpleName.replace("$", "")
private val apiInstanceId = APIUtil.getPropsValue("api_instance_id", "NOT_SET")
private val apiInstanceId = Constant.ApiInstanceId
def start(intervalInSeconds: Long): Unit = {
logger.info(s"Hello from $jobName.start")

View File

@ -2,8 +2,8 @@ package code.scheduler
import java.util.concurrent.TimeUnit
import java.util.{Calendar, Date}
import code.actorsystem.ObpLookupSystem
import code.api.Constant
import code.api.util.APIUtil.generateUUID
import code.api.util.{APIUtil, OBPLimit, OBPToDate}
import code.metrics.{APIMetric, APIMetrics, MappedMetric, MetricArchive}
@ -21,7 +21,7 @@ object MetricsArchiveScheduler extends MdcLoggable {
private lazy val scheduler = actorSystem.scheduler
private val oneDayInMillis: Long = 86400000
private val jobName = "MetricsArchiveScheduler"
private val apiInstanceId = APIUtil.getPropsValue("api_instance_id", "NOT_SET")
private val apiInstanceId = Constant.ApiInstanceId
def start(intervalInSeconds: Long): Unit = {
logger.info("Hello from MetricsArchiveScheduler.start")

View File

@ -117,7 +117,7 @@ object RunMTLSWebApp extends App with PropsProgrammatically {
context.setWar(s"${basePath}src/main/webapp")
// rename JSESSIONID, avoid conflict with other project when start two project at local
val propsApiInstanceId = APIUtil.getPropsValue("api_instance_id").openOrThrowException("connector props filed `api_instance_id` not set")
val propsApiInstanceId = Constant.ApiInstanceId
context.getSessionHandler.getSessionCookieConfig.setName("JSESSIONID_OBP_API_" + propsApiInstanceId)
server.setHandler(context)

View File

@ -118,7 +118,7 @@ object RunTLSWebApp extends App with PropsProgrammatically {
context.setWar(s"${basePath}src/main/webapp")
// rename JSESSIONID, avoid conflict with other project when start two project at local
val propsApiInstanceId = APIUtil.getPropsValue("api_instance_id").openOrThrowException("connector props filed `api_instance_id` not set")
val propsApiInstanceId = Constant.ApiInstanceId
context.getSessionHandler.getSessionCookieConfig.setName("JSESSIONID_OBP_API_" + propsApiInstanceId)
server.setHandler(context)

View File

@ -70,7 +70,7 @@ object RunWebApp extends App {
val basePath = this.getClass.getResource("/").toString .replaceFirst("target[/\\\\].*$", "")
context.setWar(s"${basePath}src/main/webapp")
// rename JSESSIONID, avoid conflict with other project when start two project at local
val propsApiInstanceId = APIUtil.getPropsValue("api_instance_id").openOrThrowException("connector props filed `api_instance_id` not set")
val propsApiInstanceId = code.api.Constant.ApiInstanceId
context.getSessionHandler.getSessionCookieConfig.setName("JSESSIONID_OBP_API_" + propsApiInstanceId)
server.setHandler(context)

View File

@ -66,7 +66,7 @@ class KafkaMappedConnector_vMay2019Test extends KafkaSetup with ServerSetupWithT
scenario("1st test `getObpConnectorLoopback` method, there no need Adapter message for this method!", kafkaTest) {
//This method is only used for `kafka` connector, should first set `connector=kafka_vSept2018` in test.default.props.
//and also need to set up `api_instance_id` and `remotedata.timeout` field for it.
val propsApiInstanceId = APIUtil.getPropsValue("api_instance_id").openOrThrowException("connector props filed `api_instance_id` not set")
val propsApiInstanceId = code.api.Constant.ApiInstanceId
val propsRemotedataTimeout = APIUtil.getPropsValue("remotedata.timeout").openOrThrowException("connector props filed `remotedata.timeout` not set")
PropsConnectorVersion contains ("kafka") should be(true)

View File

@ -46,7 +46,7 @@ class KafkaTest extends KafkaSetup with ServerSetupWithTestData {
scenario("1st test `getObpConnectorLoopback` method, there no need Adapter message for this method!", kafkaTest) {
//This method is only used for `kafka` connector, should first set `connector=kafka_vSept2018` in test.default.props.
//and also need to set up `api_instance_id` and `remotedata.timeout` field for it.
val propsApiInstanceId = APIUtil.getPropsValue("api_instance_id").openOrThrowException("connector props filed `api_instance_id` not set")
val propsApiInstanceId = code.api.Constant.ApiInstanceId
val propsRemotedataTimeout = APIUtil.getPropsValue("remotedata.timeout").openOrThrowException("connector props filed `remotedata.timeout` not set")
PropsConnectorVersion contains ("kafka") should be (true)

View File

@ -53,6 +53,7 @@ trait ServerSetup extends FeatureSpec with SendServerRequests
setPropsValues("jwt.public_key_rsa" -> "src/test/resources/cert/public_dauth.pem")
setPropsValues("transactionRequests_supported_types" -> "SEPA,SANDBOX_TAN,FREE_FORM,COUNTERPARTY,ACCOUNT,ACCOUNT_OTP,SIMPLE,CARD")
setPropsValues("CARD_OTP_INSTRUCTION_TRANSPORT" -> "DUMMY")
setPropsValues("api_instance_id" -> "1_final")
val server = TestServer
def baseRequest = host(server.host, server.port)