use of com.cloud.storage.datastore.db.TemplateDataStoreVO in project cosmic by MissionCriticalCloud.
the class StorageManagerImpl method cleanupDownloadUrls.
@Override
public void cleanupDownloadUrls() {
// Cleanup expired volume URLs
final List<VolumeDataStoreVO> volumesOnImageStoreList = _volumeStoreDao.listVolumeDownloadUrls();
for (final VolumeDataStoreVO volumeOnImageStore : volumesOnImageStoreList) {
final long downloadUrlCurrentAgeInSecs = DateUtil.getTimeDifference(DateUtil.now(), volumeOnImageStore.getExtractUrlCreated());
if (downloadUrlCurrentAgeInSecs < _downloadUrlExpirationInterval) {
// URL hasnt expired yet
continue;
}
final long volumeId = volumeOnImageStore.getVolumeId();
s_logger.debug("Removing download url " + volumeOnImageStore.getExtractUrl() + " for volume id " + volumeId);
// Remove it from image store
final ImageStoreEntity secStore = (ImageStoreEntity) _dataStoreMgr.getDataStore(volumeOnImageStore.getDataStoreId(), DataStoreRole.Image);
secStore.deleteExtractUrl(volumeOnImageStore.getInstallPath(), volumeOnImageStore.getExtractUrl(), Upload.Type.VOLUME);
// Now expunge it from DB since this entry was created only for download purpose
_volumeStoreDao.expunge(volumeOnImageStore.getId());
final Volume volume = _volumeDao.findById(volumeId);
if (volume != null && volume.getState() == Volume.State.Expunged) {
_volumeDao.remove(volumeId);
}
}
// Cleanup expired template URLs
final List<TemplateDataStoreVO> templatesOnImageStoreList = _templateStoreDao.listTemplateDownloadUrls();
for (final TemplateDataStoreVO templateOnImageStore : templatesOnImageStoreList) {
final long downloadUrlCurrentAgeInSecs = DateUtil.getTimeDifference(DateUtil.now(), templateOnImageStore.getExtractUrlCreated());
if (downloadUrlCurrentAgeInSecs < _downloadUrlExpirationInterval) {
// URL hasnt expired yet
continue;
}
s_logger.debug("Removing download url " + templateOnImageStore.getExtractUrl() + " for template id " + templateOnImageStore.getTemplateId());
// Remove it from image store
final ImageStoreEntity secStore = (ImageStoreEntity) _dataStoreMgr.getDataStore(templateOnImageStore.getDataStoreId(), DataStoreRole.Image);
secStore.deleteExtractUrl(templateOnImageStore.getInstallPath(), templateOnImageStore.getExtractUrl(), Upload.Type.TEMPLATE);
// Now remove download details from DB.
templateOnImageStore.setExtractUrl(null);
templateOnImageStore.setExtractUrlCreated(null);
_templateStoreDao.update(templateOnImageStore.getId(), templateOnImageStore);
}
}
use of com.cloud.storage.datastore.db.TemplateDataStoreVO in project cosmic by MissionCriticalCloud.
the class TemplateManagerImpl method registerTemplateForPostUpload.
@Override
@ActionEvent(eventType = EventTypes.EVENT_TEMPLATE_CREATE, eventDescription = "creating post upload template")
public GetUploadParamsResponse registerTemplateForPostUpload(final GetUploadParamsForTemplateCmd cmd) throws ResourceAllocationException, MalformedURLException {
final TemplateAdapter adapter = getAdapter(HypervisorType.getType(cmd.getHypervisor()));
final TemplateProfile profile = adapter.prepare(cmd);
final List<TemplateOrVolumePostUploadCommand> payload = adapter.createTemplateForPostUpload(profile);
if (CollectionUtils.isNotEmpty(payload)) {
final GetUploadParamsResponse response = new GetUploadParamsResponse();
/*
* There can be one or more commands depending on the number of secondary stores the template needs to go to. Taking the first one to do the url upload. The
* template will be propagated to the rest through copy by management server commands.
*/
final TemplateOrVolumePostUploadCommand firstCommand = payload.get(0);
final String ssvmUrlDomain = _configDao.getValue(Config.SecStorageSecureCopyCert.key());
final String url = ImageStoreUtil.generatePostUploadUrl(ssvmUrlDomain, firstCommand.getRemoteEndPoint(), firstCommand.getEntityUUID());
response.setPostURL(new URL(url));
// set the post url, this is used in the monitoring thread to determine the SSVM
final TemplateDataStoreVO templateStore = _tmplStoreDao.findByTemplate(firstCommand.getEntityId(), DataStoreRole.getRole(firstCommand.getDataToRole()));
if (templateStore != null) {
templateStore.setExtractUrl(url);
_tmplStoreDao.persist(templateStore);
}
response.setId(UUID.fromString(firstCommand.getEntityUUID()));
final int timeout = ImageStoreUploadMonitorImpl.getUploadOperationTimeout();
final DateTime currentDateTime = new DateTime(DateTimeZone.UTC);
final String expires = currentDateTime.plusMinutes(timeout).toString();
response.setTimeout(expires);
final String key = _configDao.getValue(Config.SSVMPSK.key());
/*
* encoded metadata using the post upload config ssh key
*/
final Gson gson = new GsonBuilder().create();
final String metadata = EncryptionUtil.encodeData(gson.toJson(firstCommand), key);
response.setMetadata(metadata);
/*
* signature calculated on the url, expiry, metadata.
*/
response.setSignature(EncryptionUtil.generateSignature(metadata + url + expires, key));
return response;
} else {
throw new CloudRuntimeException("Unable to register template.");
}
}
use of com.cloud.storage.datastore.db.TemplateDataStoreVO in project cosmic by MissionCriticalCloud.
the class TemplateManagerImpl method getAbsoluteIsoPath.
@Override
public Pair<String, String> getAbsoluteIsoPath(final long templateId, final long dataCenterId) {
final TemplateDataStoreVO templateStoreRef = _tmplStoreDao.findByTemplateZoneDownloadStatus(templateId, dataCenterId, VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
if (templateStoreRef == null) {
throw new CloudRuntimeException("Template " + templateId + " has not been completely downloaded to zone " + dataCenterId);
}
final DataStore store = _dataStoreMgr.getDataStore(templateStoreRef.getDataStoreId(), DataStoreRole.Image);
final String isoPath = store.getUri() + "/" + templateStoreRef.getInstallPath();
return new Pair<>(isoPath, store.getUri());
}
use of com.cloud.storage.datastore.db.TemplateDataStoreVO in project cosmic by MissionCriticalCloud.
the class DownloadMonitorImpl method initiateTemplateDownload.
private void initiateTemplateDownload(final DataObject template, final AsyncCompletionCallback<DownloadAnswer> callback) {
boolean downloadJobExists = false;
TemplateDataStoreVO vmTemplateStore = null;
final DataStore store = template.getDataStore();
vmTemplateStore = _vmTemplateStoreDao.findByStoreTemplate(store.getId(), template.getId());
if (vmTemplateStore == null) {
vmTemplateStore = new TemplateDataStoreVO(store.getId(), template.getId(), new Date(), 0, Status.NOT_DOWNLOADED, null, null, "jobid0000", null, template.getUri());
vmTemplateStore.setDataStoreRole(store.getRole());
vmTemplateStore = _vmTemplateStoreDao.persist(vmTemplateStore);
} else if ((vmTemplateStore.getJobId() != null) && (vmTemplateStore.getJobId().length() > 2)) {
downloadJobExists = true;
}
final Long maxTemplateSizeInBytes = getMaxTemplateSizeInBytes();
if (vmTemplateStore != null) {
start();
final VirtualMachineTemplate tmpl = _templateDao.findById(template.getId());
DownloadCommand dcmd = new DownloadCommand((TemplateObjectTO) (template.getTO()), maxTemplateSizeInBytes);
dcmd.setProxy(getHttpProxy());
if (downloadJobExists) {
dcmd = new DownloadProgressCommand(dcmd, vmTemplateStore.getJobId(), RequestType.GET_OR_RESTART);
}
if (vmTemplateStore.isCopy()) {
dcmd.setCreds(TemplateConstants.DEFAULT_HTTP_AUTH_USER, _copyAuthPasswd);
}
final EndPoint ep = _epSelector.select(template);
if (ep == null) {
final String errMsg = "There is no secondary storage VM for downloading template to image store " + store.getName();
s_logger.warn(errMsg);
throw new CloudRuntimeException(errMsg);
}
final DownloadListener dl = new DownloadListener(ep, store, template, _timer, this, dcmd, callback);
// initialize those auto-wired field in download listener.
ComponentContext.inject(dl);
if (downloadJobExists) {
// due to handling existing download job issues, we still keep
// downloadState in template_store_ref to avoid big change in
// DownloadListener to use
// new ObjectInDataStore.State transition. TODO: fix this later
// to be able to remove downloadState from template_store_ref.
s_logger.info("found existing download job");
dl.setCurrState(vmTemplateStore.getDownloadState());
}
try {
ep.sendMessageAsync(dcmd, new UploadListener.Callback(ep.getId(), dl));
} catch (final Exception e) {
s_logger.warn("Unable to start /resume download of template " + template.getId() + " to " + store.getName(), e);
dl.setDisconnected();
dl.scheduleStatusCheck(RequestType.GET_OR_RESTART);
}
}
}
Aggregations