use of com.emc.storageos.plugins.StorageSystemViewObject in project coprhd-controller by CoprHD.
the class BlockDeviceController method scanProvider.
private boolean scanProvider(StorageProvider provider, StorageSystem storageSystem, boolean activeProvider, String opId) throws DatabaseException, BaseCollectionException, ControllerException {
Map<String, StorageSystemViewObject> storageCache = new HashMap<String, StorageSystemViewObject>();
_dbClient.createTaskOpStatus(StorageProvider.class, provider.getId(), opId, ResourceOperationTypeEnum.SCAN_SMISPROVIDER);
ScanTaskCompleter scanCompleter = new ScanTaskCompleter(StorageProvider.class, provider.getId(), opId);
try {
scanCompleter.statusPending(_dbClient, "Scan for storage system is Initiated");
provider.setLastScanStatusMessage("");
_dbClient.updateObject(provider);
ControllerServiceImpl.performScan(provider.getId(), scanCompleter, storageCache);
scanCompleter.statusReady(_dbClient, "Scan for storage system has completed");
} catch (Exception ex) {
_log.error("Scan failed for {}--->", provider, ex);
scanCompleter.statusError(_dbClient, DeviceControllerErrors.dataCollectionErrors.scanFailed(ex.getLocalizedMessage(), ex));
throw DeviceControllerException.exceptions.scanProviderFailed(storageSystem.getNativeGuid(), provider.getId().toString());
}
if (!storageCache.containsKey(storageSystem.getNativeGuid())) {
return false;
} else {
StorageSystemViewObject vo = storageCache.get(storageSystem.getNativeGuid());
String model = vo.getProperty(StorageSystemViewObject.MODEL);
if (StringUtils.isNotBlank(model)) {
storageSystem.setModel(model);
}
String serialNo = vo.getProperty(StorageSystemViewObject.SERIAL_NUMBER);
if (StringUtils.isNotBlank(serialNo)) {
storageSystem.setSerialNumber(serialNo);
}
String version = vo.getProperty(StorageSystemViewObject.VERSION);
if (StringUtils.isNotBlank(version)) {
storageSystem.setMajorVersion(version);
}
String name = vo.getProperty(StorageSystemViewObject.STORAGE_NAME);
if (StringUtils.isNotBlank(name)) {
storageSystem.setLabel(name);
}
provider.addStorageSystem(_dbClient, storageSystem, activeProvider);
return true;
}
}
use of com.emc.storageos.plugins.StorageSystemViewObject in project coprhd-controller by CoprHD.
the class VPlexCommunicationInterface method scanManagedSystems.
/**
* First gets the VPLEX cluster(s) that are manageable by the VPLEX management
* server. For a VPLEX local configuration there will be one cluster. For
* a VPLEX Metro configuration there will be two clusters. We then create a
* StorageSystemViewObject to represent the managed clusters as a storage system
* to be managed by this management server.
*
* @param client The VPlex API client.
* @param mgmntServer A reference to the VPlex management server.
* @param scanCache A map holding previously found systems during a scan.
*
* @throws VPlexCollectionException When an error occurs getting the VPLEX
* information.
*/
private void scanManagedSystems(VPlexApiClient client, StorageProvider mgmntServer, Map<String, StorageSystemViewObject> scanCache) throws VPlexCollectionException {
try {
List<String> clusterAssemblyIds = new ArrayList<String>();
String systemSerialNumber = getSystemSerialNumber(client, mgmntServer, clusterAssemblyIds);
// Get the native GUID for the system using the constructed
// serial number.
String systemNativeGUID = NativeGUIDGenerator.generateNativeGuid(mgmntServer.getInterfaceType(), systemSerialNumber);
s_logger.info("Scanned VPLEX system {}", systemNativeGUID);
// Check for potential cluster hardware changes from local to metro, or vice versa
checkForClusterHardwareChange(clusterAssemblyIds, systemNativeGUID, systemSerialNumber, client, scanCache, mgmntServer);
// Determine if the VPLEX system was already scanned by another
// VPLEX management server by checking the scan cache. If not,
// then we create a StorageSystemViewObject to represent this
// VPLEX system and add it to the scan cache.
StorageSystemViewObject systemViewObj = null;
if (scanCache.containsKey(systemNativeGUID)) {
s_logger.info("VPLEX system {} was previously found.", systemNativeGUID);
systemViewObj = scanCache.get(systemNativeGUID);
} else {
s_logger.info("Found new VPLEX system {}, adding to scan cache.", systemNativeGUID);
systemViewObj = new StorageSystemViewObject();
}
systemViewObj.setDeviceType(mgmntServer.getInterfaceType());
systemViewObj.addprovider(mgmntServer.getId().toString());
systemViewObj.setProperty(StorageSystemViewObject.SERIAL_NUMBER, systemSerialNumber);
systemViewObj.setProperty(StorageSystemViewObject.STORAGE_NAME, systemNativeGUID);
scanCache.put(systemNativeGUID, systemViewObj);
} catch (Exception e) {
s_logger.error("Error scanning managed systems for {}:", mgmntServer.getIPAddress(), e);
throw VPlexCollectionException.exceptions.failedScanningManagedSystems(mgmntServer.getIPAddress(), e.getLocalizedMessage(), e);
}
}
use of com.emc.storageos.plugins.StorageSystemViewObject in project coprhd-controller by CoprHD.
the class XtremIOCommunicationInterface method scan.
@Override
public void scan(AccessProfile accessProfile) throws BaseCollectionException {
_logger.info("Scanning started for provider: {}", accessProfile.getSystemId());
StorageProvider.ConnectionStatus cxnStatus = StorageProvider.ConnectionStatus.CONNECTED;
StorageProvider provider = _dbClient.queryObject(StorageProvider.class, accessProfile.getSystemId());
XtremIOClient xtremIOClient = null;
try {
xtremIOClient = (XtremIOClient) xtremioRestClientFactory.getXtremIOV1Client(URI.create(XtremIOConstants.getXIOBaseURI(accessProfile.getIpAddress(), accessProfile.getPortNumber())), accessProfile.getUserName(), accessProfile.getPassword(), true);
String xmsVersion = xtremIOClient.getXtremIOXMSVersion();
String minimumSupportedVersion = VersionChecker.getMinimumSupportedVersion(StorageSystem.Type.xtremio).replace("-", ".");
String compatibility = (VersionChecker.verifyVersionDetails(minimumSupportedVersion, xmsVersion) < 0) ? StorageSystem.CompatibilityStatus.INCOMPATIBLE.name() : StorageSystem.CompatibilityStatus.COMPATIBLE.name();
provider.setCompatibilityStatus(compatibility);
provider.setVersionString(xmsVersion);
String systemType = StorageSystem.Type.xtremio.name();
List<XtremIOSystem> xioSystems = xtremIOClient.getXtremIOSystemInfo();
_logger.info("Found {} clusters during scan of XMS {}", xioSystems.size(), accessProfile.getIpAddress());
Map<String, StorageSystemViewObject> storageSystemsCache = accessProfile.getCache();
for (XtremIOSystem system : xioSystems) {
String arrayNativeGUID = NativeGUIDGenerator.generateNativeGuid(DiscoveredDataObject.Type.xtremio.name(), system.getSerialNumber());
StorageSystemViewObject viewObject = storageSystemsCache.get(arrayNativeGUID);
if (viewObject == null) {
viewObject = new StorageSystemViewObject();
}
viewObject.setDeviceType(systemType);
viewObject.addprovider(accessProfile.getSystemId().toString());
viewObject.setProperty(StorageSystemViewObject.SERIAL_NUMBER, system.getSerialNumber());
viewObject.setProperty(StorageSystemViewObject.VERSION, system.getVersion());
viewObject.setProperty(StorageSystemViewObject.STORAGE_NAME, arrayNativeGUID);
storageSystemsCache.put(arrayNativeGUID, viewObject);
}
} catch (Exception ex) {
_logger.error("Error scanning XMS", ex);
cxnStatus = StorageProvider.ConnectionStatus.NOTCONNECTED;
// throw exception only if system discovery failed.
throw XtremIOApiException.exceptions.discoveryFailed(provider.toString());
} finally {
provider.setConnectionStatus(cxnStatus.name());
_dbClient.persistObject(provider);
if (xtremIOClient != null) {
xtremIOClient.close();
}
_logger.info("Completed scan of XtremIO StorageProvider. IP={}", accessProfile.getIpAddress());
}
}
use of com.emc.storageos.plugins.StorageSystemViewObject in project coprhd-controller by CoprHD.
the class DataCollectionJobConsumer method triggerScanning.
/**
* 1. refreshConnections - needs to get called on each Controller, before acquiring lock.
* 2. Try to acquire lock, if found
* 3. Acquiring lock is not made as a Blocking Call, hence Controllers will return immediately,
* if lock not found
* 3. If lock found, spawn a new thread to do triggerScanning.
* 4. Release lock immediately.
*/
private void triggerScanning(DataCollectionScanJob job) throws Exception {
_logger.info("Started scanning Providers : triggerScanning()");
List<URI> providerList = job.getProviders();
String providerType = null;
if (!providerList.isEmpty()) {
providerType = _dbClient.queryObject(StorageProvider.class, providerList.iterator().next()).getInterfaceType();
}
_jobScheduler.refreshProviderConnections(providerType);
List<URI> allProviderURI = _dbClient.queryByType(StorageProvider.class, true);
List<StorageProvider> allProvidersAllTypes = _dbClient.queryObject(StorageProvider.class, allProviderURI);
List<StorageProvider> allProviders = new ArrayList<StorageProvider>();
// since dbQuery does not return a normal list required by bookkeeping, we need to rebuild it.
allProviderURI = new ArrayList<URI>();
for (StorageProvider provider : allProvidersAllTypes) {
if (providerType == null || providerType.equals(provider.getInterfaceType())) {
allProviderURI.add(provider.getId());
allProviders.add(provider);
}
}
Map<String, StorageSystemViewObject> storageSystemsCache = Collections.synchronizedMap(new HashMap<String, StorageSystemViewObject>());
boolean exceptionIntercepted = false;
/**
* Run "Scheduled" Scanner Jobs of all Providers in only one Controller.
* means our Cache is populated with the latest
* physicalStorageSystems ID got from this scheduled Scan Job.
* Compare the list against the ones in DB, and decide the physicalStorageSystem's
* state REACHABLE
*/
String lockKey = ControllerServiceImpl.Lock.SCAN_COLLECTION_LOCK.toString();
if (providerType != null) {
lockKey += providerType;
}
InterProcessLock scanLock = _coordinator.getLock(lockKey);
if (scanLock.acquire(ControllerServiceImpl.Lock.SCAN_COLLECTION_LOCK.getRecommendedTimeout(), TimeUnit.SECONDS)) {
_logger.info("Acquired a lock {} to run scanning Job", ControllerServiceImpl.Lock.SCAN_COLLECTION_LOCK.toString() + providerType);
List<URI> cacheProviders = new ArrayList<URI>();
Map<URI, Exception> cacheErrorProviders = new HashMap<URI, Exception>();
try {
boolean scanIsNeeded = false;
boolean hasProviders = false;
// First find out if scan is needed. If it needed for a single system , it is needed for all
for (StorageProvider provider : allProviders) {
if (provider.connected() || provider.initializing()) {
hasProviders = true;
if (_jobScheduler.isProviderScanJobSchedulingNeeded(provider, ControllerServiceImpl.SCANNER, job.isSchedulerJob())) {
scanIsNeeded = true;
break;
}
}
}
if (!scanIsNeeded) {
for (StorageProvider provider : allProviders) {
ScanTaskCompleter scanCompleter = job.findProviderTaskCompleter(provider.getId());
if (scanCompleter == null) {
continue;
}
if (provider.connected() || provider.initializing()) {
scanCompleter.ready(_dbClient);
} else {
String errMsg = "Failed to establish connection to the storage provider";
scanCompleter.error(_dbClient, DeviceControllerErrors.smis.unableToCallStorageProvider(errMsg));
provider.setLastScanStatusMessage(errMsg);
_dbClient.updateObject(provider);
}
}
if (!hasProviders) {
_util.performBookKeeping(storageSystemsCache, allProviderURI);
}
_logger.info("Scan is not needed");
} else {
// If scan is needed for a single system,
// it must be performed for all available providers in the database at the same time.
// update each provider that is reachable to scan in progress
List<StorageProvider> connectedProviders = new ArrayList<StorageProvider>();
for (StorageProvider provider : allProviders) {
if (provider.connected() || provider.initializing()) {
ScanTaskCompleter scanCompleter = job.findProviderTaskCompleter(provider.getId());
if (scanCompleter == null) {
String taskId = UUID.randomUUID().toString();
scanCompleter = new ScanTaskCompleter(StorageProvider.class, provider.getId(), taskId);
job.addCompleter(scanCompleter);
}
scanCompleter.createDefaultOperation(_dbClient);
scanCompleter.updateObjectState(_dbClient, DiscoveredDataObject.DataCollectionJobStatus.IN_PROGRESS);
scanCompleter.setNextRunTime(_dbClient, System.currentTimeMillis() + DataCollectionJobScheduler.JobIntervals.get(ControllerServiceImpl.SCANNER).getInterval() * 1000);
provider.setLastScanStatusMessage("");
_dbClient.updateObject(provider);
connectedProviders.add(provider);
} else {
if (null != provider.getStorageSystems() && !provider.getStorageSystems().isEmpty()) {
provider.getStorageSystems().clear();
}
if (providerList.contains(provider.getId())) {
String errMsg = "Failed to establish connection to the storage provider";
provider.setLastScanStatusMessage(errMsg);
job.findProviderTaskCompleter(provider.getId()).error(_dbClient, DeviceControllerErrors.smis.unableToCallStorageProvider(errMsg));
}
_dbClient.updateObject(provider);
}
}
// now scan each connected provider
for (StorageProvider provider : connectedProviders) {
try {
_logger.info("provider.getInterfaceType():{}", provider.getInterfaceType());
ScanTaskCompleter scanCompleter = job.findProviderTaskCompleter(provider.getId());
performScan(provider.getId(), scanCompleter, storageSystemsCache);
cacheProviders.add(provider.getId());
} catch (Exception ex) {
_logger.error("Scan failed for {}--->", provider.getId(), ex);
cacheErrorProviders.put(provider.getId(), ex);
}
}
// Perform BooKKeeping
// TODO: we need to access the status of job completer.
// for now we assume that this operation can not fail.
_util.performBookKeeping(storageSystemsCache, allProviderURI);
}
} catch (final Exception ex) {
_logger.error("Scan failed for {} ", ex.getMessage());
exceptionIntercepted = true;
for (URI provider : cacheProviders) {
job.findProviderTaskCompleter(provider).error(_dbClient, DeviceControllerErrors.dataCollectionErrors.scanFailed(ex.getLocalizedMessage(), ex));
_logger.error("Scan failed for {}--->", provider, ex);
}
throw ex;
} finally {
if (!exceptionIntercepted) {
for (URI provider : cacheProviders) {
job.findProviderTaskCompleter(provider).ready(_dbClient);
_logger.info("Scan complete successfully for " + provider);
}
}
for (Entry<URI, Exception> entry : cacheErrorProviders.entrySet()) {
URI provider = entry.getKey();
Exception ex = entry.getValue();
job.findProviderTaskCompleter(provider).error(_dbClient, DeviceControllerErrors.dataCollectionErrors.scanFailed(ex.getLocalizedMessage(), ex));
}
scanLock.release();
_logger.info("Released a lock {} to run scanning Job", lockKey);
try {
if (!exceptionIntercepted) /* && job.isSchedulerJob() */
{
// Manually trigger discoveries, if any new Arrays detected
triggerDiscoveryNew(storageSystemsCache, (job.isSchedulerJob() ? DataCollectionJob.JobOrigin.SCHEDULER : DataCollectionJob.JobOrigin.USER_API));
}
} catch (Exception ex) {
_logger.error("Exception occurred while triggering discovery of new systems", ex);
}
}
} else {
job.setTaskError(_dbClient, DeviceControllerErrors.dataCollectionErrors.scanLockFailed());
_logger.error("Not able to Acquire Scanning {} lock-->{}", lockKey, Thread.currentThread().getId());
}
}
use of com.emc.storageos.plugins.StorageSystemViewObject in project coprhd-controller by CoprHD.
the class DataCollectionJobUtil method updateActiveProviderDetailsInDbSystem.
/**
* Finds & update the storage systems in the following scenarios.
*
* 1. Query all systems from db.
* 2. If the system is not vnxblock or vmaxblock, then continue.
* 3. Verify each system whether it is in the scanned list or not.
* 4. If it is in the scannedList then update the activeprovider details.
* 5. If it is not in the scannedList then
* 6 .Check whether the system's active Provider is part of the InitialScanList
* (both Providers which tookj part for Scanning + providers which had dropped due
* to connection issues found in refreshConnections)
* 7. If yes, then set check whether the system is registered or not.
* If it is registered, then set the reachableStatus to false
* else delete all its components.
* 8. If NO, then don't disturb.
*
* @param scannedSystemsNativeGuidsMap
* : List of scanned Systems NativeGuids.
* @param systemsToPersist : List of systems to persist.
* @param initialScanList : intialScanned List of providers.
* @param providersToUpdate : Providers to update holds provider => List of managed systems
*/
public void updateActiveProviderDetailsInDbSystem(Map<String, StorageSystemViewObject> scannedSystemsNativeGuidsMap, List<StorageSystem> systemsToPersist, Set<URI> initialScanList, Map<URI, List<String>> providersToUpdate) {
Iterator<URI> storageSystemUrisInDb;
StorageSystem storageSystemInDb = null;
try {
storageSystemUrisInDb = _dbClient.queryByType(StorageSystem.class, true).iterator();
} catch (DatabaseException e) {
_logger.error("Exception occurred while querying db to get StorageSystems due to ", e);
return;
}
while (storageSystemUrisInDb.hasNext()) {
URI dbSystemUri = storageSystemUrisInDb.next();
try {
storageSystemInDb = _dbClient.queryObject(StorageSystem.class, dbSystemUri);
if (null == storageSystemInDb || !storageSystemInDb.isStorageSystemManagedByProvider()) {
_logger.info("Either storageSystem object is null or system not managed by provider : {}", dbSystemUri);
continue;
}
// By this time, DB has true reflection of physical Environment
// Case 1: registered and managed by provider. mark it visible
// Case 2: not registered still managed by provider. mark it
// visible.
String dbSystemNativeGuid = storageSystemInDb.getNativeGuid();
if (scannedSystemsNativeGuidsMap.containsKey(dbSystemNativeGuid)) {
_logger.info("Detected a existing storage system {} via scan process again.", dbSystemNativeGuid);
StorageSystemViewObject systemDetails = scannedSystemsNativeGuidsMap.get(dbSystemNativeGuid);
updateActiveProviders(systemDetails, storageSystemInDb, providersToUpdate);
} else {
_logger.info("Existing discovered storage system {} is not part of available new scan list.", dbSystemNativeGuid);
if (initialScanList.contains(storageSystemInDb.getActiveProviderURI())) {
// Invisible.
if (RegistrationStatus.REGISTERED.toString().equalsIgnoreCase(storageSystemInDb.getRegistrationStatus())) {
injectReachableStatusInSystem(storageSystemInDb, null, NullColumnValueGetter.getNullURI(), false);
}
}
}
} catch (Exception e) {
_logger.error("Exception while updating visible status for id: {} due to", storageSystemInDb.getId(), e);
}
systemsToPersist.add(storageSystemInDb);
}
}
Aggregations