-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce Anchor peer API and other refractoring
Signed-off-by: n0s09by <Nidhi.singh0@walmart.com>
- Loading branch information
1 parent
75664d6
commit a73e2bb
Showing
12 changed files
with
492 additions
and
190 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
10 changes: 10 additions & 0 deletions
10
src/main/java/hlf/java/rest/client/model/AnchorPeerParamsDTO.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,10 @@ | ||
package hlf.java.rest.client.model; | ||
|
||
import java.util.List; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class AnchorPeerParamsDTO { | ||
private String organizationMspId; | ||
private List<AnchorPeerDTO> anchorPeerDTOs; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/hlf/java/rest/client/service/AddAnchorPeerToChannelWriteSetBuilder.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,11 @@ | ||
package hlf.java.rest.client.service; | ||
|
||
import hlf.java.rest.client.exception.ServiceException; | ||
import hlf.java.rest.client.model.AnchorPeerParamsDTO; | ||
import org.hyperledger.fabric.protos.common.Configtx.ConfigGroup; | ||
|
||
public interface AddAnchorPeerToChannelWriteSetBuilder { | ||
|
||
ConfigGroup buildWriteSetForAnchorPeers( | ||
ConfigGroup readset, AnchorPeerParamsDTO anchorPeerParamsDTO) throws ServiceException; | ||
} |
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
91 changes: 91 additions & 0 deletions
91
...ain/java/hlf/java/rest/client/service/impl/AddAnchorPeerToChannelWriteSetBuilderImpl.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,91 @@ | ||
package hlf.java.rest.client.service.impl; | ||
|
||
import hlf.java.rest.client.exception.ServiceException; | ||
import hlf.java.rest.client.model.AnchorPeerDTO; | ||
import hlf.java.rest.client.model.AnchorPeerParamsDTO; | ||
import hlf.java.rest.client.service.AddAnchorPeerToChannelWriteSetBuilder; | ||
import hlf.java.rest.client.util.FabricChannelUtil; | ||
import hlf.java.rest.client.util.FabricClientConstants; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.hyperledger.fabric.protos.common.Configtx.ConfigGroup; | ||
import org.hyperledger.fabric.protos.common.Configtx.ConfigValue; | ||
import org.hyperledger.fabric.protos.peer.Configuration.AnchorPeer; | ||
import org.hyperledger.fabric.protos.peer.Configuration.AnchorPeers; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class AddAnchorPeerToChannelWriteSetBuilderImpl | ||
implements AddAnchorPeerToChannelWriteSetBuilder { | ||
|
||
private AnchorPeerParamsDTO anchorPeerParamsDTO; | ||
|
||
@Override | ||
public ConfigGroup buildWriteSetForAnchorPeers( | ||
ConfigGroup readset, AnchorPeerParamsDTO anchorPeerParamsDTO) throws ServiceException { | ||
this.anchorPeerParamsDTO = anchorPeerParamsDTO; | ||
String orgMspId = anchorPeerParamsDTO.getOrganizationMspId(); | ||
Map<String, ConfigGroup> existingOrganizations = | ||
FabricChannelUtil.getExistingOrgsFromReadset(readset); | ||
// The "Application" group | ||
ConfigGroup applicationGroup = | ||
ConfigGroup.newBuilder() | ||
.setModPolicy(FabricClientConstants.CHANNEL_CONFIG_MOD_POLICY_ADMINS) | ||
.putAllPolicies(FabricChannelUtil.setApplicationPolicies(readset)) | ||
.putGroups(orgMspId, setAnchorPeerInGroup(orgMspId, readset)) | ||
// putAllGroups excludes new organization | ||
.putAllGroups(existingOrganizations) | ||
// Application group version | ||
.setVersion( | ||
FabricChannelUtil.retrieveMSPGroupVersionFromReadset( | ||
readset, FabricClientConstants.CHANNEL_CONFIG_GROUP_APPLICATION) | ||
+ 1) // will be tied to current version + 1 for this level | ||
.build(); | ||
// the "/Channel" group | ||
return ConfigGroup.newBuilder() | ||
.putGroups(FabricClientConstants.CHANNEL_CONFIG_GROUP_APPLICATION, applicationGroup) | ||
.setModPolicy(FabricClientConstants.CHANNEL_CONFIG_MOD_POLICY_ADMINS) | ||
// Channel group version | ||
.setVersion(readset.getVersion()) | ||
.build(); | ||
} | ||
|
||
private ConfigGroup setAnchorPeerInGroup(String orgMspId, ConfigGroup readSet) { | ||
Map<String, ConfigValue> valueMap = new HashMap<>(); | ||
if (anchorPeerParamsDTO.getAnchorPeerDTOs() != null) { | ||
valueMap.put( | ||
FabricClientConstants.CHANNEL_CONFIG_GROUP_VALUE_ANCHORPEERS, setNewOrgAnchorPeerValue()); | ||
} | ||
return ConfigGroup.newBuilder() | ||
.setModPolicy(FabricClientConstants.CHANNEL_CONFIG_MOD_POLICY_ADMINS) | ||
.putAllPolicies(FabricChannelUtil.getDefaultRolePolicy(orgMspId)) | ||
.putAllValues(valueMap) | ||
.setVersion( | ||
FabricChannelUtil.retrieveMSPGroupVersionFromReadset( | ||
readSet, FabricClientConstants.CHANNEL_CONFIG_GROUP_APPLICATION) | ||
+ 1) | ||
.build(); | ||
} | ||
|
||
private ConfigValue setNewOrgAnchorPeerValue() { | ||
return ConfigValue.newBuilder() | ||
.setModPolicy(FabricClientConstants.CHANNEL_CONFIG_MOD_POLICY_ADMINS) | ||
.setValue(setAnchorPeers().toByteString()) | ||
.setVersion(0) | ||
.build(); | ||
} | ||
|
||
private AnchorPeers setAnchorPeers() { | ||
List<AnchorPeer> anchorPeerList = new ArrayList<>(); | ||
for (AnchorPeerDTO anchorPeerDTO : anchorPeerParamsDTO.getAnchorPeerDTOs()) { | ||
anchorPeerList.add( | ||
AnchorPeer.newBuilder() | ||
.setHost(anchorPeerDTO.getHostname()) | ||
.setPort(anchorPeerDTO.getPort()) | ||
.build()); | ||
} | ||
return AnchorPeers.newBuilder().addAllAnchorPeers(anchorPeerList).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
Oops, something went wrong.