use of com.emc.storageos.db.client.model.StorageProvider in project coprhd-controller by CoprHD.
the class VPlexDeviceController method validateStorageProviderConnection.
/**
* Validate a VPLEX Storage Provider connection.
*
* @param ipAddress
* the Storage Provider's IP address
* @param portNumber
* the Storage Provider's IP port
*
* @return true if the Storage Provider connection is valid
*/
@Override
public boolean validateStorageProviderConnection(String ipAddress, Integer portNumber) {
boolean connectionValid;
try {
// look up the provider by ip address and port
StringBuffer providerId = new StringBuffer(ipAddress).append(HYPHEN_OPERATOR).append(portNumber);
URIQueryResultList providerUriList = new URIQueryResultList();
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getStorageProviderByProviderIDConstraint(providerId.toString()), providerUriList);
if (providerUriList.iterator().hasNext()) {
StorageProvider provider = _dbClient.queryObject(StorageProvider.class, providerUriList.iterator().next());
VPlexApiClient client = getVPlexAPIClient(_vplexApiFactory, provider, _dbClient);
if (client != null) {
client.verifyConnectivity();
// if we got this far without blowing up, then the connection is valid
_log.info("VPLEX Storage Provider connection at {} is valid.", providerId);
connectionValid = true;
} else {
_log.error("a VplexApiClient could not be created for provider {}.", provider.getLabel());
connectionValid = false;
}
} else {
_log.error("Could not find a VPLEX Storage Provider " + "with address-port {} in ViPR.", providerId);
connectionValid = false;
}
} catch (Exception ex) {
_log.error("Connection to VPLEX Storage Provider {} is invalid.", ipAddress, ex);
connectionValid = false;
}
return connectionValid;
}
use of com.emc.storageos.db.client.model.StorageProvider in project coprhd-controller by CoprHD.
the class VPlexDeviceController method refreshConnectionStatusForAllVPlexManagementServers.
/**
* Refreshes the connection status for all VPLEX management servers.
*
* @return The list of those to which a connection was successful.
*/
public List<URI> refreshConnectionStatusForAllVPlexManagementServers() {
List<URI> activeMgmntServers = new ArrayList<URI>();
List<StorageProvider> vplexMnmgtServers = CustomQueryUtility.getActiveStorageProvidersByInterfaceType(_dbClient, StorageProvider.InterfaceType.vplex.name());
for (StorageProvider vplexMnmgtServer : vplexMnmgtServers) {
try {
VPlexApiClient client = getVPlexAPIClient(_vplexApiFactory, vplexMnmgtServer, _dbClient);
client.verifyConnectivity();
activeMgmntServers.add(vplexMnmgtServer.getId());
vplexMnmgtServer.setConnectionStatus(StorageProvider.ConnectionStatus.CONNECTED.toString());
} catch (Exception e) {
_log.warn("Can't connect to VPLEX management server {}", vplexMnmgtServer.getIPAddress());
vplexMnmgtServer.setConnectionStatus(StorageProvider.ConnectionStatus.NOTCONNECTED.toString());
} finally {
_dbClient.updateObject(vplexMnmgtServer);
}
}
return activeMgmntServers;
}
use of com.emc.storageos.db.client.model.StorageProvider in project coprhd-controller by CoprHD.
the class XIVRestOperationsHelper method getRestClient.
/**
* Gets REST Client instance for a StorageSystem
*
* @param storage
* StorageSystem instance
* @return XIVRESTExportOperations instance
*/
private XIVRestClient getRestClient(StorageSystem storage) {
XIVRestClient restClient = null;
StorageProvider provider = _dbClient.queryObject(StorageProvider.class, storage.getActiveProviderURI());
String providerUser = provider.getSecondaryUsername();
String providerPassword = provider.getSecondaryPassword();
String providerURL = provider.getSecondaryURL();
if (StringUtils.isNotEmpty(providerURL) && StringUtils.isNotEmpty(providerPassword) && StringUtils.isNotEmpty(providerUser)) {
restClient = (XIVRestClient) _restClientFactory.getRESTClient(URI.create(providerURL), providerUser, providerPassword);
}
return restClient;
}
use of com.emc.storageos.db.client.model.StorageProvider in project coprhd-controller by CoprHD.
the class XtremIOProvUtils method refreshXtremeIOConnections.
/**
* Refresh the XIO Providers & its client connections.
*
* @param xioProviderList
* the XIO provider list
* @param dbClient
* the db client
* @return the list of active providers
*/
public static List<URI> refreshXtremeIOConnections(final List<StorageProvider> xioProviderList, DbClient dbClient, XtremIOClientFactory xtremioRestClientFactory) {
List<URI> activeProviders = new ArrayList<URI>();
for (StorageProvider provider : xioProviderList) {
try {
// For providers without version/model, let it try connecting V1 client to update connection status
XtremIOClient xioClient = (XtremIOClient) xtremioRestClientFactory.getRESTClient(URI.create(XtremIOConstants.getXIOBaseURI(provider.getIPAddress(), provider.getPortNumber())), provider.getUserName(), provider.getPassword(), provider.getVersionString(), true);
if (null != xioClient.getXtremIOXMSVersion()) {
// Now update provider status based on connection live check.
provider.setConnectionStatus(StorageProvider.ConnectionStatus.CONNECTED.toString());
activeProviders.add(provider.getId());
} else {
_log.info("XIO Connection is not active {}", provider.getProviderID());
provider.setConnectionStatus(StorageProvider.ConnectionStatus.NOTCONNECTED.toString());
}
} catch (Exception ex) {
_log.error("Exception occurred while validating XIO client for {}", provider.getProviderID(), ex);
provider.setConnectionStatus(StorageProvider.ConnectionStatus.NOTCONNECTED.toString());
} finally {
dbClient.updateObject(provider);
}
}
return activeProviders;
}
use of com.emc.storageos.db.client.model.StorageProvider 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