Skip to content

Commit efa0417

Browse files
Abhinandan Prateekroot
authored andcommitted
bug 5242: adding a host does not return useful error
status 5242: closed fixed
1 parent 8c5c58d commit efa0417

6 files changed

Lines changed: 33 additions & 7 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.cloud.exception;
2+
3+
import com.cloud.utils.SerialVersionUID;
4+
5+
public class DiscoveredWithErrorException extends DiscoveryException {
6+
7+
private static final long serialVersionUID = SerialVersionUID.DiscoveredWithErrorException;
8+
9+
public DiscoveredWithErrorException(String msg) {
10+
this(msg, null);
11+
}
12+
13+
public DiscoveredWithErrorException(String msg, Throwable cause) {
14+
super(msg, cause);
15+
}
16+
}

‎core/src/com/cloud/hypervisor/xen/resource/XenServerConnectionPool.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ public Connection masterConnect(String ip, String username, String password) {
298298
}
299299

300300

301-
public String getMasterIp(String ip, String username, String password) {
301+
public String getMasterIp(String ip, String username, String password) throws XenAPIException {
302302
Connection slaveConn = null;
303303
try{
304304
slaveConn = new Connection(getURL(ip), 10);
@@ -312,6 +312,9 @@ public String getMasterIp(String ip, String username, String password) {
312312
Host master = pr.master;
313313
masterIp = master.getAddress(slaveConn);
314314
return masterIp;
315+
}catch(Types.SessionAuthenticationFailed e){
316+
s_logger.debug("Failed to slave local login to " + ip + " due to " + e.toString());
317+
throw e;
315318
}catch ( Exception e){
316319
s_logger.debug("Failed to slave local login to " + ip + " due to " + e.toString());
317320
} finally {

‎server/src/com/cloud/agent/manager/AgentManagerImpl.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
import com.cloud.event.dao.EventDao;
107107
import com.cloud.exception.AgentUnavailableException;
108108
import com.cloud.exception.ConnectionException;
109+
import com.cloud.exception.DiscoveredWithErrorException;
109110
import com.cloud.exception.DiscoveryException;
110111
import com.cloud.exception.InsufficientServerCapacityException;
111112
import com.cloud.exception.InvalidParameterValueException;
@@ -970,7 +971,9 @@ private List<HostVO> discoverHostsFull(Long dcId, Long podId, Long clusterId,
970971
try {
971972
resources = discoverer.find(dcId, podId, clusterId, uri,
972973
username, password);
973-
} catch (Exception e) {
974+
} catch (DiscoveredWithErrorException e){
975+
throw e;
976+
}catch (Exception e) {
974977
s_logger.info("Exception in host discovery process with discoverer: "
975978
+ discoverer.getName()
976979
+ ", skip to another discoverer if there is any");

‎server/src/com/cloud/hypervisor/kvm/discoverer/KvmServerDiscoverer.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import com.cloud.configuration.dao.ConfigurationDao;
4141
import com.cloud.dc.ClusterVO;
4242
import com.cloud.dc.dao.ClusterDao;
43+
import com.cloud.exception.DiscoveredWithErrorException;
4344
import com.cloud.exception.DiscoveryException;
4445
import com.cloud.host.Host;
4546
import com.cloud.host.HostVO;
@@ -157,7 +158,7 @@ public Map<? extends ServerResource, Map<String, String>> find(long dcId,
157158
sshConnection.connect(null, 60000, 60000);
158159
if (!sshConnection.authenticateWithPassword(username, password)) {
159160
s_logger.debug("Failed to authenticate");
160-
return null;
161+
throw new DiscoveredWithErrorException("Authetication error");
161162
}
162163

163164
if (!SSHCmdHelper.sshExecuteCmd(sshConnection, "lsmod|grep kvm >& /dev/null", 3)) {
@@ -198,7 +199,9 @@ public Map<? extends ServerResource, Map<String, String>> find(long dcId,
198199

199200
details.put("guid", guidWithTail);
200201
return resources;
201-
} catch (Exception e) {
202+
} catch (DiscoveredWithErrorException e){
203+
throw e;
204+
}catch (Exception e) {
202205
String msg = " can't setup agent, due to " + e.toString() + " - " + e.getMessage();
203206
s_logger.warn(msg);
204207
} finally {

‎server/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import com.cloud.dc.dao.ClusterDao;
4747
import com.cloud.exception.AgentUnavailableException;
4848
import com.cloud.exception.ConnectionException;
49+
import com.cloud.exception.DiscoveredWithErrorException;
4950
import com.cloud.exception.DiscoveryException;
5051
import com.cloud.exception.OperationTimedoutException;
5152
import com.cloud.host.HostEnvironment;
@@ -290,9 +291,8 @@ public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long p
290291
resource.start();
291292
resources.put(resource, details);
292293
}
293-
} catch (SessionAuthenticationFailed e) {
294-
s_logger.warn("Authentication error", e);
295-
return null;
294+
} catch (SessionAuthenticationFailed e) {
295+
throw new DiscoveredWithErrorException("Authetication error");
296296
} catch (XenAPIException e) {
297297
s_logger.warn("XenAPI exception", e);
298298
return null;

‎utils/src/com/cloud/utils/SerialVersionUID.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,5 @@ public interface SerialVersionUID {
6262
public static final long sshException = Base | 0x22;
6363
public static final long HttpCallException = Base | 0x23;
6464
public static final long VirtualMachineMigrationException = Base | 0x24;
65+
public static final long DiscoveredWithErrorException = Base | 0x25;
6566
}

0 commit comments

Comments
 (0)