forked from hyperledger/fabric-chaincode-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A fairly sizeable CR for improving the load handling ability of the Java chaincode. This required a rework of the threading model within the core shim layer. Plus adding configuration and metrics to support this. The configuration is a simple Java props file should the need be to ever modify the default thread pool settings. Metrics are basic stats on the thread pool are written to the log Change-Id: I31b05585a0aa650f7e2a7e2b0389799e90adc2c3 Signed-off-by: Matthew B. White <[email protected]> (cherry picked from commit baaaef8)
- Loading branch information
Showing
53 changed files
with
2,488 additions
and
2,072 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
*.swp | ||
.gradletasknamecache | ||
.classpath | ||
/bin/ | ||
**/bin/ | ||
/build/ | ||
build/* | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...de-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/FabricState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperleder.fabric.shim.integration; | ||
|
||
import org.hyperleder.fabric.shim.integration.DockerCompose.DockerComposeBuilder; | ||
|
||
public class FabricState { | ||
|
||
private static FabricState state; | ||
|
||
public static FabricState getState(){ | ||
if (state==null){ | ||
state = new FabricState(); | ||
} | ||
|
||
return state; | ||
} | ||
|
||
private boolean started = false; | ||
|
||
public synchronized void start(){ | ||
if (!this.started) { | ||
|
||
// create the docker-compose command | ||
DockerComposeBuilder composebuilder = DockerCompose.newBuilder() | ||
.file("src/test/resources/first-network/docker-compose-cli.yaml"); | ||
|
||
// close down anything running... | ||
composebuilder.duplicate().down().build().run(); | ||
|
||
// ...and bring up | ||
DockerCompose compose = composebuilder.up().detach().build(); | ||
compose.run(); | ||
|
||
this.started = true; | ||
} else { | ||
System.out.println("Fabric already started...."); | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/Logging.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.fabric; | ||
|
||
import java.io.PrintWriter; | ||
import java.io.StringWriter; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.logging.Level; | ||
import java.util.logging.LogManager; | ||
|
||
/** | ||
* Assistance class to use when logging. | ||
* | ||
* For chaincode/contract implementations please use java.util.logging or your | ||
* own framework. All the Hyperledger Fabric code here is logged in loggers with | ||
* names starting org.hyperledger | ||
* | ||
* Control of this is via the environment variables | ||
* 'CORE_CHAINCODE_LOGGING_LEVEL' this takes a string that matches the following | ||
* Java.util.logging levels (case insensitive) | ||
* | ||
* CRITICAL, ERROR == Level.SEVERE, WARNING == Level.WARNING, INFO == Level.INFO | ||
* NOTICE == Level.CONFIG, DEBUG == Level.FINEST | ||
* | ||
*/ | ||
public class Logging { | ||
|
||
public static final String PERFLOGGER = "org.hyperledger.Performance"; | ||
|
||
/** | ||
* Formats a Throwable to a string with details of all the causes as well | ||
* | ||
* @param throwable Exception | ||
* @return String formatted with all the details | ||
*/ | ||
public static String formatError(final Throwable throwable) { | ||
if (throwable == null) { | ||
return null; | ||
} | ||
final StringWriter buffer = new StringWriter(); | ||
buffer.append(throwable.getMessage()).append(System.lineSeparator()); | ||
|
||
throwable.printStackTrace(new PrintWriter(buffer)); | ||
|
||
final Throwable cause = throwable.getCause(); | ||
if (cause != null) { | ||
buffer.append(".. caused by ..").append(System.lineSeparator()); | ||
buffer.append(Logging.formatError(cause)); | ||
} | ||
|
||
return buffer.toString(); | ||
|
||
} | ||
|
||
/** | ||
* Sets the log level to the the | ||
* @param newLevel the new logging level | ||
*/ | ||
public static void setLogLevel(String newLevel) { | ||
|
||
Level l = mapLevel(newLevel); | ||
LogManager logManager = LogManager.getLogManager(); | ||
// slightly cumbersome approach - but the loggers don't have a 'get children' | ||
// so find those that have the correct stem. | ||
final ArrayList<String> allLoggers = Collections.list(logManager.getLoggerNames()); | ||
allLoggers.add("org.hyperledger"); | ||
allLoggers.stream().filter(name -> name.startsWith("org.hyperledger")).map(name -> logManager.getLogger(name)) | ||
.forEach(logger -> { | ||
if (logger != null) { | ||
logger.setLevel(l); | ||
} | ||
}); | ||
} | ||
|
||
private static Level mapLevel(final String level) { | ||
if (level != null) { | ||
switch (level.toUpperCase().trim()) { | ||
case "ERROR": | ||
case "CRITICAL": | ||
return Level.SEVERE; | ||
case "WARNING": | ||
return Level.WARNING; | ||
case "INFO": | ||
return Level.INFO; | ||
case "NOTICE": | ||
return Level.CONFIG; | ||
case "DEBUG": | ||
return Level.FINEST; | ||
} | ||
} | ||
return Level.INFO; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.