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

[#4107] feat(all): Add testConnection API for catalog #4108

Merged
merged 4 commits into from
Jul 16, 2024

Conversation

mchades
Copy link
Contributor

@mchades mchades commented Jul 9, 2024

What changes were proposed in this pull request?

Add testConnection API for catalog

Why are the changes needed?

Fix: #4107

Does this PR introduce any user-facing change?

yes, add a new API

How was this patch tested?

tests added

@mchades mchades requested a review from jerryshao July 9, 2024 04:04
@mchades mchades self-assigned this Jul 9, 2024
return exception;
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I have some comments on the API design:

  1. It is not necessary to have a new Interface, adding a new method in the existing interface should be fine.
  2. testCatalogCreation is a big weird, I think testConnection should be OK.
  3. The interface design is not Java-ish, it is more like a REST interface, especially TestResult, it is totally DTO related stuff, which is weird for Java API design. For Java, it is better like
boolean testConnection(xxxx);

or 

void testConnection(xxxx) throws Exception;

Copy link
Contributor

Choose a reason for hiding this comment

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

Internally, you can design a such interface, but for API which is used by Java users, we should design to be more Java-ish.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay, using void testConnection(xxxx) throws Exception; to refactor the API, please help to review when you have time, thanks

@mchades mchades changed the title [#4107] feat(all): Add test API for catalog creation [#4107] feat(all): Add testConnection API for catalog Jul 11, 2024
@jerryshao
Copy link
Contributor

I'm fine with the API and REST interface. For the details, I need to take a deep look.

@@ -114,4 +114,23 @@ Catalog alterCatalog(String catalogName, CatalogChange... changes)
* @return True if the catalog was dropped, false otherwise.
*/
boolean dropCatalog(String catalogName);

/**
* Test whether a catalog can be created successfully with the specified parameters, without
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe, this should be 'Test whether we can connect to catalog engine(or something similar) with specified parameters'.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

String comment,
Map<String, String> properties) {
try {
adminClient.listTopics().names().get();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you use an already-created adminClient to test Connection since you intend to test connection with the parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The adminClient was initialized with the provided parameters

return;
}

ErrorHandlers.catalogErrorHandler().accept(resp);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do need to call this again?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To throw the corresponding exception

Copy link
Contributor Author

Choose a reason for hiding this comment

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

comment added

}
});
if (store.exists(ident, EntityType.CATALOG)) {
throw new CatalogAlreadyExistsException("Catalog %s already exists", ident);
Copy link
Contributor

Choose a reason for hiding this comment

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

Will it lead to test error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, whether the catalog name already exists is also a validation item.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

More precisely, this will cause the testConnection method to throw a CatalogAlreadyExistsException exception.

@mchades mchades requested a review from jerryshao July 16, 2024 09:21
new CatalogCreateRequest(catalogName, type, provider, comment, properties);
req.validate();

ErrorResponse resp =
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you use ErrorResponse here, I found that it returns BaseResponse for normal scenario.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just one comment, can you please explain this @mchades

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can be BaseResponse (test successfully) or ErrorResponse (test failed).

Since the ErrorResponse can contain all fields of BaseResponse (code field only), so I use ErrorResponse here. @jerryshao

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add a comment here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

@jerryshao jerryshao merged commit 116e5ae into apache:main Jul 16, 2024
33 checks passed
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.

[FEATURE] Add test API for catalog creation
3 participants