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-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to