Skip to content

Commit a66f741

Browse files
committed
fixups
1 parent a77ed3e commit a66f741

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

server/src/main/java/org/apache/cloudstack/ca/CAManagerImpl.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,27 @@ private boolean provisionKvmHostViaSsh(Host host, String caProvider) {
324324
provisionCertificateViaSsh(sshConnection, hostIp, host.getName(), caProvider);
325325

326326
SSHCmdHelper.sshExecuteCmd(sshConnection, "sudo service cloudstack-agent restart");
327+
328+
long start = System.currentTimeMillis();
329+
while ((System.currentTimeMillis() - start) < 120000) {
330+
Host refreshedHost = hostDao.findById(host.getId());
331+
if (refreshedHost != null && (refreshedHost.getStatus() == Status.Up || refreshedHost.getStatus() == Status.Alert)) {
332+
logger.debug("Host {} is now in {} state, attempting to reconnect", host, refreshedHost.getStatus());
333+
try {
334+
agentManager.reconnect(host.getId());
335+
logger.debug("Successfully reconnected agent to host {}", host);
336+
} catch (AgentUnavailableException | CloudRuntimeException e) {
337+
logger.warn("Failed to reconnect agent to host {} after certificate provisioning", host, e);
338+
}
339+
break;
340+
}
341+
try {
342+
Thread.sleep(5000);
343+
} catch (InterruptedException e) {
344+
logger.debug("Interrupted while polling for host {} status", host);
345+
break;
346+
}
347+
}
327348
return true;
328349
} catch (Exception e) {
329350
logger.error("Error during forced SSH provisioning for KVM host " + host.getUuid(), e);

server/src/test/java/org/apache/cloudstack/ca/CAManagerImplTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ public void testProvisionCertificateViaSsh() throws Exception {
264264
@Test
265265
public void testProvisionKvmHostViaSsh() throws Exception {
266266
HostVO host = Mockito.mock(HostVO.class);
267+
Mockito.when(host.getId()).thenReturn(1L);
268+
Mockito.when(host.getStatus()).thenReturn(com.cloud.host.Status.Up);
269+
Mockito.when(hostDao.findById(1L)).thenReturn(host);
267270
Mockito.when(host.getPrivateIpAddress()).thenReturn("192.168.1.1");
268271
Mockito.when(host.getName()).thenReturn("host1");
269272
Mockito.when(host.getClusterId()).thenReturn(1L);

services/console-proxy/server/src/main/java/com/cloud/consoleproxy/vnc/network/NioSocketSSLEngineManager.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import javax.net.ssl.SSLSession;
2525
import java.io.IOException;
2626
import java.nio.ByteBuffer;
27-
import java.util.concurrent.Executor;
28-
import java.util.concurrent.Executors;
2927

3028
public class NioSocketSSLEngineManager {
3129

@@ -34,7 +32,6 @@ public class NioSocketSSLEngineManager {
3432
private final ByteBuffer myNetData;
3533
private final ByteBuffer peerNetData;
3634

37-
private final Executor executor;
3835
private final NioSocketInputStream inputStream;
3936
private final NioSocketOutputStream outputStream;
4037

@@ -43,8 +40,6 @@ public NioSocketSSLEngineManager(SSLEngine sslEngine, NioSocketHandler socket) {
4340
this.outputStream = socket.getOutputStream();
4441
engine = sslEngine;
4542

46-
executor = Executors.newSingleThreadExecutor();
47-
4843
int networkBufSize = Math.max(engine.getSession().getPacketBufferSize(), ConsoleProxy.defaultBufferSize);
4944
myNetData = ByteBuffer.allocate(networkBufSize);
5045
peerNetData = ByteBuffer.allocate(networkBufSize);
@@ -129,7 +124,7 @@ public void doHandshake() throws SSLException {
129124
private void executeTasks() {
130125
Runnable task;
131126
while ((task = engine.getDelegatedTask()) != null) {
132-
executor.execute(task);
127+
task.run();
133128
}
134129
}
135130

utils/src/main/java/com/cloud/utils/nio/Link.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
import java.security.KeyStore;
3333
import java.security.SecureRandom;
3434
import java.util.concurrent.ConcurrentLinkedQueue;
35-
import java.util.concurrent.Executor;
36-
import java.util.concurrent.Executors;
35+
3736

3837
import javax.net.ssl.KeyManagerFactory;
3938
import javax.net.ssl.SSLContext;
@@ -430,7 +429,7 @@ public static SSLContext initClientSSLContext() throws GeneralSecurityException,
430429
}
431430

432431
final KeyStore ks = loadKeyStore(stream, passphrase);
433-
final TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
432+
final TrustManagerFactory tmf = TrustManagerFactory.getInstance("PKIX");
434433
tmf.init(ks);
435434
TrustManager[] tms;
436435
if (stream != null) {
@@ -607,7 +606,6 @@ public static boolean doHandshake(final SocketChannel socketChannel, final SSLEn
607606
ByteBuffer myNetData = ByteBuffer.allocate(netBufferSize);
608607
ByteBuffer peerNetData = ByteBuffer.allocate(netBufferSize);
609608

610-
final Executor executor = Executors.newSingleThreadExecutor();
611609
final long startTimeMills = System.currentTimeMillis();
612610

613611
HandshakeStatus handshakeStatus = sslEngine.getHandshakeStatus();
@@ -644,7 +642,7 @@ public static boolean doHandshake(final SocketChannel socketChannel, final SSLEn
644642
if (LOGGER.isTraceEnabled()) {
645643
LOGGER.trace("SSL: Running delegated task!");
646644
}
647-
executor.execute(task);
645+
task.run();
648646
}
649647
break;
650648
case FINISHED:

0 commit comments

Comments
 (0)