use of org.apache.cloudstack.backup.veeam.api.ObjectsInJob 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;
}
Aggregations