use of com.cloud.engine.subsystem.api.storage.EndPoint in project cosmic by MissionCriticalCloud.
the class SnapshotManagerImpl method deleteSnapshotDirsForAccount.
@Override
public boolean deleteSnapshotDirsForAccount(final long accountId) {
final List<VolumeVO> volumes = _volsDao.findIncludingRemovedByAccount(accountId);
// The above call will list only non-destroyed volumes.
// So call this method before marking the volumes as destroyed.
// i.e Call them before the VMs for those volumes are destroyed.
boolean success = true;
for (final VolumeVO volume : volumes) {
if (volume.getPoolId() == null) {
continue;
}
final Long volumeId = volume.getId();
final Long dcId = volume.getDataCenterId();
if (_snapshotDao.listByVolumeIdIncludingRemoved(volumeId).isEmpty()) {
// This volume doesn't have any snapshots. Nothing do delete.
continue;
}
final List<DataStore> ssHosts = dataStoreMgr.getImageStoresByScope(new ZoneScope(dcId));
for (final DataStore ssHost : ssHosts) {
final String snapshotDir = TemplateConstants.DEFAULT_SNAPSHOT_ROOT_DIR + "/" + accountId + "/" + volumeId;
final DeleteSnapshotsDirCommand cmd = new DeleteSnapshotsDirCommand(ssHost.getTO(), snapshotDir);
final EndPoint ep = _epSelector.select(ssHost);
final Answer answer;
if (ep == null) {
final String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
s_logger.error(errMsg);
answer = new Answer(cmd, false, errMsg);
} else {
answer = ep.sendMessage(cmd);
}
if (answer != null && answer.getResult()) {
s_logger.debug("Deleted all snapshots for volume: " + volumeId + " under account: " + accountId);
} else {
success = false;
if (answer != null) {
s_logger.warn("Failed to delete all snapshot for volume " + volumeId + " on secondary storage " + ssHost.getUri());
s_logger.error(answer.getDetails());
}
}
}
// Either way delete the snapshots for this volume.
final List<SnapshotVO> snapshots = listSnapsforVolume(volumeId);
for (final SnapshotVO snapshot : snapshots) {
final SnapshotStrategy snapshotStrategy = _storageStrategyFactory.getSnapshotStrategy(snapshot, SnapshotOperation.DELETE);
if (snapshotStrategy == null) {
s_logger.error("Unable to find snaphot strategy to handle snapshot with id '" + snapshot.getId() + "'");
continue;
}
final SnapshotDataStoreVO snapshotStoreRef = _snapshotStoreDao.findBySnapshot(snapshot.getId(), DataStoreRole.Image);
if (snapshotStrategy.deleteSnapshot(snapshot.getId())) {
if (Type.MANUAL == snapshot.getRecurringType()) {
_resourceLimitMgr.decrementResourceCount(accountId, ResourceType.snapshot);
if (snapshotStoreRef != null) {
_resourceLimitMgr.decrementResourceCount(accountId, ResourceType.secondary_storage, new Long(snapshotStoreRef.getPhysicalSize()));
}
}
}
}
}
// Returns true if snapshotsDir has been deleted for all volumes.
return success;
}
use of com.cloud.engine.subsystem.api.storage.EndPoint in project cosmic by MissionCriticalCloud.
the class UploadListener method sendCommand.
public void sendCommand(final RequestType reqType) {
if (getJobId() != null) {
if (s_logger.isTraceEnabled()) {
logTrace("Sending progress command ");
}
try {
final EndPoint ep = _epSelector.select(sserver);
if (ep == null) {
final String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
s_logger.error(errMsg);
return;
}
ep.sendMessageAsync(new UploadProgressCommand(getCommand(), getJobId(), reqType), new Callback(ep.getId(), this));
} catch (final Exception e) {
s_logger.debug("Send command failed", e);
setDisconnected();
}
}
}
use of com.cloud.engine.subsystem.api.storage.EndPoint in project cosmic by MissionCriticalCloud.
the class UploadMonitorImpl method createEntityDownloadURL.
@Override
public UploadVO createEntityDownloadURL(final VMTemplateVO template, final TemplateDataStoreVO vmTemplateHost, final Long dataCenterId, final long eventId) {
String errorString = "";
boolean success = false;
final Type type = (template.getFormat() == ImageFormat.ISO) ? Type.ISO : Type.TEMPLATE;
// find an endpoint to send command
final DataStore store = storeMgr.getDataStore(vmTemplateHost.getDataStoreId(), DataStoreRole.Image);
final EndPoint ep = _epSelector.select(store);
if (ep == null) {
final String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
s_logger.error(errMsg);
return null;
}
// Check if it already exists.
final List<UploadVO> extractURLList = _uploadDao.listByTypeUploadStatus(template.getId(), type, UploadVO.Status.DOWNLOAD_URL_CREATED);
if (extractURLList.size() > 0) {
// do some check here
final UploadVO upload = extractURLList.get(0);
String uploadUrl = extractURLList.get(0).getUploadUrl();
final String[] token = uploadUrl.split("/");
// example: uploadUrl = https://10-11-101-112.realhostip.com/userdata/2fdd9a70-9c4a-4a04-b1d5-1e41c221a1f9.iso
// then token[2] = 10-11-101-112.realhostip.com, token[4] = 2fdd9a70-9c4a-4a04-b1d5-1e41c221a1f9.iso
final String hostname = ep.getPublicAddr().replace(".", "-") + ".";
if (// ssvm publicip and domain suffix not changed
(token != null) && (token.length == 5) && (token[2].equals(hostname + _ssvmUrlDomain))) {
return extractURLList.get(0);
} else if ((token != null) && (token.length == 5) && (token[2].startsWith(hostname))) {
// domain suffix changed
final String uuid = token[4];
uploadUrl = generateCopyUrl(ep.getPublicAddr(), uuid);
final UploadVO vo = _uploadDao.createForUpdate();
vo.setLastUpdated(new Date());
vo.setUploadUrl(uploadUrl);
_uploadDao.update(upload.getId(), vo);
return _uploadDao.findById(upload.getId(), true);
} else {
// ssvm publicip changed
return null;
}
}
// It doesn't exist so create a DB entry.
final UploadVO uploadTemplateObj = new UploadVO(vmTemplateHost.getDataStoreId(), template.getId(), new Date(), Status.DOWNLOAD_URL_NOT_CREATED, 0, type, Mode.HTTP_DOWNLOAD);
uploadTemplateObj.setInstallPath(vmTemplateHost.getInstallPath());
_uploadDao.persist(uploadTemplateObj);
try {
// Create Symlink at ssvm
final String path = vmTemplateHost.getInstallPath();
// adding "." + vhd/ova... etc.
final String uuid = UUID.randomUUID().toString() + "." + template.getFormat().getFileExtension();
final CreateEntityDownloadURLCommand cmd = new CreateEntityDownloadURLCommand(((ImageStoreEntity) store).getMountPoint(), path, uuid, null);
final Answer ans = ep.sendMessage(cmd);
if (ans == null || !ans.getResult()) {
errorString = "Unable to create a link for " + type + " id:" + template.getId() + "," + (ans == null ? "" : ans.getDetails());
s_logger.error(errorString);
throw new CloudRuntimeException(errorString);
}
// Construct actual URL locally now that the symlink exists at SSVM
final String extractURL = generateCopyUrl(ep.getPublicAddr(), uuid);
final UploadVO vo = _uploadDao.createForUpdate();
vo.setLastUpdated(new Date());
vo.setUploadUrl(extractURL);
vo.setUploadState(Status.DOWNLOAD_URL_CREATED);
_uploadDao.update(uploadTemplateObj.getId(), vo);
success = true;
return _uploadDao.findById(uploadTemplateObj.getId(), true);
} finally {
if (!success) {
final UploadVO uploadJob = _uploadDao.createForUpdate(uploadTemplateObj.getId());
uploadJob.setLastUpdated(new Date());
uploadJob.setErrorString(errorString);
uploadJob.setUploadState(Status.ERROR);
_uploadDao.update(uploadTemplateObj.getId(), uploadJob);
}
}
}
use of com.cloud.engine.subsystem.api.storage.EndPoint in project cosmic by MissionCriticalCloud.
the class UploadMonitorImpl method extractTemplate.
@Override
public Long extractTemplate(final VMTemplateVO template, final String url, final TemplateDataStoreVO vmTemplateHost, final Long dataCenterId, final long eventId, final long asyncJobId, final AsyncJobManager asyncMgr) {
final Type type = (template.getFormat() == ImageFormat.ISO) ? Type.ISO : Type.TEMPLATE;
final DataStore secStore = storeMgr.getImageStore(dataCenterId);
final UploadVO uploadTemplateObj = new UploadVO(secStore.getId(), template.getId(), new Date(), Upload.Status.NOT_UPLOADED, type, url, Mode.FTP_UPLOAD);
_uploadDao.persist(uploadTemplateObj);
if (vmTemplateHost != null) {
start();
final UploadCommand ucmd = new UploadCommand(template, url, vmTemplateHost.getInstallPath(), vmTemplateHost.getSize());
final UploadListener ul = new UploadListener(secStore, _timer, _uploadDao, uploadTemplateObj, this, ucmd, template.getAccountId(), template.getName(), type, eventId, asyncJobId, asyncMgr);
_listenerMap.put(uploadTemplateObj, ul);
try {
final EndPoint ep = _epSelector.select(secStore);
if (ep == null) {
final String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
s_logger.error(errMsg);
return null;
}
ep.sendMessageAsync(ucmd, new UploadListener.Callback(ep.getId(), ul));
} catch (final Exception e) {
s_logger.warn("Unable to start upload of " + template.getUniqueName() + " from " + secStore.getName() + " to " + url, e);
ul.setDisconnected();
ul.scheduleStatusCheck(RequestType.GET_OR_RESTART);
}
return uploadTemplateObj.getId();
}
return null;
}
use of com.cloud.engine.subsystem.api.storage.EndPoint in project cosmic by MissionCriticalCloud.
the class UploadMonitorImpl method cleanupStorage.
public void cleanupStorage() {
final int EXTRACT_URL_LIFE_LIMIT_IN_SECONDS = _urlExpirationInterval;
final List<UploadVO> extractJobs = _uploadDao.listByModeAndStatus(Mode.HTTP_DOWNLOAD, Status.DOWNLOAD_URL_CREATED);
for (final UploadVO extractJob : extractJobs) {
if (getTimeDiff(extractJob.getLastUpdated()) > EXTRACT_URL_LIFE_LIMIT_IN_SECONDS) {
final String path = extractJob.getInstallPath();
final DataStore secStore = storeMgr.getDataStore(extractJob.getDataStoreId(), DataStoreRole.Image);
// Would delete the symlink for the Type and if Type == VOLUME then also the volume
final DeleteEntityDownloadURLCommand cmd = new DeleteEntityDownloadURLCommand(path, extractJob.getType(), extractJob.getUploadUrl(), ((ImageStoreVO) secStore).getParent());
final EndPoint ep = _epSelector.select(secStore);
if (ep == null) {
s_logger.warn("UploadMonitor cleanup: There is no secondary storage VM for secondary storage host " + extractJob.getDataStoreId());
// TODO: why continue? why not break?
continue;
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("UploadMonitor cleanup: Sending deletion of extract URL " + extractJob.getUploadUrl() + " to ssvm " + ep.getHostAddr());
}
final Answer ans = ep.sendMessage(cmd);
if (ans != null && ans.getResult()) {
_uploadDao.remove(extractJob.getId());
} else {
s_logger.warn("UploadMonitor cleanup: Unable to delete the link for " + extractJob.getType() + " id=" + extractJob.getTypeId() + " url=" + extractJob.getUploadUrl() + " on ssvm " + ep.getHostAddr());
}
}
}
}
Aggregations