mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Fix SecStorageSetupCommand for Nfs image store.
This commit is contained in:
parent
14b5f0da19
commit
fe4f53bfcd
@ -17,8 +17,10 @@
|
|||||||
package com.cloud.agent.api;
|
package com.cloud.agent.api;
|
||||||
|
|
||||||
import com.cloud.agent.api.LogLevel.Log4jLevel;
|
import com.cloud.agent.api.LogLevel.Log4jLevel;
|
||||||
|
import com.cloud.agent.api.to.DataStoreTO;
|
||||||
|
|
||||||
public class SecStorageSetupCommand extends Command {
|
public class SecStorageSetupCommand extends Command {
|
||||||
|
private DataStoreTO store;
|
||||||
private String secUrl;
|
private String secUrl;
|
||||||
private Certificates certs;
|
private Certificates certs;
|
||||||
|
|
||||||
@ -57,10 +59,11 @@ public class SecStorageSetupCommand extends Command {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SecStorageSetupCommand(String secUrl, Certificates certs) {
|
public SecStorageSetupCommand(DataStoreTO store, String secUrl, Certificates certs) {
|
||||||
super();
|
super();
|
||||||
this.secUrl = secUrl;
|
this.secUrl = secUrl;
|
||||||
this.certs = certs;
|
this.certs = certs;
|
||||||
|
this.store = store;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -80,4 +83,14 @@ public class SecStorageSetupCommand extends Command {
|
|||||||
this.secUrl = secUrl;
|
this.secUrl = secUrl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DataStoreTO getDataStore() {
|
||||||
|
return store;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDataStore(DataStoreTO store) {
|
||||||
|
this.store = store;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -968,6 +968,8 @@ SecondaryStorageResource {
|
|||||||
if (!_inSystemVM){
|
if (!_inSystemVM){
|
||||||
return new Answer(cmd, true, null);
|
return new Answer(cmd, true, null);
|
||||||
}
|
}
|
||||||
|
DataStoreTO dStore = cmd.getDataStore();
|
||||||
|
if (dStore instanceof NfsTO ){
|
||||||
String secUrl = cmd.getSecUrl();
|
String secUrl = cmd.getSecUrl();
|
||||||
try {
|
try {
|
||||||
URI uri = new URI(secUrl);
|
URI uri = new URI(secUrl);
|
||||||
@ -993,6 +995,11 @@ SecondaryStorageResource {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String deleteSnapshotBackupFromLocalFileSystem(
|
private String deleteSnapshotBackupFromLocalFileSystem(
|
||||||
final String secondaryStorageUrl, final Long accountId,
|
final String secondaryStorageUrl, final Long accountId,
|
||||||
|
|||||||
@ -76,6 +76,11 @@ public class ImageStoreVO implements ImageStore {
|
|||||||
@Enumerated(value = EnumType.STRING)
|
@Enumerated(value = EnumType.STRING)
|
||||||
private DataStoreRole role;
|
private DataStoreRole role;
|
||||||
|
|
||||||
|
@Column(name="parent")
|
||||||
|
private String parent;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public DataStoreRole getRole() {
|
public DataStoreRole getRole() {
|
||||||
return role;
|
return role;
|
||||||
}
|
}
|
||||||
@ -160,6 +165,14 @@ public class ImageStoreVO implements ImageStore {
|
|||||||
this.removed = removed;
|
this.removed = removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getParent() {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParent(String parent) {
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -178,5 +178,8 @@ public class ImageStoreImpl implements ImageStoreEntity {
|
|||||||
return getDriver().getStoreTO(this);
|
return getDriver().getStoreTO(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ImageStoreVO getImageStoreVO(){
|
||||||
|
return this.imageDataStoreVO;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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.CreateCmdResult;
|
||||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
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.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.TemplateDataStoreDao;
|
||||||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
|
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
|
||||||
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
|
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
|
||||||
@ -126,6 +128,8 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor
|
|||||||
@Inject
|
@Inject
|
||||||
SecondaryStorageVmDao _secStorageVmDao;
|
SecondaryStorageVmDao _secStorageVmDao;
|
||||||
@Inject
|
@Inject
|
||||||
|
ImageStoreDao _imageStoreDao;
|
||||||
|
@Inject
|
||||||
VolumeDao _volumeDao;
|
VolumeDao _volumeDao;
|
||||||
@Inject
|
@Inject
|
||||||
VolumeHostDao _volumeHostDao;
|
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?");
|
s_logger.warn("A running secondary storage vm has a null public ip?");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
//TODO: how to handle parent field from hostVO in image_store? and how we can populate that column?
|
// get parent path of nfs secondary storage
|
||||||
// return generateCopyUrl(ssVm.getPublicIpAddress(), sourceServer.getParent(), srcTmpltStore.getInstallPath());
|
ImageStoreVO svo = this._imageStoreDao.findById(sourceServer.getId());
|
||||||
return generateCopyUrl(ssVm.getPublicIpAddress(), null, srcTmpltStore.getInstallPath());
|
return generateCopyUrl(ssVm.getPublicIpAddress(), svo.getParent(), srcTmpltStore.getInstallPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
VMTemplateVO tmplt = _templateDao.findById(srcTmpltStore.getTemplateId());
|
VMTemplateVO tmplt = _templateDao.findById(srcTmpltStore.getTemplateId());
|
||||||
|
|||||||
@ -30,7 +30,11 @@ import javax.inject.Inject;
|
|||||||
import javax.naming.ConfigurationException;
|
import javax.naming.ConfigurationException;
|
||||||
|
|
||||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
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.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.apache.log4j.Logger;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@ -240,6 +244,10 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
KeystoreManager _keystoreMgr;
|
KeystoreManager _keystoreMgr;
|
||||||
|
@Inject
|
||||||
|
DataStoreManager _dataStoreMgr;
|
||||||
|
@Inject
|
||||||
|
ImageStoreDao _imageStoreDao;
|
||||||
private long _capacityScanInterval = DEFAULT_CAPACITY_SCAN_INTERVAL;
|
private long _capacityScanInterval = DEFAULT_CAPACITY_SCAN_INTERVAL;
|
||||||
private int _secStorageVmMtuSize;
|
private int _secStorageVmMtuSize;
|
||||||
|
|
||||||
@ -300,33 +308,39 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<HostVO> ssHosts = _ssvmMgr.listSecondaryStorageHostsInOneZone(zoneId);
|
List<DataStore> ssStores = this._dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId));
|
||||||
for( HostVO ssHost : ssHosts ) {
|
for( DataStore ssStore : ssStores ) {
|
||||||
String secUrl = ssHost.getStorageUrl();
|
String secUrl = ssStore.getUri();
|
||||||
SecStorageSetupCommand setupCmd = null;
|
SecStorageSetupCommand setupCmd = null;
|
||||||
if (!_useSSlCopy) {
|
if (!_useSSlCopy) {
|
||||||
setupCmd = new SecStorageSetupCommand(secUrl, null);
|
setupCmd = new SecStorageSetupCommand(ssStore.getTO(), secUrl, null);
|
||||||
} else {
|
} else {
|
||||||
Certificates certs = _keystoreMgr.getCertificates(ConsoleProxyManager.CERTIFICATE_NAME);
|
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);
|
Answer answer = _agentMgr.easySend(ssHostId, setupCmd);
|
||||||
if (answer != null && answer.getResult()) {
|
if (answer != null && answer.getResult()) {
|
||||||
SecStorageSetupAnswer an = (SecStorageSetupAnswer) answer;
|
SecStorageSetupAnswer an = (SecStorageSetupAnswer) answer;
|
||||||
ssHost.setParent(an.get_dir());
|
if (an.get_dir() != null){
|
||||||
_hostDao.update(ssHost.getId(), ssHost);
|
// 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()) {
|
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 {
|
} else {
|
||||||
if (s_logger.isDebugEnabled()) {
|
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;
|
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);
|
List<SecondaryStorageVmVO> alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, zoneId, State.Running);
|
||||||
String secUrl = cssHost.getStorageUrl();
|
String secUrl = cssHost.getStorageUrl();
|
||||||
SecStorageSetupCommand setupCmd = new SecStorageSetupCommand(secUrl, null);
|
SecStorageSetupCommand setupCmd = new SecStorageSetupCommand(secUrl, null);
|
||||||
@ -345,6 +359,7 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -252,7 +252,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
|||||||
@Inject
|
@Inject
|
||||||
SnapshotDataFactory snapshotFactory;
|
SnapshotDataFactory snapshotFactory;
|
||||||
@Inject
|
@Inject
|
||||||
TemplateService imageSvr;
|
TemplateService tmpltSvr;
|
||||||
@Inject
|
@Inject
|
||||||
DataStoreManager dataStoreMgr;
|
DataStoreManager dataStoreMgr;
|
||||||
@Inject
|
@Inject
|
||||||
@ -1768,11 +1768,11 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
|||||||
AsyncCallFuture<CommandResult> future = null;
|
AsyncCallFuture<CommandResult> future = null;
|
||||||
if (snapshotId != null) {
|
if (snapshotId != null) {
|
||||||
SnapshotInfo snapInfo = this.snapshotFactory.getSnapshot(snapshotId);
|
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) {
|
} else if (volumeId != null) {
|
||||||
volume = _volumeDao.findById(volumeId);
|
volume = _volumeDao.findById(volumeId);
|
||||||
VolumeInfo volInfo = this.volFactory.getVolume(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 {
|
} else {
|
||||||
throw new CloudRuntimeException(
|
throw new CloudRuntimeException(
|
||||||
"Creating private Template need to specify snapshotId or volumeId");
|
"Creating private Template need to specify snapshotId or volumeId");
|
||||||
|
|||||||
@ -68,6 +68,7 @@ public class Upgrade410to420 implements DbUpgrade {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateSystemVmTemplates(Connection conn) {
|
private void updateSystemVmTemplates(Connection conn) {
|
||||||
|
/* TODO: where should be system vm templates located?
|
||||||
PreparedStatement sql = null;
|
PreparedStatement sql = null;
|
||||||
try {
|
try {
|
||||||
sql = conn.prepareStatement("update vm_template set image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'");
|
sql = conn.prepareStatement("update vm_template set image_data_store_id = 1 where type = 'SYSTEM' or type = 'BUILTIN'");
|
||||||
@ -82,6 +83,7 @@ public class Upgrade410to420 implements DbUpgrade {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updatePrimaryStore(Connection conn) {
|
private void updatePrimaryStore(Connection conn) {
|
||||||
|
|||||||
@ -77,6 +77,7 @@ CREATE TABLE `cloud`.`image_store` (
|
|||||||
`data_center_id` bigint unsigned COMMENT 'datacenter id of data store',
|
`data_center_id` bigint unsigned COMMENT 'datacenter id of data store',
|
||||||
`scope` varchar(255) COMMENT 'scope of data store',
|
`scope` varchar(255) COMMENT 'scope of data store',
|
||||||
`uuid` varchar(255) COMMENT 'uuid 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',
|
`created` datetime COMMENT 'date the image store first signed on',
|
||||||
`removed` datetime COMMENT 'date removed if not null',
|
`removed` datetime COMMENT 'date removed if not null',
|
||||||
PRIMARY KEY(`id`)
|
PRIMARY KEY(`id`)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user