Search in sources :

Example 1 with EchoCommand

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

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

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

the class HDSApiExportManager method registerHost.

/**
 * Register the given host with HiCommand Device Manager.
 *
 * @param hostName
 * @param ipAddress
 * @param portWWN
 * @return
 * @throws Exception
 */
public HDSHost registerHost(HDSHost hdshost, List<String> portWWNList, String initiatorType) throws Exception {
    String addHostQueryWithParams = null;
    InputStream responseStream = null;
    HDSHost registeredhost = null;
    try {
        if (initiatorType.equalsIgnoreCase(HDSConstants.FC)) {
            addHostQueryWithParams = constructAddFCInitiatorHostQuery(hdshost, portWWNList);
        } else if (initiatorType.equalsIgnoreCase(HDSConstants.ISCSI)) {
            addHostQueryWithParams = constructAddiSCSIInitiatorHostQuery(hdshost, portWWNList);
        }
        log.info("Query to Add host: {}", addHostQueryWithParams);
        URI endpointURI = hdsApiClient.getBaseURI();
        ClientResponse response = hdsApiClient.post(endpointURI, addHostQueryWithParams);
        if (HttpStatus.SC_OK == response.getStatus()) {
            responseStream = response.getEntityInputStream();
            JavaResult javaResult = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.HOST_INFO_SMOOKS_CONFIG_FILE);
            EchoCommand command = javaResult.getBean(EchoCommand.class);
            if (null == command || null == command.getStatus() || HDSConstants.FAILED_STR.equalsIgnoreCase(command.getStatus())) {
                Error error = javaResult.getBean(Error.class);
                if (error.getCode() == HDSConstants.HOST_ALREADY_EXISTS) {
                    log.info("The host {} already exists on DeviceManager", hdshost.getName());
                    return registeredhost;
                } else if (error.getCode() == HDSConstants.HOST_PORT_WWN_ALREADY_EXISTS) {
                    log.info("The WWN is already in use by another host");
                    return registeredhost;
                } else {
                    log.error("Error response received for messageID", command.getMessageID());
                    log.error("command failed with error code: {} with message {}", error.getCode(), error.getDescription());
                    throw HDSException.exceptions.notAbleToAddHostToDeviceManager(hdshost.getName());
                }
            }
            registeredhost = javaResult.getBean(HDSHost.class);
            if (null == registeredhost) {
                throw HDSException.exceptions.notAbleToAddHostToDeviceManager(String.format("Not able to add host:%1$s to Device manager", hdshost.getName()));
            }
        } else {
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("Add Host to Device Manager failed 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 registeredhost;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) HDSHost(com.emc.storageos.hds.model.HDSHost) InputStream(java.io.InputStream) Error(com.emc.storageos.hds.model.Error) IOException(java.io.IOException) URI(java.net.URI) JavaResult(org.milyn.payload.JavaResult) EchoCommand(com.emc.storageos.hds.model.EchoCommand)

Example 4 with EchoCommand

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

the class HDSApiProtectionManager method createShadowImagePair.

/**
 * Creates ShadowImage Pair
 *
 * @param replicationGroupObjId
 * @param pairName
 * @param arrayType
 * @param arraySerialNumber
 * @param pvolDevNum
 * @param svolDevNum
 * @param model
 * @return {@link ReplicationInfo}
 */
public ReplicationInfo createShadowImagePair(String replicationGroupObjId, String pairName, String arrayType, String arraySerialNumber, String pvolDevNum, String svolDevNum, String model) throws Exception {
    log.info("Shadow Image pair creation started");
    InputStream responseStream = null;
    ReplicationInfo replicationInfoResponse = null;
    String syncTaskMessageId = null;
    try {
        log.info("replicationGroupObjId {} ", replicationGroupObjId);
        log.info("arrayType {} arraySerialNumber {}", arrayType, arraySerialNumber);
        log.info(" pvolDevNum {} svolDevNum {}", pvolDevNum, svolDevNum);
        Map<String, Object> attributeMap = new HashMap<String, Object>();
        Add addOp = new Add(HDSConstants.REPLICATION);
        ReplicationGroup replicationGroup = new ReplicationGroup();
        replicationGroup.setObjectID(replicationGroupObjId);
        replicationGroup.setReplicationFunction(HDSConstants.SHADOW_IMAGE);
        ReplicationInfo replicationInfo = new ReplicationInfo();
        replicationInfo.setPairName(pairName);
        replicationInfo.setPvolArrayType(arrayType);
        replicationInfo.setPvolSerialNumber(arraySerialNumber);
        replicationInfo.setPvolDevNum(pvolDevNum);
        replicationInfo.setSvolArrayType(arrayType);
        replicationInfo.setSvolSerialNumber(arraySerialNumber);
        replicationInfo.setSvolDevNum(svolDevNum);
        replicationInfo.setReplicationFunction(HDSConstants.SHADOW_IMAGE);
        attributeMap.put(HDSConstants.ADD, addOp);
        attributeMap.put(HDSConstants.MODEL, model);
        attributeMap.put(HDSConstants.REPLICATION_GROUP, replicationGroup);
        attributeMap.put(HDSConstants.REPLICATION_INFO, replicationInfo);
        String createShadowImagePairInputXML = InputXMLGenerationClient.getInputXMLString(HDSConstants.CREATE_SHADOW_IMAGE_PAIR_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
        log.info("Query to create shadow image pair volume: {}", createShadowImagePairInputXML);
        URI endpointURI = hdsApiClient.getBaseURI();
        ClientResponse response = hdsApiClient.post(endpointURI, createShadowImagePairInputXML);
        if (HttpStatus.SC_OK == response.getStatus()) {
            responseStream = response.getEntityInputStream();
            JavaResult result = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.HITACHI_SMOOKS_REPLICATION_CONFIG_FILE);
            EchoCommand command = result.getBean(EchoCommand.class);
            if (HDSConstants.COMPLETED_STR.equalsIgnoreCase(command.getStatus())) {
                log.info("ShadowImage Pair has been created successfully");
                replicationInfoResponse = result.getBean(ReplicationInfo.class);
                if (null == replicationInfoResponse) {
                    throw HDSException.exceptions.notAbleToCreateShadowImagePair();
                }
            } else if (HDSConstants.PROCESSING_STR.equalsIgnoreCase(command.getStatus())) {
                syncTaskMessageId = command.getMessageID();
            } else if (HDSConstants.FAILED_STR.equalsIgnoreCase(command.getStatus())) {
                Error error = result.getBean(Error.class);
                log.error("Shadow Image pair creation failed status messageID: {}", command.getMessageID());
                log.error("Shadow Image pair creation failed with error code: {} with message: {}", error.getCode(), error.getDescription());
                throw HDSException.exceptions.notAbleToCreateVolume(error.getCode(), error.getDescription());
            }
        } else {
            log.error("Shadow Image pair creation failed with invalid response code {}", response.getStatus());
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("Shadow Image pair creation failed due to invalid response %1$s from server for system %2$s", response.getStatus(), arraySerialNumber));
        }
    } finally {
        if (null != responseStream) {
            try {
                responseStream.close();
            } catch (IOException e) {
                log.warn("Exception occurred while close Shadow Image Pair creation response stream");
            }
        }
    }
    log.info("Shadow Image pair creation completed");
    return replicationInfoResponse;
}
Also used : Add(com.emc.storageos.hds.model.Add) ClientResponse(com.sun.jersey.api.client.ClientResponse) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Error(com.emc.storageos.hds.model.Error) IOException(java.io.IOException) ReplicationGroup(com.emc.storageos.hds.model.ReplicationGroup) URI(java.net.URI) ReplicationInfo(com.emc.storageos.hds.model.ReplicationInfo) JavaResult(org.milyn.payload.JavaResult) EchoCommand(com.emc.storageos.hds.model.EchoCommand)

Example 5 with EchoCommand

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

the class HDSApiProtectionManager method createThinImagePair.

/**
 * Creates ThinImage pair for HDS Snapshot
 *
 * @param snapshotGroupObjId
 * @param hostObjId
 * @param sourNativeId
 * @param snapNativeId
 * @param thinImagePoolId
 * @return
 * @throws Exception
 */
public boolean createThinImagePair(String snapshotGroupObjId, String hostObjId, String sourNativeId, String snapNativeId, String thinImagePoolId, String model) throws Exception {
    log.info("Thin Image pair creation started");
    boolean status = false;
    InputStream responseStream = null;
    String syncTaskMessageId = null;
    try {
        log.info("snapshotGroupObjId {} ", snapshotGroupObjId);
        Map<String, Object> attributeMap = new HashMap<String, Object>();
        Add addOp = new Add(HDSConstants.REPLICATION);
        addOp.setOption(HDSConstants.INBAND2);
        HDSHost host = new HDSHost();
        host.setObjectID(hostObjId);
        SnapshotGroup snapshotGroup = new SnapshotGroup();
        snapshotGroup.setObjectID(snapshotGroupObjId);
        snapshotGroup.setReplicationFunction(HDSConstants.THIN_IMAGE);
        ReplicationInfo replicationInfo = new ReplicationInfo();
        replicationInfo.setPvolDevNum(sourNativeId);
        replicationInfo.setSvolDevNum(snapNativeId);
        replicationInfo.setPvolPoolID(thinImagePoolId);
        attributeMap.put(HDSConstants.ADD, addOp);
        attributeMap.put(HDSConstants.MODEL, model);
        attributeMap.put(HDSConstants.HOST, host);
        attributeMap.put(HDSConstants.SNAPSHOTGROUP, snapshotGroup);
        attributeMap.put(HDSConstants.REPLICATION_INFO, replicationInfo);
        String createThinImagePairInputXML = InputXMLGenerationClient.getInputXMLString(HDSConstants.CREATE_THIN_IMAGE_PAIR_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
        log.info("Query to create thin image pair : {}", createThinImagePairInputXML);
        URI endpointURI = hdsApiClient.getBaseURI();
        ClientResponse response = hdsApiClient.post(endpointURI, createThinImagePairInputXML);
        if (HttpStatus.SC_OK == response.getStatus()) {
            responseStream = response.getEntityInputStream();
            JavaResult result = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.HITACHI_SMOOKS_THINIMAGE_CONFIG_FILE);
            EchoCommand command = result.getBean(EchoCommand.class);
            if (HDSConstants.COMPLETED_STR.equalsIgnoreCase(command.getStatus())) {
                log.info("ThinImage Pair has been created successfully");
                status = true;
                SnapshotGroup snapshotGrpResponse = result.getBean(SnapshotGroup.class);
                if (null == snapshotGrpResponse) {
                    throw HDSException.exceptions.notAbleToCreateThinImagePair();
                }
            } else if (HDSConstants.PROCESSING_STR.equalsIgnoreCase(command.getStatus())) {
                syncTaskMessageId = command.getMessageID();
            } else if (HDSConstants.FAILED_STR.equalsIgnoreCase(command.getStatus())) {
                Error error = result.getBean(Error.class);
                log.error("Thin Image pair creation failed status messageID: {}", command.getMessageID());
                log.error("Thin Image pair creation failed with error code: {} with message: {}", error.getCode(), error.getDescription());
                throw HDSException.exceptions.notAbleToCreateThinImagePairError(error.getCode(), error.getDescription());
            }
        } else {
            log.error("Thin Image pair creation failed with invalid response code {}", response.getStatus());
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("Thin Image pair creation failed due to invalid response %1$s from server", response.getStatus()));
        }
    } finally {
        if (null != responseStream) {
            try {
                responseStream.close();
            } catch (IOException e) {
                log.warn("Exception occurred while close Thin Image Pair creation response stream");
            }
        }
    }
    log.info("Thin Image pair creation completed");
    return status;
}
Also used : Add(com.emc.storageos.hds.model.Add) ClientResponse(com.sun.jersey.api.client.ClientResponse) HDSHost(com.emc.storageos.hds.model.HDSHost) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Error(com.emc.storageos.hds.model.Error) IOException(java.io.IOException) URI(java.net.URI) SnapshotGroup(com.emc.storageos.hds.model.SnapshotGroup) ReplicationInfo(com.emc.storageos.hds.model.ReplicationInfo) JavaResult(org.milyn.payload.JavaResult) EchoCommand(com.emc.storageos.hds.model.EchoCommand)

Aggregations

EchoCommand (com.emc.storageos.hds.model.EchoCommand)21 Error (com.emc.storageos.hds.model.Error)21 JavaResult (org.milyn.payload.JavaResult)14 ClientResponse (com.sun.jersey.api.client.ClientResponse)13 InputStream (java.io.InputStream)13 IOException (java.io.IOException)12 URI (java.net.URI)12 HashMap (java.util.HashMap)11 LogicalUnit (com.emc.storageos.hds.model.LogicalUnit)9 StorageArray (com.emc.storageos.hds.model.StorageArray)9 Add (com.emc.storageos.hds.model.Add)5 Delete (com.emc.storageos.hds.model.Delete)3 Modify (com.emc.storageos.hds.model.Modify)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 ArrayList (java.util.ArrayList)2 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)1 HDSException (com.emc.storageos.hds.HDSException)1 HDSApiClient (com.emc.storageos.hds.api.HDSApiClient)1