Search in sources :

Example 66 with StorageProvider

use of com.emc.storageos.db.client.model.StorageProvider in project coprhd-controller by CoprHD.

the class DataCollectionJobScheduler method scheduleScannerJobs.

/**
 * scans a list of providers in one scan job
 *
 * @param providers
 * @throws Exception
 */
public void scheduleScannerJobs(DataCollectionScanJob scanJob) throws Exception {
    List<StorageProvider> providers = _dbClient.queryObject(StorageProvider.class, scanJob.getProviders());
    if (providers == null || providers.isEmpty()) {
        _logger.info("No scanning needed: provider list is empty");
        return;
    }
    _logger.info("Starting scan of providers of type {}", providers.iterator().next().getInterfaceType());
    long lastScanTime = 0;
    List<URI> provUris = scanJob.getProviders();
    if (provUris != null && !provUris.isEmpty()) {
        ControllerServiceImpl.Lock lock = ControllerServiceImpl.Lock.getLock(ControllerServiceImpl.SCANNER);
        if (lock.acquire(lock.getRecommendedTimeout())) {
            try {
                _logger.info("Acquired a lock {} to schedule {} scanner Jobs", providers.iterator().next().getInterfaceType(), lock.toString());
                boolean inProgress = ControllerServiceImpl.isDataCollectionJobInProgress(scanJob) || ControllerServiceImpl.isDataCollectionJobQueued(scanJob);
                // Find the last scan time from the provider whose scan status is not in progress or scheduled
                if (!inProgress) {
                    lastScanTime = providers.iterator().next().getLastScanTime();
                    // tasks created for the jobs currently being scheduled
                    for (StorageProvider provider : providers) {
                        Calendar oneHourAgo = Calendar.getInstance();
                        oneHourAgo.setTime(Date.from(LocalDateTime.now().minusHours(1).atZone(ZoneId.systemDefault()).toInstant()));
                        TaskUtils.cleanupPendingTasks(_dbClient, provider.getId(), ResourceOperationTypeEnum.SCAN_STORAGEPROVIDER.getName(), URI.create(SYSTEM_TENANT_ID), oneHourAgo);
                    }
                }
                if (isDataCollectionScanJobSchedulingNeeded(lastScanTime, inProgress)) {
                    for (StorageProvider provider : providers) {
                        provider.setScanStatus(DataCollectionJobStatus.SCHEDULED.toString());
                        _dbClient.updateObject(provider);
                    }
                    _logger.info("Added Scan job to the Distributed Queue");
                    ControllerServiceImpl.enqueueDataCollectionJob(scanJob);
                } else {
                    // clear the task that was created for this job but don't set the provider to not in progress
                    scanJob.setTaskReady(_dbClient, "Scan job was not run because it is either in progress or was run recently");
                }
            } catch (Exception e) {
                _logger.error(e.getMessage(), e);
            } finally {
                try {
                    lock.release();
                    _logger.info("Released a lock {} to schedule Jobs", lock.toString());
                } catch (Exception e) {
                    _logger.error("Failed to release  Lock {} -->{}", lock.toString(), e.getMessage());
                }
            }
        } else {
            _logger.debug("Not able to Acquire lock {}-->{}", lock.toString(), Thread.currentThread().getId());
            throw new DeviceControllerException("Failed to acquire lock : " + lock.toString());
        }
    }
}
Also used : ControllerServiceImpl(com.emc.storageos.volumecontroller.impl.ControllerServiceImpl) Calendar(java.util.Calendar) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) URI(java.net.URI) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 67 with StorageProvider

use of com.emc.storageos.db.client.model.StorageProvider in project coprhd-controller by CoprHD.

the class DataCollectionJobScheduler method scheduleScannerJobs.

/**
 * Core method, responsible for loading StorageProviders from DB and do scanning.
 *
 * @throws Exception
 */
private void scheduleScannerJobs() throws Exception {
    _logger.info("Started Loading Storage Providers from DB");
    List<StorageProvider> providers = _dbClient.queryObject(StorageProvider.class, _dbClient.queryByType(StorageProvider.class, true));
    Map<String, DataCollectionScanJob> scanJobByInterfaceType = new HashMap<String, DataCollectionScanJob>();
    for (StorageProvider provider : providers) {
        if (scanJobByInterfaceType.get(provider.getInterfaceType()) == null) {
            scanJobByInterfaceType.put(provider.getInterfaceType(), new DataCollectionScanJob(DataCollectionJob.JobOrigin.SCHEDULER));
        }
        String taskId = UUID.randomUUID().toString();
        scanJobByInterfaceType.get(provider.getInterfaceType()).addCompleter(new ScanTaskCompleter(StorageProvider.class, provider.getId(), taskId));
    }
    for (DataCollectionScanJob scanJob : scanJobByInterfaceType.values()) {
        scheduleScannerJobs(scanJob);
    }
}
Also used : HashMap(java.util.HashMap) StorageProvider(com.emc.storageos.db.client.model.StorageProvider)

Example 68 with StorageProvider

use of com.emc.storageos.db.client.model.StorageProvider in project coprhd-controller by CoprHD.

the class DataCollectionJobUtil method updateActiveProviders.

/**
 * Updates the active/passive provider details in the StorageSystem object.
 *
 * @param scannedStorageSystemViewObj
 *            : scannedProvider details of this system.
 * @param storageSystemInDb
 *            : storageSystem in DB.
 * @param providersToUpdate : Providers to update.
 */
private void updateActiveProviders(StorageSystemViewObject scannedStorageSystemViewObj, StorageSystem storageSystemInDb, Map<URI, List<String>> providersToUpdate) throws IOException {
    Set<String> allProviders = scannedStorageSystemViewObj.getProviders();
    // 1. If activeProviders are null then set the active to null and blank set to providers.
    if (allProviders == null || allProviders.isEmpty()) {
        _logger.info("Scanned system {} does not have any storage provider", scannedStorageSystemViewObj.SERIAL_NUMBER);
        injectReachableStatusInSystem(storageSystemInDb, null, NullColumnValueGetter.getNullURI(), false);
        return;
    // 2. If Current ActiveProvider is not in ActiveList.
    } else if (!allProviders.contains(storageSystemInDb.getActiveProviderURI().toString())) {
        _logger.info("Existing active provider{} of StorageSystem {} is not active now", storageSystemInDb.getActiveProviderURI(), storageSystemInDb.getNativeGuid());
        Iterator<String> iterator = allProviders.iterator();
        if (iterator.hasNext()) {
            String newProviderURI = iterator.next();
            injectReachableStatusInSystem(storageSystemInDb, allProviders, URI.create(newProviderURI), true);
            StorageProvider newProvider = _dbClient.queryObject(StorageProvider.class, URI.create(newProviderURI));
            setActiveProviderDetailsInSystem(newProvider, storageSystemInDb, providersToUpdate);
        } else {
            injectReachableStatusInSystem(storageSystemInDb, null, NullColumnValueGetter.getNullURI(), false);
        }
    } else {
        // If the current provider is already active, then set its passive providers.
        StringSet dbSystemAllProviders = storageSystemInDb.getProviders();
        if (null != dbSystemAllProviders && !dbSystemAllProviders.isEmpty()) {
            storageSystemInDb.getProviders().addAll(allProviders);
        } else {
            StringSet scannedProviders = new StringSet(allProviders);
            storageSystemInDb.setProviders(scannedProviders);
        }
        _logger.info("Added passive provider information in StorageSyetem instance {}", storageSystemInDb.getId());
        // Even if the current provider is active, we should update the storage systems in SMISProvider.
        for (String providerStr : allProviders) {
            StorageProvider provider = _dbClient.queryObject(StorageProvider.class, URI.create(providerStr));
            updateStorageSystemsInProvider(provider, providersToUpdate, storageSystemInDb);
            // in storage system object, so that any change in provider object will take effect.
            if (provider.getId().equals(storageSystemInDb.getActiveProviderURI())) {
                if (!StringUtils.equals(provider.getIPAddress(), storageSystemInDb.getSmisProviderIP())) {
                    storageSystemInDb.setSmisProviderIP(provider.getIPAddress());
                }
                if (provider.getPortNumber() != storageSystemInDb.getSmisPortNumber()) {
                    storageSystemInDb.setSmisPortNumber(provider.getPortNumber());
                }
                if (!StringUtils.equals(provider.getUserName(), storageSystemInDb.getSmisUserName())) {
                    storageSystemInDb.setSmisUserName(provider.getUserName());
                }
                if (!StringUtils.equals(provider.getPassword(), storageSystemInDb.getSmisPassword())) {
                    storageSystemInDb.setSmisPassword(provider.getPassword());
                }
                if (provider.getUseSSL() != storageSystemInDb.getSmisUseSSL()) {
                    storageSystemInDb.setSmisUseSSL(provider.getUseSSL());
                }
            }
        }
    }
}
Also used : Iterator(java.util.Iterator) StringSet(com.emc.storageos.db.client.model.StringSet) StorageProvider(com.emc.storageos.db.client.model.StorageProvider)

Example 69 with StorageProvider

use of com.emc.storageos.db.client.model.StorageProvider in project coprhd-controller by CoprHD.

the class DataCollectionJobUtil method getAccessProfile.

/**
 * Create AccessProfile from DiscoveryJob
 *
 * TODO create subClasses for Accessprofile based on deviceType and Profile.
 * i.e. Metering-isilon accessProfile - a subclass under AccessProfile
 *
 * @param clazz
 * @param objectID
 * @param jobProfile
 * @return AccessProfile
 * @throws IOException
 */
public AccessProfile getAccessProfile(Class<? extends DataObject> clazz, URI objectID, String jobProfile, String nameSpace) throws DatabaseException, DeviceControllerException {
    DataObject taskObject = _dbClient.queryObject(clazz, objectID);
    AccessProfile profile = new AccessProfile();
    profile.setProfileName(jobProfile);
    profile.setRecordableEventManager(_eventManager);
    if (clazz == StorageProvider.class && StorageProvider.InterfaceType.smis.name().equalsIgnoreCase(((StorageProvider) taskObject).getInterfaceType())) {
        populateSMISAccessProfile(profile, (StorageProvider) taskObject);
    } else if (clazz == StorageProvider.class && StorageProvider.InterfaceType.hicommand.name().equalsIgnoreCase(((StorageProvider) taskObject).getInterfaceType())) {
        populateHDSAccessProfile(profile, (StorageProvider) taskObject);
    } else if (clazz == StorageProvider.class && StorageProvider.InterfaceType.cinder.name().equalsIgnoreCase(((StorageProvider) taskObject).getInterfaceType())) {
        populateCinderAccessProfile(profile, (StorageProvider) taskObject);
    } else if ((clazz == StorageProvider.class && StorageProvider.InterfaceType.vplex.name().equalsIgnoreCase(((StorageProvider) taskObject).getInterfaceType())) || (clazz == StorageSystem.class && DiscoveredDataObject.Type.vplex.name().equalsIgnoreCase(((StorageSystem) taskObject).getSystemType()))) {
        populateVPLEXAccessProfile(profile, taskObject, nameSpace);
    } else if (clazz == StorageProvider.class && StorageProvider.InterfaceType.scaleioapi.name().equalsIgnoreCase(((StorageProvider) taskObject).getInterfaceType())) {
        populateScaleIOAccessProfile(profile, (StorageProvider) taskObject);
    } else if (clazz == StorageProvider.class && StorageProvider.InterfaceType.ddmc.name().equalsIgnoreCase(((StorageProvider) taskObject).getInterfaceType())) {
        populateDataDomainAccessProfile(profile, (StorageProvider) taskObject);
    } else if (clazz == StorageProvider.class && StorageProvider.InterfaceType.ibmxiv.name().equalsIgnoreCase(((StorageProvider) taskObject).getInterfaceType())) {
        populateSMISAccessProfile(profile, (StorageProvider) taskObject);
        profile.setnamespace(Constants.IBM_NAMESPACE);
    } else if (clazz == StorageProvider.class && StorageProvider.InterfaceType.xtremio.name().equalsIgnoreCase(((StorageProvider) taskObject).getInterfaceType())) {
        populateXtremIOAccessProfile(profile, (StorageProvider) taskObject);
    } else if (clazz == StorageProvider.class && StorageProvider.InterfaceType.ceph.name().equalsIgnoreCase(((StorageProvider) taskObject).getInterfaceType())) {
        populateCephAccessProfile(profile, (StorageProvider) taskObject);
    } else if (clazz == StorageProvider.class && StorageProvider.InterfaceType.unity.name().equalsIgnoreCase(((StorageProvider) taskObject).getInterfaceType())) {
        populateUnityAccessProfile(profile, (StorageProvider) taskObject);
    } else if (clazz == StorageProvider.class && StorageSystem.Type.isDriverManagedStorageProvider(((StorageProvider) taskObject).getInterfaceType())) {
        populateExternalProviderAccessProfile(profile, (StorageProvider) taskObject);
    } else if (clazz == StorageSystem.class) {
        populateAccessProfile(profile, (StorageSystem) taskObject, nameSpace);
    } else if (clazz == ProtectionSystem.class) {
        populateAccessProfile(profile, (ProtectionSystem) taskObject, nameSpace);
    } else if (clazz == ComputeSystem.class) {
        populateAccessProfile(profile, (ComputeSystem) taskObject);
    } else if (clazz == NetworkSystem.class) {
        populateAccessProfile(profile, (NetworkSystem) taskObject);
    } else if (clazz == Host.class) {
        populateAccessProfile(profile, (Host) taskObject);
    } else if (clazz == Vcenter.class) {
        populateAccessProfile(profile, (Vcenter) taskObject);
    } else {
        throw new RuntimeException("getAccessProfile: profile is unknown for objects of type : " + taskObject.getClass());
    }
    return profile;
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) Host(com.emc.storageos.db.client.model.Host) AccessProfile(com.emc.storageos.plugins.AccessProfile) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 70 with StorageProvider

use of com.emc.storageos.db.client.model.StorageProvider in project coprhd-controller by CoprHD.

the class DataCollectionJobUtil method populateVPLEXAccessProfile.

/**
 * inject details needed for Scanning
 *
 * @param accessProfile
 * @param providerInfo
 */
private void populateVPLEXAccessProfile(AccessProfile accessProfile, DataObject vplexDataObject, String nameSpace) {
    if (vplexDataObject instanceof StorageProvider) {
        // Access profile for provider scanning
        StorageProvider vplexProvider = (StorageProvider) vplexDataObject;
        accessProfile.setSystemId(vplexProvider.getId());
        accessProfile.setSystemClazz(vplexProvider.getClass());
        accessProfile.setIpAddress(vplexProvider.getIPAddress());
        accessProfile.setUserName(vplexProvider.getUserName());
        accessProfile.setPassword(vplexProvider.getPassword());
        accessProfile.setSystemType(StorageProvider.InterfaceType.vplex.name());
        accessProfile.setPortNumber(vplexProvider.getPortNumber());
    } else {
        // Access profile for storage system discovery.
        StorageSystem vplexSystem = (StorageSystem) vplexDataObject;
        // Get the active VPLEX management server for the VPLEX system.
        StorageProvider activeProvider = null;
        URI activeProviderURI = vplexSystem.getActiveProviderURI();
        if (!NullColumnValueGetter.isNullURI(activeProviderURI)) {
            activeProvider = _dbClient.queryObject(StorageProvider.class, activeProviderURI);
        }
        // If there is no active provider, we can't discover.
        if (activeProvider == null) {
            vplexSystem.setLastDiscoveryStatusMessage("Discovery failed because we could not find an active management server");
            _dbClient.persistObject(vplexSystem);
            throw DeviceControllerException.exceptions.cannotFindActiveProviderForStorageSystem();
        }
        accessProfile.setSystemId(vplexSystem.getId());
        accessProfile.setSystemClazz(vplexSystem.getClass());
        accessProfile.setSystemType(vplexSystem.getSystemType());
        accessProfile.setserialID(vplexSystem.getSerialNumber());
        accessProfile.setIpAddress(activeProvider.getIPAddress());
        accessProfile.setUserName(activeProvider.getUserName());
        accessProfile.setPassword(activeProvider.getPassword());
        accessProfile.setPortNumber(activeProvider.getPortNumber());
        // accessProfile.setLastSampleTime(0L);
        if (null != nameSpace) {
            accessProfile.setnamespace(nameSpace);
        }
    }
}
Also used : StorageProvider(com.emc.storageos.db.client.model.StorageProvider) URI(java.net.URI) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

StorageProvider (com.emc.storageos.db.client.model.StorageProvider)97 URI (java.net.URI)44 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)26 ArrayList (java.util.ArrayList)24 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)23 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)19 Produces (javax.ws.rs.Produces)19 IOException (java.io.IOException)18 StringSet (com.emc.storageos.db.client.model.StringSet)17 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)15 Path (javax.ws.rs.Path)15 Consumes (javax.ws.rs.Consumes)11 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)10 MapStorageProvider (com.emc.storageos.api.mapper.functions.MapStorageProvider)8 StorageSystemViewObject (com.emc.storageos.plugins.StorageSystemViewObject)8 GET (javax.ws.rs.GET)8 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)7 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)7 AsyncTask (com.emc.storageos.volumecontroller.AsyncTask)7 BlockController (com.emc.storageos.volumecontroller.BlockController)7