Skip to content

Commit 8d08f9b

Browse files
committed
CLOUDSTACK-2655: use ssvm public IP to construct extract url.
1 parent 4611b51 commit 8d08f9b

9 files changed

Lines changed: 43 additions & 28 deletions

File tree

engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/EndPoint.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
public interface EndPoint {
2525
public long getId();
2626
public String getHostAddr();
27+
public String getPublicAddr();
2728
public Answer sendMessage(Command cmd);
2829
public void sendMessageAsync(Command cmd, AsyncCompletionCallback<Answer> callback);
2930
}

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,12 @@ protected void injectMockito() {
266266
hosts.add(this.host);
267267
Mockito.when(resourceMgr.listAllUpAndEnabledHosts((Type) Mockito.any(), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyLong())).thenReturn(hosts);
268268

269-
remoteEp = RemoteHostEndPoint.getHypervisorHostEndPoint(this.host.getId(), this.host.getPrivateIpAddress());
269+
remoteEp = RemoteHostEndPoint.getHypervisorHostEndPoint(this.host.getId(), this.host.getPrivateIpAddress(), this.host.getPublicIpAddress());
270270
Mockito.when(epSelector.select(Mockito.any(DataObject.class), Mockito.any(DataObject.class))).thenReturn(remoteEp);
271271
Mockito.when(epSelector.select(Mockito.any(DataObject.class))).thenReturn(remoteEp);
272272
Mockito.when(epSelector.select(Mockito.any(DataStore.class))).thenReturn(remoteEp);
273273
Mockito.when(hyGuruMgr.getGuruProcessedCommandTargetHost(Mockito.anyLong(), Mockito.any(Command.class))).thenReturn(this.host.getId());
274-
274+
275275
}
276276

277277
public DataStore createPrimaryDataStore() {
@@ -333,7 +333,7 @@ private SnapshotVO createSnapshotInDb(VolumeInfo volume) {
333333
}
334334

335335
private VolumeVO createVolume(Long templateId, long dataStoreId) {
336-
336+
337337
VolumeVO volume = new VolumeVO(Volume.Type.DATADISK, UUID.randomUUID().toString(), this.dcId, 1L, 1L, 1L, 1000);
338338
volume.setDataCenterId(this.dcId);
339339
volume.setPoolId(dataStoreId);
@@ -376,18 +376,18 @@ public void createSnapshot() {
376376
}
377377
}
378378
AssertJUnit.assertNotNull(newSnapshot);
379-
379+
380380
LocalHostEndpoint ep = new MockLocalHostEndPoint();
381381
ep.setResource(new MockLocalNfsSecondaryStorageResource());
382382
Mockito.when(epSelector.select(Mockito.any(DataStore.class))).thenReturn(ep);
383-
383+
384384
//delete snapshot
385385
for (SnapshotStrategy strategy : this.snapshotStrategies) {
386386
if (strategy.canHandle(snapshot)) {
387387
strategy.deleteSnapshot(newSnapshot.getId());
388388
}
389389
}
390-
390+
391391
Mockito.when(epSelector.select(Mockito.any(DataStore.class))).thenReturn(remoteEp);
392392
}
393393

@@ -412,7 +412,7 @@ private VMTemplateVO createTemplateInDb() {
412412
image = imageDataDao.persist(image);
413413
return image;
414414
}
415-
415+
416416
@Test
417417
public void createVolumeFromSnapshot() {
418418
VolumeInfo vol = createCopyBaseImage();
@@ -432,7 +432,7 @@ public void createVolumeFromSnapshot() {
432432
VolumeInfo newVol = this.volFactory.getVolume(volVO.getId());
433433
this.volumeService.createVolumeFromSnapshot(newVol, newVol.getDataStore(), snapshot);
434434
}
435-
435+
436436
@Test
437437
public void deleteSnapshot() {
438438
VolumeInfo vol = createCopyBaseImage();
@@ -445,14 +445,14 @@ public void deleteSnapshot() {
445445
}
446446
}
447447
AssertJUnit.assertNotNull(newSnapshot);
448-
448+
449449
//create another snapshot
450450
for (SnapshotStrategy strategy : this.snapshotStrategies) {
451451
if (strategy.canHandle(snapshot)) {
452452
strategy.deleteSnapshot(newSnapshot.getId());
453453
}
454454
}
455-
455+
456456
}
457457

458458
@Test
@@ -477,6 +477,6 @@ public void createTemplateFromSnapshot() {
477477
DataStore imageStore = this.dataStoreMgr.getImageStore(this.dcId);
478478
this.imageService.createTemplateFromSnapshotAsync(snapshot, tmpl, imageStore);
479479
}
480-
481-
480+
481+
482482
}

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
@@ -247,7 +247,7 @@ protected void injectMockito() {
247247
hosts.add(this.host);
248248
Mockito.when(resourceMgr.listAllUpAndEnabledHosts((Type) Mockito.any(), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyLong())).thenReturn(hosts);
249249

250-
RemoteHostEndPoint ep = RemoteHostEndPoint.getHypervisorHostEndPoint(this.host.getId(), this.host.getPrivateIpAddress());
250+
RemoteHostEndPoint ep = RemoteHostEndPoint.getHypervisorHostEndPoint(this.host.getId(), this.host.getPrivateIpAddress(), this.host.getPublicIpAddress());
251251
Mockito.when(epSelector.select(Mockito.any(DataObject.class), Mockito.any(DataObject.class))).thenReturn(ep);
252252
Mockito.when(epSelector.select(Mockito.any(DataObject.class))).thenReturn(ep);
253253
Mockito.when(epSelector.select(Mockito.any(DataStore.class))).thenReturn(ep);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public void setUp() {
167167
cluster.setManagedState(ManagedState.Managed);
168168
cluster = clusterDao.persist(cluster);
169169
clusterId = cluster.getId();
170-
170+
171171
//setup vcenter
172172
ClusterDetailsVO clusterDetailVO = new ClusterDetailsVO(cluster.getId(), "url", null);
173173
this.clusterDetailsDao.persist(clusterDetailVO);
@@ -253,7 +253,7 @@ protected void injectMockito() {
253253
hosts.add(this.host);
254254
Mockito.when(resourceMgr.listAllUpAndEnabledHosts((Type) Mockito.any(), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyLong())).thenReturn(hosts);
255255

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

engine/storage/integration-test/test/org/apache/cloudstack/storage/test/volumeServiceTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public class volumeServiceTest extends CloudStackTestNGBase {
128128
@Test(priority = -1)
129129
public void setUp() {
130130
ComponentContext.initComponentsLifeCycle();
131-
131+
132132
host = hostDao.findByGuid(this.getHostGuid());
133133
if (host != null) {
134134
dcId = host.getDataCenterId();
@@ -170,7 +170,7 @@ public void setUp() {
170170
host.setClusterId(cluster.getId());
171171

172172
host = hostDao.persist(host);
173-
173+
174174
imageStore = new ImageStoreVO();
175175
imageStore.setName("test");
176176
imageStore.setDataCenterId(dcId);
@@ -194,7 +194,7 @@ protected void injectMockito() {
194194
Mockito.when(hostDao.findHypervisorHostInCluster(Mockito.anyLong())).thenReturn(results);
195195
List<EndPoint> eps = new ArrayList<EndPoint>();
196196
eps.add(RemoteHostEndPoint.getHypervisorHostEndPoint(host.getId(),
197-
host.getPrivateIpAddress()));
197+
host.getPrivateIpAddress(), host.getPublicIpAddress()));
198198
Mockito.when(selector.selectAll(Mockito.any(DataStore.class))).thenReturn(eps);
199199
Mockito.when(selector.select(Mockito.any(DataObject.class))).thenReturn(eps.get(0));
200200
Mockito.when(selector.select(Mockito.any(DataObject.class), Mockito.any(DataObject.class))).thenReturn(eps.get(0));
@@ -219,10 +219,10 @@ private VMTemplateVO createImageData() {
219219
image.setCrossZones(true);
220220
image.setExtractable(true);
221221

222-
222+
223223
//image.setImageDataStoreId(storeId);
224224
image = imageDataDao.persist(image);
225-
225+
226226

227227
return image;
228228
}

engine/storage/src/org/apache/cloudstack/storage/LocalHostEndpoint.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.cloud.resource.ServerResource;
3434
import com.cloud.storage.VMTemplateStorageResourceAssoc;
3535
import com.cloud.storage.download.DownloadListener;
36+
import com.cloud.utils.net.NetUtils;
3637

3738
public class LocalHostEndpoint implements EndPoint {
3839
private ScheduledExecutorService executor;
@@ -53,6 +54,12 @@ public String getHostAddr() {
5354
return "127.0.0.0";
5455
}
5556

57+
58+
@Override
59+
public String getPublicAddr() {
60+
return NetUtils.getDefaultHostIp();
61+
}
62+
5663
@Override
5764
public Answer sendMessage(Command cmd) {
5865
if ((cmd instanceof CopyCommand) || (cmd instanceof DownloadCommand)) {

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class RemoteHostEndPoint implements EndPoint {
4949
private static final Logger s_logger = Logger.getLogger(RemoteHostEndPoint.class);
5050
private long hostId;
5151
private String hostAddress;
52+
private String publicAddress;
5253
@Inject
5354
AgentManager agentMgr;
5455
@Inject
@@ -61,14 +62,15 @@ public RemoteHostEndPoint() {
6162
executor = Executors.newScheduledThreadPool(10);
6263
}
6364

64-
private void configure(long hostId, String hostAddress) {
65+
private void configure(long hostId, String hostAddress, String publicAddress) {
6566
this.hostId = hostId;
6667
this.hostAddress = hostAddress;
68+
this.publicAddress = publicAddress;
6769
}
6870

69-
public static RemoteHostEndPoint getHypervisorHostEndPoint(long hostId, String hostAddress) {
71+
public static RemoteHostEndPoint getHypervisorHostEndPoint(long hostId, String hostAddress, String publicAddress) {
7072
RemoteHostEndPoint ep = ComponentContext.inject(RemoteHostEndPoint.class);
71-
ep.configure(hostId, hostAddress);
73+
ep.configure(hostId, hostAddress, publicAddress);
7274
return ep;
7375
}
7476

@@ -77,6 +79,11 @@ public String getHostAddr() {
7779
return this.hostAddress;
7880
}
7981

82+
83+
public String getPublicAddr() {
84+
return this.publicAddress;
85+
}
86+
8087
@Override
8188
public long getId() {
8289
return this.hostId;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ protected EndPoint findEndPointInScope(Scope scope, String sqlBase) {
144144
}
145145

146146
return RemoteHostEndPoint.getHypervisorHostEndPoint(host.getId(),
147-
host.getPrivateIpAddress());
147+
host.getPrivateIpAddress(), host.getPublicIpAddress());
148148
}
149149

150150
protected EndPoint findEndPointForImageMove(DataStore srcStore,
@@ -204,7 +204,7 @@ protected EndPoint findEndpointForImageStorage(DataStore store) {
204204
}
205205
Collections.shuffle(ssAHosts);
206206
HostVO host = ssAHosts.get(0);
207-
return RemoteHostEndPoint.getHypervisorHostEndPoint(host.getId(), host.getPrivateIpAddress());
207+
return RemoteHostEndPoint.getHypervisorHostEndPoint(host.getId(), host.getPrivateIpAddress(), host.getPublicIpAddress());
208208
}
209209

210210
private List<HostVO> listUpAndConnectingSecondaryStorageVmHost(Long dcId) {
@@ -243,15 +243,15 @@ public List<EndPoint> selectAll(DataStore store) {
243243
if (store.getScope().getScopeType() == ScopeType.HOST) {
244244
HostVO host = hostDao.findById(store.getScope().getScopeId());
245245
endPoints.add(RemoteHostEndPoint.getHypervisorHostEndPoint(host.getId(),
246-
host.getPrivateIpAddress()));
246+
host.getPrivateIpAddress(), host.getPublicIpAddress()));
247247
} else if (store.getScope().getScopeType() == ScopeType.CLUSTER) {
248248
SearchCriteriaService<HostVO, HostVO> sc = SearchCriteria2.create(HostVO.class);
249249
sc.addAnd(sc.getEntity().getClusterId(), Op.EQ, store.getScope().getScopeId());
250250
sc.addAnd(sc.getEntity().getStatus(), Op.EQ, Status.Up);
251251
List<HostVO> hosts = sc.find();
252252
for (HostVO host : hosts) {
253253
endPoints.add(RemoteHostEndPoint.getHypervisorHostEndPoint(host.getId(),
254-
host.getPrivateIpAddress()));
254+
host.getPrivateIpAddress(), host.getPublicIpAddress()));
255255
}
256256

257257
} else {

server/src/com/cloud/storage/upload/UploadMonitorImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public UploadVO createEntityDownloadURL(VMTemplateVO template, TemplateDataStore
239239
}
240240

241241
//Construct actual URL locally now that the symlink exists at SSVM
242-
String extractURL = generateCopyUrl(ep.getHostAddr(), uuid);
242+
String extractURL = generateCopyUrl(ep.getPublicAddr(), uuid);
243243
UploadVO vo = _uploadDao.createForUpdate();
244244
vo.setLastUpdated(new Date());
245245
vo.setUploadUrl(extractURL);

0 commit comments

Comments
 (0)