use of org.milyn.payload.JavaResult in project coprhd-controller by CoprHD.
the class HDSBatchApiExportManager method addHostStorageDomains.
/**
* This method makes http POST call with a payload of bulk
* HostStorageDomains.
*
* @param systemId
* - SystemObjectID.
* @param hostGroups
* - List of HostStorageDomain objects.
* @return - Returns a List of created HostStorageDomain on Array.
* @throws Exception
* - In case processing errors.
*/
public List<HostStorageDomain> addHostStorageDomains(String systemId, List<HostStorageDomain> hostGroups, String model) throws Exception {
InputStream responseStream = null;
List<HostStorageDomain> hsdList = null;
try {
Map<String, Object> attributeMap = new HashMap<String, Object>();
StorageArray array = new StorageArray(systemId);
Add addOp = new Add(HDSConstants.HOST_STORAGE_DOMAIN);
attributeMap.put(HDSConstants.STORAGEARRAY, array);
attributeMap.put(HDSConstants.ADD, addOp);
attributeMap.put(HDSConstants.MODEL, model);
attributeMap.put(HDSConstants.HOSTGROUP_LIST, hostGroups);
String addHSDToSystemQuery = InputXMLGenerationClient.getInputXMLString(HDSConstants.BATCH_ADD_HSDS_TO_SYSTEM_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
log.info("Batch query to create HostStorageDomains: {}", addHSDToSystemQuery);
URI endpointURI = hdsApiClient.getBaseURI();
ClientResponse response = hdsApiClient.post(endpointURI, addHSDToSystemQuery);
if (HttpStatus.SC_OK == response.getStatus()) {
responseStream = response.getEntityInputStream();
JavaResult javaResult = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
verifyErrorPayload(javaResult);
hsdList = (List<HostStorageDomain>) javaResult.getBean(HDSConstants.HSD_RESPONSE_BEAN_ID);
if (null == hsdList || hsdList.isEmpty()) {
throw HDSException.exceptions.notAbleToAddHSD(systemId);
}
} else {
throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to add HostStorageDomains 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 addHostStorageDomains");
}
}
}
return hsdList;
}
use of org.milyn.payload.JavaResult in project coprhd-controller by CoprHD.
the class SmooksUtil method getParsedXMLJavaResult.
/**
* This initializes the Smooks & parse the given inputStream and returns the javaResult.
*
* @param inputStream : Response in inputStream received from server.
* @param configFile : Smooks configuration file.
* @return
*/
public static JavaResult getParsedXMLJavaResult(InputStream inputStream, String configFile) {
Smooks smooks = null;
JavaResult javaResult = null;
try {
smooks = new Smooks(configFile);
log.debug("initialized smooks");
ExecutionContext executionContext = smooks.createExecutionContext();
// The result of this transform is a set of Java objects...
javaResult = new JavaResult();
// Filter the input message to extract, using the execution context...
smooks.filterSource(executionContext, new StreamSource(inputStream), javaResult);
log.debug("Parsing completed");
} catch (Exception e) {
log.error("Unable to parse the response received from server.", e);
throw HDSException.exceptions.unableToParseResponse();
} finally {
if (null != smooks) {
smooks.close();
}
}
return javaResult;
}
use of org.milyn.payload.JavaResult in project tutorials by eugenp.
the class OrderValidator method validate.
public ValidationResult validate(String path) throws IOException, SAXException {
Smooks smooks = new Smooks(OrderValidator.class.getResourceAsStream("/smooks/smooks-validation.xml"));
try {
StringResult xmlResult = new StringResult();
JavaResult javaResult = new JavaResult();
ValidationResult validationResult = new ValidationResult();
smooks.filterSource(new StreamSource(OrderValidator.class.getResourceAsStream(path)), xmlResult, javaResult, validationResult);
return validationResult;
} finally {
smooks.close();
}
}
use of org.milyn.payload.JavaResult in project coprhd-controller by CoprHD.
the class HDSApiDiscoveryManager method getStoragePoolTierInfo.
/**
* Returns all storage system information.
*
* @return
* @throws Exception
*/
public Pool getStoragePoolTierInfo(String systemObjectID, String poolObjectID) throws Exception {
InputStream responseStream = null;
Pool pool = 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);
Pool inputPool = new Pool(poolObjectID);
attributeMap.put(HDSConstants.JOURNAL_POOL, inputPool);
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 StoragePool 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);
pool = result.getBean(Pool.class);
} else {
log.error("Get pool tiering info failed with invalid response code {}", response.getStatus());
throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to query pool tiering info due to invalid response %1$s from server", response.getStatus()));
}
return pool;
}
use of org.milyn.payload.JavaResult in project coprhd-controller by CoprHD.
the class HDSApiDiscoveryManager method getStorageSystemDetails.
/**
* Returns all storage system information.
*
* @return
* @throws Exception
*/
public StorageArray getStorageSystemDetails(String systemObjectID) throws Exception {
InputStream responseStream = null;
StorageArray storageArray = 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 getSystemDetailsInputXML = InputXMLGenerationClient.getInputXMLString(HDSConstants.GET_SYSTEM_DETAILS_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
log.info("Get system details query payload :{}", getSystemDetailsInputXML);
ClientResponse response = hdsApiClient.post(endpointURI, getSystemDetailsInputXML);
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()));
}
return storageArray;
}
Aggregations