Skip to content

Commit a22208b

Browse files
committed
undo submod
1 parent 4b1cb83 commit a22208b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1122
-0
lines changed
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

Basic/logging-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.

Basic/logging-cordapp/README.md

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# Logging CorDapp [<img src="../../webIDE.png" height=25 />](https://ide.corda.net/?folder=/home/coder/samples-java/Basic/yo-cordapp)
2+
3+
4+
## Custom Logging
5+
6+
This is a modified version of the original yo cordapp with some additions to use custom log4j2 configurations.
7+
8+
9+
The primary example we've implemented here is json logging which is configured in `config/dev/log4j2.xml`.
10+
11+
This gives us the ability to use Log4j thread contexts to log arbitrary objects or data points in json format.
12+
13+
In this example not only do the node logs output in json but we can add arbitrary key value pairs as well.
14+
15+
```java
16+
// here we have our first opportunity to log out the contents of the flow arguments.
17+
ThreadContext.put("initiator", me.getName().toString());
18+
ThreadContext.put("target", target.getName().toString());
19+
// publish to the log with the additional context
20+
logger.info("Initializing the transaction.");
21+
```
22+
23+
When we log this informational message, it gets output along with the other key value pairs we've specified.
24+
This can be quite powerful if you're looking to produce a consumable output stream to a log aggregator like splunk.
25+
26+
You can end up getting log feeds in json that look something like this:
27+
28+
```json
29+
{"epochSecond":1612369055,"nanoOfSecond":12000000},"thread":"main","level":"INFO","loggerName":"net.corda.node.internal.Node","message":"Vendor: Corda Open Source","endOfBatch":true,"loggerFqcn":"org.apache.logging.slf4j.Log4jLogger","threadId":1,"threadPriority":5}
30+
{"instant":{"epochSecond":1612369055,"nanoOfSecond":12000000},"thread":"main","level":"INFO","loggerName":"net.corda.node.internal.Node","message":"Release: 4.6","endOfBatch":false,"loggerFqcn":"org.apache.logging.slf4j.Log4jLogger","threadId":1,"threadPriority":5}
31+
{"instant":{"epochSecond":1612369055,"nanoOfSecond":12000000},"thread":"main","level":"INFO","loggerName":"net.corda.node.internal.Node","message":"Platform Version: 8","endOfBatch":false,"loggerFqcn":"org.apache.logging.slf4j.Log4jLogger","threadId":1,"threadPriority":5}
32+
{"instant":{"epochSecond":1612369055,"nanoOfSecond":12000000},"thread":"main","level":"INFO","loggerName":"net.corda.node.internal.Node","message":"Revision: 85e387ea730d9be7d6dc2b23caba1ee18305af74","endOfBatch":false,"loggerFqcn":"org.apache.logging.slf4j.Log4jLogger","threadId":1,"threadPriority":5}
33+
{"instant":{"epochSecond":1612369055,"nanoOfSecond":13000000},"thread":"main","level":"INFO","loggerName":"net.corda.node.internal.Node","message":"PID: 94369","endOfBatch":false,"loggerFqcn":"org.apache.logging.slf4j.Log4jLogger","threadId":1,"threadPriority":5}
34+
```
35+
36+
37+
## Yo CorDapp Concepts
38+
39+
In the original yo application, the app sent what is essentially a nudge from one endpoint and another.
40+
41+
In corda, we can use abstractions to accomplish the same thing.
42+
43+
44+
We define a [state](https://training.corda.net/key-concepts/concepts/#states) (the yo to be shared), define a [contract](https://training.corda.net/key-concepts/concepts/#contracts) (the way to make sure the yo is legit), and define the [flow](https://training.corda.net/key-concepts/concepts/#flows) (the control flow of our cordapp).
45+
46+
### States
47+
We define a [Yo as a state](./contracts/src/main/java/net/corda/examples/yo/states/YoState.java#L31-L35), or a corda fact.
48+
49+
```java
50+
public YoState(Party origin, Party target) {
51+
this.origin = origin;
52+
this.target = target;
53+
this.yo = "Yo!";
54+
}
55+
```
56+
57+
58+
### Contracts
59+
We define the ["Yo Social Contract"](./contracts/src/main/java/net/corda/examples/yo/contracts/YoContract.java#L21-L32), which, in this case, verifies some basic assumptions about a Yo.
60+
61+
```java
62+
@Override
63+
public void verify(@NotNull LedgerTransaction tx) throws IllegalArgumentException {
64+
CommandWithParties<Commands.Send> command = requireSingleCommand(tx.getCommands(), Commands.Send.class);
65+
requireThat(req -> {
66+
req.using("There can be no inputs when Yo'ing other parties", tx.getInputs().isEmpty());
67+
req.using("There must be one output: The Yo!", tx.getOutputs().size() == 1);
68+
YoState yo = tx.outputsOfType(YoState.class).get(0);
69+
req.using("No sending Yo's to yourself!", !yo.getTarget().equals(yo.getOrigin()));
70+
req.using("The Yo! must be signed by the sender.", command.getSigners().contains(yo.getOrigin().getOwningKey()));
71+
return null;
72+
});
73+
}
74+
75+
```
76+
77+
78+
### Flows
79+
And then we send the Yo [within a flow](./workflows/src/main/java/net/corda/examples/yo/flows/YoFlow.java#L59-L64).
80+
81+
```java
82+
Party me = getOurIdentity();
83+
Party notary = getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0);
84+
Command<YoContract.Commands.Send> command = new Command<YoContract.Commands.Send>(new YoContract.Commands.Send(), ImmutableList.of(me.getOwningKey()));
85+
YoState state = new YoState(me, target);
86+
StateAndContract stateAndContract = new StateAndContract(state, YoContract.ID);
87+
TransactionBuilder utx = new TransactionBuilder(notary).withItems(stateAndContract, command);
88+
```
89+
90+
On the receiving end, the other corda node will simply receive the Yo using corda provided subroutines, or subflows.
91+
92+
```java
93+
return subFlow(new ReceiveFinalityFlow(counterpartySession));
94+
```
95+
96+
97+
## Usage
98+
99+
100+
### Pre-Requisites
101+
102+
See https://docs.corda.net/getting-set-up.html.
103+
104+
105+
### Running the CorDapp
106+
107+
Open a terminal and go to the project root directory and type: (to deploy the nodes using bootstrapper)
108+
```
109+
./gradlew clean deployNodes
110+
```
111+
Then type: (to run the nodes)
112+
113+
```
114+
./build/nodes/runnodes
115+
```
116+
117+
### Sending a Yo
118+
119+
We will interact with the nodes via their specific shells. When the nodes are up and running, use the following command to send a
120+
Yo to another node:
121+
122+
```
123+
flow start YoFlow target: PartyB
124+
```
125+
126+
Where `NODE_NAME` is 'PartyA' or 'PartyB'. The space after the `:` is required. You are not required to use the full
127+
X500 name in the node shell. Note you can't sent a Yo! to yourself because that's not cool!
128+
129+
To see all the Yo's! other nodes have sent you in your vault (you do not store the Yo's! you send yourself), run:
130+
131+
```
132+
run vaultQuery contractStateType: YoState
133+
```
134+
135+
### Viewing custom logs
136+
137+
This will depend on your cordapp setup, if you're running your corda nodes all you need to do is specify the particular config file. You can do that in a couple of ways.
138+
139+
140+
```
141+
"-Dlog4j.configurationFile=logging-cordapp/build/resources/main/log4j2.xml"
142+
```
143+
144+
If you're running with the bootstrapped corda network you can run it by simply adding this argument to the result of the runnodes command.
145+
146+
147+
```
148+
'cd "/Users/corda/logging-cordapp/build/nodes/PartyA" ; "/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre/bin/java" "-Dcapsule.jvm.args=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5006 -javaagent:drivers/jolokia-jvm-1.6.0-agent.jar=port=7006,logHandlerClass=net.corda.node.JolokiaSlf4jAdapter" "-Dname=PartyA" "-jar" "-Dlog4j.configurationFile=/Users/corda/logging-cordapp/build/resources/main/log4j2.xml" "/Users/corda/logging-cordapp/build/nodes/PartyA/corda.jar" ; and exit'
149+
150+
```
151+
152+
153+
154+
## Attribution
155+
156+
This example was built in collaboration with [Splunk](https://splunk.com), and they have our thanks.
157+
158+
159+
160+
161+

Basic/logging-cordapp/TRADEMARK

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/.

Basic/logging-cordapp/build.gradle

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
buildscript {
2+
Properties constants = new Properties()
3+
// file("$projectDir/../constants.properties").withInputStream { constants.load(it) }
4+
file("$projectDir/../constants.properties").withInputStream { constants.load(it) }
5+
6+
ext {
7+
corda_release_group = constants.getProperty("cordaReleaseGroup")
8+
corda_release_version = constants.getProperty("cordaVersion")
9+
corda_gradle_plugins_version = constants.getProperty("gradlePluginsVersion")
10+
junit_version = constants.getProperty("junitVersion")
11+
quasar_version = constants.getProperty("quasarVersion")
12+
log4j_version = constants.getProperty("log4jVersion")
13+
slf4j_version = constants.getProperty("slf4jVersion")
14+
corda_platform_version = constants.getProperty("platformVersion").toInteger()
15+
}
16+
17+
repositories {
18+
mavenLocal()
19+
mavenCentral()
20+
jcenter()
21+
maven { url 'https://software.r3.com/artifactory/corda-releases' }
22+
}
23+
24+
dependencies {
25+
classpath "net.corda.plugins:cordapp:$corda_gradle_plugins_version"
26+
classpath "net.corda.plugins:cordformation:$corda_gradle_plugins_version"
27+
classpath "net.corda.plugins:quasar-utils:$corda_gradle_plugins_version"
28+
}
29+
}
30+
31+
allprojects {
32+
apply from: "${rootProject.projectDir}/repositories.gradle"
33+
apply plugin: 'java'
34+
35+
repositories {
36+
mavenLocal()
37+
jcenter()
38+
mavenCentral()
39+
maven { url 'https://software.r3.com/artifactory/corda' }
40+
maven { url 'https://jitpack.io' }
41+
}
42+
43+
tasks.withType(JavaCompile) {
44+
options.compilerArgs << "-parameters" // Required for shell commands.
45+
// jvmArgs = "-Dlog4j.configurationFile=config/dev/log4j2.xml"
46+
}
47+
48+
jar {
49+
// CorDapps do not configure a Node's logging.
50+
exclude '**/log4j2*.xml'
51+
}
52+
}
53+
54+
apply plugin: 'net.corda.plugins.cordapp'
55+
apply plugin: 'net.corda.plugins.cordformation'
56+
apply plugin: 'net.corda.plugins.quasar-utils'
57+
58+
sourceSets {
59+
main {
60+
resources {
61+
srcDir rootProject.file("config/dev")
62+
}
63+
}
64+
}
65+
66+
dependencies {
67+
// Corda dependencies.
68+
cordaCompile "$corda_release_group:corda-core:$corda_release_version"
69+
cordaCompile "$corda_release_group:corda-node-api:$corda_release_version"
70+
cordaRuntime "$corda_release_group:corda:$corda_release_version"
71+
72+
// CorDapp dependencies.
73+
cordapp project(":workflows")
74+
cordapp project(":contracts")
75+
76+
// specific dependency for log4j2 core
77+
cordaCompile 'org.apache.logging.log4j:log4j-core:2.13.3'
78+
cordaCompile "org.apache.logging.log4j:log4j-slf4j-impl:${log4j_version}"
79+
cordaCompile "org.apache.logging.log4j:log4j-web:${log4j_version}"
80+
cordaCompile "org.slf4j:jul-to-slf4j:$slf4j_version"
81+
}
82+
83+
cordapp {
84+
info {
85+
name "Yo CorDapp"
86+
vendor "Corda Open Source"
87+
targetPlatformVersion corda_platform_version
88+
minimumPlatformVersion corda_platform_version
89+
}
90+
}
91+
92+
task deployNodesJava(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
93+
94+
nodeDefaults {
95+
projectCordapp {
96+
deploy = false
97+
}
98+
99+
cordapp project(':contracts')
100+
cordapp project(':workflows')
101+
102+
runSchemaMigration = false
103+
104+
extraConfig = [
105+
custom: [
106+
jvmArgs: ["-Dlog4j.configurationFile=config/dev/log4j2.xml"]
107+
]
108+
]
109+
}
110+
111+
node {
112+
name "O=Notary,L=London,C=GB"
113+
notary = [validating : false]
114+
p2pPort 10002
115+
rpcSettings {
116+
address("localhost:10003")
117+
adminAddress("localhost:10043")
118+
}
119+
}
120+
node {
121+
name "O=PartyA,L=London,C=GB"
122+
p2pPort 10005
123+
rpcSettings {
124+
address("localhost:10006")
125+
adminAddress("localhost:10046")
126+
}
127+
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
128+
}
129+
node {
130+
name "O=PartyB,L=New York,C=US"
131+
p2pPort 10008
132+
rpcSettings {
133+
address("localhost:10009")
134+
adminAddress("localhost:10049")
135+
}
136+
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
137+
}
138+
139+
}
140+
141+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Be aware that this is a configuration file for Apache log4j,
4+
This example file will log json files but there are many other configurations
5+
6+
You can also use files such as ../sql.xml as well.
7+
-->
8+
9+
<Configuration status="info">
10+
<Appenders>
11+
<Console name="ConsoleJSONAppender" target="SYSTEM_OUT">
12+
<JsonLayout complete="false" compact="true"/>
13+
</Console>
14+
<File name="FileJSONAppender" fileName="logs/node.json" immediateFlush="false" append="true">
15+
<JsonLayout complete="false" compact="true" properties="true" eventEol="true"/>
16+
</File>
17+
</Appenders>
18+
<Loggers>
19+
<Root level="info">
20+
<AppenderRef ref="ConsoleJSONAppender"/>
21+
<AppenderRef ref="FileJSONAppender"/>
22+
</Root>
23+
<Logger name="net.corda" level="info" additivity="false">
24+
<AppenderRef ref="ConsoleJSONAppender"/>
25+
<AppenderRef ref="FileJSONAppender"/>
26+
</Logger>
27+
<Logger name="com.r3.corda" level="info" additivity="false">
28+
<AppenderRef ref="ConsoleJSONAppender"/>
29+
<AppenderRef ref="FileJSONAppender"/>
30+
</Logger>
31+
<Logger name="org.hibernate" level="info" additivity="false">
32+
<AppenderRef ref="ConsoleJSONAppender"/>
33+
<AppenderRef ref="FileJSONAppender"/>
34+
</Logger>
35+
</Loggers>
36+
</Configuration>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration status="WARN">
3+
<Appenders>
4+
<Console name="Console" target="SYSTEM_OUT">
5+
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
6+
</Console>
7+
</Appenders>
8+
<Loggers>
9+
<Logger name="org.hibernate" level="debug" additivity="false">
10+
<AppenderRef ref="Console"/>
11+
</Logger>
12+
<Root level="error">
13+
<AppenderRef ref="Console"/>
14+
</Root>
15+
</Loggers>
16+
</Configuration>
17+

0 commit comments

Comments
 (0)