use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.
the class SolidFireHostListener method getTargets.
private List<Map<String, String>> getTargets(long clusterId, long storagePoolId) {
List<Map<String, String>> targets = new ArrayList<>();
StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId);
// If you do not pass in null for the second parameter, you only get back applicable ROOT disks.
List<VolumeVO> volumes = volumeDao.findByPoolId(storagePoolId, null);
if (volumes != null) {
for (VolumeVO volume : volumes) {
Long instanceId = volume.getInstanceId();
if (instanceId != null) {
VMInstanceVO vmInstance = vmDao.findById(instanceId);
Long hostIdForVm = vmInstance.getHostId() != null ? vmInstance.getHostId() : vmInstance.getLastHostId();
if (hostIdForVm != null) {
HostVO hostForVm = hostDao.findById(hostIdForVm);
if (hostForVm.getClusterId().equals(clusterId)) {
Map<String, String> details = new HashMap<>();
details.put(ModifyTargetsCommand.IQN, volume.get_iScsiName());
details.put(ModifyTargetsCommand.STORAGE_HOST, storagePool.getHostAddress());
details.put(ModifyTargetsCommand.STORAGE_PORT, String.valueOf(storagePool.getPort()));
targets.add(details);
}
}
}
}
}
return targets;
}
use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.
the class SolidFireHostListener method handleVMware.
private void handleVMware(HostVO host, boolean add, ModifyTargetsCommand.TargetTypeToRemove targetTypeToRemove) {
if (host != null && HypervisorType.VMware.equals(host.getHypervisorType())) {
List<StoragePoolVO> storagePools = storagePoolDao.findPoolsByProvider(SolidFireUtil.PROVIDER_NAME);
if (storagePools != null && storagePools.size() > 0) {
List<Map<String, String>> targets = new ArrayList<>();
for (StoragePoolVO storagePool : storagePools) {
List<Map<String, String>> targetsForClusterAndStoragePool = getTargets(host.getClusterId(), storagePool.getId());
targets.addAll(targetsForClusterAndStoragePool);
}
ModifyTargetsCommand cmd = new ModifyTargetsCommand();
cmd.setTargets(targets);
cmd.setAdd(add);
cmd.setTargetTypeToRemove(targetTypeToRemove);
cmd.setRemoveAsync(true);
sendModifyTargetsCommand(cmd, host.getId());
}
}
}
use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.
the class SolidFireSharedHostListener method hostConnect.
@Override
public boolean hostConnect(long hostId, long storagePoolId) {
StoragePool storagePool = (StoragePool) dataStoreMgr.getDataStore(storagePoolId, DataStoreRole.Primary);
ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, storagePool);
ModifyStoragePoolAnswer answer = sendModifyStoragePoolCommand(cmd, storagePool, hostId);
StoragePoolHostVO storagePoolHost = storagePoolHostDao.findByPoolHost(storagePoolId, hostId);
if (storagePoolHost != null) {
storagePoolHost.setLocalPath(answer.getPoolInfo().getLocalPath().replaceAll("//", "/"));
} else {
storagePoolHost = new StoragePoolHostVO(storagePoolId, hostId, answer.getPoolInfo().getLocalPath().replaceAll("//", "/"));
storagePoolHostDao.persist(storagePoolHost);
}
StoragePoolVO storagePoolVO = storagePoolDao.findById(storagePoolId);
storagePoolVO.setCapacityBytes(answer.getPoolInfo().getCapacityBytes());
storagePoolVO.setUsedBytes(answer.getPoolInfo().getCapacityBytes() - answer.getPoolInfo().getAvailableBytes());
storagePoolDao.update(storagePoolId, storagePoolVO);
return true;
}
use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.
the class ConfigurationManagerImpl method resetConfiguration.
@Override
@ActionEvent(eventType = EventTypes.EVENT_CONFIGURATION_VALUE_EDIT, eventDescription = "resetting configuration")
public Pair<Configuration, String> resetConfiguration(final ResetCfgCmd cmd) throws InvalidParameterValueException {
final Long userId = CallContext.current().getCallingUserId();
final String name = cmd.getCfgName();
final Long zoneId = cmd.getZoneId();
final Long clusterId = cmd.getClusterId();
final Long storagepoolId = cmd.getStoragepoolId();
final Long accountId = cmd.getAccountId();
final Long domainId = cmd.getDomainId();
final Long imageStoreId = cmd.getImageStoreId();
Optional optionalValue;
final ConfigKey<?> configKey = _configDepot.get(name);
if (configKey == null) {
s_logger.warn("Probably the component manager where configuration variable " + name + " is defined needs to implement Configurable interface");
throw new InvalidParameterValueException("Config parameter with name " + name + " doesn't exist");
}
String defaultValue = configKey.defaultValue();
String category = configKey.category();
String configScope = configKey.scope().toString();
String scope = "";
Map<String, Long> scopeMap = new LinkedHashMap<>();
Long id = null;
int paramCountCheck = 0;
scopeMap.put(ConfigKey.Scope.Zone.toString(), zoneId);
scopeMap.put(ConfigKey.Scope.Cluster.toString(), clusterId);
scopeMap.put(ConfigKey.Scope.Domain.toString(), domainId);
scopeMap.put(ConfigKey.Scope.Account.toString(), accountId);
scopeMap.put(ConfigKey.Scope.StoragePool.toString(), storagepoolId);
scopeMap.put(ConfigKey.Scope.ImageStore.toString(), imageStoreId);
ParamCountPair paramCountPair = getParamCount(scopeMap);
id = paramCountPair.getId();
paramCountCheck = paramCountPair.getParamCount();
scope = paramCountPair.getScope();
if (paramCountCheck > 1) {
throw new InvalidParameterValueException("cannot handle multiple IDs, provide only one ID corresponding to the scope");
}
if (scope != null && !scope.equals(ConfigKey.Scope.Global.toString()) && !configScope.contains(scope)) {
throw new InvalidParameterValueException("Invalid scope id provided for the parameter " + name);
}
String newValue = null;
switch(ConfigKey.Scope.valueOf(scope)) {
case Zone:
final DataCenterVO zone = _zoneDao.findById(id);
if (zone == null) {
throw new InvalidParameterValueException("unable to find zone by id " + id);
}
_dcDetailsDao.removeDetail(id, name);
optionalValue = Optional.ofNullable(configKey.valueIn(id));
newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
break;
case Cluster:
final ClusterVO cluster = _clusterDao.findById(id);
if (cluster == null) {
throw new InvalidParameterValueException("unable to find cluster by id " + id);
}
ClusterDetailsVO clusterDetailsVO = _clusterDetailsDao.findDetail(id, name);
newValue = configKey.value().toString();
if (name.equalsIgnoreCase("cpu.overprovisioning.factor") || name.equalsIgnoreCase("mem.overprovisioning.factor")) {
_clusterDetailsDao.persist(id, name, newValue);
} else if (clusterDetailsVO != null) {
_clusterDetailsDao.remove(clusterDetailsVO.getId());
}
optionalValue = Optional.ofNullable(configKey.valueIn(id));
newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
break;
case StoragePool:
final StoragePoolVO pool = _storagePoolDao.findById(id);
if (pool == null) {
throw new InvalidParameterValueException("unable to find storage pool by id " + id);
}
_storagePoolDetailsDao.removeDetail(id, name);
optionalValue = Optional.ofNullable(configKey.valueIn(id));
newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
break;
case Domain:
final DomainVO domain = _domainDao.findById(id);
if (domain == null) {
throw new InvalidParameterValueException("unable to find domain by id " + id);
}
DomainDetailVO domainDetailVO = _domainDetailsDao.findDetail(id, name);
if (domainDetailVO != null) {
_domainDetailsDao.remove(domainDetailVO.getId());
}
optionalValue = Optional.ofNullable(configKey.valueIn(id));
newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
break;
case Account:
final AccountVO account = _accountDao.findById(id);
if (account == null) {
throw new InvalidParameterValueException("unable to find account by id " + id);
}
AccountDetailVO accountDetailVO = _accountDetailsDao.findDetail(id, name);
if (accountDetailVO != null) {
_accountDetailsDao.remove(accountDetailVO.getId());
}
optionalValue = Optional.ofNullable(configKey.valueIn(id));
newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
break;
case ImageStore:
final ImageStoreVO imageStoreVO = _imageStoreDao.findById(id);
if (imageStoreVO == null) {
throw new InvalidParameterValueException("unable to find the image store by id " + id);
}
ImageStoreDetailVO imageStoreDetailVO = _imageStoreDetailsDao.findDetail(id, name);
if (imageStoreDetailVO != null) {
_imageStoreDetailsDao.remove(imageStoreDetailVO.getId());
}
optionalValue = Optional.ofNullable(configKey.valueIn(id));
newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
break;
default:
if (!_configDao.update(name, category, defaultValue)) {
s_logger.error("Failed to reset configuration option, name: " + name + ", defaultValue:" + defaultValue);
throw new CloudRuntimeException("Failed to reset configuration value. Please contact Cloud Support.");
}
optionalValue = Optional.ofNullable(configKey.value());
newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue;
}
CallContext.current().setEventDetails(" Name: " + name + " New Value: " + (name.toLowerCase().contains("password") ? "*****" : defaultValue == null ? "" : defaultValue));
return new Pair<Configuration, String>(_configDao.findByName(name), newValue);
}
use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.
the class VolumeTest method createPrimaryDataStore.
public DataStore createPrimaryDataStore() {
try {
List<StoragePoolVO> pools = primaryDataStoreDao.findPoolByName(this.primaryName);
if (pools.size() > 0) {
return this.dataStoreMgr.getPrimaryDataStore(pools.get(0).getId());
}
/*
* DataStoreProvider provider =
* dataStoreProviderMgr.getDataStoreProvider
* ("cloudstack primary data store provider"); Map<String, Object>
* params = new HashMap<String, Object>(); URI uri = new
* URI(this.getPrimaryStorageUrl()); params.put("url",
* this.getPrimaryStorageUrl()); params.put("server",
* uri.getHost()); params.put("path", uri.getPath());
* params.put("protocol",
* Storage.StoragePoolType.NetworkFilesystem); params.put("zoneId",
* dcId); params.put("clusterId", clusterId); params.put("name",
* this.primaryName); params.put("port", 1); params.put("podId",
* this.podId); params.put("roles",
* DataStoreRole.Primary.toString()); params.put("uuid", uuid);
* params.put("providerName", String.valueOf(provider.getName()));
*
* DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
* DataStore store = lifeCycle.initialize(params); ClusterScope
* scope = new ClusterScope(clusterId, podId, dcId);
* lifeCycle.attachCluster(store, scope);
*/
StoragePoolVO pool = new StoragePoolVO();
pool.setClusterId(clusterId);
pool.setDataCenterId(dcId);
URI uri = new URI(this.getPrimaryStorageUrl());
pool.setHostAddress(uri.getHost());
pool.setPath(uri.getPath());
pool.setPort(0);
pool.setName(this.primaryName);
pool.setUuid(this.getPrimaryStorageUuid());
pool.setStatus(StoragePoolStatus.Up);
pool.setPoolType(StoragePoolType.NetworkFilesystem);
pool.setPodId(podId);
pool.setScope(ScopeType.CLUSTER);
pool.setStorageProviderName(DataStoreProvider.DEFAULT_PRIMARY);
pool = this.primaryStoreDao.persist(pool);
DataStore store = this.dataStoreMgr.getPrimaryDataStore(pool.getId());
return store;
} catch (Exception e) {
return null;
}
}
Aggregations