Search in sources :

Example 1 with JavaResult

use of org.milyn.payload.JavaResult 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 JavaResult

use of org.milyn.payload.JavaResult in project coprhd-controller by CoprHD.

the class HDSApiClient method checkAsyncTaskStatus.

/**
 * This method is responsible to check the async task status.
 *
 * @param messageID : Task status for messageID
 * @return Parsed java result of response stream.
 */
public JavaResult checkAsyncTaskStatus(String messageID) throws Exception {
    InputStream responseStream = null;
    JavaResult result = null;
    try {
        String statusQueryWithParams = String.format(STATUS_QUERY, messageID);
        ClientResponse response = client.post(getBaseURI(), statusQueryWithParams);
        if (HttpStatus.SC_OK == response.getStatus()) {
            responseStream = response.getEntityInputStream();
            result = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
        } 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);
        }
    }
    return result;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) InputStream(java.io.InputStream) IOException(java.io.IOException) JavaResult(org.milyn.payload.JavaResult)

Example 3 with JavaResult

use of org.milyn.payload.JavaResult 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 4 with JavaResult

use of org.milyn.payload.JavaResult in project coprhd-controller by CoprHD.

the class HDSApiDiscoveryManager method getThinImagePoolList.

public List<Pool> getThinImagePoolList(String systemObjectId) throws Exception {
    InputStream responseStream = null;
    StorageArray storageArray = null;
    try {
        URI endpointURI = hdsApiClient.getBaseURI();
        Map<String, Object> attributeMap = new HashMap<String, Object>();
        StorageArray inputStorageArray = new StorageArray(systemObjectId);
        Get getOp = new Get(HDSConstants.STORAGEARRAY);
        Condition condition = new Condition("6");
        attributeMap.put(HDSConstants.GET, getOp);
        attributeMap.put(HDSConstants.STORAGEARRAY, inputStorageArray);
        attributeMap.put(HDSConstants.CONDITION, condition);
        String getThinImagePoolInputXML = InputXMLGenerationClient.getInputXMLString(HDSConstants.GET_THINIMAGE_POOL_INFO_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
        log.info("Query to get ThinImagePool :{}", getThinImagePoolInputXML);
        ClientResponse response = hdsApiClient.post(endpointURI, getThinImagePoolInputXML);
        if (HttpStatus.SC_OK == response.getStatus()) {
            responseStream = response.getEntityInputStream();
            JavaResult result = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
            verifyErrorPayload(result);
            storageArray = result.getBean(StorageArray.class);
        } else {
            log.error("Get system details failed with invalid response code {}", response.getStatus());
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to query system details due to invalid response %1$s from server", response.getStatus()));
        }
    } finally {
        if (null != responseStream) {
            try {
                responseStream.close();
            } catch (IOException e) {
                log.warn("IOException occurred while closing the response stream");
            }
        }
    }
    return storageArray.getThinPoolList();
}
Also used : Condition(com.emc.storageos.hds.model.Condition) ClientResponse(com.sun.jersey.api.client.ClientResponse) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Get(com.emc.storageos.hds.model.Get) IOException(java.io.IOException) URI(java.net.URI) JavaResult(org.milyn.payload.JavaResult) StorageArray(com.emc.storageos.hds.model.StorageArray)

Example 5 with JavaResult

use of org.milyn.payload.JavaResult in project coprhd-controller by CoprHD.

the class HDSApiDiscoveryManager method getStoragePoolsTierInfo.

/**
 * Returns all storage system information.
 *
 * @return
 * @throws Exception
 */
public List<Pool> getStoragePoolsTierInfo(String systemObjectID) throws Exception {
    InputStream responseStream = null;
    List<Pool> poolList = null;
    URI endpointURI = hdsApiClient.getBaseURI();
    Map<String, Object> attributeMap = new HashMap<String, Object>();
    StorageArray inputStorageArray = new StorageArray(systemObjectID);
    Get getOp = new Get(HDSConstants.STORAGEARRAY);
    attributeMap.put(HDSConstants.STORAGEARRAY, inputStorageArray);
    attributeMap.put(HDSConstants.GET, getOp);
    String getPoolTieringInfoInputXML = InputXMLGenerationClient.getInputXMLString(HDSConstants.GET_STORAGE_POOL_TIERING_INFO_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
    log.info("Get StoragePools Tiering info query payload :{}", getPoolTieringInfoInputXML);
    ClientResponse response = hdsApiClient.post(endpointURI, getPoolTieringInfoInputXML);
    if (HttpStatus.SC_OK == response.getStatus()) {
        responseStream = response.getEntityInputStream();
        JavaResult result = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
        verifyErrorPayload(result);
        poolList = (List<Pool>) result.getBean("thinPoolList");
    } else {
        log.error("Get pools tiering info failed with invalid response code {}", response.getStatus());
        throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to query pools tiering info due to invalid response %1$s from server", response.getStatus()));
    }
    return poolList;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Get(com.emc.storageos.hds.model.Get) Pool(com.emc.storageos.hds.model.Pool) URI(java.net.URI) JavaResult(org.milyn.payload.JavaResult) StorageArray(com.emc.storageos.hds.model.StorageArray)

Aggregations

JavaResult (org.milyn.payload.JavaResult)57 InputStream (java.io.InputStream)53 ClientResponse (com.sun.jersey.api.client.ClientResponse)52 URI (java.net.URI)50 IOException (java.io.IOException)42 HashMap (java.util.HashMap)38 StorageArray (com.emc.storageos.hds.model.StorageArray)26 Error (com.emc.storageos.hds.model.Error)17 Get (com.emc.storageos.hds.model.Get)16 EchoCommand (com.emc.storageos.hds.model.EchoCommand)15 LogicalUnit (com.emc.storageos.hds.model.LogicalUnit)13 Add (com.emc.storageos.hds.model.Add)11 HostStorageDomain (com.emc.storageos.hds.model.HostStorageDomain)11 HDSHost (com.emc.storageos.hds.model.HDSHost)8 Delete (com.emc.storageos.hds.model.Delete)7 HDSException (com.emc.storageos.hds.HDSException)6 ReplicationInfo (com.emc.storageos.hds.model.ReplicationInfo)6 Modify (com.emc.storageos.hds.model.Modify)5 Pool (com.emc.storageos.hds.model.Pool)5 ArrayList (java.util.ArrayList)5