Update config for demo
Set up easy switch between environment, chaincode and database.
This commit is contained in:
parent
c6e53fd9d2
commit
177dbe1f0d
|
@ -1,6 +1,7 @@
|
|||
package blockchain.client;
|
||||
|
||||
|
||||
import blockchain.configuration.AppConfig;
|
||||
import blockchain.configuration.Config;
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.apache.log4j.Logger;
|
||||
|
@ -56,12 +57,11 @@ public class ChannelClientWrapper {
|
|||
|
||||
//Method to init the channel for query
|
||||
static public ChannelClientWrapper setupChannel(FabricClientWrapper fabricClientWrapper) throws InvalidArgumentException, TransactionException {
|
||||
|
||||
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
|
||||
|
||||
channel = channelClientWrapper.getChannel();
|
||||
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
||||
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
||||
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,AppConfig.getPEER_0_URL());
|
||||
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,AppConfig.getORDERER_URL());
|
||||
channel.addPeer(peer);
|
||||
channel.addOrderer(orderer);
|
||||
channel.initialize();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package blockchain.client;
|
||||
|
||||
import blockchain.configuration.AppConfig;
|
||||
import blockchain.configuration.Config;
|
||||
import blockchain.user.UserContext;
|
||||
import org.hyperledger.fabric.sdk.*;
|
||||
|
@ -28,15 +29,13 @@ public class FabricClientWrapper {
|
|||
|
||||
public ChannelClientWrapper createChannelClient(String name) throws InvalidArgumentException {
|
||||
Channel channel = client.newChannel(name);
|
||||
ChannelClientWrapper channelClientWrapper = new ChannelClientWrapper(name, channel, this);
|
||||
return channelClientWrapper;
|
||||
return new ChannelClientWrapper(name, channel, this);
|
||||
}
|
||||
|
||||
public Set<String> queryForChannels() throws InvalidArgumentException, IllegalArgumentException, ProposalException {
|
||||
client.newChannel(Config.CHANNEL_NAME);
|
||||
client.newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
||||
//Peer peer = client.newPeer(Config.ORG_PEER,Config.ORG_PEER_URL);
|
||||
Peer peer = client.newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
||||
client.newOrderer(Config.ORDERER_NAME,AppConfig.getORDERER_URL());
|
||||
Peer peer = client.newPeer(Config.ORG1_PEER_0,AppConfig.getPEER_0_URL());
|
||||
return client.queryChannels(peer);
|
||||
}
|
||||
}
|
||||
|
|
56
src/main/java/blockchain/configuration/AppConfig.java
Normal file
56
src/main/java/blockchain/configuration/AppConfig.java
Normal file
|
@ -0,0 +1,56 @@
|
|||
package blockchain.configuration;
|
||||
|
||||
public class AppConfig {
|
||||
// 0 = Actual & 1 = Back-up
|
||||
private static int ENV = 0;
|
||||
// 0 = QA & 1 = PROD & 2 = TEST
|
||||
private static int CHAINCODE_IDX = 0;
|
||||
|
||||
public static String getCA_URL(){
|
||||
if(ENV==0){
|
||||
return "http://vps577432.ovh.net:7054";
|
||||
} else {
|
||||
return "http://93.30.148.59:7054";
|
||||
}
|
||||
}
|
||||
|
||||
public static String getORDERER_URL(){
|
||||
if(ENV==0){
|
||||
return "grpc://vps577432.ovh.net:7050";
|
||||
}else {
|
||||
return "grpc://93.30.148.59:7050";
|
||||
}
|
||||
}
|
||||
|
||||
public static String getPEER_0_URL(){
|
||||
if(ENV==0){
|
||||
return "grpc://vps577432.ovh.net:7051";
|
||||
} else {
|
||||
return "grpc://93.30.148.59:7051";
|
||||
}
|
||||
}
|
||||
|
||||
public static String getCHAINCODE(){
|
||||
if(CHAINCODE_IDX==0 || CHAINCODE_IDX==2){
|
||||
return "monnethic_qa";
|
||||
}else {
|
||||
return "monnethic-prod";
|
||||
}
|
||||
}
|
||||
|
||||
public static String getDATABASE(){
|
||||
if(CHAINCODE_IDX==0){
|
||||
return "monnethic_qa";
|
||||
}else if(CHAINCODE_IDX==1) {
|
||||
return "monnethic_prod";
|
||||
}else{
|
||||
return "monnethic_test";
|
||||
}
|
||||
}
|
||||
|
||||
public static void setENV(int newEnv){
|
||||
ENV = newEnv;
|
||||
}
|
||||
public static String getENV(){ return String.valueOf(ENV); }
|
||||
public static void setCHAINCODE_IDX(int newChaincode){ CHAINCODE_IDX = newChaincode; }
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package blockchain.configuration;
|
||||
|
||||
public class Config {
|
||||
|
||||
//ORGANIZATION
|
||||
public static final String ORG1_MSP = "Org1MSP";
|
||||
public static final String ORG1 = "org1";
|
||||
|
@ -10,49 +9,19 @@ public class Config {
|
|||
public static final String ADMIN = "admin";
|
||||
public static final String ADMIN_PASSWORD = "adminpw";
|
||||
|
||||
//USER
|
||||
public static final String UserPWD = "OelXVCdHnYPe";
|
||||
|
||||
|
||||
|
||||
//CA
|
||||
//public static final String CA_ORG1_URL = "http://127.0.0.1:7054";
|
||||
public static final String CA_ORG1_URL = "http://vps577432.ovh.net:7054";
|
||||
//public static final String CA_ORG1_URL = "http://93.30.148.59:7054";
|
||||
//public static final String CA_ORG1_URL = "http://vps592802.ovh.net:7054";
|
||||
|
||||
//ORDERER
|
||||
//public static final String ORDERER_URL = "grpc://127.0.0.1:7050";
|
||||
public static final String ORDERER_URL = "grpc://vps577432.ovh.net:7050";
|
||||
//public static final String ORDERER_URL = "grpc://93.30.148.59:7050";
|
||||
//public static final String ORDERER_URL = "grpc://vps592802.ovh.net:7050";
|
||||
|
||||
//ORDERER NAME
|
||||
public static final String ORDERER_NAME = "orderer.example.com";
|
||||
|
||||
//CHANNEL - CHAINCODE
|
||||
//CHANNEL NAME
|
||||
public static final String CHANNEL_NAME = "mychannel";
|
||||
|
||||
//public static final String CHAINCODE_NAME = "monnethic";
|
||||
public static final String CHAINCODE_NAME = "monnethic_qa";
|
||||
//public static final String CHAINCODE_PROD = "monnethic-prod";
|
||||
|
||||
//PEER 0
|
||||
//PEER 0 NAME
|
||||
public static final String ORG1_PEER_0 = "peer0.org1.example.com";
|
||||
|
||||
//public static final String ORG1_PEER_0_URL = "grpc://127.0.0.1:7051";
|
||||
public static final String ORG1_PEER_0_URL = "grpc://vps577432.ovh.net:7051";
|
||||
//public static final String ORG1_PEER_0_URL = "grpc://93.30.148.59:7051";
|
||||
//ublic static final String ORG1_PEER_0_URL = "grpc://vps592802.ovh.net:7051";
|
||||
|
||||
//USER
|
||||
//public static final String UserPWD = "OelXVCdHnYPe";
|
||||
|
||||
//PEER 1
|
||||
public static final String ORG_PEER = "peer1.org1.example.com";
|
||||
public static final String ORG_PEER_URL = "grpc://vps592802.ovh.net:9051";
|
||||
|
||||
|
||||
//ADMIN FILE TEST
|
||||
//public static final String ADMIN_FILE_PATH = "msp/AdminFiles";
|
||||
//public static final String ADMIN_KEY_PATH = ADMIN_FILE_PATH+"/keystore";
|
||||
//public static final String ADMIN_CERT_PATH = ADMIN_FILE_PATH+"/admincerts";
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package blockchain.query;
|
|||
|
||||
import blockchain.client.ChannelClientWrapper;
|
||||
import blockchain.client.FabricClientWrapper;
|
||||
import blockchain.configuration.AppConfig;
|
||||
import blockchain.configuration.Config;
|
||||
import blockchain.user.UserContext;
|
||||
import blockchain.utility.Util;
|
||||
|
@ -23,7 +24,7 @@ public class QueryWrapper {
|
|||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
||||
ChannelClientWrapper channelClientWrapper = ChannelClientWrapper.setupChannel(fabricClientWrapper);
|
||||
|
||||
ChaincodeID chaincodeID = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
||||
ChaincodeID chaincodeID = ChaincodeID.newBuilder().setName(AppConfig.getCHAINCODE()).build();
|
||||
QueryByChaincodeRequest queryByChaincodeRequest = fabricClientWrapper.getClient().newQueryProposalRequest();
|
||||
queryByChaincodeRequest.setArgs(args);
|
||||
queryByChaincodeRequest.setFcn(functionName);
|
||||
|
|
|
@ -2,6 +2,7 @@ package blockchain.query;
|
|||
|
||||
import blockchain.client.ChannelClientWrapper;
|
||||
import blockchain.client.FabricClientWrapper;
|
||||
import blockchain.configuration.AppConfig;
|
||||
import blockchain.configuration.Config;
|
||||
import blockchain.user.UserContext;
|
||||
import blockchain.utility.Util;
|
||||
|
@ -29,16 +30,16 @@ public class TransactionWrapper {
|
|||
|
||||
//INIT CHANNEL FOR QUERY
|
||||
Channel channel = channelClientWrapper.getChannel();
|
||||
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
||||
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,AppConfig.getORDERER_URL());
|
||||
channel.addOrderer(orderer);
|
||||
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
||||
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,AppConfig.getPEER_0_URL());
|
||||
channel.addPeer(peer);
|
||||
channel.initialize();
|
||||
//
|
||||
|
||||
//Prepare transaction
|
||||
TransactionProposalRequest tpr = fabricClientWrapper.getClient().newTransactionProposalRequest();
|
||||
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
||||
ChaincodeID cid = ChaincodeID.newBuilder().setName(AppConfig.getCHAINCODE()).build();
|
||||
tpr.setChaincodeID(cid);
|
||||
tpr.setFcn(functionName);
|
||||
tpr.setArgs(args);
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
package database;
|
||||
|
||||
import blockchain.configuration.AppConfig;
|
||||
import com.j256.ormlite.jdbc.JdbcConnectionSource;
|
||||
import com.j256.ormlite.support.ConnectionSource;
|
||||
|
||||
public class DatabaseHelper {
|
||||
//private static final String DATABASE_NAME = "monnethic_test";
|
||||
private static final String DATABASE_NAME = "monnethic_qa";
|
||||
private static final String DATABASE_USER = "monnethicadmin";
|
||||
private static final String DATABASE_PWD = "vHEQszGXcJ6;/)}z!V";
|
||||
private final static String DATABASE_URL = "jdbc:postgresql://37.187.101.44:5432/"+DATABASE_NAME;
|
||||
private final static String DATABASE_URL = "jdbc:postgresql://37.187.101.44:5432/"+AppConfig.getDATABASE();
|
||||
|
||||
private static JdbcConnectionSource jdbcConnectionSource;
|
||||
|
||||
|
@ -29,6 +28,4 @@ public class DatabaseHelper {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -4,8 +4,6 @@ import blockchain.query.TransactionWrapper;
|
|||
import database.user.User;
|
||||
import database.user.UserDao;
|
||||
import org.springframework.security.crypto.bcrypt.BCrypt;
|
||||
|
||||
import javax.json.JsonArray;
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
|
76
src/main/java/restService/ConfigResource.java
Normal file
76
src/main/java/restService/ConfigResource.java
Normal file
|
@ -0,0 +1,76 @@
|
|||
package restService;
|
||||
|
||||
import blockchain.configuration.AppConfig;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/api/rest/demo/conf")
|
||||
public class ConfigResource {
|
||||
// ENVIRONMENT
|
||||
@RequestMapping(value = "/env", method = RequestMethod.POST, produces = "application/json")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResponseEntity setEnvironment(@RequestBody Map<String,String> requestParam){
|
||||
try{
|
||||
int newEnv = Integer.parseInt(requestParam.get("env"));
|
||||
AppConfig.setENV(newEnv);
|
||||
return ResponseEntity.status(HttpStatus.OK).body("");
|
||||
}catch (Exception e){
|
||||
String r = "{\"response\":\""+e.getMessage()+"\"}";
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/env", method = RequestMethod.GET, produces = "application/json")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResponseEntity getEnvironment(){
|
||||
try{
|
||||
return ResponseEntity.status(HttpStatus.OK).body("{\"env\":"+AppConfig.getENV()+"}");
|
||||
}catch (Exception e){
|
||||
String r = "{\"response\":\""+e.getMessage()+"\"}";
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// CHAINCODE
|
||||
@RequestMapping(value = "/chaincode", method = RequestMethod.POST, produces = "application/json")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResponseEntity setChaincode(@RequestBody Map<String,String> requestParam){
|
||||
try{
|
||||
int newChaincode= Integer.parseInt(requestParam.get("chaincode"));
|
||||
AppConfig.setCHAINCODE_IDX(newChaincode);
|
||||
return ResponseEntity.status(HttpStatus.OK).body("");
|
||||
}catch (Exception e){
|
||||
String r = "{\"response\":\""+e.getMessage()+"\"}";
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/chaicode", method = RequestMethod.GET, produces = "application/json")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResponseEntity getChaincode(){
|
||||
try{
|
||||
return ResponseEntity.status(HttpStatus.OK).body("{\"chaincode\":"+AppConfig.getCHAINCODE()+"}");
|
||||
}catch (Exception e){
|
||||
String r = "{\"response\":\""+e.getMessage()+"\"}";
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// DATABASE
|
||||
@RequestMapping(value = "/db", method = RequestMethod.GET, produces = "application/json")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResponseEntity getDb(){
|
||||
try{
|
||||
return ResponseEntity.status(HttpStatus.OK).body("{\"db\":"+AppConfig.getDATABASE()+"}");
|
||||
}catch (Exception e){
|
||||
String r = "{\"response\":\""+e.getMessage()+"\"}";
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,13 +20,11 @@ public class UserResource {
|
|||
Map<String,String> userHashResponse = userImplementation.registerUser(user);
|
||||
|
||||
if(Boolean.parseBoolean(userHashResponse.get("response"))){
|
||||
|
||||
//TEMPORARY AUTOMATIC APPROVE
|
||||
user.setUser_hash(userHashResponse.get("user_hash"));
|
||||
userImplementation.approveUser(user);
|
||||
// TEMPORARY AUTOMATIC APPROVE
|
||||
// user.setUser_hash(userHashResponse.get("user_hash"));
|
||||
// userImplementation.approveUser(user);
|
||||
//
|
||||
|
||||
//StringResponse responseS = new StringResponse("Ok",userHashResponse.get("user_hash"));
|
||||
String r = "{\"response\":\"ok\",\"user_hash\":\""+userHashResponse.get("user_hash")+"\"}";
|
||||
return ResponseEntity.status(HttpStatus.OK).body(r);
|
||||
}else {
|
||||
|
@ -68,10 +66,6 @@ public class UserResource {
|
|||
String r = "{\"response\":\"Wrong authentication\"}";
|
||||
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(r);
|
||||
}
|
||||
case "" :{
|
||||
String r = "{\"response\":\"Error\"}";
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
|
||||
}
|
||||
case "true":{
|
||||
String r = "{\"response\":\"ok\",\"user_hash\":\""+response.get("user_hash")+"\"}";
|
||||
return ResponseEntity.status(HttpStatus.OK).body(r);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package restService;
|
||||
|
||||
import blockchain.client.CAClientWrapper;
|
||||
import blockchain.configuration.AppConfig;
|
||||
import blockchain.configuration.Config;
|
||||
import blockchain.user.UserContext;
|
||||
import org.hyperledger.fabric.sdk.Enrollment;
|
||||
|
@ -19,7 +20,7 @@ public class WelcomeResource {
|
|||
@RequestMapping("/bc/register/admin")
|
||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
public void registerAdminApp(){
|
||||
String caUrl = Config.CA_ORG1_URL;
|
||||
String caUrl = AppConfig.getCA_URL();
|
||||
try {
|
||||
CAClientWrapper caClientWrapper = new CAClientWrapper(caUrl,null);
|
||||
UserContext adminContext = new UserContext();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package blockchain.client;
|
||||
|
||||
import blockchain.configuration.AppConfig;
|
||||
import blockchain.configuration.Config;
|
||||
import blockchain.user.UserContext;
|
||||
import org.hyperledger.fabric.sdk.Enrollment;
|
||||
|
@ -13,7 +14,7 @@ import static org.junit.Assert.assertEquals;
|
|||
public class TestEnrollAdmin {
|
||||
@Test
|
||||
public void TestAEnrollAdmin(){
|
||||
String caUrl = Config.CA_ORG1_URL;
|
||||
String caUrl = AppConfig.getCA_URL();
|
||||
try {
|
||||
CAClientWrapper caClientWrapper = new CAClientWrapper(caUrl,null);
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package blockchain.client;
|
||||
|
||||
import blockchain.configuration.AppConfig;
|
||||
import blockchain.configuration.Config;
|
||||
import blockchain.user.UserContext;
|
||||
import blockchain.utility.Util;
|
||||
|
@ -14,7 +15,7 @@ public class TestRegisterEnrollUser {
|
|||
//Success
|
||||
@Test
|
||||
public void RegisterEnrollUser(){
|
||||
String caUrl = Config.CA_ORG1_URL;
|
||||
String caUrl = AppConfig.getCA_URL();
|
||||
try{
|
||||
CAClientWrapper caClientWrapper = new CAClientWrapper(caUrl,null);
|
||||
UserContext admin = Util.readUserContext(Config.ORG1,Config.ADMIN);
|
||||
|
|
Loading…
Reference in a new issue