mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
Swift : bug fix
This commit is contained in:
parent
d1141aff7d
commit
4116d0d4e4
@ -34,10 +34,10 @@ import com.cloud.utils.db.GenericDao;
|
||||
@Table(name="swift")
|
||||
public class SwiftVO implements Swift {
|
||||
|
||||
@Id
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
@Column(name="id")
|
||||
private long id = -1;
|
||||
private long id;
|
||||
|
||||
@Column(name="url")
|
||||
String url;
|
||||
|
||||
@ -194,6 +194,11 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
||||
try {
|
||||
String parent = getRootDir(secondaryStorageUrl);
|
||||
String lPath = parent + "/template/tmpl/" + accountId.toString() + "/" + templateId.toString();
|
||||
if (!_storage.isFile(lPath + "/template.properties")) {
|
||||
String errMsg = cmd + " Command failed due to template doesn't exist ";
|
||||
s_logger.warn(errMsg);
|
||||
return new Answer(cmd, false, errMsg);
|
||||
}
|
||||
String result = swiftUpload(swift, "T-" + templateId.toString(), lPath, "*");
|
||||
if (result != null) {
|
||||
String errMsg = "failed to download template from Swift to secondary storage " + lPath + " , err=" + result;
|
||||
|
||||
@ -130,6 +130,7 @@ import com.cloud.storage.dao.UploadDaoImpl;
|
||||
import com.cloud.storage.dao.VMTemplateDaoImpl;
|
||||
import com.cloud.storage.dao.VMTemplateHostDaoImpl;
|
||||
import com.cloud.storage.dao.VMTemplatePoolDaoImpl;
|
||||
import com.cloud.storage.dao.VMTemplateSwiftDaoImpl;
|
||||
import com.cloud.storage.dao.VMTemplateZoneDaoImpl;
|
||||
import com.cloud.storage.dao.VolumeDaoImpl;
|
||||
import com.cloud.storage.download.DownloadMonitorImpl;
|
||||
@ -218,6 +219,7 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements Com
|
||||
addDao("ResourceCountDao", ResourceCountDaoImpl.class);
|
||||
addDao("UserAccountDao", UserAccountDaoImpl.class);
|
||||
addDao("VMTemplateHostDao", VMTemplateHostDaoImpl.class);
|
||||
addDao("VMTemplateSwiftDao", VMTemplateSwiftDaoImpl.class);
|
||||
addDao("UploadDao", UploadDaoImpl.class);
|
||||
addDao("VMTemplatePoolDao", VMTemplatePoolDaoImpl.class);
|
||||
addDao("LaunchPermissionDao", LaunchPermissionDaoImpl.class);
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
|
||||
package com.cloud.storage.dao;
|
||||
|
||||
import com.cloud.agent.api.to.SwiftTO;
|
||||
import com.cloud.storage.SwiftVO;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
@ -28,4 +29,6 @@ import com.cloud.utils.db.GenericDao;
|
||||
*/
|
||||
|
||||
public interface SwiftDao extends GenericDao<SwiftVO, Long> {
|
||||
|
||||
SwiftTO getSwiftTO(Long swiftId);
|
||||
}
|
||||
|
||||
@ -17,10 +17,15 @@
|
||||
*/
|
||||
|
||||
package com.cloud.storage.dao;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.api.to.SwiftTO;
|
||||
import com.cloud.storage.SwiftVO;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
|
||||
@ -33,4 +38,23 @@ import com.cloud.utils.db.GenericDaoBase;
|
||||
@Local (value={SwiftDao.class})
|
||||
public class SwiftDaoImpl extends GenericDaoBase<SwiftVO, Long> implements SwiftDao {
|
||||
public static final Logger s_logger = Logger.getLogger(SwiftDaoImpl.class.getName());
|
||||
|
||||
@Override
|
||||
public SwiftTO getSwiftTO(Long swiftId) {
|
||||
if (swiftId != null) {
|
||||
SwiftVO swift = findById(swiftId);
|
||||
if (swift != null) {
|
||||
return swift.toSwiftTO();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
List<SwiftVO> swiftVOs = listAll();
|
||||
if (swiftVOs == null || swiftVOs.size() < 1) {
|
||||
return null;
|
||||
} else {
|
||||
Collections.shuffle(swiftVOs);
|
||||
return swiftVOs.get(0).toSwiftTO();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -292,7 +292,7 @@ public class VMTemplateHostDaoImpl extends GenericDaoBase<VMTemplateHostVO, Long
|
||||
@Override
|
||||
public List<VMTemplateHostVO> listByState(VMTemplateHostVO.Status state) {
|
||||
SearchCriteria<VMTemplateHostVO> sc = createSearchCriteria();
|
||||
sc.addAnd("download_state", SearchCriteria.Op.EQ, state);
|
||||
sc.addAnd("downloadState", SearchCriteria.Op.EQ, state);
|
||||
return search(sc, null);
|
||||
}
|
||||
|
||||
|
||||
@ -19,7 +19,6 @@ package com.cloud.storage.snapshot;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.agent.api.to.SwiftTO;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.storage.SnapshotPolicyVO;
|
||||
@ -140,6 +139,4 @@ public interface SnapshotManager {
|
||||
void deleteSnapshotsForVolume (String secondaryStoragePoolUrl, Long dcId, Long accountId, Long volumeId );
|
||||
|
||||
void deleteSnapshotsDirForVolume(String secondaryStoragePoolUrl, Long dcId, Long accountId, Long volumeId);
|
||||
|
||||
SwiftTO getSwiftTO(Long id);
|
||||
}
|
||||
|
||||
@ -870,7 +870,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
|
||||
if (backupOfSnapshot == null) {
|
||||
return true;
|
||||
}
|
||||
SwiftTO swift = getSwiftTO(null);
|
||||
SwiftTO swift = _swiftDao.getSwiftTO(null);
|
||||
DeleteSnapshotBackupCommand cmd = new DeleteSnapshotBackupCommand(swift, secondaryStoragePoolUrl, dcId, accountId, volumeId, backupOfSnapshot, false);
|
||||
Answer answer = _agentMgr.sendToSSVM(dcId, cmd);
|
||||
|
||||
@ -1036,15 +1036,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
|
||||
return _snapshotDao.search(sc, searchFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SwiftTO getSwiftTO(Long swiftId) {
|
||||
long id = swiftId == null ? 1 : swiftId;
|
||||
SwiftVO swiftVO = _swiftDao.findById(id);
|
||||
if (swiftVO != null) {
|
||||
return toSwiftTO(swiftVO);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteSnapshotDirsForAccount(long accountId) {
|
||||
|
||||
@ -1064,7 +1056,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
|
||||
continue;
|
||||
}
|
||||
List<HostVO> ssHosts = _hostDao.listSecondaryStorageHosts(dcId);
|
||||
SwiftTO swift = getSwiftTO(null);
|
||||
SwiftTO swift = _swiftDao.getSwiftTO(null);
|
||||
if (swift == null) {
|
||||
for (HostVO ssHost : ssHosts) {
|
||||
DeleteSnapshotBackupCommand cmd = new DeleteSnapshotBackupCommand(null, ssHost.getStorageUrl(), dcId, accountId, volumeId, "", true);
|
||||
|
||||
@ -106,7 +106,6 @@ import com.cloud.storage.dao.VMTemplateSwiftDao;
|
||||
import com.cloud.storage.dao.VMTemplateZoneDao;
|
||||
import com.cloud.storage.dao.VolumeDao;
|
||||
import com.cloud.storage.download.DownloadMonitor;
|
||||
import com.cloud.storage.snapshot.SnapshotManager;
|
||||
import com.cloud.storage.upload.UploadMonitor;
|
||||
import com.cloud.template.TemplateAdapter.TemplateAdapterType;
|
||||
import com.cloud.user.Account;
|
||||
@ -165,11 +164,11 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
@Inject VolumeDao _volumeDao;
|
||||
@Inject SnapshotDao _snapshotDao;
|
||||
@Inject
|
||||
SnapshotManager _snapshotMgr;
|
||||
@Inject
|
||||
SwiftDao _swiftDao;
|
||||
@Inject
|
||||
VMTemplateSwiftDao _tmpltSwiftDao;
|
||||
@Inject
|
||||
ConfigurationDao _configDao;
|
||||
@Inject DomainDao _domainDao;
|
||||
@Inject UploadDao _uploadDao;
|
||||
long _routerTemplateId = -1;
|
||||
@ -412,7 +411,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
s_logger.warn(errMsg);
|
||||
return errMsg;
|
||||
}
|
||||
SwiftTO swift = _snapshotMgr.getSwiftTO(tmpltSwift.getSwiftId());
|
||||
SwiftTO swift = _swiftDao.getSwiftTO(tmpltSwift.getSwiftId());
|
||||
if ( swift == null ) {
|
||||
String errMsg = " Swift " + tmpltSwift.getSwiftId() + " doesn't exit ?";
|
||||
s_logger.warn(errMsg);
|
||||
@ -447,7 +446,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
return errMsg;
|
||||
}
|
||||
|
||||
SwiftTO swift = _snapshotMgr.getSwiftTO(null);
|
||||
SwiftTO swift = _swiftDao.getSwiftTO(null);
|
||||
if (swift == null) {
|
||||
String errMsg = " There is no Swift in this setup ";
|
||||
s_logger.warn(errMsg);
|
||||
@ -808,6 +807,10 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
}
|
||||
|
||||
void swiftTemplateSync() {
|
||||
Boolean swiftEnable = Boolean.valueOf(_configDao.getValue(Config.SwiftEnable.key()));
|
||||
if (!swiftEnable) {
|
||||
return;
|
||||
}
|
||||
GlobalLock swiftTemplateSyncLock = GlobalLock.getInternLock("templatemgr.swiftTemplateSync");
|
||||
try {
|
||||
if (swiftTemplateSyncLock.lock(3)) {
|
||||
@ -863,7 +866,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
_swiftTemplateSyncExecutor.scheduleAtFixedRate(getSwiftTemplateSyncTask(), 120, 300, TimeUnit.SECONDS);
|
||||
_swiftTemplateSyncExecutor.scheduleAtFixedRate(getSwiftTemplateSyncTask(), 60, 60, TimeUnit.SECONDS);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -878,16 +881,11 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
_name = name;
|
||||
|
||||
ComponentLocator locator = ComponentLocator.getCurrentLocator();
|
||||
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
|
||||
|
||||
if (configDao == null) {
|
||||
throw new ConfigurationException("Unable to find ConfigurationDao");
|
||||
}
|
||||
|
||||
final Map<String, String> configs = configDao.getConfiguration("AgentManager", params);
|
||||
final Map<String, String> configs = _configDao.getConfiguration("AgentManager", params);
|
||||
_routerTemplateId = NumbersUtil.parseInt(configs.get("router.template.id"), 1);
|
||||
|
||||
String value = configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
|
||||
String value = _configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
|
||||
_primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
|
||||
|
||||
HostTemplateStatesSearch = _tmpltHostDao.createSearchBuilder();
|
||||
@ -901,7 +899,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
|
||||
HostSearch.done();
|
||||
HostTemplateStatesSearch.done();
|
||||
|
||||
_storagePoolMaxWaitSeconds = NumbersUtil.parseInt(configDao.getValue(Config.StoragePoolMaxWaitSeconds.key()), 3600);
|
||||
_storagePoolMaxWaitSeconds = NumbersUtil.parseInt(_configDao.getValue(Config.StoragePoolMaxWaitSeconds.key()), 3600);
|
||||
_preloadExecutor = Executors.newFixedThreadPool(8, new NamedThreadFactory("Template-Preloader"));
|
||||
_swiftTemplateSyncExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("swift-template-sync-Executor"));
|
||||
return false;
|
||||
|
||||
@ -79,6 +79,7 @@
|
||||
<dao name="UserAccount" class="com.cloud.user.dao.UserAccountDaoImpl"/>
|
||||
<dao name="Usage IPAddress" class="com.cloud.usage.dao.UsageIPAddressDaoImpl"/>
|
||||
<dao name="VM Template Host" class="com.cloud.storage.dao.VMTemplateHostDaoImpl"/>
|
||||
<dao name="VM Template Swift" class="com.cloud.storage.dao.VMTemplateSwiftDaoImpl"/>
|
||||
<dao name="Upload" class="com.cloud.storage.dao.UploadDaoImpl"/>
|
||||
<dao name="VM Template Pool" class="com.cloud.storage.dao.VMTemplatePoolDaoImpl"/>
|
||||
<dao name="Launch Permission" class="com.cloud.storage.dao.LaunchPermissionDaoImpl"/>
|
||||
|
||||
@ -990,7 +990,7 @@ CREATE TABLE `cloud`.`template_host_ref` (
|
||||
INDEX `i_template_host_ref__template_id`(`template_id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE `cloud`.`swift_host_ref` (
|
||||
CREATE TABLE `cloud`.`template_swift_ref` (
|
||||
`id` bigint unsigned NOT NULL auto_increment,
|
||||
`swift_id` bigint unsigned NOT NULL,
|
||||
`template_id` bigint unsigned NOT NULL,
|
||||
@ -998,8 +998,8 @@ CREATE TABLE `cloud`.`swift_host_ref` (
|
||||
`size` bigint unsigned,
|
||||
`physical_size` bigint unsigned DEFAULT 0,
|
||||
PRIMARY KEY (`id`),
|
||||
CONSTRAINT `fk_template_swift_ref__swift_id` FOREIGN KEY `fk_template_swift_ref__swift_id` (`swift_id`) REFERENCES `swift (`id`) ON DELETE CASCADE,
|
||||
INDEX `i_template_swift_ref__host_id`(`swift_id`),
|
||||
CONSTRAINT `fk_template_swift_ref__swift_id` FOREIGN KEY `fk_template_swift_ref__swift_id` (`swift_id`) REFERENCES `swift` (`id`) ON DELETE CASCADE,
|
||||
INDEX `i_template_swift_ref__swift_id`(`swift_id`),
|
||||
CONSTRAINT `fk_template_swift_ref__template_id` FOREIGN KEY `fk_template_swift_ref__template_id` (`template_id`) REFERENCES `vm_template` (`id`),
|
||||
INDEX `i_template_swift_ref__template_id`(`template_id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user