Skip to content

Commit 1772fcf

Browse files
minchen07sebgoa
authored andcommitted
CLOUDSTACK-6478: Failed to download Template when having 3 SSVM's in one
1 parent f304df0 commit 1772fcf

1 file changed

Lines changed: 33 additions & 11 deletions

File tree

‎engine/storage/src/org/apache/cloudstack/storage/RemoteHostEndPoint.java‎

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
import javax.inject.Inject;
2626

27-
import com.cloud.vm.SecondaryStorageVmVO;
28-
import com.cloud.vm.dao.SecondaryStorageVmDao;
27+
import org.apache.log4j.Logger;
28+
2929
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
3030
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
3131
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
@@ -43,11 +43,15 @@
4343
import com.cloud.exception.ConnectionException;
4444
import com.cloud.exception.OperationTimedoutException;
4545
import com.cloud.host.Host;
46+
import com.cloud.host.HostVO;
4647
import com.cloud.host.Status;
48+
import com.cloud.host.dao.HostDao;
4749
import com.cloud.hypervisor.HypervisorGuruManager;
4850
import com.cloud.utils.component.ComponentContext;
4951
import com.cloud.utils.concurrency.NamedThreadFactory;
5052
import com.cloud.utils.exception.CloudRuntimeException;
53+
import com.cloud.vm.SecondaryStorageVmVO;
54+
import com.cloud.vm.dao.SecondaryStorageVmDao;
5155

5256
public class RemoteHostEndPoint implements EndPoint {
5357
private static final Logger s_logger = Logger.getLogger(RemoteHostEndPoint.class);
@@ -60,21 +64,23 @@ public class RemoteHostEndPoint implements EndPoint {
6064
protected HypervisorGuruManager _hvGuruMgr;
6165
@Inject
6266
protected SecondaryStorageVmDao vmDao;
67+
@Inject
68+
protected HostDao _hostDao;
6369
private ScheduledExecutorService executor;
6470

6571
public RemoteHostEndPoint() {
6672
executor = Executors.newScheduledThreadPool(10, new NamedThreadFactory("RemoteHostEndPoint"));
6773
}
6874

6975
private void configure(Host host) {
70-
this.hostId = host.getId();
71-
this.hostAddress = host.getPrivateIpAddress();
72-
this.publicAddress = host.getPublicIpAddress();
76+
hostId = host.getId();
77+
hostAddress = host.getPrivateIpAddress();
78+
publicAddress = host.getPublicIpAddress();
7379
if (Host.Type.SecondaryStorageVM == host.getType()) {
7480
String vmName = host.getName();
7581
SecondaryStorageVmVO ssvm = vmDao.findByInstanceName(vmName);
7682
if (ssvm != null) {
77-
this.publicAddress = ssvm.getPublicIpAddress();
83+
publicAddress = ssvm.getPublicIpAddress();
7884
}
7985
}
8086
}
@@ -87,24 +93,36 @@ public static RemoteHostEndPoint getHypervisorHostEndPoint(Host host) {
8793

8894
@Override
8995
public String getHostAddr() {
90-
return this.hostAddress;
96+
return hostAddress;
9197
}
9298

9399
@Override
94100
public String getPublicAddr() {
95-
return this.publicAddress;
101+
return publicAddress;
96102
}
97103

98104
@Override
99105
public long getId() {
100-
return this.hostId;
106+
return hostId;
107+
}
108+
109+
// used when HypervisorGuruManager choose a different host to send command
110+
private void setId(long id) {
111+
HostVO host = _hostDao.findById(hostId);
112+
if (host != null) {
113+
configure(host);
114+
}
101115
}
102116

103117
@Override
104118
public Answer sendMessage(Command cmd) {
105119
String errMsg = null;
106120
try {
107121
long newHostId = _hvGuruMgr.getGuruProcessedCommandTargetHost(hostId, cmd);
122+
if (newHostId != hostId) {
123+
// update endpoint with new host if changed
124+
setId(newHostId);
125+
}
108126
return agentMgr.send(newHostId, cmd);
109127
} catch (AgentUnavailableException e) {
110128
errMsg = e.toString();
@@ -126,7 +144,7 @@ public CmdRunner(AsyncCompletionCallback<Answer> callback) {
126144

127145
@Override
128146
public boolean processAnswers(long agentId, long seq, Answer[] answers) {
129-
this.answer = answers[0];
147+
answer = answers[0];
130148
executor.schedule(this, 10, TimeUnit.SECONDS);
131149
return true;
132150
}
@@ -182,7 +200,11 @@ protected void runInContext() {
182200
@Override
183201
public void sendMessageAsync(Command cmd, AsyncCompletionCallback<Answer> callback) {
184202
try {
185-
long newHostId = _hvGuruMgr.getGuruProcessedCommandTargetHost(this.hostId, cmd);
203+
long newHostId = _hvGuruMgr.getGuruProcessedCommandTargetHost(hostId, cmd);
204+
if (newHostId != hostId) {
205+
// update endpoint with new host if changed
206+
setId(newHostId);
207+
}
186208
if (s_logger.isDebugEnabled()) {
187209
s_logger.debug("Sending command " + cmd.toString() + " to host: " + newHostId);
188210
}

0 commit comments

Comments
 (0)