Skip to content

Commit c40d03b

Browse files
committed
CS-18582: if EIP is used, extract volume and template returns wrong public ip address. If remote agent is ssvm agent, then looking up public ip address from ssvm table
Conflicts: engine/storage/integration-test/test/org/apache/cloudstack/storage/test/SnapshotTest.java engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeServiceTest.java engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeTest.java engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeTestVmware.java engine/storage/src/org/apache/cloudstack/storage/RemoteHostEndPoint.java engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
1 parent 9c77f68 commit c40d03b

6 files changed

Lines changed: 26 additions & 16 deletions

File tree

‎engine/storage/integration-test/test/org/apache/cloudstack/storage/test/SnapshotTest.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,7 @@ protected void injectMockito() {
277277
List<HostVO> hosts = new ArrayList<HostVO>();
278278
hosts.add(this.host);
279279
Mockito.when(resourceMgr.listAllUpAndEnabledHosts((Type)Matchers.any(), Matchers.anyLong(), Matchers.anyLong(), Matchers.anyLong())).thenReturn(hosts);
280-
281-
remoteEp = RemoteHostEndPoint.getHypervisorHostEndPoint(this.host.getId(), this.host.getPrivateIpAddress(), this.host.getPublicIpAddress());
280+
remoteEp = RemoteHostEndPoint.getHypervisorHostEndPoint(this.host);
282281
Mockito.when(epSelector.select(Matchers.any(DataObject.class), Matchers.any(DataObject.class))).thenReturn(remoteEp);
283282
Mockito.when(epSelector.select(Matchers.any(DataObject.class))).thenReturn(remoteEp);
284283
Mockito.when(epSelector.select(Matchers.any(DataStore.class))).thenReturn(remoteEp);

‎engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeServiceTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ protected void injectMockito() {
195195
Mockito.when(hostDao.findById(Matchers.anyLong())).thenReturn(host);
196196
Mockito.when(hostDao.findHypervisorHostInCluster(Matchers.anyLong())).thenReturn(results);
197197
List<EndPoint> eps = new ArrayList<EndPoint>();
198-
eps.add(RemoteHostEndPoint.getHypervisorHostEndPoint(host.getId(), host.getPrivateIpAddress(), host.getPublicIpAddress()));
198+
eps.add(RemoteHostEndPoint.getHypervisorHostEndPoint(host));
199199
Mockito.when(selector.selectAll(Matchers.any(DataStore.class))).thenReturn(eps);
200200
Mockito.when(selector.select(Matchers.any(DataObject.class))).thenReturn(eps.get(0));
201201
Mockito.when(selector.select(Matchers.any(DataObject.class), Matchers.any(DataObject.class))).thenReturn(eps.get(0));

‎engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ protected void injectMockito() {
254254
hosts.add(this.host);
255255
Mockito.when(resourceMgr.listAllUpAndEnabledHosts((Type)Matchers.any(), Matchers.anyLong(), Matchers.anyLong(), Matchers.anyLong())).thenReturn(hosts);
256256

257-
RemoteHostEndPoint ep = RemoteHostEndPoint.getHypervisorHostEndPoint(this.host.getId(), this.host.getPrivateIpAddress(), this.host.getPublicIpAddress());
257+
RemoteHostEndPoint ep = RemoteHostEndPoint.getHypervisorHostEndPoint(this.host);
258258
Mockito.when(epSelector.select(Matchers.any(DataObject.class), Matchers.any(DataObject.class))).thenReturn(ep);
259259
Mockito.when(epSelector.select(Matchers.any(DataObject.class))).thenReturn(ep);
260260
Mockito.when(epSelector.select(Matchers.any(DataStore.class))).thenReturn(ep);

‎engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeTestVmware.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ protected void injectMockito() {
256256
hosts.add(this.host);
257257
Mockito.when(resourceMgr.listAllUpAndEnabledHosts((Type)Matchers.any(), Matchers.anyLong(), Matchers.anyLong(), Matchers.anyLong())).thenReturn(hosts);
258258

259-
RemoteHostEndPoint ep = RemoteHostEndPoint.getHypervisorHostEndPoint(this.host.getId(), this.host.getPrivateIpAddress(), this.host.getPublicIpAddress());
259+
RemoteHostEndPoint ep = RemoteHostEndPoint.getHypervisorHostEndPoint(this.host);
260260
Mockito.when(epSelector.select(Matchers.any(DataObject.class), Matchers.any(DataObject.class))).thenReturn(ep);
261261
Mockito.when(epSelector.select(Matchers.any(DataObject.class))).thenReturn(ep);
262262
Mockito.when(epSelector.select(Matchers.any(DataStore.class))).thenReturn(ep);

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
import javax.inject.Inject;
2626

2727
import org.apache.log4j.Logger;
28-
28+
import com.cloud.vm.SecondaryStorageVmVO;
29+
import com.cloud.vm.dao.SecondaryStorageVmDao;
2930
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
3031
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
3132
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
@@ -57,21 +58,30 @@ public class RemoteHostEndPoint implements EndPoint {
5758
AgentManager agentMgr;
5859
@Inject
5960
protected HypervisorGuruManager _hvGuruMgr;
61+
@Inject
62+
protected SecondaryStorageVmDao vmDao;
6063
private ScheduledExecutorService executor;
6164

6265
public RemoteHostEndPoint() {
6366
executor = Executors.newScheduledThreadPool(10, new NamedThreadFactory("RemoteHostEndPoint"));
6467
}
6568

66-
private void configure(long hostId, String hostAddress, String publicAddress) {
67-
this.hostId = hostId;
68-
this.hostAddress = hostAddress;
69-
this.publicAddress = publicAddress;
69+
private void configure(Host host) {
70+
this.hostId = host.getId();
71+
this.hostAddress = host.getPrivateIpAddress();
72+
this.publicAddress = host.getPublicIpAddress();
73+
if (Host.Type.SecondaryStorageVM == host.getType()) {
74+
String vmName = host.getName();
75+
SecondaryStorageVmVO ssvm = vmDao.findByInstanceName(vmName);
76+
if (ssvm != null) {
77+
this.publicAddress = ssvm.getPublicIpAddress();
78+
}
79+
}
7080
}
7181

72-
public static RemoteHostEndPoint getHypervisorHostEndPoint(long hostId, String hostAddress, String publicAddress) {
82+
public static RemoteHostEndPoint getHypervisorHostEndPoint(Host host) {
7383
RemoteHostEndPoint ep = ComponentContext.inject(RemoteHostEndPoint.class);
74-
ep.configure(hostId, hostAddress, publicAddress);
84+
ep.configure(host);
7585
return ep;
7686
}
7787

‎engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ protected EndPoint findEndPointInScope(Scope scope, String sqlBase, Long poolId)
140140
return null;
141141
}
142142

143-
return RemoteHostEndPoint.getHypervisorHostEndPoint(host.getId(), host.getPrivateIpAddress(), host.getPublicIpAddress());
143+
return RemoteHostEndPoint.getHypervisorHostEndPoint(host);
144144
}
145145

146146
protected EndPoint findEndPointForImageMove(DataStore srcStore, DataStore destStore) {
@@ -223,7 +223,7 @@ protected EndPoint findEndpointForImageStorage(DataStore store) {
223223
}
224224
Collections.shuffle(ssAHosts);
225225
HostVO host = ssAHosts.get(0);
226-
return RemoteHostEndPoint.getHypervisorHostEndPoint(host.getId(), host.getPrivateIpAddress(), host.getPublicIpAddress());
226+
return RemoteHostEndPoint.getHypervisorHostEndPoint(host);
227227
}
228228

229229
private List<HostVO> listUpAndConnectingSecondaryStorageVmHost(Long dcId) {
@@ -276,14 +276,15 @@ public List<EndPoint> selectAll(DataStore store) {
276276
List<EndPoint> endPoints = new ArrayList<EndPoint>();
277277
if (store.getScope().getScopeType() == ScopeType.HOST) {
278278
HostVO host = hostDao.findById(store.getScope().getScopeId());
279-
endPoints.add(RemoteHostEndPoint.getHypervisorHostEndPoint(host.getId(), host.getPrivateIpAddress(), host.getPublicIpAddress()));
279+
280+
endPoints.add(RemoteHostEndPoint.getHypervisorHostEndPoint(host));
280281
} else if (store.getScope().getScopeType() == ScopeType.CLUSTER) {
281282
QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
282283
sc.and(sc.entity().getClusterId(), Op.EQ, store.getScope().getScopeId());
283284
sc.and(sc.entity().getStatus(), Op.EQ, Status.Up);
284285
List<HostVO> hosts = sc.list();
285286
for (HostVO host : hosts) {
286-
endPoints.add(RemoteHostEndPoint.getHypervisorHostEndPoint(host.getId(), host.getPrivateIpAddress(), host.getPublicIpAddress()));
287+
endPoints.add(RemoteHostEndPoint.getHypervisorHostEndPoint(host));
287288
}
288289

289290
} else {

0 commit comments

Comments
 (0)