DaanHoogland commented on a change in pull request #3610: [WIP DO NOT MERGE] 
KVM: Rolling maintenance
URL: https://github.com/apache/cloudstack/pull/3610#discussion_r366407509
 
 

 ##########
 File path: 
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/rolling/maintenance/RollingMaintenanceServiceExecutor.java
 ##########
 @@ -0,0 +1,137 @@
+// 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 com.cloud.hypervisor.kvm.resource.rolling.maintenance;
+
+import com.cloud.utils.Pair;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.script.OutputInterpreter;
+import com.cloud.utils.script.Script;
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.stream.Stream;
+
+public class RollingMaintenanceServiceExecutor extends 
RollingMaintenanceExecutorBase implements RollingMaintenanceExecutor {
+
+    private static final String servicePrefix = 
"cloudstack-rolling-maintenance";
+    private static final String resultsFileSuffix = 
"rolling-maintenance-results";
+    private static final String outputFileSuffix = 
"rolling-maintenance-output";
+
+    private static final Logger s_logger = 
Logger.getLogger(RollingMaintenanceServiceExecutor.class);
+
+    public RollingMaintenanceServiceExecutor(String hooksDir) {
+        super(hooksDir);
+    }
+
+    /**
+     * Generate and return escaped instance name to use on systemd service 
invokation
+     */
+    private String generateInstanceName(String stage, String file, String 
payload) {
+        String instanceName = String.format("%s,%s,%s,%s,%s", stage, file, 
getTimeout(),
+                getResultsFilePath(), getOutputFilePath());
+        if (StringUtils.isNotBlank(payload)) {
+            instanceName += "," + payload;
+        }
+        return Script.runSimpleBashScript(String.format("systemd-escape '%s'", 
instanceName));
+    }
+
+    private String invokeService(String action, String stage, String file, 
String payload) {
+        s_logger.debug("Invoking rolling maintenance service for stage: " + 
stage + " and file " + file + " with action: " + action);
+        final OutputInterpreter.AllLinesParser parser = new 
OutputInterpreter.AllLinesParser();
+        Script command = new Script("/bin/systemctl", s_logger);
+        command.add(action);
+        String service = servicePrefix + "@" + generateInstanceName(stage, 
file, payload);
+        command.add(service);
+        String result = command.execute(parser);
+        int exitValue = command.getExitValue();
+        s_logger.trace("Execution: " + command.toString() + " - exit code: " + 
exitValue +
+                ": " + result + (StringUtils.isNotBlank(parser.getLines()) ? 
parser.getLines() : ""));
+        return StringUtils.isBlank(result) ? parser.getLines().replace("\n", 
"") : result;
 
 Review comment:
   maybe replace "\n" with " " instead of "", never know what gets concatenated.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to