Search in sources :

Example 1 with EndPoint

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;
}
Also used : SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) DeleteSnapshotsDirCommand(com.cloud.agent.api.DeleteSnapshotsDirCommand) Answer(com.cloud.agent.api.Answer) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) SnapshotVO(com.cloud.storage.SnapshotVO) VolumeVO(com.cloud.storage.VolumeVO) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) SnapshotStrategy(com.cloud.engine.subsystem.api.storage.SnapshotStrategy)

Example 2 with EndPoint

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();
        }
    }
}
Also used : AsyncCompletionCallback(com.cloud.framework.async.AsyncCompletionCallback) UploadProgressCommand(com.cloud.agent.api.storage.UploadProgressCommand) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 3 with EndPoint

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);
        }
    }
}
Also used : CreateEntityDownloadURLCommand(com.cloud.agent.api.storage.CreateEntityDownloadURLCommand) Answer(com.cloud.agent.api.Answer) Type(com.cloud.storage.Upload.Type) RequestType(com.cloud.agent.api.storage.UploadProgressCommand.RequestType) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) UploadVO(com.cloud.storage.UploadVO) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) Date(java.util.Date)

Example 4 with EndPoint

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;
}
Also used : Type(com.cloud.storage.Upload.Type) RequestType(com.cloud.agent.api.storage.UploadProgressCommand.RequestType) UploadCommand(com.cloud.agent.api.storage.UploadCommand) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) UploadVO(com.cloud.storage.UploadVO) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) Date(java.util.Date) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 5 with EndPoint

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());
            }
        }
    }
}
Also used : Answer(com.cloud.agent.api.Answer) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) UploadVO(com.cloud.storage.UploadVO) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) DeleteEntityDownloadURLCommand(com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand)

Aggregations

EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)36 Answer (com.cloud.agent.api.Answer)25 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)17 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)14 RemoteHostEndPoint (com.cloud.storage.RemoteHostEndPoint)12 DataObject (com.cloud.engine.subsystem.api.storage.DataObject)8 CopyCmdAnswer (com.cloud.storage.command.CopyCmdAnswer)8 CopyCommand (com.cloud.storage.command.CopyCommand)8 Date (java.util.Date)8 MigrateVolumeAnswer (com.cloud.agent.api.storage.MigrateVolumeAnswer)7 ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)6 ResizeVolumeAnswer (com.cloud.agent.api.storage.ResizeVolumeAnswer)5 CopyCommandResult (com.cloud.engine.subsystem.api.storage.CopyCommandResult)4 VolumeVO (com.cloud.storage.VolumeVO)4 CreateEntityDownloadURLCommand (com.cloud.agent.api.storage.CreateEntityDownloadURLCommand)3 ListVolumeAnswer (com.cloud.agent.api.storage.ListVolumeAnswer)3 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)3 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)3 UploadVO (com.cloud.storage.UploadVO)3 CommandResult (com.cloud.storage.command.CommandResult)3