Skip to content

Commit

Permalink
Review Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jujoramos committed Oct 9, 2023
1 parent a69aaef commit 658d7c6
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,13 @@ class CombinedWorker @Activate constructor(
*/
private fun prepareStateManagerConfig(stateManagerConfig: Config): Config {
val defaultConfig = ConfigFactory.empty()
.withValue(StateManagerConfig.DataBase.JDBC_DRIVER, fromAnyRef("org.postgresql.Driver"))
.withValue(StateManagerConfig.DataBase.JDBC_PERSISTENCE_UNIT_NAME, fromAnyRef("corda-state-manager"))
.withValue(StateManagerConfig.DataBase.JDBC_POOL_MIN_SIZE, fromAnyRef(1))
.withValue(StateManagerConfig.DataBase.JDBC_POOL_MAX_SIZE, fromAnyRef(5))
.withValue(StateManagerConfig.DataBase.JDBC_POOL_IDLE_TIMEOUT_SECONDS, fromAnyRef(Duration.ofMinutes(2).toSeconds()))
.withValue(StateManagerConfig.DataBase.JDBC_POOL_MAX_LIFETIME_SECONDS, fromAnyRef(Duration.ofMinutes(30).toSeconds()))
.withValue(StateManagerConfig.DataBase.JDBC_POOL_KEEP_ALIVE_TIME_SECONDS, fromAnyRef(Duration.ZERO.toSeconds()))
.withValue(StateManagerConfig.DataBase.JDBC_POOL_VALIDATION_TIMEOUT_SECONDS, fromAnyRef(Duration.ofSeconds(5).toSeconds()))
.withValue(StateManagerConfig.Database.JDBC_DRIVER, fromAnyRef("org.postgresql.Driver"))
.withValue(StateManagerConfig.Database.JDBC_POOL_MIN_SIZE, fromAnyRef(1))
.withValue(StateManagerConfig.Database.JDBC_POOL_MAX_SIZE, fromAnyRef(5))
.withValue(StateManagerConfig.Database.JDBC_POOL_IDLE_TIMEOUT_SECONDS, fromAnyRef(Duration.ofMinutes(2).toSeconds()))
.withValue(StateManagerConfig.Database.JDBC_POOL_MAX_LIFETIME_SECONDS, fromAnyRef(Duration.ofMinutes(30).toSeconds()))
.withValue(StateManagerConfig.Database.JDBC_POOL_KEEP_ALIVE_TIME_SECONDS, fromAnyRef(Duration.ZERO.toSeconds()))
.withValue(StateManagerConfig.Database.JDBC_POOL_VALIDATION_TIMEOUT_SECONDS, fromAnyRef(Duration.ofSeconds(5).toSeconds()))
val stateManagerConfigWithFallback = stateManagerConfig.withFallback(
ConfigFactory.empty().withValue(StateManagerConfig.STATE_MANAGER, defaultConfig.root())
)
Expand Down
4 changes: 2 additions & 2 deletions charts/corda-lib/templates/_bootstrap.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ spec:
echo 'Generating DB specification'
mkdir /tmp/db
java -Dpf4j.pluginsDir=/opt/override/plugins -Dlog4j2.debug=false -jar /opt/override/cli.jar database spec \
-s "config,rbac,crypto,statemanager" \
-g "config:${DB_CLUSTER_SCHEMA},rbac:${DB_RBAC_SCHEMA},crypto:${DB_CRYPTO_SCHEMA},statemanager:${DB_STATE_MANAGER_SCHEMA}" \
-s "config,rbac,crypto,state-manager" \
-g "config:${DB_CLUSTER_SCHEMA},rbac:${DB_RBAC_SCHEMA},crypto:${DB_CRYPTO_SCHEMA},state-manager:${DB_STATE_MANAGER_SCHEMA}" \
-u "${PGUSER}" -p "${PGPASSWORD}" \
--jdbc-url "${JDBC_URL}" \
-c -l /tmp/db
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ConfigurationReadServiceImplTest {

private const val STATE_MANAGER_CONFIG_STRING = """
${StateManagerConfig.TYPE} = "DATABASE"
${StateManagerConfig.DataBase.JDBC_URL} = $STATE_MANAGER_JDBC_URL_DATA
${StateManagerConfig.Database.JDBC_URL} = $STATE_MANAGER_JDBC_URL_DATA
"""

private const val TIMEOUT = 10000L
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ commonsTextVersion = 1.10.0
bouncycastleVersion=1.73
# Corda API libs revision (change in 4th digit indicates a breaking change)
# Change to 5.1.0.xx-SNAPSHOT to pick up maven local published copy
cordaApiVersion=5.1.0.30-alpha-1696534830242
cordaApiVersion=5.1.0.30-alpha-1696848485562

disruptorVersion=3.4.4
felixConfigAdminVersion=1.9.26
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class ConfigurationValidatorImplTest {
private const val NO_FILE_EXISTS = "no-file-here"

private const val VALID_DATA = "data/valid.conf"
private const val VALID_MISSING_REFERENCE_DATA = "data/valid-missing-reference.conf"
private const val INVALID_DATA = "data/invalid.conf"

private val TEST_VERSION = Version.fromString("1.0")
Expand All @@ -56,6 +55,15 @@ class ConfigurationValidatorImplTest {
assertThat(outputConfig.getInt("testInteger")).isEqualTo(7)
}

@Test
fun `valid document against test schema, applies defaults and cast types when possible`() {
val validator = createSchemaValidator()
val smartConfig = loadData(VALID_DATA)
val outputConfig = validator.validate(TEST_SCHEMA, TEST_VERSION, smartConfig, true)
assertThat(smartConfig).isNotEqualTo(outputConfig)
assertThat(outputConfig.getInt("anotherTestInteger")).isEqualTo(20)
}

@Test
fun `valid document against test schema with missing testReference fields, applies defaults`() {
val validator = createSchemaValidator()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"testString": "hello",
"anotherTestInteger": "20",
"testReference": {
"foo": [1, 2, 3.14],
"bar": false
}
"testObject": {
"testPropertyB": {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
"maximum": 500,
"default": 7
},
"anotherTestInteger": {
"type": "integer",
"minimum": 0,
"maximum": 500
},
"testString": {
"type": "string"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@ import net.corda.libs.statemanager.impl.repository.impl.QueryProvider
import net.corda.libs.statemanager.impl.repository.impl.StateRepositoryImpl
import net.corda.orm.DbEntityManagerConfiguration
import net.corda.orm.EntityManagerFactoryFactory
import net.corda.schema.configuration.StateManagerConfig.DataBase.JDBC_DRIVER
import net.corda.schema.configuration.StateManagerConfig.DataBase.JDBC_PASS
import net.corda.schema.configuration.StateManagerConfig.DataBase.JDBC_PERSISTENCE_UNIT_NAME
import net.corda.schema.configuration.StateManagerConfig.DataBase.JDBC_POOL_IDLE_TIMEOUT_SECONDS
import net.corda.schema.configuration.StateManagerConfig.DataBase.JDBC_POOL_KEEP_ALIVE_TIME_SECONDS
import net.corda.schema.configuration.StateManagerConfig.DataBase.JDBC_POOL_MAX_LIFETIME_SECONDS
import net.corda.schema.configuration.StateManagerConfig.DataBase.JDBC_POOL_MAX_SIZE
import net.corda.schema.configuration.StateManagerConfig.DataBase.JDBC_POOL_MIN_SIZE
import net.corda.schema.configuration.StateManagerConfig.DataBase.JDBC_POOL_VALIDATION_TIMEOUT_SECONDS
import net.corda.schema.configuration.StateManagerConfig.DataBase.JDBC_URL
import net.corda.schema.configuration.StateManagerConfig.DataBase.JDBC_USER
import net.corda.schema.configuration.StateManagerConfig.Database.JDBC_DRIVER
import net.corda.schema.configuration.StateManagerConfig.Database.JDBC_PASS
import net.corda.schema.configuration.StateManagerConfig.Database.JDBC_POOL_IDLE_TIMEOUT_SECONDS
import net.corda.schema.configuration.StateManagerConfig.Database.JDBC_POOL_KEEP_ALIVE_TIME_SECONDS
import net.corda.schema.configuration.StateManagerConfig.Database.JDBC_POOL_MAX_LIFETIME_SECONDS
import net.corda.schema.configuration.StateManagerConfig.Database.JDBC_POOL_MAX_SIZE
import net.corda.schema.configuration.StateManagerConfig.Database.JDBC_POOL_MIN_SIZE
import net.corda.schema.configuration.StateManagerConfig.Database.JDBC_POOL_VALIDATION_TIMEOUT_SECONDS
import net.corda.schema.configuration.StateManagerConfig.Database.JDBC_URL
import net.corda.schema.configuration.StateManagerConfig.Database.JDBC_USER
import org.osgi.service.component.annotations.Activate
import org.osgi.service.component.annotations.Component
import org.osgi.service.component.annotations.Reference
Expand All @@ -39,7 +38,6 @@ class StateManagerFactoryImpl @Activate constructor(
val pass = config.getString(JDBC_PASS)
val jdbcUrl = config.getString(JDBC_URL)
val jdbcDiver = config.getString(JDBC_DRIVER)
val persistenceUnitName = config.getString(JDBC_PERSISTENCE_UNIT_NAME)
val maxPoolSize = config.getInt(JDBC_POOL_MAX_SIZE)
val minPoolSize = config.getIntOrDefault(JDBC_POOL_MIN_SIZE, maxPoolSize)
val idleTimeout = config.getInt(JDBC_POOL_IDLE_TIMEOUT_SECONDS).toLong().run(Duration::ofSeconds)
Expand All @@ -61,7 +59,8 @@ class StateManagerFactoryImpl @Activate constructor(
)

val entityManagerFactory = entityManagerFactoryFactory.create(
persistenceUnitName,
// TODO-[CORE-CORE-17025]: persistent unit name will not be required after removing Hibernate.
"corda-state-manager",
StateManagerEntities.classes,
DbEntityManagerConfiguration(dataSource)
)
Expand Down

0 comments on commit 658d7c6

Please sign in to comment.