Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions core/src/main/java/com/cloud/agent/api/UpdateHaStateCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// 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.agent.api;

public class UpdateHaStateCommand extends Command {

String hostHAState;

public UpdateHaStateCommand(String hostHAState) {
this.hostHAState = hostHAState;
}

public String getHostHAState() {
return hostHAState;
}

@Override
public boolean executeInSequence() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3759,7 +3759,16 @@ private void createVif(final LibvirtVMDef vm, final VirtualMachineTO vmSpec, fin
throw new InternalErrorException("LibvirtVMDef object get devices with null result");
}
final InterfaceDef interfaceDef = getVifDriver(nic.getType(), nic.getName()).plug(nic, vm.getPlatformEmulator(), nicAdapter, extraConfig);
if (!nic.isSecurityGroupEnabled()) {

String defaultVifDriver = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.LIBVIRT_VIF_DRIVER);
final String bridgeType = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.NETWORK_BRIDGE_TYPE);
boolean enableOVSDriver = false;

if (defaultVifDriver != null && defaultVifDriver.equals(DEFAULT_OVS_VIF_DRIVER_CLASS_NAME) && bridgeType != null && "openvswitch".equals(bridgeType)) {
enableOVSDriver = true;
}

if (!nic.isSecurityGroupEnabled() && !enableOVSDriver) {
interfaceDef.setFilterrefFilterTag();
}
if (vmSpec.getDetails() != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// 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.wrapper;

import com.cloud.agent.api.Answer;
import com.cloud.agent.api.UpdateHaStateCommand;
import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource;
import com.cloud.resource.CommandWrapper;
import com.cloud.resource.ResourceWrapper;
import com.cloud.utils.script.Script;

@ResourceWrapper(handles = UpdateHaStateCommand.class)
public final class LibvirtUpdateHaStateCommandWrapper extends CommandWrapper<UpdateHaStateCommand, Answer, LibvirtComputingResource> {
@Override
public Answer execute(UpdateHaStateCommand command, LibvirtComputingResource serverResource) {
logger.debug(String.format("HA state change : [%s]", command.getHostHAState()));
final String listStonith = Script.runSimpleBashScript("pcs stonith status | awk '{print $2}' | xargs");
if (!"".equals(listStonith) && !"stonith".equals(listStonith)) {
final String[] list = listStonith.split(" ");
for (String ls : list) {
Script.runSimpleBashScript("pcs stonith " + command.getHostHAState() + " " + ls);
}
logger.debug(String.format("Update PCS Stonith State : [%s]", command.getHostHAState()));
}
return new Answer(command, true, "success");
}
}
22 changes: 18 additions & 4 deletions server/src/main/java/org/apache/cloudstack/ha/HAManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import org.apache.cloudstack.poll.BackgroundPollManager;
import org.apache.cloudstack.poll.BackgroundPollTask;
import org.apache.cloudstack.utils.identity.ManagementServerNode;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import com.cloud.host.HostVO;
Expand All @@ -90,6 +91,7 @@
import com.cloud.vm.dao.VMInstanceDao;
import com.cloud.vm.UserVmService;
import com.cloud.org.Cluster;
import com.cloud.resource.ResourceManager;
import com.cloud.resource.ResourceService;
import com.cloud.storage.DiskOfferingVO;
import com.cloud.storage.VolumeVO;
Expand All @@ -108,6 +110,7 @@
import com.google.common.base.Preconditions;
import org.apache.cloudstack.api.ResponseGenerator;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.UpdateHaStateCommand;
import com.cloud.api.query.vo.UserVmJoinVO;
import com.cloud.api.query.dao.UserVmJoinDao;

Expand Down Expand Up @@ -152,6 +155,9 @@ public final class HAManagerImpl extends ManagerBase implements HAManager, Clust
@Inject
private DiskOfferingDao diskOfferingDao;

@Inject
private ResourceManager resourceManager;

private List<HAProvider<HAResource>> haProviders;
private Map<String, HAProvider<HAResource>> haProviderMap = new HashMap<>();

Expand Down Expand Up @@ -466,10 +472,14 @@ public boolean disableHA(final Long resourceId, final HAResource.ResourceType re
public boolean enableHA(final Cluster cluster, Boolean includeHost) {
clusterDetailsDao.persist(cluster.getId(), HA_ENABLED_DETAIL, String.valueOf(true));

List<? extends HAResource> hosts = hostDao.findHypervisorHostInCluster(cluster.getId());
if (CollectionUtils.isNotEmpty(hosts)) {
UpdateHaStateCommand cmd = new UpdateHaStateCommand("enable");
_agentMgr.easySend(hosts.get(0).getId(), cmd);
}
//host enableHA
if (includeHost) {
List<? extends HAResource> resources = hostDao.findByClusterId(cluster.getId());
for (HAResource resource : resources) {
for (HAResource resource : hosts) {
final HAConfig haConfig = haConfigDao.findHAResource(resource.getId(), resource.resourceType());
if (haConfig == null) {
boolean configureHA = configureHA(resource.getId(), resource.resourceType(), true, "kvmhaprovider");
Expand All @@ -486,10 +496,14 @@ public boolean enableHA(final Cluster cluster, Boolean includeHost) {
public boolean disableHA(final Cluster cluster, Boolean includeHost) {
clusterDetailsDao.persist(cluster.getId(), HA_ENABLED_DETAIL, String.valueOf(false));

List<? extends HAResource> hosts = hostDao.findHypervisorHostInCluster(cluster.getId());
if (CollectionUtils.isNotEmpty(hosts)) {
UpdateHaStateCommand cmd = new UpdateHaStateCommand("disable");
_agentMgr.easySend(hosts.get(0).getId(), cmd);
}
//host disableHA
if (includeHost) {
List<? extends HAResource> resources = hostDao.findByClusterId(cluster.getId());
for (HAResource resource : resources) {
for (HAResource resource : hosts) {
final HAConfig haConfig = haConfigDao.findHAResource(resource.getId(), resource.resourceType());
if (haConfig != null && haConfig.isEnabled()) {
boolean result = disableHA(resource.getId(), resource.resourceType());
Expand Down
Loading