Skip to content

Commit c98278f

Browse files
authored
Merge pull request #640 from jschoiRR/mold-main#2025
[Mold API, Agent] 클러스터 HA 활성화 시 pcs stonith 활성화, 비활성화 이벤트 전달 / OpenVSwitch 기능을 사용하는 조건일때 nwfilter xml(<filterref filter='allow-all-traffic'/>) 태그를 사용하지 않도록 수정
2 parents 46e2a1a + 9069f74 commit c98278f

File tree

4 files changed

+110
-5
lines changed

4 files changed

+110
-5
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package com.cloud.agent.api;
21+
22+
public class UpdateHaStateCommand extends Command {
23+
24+
String hostHAState;
25+
26+
public UpdateHaStateCommand(String hostHAState) {
27+
this.hostHAState = hostHAState;
28+
}
29+
30+
public String getHostHAState() {
31+
return hostHAState;
32+
}
33+
34+
@Override
35+
public boolean executeInSequence() {
36+
return true;
37+
}
38+
}

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3759,7 +3759,16 @@ private void createVif(final LibvirtVMDef vm, final VirtualMachineTO vmSpec, fin
37593759
throw new InternalErrorException("LibvirtVMDef object get devices with null result");
37603760
}
37613761
final InterfaceDef interfaceDef = getVifDriver(nic.getType(), nic.getName()).plug(nic, vm.getPlatformEmulator(), nicAdapter, extraConfig);
3762-
if (!nic.isSecurityGroupEnabled()) {
3762+
3763+
String defaultVifDriver = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.LIBVIRT_VIF_DRIVER);
3764+
final String bridgeType = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.NETWORK_BRIDGE_TYPE);
3765+
boolean enableOVSDriver = false;
3766+
3767+
if (defaultVifDriver != null && defaultVifDriver.equals(DEFAULT_OVS_VIF_DRIVER_CLASS_NAME) && bridgeType != null && "openvswitch".equals(bridgeType)) {
3768+
enableOVSDriver = true;
3769+
}
3770+
3771+
if (!nic.isSecurityGroupEnabled() && !enableOVSDriver) {
37633772
interfaceDef.setFilterrefFilterTag();
37643773
}
37653774
if (vmSpec.getDetails() != null) {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package com.cloud.hypervisor.kvm.resource.wrapper;
21+
22+
import com.cloud.agent.api.Answer;
23+
import com.cloud.agent.api.UpdateHaStateCommand;
24+
import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource;
25+
import com.cloud.resource.CommandWrapper;
26+
import com.cloud.resource.ResourceWrapper;
27+
import com.cloud.utils.script.Script;
28+
29+
@ResourceWrapper(handles = UpdateHaStateCommand.class)
30+
public final class LibvirtUpdateHaStateCommandWrapper extends CommandWrapper<UpdateHaStateCommand, Answer, LibvirtComputingResource> {
31+
@Override
32+
public Answer execute(UpdateHaStateCommand command, LibvirtComputingResource serverResource) {
33+
logger.debug(String.format("HA state change : [%s]", command.getHostHAState()));
34+
final String listStonith = Script.runSimpleBashScript("pcs stonith status | awk '{print $2}' | xargs");
35+
if (!"".equals(listStonith) && !"stonith".equals(listStonith)) {
36+
final String[] list = listStonith.split(" ");
37+
for (String ls : list) {
38+
Script.runSimpleBashScript("pcs stonith " + command.getHostHAState() + " " + ls);
39+
}
40+
logger.debug(String.format("Update PCS Stonith State : [%s]", command.getHostHAState()));
41+
}
42+
return new Answer(command, true, "success");
43+
}
44+
}

server/src/main/java/org/apache/cloudstack/ha/HAManagerImpl.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import org.apache.cloudstack.poll.BackgroundPollManager;
6565
import org.apache.cloudstack.poll.BackgroundPollTask;
6666
import org.apache.cloudstack.utils.identity.ManagementServerNode;
67+
import org.apache.commons.collections.CollectionUtils;
6768
import org.apache.commons.lang3.StringUtils;
6869

6970
import com.cloud.host.HostVO;
@@ -90,6 +91,7 @@
9091
import com.cloud.vm.dao.VMInstanceDao;
9192
import com.cloud.vm.UserVmService;
9293
import com.cloud.org.Cluster;
94+
import com.cloud.resource.ResourceManager;
9395
import com.cloud.resource.ResourceService;
9496
import com.cloud.storage.DiskOfferingVO;
9597
import com.cloud.storage.VolumeVO;
@@ -108,6 +110,7 @@
108110
import com.google.common.base.Preconditions;
109111
import org.apache.cloudstack.api.ResponseGenerator;
110112
import com.cloud.agent.AgentManager;
113+
import com.cloud.agent.api.UpdateHaStateCommand;
111114
import com.cloud.api.query.vo.UserVmJoinVO;
112115
import com.cloud.api.query.dao.UserVmJoinDao;
113116

@@ -152,6 +155,9 @@ public final class HAManagerImpl extends ManagerBase implements HAManager, Clust
152155
@Inject
153156
private DiskOfferingDao diskOfferingDao;
154157

158+
@Inject
159+
private ResourceManager resourceManager;
160+
155161
private List<HAProvider<HAResource>> haProviders;
156162
private Map<String, HAProvider<HAResource>> haProviderMap = new HashMap<>();
157163

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

475+
List<? extends HAResource> hosts = hostDao.findHypervisorHostInCluster(cluster.getId());
476+
if (CollectionUtils.isNotEmpty(hosts)) {
477+
UpdateHaStateCommand cmd = new UpdateHaStateCommand("enable");
478+
_agentMgr.easySend(hosts.get(0).getId(), cmd);
479+
}
469480
//host enableHA
470481
if (includeHost) {
471-
List<? extends HAResource> resources = hostDao.findByClusterId(cluster.getId());
472-
for (HAResource resource : resources) {
482+
for (HAResource resource : hosts) {
473483
final HAConfig haConfig = haConfigDao.findHAResource(resource.getId(), resource.resourceType());
474484
if (haConfig == null) {
475485
boolean configureHA = configureHA(resource.getId(), resource.resourceType(), true, "kvmhaprovider");
@@ -486,10 +496,14 @@ public boolean enableHA(final Cluster cluster, Boolean includeHost) {
486496
public boolean disableHA(final Cluster cluster, Boolean includeHost) {
487497
clusterDetailsDao.persist(cluster.getId(), HA_ENABLED_DETAIL, String.valueOf(false));
488498

499+
List<? extends HAResource> hosts = hostDao.findHypervisorHostInCluster(cluster.getId());
500+
if (CollectionUtils.isNotEmpty(hosts)) {
501+
UpdateHaStateCommand cmd = new UpdateHaStateCommand("disable");
502+
_agentMgr.easySend(hosts.get(0).getId(), cmd);
503+
}
489504
//host disableHA
490505
if (includeHost) {
491-
List<? extends HAResource> resources = hostDao.findByClusterId(cluster.getId());
492-
for (HAResource resource : resources) {
506+
for (HAResource resource : hosts) {
493507
final HAConfig haConfig = haConfigDao.findHAResource(resource.getId(), resource.resourceType());
494508
if (haConfig != null && haConfig.isEnabled()) {
495509
boolean result = disableHA(resource.getId(), resource.resourceType());

0 commit comments

Comments
 (0)