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