Search in sources :

Example 6 with TemplateInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo in project cloudstack by apache.

the class VolumeTestVmware method testCreateTemplateFromVolume.

@Test
public void testCreateTemplateFromVolume() {
    DataStore primaryStore = createPrimaryDataStore();
    primaryStoreId = primaryStore.getId();
    primaryStore = this.dataStoreMgr.getPrimaryDataStore(primaryStoreId);
    VolumeVO volume = createVolume(null, primaryStore.getId());
    VolumeInfo volInfo = this.volFactory.getVolume(volume.getId());
    AsyncCallFuture<VolumeApiResult> future = this.volumeService.createVolumeAsync(volInfo, primaryStore);
    try {
        VolumeApiResult result = future.get();
        AssertJUnit.assertTrue(result.isSuccess());
        volInfo = result.getVolume();
        VMTemplateVO templateVO = createTemplateInDb();
        TemplateInfo tmpl = this.templateFactory.getTemplate(templateVO.getId(), DataStoreRole.Image);
        DataStore imageStore = this.dataStoreMgr.getImageStore(this.dcId);
        this.imageService.createTemplateFromVolumeAsync(volInfo, tmpl, imageStore);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ExecutionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) VolumeVO(com.cloud.storage.VolumeVO) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) VolumeApiResult(org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult) ExecutionException(java.util.concurrent.ExecutionException) Test(org.testng.annotations.Test)

Example 7 with TemplateInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo in project cloudstack by apache.

the class TemplateServiceImpl method handleSysTemplateDownload.

@Override
public void handleSysTemplateDownload(HypervisorType hostHyper, Long dcId) {
    Set<VMTemplateVO> toBeDownloaded = new HashSet<VMTemplateVO>();
    List<DataStore> stores = _storeMgr.getImageStoresByScope(new ZoneScope(dcId));
    if (stores == null || stores.isEmpty()) {
        return;
    }
    /* Download all the templates in zone with the same hypervisortype */
    for (DataStore store : stores) {
        List<VMTemplateVO> rtngTmplts = _templateDao.listAllSystemVMTemplates();
        List<VMTemplateVO> defaultBuiltin = _templateDao.listDefaultBuiltinTemplates();
        for (VMTemplateVO rtngTmplt : rtngTmplts) {
            if (rtngTmplt.getHypervisorType() == hostHyper) {
                toBeDownloaded.add(rtngTmplt);
            }
        }
        for (VMTemplateVO builtinTmplt : defaultBuiltin) {
            if (builtinTmplt.getHypervisorType() == hostHyper) {
                toBeDownloaded.add(builtinTmplt);
            }
        }
        for (VMTemplateVO template : toBeDownloaded) {
            TemplateDataStoreVO tmpltHost = _vmTemplateStoreDao.findByStoreTemplate(store.getId(), template.getId());
            if (tmpltHost == null) {
                associateTemplateToZone(template.getId(), dcId);
                s_logger.info("Downloading builtin template " + template.getUniqueName() + " to data center: " + dcId);
                TemplateInfo tmplt = _templateFactory.getTemplate(template.getId(), DataStoreRole.Image);
                createTemplateAsync(tmplt, store, null);
            }
        }
    }
}
Also used : ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO) HashSet(java.util.HashSet)

Example 8 with TemplateInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo in project cloudstack by apache.

the class TemplateServiceImpl method syncTemplateCallBack.

protected Void syncTemplateCallBack(AsyncCallbackDispatcher<TemplateServiceImpl, CopyCommandResult> callback, TemplateOpContext<TemplateApiResult> context) {
    TemplateInfo destTemplate = context.getTemplate();
    CopyCommandResult result = callback.getResult();
    AsyncCallFuture<TemplateApiResult> future = context.getFuture();
    TemplateApiResult res = new TemplateApiResult(destTemplate);
    try {
        if (result.isFailed()) {
            res.setResult(result.getResult());
        // no change to existing template_store_ref, will try to re-sync later if other call triggers this sync operation, like copy template
        } else {
            // this will update install path properly, next time it will not sync anymore.
            destTemplate.processEvent(Event.OperationSuccessed, result.getAnswer());
        }
        future.complete(res);
    } catch (Exception e) {
        s_logger.debug("Failed to process sync template callback", e);
        res.setResult(e.toString());
        future.complete(res);
    }
    return null;
}
Also used : TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 9 with TemplateInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo in project cloudstack by apache.

the class TemplateServiceImpl method copyTemplateCrossZoneCallBack.

protected Void copyTemplateCrossZoneCallBack(AsyncCallbackDispatcher<TemplateServiceImpl, CreateCmdResult> callback, TemplateOpContext<TemplateApiResult> context) {
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Performing copy template cross zone callback after completion");
    }
    TemplateInfo destTemplate = context.getTemplate();
    CreateCmdResult result = callback.getResult();
    AsyncCallFuture<TemplateApiResult> future = context.getFuture();
    TemplateApiResult res = new TemplateApiResult(destTemplate);
    try {
        if (result.isFailed()) {
            res.setResult(result.getResult());
            destTemplate.processEvent(Event.OperationFailed);
        } else {
            destTemplate.processEvent(Event.OperationSuccessed, result.getAnswer());
        }
        future.complete(res);
    } catch (Exception e) {
        s_logger.debug("Failed to process copy template cross zones callback", e);
        res.setResult(e.toString());
        future.complete(res);
    }
    return null;
}
Also used : TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 10 with TemplateInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo 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)

Aggregations

TemplateInfo (org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo)49 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)25 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)19 VMTemplateVO (com.cloud.storage.VMTemplateVO)17 TemplateDataStoreVO (org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)15 ExecutionException (java.util.concurrent.ExecutionException)13 TemplateApiResult (org.apache.cloudstack.engine.subsystem.api.storage.TemplateService.TemplateApiResult)13 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)11 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)9 PrimaryDataStore (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)9 AsyncCallFuture (org.apache.cloudstack.framework.async.AsyncCallFuture)9 Test (org.testng.annotations.Test)9 ZoneScope (org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope)8 DB (com.cloud.utils.db.DB)7 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)6 CreateCmdResult (org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)6 SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)6 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)5 HashSet (java.util.HashSet)5 DataObject (org.apache.cloudstack.engine.subsystem.api.storage.DataObject)5