Search in sources :

Example 1 with ObjectsInJob

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;
}
Also used : ObjectsInJob(org.apache.cloudstack.backup.veeam.api.ObjectsInJob) HttpResponse(org.apache.http.HttpResponse) ObjectInJob(org.apache.cloudstack.backup.veeam.api.ObjectInJob) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)1 IOException (java.io.IOException)1 ObjectInJob (org.apache.cloudstack.backup.veeam.api.ObjectInJob)1 ObjectsInJob (org.apache.cloudstack.backup.veeam.api.ObjectsInJob)1 HttpResponse (org.apache.http.HttpResponse)1