Search in sources :

Example 1 with PrimaryStorageDownloadAnswer

use of com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer in project cloudstack by apache.

the class OvmResourceBase method execute.

protected PrimaryStorageDownloadAnswer execute(final PrimaryStorageDownloadCommand cmd) {
    try {
        URI uri = new URI(cmd.getUrl());
        String secondaryStoragePath = uri.getHost() + ":" + uri.getPath();
        Pair<String, Long> res = OvmStoragePool.downloadTemplate(_conn, cmd.getPoolUuid(), secondaryStoragePath);
        return new PrimaryStorageDownloadAnswer(res.first(), res.second());
    } catch (Exception e) {
        s_logger.debug("PrimaryStorageDownloadCommand failed", e);
        return new PrimaryStorageDownloadAnswer(e.getMessage());
    }
}
Also used : PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) URI(java.net.URI) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ConfigurationException(javax.naming.ConfigurationException)

Example 2 with PrimaryStorageDownloadAnswer

use of com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer in project cloudstack by apache.

the class VmwareStorageManagerImpl method execute.

@Override
public Answer execute(VmwareHostService hostService, PrimaryStorageDownloadCommand cmd) {
    String secondaryStorageUrl = cmd.getSecondaryStorageUrl();
    assert (secondaryStorageUrl != null);
    String templateUrl = cmd.getUrl();
    String templateName = null;
    String mountPoint = null;
    if (templateUrl.endsWith(".ova")) {
        int index = templateUrl.lastIndexOf("/");
        mountPoint = templateUrl.substring(0, index);
        mountPoint = mountPoint.substring(secondaryStorageUrl.length() + 1);
        if (!mountPoint.endsWith("/")) {
            mountPoint = mountPoint + "/";
        }
        templateName = templateUrl.substring(index + 1).replace("." + ImageFormat.OVA.getFileExtension(), "");
        if (templateName == null || templateName.isEmpty()) {
            templateName = cmd.getName();
        }
    } else {
        mountPoint = templateUrl.substring(secondaryStorageUrl.length() + 1);
        if (!mountPoint.endsWith("/")) {
            mountPoint = mountPoint + "/";
        }
        templateName = cmd.getName();
    }
    VmwareContext context = hostService.getServiceContext(cmd);
    try {
        VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd);
        String templateUuidName = UUID.nameUUIDFromBytes((templateName + "@" + cmd.getPoolUuid() + "-" + hyperHost.getMor().getValue()).getBytes("UTF-8")).toString();
        // truncate template name to 32 chars to ensure they work well with vSphere API's.
        templateUuidName = templateUuidName.replace("-", "");
        DatacenterMO dcMo = new DatacenterMO(context, hyperHost.getHyperHostDatacenter());
        VirtualMachineMO templateMo = VmwareHelper.pickOneVmOnRunningHost(dcMo.findVmByNameAndLabel(templateUuidName), true);
        if (templateMo == null) {
            if (s_logger.isInfoEnabled()) {
                s_logger.info("Template " + templateName + " is not setup yet, setup template from secondary storage with uuid name: " + templateUuidName);
            }
            ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, cmd.getPoolUuid());
            assert (morDs != null);
            DatastoreMO primaryStorageDatastoreMo = new DatastoreMO(context, morDs);
            copyTemplateFromSecondaryToPrimary(hyperHost, primaryStorageDatastoreMo, secondaryStorageUrl, mountPoint, templateName, templateUuidName, cmd.getNfsVersion());
        } else {
            s_logger.info("Template " + templateName + " has already been setup, skip the template setup process in primary storage");
        }
        return new PrimaryStorageDownloadAnswer(templateUuidName, 0);
    } catch (Throwable e) {
        if (e instanceof RemoteException) {
            hostService.invalidateServiceContext(context);
        }
        String msg = "Unable to execute PrimaryStorageDownloadCommand due to exception";
        s_logger.error(msg, e);
        return new PrimaryStorageDownloadAnswer(msg);
    }
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) VirtualMachineMO(com.cloud.hypervisor.vmware.mo.VirtualMachineMO) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) RemoteException(java.rmi.RemoteException) DatastoreMO(com.cloud.hypervisor.vmware.mo.DatastoreMO) DatacenterMO(com.cloud.hypervisor.vmware.mo.DatacenterMO) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 3 with PrimaryStorageDownloadAnswer

use of com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer in project cloudstack by apache.

the class CitrixPrimaryStorageDownloadCommandWrapper method execute.

@Override
public Answer execute(final PrimaryStorageDownloadCommand command, final CitrixResourceBase citrixResourceBase) {
    final String tmplturl = command.getUrl();
    final String poolName = command.getPoolUuid();
    final int wait = command.getWait();
    try {
        final URI uri = new URI(tmplturl);
        final String tmplpath = uri.getHost() + ":" + uri.getPath();
        final Connection conn = citrixResourceBase.getConnection();
        SR poolsr = null;
        final Set<SR> srs = SR.getByNameLabel(conn, poolName);
        if (srs.size() != 1) {
            final String msg = "There are " + srs.size() + " SRs with same name: " + poolName;
            s_logger.warn(msg);
            return new PrimaryStorageDownloadAnswer(msg);
        } else {
            poolsr = srs.iterator().next();
        }
        final String pUuid = poolsr.getUuid(conn);
        final boolean isISCSI = citrixResourceBase.IsISCSI(poolsr.getType(conn));
        final String uuid = citrixResourceBase.copyVhdFromSecondaryStorage(conn, tmplpath, pUuid, wait);
        final VDI tmpl = citrixResourceBase.getVDIbyUuid(conn, uuid);
        final VDI snapshotvdi = tmpl.snapshot(conn, new HashMap<String, String>());
        final String snapshotUuid = snapshotvdi.getUuid(conn);
        snapshotvdi.setNameLabel(conn, "Template " + command.getName());
        final String parentuuid = citrixResourceBase.getVhdParent(conn, pUuid, snapshotUuid, isISCSI);
        final VDI parent = citrixResourceBase.getVDIbyUuid(conn, parentuuid);
        final Long phySize = parent.getPhysicalUtilisation(conn);
        tmpl.destroy(conn);
        poolsr.scan(conn);
        try {
            Thread.sleep(5000);
        } catch (final Exception e) {
        }
        return new PrimaryStorageDownloadAnswer(snapshotvdi.getUuid(conn), phySize);
    } catch (final Exception e) {
        final String msg = "Catch Exception " + e.getClass().getName() + " on host:" + citrixResourceBase.getHost().getUuid() + " for template: " + tmplturl + " due to " + e.toString();
        s_logger.warn(msg, e);
        return new PrimaryStorageDownloadAnswer(msg);
    }
}
Also used : PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) Connection(com.xensource.xenapi.Connection) VDI(com.xensource.xenapi.VDI) URI(java.net.URI) SR(com.xensource.xenapi.SR)

Example 4 with PrimaryStorageDownloadAnswer

use of com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer in project cloudstack by apache.

the class Ovm3StoragePool method execute.

/**
     * Download from template url into primary storage ?.. is this relevant ?
     *
     * @param cmd
     * @return
     */
public PrimaryStorageDownloadAnswer execute(final PrimaryStorageDownloadCommand cmd) {
    try {
        Repository repo = new Repository(c);
        String tmplturl = cmd.getUrl();
        String poolName = cmd.getPoolUuid();
        String image = repo.deDash(repo.newUuid()) + ".raw";
        /* url to download from, image name, and repo to copy it to */
        repo.importVirtualDisk(tmplturl, image, poolName);
        return new PrimaryStorageDownloadAnswer(image);
    } catch (Exception e) {
        LOGGER.debug("PrimaryStorageDownloadCommand failed", e);
        return new PrimaryStorageDownloadAnswer(e.getMessage());
    }
}
Also used : PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) Repository(com.cloud.hypervisor.ovm3.objects.Repository) ConfigurationException(javax.naming.ConfigurationException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Example 5 with PrimaryStorageDownloadAnswer

use of com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer in project CloudStack-archive by CloudStack-extras.

the class MockStorageManagerImpl method primaryStorageDownload.

@Override
public PrimaryStorageDownloadAnswer primaryStorageDownload(PrimaryStorageDownloadCommand cmd) {
    MockVolumeVO template = findVolumeFromSecondary(cmd.getUrl(), cmd.getSecondaryStorageUrl(), MockVolumeType.TEMPLATE);
    if (template == null) {
        return new PrimaryStorageDownloadAnswer("Can't find primary storage");
    }
    MockStoragePoolVO primaryStorage = _mockStoragePoolDao.findByUuid(cmd.getPoolUuid());
    if (primaryStorage == null) {
        return new PrimaryStorageDownloadAnswer("Can't find primary storage");
    }
    String volumeName = UUID.randomUUID().toString();
    MockVolumeVO newVolume = new MockVolumeVO();
    newVolume.setName(volumeName);
    newVolume.setPath(primaryStorage.getMountPoint() + volumeName);
    newVolume.setPoolId(primaryStorage.getId());
    newVolume.setSize(template.getSize());
    newVolume.setType(MockVolumeType.VOLUME);
    _mockVolumeDao.persist(newVolume);
    return new PrimaryStorageDownloadAnswer(newVolume.getPath(), newVolume.getSize());
}
Also used : PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) MockVolumeVO(com.cloud.simulator.MockVolumeVO)

Aggregations

PrimaryStorageDownloadAnswer (com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer)11 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)6 ConfigurationException (javax.naming.ConfigurationException)4 URISyntaxException (java.net.URISyntaxException)3 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)2 MockStoragePoolVO (com.cloud.simulator.MockStoragePoolVO)2 MockVolumeVO (com.cloud.simulator.MockVolumeVO)2 IOException (java.io.IOException)2 URI (java.net.URI)2 RemoteException (java.rmi.RemoteException)2 XmlRpcException (org.apache.xmlrpc.XmlRpcException)2 RadosException (com.ceph.rados.exceptions.RadosException)1 RbdException (com.ceph.rbd.RbdException)1 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)1 DataTO (com.cloud.agent.api.to.DataTO)1 NfsTO (com.cloud.agent.api.to.NfsTO)1 KVMPhysicalDisk (com.cloud.agent.storage.KVMPhysicalDisk)1 KVMStoragePool (com.cloud.agent.storage.KVMStoragePool)1 InternalErrorException (com.cloud.exception.InternalErrorException)1 KVMPhysicalDisk (com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk)1