Package org.apache.cloudstack.engine.subsystem.api.storage

Examples of org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo


    }

    @Override
    public EndPoint select(DataObject object, StorageAction action) {
        if (action == StorageAction.TAKESNAPSHOT) {
            SnapshotInfo snapshotInfo = (SnapshotInfo)object;
            if (snapshotInfo.getHypervisorType() == Hypervisor.HypervisorType.KVM) {
                VolumeInfo volumeInfo = snapshotInfo.getBaseVolume();
                VirtualMachine vm = volumeInfo.getAttachedVM();
                if ((vm != null) && (vm.getState() == VirtualMachine.State.Running)) {
                    Long hostId = vm.getHostId();
                    return getEndPointFromHostId(hostId);
                }
View Full Code Here


            snapshot = snapshot.getParent();
        }
    }

    protected Answer copyVolumeFromSnapshot(DataObject snapObj, DataObject volObj) {
        SnapshotInfo snapshot = (SnapshotInfo) snapObj;
        StoragePool pool = (StoragePool) volObj.getDataStore();

        String basicErrMsg = "Failed to create volume from " + snapshot.getName() + " on pool " + pool;
        DataStore store = snapObj.getDataStore();
        DataStoreTO storTO = store.getTO();
        DataObject srcData = snapObj;
        try {
            if (!(storTO instanceof NfsTO)) {
View Full Code Here

                Integer.parseInt(Config.CreatePrivateTemplateFromSnapshotWait.getDefaultValue()));

        boolean needCache = false;
        if (needCacheStorage(srcData, destData)) {
            needCache = true;
            SnapshotInfo snapshot = (SnapshotInfo) srcData;
            srcData = cacheSnapshotChain(snapshot, snapshot.getDataStore().getScope());
        }

        EndPoint ep = null;
        if (srcData.getDataStore().getRole() == DataStoreRole.Primary) {
            ep = selector.select(destData);
View Full Code Here

        String value = configDao.getValue(Config.BackupSnapshotWait.toString());
        int _backupsnapshotwait = NumbersUtil.parseInt(value,
                Integer.parseInt(Config.BackupSnapshotWait.getDefaultValue()));

        DataObject cacheData = null;
        SnapshotInfo snapshotInfo = (SnapshotInfo)srcData;
        Object payload = snapshotInfo.getPayload();
        Boolean fullSnapshot = true;
        if (payload != null) {
            fullSnapshot = (Boolean)payload;
        }
        Map<String, String> options = new HashMap<String, String>();
View Full Code Here

        return snapshot;
    }

    @Override
    public Snapshot backupSnapshot(Long snapshotId) {
        SnapshotInfo snapshot = snapshotFactory.getSnapshot(snapshotId, DataStoreRole.Image);
        if (snapshot != null) {
            throw new CloudRuntimeException("Already in the backup snapshot:" + snapshotId);
        }

        return snapshotSrv.backupSnapshot(snapshot);
View Full Code Here

    @DB
    public SnapshotInfo takeSnapshot(VolumeInfo volume) throws ResourceAllocationException {
        CreateSnapshotPayload payload = (CreateSnapshotPayload)volume.getpayload();
        Long snapshotId = payload.getSnapshotId();
        Account snapshotOwner = payload.getAccount();
        SnapshotInfo snapshot = snapshotFactory.getSnapshot(snapshotId, volume.getDataStore());
        snapshot.addPayload(payload);
        try {
            SnapshotStrategy snapshotStrategy = _storageStrategyFactory.getSnapshotStrategy(snapshot, SnapshotOperation.TAKE);

            if (snapshotStrategy == null) {
                throw new CloudRuntimeException("Can't find snapshot strategy to deal with snapshot:" + snapshotId);
            }

            snapshotStrategy.takeSnapshot(snapshot);

            try {
                postCreateSnapshot(volume.getId(), snapshotId, payload.getSnapshotPolicyId());

                UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_CREATE, snapshot.getAccountId(),
                        snapshot.getDataCenterId(), snapshotId, snapshot.getName(), null, null,
                        volume.getSize(), snapshot.getClass().getName(), snapshot.getUuid());
                SnapshotDataStoreVO snapshotStoreRef = _snapshotStoreDao.findBySnapshot(snapshotId, DataStoreRole.Image);
                // Correct the resource count of snapshot in case of delta snapshots.
                _resourceLimitMgr.decrementResourceCount(snapshotOwner.getId(), ResourceType.secondary_storage, new Long(volume.getSize() - snapshotStoreRef.getSize()));
            } catch (Exception e) {
                s_logger.debug("post process snapshot failed", e);
View Full Code Here

        if (dataStore.getRole() == DataStoreRole.Primary) {
            if (obj.getType() == DataObjectType.TEMPLATE) {
                VMTemplateStoragePoolVO vo = new VMTemplateStoragePoolVO(dataStore.getId(), obj.getId());
                vo = templatePoolDao.persist(vo);
            } else if (obj.getType() == DataObjectType.SNAPSHOT) {
                SnapshotInfo snapshotInfo = (SnapshotInfo)obj;
                SnapshotDataStoreVO ss = new SnapshotDataStoreVO();
                ss.setSnapshotId(obj.getId());
                ss.setDataStoreId(dataStore.getId());
                ss.setRole(dataStore.getRole());
                ss.setVolumeId(snapshotInfo.getVolumeId());
                ss.setSize(snapshotInfo.getSize()); // this is the virtual size of snapshot in primary storage.
                SnapshotDataStoreVO snapshotDataStoreVO = snapshotDataStoreDao.findParent(dataStore.getRole(), dataStore.getId(),snapshotInfo.getVolumeId());
                if (snapshotDataStoreVO != null) {
                    ss.setParentSnapshotId(snapshotDataStoreVO.getSnapshotId());
                }
                ss.setState(ObjectInDataStoreStateMachine.State.Allocated);
                ss = snapshotDataStoreDao.persist(ss);
            }
        } else {
            // Image store
            switch (obj.getType()) {
            case TEMPLATE:
                TemplateDataStoreVO ts = new TemplateDataStoreVO();
                ts.setTemplateId(obj.getId());
                ts.setDataStoreId(dataStore.getId());
                ts.setDataStoreRole(dataStore.getRole());
                String installPath = TemplateConstants.DEFAULT_TMPLT_ROOT_DIR + "/"
                        + TemplateConstants.DEFAULT_TMPLT_FIRST_LEVEL_DIR
                        + templateDao.findById(obj.getId()).getAccountId() + "/" + obj.getId();
                if (dataStore.getTO() instanceof S3TO) {
                    TemplateInfo tmpl = (TemplateInfo) obj;
                    installPath += "/" + tmpl.getUniqueName(); // for S3, we
                    // append
                    // template name
                    // in the path
                    // for template
                    // sync since we
                    // don't have
                    // template.properties
                    // there
                }
                ts.setInstallPath(installPath);
                ts.setState(ObjectInDataStoreStateMachine.State.Allocated);
                ts = templateDataStoreDao.persist(ts);
                break;
            case SNAPSHOT:
                SnapshotInfo snapshot = (SnapshotInfo) obj;
                SnapshotDataStoreVO ss = new SnapshotDataStoreVO();
                ss.setSnapshotId(obj.getId());
                ss.setDataStoreId(dataStore.getId());
                ss.setRole(dataStore.getRole());
                ss.setRole(dataStore.getRole());
                ss.setVolumeId(snapshot.getVolumeId());
                SnapshotDataStoreVO snapshotDataStoreVO = snapshotDataStoreDao.findParent(dataStore.getRole(), dataStore.getId(),snapshot.getVolumeId());
                if (snapshotDataStoreVO != null) {
                    ss.setParentSnapshotId(snapshotDataStoreVO.getSnapshotId());
                }
                ss.setInstallPath(TemplateConstants.DEFAULT_SNAPSHOT_ROOT_DIR + "/"
                        + snapshotDao.findById(obj.getId()).getAccountId() + "/" + snapshot.getVolumeId());
                ss.setState(ObjectInDataStoreStateMachine.State.Allocated);
                ss = snapshotDataStoreDao.persist(ss);
                break;
            case VOLUME:
                VolumeDataStoreVO vs = new VolumeDataStoreVO();
View Full Code Here

                    List<SnapshotDataStoreVO> destroyedSnapshotStoreVOs = _snapshotStoreDao.listDestroyed(store.getId());
                    s_logger.debug("Secondary storage garbage collector found " + destroyedSnapshotStoreVOs.size()
                            + " snapshots to cleanup on snapshot_store_ref for store: " + store.getName());
                    for (SnapshotDataStoreVO destroyedSnapshotStoreVO : destroyedSnapshotStoreVOs) {
                        // check if this snapshot has child
                        SnapshotInfo snap = snapshotFactory.getSnapshot(destroyedSnapshotStoreVO.getSnapshotId(), store);
                        if ( snap.getChild() != null ){
                            s_logger.debug("Skip snapshot on store: " + destroyedSnapshotStoreVO + " , because it has child");
                            continue;
                        }

                        if (s_logger.isDebugEnabled()) {
View Full Code Here

            if (store == null) {
                throw new CloudRuntimeException("cannot find an image store for zone " + zoneId);
            }
            AsyncCallFuture<TemplateApiResult> future = null;
            if (snapshotId != null) {
                SnapshotInfo snapInfo = _snapshotFactory.getSnapshot(snapshotId, DataStoreRole.Image);
                DataStore snapStore = snapInfo.getDataStore();
                if (snapStore != null) {
                    store = snapStore; // pick snapshot image store to create template
                }
                future = _tmpltSvr.createTemplateFromSnapshotAsync(snapInfo, tmplInfo, store);
            } else if (volumeId != null) {
View Full Code Here

            throw new StorageUnavailableException(msg, -1);
        }

        VolumeInfo vol = volFactory.getVolume(volume.getId());
        DataStore store = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
        SnapshotInfo snapInfo = snapshotFactory.getSnapshot(snapshot.getId(), DataStoreRole.Image);
        // sync snapshot to region store if necessary
        DataStore snapStore = snapInfo.getDataStore();
        long snapVolId = snapInfo.getVolumeId();
        try {
            _snapshotSrv.syncVolumeSnapshotsToRegionStore(snapVolId, snapStore);
        } catch (Exception ex) {
            // log but ignore the sync error to avoid any potential S3 down issue, it should be sync next time
            s_logger.warn(ex.getMessage(), ex);
View Full Code Here

TOP

Related Classes of org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.