Mihhai commented on code in PR #10353:
URL: https://github.com/apache/nifi/pull/10353#discussion_r2398041499


##########
minifi/minifi-nar-bundles/minifi-framework-bundle/minifi-framework/minifi-framework-core/src/main/java/org/apache/nifi/minifi/c2/command/DefaultProcessorStateStrategy.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.c2.command;
+
+import org.apache.nifi.c2.protocol.api.C2OperationState.OperationState;
+import org.apache.nifi.c2.client.service.operation.ProcessorStateStrategy;
+import org.apache.nifi.controller.FlowController;
+import org.apache.nifi.controller.ProcessorNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+import static 
org.apache.nifi.c2.protocol.api.C2OperationState.OperationState.FULLY_APPLIED;
+import static 
org.apache.nifi.c2.protocol.api.C2OperationState.OperationState.NOT_APPLIED;
+import static 
org.apache.nifi.c2.protocol.api.C2OperationState.OperationState.PARTIALLY_APPLIED;
+
+public class DefaultProcessorStateStrategy implements ProcessorStateStrategy {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(DefaultProcessorStateStrategy.class);
+
+    private final FlowController flowController;
+
+    public DefaultProcessorStateStrategy(FlowController flowController) {
+        this.flowController = flowController;
+    }
+
+    @Override
+    public OperationState startProcessor(String processorId) {
+        return changeState(processorId, true);
+    }
+
+    @Override
+    public OperationState stopProcessor(String processorId) {
+        return changeState(processorId, false);
+    }
+
+    private OperationState changeState(String processorId, boolean start) {
+        try {
+            ProcessorNode node = 
flowController.getFlowManager().getProcessorNode(processorId);
+            if (node == null) {
+                LOGGER.warn("Processor with id {} not found", processorId);
+                return NOT_APPLIED;
+            }
+            String parentGroupId = node.getProcessGroupIdentifier();
+            if (start) {
+                flowController.startProcessor(parentGroupId, processorId, 
true);
+                LOGGER.info("Started processor {} (group={})", processorId, 
parentGroupId);
+            } else {
+                flowController.stopProcessor(parentGroupId, processorId);
+                LOGGER.info("Stopped processor {} (group={})", processorId, 
parentGroupId);
+            }
+            return FULLY_APPLIED;
+        } catch (Exception e) {
+            LOGGER.error("Failed to change state for processor {}", 
processorId, e);
+            return PARTIALLY_APPLIED;

Review Comment:
   According to the cpp implementation [response construction for 
start/stop](https://github.com/apache/nifi-minifi-cpp/blob/main/libminifi/src/c2/C2Agent.cpp#L360)
 and [c2payload 
implementation](https://github.com/apache/nifi-minifi-cpp/blob/main/libminifi/src/c2/C2Payload.cpp#L28)
 it seems the response to a successful start/stop is a `FULLY_APPLIED` status. 
As a result i removed the `PARTIALLY_APPLIED ` response as you suggested but 
still left the `NOT_APPLIED` in case of error. From my understanding of the cpp 
code there doesnt seem to be any handling of the case where the start/stop 
operation fails.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to