Search in sources :

Example 1 with PrimaryDataStore

use of com.cloud.engine.subsystem.api.storage.PrimaryDataStore in project cosmic by MissionCriticalCloud.

the class VolumeServiceImpl method createVolumeFromTemplateAsync.

@DB
@Override
public AsyncCallFuture<VolumeApiResult> createVolumeFromTemplateAsync(final VolumeInfo volume, final long dataStoreId, final TemplateInfo template) {
    final PrimaryDataStore pd = dataStoreMgr.getPrimaryDataStore(dataStoreId);
    final TemplateInfo templateOnPrimaryStore = pd.getTemplate(template.getId());
    final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
    if (templateOnPrimaryStore == null) {
        createBaseImageAsync(volume, pd, template, future);
        return future;
    }
    createVolumeFromBaseImageAsync(volume, templateOnPrimaryStore, pd, future);
    return future;
}
Also used : AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) DB(com.cloud.utils.db.DB)

Example 2 with PrimaryDataStore

use of com.cloud.engine.subsystem.api.storage.PrimaryDataStore in project cosmic by MissionCriticalCloud.

the class VolumeServiceImpl method resizeVolumeOnHypervisor.

@Override
public void resizeVolumeOnHypervisor(final long volumeId, final long newSize, final long destHostId, final String instanceName) {
    final String errMsg = "Resize command failed";
    try {
        Answer answer = null;
        final Host destHost = _hostDao.findById(destHostId);
        final EndPoint ep = RemoteHostEndPoint.getHypervisorHostEndPoint(destHost);
        if (ep != null) {
            final VolumeVO volume = volDao.findById(volumeId);
            final PrimaryDataStore primaryDataStore = this.dataStoreMgr.getPrimaryDataStore(volume.getPoolId());
            final ResizeVolumeCommand resizeCmd = new ResizeVolumeCommand(volume.getPath(), new StorageFilerTO(primaryDataStore), volume.getSize(), newSize, true, instanceName);
            answer = ep.sendMessage(resizeCmd);
        } else {
            throw new CloudRuntimeException("Could not find a remote endpoint to send command to. Check if host or SSVM is down.");
        }
        if (answer == null || !answer.getResult()) {
            throw new CloudRuntimeException(answer != null ? answer.getDetails() : errMsg);
        }
    } catch (final Exception e) {
        throw new CloudRuntimeException(errMsg, e);
    }
}
Also used : Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer) ListVolumeAnswer(com.cloud.agent.api.storage.ListVolumeAnswer) VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResizeVolumeCommand(com.cloud.agent.api.storage.ResizeVolumeCommand) Host(com.cloud.host.Host) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore)

Example 3 with PrimaryDataStore

use of com.cloud.engine.subsystem.api.storage.PrimaryDataStore in project cosmic by MissionCriticalCloud.

the class VolumeServiceImpl method createManagedStorageAndVolumeFromTemplateAsync.

@Override
public AsyncCallFuture<VolumeApiResult> createManagedStorageAndVolumeFromTemplateAsync(VolumeInfo volumeInfo, final long destDataStoreId, final TemplateInfo srcTemplateInfo, final long destHostId) {
    final PrimaryDataStore destPrimaryDataStore = dataStoreMgr.getPrimaryDataStore(destDataStoreId);
    final TemplateInfo destTemplateInfo = (TemplateInfo) destPrimaryDataStore.create(srcTemplateInfo);
    final Host destHost = _hostDao.findById(destHostId);
    if (destHost == null) {
        throw new CloudRuntimeException("Destinatin host should not be null.");
    }
    final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
    try {
        // must call driver to have a volume created
        final AsyncCallFuture<VolumeApiResult> createVolumeFuture = createVolumeAsync(volumeInfo, destPrimaryDataStore);
        final VolumeApiResult createVolumeResult = createVolumeFuture.get();
        if (createVolumeResult.isFailed()) {
            throw new CloudRuntimeException("Creation of a volume failed: " + createVolumeResult.getResult());
        }
        // refresh the volume from the DB
        volumeInfo = volFactory.getVolume(volumeInfo.getId(), destPrimaryDataStore);
        grantAccess(volumeInfo, destHost, destPrimaryDataStore);
        final ManagedCreateBaseImageContext<CreateCmdResult> context = new ManagedCreateBaseImageContext<>(null, volumeInfo, destPrimaryDataStore, srcTemplateInfo, future);
        final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().managedCopyBaseImageCallback(null, null)).setContext(context);
        final Map<String, String> details = new HashMap<>();
        details.put(PrimaryDataStore.MANAGED, Boolean.TRUE.toString());
        details.put(PrimaryDataStore.STORAGE_HOST, destPrimaryDataStore.getHostAddress());
        details.put(PrimaryDataStore.STORAGE_PORT, String.valueOf(destPrimaryDataStore.getPort()));
        // for managed storage, the storage repository (XenServer) or datastore (ESX) name is based off of the iScsiName property of a volume
        details.put(PrimaryDataStore.MANAGED_STORE_TARGET, volumeInfo.get_iScsiName());
        details.put(PrimaryDataStore.MANAGED_STORE_TARGET_ROOT_VOLUME, volumeInfo.getName());
        details.put(PrimaryDataStore.VOLUME_SIZE, String.valueOf(volumeInfo.getSize()));
        final ChapInfo chapInfo = getChapInfo(volumeInfo, destPrimaryDataStore);
        if (chapInfo != null) {
            details.put(PrimaryDataStore.CHAP_INITIATOR_USERNAME, chapInfo.getInitiatorUsername());
            details.put(PrimaryDataStore.CHAP_INITIATOR_SECRET, chapInfo.getInitiatorSecret());
            details.put(PrimaryDataStore.CHAP_TARGET_USERNAME, chapInfo.getTargetUsername());
            details.put(PrimaryDataStore.CHAP_TARGET_SECRET, chapInfo.getTargetSecret());
        }
        destPrimaryDataStore.setDetails(details);
        motionSrv.copyAsync(srcTemplateInfo, destTemplateInfo, destHost, caller);
    } catch (InterruptedException | ExecutionException e) {
        String errMsg = e.getMessage();
        volumeInfo.processEvent(Event.DestroyRequested);
        revokeAccess(volumeInfo, destHost, destPrimaryDataStore);
        try {
            final AsyncCallFuture<VolumeApiResult> expungeVolumeFuture = expungeVolumeAsync(volumeInfo);
            final VolumeApiResult expungeVolumeResult = expungeVolumeFuture.get();
            if (expungeVolumeResult.isFailed()) {
                errMsg += " : Failed to expunge a volume that was created";
            }
        } catch (InterruptedException | ExecutionException innerException) {
            errMsg += " : " + innerException.getMessage();
        }
        final VolumeApiResult result = new VolumeApiResult(volumeInfo);
        result.setResult(errMsg);
        future.complete(result);
    }
    return future;
}
Also used : HashMap(java.util.HashMap) ChapInfo(com.cloud.engine.subsystem.api.storage.ChapInfo) Host(com.cloud.host.Host) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore)

Example 4 with PrimaryDataStore

use of com.cloud.engine.subsystem.api.storage.PrimaryDataStore in project cosmic by MissionCriticalCloud.

the class TemplateManagerImplTest method testPrepareTemplateNotDownloaded.

@Test
public void testPrepareTemplateNotDownloaded() {
    final VMTemplateVO mockTemplate = mock(VMTemplateVO.class);
    when(mockTemplate.getId()).thenReturn(202l);
    final StoragePoolVO mockPool = mock(StoragePoolVO.class);
    when(mockPool.getId()).thenReturn(2l);
    final PrimaryDataStore mockPrimaryDataStore = mock(PrimaryDataStore.class);
    when(mockPrimaryDataStore.getId()).thenReturn(2l);
    when(mockPrimaryDataStore.getDataCenterId()).thenReturn(1l);
    when(dataStoreManager.getPrimaryDataStore(anyLong())).thenReturn(mockPrimaryDataStore);
    when(vmTemplateDao.findById(anyLong(), anyBoolean())).thenReturn(mockTemplate);
    when(vmTemplatePoolDao.findByPoolTemplate(anyLong(), anyLong())).thenReturn(null);
    when(templateDataStoreDao.findByTemplateZoneDownloadStatus(202l, 1l, VMTemplateStorageResourceAssoc.Status.DOWNLOADED)).thenReturn(null);
    final VMTemplateStoragePoolVO returnObject = templateManager.prepareTemplateForCreate(mockTemplate, (StoragePool) mockPrimaryDataStore);
    assertTrue("Test template is not ready", returnObject == null);
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) VMTemplateVO(com.cloud.storage.VMTemplateVO) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) Test(org.junit.Test)

Example 5 with PrimaryDataStore

use of com.cloud.engine.subsystem.api.storage.PrimaryDataStore in project cosmic by MissionCriticalCloud.

the class TemplateManagerImplTest method testTemplateScheduledForDownloadInDisabledPool.

@Test
public void testTemplateScheduledForDownloadInDisabledPool() {
    final VMTemplateVO mockTemplate = mock(VMTemplateVO.class);
    final StoragePoolVO mockPool = mock(StoragePoolVO.class);
    final PrimaryDataStore mockPrimaryDataStore = mock(PrimaryDataStore.class);
    final VMTemplateStoragePoolVO mockTemplateStore = mock(VMTemplateStoragePoolVO.class);
    when(mockPrimaryDataStore.getId()).thenReturn(2l);
    when(mockPool.getId()).thenReturn(2l);
    when(mockPool.getStatus()).thenReturn(StoragePoolStatus.Disabled);
    when(mockPool.getDataCenterId()).thenReturn(1l);
    when(mockTemplate.getId()).thenReturn(202l);
    when(mockTemplateStore.getDownloadState()).thenReturn(VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
    when(vmTemplateDao.findById(anyLong())).thenReturn(mockTemplate);
    when(dataStoreManager.getPrimaryDataStore(anyLong())).thenReturn(mockPrimaryDataStore);
    when(vmTemplateDao.findById(anyLong(), anyBoolean())).thenReturn(mockTemplate);
    when(vmTemplatePoolDao.findByPoolTemplate(anyLong(), anyLong())).thenReturn(mockTemplateStore);
    when(primaryDataStoreDao.findById(anyLong())).thenReturn(mockPool);
    doNothing().when(mockTemplateStore).setMarkedForGC(anyBoolean());
    final ExecutorService preloadExecutor = new CustomThreadPoolExecutor(8, 8, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), new NamedThreadFactory("Template-Preloader"));
    templateManager._preloadExecutor = preloadExecutor;
    templateManager.prepareTemplate(202, 1, 2l);
    assertTrue("Test template is not scheduled for seeding on disabled pool", ((CustomThreadPoolExecutor) preloadExecutor).getCount() == 0);
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) NamedThreadFactory(com.cloud.utils.concurrency.NamedThreadFactory) VMTemplateVO(com.cloud.storage.VMTemplateVO) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) ExecutorService(java.util.concurrent.ExecutorService) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) Test(org.junit.Test)

Aggregations

PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)12 StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)7 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)6 VMTemplateVO (com.cloud.storage.VMTemplateVO)6 Test (org.junit.Test)6 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 ExecutionException (java.util.concurrent.ExecutionException)4 TemplateInfo (com.cloud.engine.subsystem.api.storage.TemplateInfo)3 AsyncCallFuture (com.cloud.framework.async.AsyncCallFuture)3 Host (com.cloud.host.Host)3 NamedThreadFactory (com.cloud.utils.concurrency.NamedThreadFactory)3 ExecutorService (java.util.concurrent.ExecutorService)3 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)3 CopyCommandResult (com.cloud.engine.subsystem.api.storage.CopyCommandResult)2 VolumeVO (com.cloud.storage.VolumeVO)2 Answer (com.cloud.agent.api.Answer)1 ListVolumeAnswer (com.cloud.agent.api.storage.ListVolumeAnswer)1 ResizeVolumeCommand (com.cloud.agent.api.storage.ResizeVolumeCommand)1 StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)1 ChapInfo (com.cloud.engine.subsystem.api.storage.ChapInfo)1