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;
}
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);
}
}
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;
}
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());
}
}
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());
}
Aggregations