Search in sources :

Example 1 with EntityReferences

use of org.apache.cloudstack.backup.veeam.api.EntityReferences in project cloudstack by apache.

the class VeeamClient method listJobs.

public List<BackupOffering> listJobs() {
    LOG.debug("Trying to list backup policies that are Veeam jobs");
    try {
        final HttpResponse response = get("/jobs");
        checkResponseOK(response);
        final ObjectMapper objectMapper = new XmlMapper();
        final EntityReferences entityReferences = objectMapper.readValue(response.getEntity().getContent(), EntityReferences.class);
        final List<BackupOffering> policies = new ArrayList<>();
        if (entityReferences == null || entityReferences.getRefs() == null) {
            return policies;
        }
        for (final Ref ref : entityReferences.getRefs()) {
            policies.add(new VeeamBackupOffering(ref.getName(), ref.getUid()));
        }
        return policies;
    } catch (final IOException e) {
        LOG.error("Failed to list Veeam jobs due to:", e);
        checkResponseTimeOut(e);
    }
    return new ArrayList<>();
}
Also used : EntityReferences(org.apache.cloudstack.backup.veeam.api.EntityReferences) BackupOffering(org.apache.cloudstack.backup.BackupOffering) Ref(org.apache.cloudstack.backup.veeam.api.Ref) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Example 2 with EntityReferences

use of org.apache.cloudstack.backup.veeam.api.EntityReferences in project cloudstack by apache.

the class VeeamClient method listAllBackups.

public void listAllBackups() {
    LOG.debug("Trying to list Veeam backups");
    try {
        final HttpResponse response = get("/backups");
        checkResponseOK(response);
        final ObjectMapper objectMapper = new XmlMapper();
        final EntityReferences entityReferences = objectMapper.readValue(response.getEntity().getContent(), EntityReferences.class);
        for (final Ref ref : entityReferences.getRefs()) {
            LOG.debug("Veeam Backup found, name: " + ref.getName() + ", uid: " + ref.getUid() + ", type: " + ref.getType());
        }
    } catch (final IOException e) {
        LOG.error("Failed to list Veeam backups due to:", e);
        checkResponseTimeOut(e);
    }
}
Also used : EntityReferences(org.apache.cloudstack.backup.veeam.api.EntityReferences) Ref(org.apache.cloudstack.backup.veeam.api.Ref) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Example 3 with EntityReferences

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

Example 4 with EntityReferences

use of org.apache.cloudstack.backup.veeam.api.EntityReferences in project cloudstack by apache.

the class VeeamClient method findDCHierarchy.

// /////////////////////////////////////////////////////////////////
// ////////////// Private Veeam Helper Methods /////////////////////
// /////////////////////////////////////////////////////////////////
private String findDCHierarchy(final String vmwareDcName) {
    LOG.debug("Trying to find hierarchy ID for vmware datacenter: " + vmwareDcName);
    try {
        final HttpResponse response = get("/hierarchyRoots");
        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.getName().equals(vmwareDcName) && ref.getType().equals("HierarchyRootReference")) {
                return ref.getUid();
            }
        }
    } catch (final IOException e) {
        LOG.error("Failed to list Veeam jobs due to:", e);
        checkResponseTimeOut(e);
    }
    throw new CloudRuntimeException("Failed to find hierarchy reference for VMware datacenter " + vmwareDcName + " in Veeam, please ask administrator to check Veeam B&R manager configuration");
}
Also used : EntityReferences(org.apache.cloudstack.backup.veeam.api.EntityReferences) Ref(org.apache.cloudstack.backup.veeam.api.Ref) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)4 IOException (java.io.IOException)4 EntityReferences (org.apache.cloudstack.backup.veeam.api.EntityReferences)4 Ref (org.apache.cloudstack.backup.veeam.api.Ref)4 HttpResponse (org.apache.http.HttpResponse)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 ArrayList (java.util.ArrayList)1 BackupOffering (org.apache.cloudstack.backup.BackupOffering)1