Search in sources :

Example 1 with PrimaryDataStoreInfo

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

the class VirtualMachineManagerImpl method orchestrateStorageMigration.

@ReflectionUse
private Pair<JobInfo.Status, String> orchestrateStorageMigration(final VmWorkStorageMigration work) throws Exception {
    final VMInstanceVO vm = _entityMgr.findById(VMInstanceVO.class, work.getVmId());
    if (vm == null) {
        s_logger.info("Unable to find vm " + work.getVmId());
    }
    assert vm != null;
    final StoragePool pool = (PrimaryDataStoreInfo) dataStoreMgr.getPrimaryDataStore(work.getDestStoragePoolId());
    orchestrateStorageMigration(vm.getUuid(), pool);
    return new Pair<>(JobInfo.Status.SUCCEEDED, null);
}
Also used : PrimaryDataStoreInfo(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreInfo) StoragePool(com.cloud.storage.StoragePool) Pair(com.cloud.utils.Pair) ReflectionUse(com.cloud.utils.ReflectionUse)

Example 2 with PrimaryDataStoreInfo

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

the class CloudStackPrimaryDataStoreLifeCycleImpl method attachCluster.

@Override
public boolean attachCluster(final DataStore store, final ClusterScope scope) {
    final PrimaryDataStoreInfo primarystore = (PrimaryDataStoreInfo) store;
    // Check if there is host up in this cluster
    final List<HostVO> allHosts = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.Routing, primarystore.getClusterId(), primarystore.getPodId(), primarystore.getDataCenterId());
    if (allHosts.isEmpty()) {
        primaryDataStoreDao.expunge(primarystore.getId());
        throw new CloudRuntimeException("No host up to associate a storage pool with in cluster " + primarystore.getClusterId());
    }
    if (primarystore.getPoolType() == StoragePoolType.OCFS2 && !_ocfs2Mgr.prepareNodes(allHosts, primarystore)) {
        s_logger.warn("Can not create storage pool " + primarystore + " on cluster " + primarystore.getClusterId());
        primaryDataStoreDao.expunge(primarystore.getId());
        return false;
    }
    boolean success = false;
    for (final HostVO h : allHosts) {
        success = createStoragePool(h.getId(), primarystore);
        if (success) {
            break;
        }
    }
    s_logger.debug("In createPool Adding the pool to each of the hosts");
    final List<HostVO> poolHosts = new ArrayList<>();
    for (final HostVO h : allHosts) {
        try {
            storageMgr.connectHostToSharedPool(h.getId(), primarystore.getId());
            poolHosts.add(h);
        } catch (final StorageConflictException se) {
            primaryDataStoreDao.expunge(primarystore.getId());
            throw new CloudRuntimeException("Storage has already been added as local storage");
        } catch (final Exception e) {
            s_logger.warn("Unable to establish a connection between " + h + " and " + primarystore, e);
        }
    }
    if (poolHosts.isEmpty()) {
        s_logger.warn("No host can access storage pool " + primarystore + " on cluster " + primarystore.getClusterId());
        primaryDataStoreDao.expunge(primarystore.getId());
        throw new CloudRuntimeException("Failed to access storage pool");
    }
    dataStoreHelper.attachCluster(store);
    return true;
}
Also used : PrimaryDataStoreInfo(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreInfo) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList) StorageConflictException(com.cloud.exception.StorageConflictException) HostVO(com.cloud.host.HostVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) URISyntaxException(java.net.URISyntaxException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) StorageConflictException(com.cloud.exception.StorageConflictException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 3 with PrimaryDataStoreInfo

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

the class StorageManagerImpl method cancelPrimaryStorageForMaintenance.

@Override
@DB
public PrimaryDataStoreInfo cancelPrimaryStorageForMaintenance(final CancelPrimaryStorageMaintenanceCmd cmd) throws ResourceUnavailableException {
    final Long primaryStorageId = cmd.getId();
    final StoragePoolVO primaryStorage;
    primaryStorage = _storagePoolDao.findById(primaryStorageId);
    if (primaryStorage == null) {
        final String msg = "Unable to obtain lock on the storage pool in cancelPrimaryStorageForMaintenance()";
        s_logger.error(msg);
        throw new InvalidParameterValueException(msg);
    }
    if (primaryStorage.getStatus().equals(StoragePoolStatus.Up) || primaryStorage.getStatus().equals(StoragePoolStatus.PrepareForMaintenance)) {
        throw new StorageUnavailableException("Primary storage with id " + primaryStorageId + " is not ready to complete migration, as the status is:" + primaryStorage.getStatus().toString(), primaryStorageId);
    }
    final DataStoreProvider provider = _dataStoreProviderMgr.getDataStoreProvider(primaryStorage.getStorageProviderName());
    final DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
    final DataStore store = _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
    lifeCycle.cancelMaintain(store);
    return (PrimaryDataStoreInfo) _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
}
Also used : PrimaryDataStoreInfo(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreInfo) DataStoreLifeCycle(com.cloud.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) DataStoreProvider(com.cloud.engine.subsystem.api.storage.DataStoreProvider) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) DB(com.cloud.utils.db.DB)

Example 4 with PrimaryDataStoreInfo

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

the class StorageManagerImpl method createPool.

@Override
public PrimaryDataStoreInfo createPool(final CreateStoragePoolCmd cmd) throws ResourceInUseException, IllegalArgumentException, UnknownHostException, ResourceUnavailableException {
    final String providerName = cmd.getStorageProviderName();
    DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(providerName);
    if (storeProvider == null) {
        storeProvider = _dataStoreProviderMgr.getDefaultPrimaryDataStoreProvider();
        if (storeProvider == null) {
            throw new InvalidParameterValueException("can't find storage provider: " + providerName);
        }
    }
    Long clusterId = cmd.getClusterId();
    Long podId = cmd.getPodId();
    final Long zoneId = cmd.getZoneId();
    ScopeType scopeType = ScopeType.CLUSTER;
    final String scope = cmd.getScope();
    if (scope != null) {
        try {
            scopeType = Enum.valueOf(ScopeType.class, scope.toUpperCase());
        } catch (final Exception e) {
            throw new InvalidParameterValueException("invalid scope for pool " + scope);
        }
    }
    if (scopeType == ScopeType.CLUSTER && clusterId == null) {
        throw new InvalidParameterValueException("cluster id can't be null, if scope is cluster");
    } else if (scopeType == ScopeType.ZONE && zoneId == null) {
        throw new InvalidParameterValueException("zone id can't be null, if scope is zone");
    }
    HypervisorType hypervisorType = HypervisorType.KVM;
    if (scopeType == ScopeType.ZONE) {
        // ignore passed clusterId and podId
        clusterId = null;
        podId = null;
        final String hypervisor = cmd.getHypervisor();
        if (hypervisor != null) {
            try {
                hypervisorType = HypervisorType.getType(hypervisor);
            } catch (final Exception e) {
                throw new InvalidParameterValueException("invalid hypervisor type " + hypervisor);
            }
        } else {
            throw new InvalidParameterValueException("Missing parameter hypervisor. Hypervisor type is required to create zone wide primary storage.");
        }
        if (hypervisorType != HypervisorType.KVM && hypervisorType != HypervisorType.Any) {
            throw new InvalidParameterValueException("zone wide storage pool is not supported for hypervisor type " + hypervisor);
        }
    }
    final Map<String, String> details = extractApiParamAsMap(cmd.getDetails());
    final DataCenterVO zone = _dcDao.findById(cmd.getZoneId());
    if (zone == null) {
        throw new InvalidParameterValueException("unable to find zone by id " + zoneId);
    }
    // Check if zone is disabled
    final Account account = CallContext.current().getCallingAccount();
    if (AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getId())) {
        throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zoneId);
    }
    final Map<String, Object> params = new HashMap<>();
    params.put("zoneId", zone.getId());
    params.put("clusterId", clusterId);
    params.put("podId", podId);
    params.put("url", cmd.getUrl());
    params.put("tags", cmd.getTags());
    params.put("name", cmd.getStoragePoolName());
    params.put("details", details);
    params.put("providerName", storeProvider.getName());
    params.put("managed", cmd.isManaged());
    params.put("capacityBytes", cmd.getCapacityBytes());
    params.put("capacityIops", cmd.getCapacityIops());
    final DataStoreLifeCycle lifeCycle = storeProvider.getDataStoreLifeCycle();
    DataStore store = null;
    try {
        store = lifeCycle.initialize(params);
        if (scopeType == ScopeType.CLUSTER) {
            final ClusterScope clusterScope = new ClusterScope(clusterId, podId, zoneId);
            lifeCycle.attachCluster(store, clusterScope);
        } else if (scopeType == ScopeType.ZONE) {
            final ZoneScope zoneScope = new ZoneScope(zoneId);
            lifeCycle.attachZone(store, zoneScope, hypervisorType);
        }
    } catch (final Exception e) {
        s_logger.debug("Failed to add data store: " + e.getMessage(), e);
        try {
            // not deleting data store.
            if (store != null) {
                lifeCycle.deleteDataStore(store);
            }
        } catch (final Exception ex) {
            s_logger.debug("Failed to clean up storage pool: " + ex.getMessage());
        }
        throw new CloudRuntimeException("Failed to add data store: " + e.getMessage(), e);
    }
    return (PrimaryDataStoreInfo) _dataStoreMgr.getDataStore(store.getId(), DataStoreRole.Primary);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) PrimaryDataStoreInfo(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreInfo) Account(com.cloud.user.Account) HashMap(java.util.HashMap) DataStoreProvider(com.cloud.engine.subsystem.api.storage.DataStoreProvider) ConnectionException(com.cloud.exception.ConnectionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) StorageConflictException(com.cloud.exception.StorageConflictException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) ResourceInUseException(com.cloud.exception.ResourceInUseException) URISyntaxException(java.net.URISyntaxException) DiscoveryException(com.cloud.exception.DiscoveryException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) DataStoreLifeCycle(com.cloud.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) ClusterScope(com.cloud.engine.subsystem.api.storage.ClusterScope) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) PermissionDeniedException(com.cloud.exception.PermissionDeniedException)

Example 5 with PrimaryDataStoreInfo

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

the class VolumeApiServiceImpl method orchestrateAttachVolumeToVM.

private Volume orchestrateAttachVolumeToVM(final Long vmId, final Long volumeId, final Long deviceId) {
    final VolumeInfo volumeToAttach = volFactory.getVolume(volumeId);
    if (volumeToAttach.isAttachedVM()) {
        throw new CloudRuntimeException("This volume is already attached to a VM.");
    }
    UserVmVO vm = _userVmDao.findById(vmId);
    VolumeVO exstingVolumeOfVm = null;
    final List<VolumeVO> rootVolumesOfVm = _volsDao.findByInstanceAndType(vmId, Volume.Type.ROOT);
    if (rootVolumesOfVm.size() > 1) {
        throw new CloudRuntimeException("The VM " + vm.getHostName() + " has more than one ROOT volume and is in an invalid state.");
    } else {
        if (!rootVolumesOfVm.isEmpty()) {
            exstingVolumeOfVm = rootVolumesOfVm.get(0);
        } else {
            // locate data volume of the vm
            final List<VolumeVO> diskVolumesOfVm = _volsDao.findByInstanceAndType(vmId, Volume.Type.DATADISK);
            for (final VolumeVO diskVolume : diskVolumesOfVm) {
                if (diskVolume.getState() != Volume.State.Allocated) {
                    exstingVolumeOfVm = diskVolume;
                    break;
                }
            }
        }
    }
    final HypervisorType rootDiskHyperType = vm.getHypervisorType();
    final HypervisorType volumeToAttachHyperType = _volsDao.getHypervisorType(volumeToAttach.getId());
    VolumeInfo newVolumeOnPrimaryStorage = volumeToAttach;
    // don't create volume on primary storage if its being attached to the vm which Root's volume hasn't been created yet
    StoragePoolVO destPrimaryStorage = null;
    if (exstingVolumeOfVm != null && !exstingVolumeOfVm.getState().equals(Volume.State.Allocated)) {
        destPrimaryStorage = _storagePoolDao.findById(exstingVolumeOfVm.getPoolId());
    }
    final boolean volumeOnSecondary = volumeToAttach.getState() == Volume.State.Uploaded;
    if (destPrimaryStorage != null && (volumeToAttach.getState() == Volume.State.Allocated || volumeOnSecondary)) {
        try {
            newVolumeOnPrimaryStorage = _volumeMgr.createVolumeOnPrimaryStorage(vm, volumeToAttach, rootDiskHyperType, destPrimaryStorage);
        } catch (final NoTransitionException e) {
            s_logger.debug("Failed to create volume on primary storage", e);
            throw new CloudRuntimeException("Failed to create volume on primary storage", e);
        }
    }
    // reload the volume from db
    newVolumeOnPrimaryStorage = volFactory.getVolume(newVolumeOnPrimaryStorage.getId());
    final boolean moveVolumeNeeded = needMoveVolume(exstingVolumeOfVm, newVolumeOnPrimaryStorage);
    if (moveVolumeNeeded) {
        final PrimaryDataStoreInfo primaryStore = (PrimaryDataStoreInfo) newVolumeOnPrimaryStorage.getDataStore();
        if (primaryStore.isLocal()) {
            throw new CloudRuntimeException("Failed to attach local data volume " + volumeToAttach.getName() + " to VM " + vm.getDisplayName() + " as migration of local data volume is not allowed");
        }
        final StoragePoolVO vmRootVolumePool = _storagePoolDao.findById(exstingVolumeOfVm.getPoolId());
        try {
            newVolumeOnPrimaryStorage = _volumeMgr.moveVolume(newVolumeOnPrimaryStorage, vmRootVolumePool.getDataCenterId(), vmRootVolumePool.getPodId(), vmRootVolumePool.getClusterId(), volumeToAttachHyperType);
        } catch (final ConcurrentOperationException e) {
            s_logger.debug("move volume failed", e);
            throw new CloudRuntimeException("move volume failed", e);
        } catch (final StorageUnavailableException e) {
            s_logger.debug("move volume failed", e);
            throw new CloudRuntimeException("move volume failed", e);
        }
    }
    VolumeVO newVol = _volsDao.findById(newVolumeOnPrimaryStorage.getId());
    // Getting the fresh vm object in case of volume migration to check the current state of VM
    if (moveVolumeNeeded || volumeOnSecondary) {
        vm = _userVmDao.findById(vmId);
        if (vm == null) {
            throw new InvalidParameterValueException("VM not found.");
        }
    }
    newVol = sendAttachVolumeCommand(vm, newVol, deviceId);
    return newVol;
}
Also used : PrimaryDataStoreInfo(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreInfo) UserVmVO(com.cloud.vm.UserVmVO) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO)

Aggregations

PrimaryDataStoreInfo (com.cloud.engine.subsystem.api.storage.PrimaryDataStoreInfo)7 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)5 DataStoreLifeCycle (com.cloud.engine.subsystem.api.storage.DataStoreLifeCycle)4 DataStoreProvider (com.cloud.engine.subsystem.api.storage.DataStoreProvider)4 PrimaryDataStoreLifeCycle (com.cloud.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle)4 StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)3 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)3 StorageConflictException (com.cloud.exception.StorageConflictException)2 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)2 DB (com.cloud.utils.db.DB)2 URISyntaxException (java.net.URISyntaxException)2 HashMap (java.util.HashMap)2 DataCenterVO (com.cloud.dc.DataCenterVO)1 ClusterScope (com.cloud.engine.subsystem.api.storage.ClusterScope)1 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)1 ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)1 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1