Search in sources :

Example 1 with CreateObjectAnswer

use of com.cloud.legacymodel.communication.answer.CreateObjectAnswer in project cosmic by MissionCriticalCloud.

the class SnapshotObject method processEvent.

@Override
public void processEvent(final ObjectInDataStoreStateMachine.Event event, final Answer answer) {
    try {
        final SnapshotDataStoreVO snapshotStore = snapshotStoreDao.findByStoreSnapshot(getDataStore().getRole(), getDataStore().getId(), getId());
        if (answer instanceof CreateObjectAnswer) {
            final SnapshotObjectTO snapshotTO = (SnapshotObjectTO) ((CreateObjectAnswer) answer).getData();
            snapshotStore.setInstallPath(snapshotTO.getPath());
            snapshotStoreDao.update(snapshotStore.getId(), snapshotStore);
        } else if (answer instanceof CopyCmdAnswer) {
            final SnapshotObjectTO snapshotTO = (SnapshotObjectTO) ((CopyCmdAnswer) answer).getNewData();
            snapshotStore.setInstallPath(snapshotTO.getPath());
            if (snapshotTO.getPhysicalSize() != null) {
                // For S3 delta snapshot, physical size is currently not set
                snapshotStore.setPhysicalSize(snapshotTO.getPhysicalSize());
            }
            if (snapshotTO.getParentSnapshotPath() == null) {
                snapshotStore.setParentSnapshotId(0L);
            }
            snapshotStoreDao.update(snapshotStore.getId(), snapshotStore);
            // update side-effect of snapshot operation
            if (snapshotTO.getVolume() != null && snapshotTO.getVolume().getPath() != null) {
                final VolumeVO vol = volumeDao.findByUuid(snapshotTO.getVolume().getUuid());
                if (vol != null) {
                    s_logger.info("Update volume path change due to snapshot operation, volume " + vol.getId() + " path: " + vol.getPath() + "->" + snapshotTO.getVolume().getPath());
                    vol.setPath(snapshotTO.getVolume().getPath());
                    volumeDao.update(vol.getId(), vol);
                } else {
                    s_logger.error("Cound't find the original volume with uuid: " + snapshotTO.getVolume().getUuid());
                }
            }
        } else {
            throw new CloudRuntimeException("Unknown answer: " + answer.getClass());
        }
    } catch (final RuntimeException ex) {
        if (event == ObjectInDataStoreStateMachine.Event.OperationFailed) {
            objectInStoreMgr.deleteIfNotReady(this);
        }
        throw ex;
    }
    this.processEvent(event);
}
Also used : SnapshotObjectTO(com.cloud.legacymodel.to.SnapshotObjectTO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO) CreateObjectAnswer(com.cloud.legacymodel.communication.answer.CreateObjectAnswer) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer)

Example 2 with CreateObjectAnswer

use of com.cloud.legacymodel.communication.answer.CreateObjectAnswer in project cosmic by MissionCriticalCloud.

the class VolumeObject method processEvent.

@Override
public void processEvent(final ObjectInDataStoreStateMachine.Event event, final Answer answer) {
    try {
        if (dataStore.getRole() == DataStoreRole.Primary) {
            if (answer instanceof CopyCmdAnswer) {
                final CopyCmdAnswer cpyAnswer = (CopyCmdAnswer) answer;
                final VolumeVO vol = volumeDao.findById(getId());
                final VolumeObjectTO newVol = (VolumeObjectTO) cpyAnswer.getNewData();
                vol.setPath(newVol.getPath());
                if (newVol.getSize() != null) {
                    vol.setSize(newVol.getSize());
                }
                if (newVol.getFormat() != null) {
                    vol.setFormat(newVol.getFormat());
                }
                vol.setPoolId(getDataStore().getId());
                volumeDao.update(vol.getId(), vol);
            } else if (answer instanceof CreateObjectAnswer) {
                final CreateObjectAnswer createAnswer = (CreateObjectAnswer) answer;
                final VolumeObjectTO newVol = (VolumeObjectTO) createAnswer.getData();
                final VolumeVO vol = volumeDao.findById(getId());
                vol.setPath(newVol.getPath());
                if (newVol.getSize() != null) {
                    vol.setSize(newVol.getSize());
                }
                vol.setPoolId(getDataStore().getId());
                if (newVol.getFormat() != null) {
                    vol.setFormat(newVol.getFormat());
                }
                volumeDao.update(vol.getId(), vol);
            }
        } else {
            processDownloadAnswer(answer);
        }
    } catch (final RuntimeException ex) {
        if (event == ObjectInDataStoreStateMachine.Event.OperationFailed) {
            objectInStoreMgr.deleteIfNotReady(this);
        }
        throw ex;
    }
    this.processEvent(event);
}
Also used : CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) VolumeVO(com.cloud.storage.VolumeVO) CreateObjectAnswer(com.cloud.legacymodel.communication.answer.CreateObjectAnswer) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer)

Example 3 with CreateObjectAnswer

use of com.cloud.legacymodel.communication.answer.CreateObjectAnswer in project cosmic by MissionCriticalCloud.

the class KvmStorageProcessor method createVolume.

@Override
public Answer createVolume(final CreateObjectCommand cmd) {
    final VolumeObjectTO volume = (VolumeObjectTO) cmd.getData();
    final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) volume.getDataStore();
    final KvmStoragePool primaryPool;
    final KvmPhysicalDisk vol;
    final long disksize;
    try {
        primaryPool = this.storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid());
        disksize = volume.getSize();
        final PhysicalDiskFormat format;
        if (volume.getFormat() == null) {
            format = primaryPool.getDefaultFormat();
        } else {
            format = PhysicalDiskFormat.valueOf(volume.getFormat().toString().toUpperCase());
        }
        vol = primaryPool.createPhysicalDisk(volume.getUuid(), format, volume.getProvisioningType(), disksize);
        final VolumeObjectTO newVol = new VolumeObjectTO();
        if (vol != null) {
            newVol.setPath(vol.getName());
        }
        newVol.setSize(volume.getSize());
        newVol.setFormat(ImageFormat.valueOf(format.toString().toUpperCase()));
        return new CreateObjectAnswer(newVol);
    } catch (final Exception e) {
        this.logger.debug("Failed to create volume: ", e);
        return new CreateObjectAnswer(e.toString());
    }
}
Also used : PrimaryDataStoreTO(com.cloud.legacymodel.to.PrimaryDataStoreTO) CreateObjectAnswer(com.cloud.legacymodel.communication.answer.CreateObjectAnswer) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO) LibvirtException(org.libvirt.LibvirtException) QemuImgException(com.cloud.agent.resource.kvm.storage.utils.QemuImgException) FileNotFoundException(java.io.FileNotFoundException) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) IOException(java.io.IOException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) PhysicalDiskFormat(com.cloud.model.enumeration.PhysicalDiskFormat)

Example 4 with CreateObjectAnswer

use of com.cloud.legacymodel.communication.answer.CreateObjectAnswer in project cosmic by MissionCriticalCloud.

the class XenServerStorageProcessor method createVolume.

@Override
public Answer createVolume(final CreateObjectCommand cmd) {
    final DataTO data = cmd.getData();
    final VolumeObjectTO volume = (VolumeObjectTO) data;
    try {
        final Connection conn = hypervisorResource.getConnection();
        final SR poolSr = hypervisorResource.getStorageRepository(conn, data.getDataStore().getUuid());
        VDI.Record vdir = new VDI.Record();
        vdir.nameLabel = volume.getName();
        vdir.SR = poolSr;
        vdir.type = Types.VdiType.USER;
        vdir.virtualSize = volume.getSize();
        final VDI vdi;
        vdi = VDI.create(conn, vdir);
        vdir = vdi.getRecord(conn);
        final VolumeObjectTO newVol = new VolumeObjectTO();
        newVol.setName(vdir.nameLabel);
        newVol.setSize(vdir.virtualSize);
        newVol.setPath(vdir.uuid);
        return new CreateObjectAnswer(newVol);
    } catch (final Exception e) {
        s_logger.debug("create volume failed: " + e.toString());
        return new CreateObjectAnswer(e.toString());
    }
}
Also used : DataTO(com.cloud.legacymodel.to.DataTO) Connection(com.xensource.xenapi.Connection) CreateObjectAnswer(com.cloud.legacymodel.communication.answer.CreateObjectAnswer) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO) VDI(com.xensource.xenapi.VDI) XenAPIException(com.xensource.xenapi.Types.XenAPIException) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) SR(com.xensource.xenapi.SR)

Example 5 with CreateObjectAnswer

use of com.cloud.legacymodel.communication.answer.CreateObjectAnswer in project cosmic by MissionCriticalCloud.

the class XenserverSnapshotStrategy method backupSnapshot.

@Override
public SnapshotInfo backupSnapshot(final SnapshotInfo snapshot) {
    final SnapshotInfo parentSnapshot = snapshot.getParent();
    if (parentSnapshot != null && snapshot.getPath().equalsIgnoreCase(parentSnapshot.getPath())) {
        s_logger.debug("backup an empty snapshot");
        // don't need to backup this snapshot
        final SnapshotDataStoreVO parentSnapshotOnBackupStore = snapshotStoreDao.findBySnapshot(parentSnapshot.getId(), DataStoreRole.Image);
        if (parentSnapshotOnBackupStore != null && parentSnapshotOnBackupStore.getState() == State.Ready) {
            final DataStore store = dataStoreMgr.getDataStore(parentSnapshotOnBackupStore.getDataStoreId(), parentSnapshotOnBackupStore.getRole());
            final SnapshotInfo snapshotOnImageStore = (SnapshotInfo) store.create(snapshot);
            snapshotOnImageStore.processEvent(Event.CreateOnlyRequested);
            final SnapshotObjectTO snapTO = new SnapshotObjectTO();
            snapTO.setPath(parentSnapshotOnBackupStore.getInstallPath());
            final CreateObjectAnswer createSnapshotAnswer = new CreateObjectAnswer(snapTO);
            snapshotOnImageStore.processEvent(Event.OperationSuccessed, createSnapshotAnswer);
            final SnapshotObject snapObj = (SnapshotObject) snapshot;
            try {
                snapObj.processEvent(Snapshot.Event.OperationNotPerformed);
            } catch (final NoTransitionException e) {
                s_logger.debug("Failed to change state: " + snapshot.getId() + ": " + e.toString());
                throw new CloudRuntimeException(e.toString());
            }
            return snapshotDataFactory.getSnapshot(snapObj.getId(), store);
        } else {
            s_logger.debug("parent snapshot hasn't been backed up yet");
        }
    }
    // determine full snapshot backup or not
    boolean fullBackup = true;
    SnapshotDataStoreVO parentSnapshotOnBackupStore = snapshotStoreDao.findLatestSnapshotForVolume(snapshot.getVolumeId(), DataStoreRole.Image);
    final SnapshotDataStoreVO parentSnapshotOnPrimaryStore = snapshotStoreDao.findLatestSnapshotForVolume(snapshot.getVolumeId(), DataStoreRole.Primary);
    final HypervisorType hypervisorType = snapshot.getBaseVolume().getHypervisorType();
    if (parentSnapshotOnPrimaryStore != null && parentSnapshotOnBackupStore != null && hypervisorType == HypervisorType.XenServer) {
        // CS does incremental backup
        // only for XenServer
        // In case of volume migration from one pool to other pool, CS should take full snapshot to avoid any issues with delta chain,
        // to check if this is a migrated volume, compare the current pool id of volume and store_id of oldest snapshot on primary for this volume.
        // Why oldest? Because at this point CS has two snapshot on primary entries for same volume, one with old pool_id and other one with
        // current pool id. So, verify and if volume found to be migrated, delete snapshot entry with previous pool store_id.
        final SnapshotDataStoreVO oldestSnapshotOnPrimary = snapshotStoreDao.findOldestSnapshotForVolume(snapshot.getVolumeId(), DataStoreRole.Primary);
        final VolumeVO volume = volumeDao.findById(snapshot.getVolumeId());
        if (oldestSnapshotOnPrimary != null) {
            if (oldestSnapshotOnPrimary.getDataStoreId() == volume.getPoolId()) {
                final int _deltaSnapshotMax = NumbersUtil.parseInt(configDao.getValue("snapshot.delta.max"), SnapshotManager.DELTAMAX);
                final int deltaSnap = _deltaSnapshotMax;
                int i;
                for (i = 1; i < deltaSnap; i++) {
                    final Long prevBackupId = parentSnapshotOnBackupStore.getParentSnapshotId();
                    if (prevBackupId == 0) {
                        break;
                    }
                    parentSnapshotOnBackupStore = snapshotStoreDao.findBySnapshot(prevBackupId, DataStoreRole.Image);
                    if (parentSnapshotOnBackupStore == null) {
                        break;
                    }
                }
                if (i >= deltaSnap) {
                    fullBackup = true;
                } else {
                    fullBackup = false;
                }
            } else {
                // if there is an snapshot entry for previousPool(primary storage) of migrated volume, delete it becasue CS created one more snapshot entry for current pool
                snapshotStoreDao.remove(oldestSnapshotOnPrimary.getId());
            }
        }
    }
    snapshot.addPayload(fullBackup);
    return snapshotSvr.backupSnapshot(snapshot);
}
Also used : SnapshotObjectTO(com.cloud.legacymodel.to.SnapshotObjectTO) SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO) CreateObjectAnswer(com.cloud.legacymodel.communication.answer.CreateObjectAnswer) HypervisorType(com.cloud.model.enumeration.HypervisorType) SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException)

Aggregations

CreateObjectAnswer (com.cloud.legacymodel.communication.answer.CreateObjectAnswer)8 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)8 VolumeObjectTO (com.cloud.legacymodel.to.VolumeObjectTO)5 InternalErrorException (com.cloud.legacymodel.exceptions.InternalErrorException)4 SnapshotObjectTO (com.cloud.legacymodel.to.SnapshotObjectTO)4 VolumeVO (com.cloud.storage.VolumeVO)4 CopyCmdAnswer (com.cloud.legacymodel.communication.answer.CopyCmdAnswer)3 QemuImgException (com.cloud.agent.resource.kvm.storage.utils.QemuImgException)2 PrimaryDataStoreTO (com.cloud.legacymodel.to.PrimaryDataStoreTO)2 SnapshotDataStoreVO (com.cloud.storage.datastore.db.SnapshotDataStoreVO)2 Connection (com.xensource.xenapi.Connection)2 SR (com.xensource.xenapi.SR)2 XenAPIException (com.xensource.xenapi.Types.XenAPIException)2 VDI (com.xensource.xenapi.VDI)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 ConfigurationException (javax.naming.ConfigurationException)2 XmlRpcException (org.apache.xmlrpc.XmlRpcException)2 LibvirtException (org.libvirt.LibvirtException)2 IoCTX (com.ceph.rados.IoCTX)1