pkedvessy commented on code in PR #10353: URL: https://github.com/apache/nifi/pull/10353#discussion_r2389332613
########## 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: In my opinion the PARTIALLY_APPLIED result is not suitable for a single processor start/stop operation. It would make sense for a processor group what could be partially started or stopped (eg some of the processors in the group are started or stopped by the operation meanwhile others remain in the opposite state for some reason) but the operation result for a single processor should not be partial. @lordgamez could you please check what could be the operation state from the CPP agent in case of a processor start/stop operation? We should keep this in line with the existing implementation in the CPP agent. ########## minifi/minifi-nar-bundles/minifi-framework-bundle/minifi-framework/minifi-framework-core/src/main/java/org/apache/nifi/minifi/c2/C2NifiClientService.java: ########## @@ -427,9 +435,29 @@ private ProcessorStatus convertProcessorStatus(org.apache.nifi.controller.status result.setProcessingNanos(processorStatus.getProcessingNanos()); result.setActiveThreadCount(processorStatus.getActiveThreadCount()); result.setTerminatedThreadCount(processorStatus.getTerminatedThreadCount()); + RunStatus mappedRunStatus = mapProcessorRunStatus(processorStatus.getRunStatus()); + if (mappedRunStatus != null) { + result.setRunStatus(mappedRunStatus); + } return result; } + private RunStatus mapProcessorRunStatus(org.apache.nifi.controller.status.RunStatus controllerRunStatus) { Review Comment: In the switch statement, we can simply return STOPPED as default and we can keep RUNNING mapping as it is now. In other hand, controllerRunStatus parameter naming is misleading. We should use something like a runStatus or processorRunStatus as parameter name or we can simply set the runStatus without this method like `result.setRunStatus(processorStatus.getRunStatus() == Running ? RUNNING : STOPPED);` -- 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]
