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

Provide the fluent API for CentralDogma client #651

Merged
merged 13 commits into from
Jan 4, 2022

Conversation

minwoox
Copy link
Contributor

@minwoox minwoox commented Dec 2, 2021

Motivation:
Currently, CentralDogma client has a bunch of methods that take a bunch of parameters.
It makes it harder to add another optional parameter to the existing methods because we need to add another pair of existing methods. For example:

// Existing methods:
void watch(String a);
void watch(String a, String b);
void watch(String a, String b, String c);

// If we want to add an optional long value then we need another three methods:
void watch(String a, long d);
void watch(String a, String b, long d);
void watch(String a, String b, String c, long d);

Modifications:

  • Add PathPattern interface to pass as the parameter instead of String.
  • Add CentralDogma.forRepo(...) method that returns CentralDogmaRepository.
    • Users can use the instance to send a request:
      centralDogma.forRepo("foo", "bar").file("/foo.json").get();
      centralDogma.forRepo("foo", "bar").watch("/foo.json").start();
      centralDogma.forRepo("foo", "bar").watcher(PathPattern.all()).start();

Result:

  • You can now send a request to the Central Dogma server via fluent APIs.
  • (Deprecated) Various methods in CentralDogma client are deprecated. Use fluent APIs.

@codecov
Copy link

codecov bot commented Dec 2, 2021

Codecov Report

Merging #651 (c6d5393) into master (e46e977) will increase coverage by 0.21%.
The diff coverage is 80.21%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #651      +/-   ##
============================================
+ Coverage     69.87%   70.09%   +0.21%     
- Complexity     3298     3399     +101     
============================================
  Files           333      349      +16     
  Lines         13136    13464     +328     
  Branches       1425     1448      +23     
============================================
+ Hits           9179     9437     +258     
- Misses         3081     3151      +70     
  Partials        876      876              
Impacted Files Coverage Δ
...ogma/client/armeria/CentralDogmaEndpointGroup.java 60.71% <0.00%> (-4.68%) ⬇️
.../java/com/linecorp/centraldogma/client/Latest.java 76.47% <ø> (+11.76%) ⬆️
...m/linecorp/centraldogma/client/WatchConstants.java 100.00% <ø> (ø)
...com/linecorp/centraldogma/client/CentralDogma.java 3.03% <11.11%> (-56.23%) ⬇️
...corp/centraldogma/client/AbstractCentralDogma.java 25.00% <27.27%> (-45.97%) ⬇️
...m/linecorp/centraldogma/client/WatcherRequest.java 64.91% <64.91%> (ø)
...com/linecorp/centraldogma/client/FilesRequest.java 66.66% <66.66%> (ø)
...com/linecorp/centraldogma/client/WatchOptions.java 69.23% <69.23%> (ø)
.../linecorp/centraldogma/client/AbstractWatcher.java 79.47% <72.05%> (ø)
...ldogma/client/updater/CentralDogmaBeanFactory.java 59.70% <72.72%> (+0.61%) ⬆️
... and 36 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e46e977...c6d5393. Read the comment docs.

@minwoox minwoox added this to the 0.53.0 milestone Dec 3, 2021
@minwoox minwoox changed the title (WIP) Provide the fluent API for CentralDogma client Provide the fluent API for CentralDogma client Dec 3, 2021
@minwoox
Copy link
Contributor Author

minwoox commented Dec 3, 2021

This is ready for review. 😉

Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

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

Looks fluent!

di-seo and others added 2 commits December 10, 2021 00:08
### Motivation
- line#532
- To-Do of line#610

### Modifications
- Put value of `notify-entry-not-found` on `Prefer` request header to get error that entries are not found on watching file/repository
- Propagate error that entries are not found into `Watcher#initialValueFuture`

### Result
- You can get error on watching file/repository if the entry doesn't exist.
minwoox added a commit to minwoox/centraldogma that referenced this pull request Dec 20, 2021
Motivation:
I found out while I implementing line#651.
The child watcher created via `Watcher#newChild(mapper)` executes the specified mapper
every time when a listener is notified. If there are 1000 listeners, mapper is called 1000 times.
This could be a problem if the mapper has a haevy logic.

Modifications:
- Execute mapper onle once when the entry is chaned.
- Add `Watcher.newWatcher(Function, Executor)` that executes the mapper using the executor.

Result:
- The mapper `Function` of a Child watcher is executed only once when the child watcher get notified.
minwoox added a commit to minwoox/centraldogma that referenced this pull request Dec 20, 2021
Motivation:
I found out while I implementing line#651.
The child watcher created via `Watcher#newChild(mapper)` executes the specified mapper
every time when a listener is notified. If there are 1000 listeners, mapper is called 1000 times.
This could be a problem if the mapper has a haevy logic.

Modifications:
- Execute mapper onle once when the entry is chaned.
- Add `Watcher.newWatcher(Function, Executor)` that executes the mapper using the executor.

Result:
- The mapper `Function` of a Child watcher is executed only once when the child watcher get notified.
minwoox added a commit to minwoox/centraldogma that referenced this pull request Dec 20, 2021
Motivation:
I found out while I implementing line#651.
The child watcher created via `Watcher#newChild(mapper)` executes the specified mapper
every time when a listener is notified. If there are 1000 listeners, mapper is called 1000 times.
This could be a problem if the mapper has a haevy logic.

Modifications:
- Execute mapper onle once when the entry is chaned.
- Add `Watcher.newWatcher(Function, Executor)` that executes the mapper using the executor.

Result:
- The mapper `Function` of a Child watcher is executed only once when the child watcher get notified.
minwoox added a commit to minwoox/centraldogma that referenced this pull request Dec 20, 2021
Motivation:
I found out while I implementing line#651.
The child watcher created via `Watcher#newChild(mapper)` executes the specified mapper
every time when a listener is notified. If there are 1000 listeners, mapper is called 1000 times.
This could be a problem if the mapper has a haevy logic.

Modifications:
- Execute mapper onle once when the entry is chaned.
- Add `Watcher.newWatcher(Function, Executor)` that executes the mapper using the executor.

Result:
- The mapper `Function` of a Child watcher is executed only once when the child watcher get notified.
Motivation:
I found out while I implementing line#651.
The child watcher created via `Watcher#newChild(mapper)` executes the specified mapper
every time when a listener is notified. If there are 1000 listeners, mapper is called 1000 times.
This could be a problem if the mapper has heavy logic.

Modifications:
- Execute mapper only once when the entry is changed.
- Add `Watcher.newWatcher(Function, Executor)` that executes the mapper using the executor.

Result:
- The mapper `Function` of a Child watcher is executed only once when the child watcher gets notified.
@minwoox
Copy link
Contributor Author

minwoox commented Dec 23, 2021

@di-seo Please, let me know if there's anything we can improve. 😄

Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

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

The overall API looks really nice! 🙇 👍 Left some minor questions on the Watcher implementation 🙏

Copy link
Contributor

@di-seo di-seo left a comment

Choose a reason for hiding this comment

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

I left some comments.
I look forward to this changes. :)

Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

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

Mostly looks good.

@Override
protected void scaffold(CentralDogma client) {
client.createProject("foo").join();
client.createRepository("foo", "bar").join();
Copy link
Contributor

Choose a reason for hiding this comment

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

Now, it might be natual that client.createRepository("foo", "bar") returns a CompletableFuture<CentralDogmaRepository>, although it is a breaking change. 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me do that in the following PR. 😅

Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

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

Overall looks good! Left some minor comments 🙏

@minwoox
Copy link
Contributor Author

minwoox commented Dec 31, 2021

@ikhoon and @jrhee17 All addressed, PTAL. 🙇‍♂️

Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

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

Left a minor question, but overall looks good to me! Thank you @minwoox 🙇 👍 🙇

Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

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

Good shot!

@minwoox minwoox merged commit e93bc5a into line:master Jan 4, 2022
@minwoox minwoox deleted the fluentApi_client branch January 4, 2022 14:59
@minwoox
Copy link
Contributor Author

minwoox commented Jan 4, 2022

Thanks, reviewers for the valuable comments. 🙇‍♂️

minwoox added a commit to minwoox/centraldogma that referenced this pull request Jan 5, 2022
Motivation:
We introduced `CentralDogmaRepository` class in line#651 and it would be nice if we return it from
`centralDogma.createRepository(...)` so users can chain the next call.
```java
dogma.createRepository("foo", "bar)
     .join()
     .commit(...)
     .push();
```

Modifications:
- Change to return `CentralDogmaRepository` from `centralDogma.createRepository(...)` and `centralDogma.unremoveRepository(...).
- Fix flaky test in `WatchTest`.`

Result:
- (Breaking) `createRepository` and `unremoveRepository` from `CentralDogma` now returns `CentralDogmaRepository`.
minwoox added a commit that referenced this pull request Jan 6, 2022
…662)

Motivation:
We introduced `CentralDogmaRepository` class in #651 and it would be nice if we return it from
`centralDogma.createRepository(...)` so users can chain the next call.
```java
dogma.createRepository("foo", "bar)
     .join()
     .commit(...)
     .push();
```

Modifications:
- Change to return `CentralDogmaRepository` from `centralDogma.createRepository(...)` and `centralDogma.unremoveRepository(...).
- Fix flaky test in `WatchTest`.

Result:
- (Breaking) `createRepository` and `unremoveRepository` from `CentralDogma` now returns `CentralDogmaRepository`.
@ikhoon ikhoon modified the milestones: 0.54.0, 0.55.0 Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants