Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chain APIs for orderer, application, consortium, and channel operations #11

Merged
merged 6 commits into from
May 12, 2020

Conversation

wlahti
Copy link
Contributor

@wlahti wlahti commented Apr 28, 2020

Type of change

  • Improvement (improvement to code, performance, etc)

Description

First commit:

  • Chain together API calls to retrieve/update orderer configuration instead of hanging everything off the ConfigTx.

Second commit:

  • Chain together API calls to retrieve/update application configuration.

Third commit:

  • Chain together API calls to retrieve/update consortium configuration.

Fourth commit:

  • Chain together API calls to retrieve/update channel configuration.

Related issues

FAB-17744

@wlahti wlahti requested a review from a team as a code owner April 28, 2020 21:14
@wlahti wlahti force-pushed the fab-17744 branch 2 times, most recently from c0dfc2d to 3ed3691 Compare April 29, 2020 14:04
@caod123
Copy link
Contributor

caod123 commented Apr 29, 2020

@wlahti per CI, looks like theres a couple of linting issues with comments on exported functions

@wlahti
Copy link
Contributor Author

wlahti commented Apr 30, 2020

/ci-run

1 similar comment
@lindluni
Copy link
Contributor

/ci-run

@github-actions
Copy link

You are not authorized to trigger builds for this pull request!

@lindluni
Copy link
Contributor

Will, we enabled the /ci-run command now, so you can use it

@github-actions
Copy link

You are not authorized to trigger builds for this pull request!

@wlahti wlahti force-pushed the fab-17744 branch 2 times, most recently from f4756c0 to b7c21fc Compare May 1, 2020 14:15
Copy link
Contributor

@sykesm sykesm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started looking at this fairly closely but decided to step back once I got to the examples.

From my perspective, the examples are the key to all of this. I really want to see examples that show how to use the library. That should drive out the API bits that we need. When I look through the examples, I don't see any references to OriginalConfig. We use a pattern where we create an object that is populated from state in the original config (and we maintain it for our delta computation) but it's never something that someone using the API ever gets.

So, why do we have it? Do we really need it? If we don't need it, then we remove at least one level of chaining that exists already.

The other thing that stands out to me is that we didn't really update the examples to show how chaining would work in practice. All of the calls seem to use the same prefix pattern instead of holding onto the state and modifying the things that need to modified.

Then there are chains like this:

c.UpdatedConfig().Consortiums().Consortium("SampleConsortium").SetChannelCreationPolicy(...)

where I wonder if Consortium(name string) and Consortiums() are the correct API. This style lines up nicely with the REST patterns most of us a used to where the plural form results in a list and the singular form allows a reference to a single instance based on a qualifier.

I know I haven't been involved in the day-to-day of this for a bit so I don't know all of the consideration that went into what's here right now. My ask is that we really put ourselves into the consumer's shoes and see if what's being surfaced is what we'd wand to use.

@@ -37,13 +37,13 @@ func TestChannelCapabilities(t *testing.T) {
err := setValue(config.ChannelGroup, capabilitiesValue(expectedCapabilities), AdminsPolicyKey)
gt.Expect(err).NotTo(HaveOccurred())

channelCapabilities, err := c.ChannelCapabilities()
channelCapabilities, err := c.OriginalConfig().Channel().Capabilities()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the Config suffix?

// UpdatedChannelGroup is a ChannelGroup that can be modified in order to
// generate a config update.
type UpdatedChannelGroup struct {
*ChannelGroup
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

Comment on lines 39 to 31
var (
err error
consortium string
application Application
orderer Orderer
consortiums []Consortium
capabilities []string
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of 6 vars, should this simply be a Channel and err? Not sure the temporary is buying much since you're just populating the channel object.

Basically, assign each field after getting the data instead of carrying things. That keeps each of the field related blocks together. Given the length of the method, I think that would be easier to read.

@@ -361,7 +361,7 @@ func TestAddAnchorPeer(t *testing.T) {
err = c.AddAnchorPeer("Org2", newOrg2AnchorPeer)
gt.Expect(err).NotTo(HaveOccurred())

gt.Expect(proto.Equal(c.UpdatedConfig(), expectedUpdatedConfig)).To(BeTrue())
gt.Expect(proto.Equal(c.UpdatedConfig().Config, expectedUpdatedConfig)).To(BeTrue())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a follow-on, I'd suggest writing a matcher and using it.

onsi/gomega#292 (comment)

@@ -67,13 +67,13 @@ func TestOrdererCapabilities(t *testing.T) {

c := New(config)

ordererCapabilities, err := c.OrdererCapabilities()
ordererCapabilities, err := c.OriginalConfig().Orderer().Capabilities()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may have said this already in a different section but I think removing the Config suffix from Original and Updated would probably be a good move.

Comment on lines 146 to 147
orderer.Kafka.Brokers = []string{"kafka0:9092", "kafka1:9092", "kafka2:9092"}
orderer.BatchSize.MaxMessageCount = 500
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where embedding is good; makes it easy to change the updated version. It's modification of the original that I worry about but it may not be a problem...

if err != nil {
panic(err)
}

orderer.Kafka.Brokers = []string{"kafka0:9092", "kafka1:9092", "kafka2:9092"}
orderer.BatchSize.MaxMessageCount = 500

err = c.SetOrdererConfiguration(orderer)
err = c.UpdatedConfig().Orderer().SetConfiguration(orderer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The repeated use of the chain does not demonstrate how I'd expect this to be used IRL. Why isn't the orderer reference obtained and maintained across the calls?

Comment on lines 227 to 232
err = c.UpdatedConfig().Orderer().Organization("OrdererOrg").RemovePolicy(configtx.WritersPolicyKey)
if err != nil {
panic(err)
}

err = c.SetOrdererOrgPolicy("OrdererOrg", configtx.AdminsPolicyKey, "TestPolicy",
err = c.UpdatedConfig().Orderer().Organization("OrdererOrg").SetPolicy(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here; The first half of the chain is the reference that should be maintained.

Comment on lines 243 to 248
err = c.UpdatedConfig().Orderer().RemovePolicy(configtx.WritersPolicyKey)
if err != nil {
panic(err)
}

err = c.SetOrdererPolicy(configtx.AdminsPolicyKey, "TestPolicy", configtx.Policy{
err = c.UpdatedConfig().Orderer().SetPolicy(configtx.AdminsPolicyKey, "TestPolicy", configtx.Policy{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here. :) This is an example.

I'll assume this applies to the other occurrences as well.

baseConfig := fetchChannelConfig()
c := configtx.New(baseConfig)

msp, err := c.OrdererMSP("OrdererOrg")
msp, err := c.UpdatedConfig().Orderer().Organization("OrdererOrg").MSP()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a little odd for me that, as a user, I'd create a new object from the base config and then have to call UpdatedConfig to get the thing I can actually work with.

So, why is that the case?

@wlahti wlahti force-pushed the fab-17744 branch 2 times, most recently from 7202497 to 8a8de75 Compare May 4, 2020 19:14
Copy link
Contributor Author

@wlahti wlahti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored the Original/UpdatedConfig logic to simplify things and address your comments.

@@ -274,7 +287,7 @@ func newSystemChannelGroup(channelConfig Channel) (*cb.ConfigGroup, error) {

err = setPolicies(channelGroup, channelConfig.Policies, AdminsPolicyKey)
if err != nil {
return nil, fmt.Errorf("failed to set system channel policies: %v", err)
return nil, fmt.Errorf("failed to add system channel policies: %v", err)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Done.

@wlahti wlahti force-pushed the fab-17744 branch 4 times, most recently from 0b68f8c to 63b156d Compare May 6, 2020 20:08
wlahti added 5 commits May 7, 2020 16:16
Change from c.Consortiums().Consortium() to
c.Consortium().

FAB-17744

Signed-off-by: Will Lahti <[email protected]>
Copy link
Contributor

@caod123 caod123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some discussion back and forth offline we've come to a better conclusion on this track of work. I'm going to go ahead and merge this as it seems like the direction we're going in with the chaining of the APIs is appropriate and we can iterate more on it to cleanup small nuances

@caod123 caod123 merged commit 5ffb9e2 into hyperledger:master May 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants