Search in sources :

Example 16 with HDSApiClient

use of com.emc.storageos.hds.api.HDSApiClient in project coprhd-controller by CoprHD.

the class HDSJob method poll.

@Override
public JobPollResult poll(JobContext jobContext, long trackingPeriodInMillis) {
    String messageId = getHDSJobMessageId();
    try {
        StorageSystem storageSystem = jobContext.getDbClient().queryObject(StorageSystem.class, getStorageSystemURI());
        logger.info("HDSJob: Looking up job: id {}, provider: {} ", messageId, storageSystem.getActiveProviderURI());
        HDSApiClient hdsApiClient = jobContext.getHdsApiFactory().getClient(HDSUtils.getHDSServerManagementServerInfo(storageSystem), storageSystem.getSmisUserName(), storageSystem.getSmisPassword());
        _pollResult.setJobName(getJobName());
        _pollResult.setJobId(messageId);
        if (hdsApiClient == null) {
            String errorMessage = "No HDS client found for provider ip: " + storageSystem.getActiveProviderURI();
            processTransientError(messageId, trackingPeriodInMillis, errorMessage, null);
        } else {
            JavaResult javaResult = hdsApiClient.checkAsyncTaskStatus(messageId);
            if (null == javaResult) {
                _pollResult.setJobPercentComplete(100);
                _errorDescription = String.format("Async task failed for messageID %s due to no response from server", messageId);
                _status = JobStatus.FAILED;
                logger.error("HDSJob: {} failed; Details: {}", getJobName(), _errorDescription);
            } else {
                EchoCommand command = javaResult.getBean(EchoCommand.class);
                if (HDSConstants.COMPLETED_STR.equalsIgnoreCase(command.getStatus())) {
                    _status = JobStatus.SUCCESS;
                    _pollResult.setJobPercentComplete(100);
                    _javaResult = javaResult;
                    logger.info("HDSJob: {} succeeded", messageId);
                } else if (HDSConstants.FAILED_STR.equalsIgnoreCase(command.getStatus())) {
                    Error error = javaResult.getBean(Error.class);
                    _pollResult.setJobPercentComplete(100);
                    _errorDescription = String.format("Async task failed for messageID %s due to %s with error code: %d", messageId, error.getDescription(), error.getCode());
                    _status = JobStatus.FAILED;
                    logger.error("HDSJob: {} failed; Details: {}", getJobName(), _errorDescription);
                }
            }
        }
    } catch (NoHttpResponseException ex) {
        _status = JobStatus.FAILED;
        _pollResult.setJobPercentComplete(100);
        _errorDescription = ex.getMessage();
        logger.error(String.format("HDS job not found. Marking as failed as we cannot determine status. " + "User may retry the operation to be sure: Name: %s, ID: %s, Desc: %s", getJobName(), messageId, _errorDescription), ex);
    } catch (Exception e) {
        processTransientError(messageId, trackingPeriodInMillis, e.getMessage(), e);
    } finally {
        try {
            _postProcessingStatus = JobStatus.SUCCESS;
            updateStatus(jobContext);
            if (_postProcessingStatus == JobStatus.ERROR) {
                processPostProcessingError(messageId, trackingPeriodInMillis, _errorDescription, null);
            }
        } catch (Exception e) {
            setFatalErrorStatus(e.getMessage());
            setPostProcessingFailedStatus(e.getMessage());
            logger.error("Problem while trying to update status", e);
        } finally {
            if (isJobInTerminalFailedState()) {
                // Have to process job completion since updateStatus may not did this.
                ServiceError error = DeviceControllerErrors.hds.jobFailed(_errorDescription);
                getTaskCompleter().error(jobContext.getDbClient(), error);
            }
        }
    }
    _pollResult.setJobStatus(_status);
    _pollResult.setJobPostProcessingStatus(_postProcessingStatus);
    _pollResult.setErrorDescription(_errorDescription);
    return _pollResult;
}
Also used : NoHttpResponseException(org.apache.commons.httpclient.NoHttpResponseException) HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) Error(com.emc.storageos.hds.model.Error) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) JavaResult(org.milyn.payload.JavaResult) EchoCommand(com.emc.storageos.hds.model.EchoCommand) NoHttpResponseException(org.apache.commons.httpclient.NoHttpResponseException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 17 with HDSApiClient

use of com.emc.storageos.hds.api.HDSApiClient in project coprhd-controller by CoprHD.

the class HDSVolumeExpandJob method updateStatus.

/**
 * Called to update the job status when the volume expand job completes.
 *
 * @param jobContext
 *            The job context.
 */
@Override
public void updateStatus(JobContext jobContext) throws Exception {
    LogicalUnit logicalUnit = null;
    try {
        if (_status == JobStatus.IN_PROGRESS) {
            return;
        }
        DbClient dbClient = jobContext.getDbClient();
        StorageSystem storageSystem = dbClient.queryObject(StorageSystem.class, getStorageSystemURI());
        HDSApiClient hdsApiClient = jobContext.getHdsApiFactory().getClient(HDSUtils.getHDSServerManagementServerInfo(storageSystem), storageSystem.getSmisUserName(), storageSystem.getSmisPassword());
        // from pool's reserved capacity map.
        if (_status == JobStatus.SUCCESS || _status == JobStatus.FAILED) {
            StoragePool storagePool = dbClient.queryObject(StoragePool.class, storagePoolURI);
            HDSUtils.updateStoragePoolCapacity(dbClient, hdsApiClient, storagePool);
            StringMap reservationMap = storagePool.getReservedCapacityMap();
            URI volumeId = getTaskCompleter().getId();
            // remove from reservation map
            reservationMap.remove(volumeId.toString());
            dbClient.persistObject(storagePool);
        }
        String opId = getTaskCompleter().getOpId();
        StringBuilder logMsgBuilder = new StringBuilder(String.format("Updating status of job %s to %s, task: %s", this.getJobName(), _status.name(), opId));
        if (_status == JobStatus.SUCCESS) {
            VolumeExpandCompleter taskCompleter = (VolumeExpandCompleter) getTaskCompleter();
            Volume volume = dbClient.queryObject(Volume.class, taskCompleter.getId());
            // set requested capacity
            volume.setCapacity(taskCompleter.getSize());
            // set meta related properties
            volume.setIsComposite(taskCompleter.isComposite());
            volume.setCompositionType(taskCompleter.getMetaVolumeType());
            logicalUnit = (LogicalUnit) _javaResult.getBean("logicalunit");
            if (null != logicalUnit) {
                long capacityInBytes = (Long.valueOf(logicalUnit.getCapacityInKB())) * 1024L;
                volume.setProvisionedCapacity(capacityInBytes);
                volume.setAllocatedCapacity(capacityInBytes);
            }
            logMsgBuilder.append(String.format("%n   Capacity: %s, Provisioned capacity: %s, Allocated Capacity: %s", volume.getCapacity(), volume.getProvisionedCapacity(), volume.getAllocatedCapacity()));
            if (volume.getIsComposite()) {
                logMsgBuilder.append(String.format("%n  Is Meta: %s, Total meta member capacity: %s, Meta member count %s, Meta member size: %s", volume.getIsComposite(), volume.getTotalMetaMemberCapacity(), volume.getMetaMemberCount(), volume.getMetaMemberSize()));
            }
            _log.info(logMsgBuilder.toString());
            dbClient.persistObject(volume);
            // Reset list of meta members native ids in WF data (when meta
            // is created meta members are removed from array)
            WorkflowService.getInstance().storeStepData(opId, new ArrayList<String>());
        }
    } catch (Exception e) {
        _log.error("Caught an exception while trying to updateStatus for HDSVolumeExpandJob", e);
        setErrorStatus("Encountered an internal error during volume expand job status processing : " + e.getMessage());
    } finally {
        super.updateStatus(jobContext);
    }
}
Also used : HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) StringMap(com.emc.storageos.db.client.model.StringMap) DbClient(com.emc.storageos.db.client.DbClient) StoragePool(com.emc.storageos.db.client.model.StoragePool) VolumeExpandCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.VolumeExpandCompleter) LogicalUnit(com.emc.storageos.hds.model.LogicalUnit) URI(java.net.URI) Volume(com.emc.storageos.db.client.model.Volume) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 18 with HDSApiClient

use of com.emc.storageos.hds.api.HDSApiClient in project coprhd-controller by CoprHD.

the class HDSUtils method refreshHDSConnections.

/**
 * makes simple rest call to device manager to validate the provider reachable state for passed hds providers
 *
 * @param hicommandProviderList List of HiCommandDevice Manager provider URIs
 * @param dbClient
 * @param hdsApiFactory
 * @return List of Active Storage Providers
 */
public static List<URI> refreshHDSConnections(final List<StorageProvider> hicommandProviderList, DbClient dbClient, HDSApiFactory hdsApiFactory) {
    List<URI> activeProviders = new ArrayList<URI>();
    for (StorageProvider storageProvider : hicommandProviderList) {
        try {
            HDSApiClient hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storageProvider), storageProvider.getUserName(), storageProvider.getPassword());
            // Makes sure "Hi Command Device manager" is reachable
            hdsApiClient.getStorageSystemsInfo();
            storageProvider.setConnectionStatus(ConnectionStatus.CONNECTED.name());
            activeProviders.add(storageProvider.getId());
            log.info("Storage Provider {} is reachable", storageProvider.getIPAddress());
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            storageProvider.setConnectionStatus(ConnectionStatus.NOTCONNECTED.name());
            log.error("Storage Provider {} is not reachable", storageProvider.getIPAddress());
        } finally {
            dbClient.persistObject(storageProvider);
        }
    }
    return activeProviders;
}
Also used : HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) ArrayList(java.util.ArrayList) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) HDSException(com.emc.storageos.hds.HDSException)

Example 19 with HDSApiClient

use of com.emc.storageos.hds.api.HDSApiClient in project coprhd-controller by CoprHD.

the class HDSCommunicationInterface method discover.

@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());
        StorageSystem storageSystem = null;
        String detailedStatusMessage = "Unknown Status";
        try {
            storageSystem = _dbClient.queryObject(StorageSystem.class, accessProfile.getSystemId());
            HDSApiClient hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(accessProfile), accessProfile.getUserName(), accessProfile.getPassword());
            // HDS+ARRAY.AMS200.73012495
            Iterable<String> splitter = Splitter.on(HDSConstants.PLUS_OPERATOR).limit(2).split(storageSystem.getNativeGuid());
            String objectID = Iterables.getLast(splitter);
            StorageArray storageArray = hdsApiClient.getStorageSystemDetails(objectID);
            if (null != storageArray) {
                parseDiscoveryResponse(storageArray, accessProfile);
                storageArray = hdsApiClient.getStorageSystemTieringPolicies(objectID);
                parseDiscoveryTieringPolicyResponse(storageArray, accessProfile);
                fetchStoragePoolTiers(storageSystem, objectID, accessProfile, hdsApiClient);
            } else {
                _logger.error("Discovery failed for system {} as not able to retrieve information from HiCommand DM");
                throw new HDSCollectionException("Discovery failed for system as not able to retrieve information from HiCommand Device Manager.");
            }
            // discovery succeeds
            detailedStatusMessage = String.format("Discovery completed successfully for HDS: %s", accessProfile.getSystemId());
        } catch (Exception e) {
            if (null != storageSystem) {
                cleanupDiscovery(storageSystem);
            }
            detailedStatusMessage = String.format("Discovery failed for Storage System: %s because %s", storageSystem.toString(), e.getLocalizedMessage());
            _logger.error(detailedStatusMessage, e);
            throw new HDSCollectionException(detailedStatusMessage);
        } finally {
            try {
                if (storageSystem != null) {
                    storageSystem.setLastDiscoveryStatusMessage(detailedStatusMessage);
                    _dbClient.persistObject(storageSystem);
                }
            } catch (Exception e) {
                _logger.error(e.getMessage(), e);
            }
        }
        _logger.info("Discovery Ended for system {}", accessProfile.getSystemId());
    }
}
Also used : HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) HDSCollectionException(com.emc.storageos.volumecontroller.impl.hds.HDSCollectionException) HDSCollectionException(com.emc.storageos.volumecontroller.impl.hds.HDSCollectionException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) HDSException(com.emc.storageos.hds.HDSException) WBEMException(javax.wbem.WBEMException) IOException(java.io.IOException) SMIPluginException(com.emc.storageos.plugins.metering.smis.SMIPluginException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) StorageArray(com.emc.storageos.hds.model.StorageArray)

Example 20 with HDSApiClient

use of com.emc.storageos.hds.api.HDSApiClient in project coprhd-controller by CoprHD.

the class HDSCommunicationInterface method scan.

@Override
public void scan(AccessProfile accessProfile) throws BaseCollectionException {
    _logger.info("Scanning started for provider: {}", accessProfile.getSystemId());
    StorageProvider provider = _dbClient.queryObject(StorageProvider.class, accessProfile.getSystemId());
    boolean exceptionOccured = false;
    try {
        HDSApiClient hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(accessProfile), accessProfile.getUserName(), accessProfile.getPassword());
        String apiVersion = hdsApiClient.getProviderAPIVersion();
        _logger.info("Provider {} API Version:{}", provider.getLabel(), apiVersion);
        provider.setVersionString(apiVersion);
        String minimumSupportedVersion = ControllerUtils.getPropertyValueFromCoordinator(_coordinator, CONTROLLER_HICOMMAND_PROVIDER_VERSION);
        if (VersionChecker.verifyVersionDetails(minimumSupportedVersion, apiVersion) < 0) {
            provider.setCompatibilityStatus(DiscoveredDataObject.CompatibilityStatus.INCOMPATIBLE.name());
            throw new HDSCollectionException(String.format(" ** The HiCommand Device Manager API version is not supported. Minimum supported version should be: %s", minimumSupportedVersion));
        }
        provider.setCompatibilityStatus(DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name());
        List<StorageArray> storageArrayList = hdsApiClient.getStorageSystemsInfo();
        if (null != storageArrayList && !storageArrayList.isEmpty()) {
            _logger.debug("Received proper response from HiCommand server");
            processScanResponse(storageArrayList, accessProfile);
        } else {
            _logger.info("No Systems found during scanning of provider: {}", provider.getId());
        }
    } catch (Exception ex) {
        exceptionOccured = true;
        _logger.error("Exception occurred while scanning provider {}", accessProfile.getSystemId(), ex);
        throw HDSException.exceptions.scanFailed(ex);
    } finally {
        if (exceptionOccured) {
            provider.setConnectionStatus(ConnectionStatus.NOTCONNECTED.name());
        } else {
            provider.setConnectionStatus(ConnectionStatus.CONNECTED.name());
        }
        _dbClient.persistObject(provider);
    }
    _logger.info("Scanning ended for provider: {}", accessProfile.getSystemId());
}
Also used : HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) HDSCollectionException(com.emc.storageos.volumecontroller.impl.hds.HDSCollectionException) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) HDSCollectionException(com.emc.storageos.volumecontroller.impl.hds.HDSCollectionException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) HDSException(com.emc.storageos.hds.HDSException) WBEMException(javax.wbem.WBEMException) IOException(java.io.IOException) SMIPluginException(com.emc.storageos.plugins.metering.smis.SMIPluginException) StorageArray(com.emc.storageos.hds.model.StorageArray)

Aggregations

HDSApiClient (com.emc.storageos.hds.api.HDSApiClient)45 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)26 HDSException (com.emc.storageos.hds.HDSException)26 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)21 Volume (com.emc.storageos.db.client.model.Volume)14 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)13 HDSApiExportManager (com.emc.storageos.hds.api.HDSApiExportManager)12 HostStorageDomain (com.emc.storageos.hds.model.HostStorageDomain)12 ArrayList (java.util.ArrayList)12 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)11 HashSet (java.util.HashSet)11 ExportMask (com.emc.storageos.db.client.model.ExportMask)10 LogicalUnit (com.emc.storageos.hds.model.LogicalUnit)10 URI (java.net.URI)10 HDSJob (com.emc.storageos.volumecontroller.impl.hds.prov.job.HDSJob)9 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)8 ReplicationInfo (com.emc.storageos.hds.model.ReplicationInfo)7 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)7 StoragePool (com.emc.storageos.db.client.model.StoragePool)6 HDSApiProtectionManager (com.emc.storageos.hds.api.HDSApiProtectionManager)6