use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project cloudstack by apache.
the class VeeamClient method post.
private HttpResponse post(final String path, final Object obj) throws IOException {
String xml = null;
if (obj != null) {
XmlMapper xmlMapper = new XmlMapper();
xml = xmlMapper.writer().with(ToXmlGenerator.Feature.WRITE_XML_DECLARATION).writeValueAsString(obj);
// Remove invalid/empty xmlns
xml = xml.replace(" xmlns=\"\"", "");
}
String url = apiURI.toString() + path;
final HttpPost request = new HttpPost(url);
request.setHeader(SESSION_HEADER, veeamSessionId);
request.setHeader("Content-type", "application/xml");
if (StringUtils.isNotBlank(xml)) {
request.setEntity(new StringEntity(xml));
}
final HttpResponse response = httpClient.execute(request);
checkAuthFailure(response);
LOG.debug(String.format("Response received in POST request with body [%s] is: [%s] for URL [%s].", xml, response.toString(), url));
return response;
}
use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project cloudstack by apache.
the class VeeamClient method removeVMFromVeeamJob.
public boolean removeVMFromVeeamJob(final String jobId, final String vmwareInstanceName, final String vmwareDcName) {
LOG.debug("Trying to remove VM from backup offering that is a Veeam job: " + jobId);
try {
final String hierarchyId = findDCHierarchy(vmwareDcName);
final String veeamVmRefId = lookupVM(hierarchyId, vmwareInstanceName);
final HttpResponse response = get(String.format("/jobs/%s/includes", jobId));
checkResponseOK(response);
final ObjectMapper objectMapper = new XmlMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
final ObjectsInJob jobObjects = objectMapper.readValue(response.getEntity().getContent(), ObjectsInJob.class);
if (jobObjects == null || jobObjects.getObjects() == null) {
LOG.warn("No objects found in the Veeam job " + jobId);
return false;
}
for (final ObjectInJob jobObject : jobObjects.getObjects()) {
if (jobObject.getName().equals(vmwareInstanceName) && jobObject.getHierarchyObjRef().equals(veeamVmRefId)) {
final HttpResponse deleteResponse = delete(String.format("/jobs/%s/includes/%s", jobId, jobObject.getObjectInJobId()));
return checkTaskStatus(deleteResponse);
}
}
LOG.warn(vmwareInstanceName + " VM was not found to be attached to Veaam job (backup offering): " + jobId);
return false;
} catch (final IOException e) {
LOG.error("Failed to list Veeam jobs due to:", e);
checkResponseTimeOut(e);
}
return false;
}
use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project cloudstack by apache.
the class VeeamClient method listJob.
public Job listJob(final String jobId) {
LOG.debug("Trying to list veeam job id: " + jobId);
try {
final HttpResponse response = get(String.format("/jobs/%s?format=Entity", jobId.replace("urn:veeam:Job:", "")));
checkResponseOK(response);
final ObjectMapper objectMapper = new XmlMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return objectMapper.readValue(response.getEntity().getContent(), Job.class);
} catch (final IOException e) {
LOG.error("Failed to list Veeam jobs due to:", e);
checkResponseTimeOut(e);
} catch (final ServerApiException e) {
LOG.error(e);
}
return null;
}
use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project cloudstack by apache.
the class VeeamClient method parseTaskResponse.
private Task parseTaskResponse(HttpResponse response) throws IOException {
checkResponseOK(response);
final ObjectMapper objectMapper = new XmlMapper();
return objectMapper.readValue(response.getEntity().getContent(), Task.class);
}
use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project cloudstack by apache.
the class VeeamClient method listBackupRepository.
// //////////////////////////////////////////////////////
// ////////////// Public Veeam APIs /////////////////////
// //////////////////////////////////////////////////////
public Ref listBackupRepository(final String backupServerId, final String backupName) {
LOG.debug(String.format("Trying to list backup repository for backup job [name: %s] in server [id: %s].", backupName, backupServerId));
try {
String repositoryName = getRepositoryNameFromJob(backupName);
final HttpResponse response = get(String.format("/backupServers/%s/repositories", backupServerId));
checkResponseOK(response);
final ObjectMapper objectMapper = new XmlMapper();
final EntityReferences references = objectMapper.readValue(response.getEntity().getContent(), EntityReferences.class);
for (final Ref ref : references.getRefs()) {
if (ref.getType().equals("RepositoryReference") && ref.getName().equals(repositoryName)) {
return ref;
}
}
} catch (final IOException e) {
LOG.error(String.format("Failed to list Veeam backup repository used by backup job [name: %s] due to: [%s].", backupName, e.getMessage()), e);
checkResponseTimeOut(e);
}
return null;
}
Aggregations