-
Notifications
You must be signed in to change notification settings - Fork 51
feat(QTDI-1291): support guess schema as service #1220
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,8 @@ | |
| import javax.ws.rs.core.Response; | ||
|
|
||
| import org.talend.sdk.component.api.exception.ComponentException; | ||
| import org.talend.sdk.component.api.exception.DiscoverSchemaException; | ||
| import org.talend.sdk.component.api.exception.DiscoverSchemaException.HandleErrorWith; | ||
| import org.talend.sdk.component.runtime.manager.ComponentManager; | ||
| import org.talend.sdk.component.runtime.manager.ContainerComponentRegistry; | ||
| import org.talend.sdk.component.runtime.manager.ServiceMeta; | ||
|
|
@@ -127,7 +129,7 @@ | |
| .collect(toList())); | ||
| } | ||
|
|
||
| private CompletableFuture<Response> doExecuteLocalAction(final String family, final String type, | ||
|
Check failure on line 132 in component-server-parent/component-server/src/main/java/org/talend/sdk/component/server/front/ActionResourceImpl.java
|
||
| final String action, final String lang, final Map<String, String> params) { | ||
| return CompletableFuture.supplyAsync(() -> { | ||
| if (action == null) { | ||
|
|
@@ -176,16 +178,15 @@ | |
| // check org.talend.sdk.component.server.service.ComponentManagerService.readCurrentLocale if you change it | ||
| }, Runnable::run).exceptionally(e -> { | ||
| final Throwable cause; | ||
| if (e.getCause() instanceof ExecutionException) { | ||
| cause = e.getCause().getCause(); | ||
| if (e.getCause() instanceof final ExecutionException exece) { | ||
| cause = exece.getCause(); | ||
| } else { | ||
| cause = e.getCause(); | ||
| } | ||
| if (cause instanceof WebApplicationException) { | ||
| final WebApplicationException wae = (WebApplicationException) cause; | ||
| if (cause instanceof final WebApplicationException wae) { | ||
| final Response response = wae.getResponse(); | ||
| String message = ""; | ||
| if (wae.getResponse().getEntity() instanceof ErrorPayload) { | ||
| if (response.getEntity() instanceof ErrorPayload) { | ||
| throw wae; // already logged and setup broken so just rethrow | ||
| } else { | ||
| try { | ||
|
|
@@ -212,32 +213,50 @@ | |
|
|
||
| private Response onError(final Throwable re) { | ||
| log.warn(re.getMessage(), re); | ||
| if (re.getCause() instanceof WebApplicationException) { | ||
| return ((WebApplicationException) re.getCause()).getResponse(); | ||
| if (re instanceof final WebApplicationException webException) { | ||
| return webException.getResponse(); | ||
| } else if (re.getCause() instanceof final WebApplicationException webException) { | ||
| return webException.getResponse(); | ||
| } | ||
|
|
||
| if (re instanceof ComponentException) { | ||
| final ComponentException ce = (ComponentException) re; | ||
| final String description = "Action execution failed with: " + ofNullable(re.getMessage()) | ||
| .orElseGet(() -> re instanceof NullPointerException | ||
| ? "unexpected null" | ||
| : "no error message"); | ||
| if (re instanceof final DiscoverSchemaException eSchema) { | ||
| // we send reason to recognize the error on client side | ||
| final String subCode = ofNullable(eSchema.getPossibleHandleErrorWith()) | ||
| .orElse(HandleErrorWith.EXCEPTION) | ||
| .toString(); | ||
| throw new WebApplicationException(Response | ||
| .status(ce.getErrorOrigin() == ComponentException.ErrorOrigin.USER ? 400 | ||
| : ce.getErrorOrigin() == ComponentException.ErrorOrigin.BACKEND ? 456 : 520, | ||
| "Unexpected callback error") | ||
| .entity(new ErrorPayload(ErrorDictionary.ACTION_ERROR, | ||
| "Action execution failed with: " + ofNullable(re.getMessage()) | ||
| .orElseGet(() -> re instanceof NullPointerException ? "unexpected null" | ||
| : "no error message"))) | ||
| .status(400, subCode) | ||
| .entity(new ErrorPayload(ErrorDictionary.ACTION_ERROR, subCode, description)) | ||
| .build()); | ||
|
Comment on lines
+226
to
+234
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @undx Do you know why we throw an exception instead just return the Result?
Comment on lines
+226
to
+234
Comment on lines
+226
to
+234
|
||
| } else if (re instanceof final ComponentException eComponent) { | ||
| throw new WebApplicationException(Response | ||
| .status(evaluateStatusCodeForException(eComponent), "Unexpected callback error") | ||
| .entity(new ErrorPayload(ErrorDictionary.ACTION_ERROR, description)) | ||
| .build()); | ||
|
Comment on lines
+236
to
239
|
||
| } | ||
|
|
||
| throw new WebApplicationException(Response | ||
| .status(520, "Unexpected callback error") | ||
| .entity(new ErrorPayload(ErrorDictionary.ACTION_ERROR, | ||
| "Action execution failed with: " + ofNullable(re.getMessage()) | ||
| .orElseGet(() -> re instanceof NullPointerException ? "unexpected null" | ||
| : "no error message"))) | ||
| .entity(new ErrorPayload(ErrorDictionary.ACTION_ERROR, description)) | ||
| .build()); | ||
|
Comment on lines
242
to
245
|
||
| } | ||
|
|
||
| private static int evaluateStatusCodeForException(final ComponentException eComponent) { | ||
| if (null == eComponent.getErrorOrigin()) { | ||
| return 520; | ||
| } | ||
|
|
||
| return switch (eComponent.getErrorOrigin()) { | ||
| case USER -> 400; | ||
| case BACKEND -> 456; | ||
| default -> 520; | ||
| }; | ||
| } | ||
|
|
||
| private Stream<ActionItem> findVirtualActions(final Predicate<String> typeMatcher, | ||
| final Predicate<String> componentMatcher, final Locale locale) { | ||
| return virtualActions | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've a model change, we need to specify it in jira issue (pinging @acatoire) but, apparently, it doesn't affect
TCOMP-api-test.