bug 12040: fixed the problem where if the connection is not retrievable, we cause a classcastexception

Reviewed-by: Anthony
This commit is contained in:
Alex Huang 2011-11-15 12:02:05 -08:00
parent 58a09e00a7
commit 67aa34f46d
3 changed files with 14 additions and 4 deletions

View File

@ -45,6 +45,10 @@ public class RebootAnswer extends Answer {
bytesReceived = null;
}
public RebootAnswer(RebootCommand cmd, Exception e) {
super(cmd, e);
}
public void setBytesReceived(Long bytesReceived) {
this.bytesReceived = bytesReceived;
}

View File

@ -34,6 +34,11 @@ public class StopAnswer extends RebootAnswer {
}
public StopAnswer(StopCommand cmd, Exception e) {
super(cmd, e);
}
@Override
public Integer getVncPort() {
return vncPort;
}

View File

@ -103,7 +103,6 @@ import com.cloud.agent.api.ModifyStoragePoolAnswer;
import com.cloud.agent.api.ModifyStoragePoolCommand;
import com.cloud.agent.api.NetworkRulesSystemVmCommand;
import com.cloud.agent.api.PingCommand;
import com.cloud.agent.api.PingRoutingCommand;
import com.cloud.agent.api.PingRoutingWithNwGroupsCommand;
import com.cloud.agent.api.PingRoutingWithOvsCommand;
import com.cloud.agent.api.PingTestCommand;
@ -123,7 +122,6 @@ import com.cloud.agent.api.StartAnswer;
import com.cloud.agent.api.StartCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupRoutingCommand;
import com.cloud.agent.api.StartupRoutingCommand.VmState;
import com.cloud.agent.api.StartupStorageCommand;
import com.cloud.agent.api.StopAnswer;
import com.cloud.agent.api.StopCommand;
@ -2855,7 +2853,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
task = vm.poolMigrateAsync(conn, destHost, other);
try {
// poll every 1 seconds
long timeout = (long)(_migratewait) * 1000L;
long timeout = (_migratewait) * 1000L;
waitForTask(conn, task, 1000, timeout);
checkForSuccess(conn, task);
} catch (Types.HandleInvalid e) {
@ -3040,9 +3038,9 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
@Override
public StopAnswer execute(StopCommand cmd) {
Connection conn = getConnection();
String vmName = cmd.getVmName();
try {
Connection conn = getConnection();
Set<VM> vms = VM.getByNameLabel(conn, vmName);
// stop vm which is running on this host or is in halted state
Iterator<VM> iter = vms.iterator();
@ -3158,6 +3156,9 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
String msg = "Stop Vm " + vmName + " fail due to " + e.getMessage();
s_logger.warn(msg, e);
return new StopAnswer(cmd, msg);
} catch (Exception e) {
s_logger.warn("Unable to stop " + vmName + " due to ", e);
return new StopAnswer(cmd, e);
}
return new StopAnswer(cmd, "Stop VM failed");
}