use of com.emc.storageos.cinder.api.CinderApi in project coprhd-controller by CoprHD.
the class CinderCommunicationInterface method discover.
/**
* Get volume types, and create a storage pool for each volume type
*/
@Override
public void discover(AccessProfile accessProfile) throws BaseCollectionException {
if ((null != accessProfile.getnamespace()) && (accessProfile.getnamespace().equals(StorageSystem.Discovery_Namespaces.UNMANAGED_VOLUMES.toString()))) {
discoverUnManagedVolumes(accessProfile);
} else {
_logger.info("Discovery started for system {}", accessProfile.getSystemId());
List<StoragePool> newPools = new ArrayList<StoragePool>();
List<StoragePool> updatePools = new ArrayList<StoragePool>();
List<StoragePool> allPools = new ArrayList<StoragePool>();
String token = "";
StorageSystem system = null;
StorageProvider provider = null;
String detailedStatusMessage = "Unknown Status";
try {
String hostName = null;
String restuserName = null;
String restPassword = null;
String restBaseUri = null;
String tenantName = null;
String oldToken = null;
String tenantId = null;
system = _dbClient.queryObject(StorageSystem.class, accessProfile.getSystemId());
system.setReachableStatus(true);
// first add storage ports if necessary
addPorts(system);
// now do the pool discovery
URI providerUri = system.getActiveProviderURI();
provider = _dbClient.queryObject(StorageProvider.class, providerUri);
if (null != provider.getKeys()) {
StringMap providerKeys = provider.getKeys();
oldToken = providerKeys.get(CinderConstants.KEY_CINDER_REST_TOKEN);
hostName = providerKeys.get(CinderConstants.KEY_CINDER_HOST_NAME);
restuserName = providerKeys.get(CinderConstants.KEY_CINDER_REST_USER);
restPassword = providerKeys.get(CinderConstants.KEY_CINDER_REST_PASSWORD);
restBaseUri = providerKeys.get(CinderConstants.KEY_CINDER_REST_URI_BASE);
tenantName = providerKeys.get(CinderConstants.KEY_CINDER_TENANT_NAME);
tenantId = providerKeys.get(CinderConstants.KEY_CINDER_TENANT_ID);
}
if (null == endPointInfo) {
endPointInfo = new CinderEndPointInfo(hostName, restuserName, restPassword, tenantName);
if (restBaseUri.startsWith(CinderConstants.HTTP_URL)) {
endPointInfo.setCinderBaseUriHttp(restBaseUri);
} else {
endPointInfo.setCinderBaseUriHttps(restBaseUri);
}
// Always set the token and tenant id, when new instance is created
endPointInfo.setCinderToken(oldToken);
endPointInfo.setCinderTenantId(tenantId);
}
CinderApi api = _cinderApiFactory.getApi(providerUri, endPointInfo);
_logger.debug("discover : Got the cinder api factory for provider with id: {}", providerUri);
// check if the cinder is authenticated and if the token is valid
if (null == oldToken || (isTokenExpired(oldToken))) {
// This means, authentication is required, go and fetch the token
token = api.getAuthToken(restBaseUri + "/tokens");
if (null != token) {
_logger.debug("Got new token : {}", token);
// update the token in the provider
provider.addKey(CinderConstants.KEY_CINDER_REST_TOKEN, token);
provider.addKey(CinderConstants.KEY_CINDER_TENANT_ID, endPointInfo.getCinderTenantId());
}
} else {
token = oldToken;
_logger.debug("Using the old token : {}", token);
}
if (token.length() > 1) {
// Now get the number of volume types
VolumeTypes types = api.getVolumeTypes();
if (types != null) {
_logger.info("Got {} Volume Type(s)", types.volume_types.length);
boolean isDefaultStoragePoolCreated = false;
for (int i = 0; i < types.volume_types.length; i++) {
boolean isNew = false;
String poolName = types.volume_types[i].name;
String nativeGuid = types.volume_types[i].id;
_logger.info("Storage Pool name = {}, id = {}", poolName, nativeGuid);
// Now find association with storage system
Map<String, String> extra_specs = types.volume_types[i].extra_specs;
String system_title = extra_specs.get(VOLUME_BACKEND_NAME);
boolean isThickPool = Boolean.parseBoolean(extra_specs.get(VIPR_THICK_POOL));
// If no volume backend name, use default
if (system_title == null) {
system_title = CinderConstants.DEFAULT;
}
if (system.getNativeGuid().toUpperCase().contains(system_title.toUpperCase())) {
// Check if volume type belongs to the default storage system
if (system.getNativeGuid().toUpperCase().startsWith(CinderConstants.DEFAULT)) {
isDefaultStoragePoolCreated = true;
}
// do the association
_logger.info("Found association between system {} and pool {}", system_title, poolName);
StoragePool pool = checkPoolExistsInDB(nativeGuid);
if (null == pool) {
isNew = true;
pool = createPoolforStorageSystem(system, nativeGuid, poolName, isThickPool);
newPools.add(pool);
}
pool.setPoolName(poolName);
pool.setCompatibilityStatus(CompatibilityStatus.COMPATIBLE.name());
pool.setDiscoveryStatus(DiscoveryStatus.VISIBLE.name());
if (!isNew) {
updatePools.add(pool);
}
} else {
_logger.info("Pool {} doesn't belong to storage system {}", poolName, system.getLabel());
}
}
// create default storage pool for storage system
if (system.getNativeGuid().toUpperCase().startsWith(CinderConstants.DEFAULT) && !isDefaultStoragePoolCreated) {
_logger.debug("Creating defual pool for default storage system");
String nativeGuid = "DefaultPool";
StoragePool pool = checkPoolExistsInDB(nativeGuid);
String poolName = "DefaultPool";
if (null != pool) {
updatePools.add(pool);
} else {
pool = createPoolforStorageSystem(system, nativeGuid, poolName, false);
newPools.add(pool);
}
pool.setPoolName(poolName);
pool.setCompatibilityStatus(CompatibilityStatus.COMPATIBLE.name());
pool.setDiscoveryStatus(DiscoveryStatus.VISIBLE.name());
}
StoragePoolAssociationHelper.setStoragePoolVarrays(system.getId(), newPools, _dbClient);
allPools.addAll(newPools);
allPools.addAll(updatePools);
StringBuffer errorMessage = new StringBuffer();
ImplicitPoolMatcher.matchModifiedStoragePoolsWithAllVpool(allPools, _dbClient, _coordinator, accessProfile.getSystemId(), errorMessage);
_logger.info("New pools size: {}", newPools.size());
_logger.info("updatePools size: {}", updatePools.size());
DiscoveryUtils.checkStoragePoolsNotVisible(allPools, _dbClient, system.getId());
_dbClient.createObject(newPools);
_dbClient.persistObject(updatePools);
// discovery succeeds
detailedStatusMessage = String.format("Discovery completed successfully for OpenStack: %s", accessProfile.getSystemId());
} else /* if types */
{
_logger.error("Error in getting volume types from cinder");
}
} else /* if token length */
{
_logger.error("Error in getting token from keystone");
}
} catch (Exception e) {
if (null != system) {
cleanupDiscovery(system);
}
detailedStatusMessage = String.format("Discovery failed for Storage System: %s because %s", system.toString(), e.getLocalizedMessage());
_logger.error(detailedStatusMessage, e);
throw new CinderColletionException(false, ServiceCode.DISCOVERY_ERROR, null, detailedStatusMessage, null, null);
} finally {
try {
if (system != null) {
system.setLastDiscoveryStatusMessage(detailedStatusMessage);
_dbClient.persistObject(system);
}
// persist the provider
if (null != provider) {
_dbClient.persistObject(provider);
}
} catch (DatabaseException e) {
_logger.error("Failed to persist cinder storage system to Database, Reason: {}", e.getMessage(), e);
}
}
_logger.info("Discovery Ended for system {}", accessProfile.getSystemId());
}
}
use of com.emc.storageos.cinder.api.CinderApi in project coprhd-controller by CoprHD.
the class CinderExportOperations method detachVolumesFromInitiators.
/**
* Detaches volumes from initiators.
*
* @param storage
* the storage
* @param volumes
* the volumes
* @param initiators
* the initiators
* @throws Exception
* the exception
*/
private void detachVolumesFromInitiators(StorageSystem storage, List<Volume> volumes, List<Initiator> initiators) throws Exception {
CinderEndPointInfo ep = CinderUtils.getCinderEndPoint(storage.getActiveProviderURI(), dbClient);
log.debug("Getting the cinder APi for the provider with id {}", storage.getActiveProviderURI());
CinderApi cinderApi = cinderApiFactory.getApi(storage.getActiveProviderURI(), ep);
List<Initiator> iSCSIInitiators = new ArrayList<Initiator>();
List<Initiator> fcInitiators = new ArrayList<Initiator>();
splitInitiatorsByProtocol(initiators, iSCSIInitiators, fcInitiators);
String host = getHostNameFromInitiators(initiators);
Map<String, String[]> mapSettingVsValues = getFCInitiatorsArray(fcInitiators);
String[] fcInitiatorsWwpns = mapSettingVsValues.get(WWPNS);
String[] fcInitiatorsWwnns = mapSettingVsValues.get(WWNNS);
for (Volume volume : volumes) {
// cinder generated volume ID
String volumeId = volume.getNativeId();
// for iSCSI
for (Initiator initiator : iSCSIInitiators) {
String initiatorPort = initiator.getInitiatorPort();
log.debug(String.format("Detaching volume %s ( %s ) from initiator %s on Openstack cinder node", volumeId, volume.getId(), initiatorPort));
cinderApi.detachVolume(volumeId, initiatorPort, null, null, host);
// TODO : Do not use Job to poll status till we figure out how
// to get detach status.
/*
* CinderJob detachJob = new CinderDetachVolumeJob(volumeId,
* volume.getLabel(), storage.getId(),
* CinderConstants.ComponentType.volume.name(), ep,
* taskCompleter); ControllerServiceImpl.enqueueJob(new
* QueueJob(detachJob));
*/
}
// for FC
if (fcInitiatorsWwpns.length > 0) {
log.debug(String.format("Detaching volume %s ( %s ) from initiator %s on Openstack cinder node", volumeId, volume.getId(), fcInitiatorsWwpns));
cinderApi.detachVolume(volumeId, null, fcInitiatorsWwpns, fcInitiatorsWwnns, host);
}
// If ITLs are added, remove them
removeITLsFromVolume(volume);
}
}
use of com.emc.storageos.cinder.api.CinderApi in project coprhd-controller by CoprHD.
the class CinderExportOperations method attachVolumesToInitiators.
/**
* Attaches volumes to initiators.
*
* @param storage
* the storage
* @param volumes
* the volumes
* @param initiators
* the initiators
* @param volumeToTargetLunMap
* the volume to target lun map
* @throws Exception
* the exception
*/
private void attachVolumesToInitiators(StorageSystem storage, List<Volume> volumes, List<Initiator> initiators, Map<URI, Integer> volumeToTargetLunMap, Map<Volume, Map<String, List<String>>> volumeToInitiatorTargetMap, ExportMask exportMask) throws Exception {
CinderEndPointInfo ep = CinderUtils.getCinderEndPoint(storage.getActiveProviderURI(), dbClient);
log.debug("Getting the cinder APi for the provider with id {}", storage.getActiveProviderURI());
CinderApi cinderApi = cinderApiFactory.getApi(storage.getActiveProviderURI(), ep);
List<Initiator> iSCSIInitiators = new ArrayList<Initiator>();
List<Initiator> fcInitiators = new ArrayList<Initiator>();
splitInitiatorsByProtocol(initiators, iSCSIInitiators, fcInitiators);
String host = getHostNameFromInitiators(initiators);
Map<String, String[]> mapSettingVsValues = getFCInitiatorsArray(fcInitiators);
String[] fcInitiatorsWwpns = mapSettingVsValues.get(WWPNS);
String[] fcInitiatorsWwnns = mapSettingVsValues.get(WWNNS);
for (Volume volume : volumes) {
// cinder generated volume ID
String volumeId = volume.getNativeId();
int targetLunId = -1;
VolumeAttachResponse attachResponse = null;
// for iSCSI
for (Initiator initiator : iSCSIInitiators) {
String initiatorPort = initiator.getInitiatorPort();
log.debug(String.format("Attaching volume %s ( %s ) to initiator %s on Openstack cinder node", volumeId, volume.getId(), initiatorPort));
attachResponse = cinderApi.attachVolume(volumeId, initiatorPort, null, null, host);
log.info("Got response : {}", attachResponse.connection_info.toString());
targetLunId = attachResponse.connection_info.data.target_lun;
}
// for FC
if (fcInitiatorsWwpns.length > 0) {
log.debug(String.format("Attaching volume %s ( %s ) to initiators %s on Openstack cinder node", volumeId, volume.getId(), fcInitiatorsWwpns));
attachResponse = cinderApi.attachVolume(volumeId, null, fcInitiatorsWwpns, fcInitiatorsWwnns, host);
log.info("Got response : {}", attachResponse.connection_info.toString());
targetLunId = attachResponse.connection_info.data.target_lun;
Map<String, List<String>> initTargetMap = attachResponse.connection_info.data.initiator_target_map;
if (null != initTargetMap && !initTargetMap.isEmpty()) {
volumeToInitiatorTargetMap.put(volume, attachResponse.connection_info.data.initiator_target_map);
}
}
volumeToTargetLunMap.put(volume.getId(), targetLunId);
// After the successful export, create or modify the storage ports
CinderStoragePortOperations storagePortOperationsInstance = CinderStoragePortOperations.getInstance(storage, dbClient);
storagePortOperationsInstance.invoke(attachResponse);
}
// Add ITLs to volume objects
storeITLMappingInVolume(volumeToTargetLunMap, exportMask);
}
use of com.emc.storageos.cinder.api.CinderApi in project coprhd-controller by CoprHD.
the class CinderStorageDevice method doDeleteSnapshot.
/*
* (non-Javadoc)
*
* @see com.emc.storageos.volumecontroller.BlockStorageDevice#doDeleteSnapshot
* (com.emc.storageos.db.client.model.StorageSystem,
* java.net.URI, com.emc.storageos.volumecontroller.TaskCompleter)
*/
@Override
public void doDeleteSnapshot(StorageSystem storageSystem, URI snapshotURI, TaskCompleter taskCompleter) throws DeviceControllerException {
try {
StringBuilder logMsgBuilder = new StringBuilder(String.format("Delete Snapshot Start - Array:%s", storageSystem.getSerialNumber()));
log.info(logMsgBuilder.toString());
BlockSnapshot snapshot = dbClient.queryObject(BlockSnapshot.class, snapshotURI);
CinderEndPointInfo ep = CinderUtils.getCinderEndPoint(storageSystem.getActiveProviderURI(), dbClient);
log.info("Getting the cinder APi for the provider with id " + storageSystem.getActiveProviderURI());
CinderApi cinderApi = cinderApiFactory.getApi(storageSystem.getActiveProviderURI(), ep);
try {
cinderApi.showSnapshot(snapshot.getId().toString());
} catch (CinderException ce) {
// This means, the snapshot is not present on the back-end device
log.info(String.format("Snapshot %s already deleted: ", snapshot.getNativeId()));
snapshot.setInactive(true);
dbClient.updateObject(snapshot);
taskCompleter.ready(dbClient);
}
// Now - trigger the delete
cinderApi.deleteSnapshot(snapshot.getNativeId().toString());
ControllerServiceImpl.enqueueJob(new QueueJob(new CinderSnapshotDeleteJob(snapshot.getNativeId(), snapshot.getLabel(), storageSystem.getId(), CinderConstants.ComponentType.snapshot.name(), ep, taskCompleter)));
} catch (Exception e) {
log.error("Problem in doDeleteVolume: ", e);
ServiceError error = DeviceControllerErrors.cinder.operationFailed("doDeleteSnapshot", e.getMessage());
taskCompleter.error(dbClient, error);
}
}
use of com.emc.storageos.cinder.api.CinderApi in project coprhd-controller by CoprHD.
the class CinderStorageDevice method doCreateVolumes.
/*
* (non-Javadoc)
*
* @see com.emc.storageos.volumecontroller.BlockStorageDevice#doCreateVolumes
* (com.emc.storageos.db.client.model.StorageSystem,
* com.emc.storageos.db.client.model.StoragePool,
* java.lang.String, java.util.List,
* com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper,
* com.emc.storageos.volumecontroller.TaskCompleter)
*/
@Override
public void doCreateVolumes(StorageSystem storageSystem, StoragePool storagePool, String opId, List<Volume> volumes, VirtualPoolCapabilityValuesWrapper capabilities, TaskCompleter taskCompleter) throws DeviceControllerException {
String label = null;
Long capacity = null;
boolean opCreationFailed = false;
StringBuilder logMsgBuilder = new StringBuilder(String.format("Create Volume Start - Array:%s, Pool:%s", storageSystem.getSerialNumber(), storagePool.getNativeGuid()));
for (Volume volume : volumes) {
logMsgBuilder.append(String.format("%nVolume:%s", volume.getLabel()));
String tenantName = "";
try {
TenantOrg tenant = dbClient.queryObject(TenantOrg.class, volume.getTenant().getURI());
tenantName = tenant.getLabel();
} catch (DatabaseException e) {
log.error("Error lookup TenantOrg object", e);
}
label = nameGenerator.generate(tenantName, volume.getLabel(), volume.getId().toString(), CinderConstants.CHAR_HYPHEN, SmisConstants.MAX_VOLUME_NAME_LENGTH);
if (capacity == null) {
capacity = volume.getCapacity();
}
}
log.info(logMsgBuilder.toString());
try {
CinderEndPointInfo ep = CinderUtils.getCinderEndPoint(storageSystem.getActiveProviderURI(), dbClient);
log.info("Getting the cinder APi for the provider with id {}", storageSystem.getActiveProviderURI());
CinderApi cinderApi = cinderApiFactory.getApi(storageSystem.getActiveProviderURI(), ep);
String volumeId = null;
Map<String, URI> volumeIds = new HashMap<String, URI>();
if (volumes.size() == 1) {
volumeId = cinderApi.createVolume(label, CinderUtils.convertToGB(capacity), storagePool.getNativeId());
volumeIds.put(volumeId, volumes.get(0).getId());
log.debug("Creating volume with the id {} on Openstack cinder node", volumeId);
} else {
log.debug("Starting to create {} volumes", volumes.size());
for (int volumeIndex = 0; volumeIndex < volumes.size(); volumeIndex++) {
volumeId = cinderApi.createVolume(label + CinderConstants.HYPHEN + (volumeIndex + 1), CinderUtils.convertToGB(capacity), storagePool.getNativeId());
volumeIds.put(volumeId, volumes.get(volumeIndex).getId());
log.debug("Creating volume with the id {} on Openstack cinder node", volumeId);
}
}
if (!volumeIds.isEmpty()) {
CinderJob createVolumeJob = (volumes.size() > 1) ? new CinderMultiVolumeCreateJob(volumeId, label, volumes.get(0).getStorageController(), CinderConstants.ComponentType.volume.name(), ep, taskCompleter, storagePool.getId(), volumeIds) : new CinderSingleVolumeCreateJob(volumeId, label, volumes.get(0).getStorageController(), CinderConstants.ComponentType.volume.name(), ep, taskCompleter, storagePool.getId(), volumeIds);
ControllerServiceImpl.enqueueJob(new QueueJob(createVolumeJob));
}
} catch (final InternalException e) {
log.error("Problem in doCreateVolumes: ", e);
opCreationFailed = true;
taskCompleter.error(dbClient, e);
} catch (final Exception e) {
log.error("Problem in doCreateVolumes: ", e);
opCreationFailed = true;
ServiceError serviceError = DeviceControllerErrors.cinder.operationFailed("doCreateVolumes", e.getMessage());
taskCompleter.error(dbClient, serviceError);
}
if (opCreationFailed) {
for (Volume vol : volumes) {
vol.setInactive(true);
dbClient.persistObject(vol);
}
}
logMsgBuilder = new StringBuilder(String.format("Create Volumes End - Array:%s, Pool:%s", storageSystem.getSerialNumber(), storagePool.getNativeGuid()));
for (Volume volume : volumes) {
logMsgBuilder.append(String.format("%nVolume:%s", volume.getLabel()));
}
log.info(logMsgBuilder.toString());
}
Aggregations