Fix SecStorageSetupCommand for Nfs image store.

This commit is contained in:
Min Chen 2013-04-17 17:16:01 -07:00
parent 14b5f0da19
commit fe4f53bfcd
9 changed files with 102 additions and 44 deletions

View File

@ -17,8 +17,10 @@
package com.cloud.agent.api;
import com.cloud.agent.api.LogLevel.Log4jLevel;
import com.cloud.agent.api.to.DataStoreTO;
public class SecStorageSetupCommand extends Command {
private DataStoreTO store;
private String secUrl;
private Certificates certs;
@ -57,10 +59,11 @@ public class SecStorageSetupCommand extends Command {
super();
}
public SecStorageSetupCommand(String secUrl, Certificates certs) {
public SecStorageSetupCommand(DataStoreTO store, String secUrl, Certificates certs) {
super();
this.secUrl = secUrl;
this.certs = certs;
this.store = store;
}
@Override
@ -80,4 +83,14 @@ public class SecStorageSetupCommand extends Command {
this.secUrl = secUrl;
}
public DataStoreTO getDataStore() {
return store;
}
public void setDataStore(DataStoreTO store) {
this.store = store;
}
}

View File

@ -968,29 +968,36 @@ SecondaryStorageResource {
if (!_inSystemVM){
return new Answer(cmd, true, null);
}
String secUrl = cmd.getSecUrl();
try {
URI uri = new URI(secUrl);
String nfsHost = uri.getHost();
DataStoreTO dStore = cmd.getDataStore();
if (dStore instanceof NfsTO ){
String secUrl = cmd.getSecUrl();
try {
URI uri = new URI(secUrl);
String nfsHost = uri.getHost();
InetAddress nfsHostAddr = InetAddress.getByName(nfsHost);
String nfsHostIp = nfsHostAddr.getHostAddress();
InetAddress nfsHostAddr = InetAddress.getByName(nfsHost);
String nfsHostIp = nfsHostAddr.getHostAddress();
addRouteToInternalIpOrCidr(_storageGateway, _storageIp, _storageNetmask, nfsHostIp);
String nfsPath = nfsHostIp + ":" + uri.getPath();
String dir = UUID.nameUUIDFromBytes(nfsPath.getBytes()).toString();
String root = _parent + "/" + dir;
mount(root, nfsPath);
addRouteToInternalIpOrCidr(_storageGateway, _storageIp, _storageNetmask, nfsHostIp);
String nfsPath = nfsHostIp + ":" + uri.getPath();
String dir = UUID.nameUUIDFromBytes(nfsPath.getBytes()).toString();
String root = _parent + "/" + dir;
mount(root, nfsPath);
configCerts(cmd.getCerts());
configCerts(cmd.getCerts());
nfsIps.add(nfsHostIp);
return new SecStorageSetupAnswer(dir);
} catch (Exception e) {
String msg = "GetRootDir for " + secUrl + " failed due to " + e.toString();
s_logger.error(msg);
return new Answer(cmd, false, msg);
nfsIps.add(nfsHostIp);
return new SecStorageSetupAnswer(dir);
} catch (Exception e) {
String msg = "GetRootDir for " + secUrl + " failed due to " + e.toString();
s_logger.error(msg);
return new Answer(cmd, false, msg);
}
}
else{
// TODO: what do we need to setup for S3/Swift, maybe need to mount to some cache storage
return new Answer(cmd, true, null);
}
}

View File

@ -71,11 +71,16 @@ public class ImageStoreVO implements ImageStore {
@Column(name=GenericDao.REMOVED_COLUMN)
private Date removed;
@Column(name = "role")
@Enumerated(value = EnumType.STRING)
private DataStoreRole role;
@Column(name="parent")
private String parent;
public DataStoreRole getRole() {
return role;
}
@ -160,6 +165,14 @@ public class ImageStoreVO implements ImageStore {
this.removed = removed;
}
public String getParent() {
return parent;
}
public void setParent(String parent) {
this.parent = parent;
}
}

View File

@ -178,5 +178,8 @@ public class ImageStoreImpl implements ImageStoreEntity {
return getDriver().getStoreTO(this);
}
public ImageStoreVO getImageStoreVO(){
return this.imageDataStoreVO;
}
}

View File

@ -30,6 +30,8 @@ import javax.inject.Inject;
import org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
@ -126,6 +128,8 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor
@Inject
SecondaryStorageVmDao _secStorageVmDao;
@Inject
ImageStoreDao _imageStoreDao;
@Inject
VolumeDao _volumeDao;
@Inject
VolumeHostDao _volumeHostDao;
@ -344,9 +348,9 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor
s_logger.warn("A running secondary storage vm has a null public ip?");
return null;
}
//TODO: how to handle parent field from hostVO in image_store? and how we can populate that column?
// return generateCopyUrl(ssVm.getPublicIpAddress(), sourceServer.getParent(), srcTmpltStore.getInstallPath());
return generateCopyUrl(ssVm.getPublicIpAddress(), null, srcTmpltStore.getInstallPath());
// get parent path of nfs secondary storage
ImageStoreVO svo = this._imageStoreDao.findById(sourceServer.getId());
return generateCopyUrl(ssVm.getPublicIpAddress(), svo.getParent(), srcTmpltStore.getInstallPath());
}
VMTemplateVO tmplt = _templateDao.findById(srcTmpltStore.getTemplateId());

View File

@ -30,7 +30,11 @@ import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
import org.apache.log4j.Logger;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
@ -240,6 +244,10 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
@Inject
KeystoreManager _keystoreMgr;
@Inject
DataStoreManager _dataStoreMgr;
@Inject
ImageStoreDao _imageStoreDao;
private long _capacityScanInterval = DEFAULT_CAPACITY_SCAN_INTERVAL;
private int _secStorageVmMtuSize;
@ -300,33 +308,39 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
return false;
}
List<HostVO> ssHosts = _ssvmMgr.listSecondaryStorageHostsInOneZone(zoneId);
for( HostVO ssHost : ssHosts ) {
String secUrl = ssHost.getStorageUrl();
List<DataStore> ssStores = this._dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId));
for( DataStore ssStore : ssStores ) {
String secUrl = ssStore.getUri();
SecStorageSetupCommand setupCmd = null;
if (!_useSSlCopy) {
setupCmd = new SecStorageSetupCommand(secUrl, null);
setupCmd = new SecStorageSetupCommand(ssStore.getTO(), secUrl, null);
} else {
Certificates certs = _keystoreMgr.getCertificates(ConsoleProxyManager.CERTIFICATE_NAME);
setupCmd = new SecStorageSetupCommand(secUrl, certs);
setupCmd = new SecStorageSetupCommand(ssStore.getTO(), secUrl, certs);
}
Answer answer = _agentMgr.easySend(ssHostId, setupCmd);
if (answer != null && answer.getResult()) {
SecStorageSetupAnswer an = (SecStorageSetupAnswer) answer;
ssHost.setParent(an.get_dir());
_hostDao.update(ssHost.getId(), ssHost);
if (an.get_dir() != null){
// update the parent path in image_store table for this image store
ImageStoreVO svo = this._imageStoreDao.findById(ssStore.getId());
svo.setParent(an.get_dir());
_imageStoreDao.update(ssStore.getId(), svo);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Successfully programmed secondary storage " + ssHost.getName() + " in secondary storage VM " + secStorageVm.getInstanceName());
s_logger.debug("Successfully programmed secondary storage " + ssStore.getName() + " in secondary storage VM " + secStorageVm.getInstanceName());
}
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Successfully programmed secondary storage " + ssHost.getName() + " in secondary storage VM " + secStorageVm.getInstanceName());
s_logger.debug("Successfully programmed secondary storage " + ssStore.getName() + " in secondary storage VM " + secStorageVm.getInstanceName());
}
return false;
}
}
} else if( cssHost.getType() == Host.Type.SecondaryStorage ) {
}
/* After removing SecondaryStorage entries from host table, control should never come here!!
else if( cssHost.getType() == Host.Type.SecondaryStorage ) {
List<SecondaryStorageVmVO> alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, zoneId, State.Running);
String secUrl = cssHost.getStorageUrl();
SecStorageSetupCommand setupCmd = new SecStorageSetupCommand(secUrl, null);
@ -345,6 +359,7 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
}
}
}
*/
return true;
}

View File

@ -252,7 +252,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
@Inject
SnapshotDataFactory snapshotFactory;
@Inject
TemplateService imageSvr;
TemplateService tmpltSvr;
@Inject
DataStoreManager dataStoreMgr;
@Inject
@ -1768,11 +1768,11 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
AsyncCallFuture<CommandResult> future = null;
if (snapshotId != null) {
SnapshotInfo snapInfo = this.snapshotFactory.getSnapshot(snapshotId);
future = this.imageSvr.createTemplateFromSnapshotAsync(snapInfo, tmplInfo, store.get(0));
future = this.tmpltSvr.createTemplateFromSnapshotAsync(snapInfo, tmplInfo, store.get(0));
} else if (volumeId != null) {
volume = _volumeDao.findById(volumeId);
VolumeInfo volInfo = this.volFactory.getVolume(volumeId);
future = this.imageSvr.createTemplateFromVolumeAsync(volInfo, tmplInfo, store.get(0));
future = this.tmpltSvr.createTemplateFromVolumeAsync(volInfo, tmplInfo, store.get(0));
} else {
throw new CloudRuntimeException(
"Creating private Template need to specify snapshotId or volumeId");

View File

@ -66,8 +66,9 @@ public class Upgrade410to420 implements DbUpgrade {
updateCluster_details(conn);
updatePrimaryStore(conn);
}
private void updateSystemVmTemplates(Connection conn) {
/* TODO: where should be system vm templates located?
PreparedStatement sql = null;
try {
sql = conn.prepareStatement("update vm_template set image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'");
@ -82,8 +83,9 @@ public class Upgrade410to420 implements DbUpgrade {
}
}
}
*/
}
private void updatePrimaryStore(Connection conn) {
PreparedStatement sql = null;
PreparedStatement sql2 = null;
@ -92,7 +94,7 @@ public class Upgrade410to420 implements DbUpgrade {
sql.setString(1, "ancient primary data store provider");
sql.setString(2, "HOST");
sql.executeUpdate();
sql2 = conn.prepareStatement("update storage_pool set storage_provider_name = ? , scope = ? where pool_type != 'Filesystem' and pool_type != 'LVM'");
sql2.setString(1, "ancient primary data store provider");
sql2.setString(2, "CLUSTER");
@ -106,7 +108,7 @@ public class Upgrade410to420 implements DbUpgrade {
} catch (SQLException e) {
}
}
if (sql2 != null) {
try {
sql2.close();
@ -234,7 +236,7 @@ public class Upgrade410to420 implements DbUpgrade {
}
}
}
private void createPlaceHolderNics(Connection conn) {
PreparedStatement pstmt = null;
ResultSet rs = null;
@ -255,7 +257,7 @@ public class Upgrade410to420 implements DbUpgrade {
pstmt.setLong(4, networkId);
pstmt.executeUpdate();
s_logger.debug("Created placeholder nic for the ipAddress " + ip);
}
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to create placeholder nics", e);
@ -271,8 +273,8 @@ public class Upgrade410to420 implements DbUpgrade {
}
}
}
private void updateRemoteAccessVpn(Connection conn) {
PreparedStatement pstmt = null;
ResultSet rs = null;

View File

@ -77,6 +77,7 @@ CREATE TABLE `cloud`.`image_store` (
`data_center_id` bigint unsigned COMMENT 'datacenter id of data store',
`scope` varchar(255) COMMENT 'scope of data store',
`uuid` varchar(255) COMMENT 'uuid of data store',
`parent` varchar(255) COMMENT 'parent path for the storage server',
`created` datetime COMMENT 'date the image store first signed on',
`removed` datetime COMMENT 'date removed if not null',
PRIMARY KEY(`id`)