CLOUDSTACK-6478: Failed to download Template when having 3 SSVM's in one

zone on Vmware.
This commit is contained in:
Min Chen 2014-04-22 19:14:55 -07:00
parent 9c4d20cb68
commit 8e286996c8
1 changed files with 32 additions and 11 deletions

View File

@ -25,8 +25,7 @@ import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import org.apache.log4j.Logger;
import com.cloud.vm.SecondaryStorageVmVO;
import com.cloud.vm.dao.SecondaryStorageVmDao;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
@ -43,11 +42,15 @@ import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.ConnectionException;
import com.cloud.exception.OperationTimedoutException;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.host.Status;
import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.HypervisorGuruManager;
import com.cloud.utils.component.ComponentContext;
import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.SecondaryStorageVmVO;
import com.cloud.vm.dao.SecondaryStorageVmDao;
public class RemoteHostEndPoint implements EndPoint {
private static final Logger s_logger = Logger.getLogger(RemoteHostEndPoint.class);
@ -60,6 +63,8 @@ public class RemoteHostEndPoint implements EndPoint {
protected HypervisorGuruManager _hvGuruMgr;
@Inject
protected SecondaryStorageVmDao vmDao;
@Inject
protected HostDao _hostDao;
private ScheduledExecutorService executor;
public RemoteHostEndPoint() {
@ -67,14 +72,14 @@ public class RemoteHostEndPoint implements EndPoint {
}
private void configure(Host host) {
this.hostId = host.getId();
this.hostAddress = host.getPrivateIpAddress();
this.publicAddress = host.getPublicIpAddress();
hostId = host.getId();
hostAddress = host.getPrivateIpAddress();
publicAddress = host.getPublicIpAddress();
if (Host.Type.SecondaryStorageVM == host.getType()) {
String vmName = host.getName();
SecondaryStorageVmVO ssvm = vmDao.findByInstanceName(vmName);
if (ssvm != null) {
this.publicAddress = ssvm.getPublicIpAddress();
publicAddress = ssvm.getPublicIpAddress();
}
}
}
@ -87,17 +92,25 @@ public class RemoteHostEndPoint implements EndPoint {
@Override
public String getHostAddr() {
return this.hostAddress;
return hostAddress;
}
@Override
public String getPublicAddr() {
return this.publicAddress;
return publicAddress;
}
@Override
public long getId() {
return this.hostId;
return hostId;
}
// used when HypervisorGuruManager choose a different host to send command
private void setId(long id) {
HostVO host = _hostDao.findById(hostId);
if (host != null) {
configure(host);
}
}
@Override
@ -105,6 +118,10 @@ public class RemoteHostEndPoint implements EndPoint {
String errMsg = null;
try {
long newHostId = _hvGuruMgr.getGuruProcessedCommandTargetHost(hostId, cmd);
if (newHostId != hostId) {
// update endpoint with new host if changed
setId(newHostId);
}
return agentMgr.send(newHostId, cmd);
} catch (AgentUnavailableException e) {
errMsg = e.toString();
@ -126,7 +143,7 @@ public class RemoteHostEndPoint implements EndPoint {
@Override
public boolean processAnswers(long agentId, long seq, Answer[] answers) {
this.answer = answers[0];
answer = answers[0];
executor.schedule(this, 10, TimeUnit.SECONDS);
return true;
}
@ -182,7 +199,11 @@ public class RemoteHostEndPoint implements EndPoint {
@Override
public void sendMessageAsync(Command cmd, AsyncCompletionCallback<Answer> callback) {
try {
long newHostId = _hvGuruMgr.getGuruProcessedCommandTargetHost(this.hostId, cmd);
long newHostId = _hvGuruMgr.getGuruProcessedCommandTargetHost(hostId, cmd);
if (newHostId != hostId) {
// update endpoint with new host if changed
setId(newHostId);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Sending command " + cmd.toString() + " to host: " + newHostId);
}