Search in sources :

Example 6 with TemplateObjectTO

use of org.apache.cloudstack.storage.to.TemplateObjectTO in project cloudstack by apache.

the class VmwareStorageProcessor method createTemplateFromSnapshot.

@Override
public Answer createTemplateFromSnapshot(CopyCommand cmd) {
    SnapshotObjectTO snapshot = (SnapshotObjectTO) cmd.getSrcTO();
    TemplateObjectTO template = (TemplateObjectTO) cmd.getDestTO();
    DataStoreTO imageStore = template.getDataStore();
    String details;
    String uniqeName = UUID.randomUUID().toString();
    VmwareContext context = hostService.getServiceContext(cmd);
    try {
        if (!(imageStore instanceof NfsTO)) {
            return new CopyCmdAnswer("Only support create template from snapshot, when the dest store is nfs");
        }
        NfsTO nfsSvr = (NfsTO) imageStore;
        Ternary<String, Long, Long> result = createTemplateFromSnapshot(template.getPath(), uniqeName, nfsSvr.getUrl(), snapshot.getPath(), template.getId(), (long) cmd.getWait() * 1000, _nfsVersion);
        TemplateObjectTO newTemplate = new TemplateObjectTO();
        newTemplate.setPath(result.first());
        newTemplate.setPhysicalSize(result.second());
        newTemplate.setSize(result.third());
        newTemplate.setFormat(ImageFormat.OVA);
        newTemplate.setName(uniqeName);
        return new CopyCmdAnswer(newTemplate);
    } catch (Throwable e) {
        if (e instanceof RemoteException) {
            hostService.invalidateServiceContext(context);
        }
        s_logger.error("Unexpecpted exception ", e);
        details = "create template from snapshot exception: " + VmwareHelper.getExceptionMessage(e);
        return new CopyCmdAnswer(details);
    }
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) RemoteException(java.rmi.RemoteException) NfsTO(com.cloud.agent.api.to.NfsTO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 7 with TemplateObjectTO

use of org.apache.cloudstack.storage.to.TemplateObjectTO in project cloudstack by apache.

the class DirectAgentTest method testDownloadTemplate.

@Test
public void testDownloadTemplate() {
    ImageStoreTO image = Mockito.mock(ImageStoreTO.class);
    PrimaryDataStoreTO primaryStore = Mockito.mock(PrimaryDataStoreTO.class);
    Mockito.when(primaryStore.getUuid()).thenReturn(getLocalStorageUuid());
    // Mockito.when(image.get).thenReturn(primaryStore);
    ImageStoreTO imageStore = Mockito.mock(ImageStoreTO.class);
    Mockito.when(imageStore.getProtocol()).thenReturn("http");
    TemplateObjectTO template = Mockito.mock(TemplateObjectTO.class);
    Mockito.when(template.getPath()).thenReturn(getTemplateUrl());
    Mockito.when(template.getDataStore()).thenReturn(imageStore);
    // Mockito.when(image.getTemplate()).thenReturn(template);
    // CopyTemplateToPrimaryStorageCmd cmd = new
    // CopyTemplateToPrimaryStorageCmd(image);
    Command cmd = null;
    try {
        agentMgr.send(hostId, cmd);
    } catch (AgentUnavailableException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OperationTimedoutException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ImageStoreTO(org.apache.cloudstack.storage.to.ImageStoreTO) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) Command(com.cloud.agent.api.Command) ReadyCommand(com.cloud.agent.api.ReadyCommand) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) Test(org.testng.annotations.Test)

Example 8 with TemplateObjectTO

use of org.apache.cloudstack.storage.to.TemplateObjectTO in project cloudstack by apache.

the class SnapshotTest method setUp.

@Test(priority = -1)
public void setUp() {
    ComponentContext.initComponentsLifeCycle();
    host = hostDao.findByGuid(this.getHostGuid());
    if (host != null) {
        dcId = host.getDataCenterId();
        clusterId = host.getClusterId();
        podId = host.getPodId();
        imageStore = this.imageStoreDao.findByName(imageStoreName);
    } else {
        // create data center
        DataCenterVO dc = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null, "10.0.0.1/24", null, null, NetworkType.Basic, null, null, true, true, null, null);
        dc = dcDao.persist(dc);
        dcId = dc.getId();
        // create pod
        HostPodVO pod = new HostPodVO(UUID.randomUUID().toString(), dc.getId(), this.getHostGateway(), this.getHostCidr(), 8, "test");
        pod = podDao.persist(pod);
        podId = pod.getId();
        // create xenserver cluster
        ClusterVO cluster = new ClusterVO(dc.getId(), pod.getId(), "devcloud cluster");
        cluster.setHypervisorType(this.getHypervisor().toString());
        cluster.setClusterType(ClusterType.CloudManaged);
        cluster.setManagedState(ManagedState.Managed);
        cluster = clusterDao.persist(cluster);
        clusterId = cluster.getId();
        // create xenserver host
        host = new HostVO(this.getHostGuid());
        host.setName("devcloud xenserver host");
        host.setType(Host.Type.Routing);
        host.setPrivateIpAddress(this.getHostIp());
        host.setDataCenterId(dc.getId());
        host.setVersion("6.0.1");
        host.setAvailable(true);
        host.setSetup(true);
        host.setPodId(podId);
        host.setLastPinged(0);
        host.setResourceState(ResourceState.Enabled);
        host.setHypervisorType(this.getHypervisor());
        host.setClusterId(cluster.getId());
        host = hostDao.persist(host);
        imageStore = new ImageStoreVO();
        imageStore.setName(imageStoreName);
        imageStore.setDataCenterId(dcId);
        imageStore.setProviderName(DataStoreProvider.NFS_IMAGE);
        imageStore.setRole(DataStoreRole.Image);
        imageStore.setUrl(this.getSecondaryStorage());
        imageStore.setUuid(UUID.randomUUID().toString());
        imageStore.setProtocol("nfs");
        imageStore = imageStoreDao.persist(imageStore);
    }
    image = new VMTemplateVO();
    image.setTemplateType(TemplateType.USER);
    image.setUrl(this.getTemplateUrl());
    image.setUniqueName(UUID.randomUUID().toString());
    image.setName(UUID.randomUUID().toString());
    image.setPublicTemplate(true);
    image.setFeatured(true);
    image.setRequiresHvm(true);
    image.setBits(64);
    image.setFormat(Storage.ImageFormat.VHD);
    image.setEnablePassword(true);
    image.setEnableSshKey(true);
    image.setGuestOSId(1);
    image.setBootable(true);
    image.setPrepopulate(true);
    image.setCrossZones(true);
    image.setExtractable(true);
    image = imageDataDao.persist(image);
    /*
         * TemplateDataStoreVO templateStore = new TemplateDataStoreVO();
         *
         * templateStore.setDataStoreId(imageStore.getId());
         * templateStore.setDownloadPercent(100);
         * templateStore.setDownloadState(Status.DOWNLOADED);
         * templateStore.setDownloadUrl(imageStore.getUrl());
         * templateStore.setInstallPath(this.getImageInstallPath());
         * templateStore.setTemplateId(image.getId());
         * templateStoreDao.persist(templateStore);
         */
    DataStore store = this.dataStoreMgr.getDataStore(imageStore.getId(), DataStoreRole.Image);
    TemplateInfo template = templateFactory.getTemplate(image.getId(), DataStoreRole.Image);
    DataObject templateOnStore = store.create(template);
    TemplateObjectTO to = new TemplateObjectTO();
    to.setPath(this.getImageInstallPath());
    to.setFormat(ImageFormat.VHD);
    to.setSize(1000L);
    CopyCmdAnswer answer = new CopyCmdAnswer(to);
    templateOnStore.processEvent(Event.CreateOnlyRequested);
    templateOnStore.processEvent(Event.OperationSuccessed, answer);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) ClusterVO(com.cloud.dc.ClusterVO) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) HostPodVO(com.cloud.dc.HostPodVO) HostVO(com.cloud.host.HostVO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) Test(org.testng.annotations.Test)

Example 9 with TemplateObjectTO

use of org.apache.cloudstack.storage.to.TemplateObjectTO in project cloudstack by apache.

the class Ovm3StorageProcessor method cloneVolumeFromBaseTemplate.

/**
     * dest is VolumeObject, src is a template
     */
@Override
public CopyCmdAnswer cloneVolumeFromBaseTemplate(CopyCommand cmd) {
    LOGGER.debug("execute cloneVolumeFromBaseTemplate: " + cmd.getClass());
    try {
        // src
        DataTO srcData = cmd.getSrcTO();
        TemplateObjectTO src = (TemplateObjectTO) srcData;
        String srcFile = getVirtualDiskPath(src.getUuid(), src.getDataStore().getUuid());
        srcFile = srcFile.replace(config.getVirtualDiskDir(), config.getTemplateDir());
        DataTO destData = cmd.getDestTO();
        VolumeObjectTO dest = (VolumeObjectTO) destData;
        String destFile = getVirtualDiskPath(dest.getUuid(), dest.getDataStore().getUuid());
        Linux host = new Linux(c);
        LOGGER.debug("CopyFrom: " + srcData.getObjectType() + "," + srcFile + " to " + destData.getObjectType() + "," + destFile);
        host.copyFile(srcFile, destFile);
        VolumeObjectTO newVol = new VolumeObjectTO();
        newVol.setUuid(dest.getUuid());
        // was destfile
        newVol.setPath(dest.getUuid());
        newVol.setFormat(ImageFormat.RAW);
        return new CopyCmdAnswer(newVol);
    } catch (Ovm3ResourceException e) {
        String msg = "Error cloneVolumeFromBaseTemplate: " + e.getMessage();
        LOGGER.info(msg);
        return new CopyCmdAnswer(msg);
    }
}
Also used : DataTO(com.cloud.agent.api.to.DataTO) Linux(com.cloud.hypervisor.ovm3.objects.Linux) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 10 with TemplateObjectTO

use of org.apache.cloudstack.storage.to.TemplateObjectTO in project cloudstack by apache.

the class Ovm3StorageProcessor method copyTemplateToPrimaryStorage.

/**
     * src is Nfs and Template from secondary storage to primary
     */
@Override
public CopyCmdAnswer copyTemplateToPrimaryStorage(CopyCommand cmd) {
    LOGGER.debug("execute copyTemplateToPrimaryStorage: " + cmd.getClass());
    DataTO srcData = cmd.getSrcTO();
    DataStoreTO srcStore = srcData.getDataStore();
    DataTO destData = cmd.getDestTO();
    NfsTO srcImageStore = (NfsTO) srcStore;
    TemplateObjectTO destTemplate = (TemplateObjectTO) destData;
    try {
        String secPoolUuid = pool.setupSecondaryStorage(srcImageStore.getUrl());
        String primaryPoolUuid = destData.getDataStore().getUuid();
        String destPath = config.getAgentOvmRepoPath() + "/" + ovmObject.deDash(primaryPoolUuid) + "/" + config.getTemplateDir();
        String sourcePath = config.getAgentSecStoragePath() + "/" + secPoolUuid;
        Linux host = new Linux(c);
        String destUuid = destTemplate.getUuid();
        /*
             * Would love to add dynamic formats (tolower), to also support
             * VHD and QCOW2, although Ovm3.2 does not have tapdisk2 anymore
             * so we can forget about that.
             */
        /* TODO: add checksumming */
        String srcFile = sourcePath + "/" + srcData.getPath();
        if (srcData.getPath().endsWith("/")) {
            srcFile = sourcePath + "/" + srcData.getPath() + "/" + destUuid + ".raw";
        }
        String destFile = destPath + "/" + destUuid + ".raw";
        LOGGER.debug("CopyFrom: " + srcData.getObjectType() + "," + srcFile + " to " + destData.getObjectType() + "," + destFile);
        host.copyFile(srcFile, destFile);
        TemplateObjectTO newVol = new TemplateObjectTO();
        newVol.setUuid(destUuid);
        // was destfile
        newVol.setPath(destUuid);
        newVol.setFormat(ImageFormat.RAW);
        return new CopyCmdAnswer(newVol);
    } catch (Ovm3ResourceException e) {
        String msg = "Error while copying template to primary storage: " + e.getMessage();
        LOGGER.info(msg);
        return new CopyCmdAnswer(msg);
    }
}
Also used : DataStoreTO(com.cloud.agent.api.to.DataStoreTO) DataTO(com.cloud.agent.api.to.DataTO) Linux(com.cloud.hypervisor.ovm3.objects.Linux) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) NfsTO(com.cloud.agent.api.to.NfsTO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Aggregations

TemplateObjectTO (org.apache.cloudstack.storage.to.TemplateObjectTO)57 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)40 NfsTO (com.cloud.agent.api.to.NfsTO)34 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)28 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)26 DataTO (com.cloud.agent.api.to.DataTO)22 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)20 InternalErrorException (com.cloud.exception.InternalErrorException)19 PrimaryDataStoreTO (org.apache.cloudstack.storage.to.PrimaryDataStoreTO)19 DiskTO (com.cloud.agent.api.to.DiskTO)13 XmlRpcException (org.apache.xmlrpc.XmlRpcException)12 XenAPIException (com.xensource.xenapi.Types.XenAPIException)11 SnapshotObjectTO (org.apache.cloudstack.storage.to.SnapshotObjectTO)11 Answer (com.cloud.agent.api.Answer)10 VDI (com.xensource.xenapi.VDI)10 Connection (com.xensource.xenapi.Connection)9 SR (com.xensource.xenapi.SR)9 URI (java.net.URI)9 ConfigurationException (javax.naming.ConfigurationException)9 IOException (java.io.IOException)8