use of com.emc.storageos.cinder.model.VolumeTypes in project coprhd-controller by CoprHD.
the class CinderApi method getVolumeTypes.
/**
* Gets all volume types present in the OpenStack
* cinder node. It is a synchronous operation.
*
* @return
*/
public VolumeTypes getVolumeTypes() {
VolumeTypes volTypes = null;
String vol_types_uri = endPoint.getBaseUri() + String.format(CinderConstants.URI_LIST_VOLUME_TYPES, endPoint.getCinderTenantId());
ClientResponse js_response = getClient().get(URI.create(vol_types_uri));
String s = js_response.getEntity(String.class);
_log.info("Volume types = {}", s);
Gson gson = new Gson();
volTypes = gson.fromJson(SecurityUtils.sanitizeJsonString(s), VolumeTypes.class);
return volTypes;
}
use of com.emc.storageos.cinder.model.VolumeTypes 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());
}
}
Aggregations