Search in sources :

Example 1 with HDSHost

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

the class HDSSnapshotOperations method restoreSingleVolumeSnapshot.

/**
 * 1. Find pair management server.
 * 2. Get SnapshotGroup's Object Id.
 * 3. Get ReplicationInfo's Object Id.
 * 4. Perform ReplicationInfo Restore operation.
 */
@Override
public void restoreSingleVolumeSnapshot(StorageSystem storage, URI volume, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
    try {
        BlockSnapshot from = dbClient.queryObject(BlockSnapshot.class, snapshot);
        Volume to = dbClient.queryObject(Volume.class, volume);
        HDSApiClient hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storage), storage.getSmisUserName(), storage.getSmisPassword());
        HDSHost pairMgmtServer = hdsApiClient.getSnapshotGroupPairManagementServer(storage.getSerialNumber());
        if (pairMgmtServer == null) {
            log.error("Unable to find snapshot group information/pair management server for Thin Image");
            throw HDSException.exceptions.snapshotGroupNotAvailable(storage.getNativeGuid());
        }
        SnapshotGroup snapShotGrp = getViPRSnapshotGroup(pairMgmtServer, storage.getSerialNumber());
        log.debug("to.getNativeId() :{}", to.getNativeId());
        log.debug("from.getNativeId() :{}", from.getNativeId());
        ReplicationInfo repInfo = getReplicationInfo(snapShotGrp, to.getNativeId(), from.getNativeId());
        hdsApiClient.restoreThinImagePair(pairMgmtServer.getObjectID(), snapShotGrp.getObjectID(), repInfo.getObjectID(), storage.getModel());
        taskCompleter.ready(dbClient);
        log.info("Restore Snapshot volume completed");
    } catch (Exception e) {
        String message = String.format("Generic exception when trying to restore from snapshot %s on array %s", snapshot.toString(), storage.getSerialNumber());
        log.error(message, e);
        ServiceError error = DeviceControllerErrors.hds.methodFailed("restoreSingleVolumeSnapshot", e.getMessage());
        taskCompleter.error(dbClient, error);
    }
}
Also used : HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) HDSHost(com.emc.storageos.hds.model.HDSHost) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) Volume(com.emc.storageos.db.client.model.Volume) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ReplicationInfo(com.emc.storageos.hds.model.ReplicationInfo) SnapshotGroup(com.emc.storageos.hds.model.SnapshotGroup) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HDSException(com.emc.storageos.hds.HDSException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 2 with HDSHost

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

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

the class HDSApiExportManager method getHostsRegisteredWithDM.

/**
 * Gets host registered with HiCommand Device Manager.
 *
 * @return
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public List<HDSHost> getHostsRegisteredWithDM() throws Exception {
    InputStream responseStream = null;
    List<HDSHost> hostList = null;
    try {
        Map<String, Object> attributeMap = new HashMap<String, Object>();
        Get getOp = new Get("Host");
        attributeMap.put("Get", getOp);
        String getHostQuery = InputXMLGenerationClient.getInputXMLString("getHostsInfo", attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
        log.info("Query to Add host: {}", getHostQuery);
        URI endpointURI = hdsApiClient.getBaseURI();
        ClientResponse response = hdsApiClient.post(endpointURI, getHostQuery);
        if (HttpStatus.SC_OK == response.getStatus()) {
            responseStream = response.getEntityInputStream();
            JavaResult javaResult = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.HOST_INFO_SMOOKS_CONFIG_FILE);
            verifyErrorPayload(javaResult);
            hostList = (List<HDSHost>) javaResult.getBean(HDSConstants.HOST_LIST_BEAN_NAME);
            if (null == hostList || hostList.isEmpty()) {
                throw HDSException.exceptions.notAbleToGetHostInfoForHSD();
            }
        } else {
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to Get registered hosts from 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 hostList;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) HDSHost(com.emc.storageos.hds.model.HDSHost) 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)

Example 4 with HDSHost

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

the class HDSApiProtectionManager method getHDSHostList.

/**
 * Returns Host List collected from Device Manager.
 *
 * @return
 * @throws Exception
 */
private List<HDSHost> getHDSHostList() throws Exception {
    List<HDSHost> hostList = null;
    InputStream responseStream = null;
    try {
        Map<String, Object> attributeMap = new HashMap<String, Object>();
        Get getOp = new Get(HDSConstants.HOST);
        attributeMap.put(HDSConstants.GET, getOp);
        HDSHost host = new HDSHost();
        host.setName("*");
        attributeMap.put(HDSConstants.HOST, host);
        String getAllHSDQuery = InputXMLGenerationClient.getInputXMLString(HDSConstants.GET_ALL_HOST_INFO_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
        log.info("Query to get All Host: {}", getAllHSDQuery);
        URI endpointURI = hdsApiClient.getBaseURI();
        ClientResponse response = hdsApiClient.post(endpointURI, getAllHSDQuery);
        if (HttpStatus.SC_OK == response.getStatus()) {
            responseStream = response.getEntityInputStream();
            JavaResult javaResult = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.HOST_INFO_SMOOKS_CONFIG_FILE);
            hdsApiClient.verifyErrorPayload(javaResult);
            hostList = (List<HDSHost>) javaResult.getBean(HDSConstants.HOST_LIST_BEAN_NAME);
        } else {
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to query HostStorageDomain's 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 hostList;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) HDSHost(com.emc.storageos.hds.model.HDSHost) 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)

Example 5 with HDSHost

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

the class HDSApiProtectionManager method getReplicationRelatedObjectIds.

/**
 * Return's replicationGroup's objectID and replicationInfo's objectID for the given P-VOl and S-VOL
 *
 * @param primaryVolumeNativeId
 * @param secondaryVolumeNativeId
 * @return {@link Map} replicationGroup's objectID and replicationInfo's objectID
 * @throws Exception
 */
public Map<String, String> getReplicationRelatedObjectIds(String primaryVolumeNativeId, String secondaryVolumeNativeId) throws Exception {
    Map<String, String> objectIds = new HashMap<>();
    log.info("primaryVolumeNativeId :{}", primaryVolumeNativeId);
    log.info("secondaryVolumeNativeId :{}", secondaryVolumeNativeId);
    List<HDSHost> hostList = getHDSHostList();
    if (hostList != null) {
        for (HDSHost hdsHost : hostList) {
            log.info("HDSHost :{}", hdsHost.toXMLString());
            if (hdsHost != null && hdsHost.getConfigFileList() != null && !hdsHost.getConfigFileList().isEmpty()) {
                for (ConfigFile configFile : hdsHost.getConfigFileList()) {
                    if (configFile != null) {
                        ReplicationGroup replicationGroup = configFile.getReplicationGroup();
                        if (replicationGroup != null && replicationGroup.getReplicationInfoList() != null) {
                            log.debug("replicationGroup :{}", replicationGroup.toXMLString());
                            List<ReplicationInfo> replicationInfoList = replicationGroup.getReplicationInfoList();
                            if (replicationInfoList != null) {
                                for (ReplicationInfo replicationInfo : replicationInfoList) {
                                    log.debug("replicationInfo :{}", replicationInfo.toXMLString());
                                    if (primaryVolumeNativeId.equalsIgnoreCase(replicationInfo.getPvolDevNum()) && secondaryVolumeNativeId.equalsIgnoreCase(replicationInfo.getSvolDevNum())) {
                                        objectIds.put(HDSConstants.REPLICATION_INFO_OBJ_ID, replicationInfo.getObjectID());
                                        objectIds.put(HDSConstants.REPLICATION_GROUP_OBJ_ID, replicationGroup.getObjectID());
                                        log.info("objectIds :{}", objectIds);
                                        return objectIds;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    log.error("Unable to get replication information from pair management server");
    return objectIds;
}
Also used : HDSHost(com.emc.storageos.hds.model.HDSHost) HashMap(java.util.HashMap) ConfigFile(com.emc.storageos.hds.model.ConfigFile) ReplicationInfo(com.emc.storageos.hds.model.ReplicationInfo) ReplicationGroup(com.emc.storageos.hds.model.ReplicationGroup)

Aggregations

HDSHost (com.emc.storageos.hds.model.HDSHost)15 HashMap (java.util.HashMap)9 ClientResponse (com.sun.jersey.api.client.ClientResponse)8 IOException (java.io.IOException)8 InputStream (java.io.InputStream)8 URI (java.net.URI)8 JavaResult (org.milyn.payload.JavaResult)8 ReplicationInfo (com.emc.storageos.hds.model.ReplicationInfo)7 SnapshotGroup (com.emc.storageos.hds.model.SnapshotGroup)6 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)3 Volume (com.emc.storageos.db.client.model.Volume)3 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)3 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)3 HDSException (com.emc.storageos.hds.HDSException)3 HDSApiClient (com.emc.storageos.hds.api.HDSApiClient)3 ConfigFile (com.emc.storageos.hds.model.ConfigFile)3 Get (com.emc.storageos.hds.model.Get)3 ReplicationGroup (com.emc.storageos.hds.model.ReplicationGroup)3 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)3 Add (com.emc.storageos.hds.model.Add)2