Search in sources :

Example 1 with Error

use of com.emc.storageos.hds.model.Error 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 2 with Error

use of com.emc.storageos.hds.model.Error in project coprhd-controller by CoprHD.

the class HDSUtils method verifyErrorPayload.

/**
 * Utility method to check if there are any errors or not.
 *
 * @param javaResult
 * @throws Exception
 */
public static void verifyErrorPayload(JavaResult javaResult) throws Exception {
    EchoCommand command = javaResult.getBean(EchoCommand.class);
    if (null == command || null == command.getStatus() || HDSConstants.FAILED_STR.equalsIgnoreCase(command.getStatus())) {
        Error error = javaResult.getBean(Error.class);
        // log.info("Error response received from Hitachi server for messageID", command.getMessageID());
        log.info("Hitachi command failed with error code:{} with message:{} for request:{}", new Object[] { error.getCode().toString(), error.getDescription(), error.getSource() });
        throw HDSException.exceptions.errorResponseReceived(error.getCode(), error.getDescription());
    }
}
Also used : Error(com.emc.storageos.hds.model.Error) EchoCommand(com.emc.storageos.hds.model.EchoCommand)

Example 3 with Error

use of com.emc.storageos.hds.model.Error in project coprhd-controller by CoprHD.

the class HDSApiClient method verifyErrorPayload.

/**
 * Utility method to check if there are any errors or not.
 *
 * @param javaResult
 * @throws Exception
 */
public void verifyErrorPayload(JavaResult javaResult) throws Exception {
    EchoCommand command = javaResult.getBean(EchoCommand.class);
    if (null == command || null == command.getStatus() || HDSConstants.FAILED_STR.equalsIgnoreCase(command.getStatus())) {
        Error error = javaResult.getBean(Error.class);
        // log.info("Error response received from Hitachi server for messageID :{}", command.getMessageID());
        log.info("Hitachi command failed with error code:{} with message:{} for request:{}", new Object[] { error.getCode().toString(), error.getDescription(), error.getSource() });
        throw HDSException.exceptions.errorResponseReceived(error.getCode(), error.getDescription());
    }
}
Also used : Error(com.emc.storageos.hds.model.Error) EchoCommand(com.emc.storageos.hds.model.EchoCommand)

Example 4 with Error

use of com.emc.storageos.hds.model.Error in project coprhd-controller by CoprHD.

the class HDSApiClient method waitForCompletion.

/**
 * This method is responsible to check the async task status for every 3 seconds
 * and if we don't get status in 60 retries, throw exception.
 *
 * @param messageID : Task status for messageID
 * @return Parsed java result of response stream.
 */
public JavaResult waitForCompletion(String messageID) throws Exception {
    log.info("Verifying the Async task status for message {}", messageID);
    InputStream responseStream = null;
    EchoCommand command = null;
    JavaResult result = null;
    String statusQueryWithParams = String.format(STATUS_QUERY, messageID);
    int retries = 0;
    do {
        try {
            log.info("retrying {}th time", retries);
            ClientResponse response = client.post(getBaseURI(), statusQueryWithParams);
            if (HttpStatus.SC_OK == response.getStatus()) {
                responseStream = response.getEntityInputStream();
                result = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
                command = result.getBean(EchoCommand.class);
                // processing state.
                if (HDSConstants.PROCESSING_STR.equalsIgnoreCase(command.getStatus())) {
                    log.info("Async task is still in processing state. Hence sleeping...");
                    Thread.sleep(HDSConstants.TASK_PENDING_WAIT_TIME);
                }
            } else {
                throw HDSException.exceptions.asyncTaskInvalidResponse(response.getStatus());
            }
        } finally {
            try {
                if (null != responseStream) {
                    responseStream.close();
                }
            } catch (IOException ioEx) {
                log.warn("Ignoring io exception that occurred during stream closing for async status check for messageID {}", messageID);
            }
        }
    } while (HDSConstants.PROCESSING_STR.equalsIgnoreCase(command.getStatus()) && retries++ < HDSConstants.MAX_RETRIES);
    if (retries >= HDSConstants.MAX_RETRIES) {
        log.error("Async task exceeded the maximum number of retries");
        throw HDSException.exceptions.asyncTaskMaximumRetriesExceed(messageID);
    // handle carefully for the generated task. is it possible to cancel the task?
    }
    if (HDSConstants.FAILED_STR.equalsIgnoreCase(command.getStatus())) {
        Error error = result.getBean(Error.class);
        String errorMessage = String.format("Async task failed for messageID %s due to %s with error code: %d", messageID, error.getDescription(), error.getCode());
        log.error(errorMessage);
        HDSException.exceptions.asyncTaskFailedWithErrorResponse(messageID, error.getDescription(), error.getCode());
        throw new Exception(errorMessage);
    }
    log.info("Async task completed for messageID {}", messageID);
    return result;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) InputStream(java.io.InputStream) Error(com.emc.storageos.hds.model.Error) IOException(java.io.IOException) JavaResult(org.milyn.payload.JavaResult) EchoCommand(com.emc.storageos.hds.model.EchoCommand) IOException(java.io.IOException) HDSException(com.emc.storageos.hds.HDSException)

Example 5 with Error

use of com.emc.storageos.hds.model.Error in project coprhd-controller by CoprHD.

the class HDSApiDiscoveryManager method verifyErrorPayload.

/**
 * Utility method to check if there are any errors or not.
 *
 * @param javaResult
 * @throws Exception
 */
private void verifyErrorPayload(JavaResult javaResult) throws Exception {
    EchoCommand command = javaResult.getBean(EchoCommand.class);
    if (null == command || null == command.getStatus() || HDSConstants.FAILED_STR.equalsIgnoreCase(command.getStatus())) {
        Error error = javaResult.getBean(Error.class);
        log.info("Error response received for messageID", command.getMessageID());
        log.info("command failed with error code: {} with message {}", error.getCode(), error.getDescription());
        throw HDSException.exceptions.errorResponseReceived(error.getCode(), error.getDescription());
    }
}
Also used : Error(com.emc.storageos.hds.model.Error) EchoCommand(com.emc.storageos.hds.model.EchoCommand)

Aggregations

Error (com.emc.storageos.hds.model.Error)24 EchoCommand (com.emc.storageos.hds.model.EchoCommand)22 JavaResult (org.milyn.payload.JavaResult)17 ClientResponse (com.sun.jersey.api.client.ClientResponse)16 InputStream (java.io.InputStream)16 IOException (java.io.IOException)15 URI (java.net.URI)15 HashMap (java.util.HashMap)12 StorageArray (com.emc.storageos.hds.model.StorageArray)10 LogicalUnit (com.emc.storageos.hds.model.LogicalUnit)9 Add (com.emc.storageos.hds.model.Add)6 HDSException (com.emc.storageos.hds.HDSException)4 Delete (com.emc.storageos.hds.model.Delete)4 Modify (com.emc.storageos.hds.model.Modify)3 ArrayList (java.util.ArrayList)3 HDSHost (com.emc.storageos.hds.model.HDSHost)2 Pool (com.emc.storageos.hds.model.Pool)2 ReplicationInfo (com.emc.storageos.hds.model.ReplicationInfo)2 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)1 HDSConstants (com.emc.storageos.hds.HDSConstants)1