Search in sources :

Example 1 with DataObject

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

the class VolumeServiceImpl method createManagedTemplateImageCallback.

protected Void createManagedTemplateImageCallback(AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> callback, CreateVolumeContext<CreateCmdResult> context) {
    CreateCmdResult result = callback.getResult();
    VolumeApiResult res = new VolumeApiResult(null);
    res.setResult(result.getResult());
    AsyncCallFuture<VolumeApiResult> future = context.getFuture();
    DataObject templateOnPrimaryStoreObj = context.getVolume();
    if (result.isSuccess()) {
        ((TemplateObject) templateOnPrimaryStoreObj).setInstallPath(result.getPath());
        templateOnPrimaryStoreObj.processEvent(Event.OperationSuccessed, result.getAnswer());
    } else {
        templateOnPrimaryStoreObj.processEvent(Event.OperationFailed);
    }
    future.complete(res);
    return null;
}
Also used : DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) TemplateObject(org.apache.cloudstack.storage.image.store.TemplateObject)

Example 2 with DataObject

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

the class VolumeServiceImpl method createVolumeFromSnapshot.

@Override
public AsyncCallFuture<VolumeApiResult> createVolumeFromSnapshot(VolumeInfo volume, DataStore store, SnapshotInfo snapshot) {
    AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<VolumeApiResult>();
    try {
        DataObject volumeOnStore = store.create(volume);
        volumeOnStore.processEvent(Event.CreateOnlyRequested);
        _volumeDetailsDao.addDetail(volume.getId(), SNAPSHOT_ID, Long.toString(snapshot.getId()), false);
        CreateVolumeFromBaseImageContext<VolumeApiResult> context = new CreateVolumeFromBaseImageContext<VolumeApiResult>(null, volume, store, volumeOnStore, future, snapshot);
        AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().createVolumeFromSnapshotCallback(null, null)).setContext(context);
        motionSrv.copyAsync(snapshot, volumeOnStore, caller);
    } catch (Exception e) {
        s_logger.debug("create volume from snapshot failed", e);
        VolumeApiResult result = new VolumeApiResult(volume);
        result.setResult(e.toString());
        future.complete(result);
    }
    return future;
}
Also used : AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 3 with DataObject

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

the class EndpointSelectorTest method testMixZonePrimaryStorages.

@Test
public void testMixZonePrimaryStorages() {
    Long srcStoreId = null;
    Long destStoreId = imageStore.getId();
    DataStore store = createPrimaryDataStore(ScopeType.ZONE);
    srcStoreId = store.getId();
    HostVO host = createHost(Hypervisor.HypervisorType.VMware);
    addStorageToHost(store, host);
    store = createPrimaryDataStore(ScopeType.ZONE);
    host = createHost(Hypervisor.HypervisorType.VMware);
    addStorageToHost(store, host);
    Long xenStoreId = null;
    store = createPrimaryDataStore(ScopeType.CLUSTER);
    xenStoreId = store.getId();
    host = createHost(Hypervisor.HypervisorType.XenServer);
    addStorageToHost(store, host);
    store = createPrimaryDataStore(ScopeType.CLUSTER);
    host = createHost(Hypervisor.HypervisorType.XenServer);
    addStorageToHost(store, host);
    ZoneScope srcScope = new ZoneScope(dcId);
    DataStore srcStore = mock(DataStore.class);
    DataStore destStore = mock(DataStore.class);
    when(srcStore.getScope()).thenReturn(srcScope);
    when(srcStore.getRole()).thenReturn(DataStoreRole.Primary);
    when(srcStore.getId()).thenReturn(srcStoreId);
    when(destStore.getScope()).thenReturn(srcScope);
    when(destStore.getRole()).thenReturn(DataStoreRole.Image);
    when(destStore.getId()).thenReturn(destStoreId);
    DataObject srcObj = mock(DataObject.class);
    DataObject destObj = mock(DataObject.class);
    when(srcObj.getDataStore()).thenReturn(srcStore);
    when(destObj.getDataStore()).thenReturn(destStore);
    EndPoint ep = endPointSelector.select(srcObj, destObj);
    Assert.assertTrue(ep != null);
    Long hostId = ep.getId();
    HostVO newHost = hostDao.findById(hostId);
    Assert.assertTrue(newHost.getHypervisorType() == Hypervisor.HypervisorType.VMware);
    when(srcStore.getRole()).thenReturn(DataStoreRole.Image);
    when(srcStore.getId()).thenReturn(destStoreId);
    when(destStore.getId()).thenReturn(srcStoreId);
    when(destStore.getRole()).thenReturn(DataStoreRole.Primary);
    ep = endPointSelector.select(srcObj, destObj);
    Assert.assertTrue(ep != null);
    hostId = ep.getId();
    newHost = hostDao.findById(hostId);
    Assert.assertTrue(newHost.getHypervisorType() == Hypervisor.HypervisorType.VMware);
    ClusterScope clusterScope = new ClusterScope(clusterId, podId, dcId);
    when(srcStore.getRole()).thenReturn(DataStoreRole.Primary);
    when(srcStore.getScope()).thenReturn(clusterScope);
    when(srcStore.getId()).thenReturn(xenStoreId);
    ep = endPointSelector.select(srcStore);
    Assert.assertTrue(ep != null);
    newHost = hostDao.findById(ep.getId());
    Assert.assertTrue(newHost.getHypervisorType() == Hypervisor.HypervisorType.XenServer);
}
Also used : ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) ClusterScope(org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) HostVO(com.cloud.host.HostVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) Test(org.junit.Test)

Example 4 with DataObject

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

the class TemplateServiceImpl method copyAsync.

private AsyncCallFuture<TemplateApiResult> copyAsync(DataObject source, TemplateInfo template, DataStore store) {
    AsyncCallFuture<TemplateApiResult> future = new AsyncCallFuture<TemplateApiResult>();
    DataObject templateOnStore = store.create(template);
    templateOnStore.processEvent(Event.CreateOnlyRequested);
    TemplateOpContext<TemplateApiResult> context = new TemplateOpContext<TemplateApiResult>(null, (TemplateObject) templateOnStore, future);
    AsyncCallbackDispatcher<TemplateServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().copyTemplateCallBack(null, null)).setContext(context);
    _motionSrv.copyAsync(source, templateOnStore, caller);
    return future;
}
Also used : AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Example 5 with DataObject

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

DataObject (org.apache.cloudstack.engine.subsystem.api.storage.DataObject)36 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)16 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)13 CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)12 CreateCmdResult (org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)11 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)11 ZoneScope (org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope)8 CopyCommand (org.apache.cloudstack.storage.command.CopyCommand)7 Answer (com.cloud.agent.api.Answer)6 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)6 AsyncCallFuture (org.apache.cloudstack.framework.async.AsyncCallFuture)6 RemoteHostEndPoint (org.apache.cloudstack.storage.RemoteHostEndPoint)6 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)6 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)5 MigrateVolumeAnswer (com.cloud.agent.api.storage.MigrateVolumeAnswer)4 HostVO (com.cloud.host.HostVO)4 ClusterScope (org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope)4 TemplateInfo (org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo)4 VMTemplateVO (com.cloud.storage.VMTemplateVO)3 DB (com.cloud.utils.db.DB)3