Skip to content

Commit 30e6c22

Browse files
Merge branch '4.22'
2 parents c0db75b + 5caf6cd commit 30e6c22

File tree

19 files changed

+128
-41
lines changed

19 files changed

+128
-41
lines changed

api/src/main/java/com/cloud/host/Host.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ public static String[] toStrings(Host.Type... types) {
5959
String HOST_INSTANCE_CONVERSION = "host.instance.conversion";
6060
String HOST_OVFTOOL_VERSION = "host.ovftool.version";
6161
String HOST_VIRTV2V_VERSION = "host.virtv2v.version";
62+
String HOST_SSH_PORT = "host.ssh.port";
63+
64+
int DEFAULT_SSH_PORT = 22;
6265

6366
/**
6467
* @return name of the machine.

api/src/main/java/org/apache/cloudstack/api/command/admin/host/AddHostCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ public class AddHostCmd extends BaseCmd {
6060
@Parameter(name = ApiConstants.POD_ID, type = CommandType.UUID, entityType = PodResponse.class, required = true, description = "The Pod ID for the host")
6161
private Long podId;
6262

63-
@Parameter(name = ApiConstants.URL, type = CommandType.STRING, required = true, description = "The host URL")
63+
@Parameter(name = ApiConstants.URL, type = CommandType.STRING, required = true, description = "The host URL, optionally add ssh port (format: 'host:port') for KVM hosts," +
64+
" otherwise falls back to the port defined at the config 'kvm.host.discovery.ssh.port'")
6465
private String url;
6566

6667
@Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, required = true, description = "The Zone ID for the host")

engine/components-api/src/main/java/com/cloud/agent/AgentManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ public interface AgentManager {
5454
"This timeout overrides the wait global config. This holds a comma separated key value pairs containing timeout (in seconds) for specific commands. " +
5555
"For example: DhcpEntryCommand=600, SavePasswordCommand=300, VmDataCommand=300", false);
5656

57+
ConfigKey<Integer> KVMHostDiscoverySshPort = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, Integer.class,
58+
"kvm.host.discovery.ssh.port", String.valueOf(Host.DEFAULT_SSH_PORT), "SSH port used for KVM host discovery and any other operations on host (using SSH)." +
59+
" Please note that this is applicable when port is not defined through host url while adding the KVM host.", true, ConfigKey.Scope.Cluster);
60+
5761
enum TapAgentsAction {
5862
Add, Del, Contains,
5963
}
@@ -172,4 +176,6 @@ enum TapAgentsAction {
172176
void propagateChangeToAgents(Map<String, String> params);
173177

174178
boolean transferDirectAgentsFromMS(String fromMsUuid, long fromMsId, long timeoutDurationInMs, boolean excludeHostsInMaintenance);
179+
180+
int getHostSshPort(HostVO host);
175181
}

engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import javax.inject.Inject;
4343
import javax.naming.ConfigurationException;
4444

45+
import com.cloud.utils.StringUtils;
4546
import org.apache.cloudstack.agent.lb.IndirectAgentLB;
4647
import org.apache.cloudstack.ca.CAManager;
4748
import org.apache.cloudstack.command.ReconcileCommandService;
@@ -64,7 +65,6 @@
6465
import org.apache.commons.collections.MapUtils;
6566
import org.apache.commons.lang3.BooleanUtils;
6667
import org.apache.commons.lang3.ObjectUtils;
67-
import org.apache.commons.lang3.StringUtils;
6868
import org.apache.logging.log4j.ThreadContext;
6969

7070
import com.cloud.agent.AgentManager;
@@ -2111,7 +2111,7 @@ public ConfigKey<?>[] getConfigKeys() {
21112111
return new ConfigKey<?>[] { CheckTxnBeforeSending, Workers, Port, Wait, AlertWait, DirectAgentLoadSize,
21122112
DirectAgentPoolSize, DirectAgentThreadCap, EnableKVMAutoEnableDisable, ReadyCommandWait,
21132113
GranularWaitTimeForCommands, RemoteAgentSslHandshakeTimeout, RemoteAgentMaxConcurrentNewConnections,
2114-
RemoteAgentNewConnectionsMonitorInterval };
2114+
RemoteAgentNewConnectionsMonitorInterval, KVMHostDiscoverySshPort };
21152115
}
21162116

21172117
protected class SetHostParamsListener implements Listener {
@@ -2234,6 +2234,25 @@ public boolean transferDirectAgentsFromMS(String fromMsUuid, long fromMsId, long
22342234
return true;
22352235
}
22362236

2237+
@Override
2238+
public int getHostSshPort(HostVO host) {
2239+
if (host == null) {
2240+
return KVMHostDiscoverySshPort.value();
2241+
}
2242+
2243+
if (host.getHypervisorType() != HypervisorType.KVM) {
2244+
return Host.DEFAULT_SSH_PORT;
2245+
}
2246+
2247+
_hostDao.loadDetails(host);
2248+
String hostPort = host.getDetail(Host.HOST_SSH_PORT);
2249+
if (StringUtils.isBlank(hostPort)) {
2250+
return KVMHostDiscoverySshPort.valueIn(host.getClusterId());
2251+
}
2252+
2253+
return Integer.parseInt(hostPort);
2254+
}
2255+
22372256
private GlobalLock getHostJoinLock(Long hostId) {
22382257
return GlobalLock.getInternLock(String.format("%s-%s", "Host-Join", hostId));
22392258
}

engine/orchestration/src/test/java/com/cloud/agent/manager/AgentManagerImplTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.cloud.agent.api.StartupCommand;
2323
import com.cloud.agent.api.StartupRoutingCommand;
2424
import com.cloud.exception.ConnectionException;
25+
import com.cloud.host.Host;
2526
import com.cloud.host.HostVO;
2627
import com.cloud.host.Status;
2728
import com.cloud.host.dao.HostDao;
@@ -104,4 +105,36 @@ public void testGetTimeoutWithGranularTimeout() {
104105

105106
Assert.assertEquals(50, result);
106107
}
108+
109+
@Test
110+
public void testGetHostSshPortWithHostNull() {
111+
int hostSshPort = mgr.getHostSshPort(null);
112+
Assert.assertEquals(22, hostSshPort);
113+
}
114+
115+
@Test
116+
public void testGetHostSshPortWithNonKVMHost() {
117+
HostVO host = Mockito.mock(HostVO.class);
118+
Mockito.when(host.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.XenServer);
119+
int hostSshPort = mgr.getHostSshPort(host);
120+
Assert.assertEquals(22, hostSshPort);
121+
}
122+
123+
@Test
124+
public void testGetHostSshPortWithKVMHostDefaultPort() {
125+
HostVO host = Mockito.mock(HostVO.class);
126+
Mockito.when(host.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.KVM);
127+
Mockito.when(host.getClusterId()).thenReturn(1L);
128+
int hostSshPort = mgr.getHostSshPort(host);
129+
Assert.assertEquals(22, hostSshPort);
130+
}
131+
132+
@Test
133+
public void testGetHostSshPortWithKVMHostCustomPort() {
134+
HostVO host = Mockito.mock(HostVO.class);
135+
Mockito.when(host.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.KVM);
136+
Mockito.when(host.getDetail(Host.HOST_SSH_PORT)).thenReturn(String.valueOf(3922));
137+
int hostSshPort = mgr.getHostSshPort(host);
138+
Assert.assertEquals(3922, hostSshPort);
139+
}
107140
}

engine/schema/src/main/java/com/cloud/storage/dao/VolumeDaoImpl.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ public ImageFormat getImageFormat(Long volumeId) {
383383

384384
public VolumeDaoImpl() {
385385
AllFieldsSearch = createSearchBuilder();
386-
AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), Op.EQ);
386+
AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), Op.IN);
387387
AllFieldsSearch.and("accountId", AllFieldsSearch.entity().getAccountId(), Op.EQ);
388388
AllFieldsSearch.and("dcId", AllFieldsSearch.entity().getDataCenterId(), Op.EQ);
389389
AllFieldsSearch.and("pod", AllFieldsSearch.entity().getPodId(), Op.EQ);
@@ -581,17 +581,16 @@ public long secondaryStorageUsedForAccount(long accountId) {
581581

582582
@Override
583583
public List<VolumeVO> listVolumesToBeDestroyed() {
584-
SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
585-
sc.setParameters("state", Volume.State.Destroy);
586-
587-
return listBy(sc);
584+
return listVolumesToBeDestroyed(null);
588585
}
589586

590587
@Override
591588
public List<VolumeVO> listVolumesToBeDestroyed(Date date) {
592589
SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
593-
sc.setParameters("state", Volume.State.Destroy);
594-
sc.setParameters("updateTime", date);
590+
sc.setParameters("state", Volume.State.Destroy, Volume.State.Expunging);
591+
if (date != null) {
592+
sc.setParameters("updateTime", date);
593+
}
595594

596595
return listBy(sc);
597596
}

engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,9 @@ public AsyncCallFuture<VolumeApiResult> expungeVolumeAsync(VolumeInfo volume) {
436436
// no need to change state in volumes table
437437
volume.processEventOnly(Event.DestroyRequested);
438438
} else if (volume.getDataStore().getRole() == DataStoreRole.Primary) {
439+
if (vol.getState() == Volume.State.Expunging) {
440+
logger.info("Volume {} is already in Expunging, retrying", volume);
441+
}
439442
volume.processEvent(Event.ExpungeRequested);
440443
}
441444

plugins/backup/networker/src/main/java/org/apache/cloudstack/backup/NetworkerBackupProvider.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package org.apache.cloudstack.backup;
1818

19+
import com.cloud.agent.AgentManager;
1920
import com.cloud.dc.dao.ClusterDao;
2021
import com.cloud.host.HostVO;
2122
import com.cloud.host.Status;
@@ -134,6 +135,9 @@ public class NetworkerBackupProvider extends AdapterBase implements BackupProvid
134135
@Inject
135136
private DiskOfferingDao diskOfferingDao;
136137

138+
@Inject
139+
private AgentManager agentMgr;
140+
137141
private static String getUrlDomain(String url) throws URISyntaxException {
138142
URI uri;
139143
try {
@@ -251,8 +255,13 @@ private String executeBackupCommand(HostVO host, String username, String passwor
251255
String nstRegex = "\\bcompleted savetime=([0-9]{10})";
252256
Pattern saveTimePattern = Pattern.compile(nstRegex);
253257

258+
if (host == null) {
259+
LOG.warn("Unable to take backup, host is null");
260+
return null;
261+
}
262+
254263
try {
255-
Pair<Boolean, String> response = SshHelper.sshExecute(host.getPrivateIpAddress(), 22,
264+
Pair<Boolean, String> response = SshHelper.sshExecute(host.getPrivateIpAddress(), agentMgr.getHostSshPort(host),
256265
username, null, password, command, 120000, 120000, 3600000);
257266
if (!response.first()) {
258267
LOG.error("Backup Script failed on HYPERVISOR {} due to: {}", host, response.second());
@@ -271,9 +280,13 @@ private String executeBackupCommand(HostVO host, String username, String passwor
271280
return null;
272281
}
273282
private boolean executeRestoreCommand(HostVO host, String username, String password, String command) {
283+
if (host == null) {
284+
LOG.warn("Unable to restore backup, host is null");
285+
return false;
286+
}
274287

275288
try {
276-
Pair<Boolean, String> response = SshHelper.sshExecute(host.getPrivateIpAddress(), 22,
289+
Pair<Boolean, String> response = SshHelper.sshExecute(host.getPrivateIpAddress(), agentMgr.getHostSshPort(host),
277290
username, null, password, command, 120000, 120000, 3600000);
278291

279292
if (!response.first()) {

plugins/event-bus/rabbitmq/src/main/java/org/apache/cloudstack/mom/rabbitmq/RabbitMQEventBus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ public boolean start() {
493493

494494
@Override
495495
public synchronized boolean stop() {
496-
if (s_connection.isOpen()) {
496+
if (s_connection != null && s_connection.isOpen()) {
497497
for (String subscriberId : s_subscribers.keySet()) {
498498
Ternary<String, Channel, EventSubscriber> subscriberDetails = s_subscribers.get(subscriberId);
499499
Channel channel = subscriberDetails.second();

plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/OauthLoginAPIAuthenticatorCmd.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,8 @@ private String doOauthAuthentication(HttpSession session, Long domainId, String
184184

185185
protected Long getDomainIdFromParams(Map<String, Object[]> params, StringBuilder auditTrailSb, String responseType) {
186186
String[] domainIdArr = (String[])params.get(ApiConstants.DOMAIN_ID);
187-
188-
if (domainIdArr == null) {
189-
domainIdArr = (String[])params.get(ApiConstants.DOMAIN__ID);
190-
}
191187
Long domainId = null;
192-
if ((domainIdArr != null) && (domainIdArr.length > 0)) {
188+
if (domainIdArr != null && domainIdArr.length > 0) {
193189
try {
194190
//check if UUID is passed in for domain
195191
domainId = _apiServer.fetchDomainId(domainIdArr[0]);

0 commit comments

Comments
 (0)