Search in sources :

Example 91 with DataStore

use of com.cloud.engine.subsystem.api.storage.DataStore 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());
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) Pair(com.cloud.utils.Pair)

Example 92 with DataStore

use of com.cloud.engine.subsystem.api.storage.DataStore in project cosmic by MissionCriticalCloud.

the class DownloadListener method processConnect.

@Override
public void processConnect(final Host agent, final StartupCommand cmd, final boolean forRebalance) throws ConnectionException {
    if (cmd instanceof StartupRoutingCommand) {
        final List<HypervisorType> hypers = _resourceMgr.listAvailHypervisorInZone(agent.getId(), agent.getDataCenterId());
        final HypervisorType hostHyper = agent.getHypervisorType();
        if (hypers.contains(hostHyper)) {
            return;
        }
        _imageSrv.handleSysTemplateDownload(hostHyper, agent.getDataCenterId());
        // update template_zone_ref for cross-zone templates
        _imageSrv.associateCrosszoneTemplatesToZone(agent.getDataCenterId());
    } else /* This can be removed
        else if ( cmd instanceof StartupStorageCommand) {
            StartupStorageCommand storage = (StartupStorageCommand)cmd;
            if( storage.getResourceType() == Storage.StorageResourceType.SECONDARY_STORAGE ||
                    storage.getResourceType() == Storage.StorageResourceType.LOCAL_SECONDARY_STORAGE  ) {
                downloadMonitor.addSystemVMTemplatesToHost(agent, storage.getTemplateInfo());
                downloadMonitor.handleTemplateSync(agent);
                downloadMonitor.handleVolumeSync(agent);
            }
        }*/
    if (cmd instanceof StartupSecondaryStorageCommand) {
        try {
            final List<DataStore> imageStores = _storeMgr.getImageStoresByScope(new ZoneScope(agent.getDataCenterId()));
            for (final DataStore store : imageStores) {
                _volumeSrv.handleVolumeSync(store);
                _imageSrv.handleTemplateSync(store);
            }
        } catch (final Exception e) {
            s_logger.error("Caught exception while doing template/volume sync ", e);
        }
    }
}
Also used : HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) StartupSecondaryStorageCommand(com.cloud.agent.api.StartupSecondaryStorageCommand) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) List(java.util.List) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) ConnectionException(com.cloud.exception.ConnectionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 93 with DataStore

use of com.cloud.engine.subsystem.api.storage.DataStore 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);
        }
    }
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) DownloadCommand(com.cloud.storage.command.DownloadCommand) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) UploadListener(com.cloud.storage.upload.UploadListener) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DownloadProgressCommand(com.cloud.storage.command.DownloadProgressCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore)

Example 94 with DataStore

use of com.cloud.engine.subsystem.api.storage.DataStore in project cosmic by MissionCriticalCloud.

the class DownloadMonitorImpl method downloadVolumeToStorage.

@Override
public void downloadVolumeToStorage(final DataObject volume, final AsyncCompletionCallback<DownloadAnswer> callback) {
    boolean downloadJobExists = false;
    VolumeDataStoreVO volumeHost = null;
    final DataStore store = volume.getDataStore();
    final VolumeInfo volInfo = (VolumeInfo) volume;
    final RegisterVolumePayload payload = (RegisterVolumePayload) volInfo.getpayload();
    final String url = payload.getUrl();
    final String checkSum = payload.getChecksum();
    final ImageFormat format = ImageFormat.valueOf(payload.getFormat());
    volumeHost = _volumeStoreDao.findByStoreVolume(store.getId(), volume.getId());
    if (volumeHost == null) {
        volumeHost = new VolumeDataStoreVO(store.getId(), volume.getId(), new Date(), 0, Status.NOT_DOWNLOADED, null, null, "jobid0000", null, url, checkSum);
        _volumeStoreDao.persist(volumeHost);
    } else if ((volumeHost.getJobId() != null) && (volumeHost.getJobId().length() > 2)) {
        downloadJobExists = true;
    } else {
        // persit url and checksum
        volumeHost.setDownloadUrl(url);
        volumeHost.setChecksum(checkSum);
        _volumeStoreDao.update(volumeHost.getId(), volumeHost);
    }
    final Long maxVolumeSizeInBytes = getMaxVolumeSizeInBytes();
    if (volumeHost != null) {
        start();
        final Volume vol = _volumeDao.findById(volume.getId());
        DownloadCommand dcmd = new DownloadCommand((VolumeObjectTO) (volume.getTO()), maxVolumeSizeInBytes, checkSum, url, format);
        dcmd.setProxy(getHttpProxy());
        if (downloadJobExists) {
            dcmd = new DownloadProgressCommand(dcmd, volumeHost.getJobId(), RequestType.GET_OR_RESTART);
            dcmd.setResourceType(ResourceType.VOLUME);
        }
        final EndPoint ep = _epSelector.select(volume);
        if (ep == null) {
            s_logger.warn("There is no secondary storage VM for image store " + store.getName());
            return;
        }
        final DownloadListener dl = new DownloadListener(ep, store, volume, _timer, this, dcmd, callback);
        // auto-wired those injected fields in DownloadListener
        ComponentContext.inject(dl);
        if (downloadJobExists) {
            dl.setCurrState(volumeHost.getDownloadState());
        }
        try {
            ep.sendMessageAsync(dcmd, new UploadListener.Callback(ep.getId(), dl));
        } catch (final Exception e) {
            s_logger.warn("Unable to start /resume download of volume " + volume.getId() + " to " + store.getName(), e);
            dl.setDisconnected();
            dl.scheduleStatusCheck(RequestType.GET_OR_RESTART);
        }
    }
}
Also used : DownloadCommand(com.cloud.storage.command.DownloadCommand) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) RegisterVolumePayload(com.cloud.storage.RegisterVolumePayload) UploadListener(com.cloud.storage.upload.UploadListener) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ImageFormat(com.cloud.storage.Storage.ImageFormat) DownloadProgressCommand(com.cloud.storage.command.DownloadProgressCommand) Volume(com.cloud.storage.Volume) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO)

Example 95 with DataStore

use of com.cloud.engine.subsystem.api.storage.DataStore in project cosmic by MissionCriticalCloud.

the class DownloadMonitorImpl method downloadTemplateToStorage.

@Override
public void downloadTemplateToStorage(final DataObject template, final AsyncCompletionCallback<DownloadAnswer> callback) {
    if (template != null) {
        final long templateId = template.getId();
        final DataStore store = template.getDataStore();
        if (isTemplateUpdateable(templateId, store.getId())) {
            if (template.getUri() != null) {
                initiateTemplateDownload(template, callback);
            } else {
                s_logger.info("Template url is null, cannot download");
                final DownloadAnswer ans = new DownloadAnswer("Template url is null", Status.UNKNOWN);
                callback.complete(ans);
            }
        } else {
            s_logger.info("Template download is already in progress or already downloaded");
            final DownloadAnswer ans = new DownloadAnswer("Template download is already in progress or already downloaded", Status.UNKNOWN);
            callback.complete(ans);
        }
    }
}
Also used : DataStore(com.cloud.engine.subsystem.api.storage.DataStore) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer)

Aggregations

DataStore (com.cloud.engine.subsystem.api.storage.DataStore)96 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)43 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)23 ExecutionException (java.util.concurrent.ExecutionException)23 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)19 ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)17 TemplateDataStoreVO (com.cloud.storage.datastore.db.TemplateDataStoreVO)17 ArrayList (java.util.ArrayList)17 VolumeVO (com.cloud.storage.VolumeVO)16 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)15 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)14 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)14 DB (com.cloud.utils.db.DB)14 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)12 SnapshotDataStoreVO (com.cloud.storage.datastore.db.SnapshotDataStoreVO)12 StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)12 VolumeDataStoreVO (com.cloud.storage.datastore.db.VolumeDataStoreVO)12 ConfigurationException (javax.naming.ConfigurationException)12 Answer (com.cloud.agent.api.Answer)10 VMTemplateVO (com.cloud.storage.VMTemplateVO)10