use of com.cloud.legacymodel.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);
}
use of com.cloud.legacymodel.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(HostType.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;
}
use of com.cloud.legacymodel.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 = this._dataStoreProviderMgr.getDataStoreProvider(providerName);
if (storeProvider == null) {
storeProvider = this._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 = this._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() && !this._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) this._dataStoreMgr.getDataStore(store.getId(), DataStoreRole.Primary);
}
use of com.cloud.legacymodel.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 = this._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 = this._dataStoreProviderMgr.getDataStoreProvider(primaryStorage.getStorageProviderName());
final DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
final DataStore store = this._dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
lifeCycle.cancelMaintain(store);
return (PrimaryDataStoreInfo) this._dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
}
use of com.cloud.legacymodel.storage.PrimaryDataStoreInfo in project cosmic by MissionCriticalCloud.
the class StorageManagerImpl method updateStoragePool.
@Override
public PrimaryDataStoreInfo updateStoragePool(final UpdateStoragePoolCmd cmd) throws IllegalArgumentException {
// Input validation
final Long id = cmd.getId();
final List<String> tags = cmd.getTags();
final StoragePoolVO pool = this._storagePoolDao.findById(id);
if (pool == null) {
throw new IllegalArgumentException("Unable to find storage pool with ID: " + id);
}
final Map<String, String> updatedDetails = new HashMap<>();
if (tags != null) {
final Map<String, String> existingDetails = this._storagePoolDetailsDao.listDetailsKeyPairs(id);
final Set<String> existingKeys = existingDetails.keySet();
final Map<String, String> existingDetailsToKeep = new HashMap<>();
for (final String existingKey : existingKeys) {
final String existingValue = existingDetails.get(existingKey);
if (!Boolean.TRUE.toString().equalsIgnoreCase(existingValue)) {
existingDetailsToKeep.put(existingKey, existingValue);
}
}
final Map<String, String> details = new HashMap<>();
for (String tag : tags) {
tag = tag.trim();
if (tag.length() > 0 && !details.containsKey(tag)) {
details.put(tag, "true");
}
}
final Set<String> existingKeysToKeep = existingDetailsToKeep.keySet();
for (final String existingKeyToKeep : existingKeysToKeep) {
final String existingValueToKeep = existingDetailsToKeep.get(existingKeyToKeep);
if (details.containsKey(existingKeyToKeep)) {
throw new CloudRuntimeException("Storage tag '" + existingKeyToKeep + "' conflicts with a stored property of this primary storage. No changes were made.");
}
details.put(existingKeyToKeep, existingValueToKeep);
}
updatedDetails.putAll(details);
}
Long updatedCapacityBytes = null;
final Long capacityBytes = cmd.getCapacityBytes();
if (capacityBytes != null) {
if (capacityBytes != pool.getCapacityBytes()) {
updatedCapacityBytes = capacityBytes;
}
}
Long updatedCapacityIops = null;
final Long capacityIops = cmd.getCapacityIops();
if (capacityIops != null) {
if (!capacityIops.equals(pool.getCapacityIops())) {
updatedCapacityIops = capacityIops;
}
}
if (updatedCapacityBytes != null || updatedCapacityIops != null) {
final StoragePoolVO storagePool = this._storagePoolDao.findById(id);
final DataStoreProvider dataStoreProvider = this._dataStoreProviderMgr.getDataStoreProvider(storagePool.getStorageProviderName());
final DataStoreLifeCycle dataStoreLifeCycle = dataStoreProvider.getDataStoreLifeCycle();
if (dataStoreLifeCycle instanceof PrimaryDataStoreLifeCycle) {
final Map<String, String> details = new HashMap<>();
details.put(PrimaryDataStoreLifeCycle.CAPACITY_BYTES, updatedCapacityBytes != null ? String.valueOf(updatedCapacityBytes) : null);
details.put(PrimaryDataStoreLifeCycle.CAPACITY_IOPS, updatedCapacityIops != null ? String.valueOf(updatedCapacityIops) : null);
((PrimaryDataStoreLifeCycle) dataStoreLifeCycle).updateStoragePool(storagePool, details);
}
}
final Boolean enabled = cmd.getEnabled();
if (enabled != null) {
if (enabled) {
enablePrimaryStoragePool(pool);
} else {
disablePrimaryStoragePool(pool);
}
} else if (updatedDetails.size() >= 0) {
this._storagePoolDao.updateDetails(id, updatedDetails);
}
if (updatedCapacityBytes != null) {
this._storagePoolDao.updateCapacityBytes(id, capacityBytes);
}
if (updatedCapacityIops != null) {
this._storagePoolDao.updateCapacityIops(id, capacityIops);
}
return (PrimaryDataStoreInfo) this._dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
}
Aggregations