Skip to content

Commit fe4f53b

Browse files
committed
Fix SecStorageSetupCommand for Nfs image store.
1 parent 14b5f0d commit fe4f53b

9 files changed

Lines changed: 102 additions & 44 deletions

File tree

‎api/src/com/cloud/agent/api/SecStorageSetupCommand.java‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
package com.cloud.agent.api;
1818

1919
import com.cloud.agent.api.LogLevel.Log4jLevel;
20+
import com.cloud.agent.api.to.DataStoreTO;
2021

2122
public class SecStorageSetupCommand extends Command {
23+
private DataStoreTO store;
2224
private String secUrl;
2325
private Certificates certs;
2426

@@ -57,10 +59,11 @@ public SecStorageSetupCommand() {
5759
super();
5860
}
5961

60-
public SecStorageSetupCommand(String secUrl, Certificates certs) {
62+
public SecStorageSetupCommand(DataStoreTO store, String secUrl, Certificates certs) {
6163
super();
6264
this.secUrl = secUrl;
6365
this.certs = certs;
66+
this.store = store;
6467
}
6568

6669
@Override
@@ -80,4 +83,14 @@ public void setSecUrl(String secUrl) {
8083
this.secUrl = secUrl;
8184

8285
}
86+
87+
public DataStoreTO getDataStore() {
88+
return store;
89+
}
90+
91+
public void setDataStore(DataStoreTO store) {
92+
this.store = store;
93+
}
94+
95+
8396
}

‎core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java‎

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -968,29 +968,36 @@ private Answer execute(SecStorageSetupCommand cmd) {
968968
if (!_inSystemVM){
969969
return new Answer(cmd, true, null);
970970
}
971-
String secUrl = cmd.getSecUrl();
972-
try {
973-
URI uri = new URI(secUrl);
974-
String nfsHost = uri.getHost();
971+
DataStoreTO dStore = cmd.getDataStore();
972+
if (dStore instanceof NfsTO ){
973+
String secUrl = cmd.getSecUrl();
974+
try {
975+
URI uri = new URI(secUrl);
976+
String nfsHost = uri.getHost();
975977

976-
InetAddress nfsHostAddr = InetAddress.getByName(nfsHost);
977-
String nfsHostIp = nfsHostAddr.getHostAddress();
978+
InetAddress nfsHostAddr = InetAddress.getByName(nfsHost);
979+
String nfsHostIp = nfsHostAddr.getHostAddress();
978980

979-
addRouteToInternalIpOrCidr(_storageGateway, _storageIp, _storageNetmask, nfsHostIp);
980-
String nfsPath = nfsHostIp + ":" + uri.getPath();
981-
String dir = UUID.nameUUIDFromBytes(nfsPath.getBytes()).toString();
982-
String root = _parent + "/" + dir;
983-
mount(root, nfsPath);
981+
addRouteToInternalIpOrCidr(_storageGateway, _storageIp, _storageNetmask, nfsHostIp);
982+
String nfsPath = nfsHostIp + ":" + uri.getPath();
983+
String dir = UUID.nameUUIDFromBytes(nfsPath.getBytes()).toString();
984+
String root = _parent + "/" + dir;
985+
mount(root, nfsPath);
984986

985-
configCerts(cmd.getCerts());
987+
configCerts(cmd.getCerts());
986988

987-
nfsIps.add(nfsHostIp);
988-
return new SecStorageSetupAnswer(dir);
989-
} catch (Exception e) {
990-
String msg = "GetRootDir for " + secUrl + " failed due to " + e.toString();
991-
s_logger.error(msg);
992-
return new Answer(cmd, false, msg);
989+
nfsIps.add(nfsHostIp);
990+
return new SecStorageSetupAnswer(dir);
991+
} catch (Exception e) {
992+
String msg = "GetRootDir for " + secUrl + " failed due to " + e.toString();
993+
s_logger.error(msg);
994+
return new Answer(cmd, false, msg);
993995

996+
}
997+
}
998+
else{
999+
// TODO: what do we need to setup for S3/Swift, maybe need to mount to some cache storage
1000+
return new Answer(cmd, true, null);
9941001
}
9951002
}
9961003

‎engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreVO.java‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,16 @@ public class ImageStoreVO implements ImageStore {
7171

7272
@Column(name=GenericDao.REMOVED_COLUMN)
7373
private Date removed;
74-
74+
7575
@Column(name = "role")
7676
@Enumerated(value = EnumType.STRING)
7777
private DataStoreRole role;
7878

79+
@Column(name="parent")
80+
private String parent;
81+
82+
83+
7984
public DataStoreRole getRole() {
8085
return role;
8186
}
@@ -160,6 +165,14 @@ public void setRemoved(Date removed) {
160165
this.removed = removed;
161166
}
162167

168+
public String getParent() {
169+
return parent;
170+
}
171+
172+
public void setParent(String parent) {
173+
this.parent = parent;
174+
}
175+
163176

164177

165178
}

‎engine/storage/image/src/org/apache/cloudstack/storage/image/store/ImageStoreImpl.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,8 @@ public DataStoreTO getTO() {
178178
return getDriver().getStoreTO(this);
179179
}
180180

181+
public ImageStoreVO getImageStoreVO(){
182+
return this.imageDataStoreVO;
183+
}
181184

182185
}

‎server/src/com/cloud/storage/download/DownloadMonitorImpl.java‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult;
3131
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
3232
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
33+
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
34+
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
3335
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
3436
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
3537
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
@@ -126,6 +128,8 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor
126128
@Inject
127129
SecondaryStorageVmDao _secStorageVmDao;
128130
@Inject
131+
ImageStoreDao _imageStoreDao;
132+
@Inject
129133
VolumeDao _volumeDao;
130134
@Inject
131135
VolumeHostDao _volumeHostDao;
@@ -344,9 +348,9 @@ private String generateCopyUrl(DataStore sourceServer, TemplateDataStoreVO srcTm
344348
s_logger.warn("A running secondary storage vm has a null public ip?");
345349
return null;
346350
}
347-
//TODO: how to handle parent field from hostVO in image_store? and how we can populate that column?
348-
// return generateCopyUrl(ssVm.getPublicIpAddress(), sourceServer.getParent(), srcTmpltStore.getInstallPath());
349-
return generateCopyUrl(ssVm.getPublicIpAddress(), null, srcTmpltStore.getInstallPath());
351+
// get parent path of nfs secondary storage
352+
ImageStoreVO svo = this._imageStoreDao.findById(sourceServer.getId());
353+
return generateCopyUrl(ssVm.getPublicIpAddress(), svo.getParent(), srcTmpltStore.getInstallPath());
350354
}
351355

352356
VMTemplateVO tmplt = _templateDao.findById(srcTmpltStore.getTemplateId());

‎server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java‎

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@
3030
import javax.naming.ConfigurationException;
3131

3232
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
33+
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
3334
import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
35+
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
36+
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
37+
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
3438
import org.apache.log4j.Logger;
3539
import org.springframework.context.annotation.Primary;
3640
import org.springframework.stereotype.Component;
@@ -240,6 +244,10 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
240244

241245
@Inject
242246
KeystoreManager _keystoreMgr;
247+
@Inject
248+
DataStoreManager _dataStoreMgr;
249+
@Inject
250+
ImageStoreDao _imageStoreDao;
243251
private long _capacityScanInterval = DEFAULT_CAPACITY_SCAN_INTERVAL;
244252
private int _secStorageVmMtuSize;
245253

@@ -300,33 +308,39 @@ public boolean generateSetupCommand(Long ssHostId) {
300308
return false;
301309
}
302310

303-
List<HostVO> ssHosts = _ssvmMgr.listSecondaryStorageHostsInOneZone(zoneId);
304-
for( HostVO ssHost : ssHosts ) {
305-
String secUrl = ssHost.getStorageUrl();
311+
List<DataStore> ssStores = this._dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId));
312+
for( DataStore ssStore : ssStores ) {
313+
String secUrl = ssStore.getUri();
306314
SecStorageSetupCommand setupCmd = null;
307315
if (!_useSSlCopy) {
308-
setupCmd = new SecStorageSetupCommand(secUrl, null);
316+
setupCmd = new SecStorageSetupCommand(ssStore.getTO(), secUrl, null);
309317
} else {
310318
Certificates certs = _keystoreMgr.getCertificates(ConsoleProxyManager.CERTIFICATE_NAME);
311-
setupCmd = new SecStorageSetupCommand(secUrl, certs);
319+
setupCmd = new SecStorageSetupCommand(ssStore.getTO(), secUrl, certs);
312320
}
313321

314322
Answer answer = _agentMgr.easySend(ssHostId, setupCmd);
315323
if (answer != null && answer.getResult()) {
316324
SecStorageSetupAnswer an = (SecStorageSetupAnswer) answer;
317-
ssHost.setParent(an.get_dir());
318-
_hostDao.update(ssHost.getId(), ssHost);
325+
if (an.get_dir() != null){
326+
// update the parent path in image_store table for this image store
327+
ImageStoreVO svo = this._imageStoreDao.findById(ssStore.getId());
328+
svo.setParent(an.get_dir());
329+
_imageStoreDao.update(ssStore.getId(), svo);
330+
}
319331
if (s_logger.isDebugEnabled()) {
320-
s_logger.debug("Successfully programmed secondary storage " + ssHost.getName() + " in secondary storage VM " + secStorageVm.getInstanceName());
332+
s_logger.debug("Successfully programmed secondary storage " + ssStore.getName() + " in secondary storage VM " + secStorageVm.getInstanceName());
321333
}
322334
} else {
323335
if (s_logger.isDebugEnabled()) {
324-
s_logger.debug("Successfully programmed secondary storage " + ssHost.getName() + " in secondary storage VM " + secStorageVm.getInstanceName());
336+
s_logger.debug("Successfully programmed secondary storage " + ssStore.getName() + " in secondary storage VM " + secStorageVm.getInstanceName());
325337
}
326338
return false;
327339
}
328340
}
329-
} else if( cssHost.getType() == Host.Type.SecondaryStorage ) {
341+
}
342+
/* After removing SecondaryStorage entries from host table, control should never come here!!
343+
else if( cssHost.getType() == Host.Type.SecondaryStorage ) {
330344
List<SecondaryStorageVmVO> alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, zoneId, State.Running);
331345
String secUrl = cssHost.getStorageUrl();
332346
SecStorageSetupCommand setupCmd = new SecStorageSetupCommand(secUrl, null);
@@ -345,6 +359,7 @@ public boolean generateSetupCommand(Long ssHostId) {
345359
}
346360
}
347361
}
362+
*/
348363
return true;
349364
}
350365

‎server/src/com/cloud/template/TemplateManagerImpl.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
252252
@Inject
253253
SnapshotDataFactory snapshotFactory;
254254
@Inject
255-
TemplateService imageSvr;
255+
TemplateService tmpltSvr;
256256
@Inject
257257
DataStoreManager dataStoreMgr;
258258
@Inject
@@ -1768,11 +1768,11 @@ public VirtualMachineTemplate createPrivateTemplate(CreateTemplateCmd command)
17681768
AsyncCallFuture<CommandResult> future = null;
17691769
if (snapshotId != null) {
17701770
SnapshotInfo snapInfo = this.snapshotFactory.getSnapshot(snapshotId);
1771-
future = this.imageSvr.createTemplateFromSnapshotAsync(snapInfo, tmplInfo, store.get(0));
1771+
future = this.tmpltSvr.createTemplateFromSnapshotAsync(snapInfo, tmplInfo, store.get(0));
17721772
} else if (volumeId != null) {
17731773
volume = _volumeDao.findById(volumeId);
17741774
VolumeInfo volInfo = this.volFactory.getVolume(volumeId);
1775-
future = this.imageSvr.createTemplateFromVolumeAsync(volInfo, tmplInfo, store.get(0));
1775+
future = this.tmpltSvr.createTemplateFromVolumeAsync(volInfo, tmplInfo, store.get(0));
17761776
} else {
17771777
throw new CloudRuntimeException(
17781778
"Creating private Template need to specify snapshotId or volumeId");

‎server/src/com/cloud/upgrade/dao/Upgrade410to420.java‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ public void performDataMigration(Connection conn) {
6666
updateCluster_details(conn);
6767
updatePrimaryStore(conn);
6868
}
69-
69+
7070
private void updateSystemVmTemplates(Connection conn) {
71+
/* TODO: where should be system vm templates located?
7172
PreparedStatement sql = null;
7273
try {
7374
sql = conn.prepareStatement("update vm_template set image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'");
@@ -82,8 +83,9 @@ private void updateSystemVmTemplates(Connection conn) {
8283
}
8384
}
8485
}
86+
*/
8587
}
86-
88+
8789
private void updatePrimaryStore(Connection conn) {
8890
PreparedStatement sql = null;
8991
PreparedStatement sql2 = null;
@@ -92,7 +94,7 @@ private void updatePrimaryStore(Connection conn) {
9294
sql.setString(1, "ancient primary data store provider");
9395
sql.setString(2, "HOST");
9496
sql.executeUpdate();
95-
97+
9698
sql2 = conn.prepareStatement("update storage_pool set storage_provider_name = ? , scope = ? where pool_type != 'Filesystem' and pool_type != 'LVM'");
9799
sql2.setString(1, "ancient primary data store provider");
98100
sql2.setString(2, "CLUSTER");
@@ -106,7 +108,7 @@ private void updatePrimaryStore(Connection conn) {
106108
} catch (SQLException e) {
107109
}
108110
}
109-
111+
110112
if (sql2 != null) {
111113
try {
112114
sql2.close();
@@ -234,7 +236,7 @@ private void upgradeVmwareLabels(Connection conn) {
234236
}
235237
}
236238
}
237-
239+
238240
private void createPlaceHolderNics(Connection conn) {
239241
PreparedStatement pstmt = null;
240242
ResultSet rs = null;
@@ -255,7 +257,7 @@ private void createPlaceHolderNics(Connection conn) {
255257
pstmt.setLong(4, networkId);
256258
pstmt.executeUpdate();
257259
s_logger.debug("Created placeholder nic for the ipAddress " + ip);
258-
260+
259261
}
260262
} catch (SQLException e) {
261263
throw new CloudRuntimeException("Unable to create placeholder nics", e);
@@ -271,8 +273,8 @@ private void createPlaceHolderNics(Connection conn) {
271273
}
272274
}
273275
}
274-
275-
276+
277+
276278
private void updateRemoteAccessVpn(Connection conn) {
277279
PreparedStatement pstmt = null;
278280
ResultSet rs = null;

‎setup/db/db/schema-410to420.sql‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ CREATE TABLE `cloud`.`image_store` (
7777
`data_center_id` bigint unsigned COMMENT 'datacenter id of data store',
7878
`scope` varchar(255) COMMENT 'scope of data store',
7979
`uuid` varchar(255) COMMENT 'uuid of data store',
80+
`parent` varchar(255) COMMENT 'parent path for the storage server',
8081
`created` datetime COMMENT 'date the image store first signed on',
8182
`removed` datetime COMMENT 'date removed if not null',
8283
PRIMARY KEY(`id`)

0 commit comments

Comments
 (0)