Skip to content

Commit

Permalink
FAB-15820 Handle query enhancements
Browse files Browse the repository at this point in the history
Change-Id: Icf663aecce454ddd77194b09ba8a9800e48dd507
Signed-off-by: rickr <cr22rc@gmail.com>
  • Loading branch information
cr22rc committed Jun 28, 2019
1 parent e0af668 commit d0f27c8
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 93 deletions.
68 changes: 34 additions & 34 deletions src/main/java/org/hyperledger/fabric/sdk/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@
import org.hyperledger.fabric.sdk.transaction.LifecycleApproveChaincodeDefinitionForMyOrgProposalBuilder;
import org.hyperledger.fabric.sdk.transaction.LifecycleCommitChaincodeDefinitionProposalBuilder;
import org.hyperledger.fabric.sdk.transaction.LifecycleInstallProposalBuilder;
import org.hyperledger.fabric.sdk.transaction.LifecycleQueryApprovalStatusBuilder;
import org.hyperledger.fabric.sdk.transaction.LifecycleQueryChaincodeDefinitionBuilder;
import org.hyperledger.fabric.sdk.transaction.LifecycleQueryInstalledChaincodeBuilder;
import org.hyperledger.fabric.sdk.transaction.LifecycleQueryInstalledChaincodesBuilder;
import org.hyperledger.fabric.sdk.transaction.LifecycleQueryNamespaceDefinitionsBuilder;
import org.hyperledger.fabric.sdk.transaction.LifecycleSimulateCommitChaincodeDefinitionBuilder;
import org.hyperledger.fabric.sdk.transaction.ProposalBuilder;
import org.hyperledger.fabric.sdk.transaction.ProtoUtils;
import org.hyperledger.fabric.sdk.transaction.QueryCollectionsConfigBuilder;
Expand Down Expand Up @@ -4059,16 +4059,16 @@ public Collection<LifecycleQueryNamespaceDefinitionsProposalResponse> lifecycleQ
/**
* Query approval status for all organizations.
*
* @param lifecycleQueryApprovalStatusRequest The request see {@link LifecycleQueryApprovalStatusRequest}
* @param lifecycleSimulateCommitChaincodeDefinitionRequest The request see {@link LifecycleSimulateCommitChaincodeDefinitionRequest}
* @param peers Peers to send the request. Usually only need one.
* @return A {@link LifecycleQueryApprovalStatusProposalResponse}
* @return A {@link LifecycleSimulateCommitChaincodeDefinitionProposalResponse}
* @throws InvalidArgumentException
* @throws ProposalException
*/
public Collection<LifecycleQueryApprovalStatusProposalResponse> sendLifecycleQueryApprovalStatusRequest(LifecycleQueryApprovalStatusRequest lifecycleQueryApprovalStatusRequest, Collection<Peer> peers) throws InvalidArgumentException, ProposalException {
public Collection<LifecycleSimulateCommitChaincodeDefinitionProposalResponse> sendLifecycleSimulateCommitChaincodeDefinitionRequest(LifecycleSimulateCommitChaincodeDefinitionRequest lifecycleSimulateCommitChaincodeDefinitionRequest, Collection<Peer> peers) throws InvalidArgumentException, ProposalException {

if (null == lifecycleQueryApprovalStatusRequest) {
throw new InvalidArgumentException("The lifecycleQueryApprovalStatusRequest parameter can not be null.");
if (null == lifecycleSimulateCommitChaincodeDefinitionRequest) {
throw new InvalidArgumentException("The lifecycleSimulateCommitChaincodeDefinitionRequest parameter can not be null.");
}

checkChannelState();
Expand All @@ -4080,66 +4080,66 @@ public Collection<LifecycleQueryApprovalStatusProposalResponse> sendLifecycleQue

String collectionData = "null";

final org.hyperledger.fabric.protos.common.Collection.CollectionConfigPackage chaincodeCollectionConfiguration = lifecycleQueryApprovalStatusRequest.getCollectionConfigPackage();
final org.hyperledger.fabric.protos.common.Collection.CollectionConfigPackage chaincodeCollectionConfiguration = lifecycleSimulateCommitChaincodeDefinitionRequest.getCollectionConfigPackage();
if (null != chaincodeCollectionConfiguration) {
final byte[] asBytes = chaincodeCollectionConfiguration.toByteArray();
if (null != asBytes) {
collectionData = toHexString(asBytes);
}
}

logger.trace(format("LifecycleQueryApprovalStatus channel: %s, sequence: %d, chaincodeName: %s, chaincodeVersion: %s" +
logger.trace(format("LifecycleSimulateCommitChaincodeDefinition channel: %s, sequence: %d, chaincodeName: %s, chaincodeVersion: %s" +
", isInitRequired: %s, validationParameter: '%s', endorsementPolicyPlugin: %s, validationPlugin: %s" +
", collectionConfiguration: %s",
name,
lifecycleQueryApprovalStatusRequest.getSequence(),
lifecycleQueryApprovalStatusRequest.getChaincodeName(),
lifecycleQueryApprovalStatusRequest.getChaincodeVersion(),

lifecycleQueryApprovalStatusRequest.isInitRequired() + "",
toHexString(lifecycleQueryApprovalStatusRequest.getValidationParameter()),
lifecycleQueryApprovalStatusRequest.getChaincodeEndorsementPlugin(),
lifecycleQueryApprovalStatusRequest.getChaincodeValidationPlugin(),
lifecycleSimulateCommitChaincodeDefinitionRequest.getSequence(),
lifecycleSimulateCommitChaincodeDefinitionRequest.getChaincodeName(),
lifecycleSimulateCommitChaincodeDefinitionRequest.getChaincodeVersion(),

lifecycleSimulateCommitChaincodeDefinitionRequest.isInitRequired() + "",
toHexString(lifecycleSimulateCommitChaincodeDefinitionRequest.getValidationParameter()),
lifecycleSimulateCommitChaincodeDefinitionRequest.getChaincodeEndorsementPlugin(),
lifecycleSimulateCommitChaincodeDefinitionRequest.getChaincodeValidationPlugin(),
collectionData));

}

TransactionContext context = getTransactionContext(lifecycleQueryApprovalStatusRequest);
TransactionContext context = getTransactionContext(lifecycleSimulateCommitChaincodeDefinitionRequest);

LifecycleQueryApprovalStatusBuilder lifecycleQueryApprovalStatusBuilder = LifecycleQueryApprovalStatusBuilder.newBuilder();
lifecycleQueryApprovalStatusBuilder.setSequence(lifecycleQueryApprovalStatusRequest.getSequence());
lifecycleQueryApprovalStatusBuilder.setName(lifecycleQueryApprovalStatusRequest.getChaincodeName());
lifecycleQueryApprovalStatusBuilder.setVersion(lifecycleQueryApprovalStatusRequest.getChaincodeVersion());
String endorsementPlugin = lifecycleQueryApprovalStatusRequest.getChaincodeEndorsementPlugin();
LifecycleSimulateCommitChaincodeDefinitionBuilder lifecycleSimulateCommitChaincodeDefinitionBuilder = LifecycleSimulateCommitChaincodeDefinitionBuilder.newBuilder();
lifecycleSimulateCommitChaincodeDefinitionBuilder.setSequence(lifecycleSimulateCommitChaincodeDefinitionRequest.getSequence());
lifecycleSimulateCommitChaincodeDefinitionBuilder.setName(lifecycleSimulateCommitChaincodeDefinitionRequest.getChaincodeName());
lifecycleSimulateCommitChaincodeDefinitionBuilder.setVersion(lifecycleSimulateCommitChaincodeDefinitionRequest.getChaincodeVersion());
String endorsementPlugin = lifecycleSimulateCommitChaincodeDefinitionRequest.getChaincodeEndorsementPlugin();
if (!isNullOrEmpty(endorsementPlugin)) {
lifecycleQueryApprovalStatusBuilder.setEndorsementPlugin(endorsementPlugin);
lifecycleSimulateCommitChaincodeDefinitionBuilder.setEndorsementPlugin(endorsementPlugin);
}
String validationPlugin = lifecycleQueryApprovalStatusRequest.getChaincodeValidationPlugin();
String validationPlugin = lifecycleSimulateCommitChaincodeDefinitionRequest.getChaincodeValidationPlugin();

if (!isNullOrEmpty(validationPlugin)) {
lifecycleQueryApprovalStatusBuilder.setValidationPlugin(validationPlugin);
lifecycleSimulateCommitChaincodeDefinitionBuilder.setValidationPlugin(validationPlugin);
}

ByteString validationParameter = lifecycleQueryApprovalStatusRequest.getValidationParameter();
ByteString validationParameter = lifecycleSimulateCommitChaincodeDefinitionRequest.getValidationParameter();
if (null != validationParameter) {
lifecycleQueryApprovalStatusBuilder.setValidationParameter(validationParameter);
lifecycleSimulateCommitChaincodeDefinitionBuilder.setValidationParameter(validationParameter);
}

org.hyperledger.fabric.protos.common.Collection.CollectionConfigPackage collectionConfigPackage = lifecycleQueryApprovalStatusRequest.getCollectionConfigPackage();
org.hyperledger.fabric.protos.common.Collection.CollectionConfigPackage collectionConfigPackage = lifecycleSimulateCommitChaincodeDefinitionRequest.getCollectionConfigPackage();

if (null != collectionConfigPackage) {
lifecycleQueryApprovalStatusBuilder.setCollections(collectionConfigPackage);
lifecycleSimulateCommitChaincodeDefinitionBuilder.setCollections(collectionConfigPackage);
}

Boolean initRequired = lifecycleQueryApprovalStatusRequest.isInitRequired();
Boolean initRequired = lifecycleSimulateCommitChaincodeDefinitionRequest.isInitRequired();
if (null != initRequired) {
lifecycleQueryApprovalStatusBuilder.setInitRequired(initRequired);
lifecycleSimulateCommitChaincodeDefinitionBuilder.setInitRequired(initRequired);
}

lifecycleQueryApprovalStatusBuilder.context(context);
lifecycleSimulateCommitChaincodeDefinitionBuilder.context(context);

SignedProposal qProposal = getSignedProposal(context, lifecycleQueryApprovalStatusBuilder.build());
return sendProposalToPeers(peers, qProposal, context, LifecycleQueryApprovalStatusProposalResponse.class);
SignedProposal qProposal = getSignedProposal(context, lifecycleSimulateCommitChaincodeDefinitionBuilder.build());
return sendProposalToPeers(peers, qProposal, context, LifecycleSimulateCommitChaincodeDefinitionProposalResponse.class);

} catch (Exception e) {
throw new ProposalException(format("QueryNamespaceDefinitions %s channel failed. " + e.getMessage(), name), e);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/hyperledger/fabric/sdk/HFClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,12 @@ public LifecycleApproveChaincodeDefinitionForMyOrgRequest newLifecycleApproveCha
}

/**
* Get a LifecycleQueryApprovalStatusRequest to find which chaincodes are approved by which organization.
* Get a LifecycleSimulateCommitChaincodeDefinitionRequest to find which chaincodes are approved by which organization.
*
* @return
*/
public LifecycleQueryApprovalStatusRequest newLifecycleQueryApprovalStatusRequest() {
return new LifecycleQueryApprovalStatusRequest(userContext);
public LifecycleSimulateCommitChaincodeDefinitionRequest newLifecycleSimulateCommitChaincodeDefinitionRequest() {
return new LifecycleSimulateCommitChaincodeDefinitionRequest(userContext);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@
import static java.lang.String.format;

/**
* Returns the response for a LifecycleQueryApprovalStatus showing what organizations have or have not approved yet.
* Returns the response for a LifecycleSimulateCommitChaincodeDefinitionStatus showing what organizations have or have not approved yet.
*/
public class LifecycleQueryApprovalStatusProposalResponse extends ProposalResponse {
LifecycleQueryApprovalStatusProposalResponse(TransactionContext transactionContext, int status, String message) {
public class LifecycleSimulateCommitChaincodeDefinitionProposalResponse extends ProposalResponse {
LifecycleSimulateCommitChaincodeDefinitionProposalResponse(TransactionContext transactionContext, int status, String message) {
super(transactionContext, status, message);
}

Lifecycle.QueryApprovalStatusResults queryApprovalStatusResults;
Lifecycle.SimulateCommitChaincodeDefinitionResult simulateCommitChaincodeDefinitionResults;

private Lifecycle.QueryApprovalStatusResults parsePayload() throws ProposalException {
private Lifecycle.SimulateCommitChaincodeDefinitionResult parsePayload() throws ProposalException {

if (null == queryApprovalStatusResults) {
if (null == simulateCommitChaincodeDefinitionResults) {

if (getStatus() != Status.SUCCESS) {
throw new ProposalException(format("Fabric response failed on peer %s %s", getPeer(), getMessage()));
Expand All @@ -52,16 +52,16 @@ private Lifecycle.QueryApprovalStatusResults parsePayload() throws ProposalExcep
}

try {
queryApprovalStatusResults = Lifecycle.QueryApprovalStatusResults.parseFrom(payload);
simulateCommitChaincodeDefinitionResults = Lifecycle.SimulateCommitChaincodeDefinitionResult.parseFrom(payload);
} catch (Exception e) {
throw new ProposalException(format("Failure on peer %s %s", getPeer(), e.getMessage()), e);
}
}

return queryApprovalStatusResults;
return simulateCommitChaincodeDefinitionResults;
}

public Lifecycle.QueryApprovalStatusResults getApprovalStatusResults() throws ProposalException {
public Lifecycle.SimulateCommitChaincodeDefinitionResult getApprovalStatusResults() throws ProposalException {

return parsePayload();

Expand Down Expand Up @@ -100,7 +100,7 @@ public Set<String> getUnApprovedOrgs() throws ProposalException {
*/
public Map<String, Boolean> getApprovalMap() throws ProposalException {

Lifecycle.QueryApprovalStatusResults rs = getApprovalStatusResults();
Lifecycle.SimulateCommitChaincodeDefinitionResult rs = getApprovalStatusResults();
if (rs == null) {
return Collections.emptyMap();
}
Expand All @@ -109,7 +109,7 @@ public Map<String, Boolean> getApprovalMap() throws ProposalException {

private void sort() throws ProposalException {

Lifecycle.QueryApprovalStatusResults rs = getApprovalStatusResults();
Lifecycle.SimulateCommitChaincodeDefinitionResult rs = getApprovalStatusResults();
if (null != rs) {
if (null != approved) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import static org.hyperledger.fabric.sdk.helper.Utils.isNullOrEmpty;

/**
* LifecycleQueryApprovalStatusRequest queries the approval status of organizations for chaincode sequence.
* LifecycleSimulateCommitChaincodeDefinitionRequest queries the approval status of organizations for chaincode sequence.
*/
public class LifecycleQueryApprovalStatusRequest extends LifecycleRequest {
public class LifecycleSimulateCommitChaincodeDefinitionRequest extends LifecycleRequest {

static Config config = Config.getConfig();
static Boolean lifecycleInitRequiredDefault = null;
Expand All @@ -37,7 +37,7 @@ public class LifecycleQueryApprovalStatusRequest extends LifecycleRequest {
private Boolean initRequired;
private ByteString validationParameter;

LifecycleQueryApprovalStatusRequest(User userContext) {
LifecycleSimulateCommitChaincodeDefinitionRequest(User userContext) {
super(userContext);
if (!isNullOrEmpty(config.getDefaultChaincodeEndorsementPlugin())) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.hyperledger.fabric.sdk.helper.Config;
import org.hyperledger.fabric.sdk.helper.Utils;

public class LifecycleQueryApprovalStatusBuilder extends LifecycleProposalBuilder {
public class LifecycleSimulateCommitChaincodeDefinitionBuilder extends LifecycleProposalBuilder {
static Config config = Config.getConfig();

static Boolean lifecycleInitRequiredDefault = null;
Expand All @@ -29,17 +29,17 @@ public class LifecycleQueryApprovalStatusBuilder extends LifecycleProposalBuilde
lifecycleInitRequiredDefault = config.getLifecycleInitRequiredDefault();
}

private final Lifecycle.QueryApprovalStatusArgs.Builder builder = Lifecycle.QueryApprovalStatusArgs.newBuilder();
private final Lifecycle.SimulateCommitChaincodeDefinitionArgs.Builder builder = Lifecycle.SimulateCommitChaincodeDefinitionArgs.newBuilder();

private LifecycleQueryApprovalStatusBuilder() {
private LifecycleSimulateCommitChaincodeDefinitionBuilder() {

if (null != lifecycleInitRequiredDefault) {
builder.setInitRequired(lifecycleInitRequiredDefault);
}
}

@Override
public LifecycleQueryApprovalStatusBuilder context(TransactionContext context) {
public LifecycleSimulateCommitChaincodeDefinitionBuilder context(TransactionContext context) {
super.context(context);
if (!Utils.isNullOrEmpty(config.getDefaultChaincodeEndorsementPlugin())) {

Expand All @@ -58,8 +58,8 @@ public LifecycleQueryApprovalStatusBuilder context(TransactionContext context) {
return this;
}

public static LifecycleQueryApprovalStatusBuilder newBuilder() {
return new LifecycleQueryApprovalStatusBuilder();
public static LifecycleSimulateCommitChaincodeDefinitionBuilder newBuilder() {
return new LifecycleSimulateCommitChaincodeDefinitionBuilder();
}

public void setSequence(long sequence) {
Expand Down Expand Up @@ -98,7 +98,7 @@ public void setInitRequired(boolean initRequired) {
public FabricProposal.Proposal build() throws ProposalException, InvalidArgumentException {

List<ByteString> argList = new ArrayList<>();
argList.add(ByteString.copyFromUtf8("QueryApprovalStatus"));
argList.add(ByteString.copyFromUtf8("SimulateCommitChaincodeDefinition"));
argList.add(builder.build().toByteString());
args(argList);
return super.build();
Expand Down
3 changes: 1 addition & 2 deletions src/main/proto/discovery/protocol.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ package discovery;
// like which peers, orderers, chaincodes, etc.
service Discovery {
// Discover receives a signed request, and returns a response.
rpc Discover (SignedRequest) returns (Response) {
}
rpc Discover (SignedRequest) returns (Response);
}

// SignedRequest contains a serialized Request in the payload field
Expand Down
6 changes: 2 additions & 4 deletions src/main/proto/gossip/message.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ import "common/collection.proto";
service Gossip {

// GossipStream is the gRPC stream used for sending and receiving messages
rpc GossipStream (stream Envelope) returns (stream Envelope) {
}
rpc GossipStream (stream Envelope) returns (stream Envelope);

// Ping is used to probe a remote peer's aliveness
rpc Ping (Empty) returns (Empty) {
}
rpc Ping (Empty) returns (Empty);
}

// Envelope contains a marshalled
Expand Down
4 changes: 2 additions & 2 deletions src/main/proto/orderer/ab.proto
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ message DeliverResponse {

service AtomicBroadcast {
// broadcast receives a reply of Acknowledgement for each common.Envelope in order, indicating success or type of failure
rpc Broadcast(stream common.Envelope) returns (stream BroadcastResponse) {}
rpc Broadcast (stream common.Envelope) returns (stream BroadcastResponse);

// deliver first requires an Envelope of type DELIVER_SEEK_INFO with Payload data as a mashaled SeekInfo message, then a stream of block replies is received.
rpc Deliver(stream common.Envelope) returns (stream DeliverResponse) {}
rpc Deliver (stream common.Envelope) returns (stream DeliverResponse);
}
15 changes: 7 additions & 8 deletions src/main/proto/peer/lifecycle/lifecycle.proto
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ message CommitChaincodeDefinitionArgs {
message CommitChaincodeDefinitionResult {
}

// QueryApprovalStatusArgs is the message used as arguments to
// `_lifecycle.QueryApprovalStatus`
message QueryApprovalStatusArgs {
// SimulateCommitChaincodeDefinitionArgs is the message used as arguments to
// `_lifecycle.SimulateCommitChaincodeDefinition`.
message SimulateCommitChaincodeDefinitionArgs {
int64 sequence = 1;
string name = 2;
string version = 3;
Expand All @@ -122,11 +122,10 @@ message QueryApprovalStatusArgs {
bool init_required = 8;
}

// QueryApprovalStatusResults is the message returned by
// `_lifecycle.QueryApprovalStatus`. It returns a map of
// orgs to their approval (true/false) for the definition
// supplied as args
message QueryApprovalStatusResults {
// SimulateCommitChaincodeDefinitionResult is the message returned by
// `_lifecycle.SimulateCommitChaincodeDefinition`. It returns a map of
// orgs to their approval (true/false) for the definition supplied as args.
message SimulateCommitChaincodeDefinitionResult {
map<string, bool> approved = 1;
}

Expand Down
Loading

0 comments on commit d0f27c8

Please sign in to comment.