You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "KalmanJantner (via GitHub)" <gi...@apache.org> on 2024/08/01 09:05:31 UTC
[PR] NIFI-13614: populate failure cause in ack response [nifi]
KalmanJantner opened a new pull request, #9136:
URL: https://github.com/apache/nifi/pull/9136
<!-- Licensed to the Apache Software Foundation (ASF) under one or more -->
<!-- contributor license agreements. See the NOTICE file distributed with -->
<!-- this work for additional information regarding copyright ownership. -->
<!-- The ASF licenses this file to You under the Apache License, Version 2.0 -->
<!-- (the "License"); you may not use this file except in compliance with -->
<!-- the License. You may obtain a copy of the License at -->
<!-- http://www.apache.org/licenses/LICENSE-2.0 -->
<!-- Unless required by applicable law or agreed to in writing, software -->
<!-- distributed under the License is distributed on an "AS IS" BASIS, -->
<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -->
<!-- See the License for the specific language governing permissions and -->
<!-- limitations under the License. -->
# Summary
[NIFI-13614](https://issues.apache.org/jira/browse/NIFI-13614)
# Tracking
Please complete the following tracking steps prior to pull request creation.
### Issue Tracking
- [x] [Apache NiFi Jira](https://issues.apache.org/jira/browse/NIFI) issue created
### Pull Request Tracking
- [x ] Pull Request title starts with Apache NiFi Jira issue number, such as `NIFI-00000`
- [x ] Pull Request commit message starts with Apache NiFi Jira issue number, as such `NIFI-00000`
### Pull Request Formatting
- [ ] Pull Request based on current revision of the `main` branch
- [ ] Pull Request refers to a feature branch with one commit containing changes
# Verification
Please indicate the verification steps performed prior to pull request creation.
### Build
- [ ] Build completed using `mvn clean install -P contrib-check`
- [ ] JDK 21
### Licensing
- [ ] New dependencies are compatible with the [Apache License 2.0](https://apache.org/licenses/LICENSE-2.0) according to the [License Policy](https://www.apache.org/legal/resolved.html)
- [ ] New dependencies are documented in applicable `LICENSE` and `NOTICE` files
### Documentation
- [ ] Documentation formatting appears as expected in rendered files
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-13614: populate failure cause in ack response [nifi]
Posted by "KalmanJantner (via GitHub)" <gi...@apache.org>.
KalmanJantner commented on code in PR #9136:
URL: https://github.com/apache/nifi/pull/9136#discussion_r1727095682
##########
c2/c2-protocol/c2-protocol-api/src/main/java/org/apache/nifi/c2/protocol/api/C2OperationState.java:
##########
@@ -42,6 +42,17 @@ public class C2OperationState implements Serializable {
@Schema(description = "Additional details about the state")
private String details;
+ @Schema(description = "Additional details cause of the failure")
Review Comment:
Fixed, thanks.
##########
minifi/minifi-nar-bundles/minifi-framework-bundle/minifi-framework/minifi-framework-core/src/main/java/org/apache/nifi/minifi/c2/command/DefaultUpdateConfigurationStrategy.java:
##########
@@ -148,7 +150,7 @@ private void reloadFlow(Set<String> proposedConnectionIds) throws IOException {
List<ValidationResult> validationErrors = validate(flowController.getFlowManager());
if (!validationErrors.isEmpty()) {
LOGGER.error("Validation errors found when reloading the flow: {}", validationErrors);
- throw new IllegalStateException("Unable to start flow due to validation errors");
+ throw new ValidationException(validationErrors);
Review Comment:
Fixed, thanks.
##########
c2/c2-protocol/c2-protocol-api/src/main/java/org/apache/nifi/c2/protocol/api/FailureCause.java:
##########
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nifi.c2.protocol.api;
+
+import java.util.List;
+import java.util.Objects;
+import org.apache.nifi.components.ValidationResult;
+
+public class FailureCause {
+ private List<ValidationResult> validationResults;
+ private String exceptionMessage;
+ private String causedByMessage;
Review Comment:
Fixed, thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-13614: populate failure cause in ack response [nifi]
Posted by "briansolo1985 (via GitHub)" <gi...@apache.org>.
briansolo1985 closed pull request #9136: NIFI-13614: populate failure cause in ack response
URL: https://github.com/apache/nifi/pull/9136
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-13614: populate failure cause in ack response [nifi]
Posted by "briansolo1985 (via GitHub)" <gi...@apache.org>.
briansolo1985 commented on code in PR #9136:
URL: https://github.com/apache/nifi/pull/9136#discussion_r1719616853
##########
c2/c2-client-bundle/c2-client-service/src/main/java/org/apache/nifi/c2/client/service/operation/C2OperationHandler.java:
##########
@@ -79,13 +81,26 @@ default boolean requiresRestart() {
* @param details additional status info to detail the state
* @return the created state
*/
- default C2OperationState operationState(C2OperationState.OperationState operationState, String details) {
+ default C2OperationState operationState(C2OperationState.OperationState operationState, String details, Exception e) {
Review Comment:
I suggest to refactor this method, a possible example:
```
default C2OperationState operationState(C2OperationState.OperationState operationState, String details, Exception e) {
C2OperationState state = new C2OperationState();
state.setState(operationState);
state.setDetails(details);
ofNullable(e).map(this::toFailureCause).ifPresent(state::setFailureCause);
return state;
}
private FailureCause toFailureCause(Exception exception) {
FailureCause failureCause = new FailureCause();
failureCause.setExceptionMessage(exception.getMessage());
ofNullable(exception.getCause()).map(Throwable::getMessage).ifPresent(failureCause::setCausedByMessage);
if (exception instanceof ValidationException validationException) {
failureCause.setValidationResults(validationException.getValidationResults());
}
return failureCause;
}
```
Also the cause message parsing should be recursive, please see my comment on the FailureCause datastructure
##########
c2/c2-client-bundle/c2-client-service/src/main/java/org/apache/nifi/minifi/validator/ValidationException.java:
##########
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nifi.minifi.validator;
+
+import java.util.List;
+import java.util.Objects;
+import org.apache.nifi.components.ValidationResult;
+
+public class ValidationException extends IllegalStateException {
+ private List<ValidationResult> validationResults;
+
+ public ValidationException(List<ValidationResult> details) {
+ this.validationResults = details;
+ }
+
+ public List<ValidationResult> getValidationResults() {
+ return validationResults;
+ }
+
+ public void setValidationResults(List<ValidationResult> validationResults) {
Review Comment:
It seems this method is never used. We could make validationResults member final, and delete this method.
##########
c2/c2-protocol/c2-protocol-api/src/main/java/org/apache/nifi/c2/protocol/api/C2OperationState.java:
##########
@@ -42,6 +42,17 @@ public class C2OperationState implements Serializable {
@Schema(description = "Additional details about the state")
private String details;
+ @Schema(description = "Additional details cause of the failure")
Review Comment:
We could improve the description by adding the about word:
`Additional details about the cause of the failure`
##########
minifi/minifi-nar-bundles/minifi-framework-bundle/minifi-framework/minifi-framework-core/src/main/java/org/apache/nifi/minifi/c2/command/DefaultUpdateConfigurationStrategy.java:
##########
@@ -148,7 +150,7 @@ private void reloadFlow(Set<String> proposedConnectionIds) throws IOException {
List<ValidationResult> validationErrors = validate(flowController.getFlowManager());
if (!validationErrors.isEmpty()) {
LOGGER.error("Validation errors found when reloading the flow: {}", validationErrors);
- throw new IllegalStateException("Unable to start flow due to validation errors");
+ throw new ValidationException(validationErrors);
Review Comment:
I would keep the error message here as well.
Otherwise when creating the operation response, the exception message will be null. It is more informative for the user if they get a message that the flow did not start due to a validation error.
For the the ValidationException class also needs to be modified:
```
public class ValidationException extends IllegalStateException {
private List<ValidationResult> validationResults;
public ValidationException(String message, List<ValidationResult> details) {
super(message);
this.validationResults = details;
}
```
##########
c2/c2-protocol/c2-protocol-api/src/main/java/org/apache/nifi/c2/protocol/api/FailureCause.java:
##########
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nifi.c2.protocol.api;
+
+import java.util.List;
+import java.util.Objects;
+import org.apache.nifi.components.ValidationResult;
+
+public class FailureCause {
+ private List<ValidationResult> validationResults;
+ private String exceptionMessage;
+ private String causedByMessage;
Review Comment:
The causedByMessage should be a collection instead of a string.
In many cases exception are recursively chained through Throwable.cause, and often the real cause is the exception on the bottom layer.
We need to process the cause exception recursively and store them into a list to keep all the information.
The list is fortunately an ordered collection so the order of the exception will also be preserved in this way
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-13614: populate failure cause in ack response [nifi]
Posted by "KalmanJantner (via GitHub)" <gi...@apache.org>.
KalmanJantner commented on code in PR #9136:
URL: https://github.com/apache/nifi/pull/9136#discussion_r1727095300
##########
c2/c2-client-bundle/c2-client-service/src/main/java/org/apache/nifi/c2/client/service/operation/C2OperationHandler.java:
##########
@@ -79,13 +81,26 @@ default boolean requiresRestart() {
* @param details additional status info to detail the state
* @return the created state
*/
- default C2OperationState operationState(C2OperationState.OperationState operationState, String details) {
+ default C2OperationState operationState(C2OperationState.OperationState operationState, String details, Exception e) {
Review Comment:
Fixed, thanks.
##########
c2/c2-client-bundle/c2-client-service/src/main/java/org/apache/nifi/minifi/validator/ValidationException.java:
##########
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nifi.minifi.validator;
+
+import java.util.List;
+import java.util.Objects;
+import org.apache.nifi.components.ValidationResult;
+
+public class ValidationException extends IllegalStateException {
+ private List<ValidationResult> validationResults;
+
+ public ValidationException(List<ValidationResult> details) {
+ this.validationResults = details;
+ }
+
+ public List<ValidationResult> getValidationResults() {
+ return validationResults;
+ }
+
+ public void setValidationResults(List<ValidationResult> validationResults) {
Review Comment:
Fixed, thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-13614: populate failure cause in ack response [nifi]
Posted by "KalmanJantner (via GitHub)" <gi...@apache.org>.
KalmanJantner commented on PR #9136:
URL: https://github.com/apache/nifi/pull/9136#issuecomment-2304722350
> Thank you for the pull request. This is really an useful feature, which will provide more insight of the status of the C2 operation when an error happens.
>
> I left some comments, please check them. Also two general comments:
>
> * we should also apply this approach for all the the handlers, not just UpdateConfigurationOperationHandler. To use this approach properly, potentially some refactoring will be needed on handler level and below. For example, in UpdateAssetOperation handler the exception is logged, an optional is returned only. We should move away from the optional approach in favor of exception managed approach like in UpdateConfigurationOperationHandler.
> * Please squash the commits. Before the final review, there should only be one commit
Thanks you for the review. I applied the recommended changes and squashed the commits.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org