bejancsaba commented on code in PR #6733:
URL: https://github.com/apache/nifi/pull/6733#discussion_r1067434531


##########
c2/c2-client-bundle/c2-client-service/src/main/java/org/apache/nifi/c2/client/service/C2ClientService.java:
##########
@@ -59,11 +120,30 @@ private void processResponse(C2HeartbeatResponse response) 
{
         }
     }
 
-    private void handleRequestedOperations(List<C2Operation> 
requestedOperations) {
-        for (C2Operation requestedOperation : requestedOperations) {
-            operationService.handleOperation(requestedOperation)
-                .ifPresent(client::acknowledgeOperation);
+    private boolean requiresRestart(C2OperationHandler c2OperationHandler, 
C2OperationAck c2OperationAck) {
+        return c2OperationHandler.requiresRestart() && 
isOperationFullyApplied(c2OperationAck);
+    }
+
+    private boolean isOperationFullyApplied(C2OperationAck c2OperationAck) {
+        return Optional.ofNullable(c2OperationAck)
+            .map(C2OperationAck::getOperationState)
+            .map(C2OperationState::getState)
+            .filter(FULLY_APPLIED::equals)
+            .isPresent();
+    }
+
+    private boolean initiateRestart(LinkedList<C2Operation> 
lRequestedOperations, C2Operation requestedOperation) {
+        try {
+            disableHeartbeat();
+            requestedOperationDAO.save(new OperationQueue(requestedOperation, 
lRequestedOperations));

Review Comment:
   Can we rename the variable similarly to earlier? Just lose the magic "l" 
prefix :)



##########
minifi/minifi-bootstrap/src/main/java/org/apache/nifi/minifi/bootstrap/command/StartRunner.java:
##########
@@ -216,6 +213,46 @@ private Process restartNifi(Properties 
bootstrapProperties, String confDir, Proc
         return process;
     }
 
+    private boolean revertFlowConfig(Properties bootstrapProperties, String 
confDir, File swapConfigFile) throws IOException {
+        DEFAULT_LOGGER.info("Swap file exists, MiNiFi failed trying to change 
configuration. Reverting to old configuration.");
+
+        try {
+            ByteBuffer tempConfigFile = 
generateConfigFiles(Files.newInputStream(swapConfigFile.toPath()), confDir, 
bootstrapProperties);
+            
runMiNiFi.getConfigFileReference().set(tempConfigFile.asReadOnlyBuffer());
+        } catch (ConfigurationChangeException e) {
+            DEFAULT_LOGGER.error("The swap file is malformed, unable to 
restart from prior state. Will not attempt to restart MiNiFi. Swap File should 
be cleaned up manually.");
+            return false;
+        }
+
+        Files.copy(swapConfigFile.toPath(), 
Paths.get(bootstrapProperties.getProperty(MINIFI_CONFIG_FILE_KEY)), 
REPLACE_EXISTING);
+
+        DEFAULT_LOGGER.info("Replacing config file with swap file and deleting 
swap file");
+        if (!swapConfigFile.delete()) {
+            DEFAULT_LOGGER.warn("The swap file failed to delete after 
replacing using it to revert to the old configuration. It should be cleaned up 
manually.");
+        }
+        runMiNiFi.setReloading(false);
+        return true;
+    }
+
+    private boolean revertBootstrapConfig(String confDir, File 
bootstrapSwapConfigFile) throws IOException {
+        DEFAULT_LOGGER.info("Bootstrap Swap file exists, MiNiFi failed trying 
to change configuration. Reverting to old configuration.");
+
+        Files.copy(bootstrapSwapConfigFile.toPath(), 
bootstrapConfigFile.toPath(), REPLACE_EXISTING);
+        try {
+            ByteBuffer tempConfigFile = 
generateConfigFiles(asByteArrayInputStream(runMiNiFi.getConfigFileReference().get().duplicate()),
 confDir, bootstrapFileProvider.getBootstrapProperties());
+            
runMiNiFi.getConfigFileReference().set(tempConfigFile.asReadOnlyBuffer());
+        } catch (ConfigurationChangeException e) {
+            DEFAULT_LOGGER.error("The swap file is malformed, unable to 
restart from prior state. Will not attempt to restart MiNiFi. Swap File should 
be cleaned up manually.");
+            return false;
+        }
+
+        if (!bootstrapSwapConfigFile.delete()) {
+            DEFAULT_LOGGER.warn("The swap file failed to delete after 
replacing using it to revert to the old configuration. It should be cleaned up 
manually.");

Review Comment:
   ok, thanks



##########
c2/c2-client-bundle/c2-client-service/src/main/java/org/apache/nifi/c2/client/service/operation/RequestedOperationDAO.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.client.service.operation;
+
+import java.util.Optional;
+
+/**
+ * The purpose of this interface is to be able to persist operations between 
MiNiFi restarts.

Review Comment:
   I know the 2 things are bound but if we can let's not reference MiNiFi in 
the c2 upper level module



-- 
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