use of org.milyn.payload.JavaResult 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 org.milyn.payload.JavaResult in project coprhd-controller by CoprHD.
the class HDSApiExportManager method getFreeLUNInfo.
/**
* Return the Free Lun's available for a Given HSD in a System.
*
* @throws Exception
*/
public List<FreeLun> getFreeLUNInfo(String systemId, String hsdId) throws Exception {
InputStream responseStream = null;
HostStorageDomain hostStorageDomain = null;
List<FreeLun> freeLunList = null;
try {
Map<String, Object> attributeMap = new HashMap<String, Object>();
StorageArray array = new StorageArray(systemId);
Get getOp = new Get(HDSConstants.STORAGEARRAY);
attributeMap.put(HDSConstants.STORAGEARRAY, array);
HostStorageDomain hsd = new HostStorageDomain(hsdId);
FreeLun freeLun = new FreeLun();
attributeMap.put(HDSConstants.GET, getOp);
attributeMap.put(HDSConstants.HOST_STORAGE_DOMAIN, hsd);
attributeMap.put(HDSConstants.FREELUN, freeLun);
String getFreeLunQueryInputXML = InputXMLGenerationClient.getInputXMLString(HDSConstants.GET_FREE_LUN_INFO_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
log.info("Query to get FreeLUN's of a HostStorageDomain: {}", getFreeLunQueryInputXML);
URI endpointURI = hdsApiClient.getBaseURI();
ClientResponse response = hdsApiClient.post(endpointURI, getFreeLunQueryInputXML);
if (HttpStatus.SC_OK == response.getStatus()) {
responseStream = response.getEntityInputStream();
JavaResult javaResult = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
verifyErrorPayload(javaResult);
hostStorageDomain = javaResult.getBean(HostStorageDomain.class);
if (null != hostStorageDomain && null != hostStorageDomain.getFreeLunList()) {
freeLunList = hostStorageDomain.getFreeLunList();
} else {
throw HDSException.exceptions.notAbleToGetFreeLunInfoForHSD(hsdId, systemId);
}
} else {
throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to get FreeLun info for HostStorageDomain 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 freeLunList;
}
use of org.milyn.payload.JavaResult in project coprhd-controller by CoprHD.
the class HDSApiExportManager method deleteHostStorageDomain.
/**
* Delete the Host Storage Domain for a given storage array.
*
* @param systemObjectId
* @param hsdObjectId
* @param model
* @throws Exception
*/
public void deleteHostStorageDomain(String systemObjectId, String hsdObjectId, String model) throws Exception {
InputStream responseStream = null;
try {
Map<String, Object> attributeMap = new HashMap<String, Object>();
StorageArray array = new StorageArray(systemObjectId);
Delete deleteOp = new Delete(HDSConstants.HOST_STORAGE_DOMAIN);
attributeMap.put(HDSConstants.STORAGEARRAY, array);
attributeMap.put(HDSConstants.DELETE, deleteOp);
attributeMap.put(HDSConstants.MODEL, model);
HostStorageDomain inputHsd = new HostStorageDomain(hsdObjectId);
attributeMap.put(HDSConstants.HOST_STORAGE_DOMAIN, inputHsd);
String deleteHSDFromSystemQuery = InputXMLGenerationClient.getInputXMLString(HDSConstants.DELETE_HSD_FROM_SYSTEM_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
log.info("Query to delete HostStorageDomain: {}", deleteHSDFromSystemQuery);
URI endpointURI = hdsApiClient.getBaseURI();
ClientResponse response = hdsApiClient.post(endpointURI, deleteHSDFromSystemQuery);
if (HttpStatus.SC_OK == response.getStatus()) {
responseStream = response.getEntityInputStream();
JavaResult javaResult = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
verifyErrorPayload(javaResult);
log.info("Deleted HSD {} from system {}", hsdObjectId, systemObjectId);
} else {
throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to delete HostStorageDomain 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");
}
}
}
}
use of org.milyn.payload.JavaResult in project coprhd-controller by CoprHD.
the class HDSApiExportManager method getHostStorageDomain.
/**
* Return the existing HSD's configured on the storage array.
*
* @param systemId
* @param type
* @return
* @throws Exception
*/
public HostStorageDomain getHostStorageDomain(String systemId, String hsdId) throws Exception {
InputStream responseStream = null;
HostStorageDomain hsd = null;
try {
Map<String, Object> attributeMap = new HashMap<String, Object>();
StorageArray array = new StorageArray(systemId);
attributeMap.put(HDSConstants.STORAGEARRAY, array);
Get getOp = new Get(HDSConstants.STORAGEARRAY);
attributeMap.put(HDSConstants.GET, getOp);
HostStorageDomain inputHsd = new HostStorageDomain(hsdId);
attributeMap.put(HDSConstants.HOST_STORAGE_DOMAIN, inputHsd);
String getHSDQuery = InputXMLGenerationClient.getInputXMLString(HDSConstants.GET_HSD_INFO_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
log.info("Query to get HostStorageDomain: {}", getHSDQuery);
URI endpointURI = hdsApiClient.getBaseURI();
ClientResponse response = hdsApiClient.post(endpointURI, getHSDQuery);
if (HttpStatus.SC_OK == response.getStatus()) {
responseStream = response.getEntityInputStream();
JavaResult javaResult = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
verifyErrorPayload(javaResult);
hsd = javaResult.getBean(HostStorageDomain.class);
} else {
throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to query HostStorageDomain 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 hsd;
}
use of org.milyn.payload.JavaResult 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;
}
Aggregations