[GitHub] [cloudstack] nvazquez commented on a change in pull request #3610: [WIP DO NOT MERGE] KVM: Rolling maintenance

2020-01-14 Thread GitBox
nvazquez commented on a change in pull request #3610: [WIP DO NOT MERGE] KVM: 
Rolling maintenance
URL: https://github.com/apache/cloudstack/pull/3610#discussion_r366670739
 
 

 ##
 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:
   Thanks


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


[GitHub] [cloudstack] nvazquez commented on a change in pull request #3610: [WIP DO NOT MERGE] KVM: Rolling maintenance

2020-01-14 Thread GitBox
nvazquez commented on a change in pull request #3610: [WIP DO NOT MERGE] KVM: 
Rolling maintenance
URL: https://github.com/apache/cloudstack/pull/3610#discussion_r366670742
 
 

 ##
 File path: 
api/src/main/java/org/apache/cloudstack/api/response/RollingMaintenanceHotsUpdatedResponse.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.cloudstack.api.response;
+
+import com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseResponse;
+
+public class RollingMaintenanceHotsUpdatedResponse extends BaseResponse {
 
 Review comment:
   Thanks, typo


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


[GitHub] [cloudstack] nvazquez commented on a change in pull request #3610: [WIP DO NOT MERGE] KVM: Rolling maintenance

2020-01-14 Thread GitBox
nvazquez commented on a change in pull request #3610: [WIP DO NOT MERGE] KVM: 
Rolling maintenance
URL: https://github.com/apache/cloudstack/pull/3610#discussion_r366670742
 
 

 ##
 File path: 
api/src/main/java/org/apache/cloudstack/api/response/RollingMaintenanceHotsUpdatedResponse.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.cloudstack.api.response;
+
+import com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseResponse;
+
+public class RollingMaintenanceHotsUpdatedResponse extends BaseResponse {
 
 Review comment:
   Thanks, typo


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


[GitHub] [cloudstack] nvazquez commented on a change in pull request #3610: [WIP DO NOT MERGE] KVM: Rolling maintenance

2020-01-14 Thread GitBox
nvazquez commented on a change in pull request #3610: [WIP DO NOT MERGE] KVM: 
Rolling maintenance
URL: https://github.com/apache/cloudstack/pull/3610#discussion_r366670739
 
 

 ##
 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:
   Thanks


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


[GitHub] [cloudstack] nvazquez commented on a change in pull request #3610: [WIP DO NOT MERGE] KVM: Rolling maintenance

2020-01-14 Thread GitBox
nvazquez commented on a change in pull request #3610: [WIP DO NOT MERGE] KVM: 
Rolling maintenance
URL: https://github.com/apache/cloudstack/pull/3610#discussion_r366676939
 
 

 ##
 File path: api/src/main/java/com/cloud/resource/RollingMaintenanceManager.java
 ##
 @@ -0,0 +1,127 @@
+// 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.resource;
+
+import com.cloud.host.Host;
+import com.cloud.utils.Pair;
+import com.cloud.utils.exception.CloudRuntimeException;
+import 
org.apache.cloudstack.api.command.admin.resource.StartRollingMaintenanceCmd;
+import org.apache.cloudstack.framework.config.ConfigKey;
+import org.apache.cloudstack.framework.config.Configurable;
+import org.apache.commons.lang3.tuple.Triple;
+
+import java.util.Date;
+import java.util.List;
+
+public interface RollingMaintenanceManager extends Configurable {
 
 Review comment:
   Would be nice to have but not adding it now as wasn't part of this feature 
scope. It however keeps track of the updated and skipped hosts but that 
information is retrieved when the process ends/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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services