Skip to content

Commit 3bd18a4

Browse files
committed
initial pr of postgres sample
1 parent fd00a2d commit 3bd18a4

File tree

27 files changed

+1183
-0
lines changed

27 files changed

+1183
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!groovy
2+
/**
3+
* Jenkins pipeline to build the java CorDapp template
4+
*/
5+
6+
/**
7+
* Kill already started job.
8+
* Assume new commit takes precedence and results from previousunfinished builds are not required.
9+
* This feature doesn't play well with disableConcurrentBuilds() option
10+
*/
11+
@Library('corda-shared-build-pipeline-steps')
12+
import static com.r3.build.BuildControl.killAllExistingBuildsForJob
13+
killAllExistingBuildsForJob(env.JOB_NAME, env.BUILD_NUMBER.toInteger())
14+
15+
pipeline {
16+
agent {
17+
label 'eight-cores'
18+
}
19+
options {
20+
ansiColor('xterm')
21+
timestamps()
22+
timeout(3*60) // 3 hours
23+
buildDiscarder(logRotator(daysToKeepStr: '7', artifactDaysToKeepStr: '7'))
24+
}
25+
stages {
26+
stage('Build') {
27+
steps {
28+
sh './gradlew --no-daemon -s clean build test deployNodes'
29+
}
30+
}
31+
}
32+
post {
33+
cleanup {
34+
deleteDir()
35+
}
36+
}
37+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Eclipse, ctags, Mac metadata, log files
2+
.classpath
3+
.project
4+
tags
5+
.DS_Store
6+
*.log
7+
*.log.gz
8+
*.orig
9+
10+
.gradle
11+
12+
# General build files
13+
**/build/*
14+
!docs/build/*
15+
16+
lib/dokka.jar
17+
18+
### JetBrains template
19+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
20+
21+
*.iml
22+
23+
## Directory-based project format:
24+
#.idea
25+
26+
# if you remove the above rule, at least ignore the following:
27+
28+
# Specific files to avoid churn
29+
.idea/*.xml
30+
.idea/copyright
31+
.idea/jsLibraryMappings.xml
32+
33+
# User-specific stuff:
34+
.idea/tasks.xml
35+
.idea/dictionaries
36+
37+
# Sensitive or high-churn files:
38+
.idea/dataSources.ids
39+
.idea/dataSources.xml
40+
.idea/sqlDataSources.xml
41+
.idea/dynamic.xml
42+
.idea/uiDesigner.xml
43+
44+
# Gradle:
45+
.idea/libraries
46+
47+
# Mongo Explorer plugin:
48+
.idea/mongoSettings.xml
49+
50+
## File-based project format:
51+
*.ipr
52+
*.iws
53+
54+
## Plugin-specific files:
55+
56+
# IntelliJ
57+
/out/
58+
/workflows/out/
59+
/contracts/out/
60+
clients/out/
61+
*/bin/*
62+
63+
# mpeltonen/sbt-idea plugin
64+
.idea_modules/
65+
66+
# JIRA plugin
67+
atlassian-ide-plugin.xml
68+
69+
# Crashlytics plugin (for Android Studio and IntelliJ)
70+
com_crashlytics_export_strings.xml
71+
crashlytics.properties
72+
crashlytics-build.properties
73+
74+
# docs related
75+
docs/virtualenv/
76+
77+
# if you use the installQuasar task
78+
lib
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate

Features/postgres-cordapp/LICENCE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2016, R3 Limited.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Postgres Cordapp
2+
3+
This application will demonstrate to you how to run corda with a postgres or other custom database.
4+
The cordapp being used is another copy of the yo cordapp, as the majority of the work here is in simply configuring the sql database connection.
5+
6+
## Pre-Requisites
7+
8+
See https://docs.corda.net/getting-set-up.html.
9+
10+
## Usage
11+
12+
### Running the sample
13+
14+
Start with provisioning the database:
15+
16+
```sh
17+
docker run --name postgres_for_corda -e POSTGRES_PASSWORD=test -d -p 5432:5432 postgres:11
18+
19+
# run sql scripts locally on the postgres instance to configure it for use
20+
cat config.sql | docker exec -i postgres_for_corda psql -h localhost -p 5432 -U postgres
21+
22+
./gradlew deployNodes
23+
24+
./build/nodes/runnodes
25+
```
26+
27+
You can then look for the shell for PartyA and run your flows.
28+
29+
30+
```sh
31+
32+
Thu Apr 22 13:03:05 EDT 2021>>> flow start net.corda.samples.postgres.flows.YoFlow target: PartyB
33+
34+
✅ Starting
35+
✅ Creating a new Yo!
36+
✅ Signing the Yo!
37+
✅ Verifying the Yo!
38+
✅ Sending the Yo!
39+
Requesting signature by notary service
40+
Requesting signature by Notary service
41+
Validating response from Notary service
42+
✅ Broadcasting transaction to participants
43+
➡️ Done
44+
Flow completed with result: SignedTransaction(id=8B3FC06F685FC8FFD29001CC6205DAECBFF436E28E0439F74F5A89D11372C578)
45+
```
46+
47+
48+
49+
### useful commands for interacting with your postgres container
50+
51+
```sh
52+
# to list all databases
53+
docker exec -i postgres_for_corda psql -U postgres -p 5432 -h localhost postgres -c "\l"
54+
55+
# to make sure that the schemas were added to the database
56+
docker exec -i postgres_for_corda psql -U postgres -p 5432 -h localhost postgres -c "\dn"
57+
58+
# show all roles
59+
docker exec -i postgres_for_corda psql -U postgres -p 5432 -h localhost postgres -c "\dg"
60+
61+
# show all tables in a schema
62+
docker exec -i postgres_for_corda psql -U postgres -p 5432 -h localhost postgres -c "\dt party_a_schema.*"
63+
64+
# select custom table rows
65+
docker exec -i postgres_for_corda psql -U postgres -p 5432 -h localhost postgres -c "select * from party_a_schema.iou_states"
66+
67+
# drop a schema
68+
docker exec -i postgres_for_corda psql -U postgres -p 5432 -h localhost postgres -c "drop schema party_a_schema cascade"
69+
70+
# drop a user
71+
docker exec -i postgres_for_corda psql -U postgres -p 5432 -h localhost postgres -c "REASSIGN OWNED BY party_a TO my_user"
72+
73+
# drop a role
74+
docker exec -i postgres_for_corda psql -U postgres -p 5432 -h localhost postgres -c "DROP role party_a"
75+
76+
# Show search path
77+
docker exec -i postgres_for_corda psql -U postgres -p 5432 -h localhost postgres -c "show search_path"
78+
```
79+
80+
### Troubleshooting
81+
You may run into some errors about node identity when running 'deployNodes', this is because the database will already have the node information, so you will want to make sure to clear the database contents so that you don't run into issues when recompiling the nodes.
82+
83+
## Additional Resources
84+
85+
- https://www.corda.net/blog/cordapp-database-setup-development-perspective/
86+
- https://medium.com/corda/cordapp-database-setup-production-perspective-2c400e60fae5
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Corda and the Corda logo are trademarks of R3CEV LLC and its affiliates. All rights reserved.
2+
3+
For R3CEV LLC's trademark and logo usage information, please consult our Trademark Usage Policy at
4+
https://www.r3.com/trademark-policy/.
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
buildscript {//properties that you need to build the project
2+
Properties constants = new Properties()
3+
file("$projectDir/../constants.properties").withInputStream { constants.load(it) }
4+
5+
ext {
6+
corda_release_group = constants.getProperty("cordaReleaseGroup")
7+
corda_core_release_group = constants.getProperty("cordaCoreReleaseGroup")
8+
corda_release_version = constants.getProperty("cordaVersion")
9+
corda_core_release_version = constants.getProperty("cordaCoreVersion")
10+
corda_gradle_plugins_version = constants.getProperty("gradlePluginsVersion")
11+
kotlin_version = constants.getProperty("kotlinVersion")
12+
junit_version = constants.getProperty("junitVersion")
13+
quasar_version = constants.getProperty("quasarVersion")
14+
log4j_version = constants.getProperty("log4jVersion")
15+
slf4j_version = constants.getProperty("slf4jVersion")
16+
corda_platform_version = constants.getProperty("platformVersion").toInteger()
17+
//springboot
18+
spring_boot_version = '2.0.2.RELEASE'
19+
spring_boot_gradle_plugin_version = '2.0.2.RELEASE'
20+
}
21+
22+
repositories {
23+
mavenLocal()
24+
mavenCentral()
25+
jcenter()
26+
maven { url 'https://software.r3.com/artifactory/corda-releases' }
27+
}
28+
29+
dependencies {
30+
classpath "net.corda.plugins:cordapp:$corda_gradle_plugins_version"
31+
classpath "net.corda.plugins:cordformation:$corda_gradle_plugins_version"
32+
classpath "net.corda.plugins:quasar-utils:$corda_gradle_plugins_version"
33+
classpath "org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_gradle_plugin_version"
34+
}
35+
}
36+
37+
allprojects {//Properties that you need to compile your project (The application)
38+
apply from: "${rootProject.projectDir}/repositories.gradle"
39+
apply plugin: 'java'
40+
41+
repositories {
42+
mavenLocal()
43+
jcenter()
44+
mavenCentral()
45+
maven { url 'https://software.r3.com/artifactory/corda' }
46+
maven { url 'https://jitpack.io' }
47+
}
48+
49+
tasks.withType(JavaCompile) {
50+
options.compilerArgs << "-parameters" // Required by Corda's serialisation framework.
51+
}
52+
53+
jar {
54+
// This makes the JAR's SHA-256 hash repeatable.
55+
preserveFileTimestamps = false
56+
reproducibleFileOrder = true
57+
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
58+
}
59+
}
60+
61+
apply plugin: 'net.corda.plugins.cordapp'
62+
apply plugin: 'net.corda.plugins.cordformation'
63+
apply plugin: 'net.corda.plugins.quasar-utils'
64+
65+
sourceSets {
66+
main {
67+
resources {
68+
srcDir rootProject.file("config/dev")
69+
}
70+
}
71+
}
72+
//Module dependencis
73+
dependencies {
74+
// Corda dependencies.
75+
cordaCompile "$corda_core_release_group:corda-core:$corda_core_release_version"
76+
cordaCompile "$corda_release_group:corda-node-api:$corda_release_version"
77+
cordaRuntime "$corda_release_group:corda:$corda_release_version"
78+
79+
// CorDapp dependencies.
80+
cordapp project(":workflows")
81+
cordapp project(":contracts")
82+
83+
cordaCompile "org.apache.logging.log4j:log4j-slf4j-impl:${log4j_version}"
84+
cordaCompile "org.apache.logging.log4j:log4j-web:${log4j_version}"
85+
cordaCompile "org.slf4j:jul-to-slf4j:$slf4j_version"
86+
87+
cordaDriver "org.postgresql:postgresql:42.2.19"
88+
}
89+
90+
91+
//Task to deploy the nodes in order to bootstrap a network
92+
task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
93+
94+
/* This property will load the CorDapps to each of the node by default, including the Notary. You can find them
95+
* in the cordapps folder of the node at build/nodes/Notary/cordapps. However, the notary doesn't really understand
96+
* the notion of cordapps. In production, Notary does not need cordapps as well. This is just a short cut to load
97+
* the Corda network bootstrapper.
98+
*/
99+
nodeDefaults {
100+
projectCordapp {
101+
deploy = false
102+
}
103+
104+
cordapp project(':contracts')
105+
cordapp project(':workflows')
106+
// runSchemaMigration = true
107+
108+
rpcUsers = [[user: "user1", "password": "test", "permissions": ["ALL"]]]
109+
}
110+
111+
node {
112+
name "O=Notary,L=London,C=GB"
113+
notary = [validating: false]
114+
p2pPort 10001
115+
rpcSettings {
116+
address("localhost:10011")
117+
adminAddress("localhost:10021")
118+
}
119+
}
120+
121+
node {
122+
name "O=PartyA,L=London,C=GB"
123+
p2pPort 10002
124+
rpcSettings {
125+
address("localhost:10012")
126+
adminAddress("localhost:10022")
127+
}
128+
129+
extraConfig = [
130+
"dataSourceProperties.dataSourceClassName": "org.postgresql.ds.PGSimpleDataSource",
131+
"dataSourceProperties.dataSource.url" : "jdbc:postgresql://localhost:5432/postgres",
132+
"dataSourceProperties.dataSource.user" : 'party_a',
133+
"dataSourceProperties.dataSource.password": 'test',
134+
"jarDirs" : ['${ rootProject.projectDir }/lib']
135+
]
136+
137+
}
138+
139+
node {
140+
name "O=PartyB,L=New York,C=US"
141+
p2pPort 10003
142+
rpcSettings {
143+
address("localhost:10013")
144+
adminAddress("localhost:10023")
145+
}
146+
147+
extraConfig = [
148+
"dataSourceProperties.dataSourceClassName": "org.postgresql.ds.PGSimpleDataSource",
149+
"dataSourceProperties.dataSource.url" : "jdbc:postgresql://localhost:5432/postgres",
150+
"dataSourceProperties.dataSource.user" : 'party_b',
151+
"dataSourceProperties.dataSource.password": 'test',
152+
"jarDirs" : ['${ rootProject.projectDir }/lib']
153+
]
154+
}
155+
156+
}

0 commit comments

Comments
 (0)