use of com.emc.storageos.ceph.CephClient in project coprhd-controller by CoprHD.
the class CephUtils method ensureConnectToCeph.
private static void ensureConnectToCeph(StorageProvider storageProvider) throws Exception {
CephClientFactory factory = new CephClientFactory();
CephClient cephClient = factory.getClient(storageProvider.getIPAddress(), storageProvider.getUserName(), storageProvider.getPassword());
cephClient.close();
}
use of com.emc.storageos.ceph.CephClient in project coprhd-controller by CoprHD.
the class CephCommunicationInterface method scan.
@Override
public void scan(AccessProfile accessProfile) throws BaseCollectionException {
_log.info("Starting scan of Ceph StorageProvider. IP={}", accessProfile.getIpAddress());
StorageProvider provider = _dbClient.queryObject(StorageProvider.class, accessProfile.getSystemId());
StorageProvider.ConnectionStatus status = StorageProvider.ConnectionStatus.NOTCONNECTED;
Map<String, StorageSystemViewObject> storageSystemsCache = accessProfile.getCache();
String cephType = StorageSystem.Type.ceph.name();
try (CephClient cephClient = CephUtils.connectToCeph(_cephClientFactory, provider)) {
ClusterInfo clusterInfo = cephClient.getClusterInfo();
String systemNativeGUID = NativeGUIDGenerator.generateNativeGuid(cephType, clusterInfo.getFsid());
StorageSystemViewObject viewObject = storageSystemsCache.get(systemNativeGUID);
if (viewObject == null) {
viewObject = new StorageSystemViewObject();
}
viewObject.setDeviceType(cephType);
viewObject.addprovider(accessProfile.getSystemId().toString());
viewObject.setProperty(StorageSystemViewObject.SERIAL_NUMBER, clusterInfo.getFsid());
viewObject.setProperty(StorageSystemViewObject.STORAGE_NAME, systemNativeGUID);
viewObject.setProperty(StorageSystemViewObject.MODEL, "Ceph Storage Cluster");
// TODO It is possible to figure out more Ceph cluster details (version, alternative IPs, etc),
// but neither Java client, nor pure librados provide this info. Since Ceph (with clien libraries)
// is an open source project it is possible to extend its functionality, and then use it here
storageSystemsCache.put(systemNativeGUID, viewObject);
status = StorageProvider.ConnectionStatus.CONNECTED;
} catch (Exception e) {
_log.error(String.format("Exception was encountered when attempting to scan Ceph Instance %s", accessProfile.getIpAddress()), e);
throw CephException.exceptions.operationException(e);
} finally {
provider.setConnectionStatus(status.name());
_dbClient.updateObject(provider);
}
}
use of com.emc.storageos.ceph.CephClient in project coprhd-controller by CoprHD.
the class CephCommunicationInterface method discover.
@Override
public void discover(AccessProfile accessProfile) throws BaseCollectionException {
_log.info("Starting discovery of Ceph StorageProvider. IP={}", accessProfile.getIpAddress());
StorageSystem system = _dbClient.queryObject(StorageSystem.class, accessProfile.getSystemId());
List<StoragePool> newPools = new ArrayList<StoragePool>();
List<StoragePool> updatePools = new ArrayList<StoragePool>();
List<StoragePool> allPools = new ArrayList<StoragePool>();
String statusMsg = null;
try (CephClient cephClient = CephUtils.connectToCeph(_cephClientFactory, system)) {
system.setReachableStatus(true);
system.setSharedStorageCapacity(true);
ClusterInfo clusterInfo = cephClient.getClusterInfo();
List<PoolInfo> pools = cephClient.getPools();
for (PoolInfo pool : pools) {
String poolNativeGUID = NativeGUIDGenerator.generateNativeGuid(system, Long.toString(pool.getId()), NativeGUIDGenerator.POOL);
List<StoragePool> storagePools = CustomQueryUtility.queryActiveResourcesByAltId(_dbClient, StoragePool.class, "nativeGuid", poolNativeGUID);
StoragePool storagePool = null;
if (storagePools.isEmpty()) {
storagePool = new StoragePool();
storagePool.setId(URIUtil.createId(StoragePool.class));
storagePool.setNativeId(Long.toString(pool.getId()));
storagePool.setNativeGuid(poolNativeGUID);
storagePool.setPoolName(pool.getName());
storagePool.setLabel(pool.getName());
storagePool.setStorageDevice(system.getId());
storagePool.setCompatibilityStatus(CompatibilityStatus.COMPATIBLE.name());
storagePool.setPoolServiceType(PoolServiceType.block.toString());
storagePool.setSupportedResourceTypes(SupportedResourceTypes.THIN_ONLY.name());
storagePool.setThinVolumePreAllocationSupported(false);
storagePool.addProtocols(RBD_ONLY);
storagePool.setSupportedCopyTypes(COPY_TYPES);
storagePool.setOperationalStatus(PoolOperationalStatus.READY.name());
storagePool.setDiscoveryStatus(DiscoveryStatus.VISIBLE.name());
storagePool.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
storagePool.setMinimumThinVolumeSize(MINIMAL_VOLUME_SIZE);
// Ceph does not limit maximum volume size, but a limitation is required by CoprHD
// to allow volume creating
storagePool.setMaximumThinVolumeSize(MAXIMAL_VOLUME_SIZE);
newPools.add(storagePool);
} else if (storagePools.size() == 1) {
storagePool = storagePools.get(0);
updatePools.add(storagePool);
} else {
_log.warn("There are {} StoragePools with nativeGuid = {}", storagePools.size(), poolNativeGUID);
continue;
}
storagePool.setFreeCapacity(clusterInfo.getKbAvail());
storagePool.setTotalCapacity(clusterInfo.getKb());
}
StoragePoolAssociationHelper.setStoragePoolVarrays(system.getId(), newPools, _dbClient);
allPools.addAll(newPools);
allPools.addAll(updatePools);
DiscoveryUtils.checkStoragePoolsNotVisible(allPools, _dbClient, system.getId());
_dbClient.createObject(newPools);
_dbClient.updateObject(updatePools);
String adapterNativeGUID = NativeGUIDGenerator.generateNativeGuid(system, "-", NativeGUIDGenerator.ADAPTER);
List<StorageHADomain> storageAdapters = CustomQueryUtility.queryActiveResourcesByAltId(_dbClient, StorageHADomain.class, "nativeGuid", adapterNativeGUID);
StorageHADomain storageHADomain = null;
if (storageAdapters.isEmpty()) {
storageHADomain = new StorageHADomain();
storageHADomain.setId(URIUtil.createId(StorageHADomain.class));
storageHADomain.setStorageDeviceURI(system.getId());
storageHADomain.setNativeGuid(adapterNativeGUID);
String monitorHost = accessProfile.getIpAddress();
storageHADomain.setAdapterName(monitorHost);
storageHADomain.setName(monitorHost);
storageHADomain.setLabel(monitorHost);
storageHADomain.setNumberofPorts("1");
storageHADomain.setAdapterType(HADomainType.FRONTEND.name());
storageHADomain.setProtocol(Block.RBD.name());
_dbClient.createObject(storageHADomain);
} else {
storageHADomain = storageAdapters.get(0);
if (storageAdapters.size() != 1) {
_log.warn("There are {} StorageHADomains with nativeGuid = {}", storageAdapters.size(), adapterNativeGUID);
}
}
String portNativeGUID = NativeGUIDGenerator.generateNativeGuid(system, "-", NativeGUIDGenerator.PORT);
List<StoragePort> storagePorts = CustomQueryUtility.queryActiveResourcesByAltId(_dbClient, StoragePort.class, "nativeGuid", portNativeGUID);
StoragePort storagePort = null;
if (storagePorts.isEmpty()) {
storagePort = new StoragePort();
storagePort.setId(URIUtil.createId(StoragePort.class));
storagePort.setNativeGuid(portNativeGUID);
storagePort.setPortNetworkId(portNativeGUID);
storagePort.setPortName(PORT_NAME);
storagePort.setPortGroup(PORT_GROUP);
storagePort.setStorageDevice(system.getId());
storagePort.setStorageHADomain(storageHADomain.getId());
storagePort.setPortType(PortType.frontend.name());
storagePort.setTransportType(Transport.IP.name());
// TODO Neither Java client, nor pure librados provide details about Ceph status, though,
// it is possible to extend Ceph client (librados and Java library) functionality, and then use it here
storagePort.setOperationalStatus(OperationalStatus.OK.name());
storagePort.setCompatibilityStatus(CompatibilityStatus.COMPATIBLE.name());
storagePort.setDiscoveryStatus(DiscoveryStatus.VISIBLE.name());
storagePort.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
_dbClient.createObject(storagePort);
} else {
storagePort = storagePorts.get(0);
if (storagePorts.size() != 1) {
_log.warn("There are {} StoragePorts with nativeGuid = {}", storagePorts.size(), portNativeGUID);
}
}
StoragePortAssociationHelper.runUpdatePortAssociationsProcess(Collections.singletonList(storagePort), null, _dbClient, _coordinator, allPools);
statusMsg = String.format("Discovery completed successfully for Storage System: %s", system.getNativeGuid());
} catch (Exception e) {
system.setReachableStatus(false);
_log.error(String.format("Exception was encountered when attempting to discover Ceph Instance %s", accessProfile.getIpAddress()), e);
statusMsg = String.format("Discovery failed because %s", e.getLocalizedMessage());
throw CephException.exceptions.operationException(e);
} finally {
if (system != null) {
system.setLastDiscoveryStatusMessage(statusMsg);
_dbClient.updateObject(system);
}
}
}
use of com.emc.storageos.ceph.CephClient in project coprhd-controller by CoprHD.
the class CephStorageDevice method doExpandVolume.
@Override
public void doExpandVolume(StorageSystem storage, StoragePool pool, Volume volume, Long size, TaskCompleter taskCompleter) throws DeviceControllerException {
try (CephClient cephClient = getClient(storage)) {
cephClient.resizeImage(pool.getPoolName(), volume.getNativeId(), size);
volume.setProvisionedCapacity(size);
volume.setAllocatedCapacity(size);
volume.setCapacity(size);
_dbClient.updateObject(volume);
taskCompleter.ready(_dbClient);
} catch (Exception e) {
_log.error("Error while expanding volumes", e);
ServiceCoded code = DeviceControllerErrors.ceph.operationFailed("expandVolume", e.getMessage());
taskCompleter.error(_dbClient, code);
}
}
use of com.emc.storageos.ceph.CephClient in project coprhd-controller by CoprHD.
the class CephStorageDevice method doDeleteVolumes.
@Override
public void doDeleteVolumes(StorageSystem storage, String opId, List<Volume> volumes, TaskCompleter taskCompleter) throws DeviceControllerException {
HashMap<URI, String> pools = new HashMap<URI, String>();
try (CephClient cephClient = getClient(storage)) {
for (Volume volume : volumes) {
if (volume.getNativeId() != null && !volume.getNativeId().isEmpty()) {
URI poolUri = volume.getPool();
String poolName = pools.get(poolUri);
if (poolName == null) {
StoragePool pool = _dbClient.queryObject(StoragePool.class, poolUri);
poolName = pool.getPoolName();
pools.put(poolUri, poolName);
}
cephClient.deleteImage(poolName, volume.getNativeId());
} else {
_log.info("Volume {} was not created completely, so skipping deletion from ceph array and just deleting from the controller's inventory", volume.getLabel());
}
volume.setInactive(true);
_dbClient.updateObject(volume);
}
taskCompleter.ready(_dbClient);
} catch (Exception e) {
_log.error("Error while deleting volumes", e);
ServiceCoded code = DeviceControllerErrors.ceph.operationFailed("deleteVolume", e.getMessage());
taskCompleter.error(_dbClient, code);
}
}
Aggregations