Examples of CopyVolumeAnswer


Examples of com.cloud.agent.api.storage.CopyVolumeAnswer

                secondaryStoragePool = _storagePoolMgr
                        .getStoragePoolByURI(secondaryStorageUrl
                                + volumeDestPath);
                _storagePoolMgr.copyPhysicalDisk(volume, destVolumeName,
                        secondaryStoragePool);
                return new CopyVolumeAnswer(cmd, true, null, null, volumeName);
            } else {
                volumePath = "/volumes/" + cmd.getVolumeId() + File.separator;
                secondaryStoragePool = _storagePoolMgr
                        .getStoragePoolByURI(secondaryStorageUrl + volumePath);
                KVMPhysicalDisk volume = secondaryStoragePool
                        .getPhysicalDisk(cmd.getVolumePath() + ".qcow2");
                _storagePoolMgr.copyPhysicalDisk(volume, volumeName,
                        primaryPool);
                return new CopyVolumeAnswer(cmd, true, null, null, volumeName);
            }
        } catch (CloudRuntimeException e) {
            return new CopyVolumeAnswer(cmd, false, e.toString(), null, null);
        } finally {
            if (secondaryStoragePool != null) {
                secondaryStoragePool.delete();
            }
        }
View Full Code Here

Examples of com.cloud.agent.api.storage.CopyVolumeAnswer

      String secondaryStorageURL = secStorage.getStorageUrl();
      String[] volumePath = volumeHostVO.getInstallPath().split("/");
      String volumeUUID = volumePath[volumePath.length - 1].split("\\.")[0];
     
        CopyVolumeCommand cvCmd = new CopyVolumeCommand(volume.getId(), volumeUUID, destPool, secondaryStorageURL, false, _copyvolumewait);
        CopyVolumeAnswer cvAnswer;
    try {
            cvAnswer = (CopyVolumeAnswer) sendToPool(destPool, cvCmd);
        } catch (StorageUnavailableException e1) {
          stateTransitTo(volume, Event.CopyFailed);
            throw new CloudRuntimeException("Failed to copy the volume from secondary storage to the destination primary storage pool.");
        }

        if (cvAnswer == null || !cvAnswer.getResult()) {
          stateTransitTo(volume, Event.CopyFailed);
            throw new CloudRuntimeException("Failed to copy the volume from secondary storage to the destination primary storage pool.");
        }       
        Transaction txn = Transaction.currentTxn();
        txn.start();       
        volume.setPath(cvAnswer.getVolumePath());
        volume.setFolder(destPool.getPath());
        volume.setPodId(destPool.getPodId());
        volume.setPoolId(destPool.getId());       
        volume.setPodId(destPool.getPodId());
        stateTransitTo(volume, Event.CopySucceeded);
View Full Code Here

Examples of com.cloud.agent.api.storage.CopyVolumeAnswer

        try {
            for (Volume volume : volumes) {
                String secondaryStorageURL = getSecondaryStorageURL(volume.getDataCenterId());
                StoragePoolVO srcPool = _storagePoolDao.findById(volume.getPoolId());
                CopyVolumeCommand cvCmd = new CopyVolumeCommand(volume.getId(), volume.getPath(), srcPool, secondaryStorageURL, true, _copyvolumewait);
                CopyVolumeAnswer cvAnswer;
                try {
                    cvAnswer = (CopyVolumeAnswer) sendToPool(srcPool, cvCmd);
                } catch (StorageUnavailableException e1) {
                    throw new CloudRuntimeException("Failed to copy the volume from the source primary storage pool to secondary storage.", e1);
                }

                if (cvAnswer == null || !cvAnswer.getResult()) {
                    throw new CloudRuntimeException("Failed to copy the volume from the source primary storage pool to secondary storage.");
                }

                String secondaryStorageVolumePath = cvAnswer.getVolumePath();

                // Copy the volume from secondary storage to the destination storage
                // pool
                cvCmd = new CopyVolumeCommand(volume.getId(), secondaryStorageVolumePath, destPool, secondaryStorageURL, false, _copyvolumewait);
                try {
                    cvAnswer = (CopyVolumeAnswer) sendToPool(destPool, cvCmd);
                } catch (StorageUnavailableException e1) {
                    throw new CloudRuntimeException("Failed to copy the volume from secondary storage to the destination primary storage pool.");
                }

                if (cvAnswer == null || !cvAnswer.getResult()) {
                    throw new CloudRuntimeException("Failed to copy the volume from secondary storage to the destination primary storage pool.");
                }

                answers.add(cvAnswer);
                destroyCmds.add(new Pair<StoragePoolVO, DestroyCommand>(srcPool, new DestroyCommand(srcPool, volume, null)));
            }
        } finally {
            if (answers.size() != volumes.size()) {
                // this means one of copying volume failed
                for (Volume volume : volumes) {
                    try {
                        stateTransitTo(volume, Volume.Event.OperationFailed);
                    } catch (NoTransitionException e) {
                        s_logger.debug("Failed to change volume state: " + e.toString());
                    }
                }
                _checkPointMgr.popCheckPoint(checkPointTaskId);
            } else {
                // Need a transaction, make sure all the volumes get migrated to new storage pool
                txn = Transaction.currentTxn();
                txn.start();

                transitResult = false;
                try {
                    for (int i = 0; i < volumes.size(); i++) {
                        CopyVolumeAnswer answer = answers.get(i);
                        VolumeVO volume = (VolumeVO) volumes.get(i);
                        Long oldPoolId = volume.getPoolId();
                        volume.setPath(answer.getVolumePath());
                        volume.setFolder(destPool.getPath());
                        volume.setPodId(destPool.getPodId());
                        volume.setPoolId(destPool.getId());
                        volume.setLastPoolId(oldPoolId);
                        volume.setPodId(destPool.getPodId());
View Full Code Here

Examples of com.cloud.agent.api.storage.CopyVolumeAnswer

                invalidateServiceContext();
            }

            String msg = "CopyVolumeCommand failed due to " + VmwareHelper.getExceptionMessage(e);
            s_logger.error(msg, e);
            return new CopyVolumeAnswer(cmd, false, msg, null, null);
        }
    }
View Full Code Here

Examples of com.cloud.agent.api.storage.CopyVolumeAnswer

                    // Look up the volume on the source primary storage pool
                    VDI srcVolume = getVDIbyUuid(conn, volumeUUID);
                    // Copy the volume to secondary storage
                    VDI destVolume = cloudVDIcopy(conn, srcVolume, secondaryStorage, wait);
                    String destVolumeUUID = destVolume.getUuid(conn);
                    return new CopyVolumeAnswer(cmd, true, null, null, destVolumeUUID);
                } finally {
                    removeSR(conn, secondaryStorage);
                }
            } else {
                try {
                    String volumePath = mountpoint + "/" + volumeUUID + ".vhd";
                    String uuid = copy_vhd_from_secondarystorage(conn, volumePath, srUuid, wait );
                    return new CopyVolumeAnswer(cmd, true, null, srUuid, uuid);
                } finally {
                    deleteSecondaryStorageFolder(conn, remoteVolumesMountPath, volumeFolder);
                }
            }
        } catch (Exception e) {
            String msg = "Catch Exception " + e.getClass().getName() + " due to " + e.toString();
            s_logger.warn(msg, e);
            return new CopyVolumeAnswer(cmd, false, msg, null, null);
        }
    }
View Full Code Here

Examples of com.cloud.agent.api.storage.CopyVolumeAnswer

                invalidateServiceContext();
            }

            String msg = "CopyVolumeCommand failed due to " + VmwareHelper.getExceptionMessage(e);
            s_logger.error(msg, e);
            return new CopyVolumeAnswer(cmd, false, msg, null, null);
        }
    }
View Full Code Here

Examples of com.cloud.agent.api.storage.CopyVolumeAnswer

        String secStorageMountPath = uri.getHost() + ":" + uri.getPath();
        String volumeFolderOnSecStorage = "volumes/" + String.valueOf(cmd.getVolumeId());
        String storagePoolUuid = cmd.getPool().getUuid();
        Boolean toSec = cmd.toSecondaryStorage();
        String res = OvmStoragePool.copyVolume(_conn, secStorageMountPath, volumeFolderOnSecStorage, volumePath, storagePoolUuid, toSec, wait);
        return new CopyVolumeAnswer(cmd, true, null, null, res);
      } catch (Exception e) {
        s_logger.debug("Copy volume failed", e);
        return new CopyVolumeAnswer(cmd, false, e.getMessage(), null, null);
      }
  }
View Full Code Here

Examples of com.cloud.agent.api.storage.CopyVolumeAnswer

                    primaryPool = _storagePoolMgr.createStoragePool(cmd.getPool().getUuid(),
                                      cmd.getPool().getHost(), cmd.getPool().getPort(),
                                      cmd.getPool().getPath(), cmd.getPool().getUserInfo(),
                                      cmd.getPool().getType());
                } else {
                    return new CopyVolumeAnswer(cmd, false, e.getMessage(), null, null);
                }
            }

            String volumeName = UUID.randomUUID().toString();

            if (copyToSecondary) {
                String destVolumeName = volumeName + ".qcow2";
                KVMPhysicalDisk volume = primaryPool.getPhysicalDisk(cmd
                        .getVolumePath());
                String volumeDestPath = "/volumes/" + cmd.getVolumeId()
                        + File.separator;
                secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI(
                        secondaryStorageUrl);
                secondaryStoragePool.createFolder(volumeDestPath);
                _storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(),secondaryStoragePool.getUuid());
                secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI(
                        secondaryStorageUrl
                        + volumeDestPath);
                _storagePoolMgr.copyPhysicalDisk(volume,
                        destVolumeName,secondaryStoragePool);
                return new CopyVolumeAnswer(cmd, true, null, null, volumeName);
            } else {
                volumePath = "/volumes/" + cmd.getVolumeId() + File.separator;
                secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI(
                        secondaryStorageUrl
                        + volumePath);
                KVMPhysicalDisk volume = secondaryStoragePool
                        .getPhysicalDisk(cmd.getVolumePath() + ".qcow2");
                _storagePoolMgr.copyPhysicalDisk(volume, volumeName,
                        primaryPool);
                return new CopyVolumeAnswer(cmd, true, null, null, volumeName);
            }
        } catch (CloudRuntimeException e) {
            return new CopyVolumeAnswer(cmd, false, e.toString(), null, null);
        } finally {
            if (secondaryStoragePool != null) {
                _storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(),secondaryStoragePool.getUuid());
            }
        }
View Full Code Here

Examples of com.cloud.agent.api.storage.CopyVolumeAnswer

        MockStoragePoolVO primaryStorage = null;
        try {
            txn.start();
            sec = _mockSecStorageDao.findByUrl(cmd.getSecondaryStorageURL());
            if (sec == null) {
                return new CopyVolumeAnswer(cmd, false, "can't find secondary storage", null, null);
            }
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Encountered " + ex.getMessage() + " when accessing secondary at "
                    + cmd.getSecondaryStorageURL(), ex);
        } finally {
            txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
        }

        txn = Transaction.open(Transaction.SIMULATOR_DB);
        try {
            txn.start();
            primaryStorage = _mockStoragePoolDao.findByUuid(cmd.getPool().getUuid());
            if (primaryStorage == null) {
                return new CopyVolumeAnswer(cmd, false, "Can't find primary storage", null, null);
            }
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Encountered " + ex.getMessage() + " when accessing primary at "
                    + cmd.getPool(), ex);
        } finally {
            txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
        }

        MockVolumeVO volume = null;
        txn = Transaction.open(Transaction.SIMULATOR_DB);
        try {
            txn.start();
            volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath());
            if (volume == null) {
                return new CopyVolumeAnswer(cmd, false, "cant' find volume" + cmd.getVolumePath(), null, null);
            }
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Encountered " + ex.getMessage() + " when accessing volume at "
                    + cmd.getVolumePath(), ex);
        } finally {
            txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
        }

        String name = UUID.randomUUID().toString();
        if (toSecondaryStorage) {
            MockVolumeVO vol = new MockVolumeVO();
            vol.setName(name);
            vol.setPath(sec.getMountPoint() + name);
            vol.setPoolId(sec.getId());
            vol.setSize(volume.getSize());
            vol.setStatus(Status.DOWNLOADED);
            vol.setType(MockVolumeType.VOLUME);
            txn = Transaction.open(Transaction.SIMULATOR_DB);
            try {
                txn.start();
                vol = _mockVolumeDao.persist(vol);
                txn.commit();
            } catch (Exception ex) {
                txn.rollback();
                throw new CloudRuntimeException("Encountered " + ex.getMessage() + " when persisting volume "
                        + vol.getName(), ex);
            } finally {
                txn.close();
                txn = Transaction.open(Transaction.CLOUD_DB);
                txn.close();
            }
            return new CopyVolumeAnswer(cmd, true, null, sec.getMountPoint(), vol.getPath());
        } else {
            MockVolumeVO vol = new MockVolumeVO();
            vol.setName(name);
            vol.setPath(primaryStorage.getMountPoint() + name);
            vol.setPoolId(primaryStorage.getId());
            vol.setSize(volume.getSize());
            vol.setStatus(Status.DOWNLOADED);
            vol.setType(MockVolumeType.VOLUME);
            txn = Transaction.open(Transaction.SIMULATOR_DB);
            try {
                txn.start();
                vol = _mockVolumeDao.persist(vol);
                txn.commit();
            } catch (Exception ex) {
                txn.rollback();
                throw new CloudRuntimeException("Encountered " + ex.getMessage() + " when persisting volume "
                        + vol.getName(), ex);
            } finally {
                txn.close();
                txn = Transaction.open(Transaction.CLOUD_DB);
                txn.close();
            }
            return new CopyVolumeAnswer(cmd, true, null, primaryStorage.getMountPoint(), vol.getPath());
        }
    }
View Full Code Here

Examples of com.cloud.agent.api.storage.CopyVolumeAnswer

                    primaryPool = _storagePoolMgr.createStoragePool(cmd.getPool().getUuid(),
                                      cmd.getPool().getHost(), cmd.getPool().getPort(),
                                      cmd.getPool().getPath(), cmd.getPool().getUserInfo(),
                                      cmd.getPool().getType());
                } else {
                    return new CopyVolumeAnswer(cmd, false, e.getMessage(), null, null);
                }
            }

            String volumeName = UUID.randomUUID().toString();

            if (copyToSecondary) {
                String destVolumeName = volumeName + ".qcow2";
                KVMPhysicalDisk volume = primaryPool.getPhysicalDisk(cmd
                        .getVolumePath());
                String volumeDestPath = "/volumes/" + cmd.getVolumeId()
                        + File.separator;
                secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI(
                        secondaryStorageUrl);
                secondaryStoragePool.createFolder(volumeDestPath);
                _storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(),secondaryStoragePool.getUuid());
                secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI(
                        secondaryStorageUrl
                        + volumeDestPath);
                _storagePoolMgr.copyPhysicalDisk(volume,
                        destVolumeName,secondaryStoragePool, 0);
                return new CopyVolumeAnswer(cmd, true, null, null, volumeName);
            } else {
                volumePath = "/volumes/" + cmd.getVolumeId() + File.separator;
                secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI(
                        secondaryStorageUrl
                        + volumePath);
                KVMPhysicalDisk volume = secondaryStoragePool
                        .getPhysicalDisk(cmd.getVolumePath() + ".qcow2");
                _storagePoolMgr.copyPhysicalDisk(volume, volumeName,
                        primaryPool, 0);
                return new CopyVolumeAnswer(cmd, true, null, null, volumeName);
            }
        } catch (CloudRuntimeException e) {
            return new CopyVolumeAnswer(cmd, false, e.toString(), null, null);
        } finally {
            if (secondaryStoragePool != null) {
                _storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(),secondaryStoragePool.getUuid());
            }
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.