Search in sources :

Example 1 with Ref

use of org.apache.cloudstack.backup.veeam.api.Ref 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 Ref

use of org.apache.cloudstack.backup.veeam.api.Ref 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 Ref

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

the class VeeamClient method cloneVeeamJob.

public boolean cloneVeeamJob(final Job parentJob, final String clonedJobName) {
    LOG.debug("Trying to clone veeam job: " + parentJob.getUid() + " with backup uuid: " + clonedJobName);
    try {
        final Ref repositoryRef = listBackupRepository(parentJob.getBackupServerId(), parentJob.getName());
        if (repositoryRef == null) {
            throw new CloudRuntimeException(String.format("Failed to clone backup job because couldn't find any " + "repository associated with backup job [id: %s, uid: %s, backupServerId: %s, name: %s].", parentJob.getId(), parentJob.getUid(), parentJob.getBackupServerId(), parentJob.getName()));
        }
        final BackupJobCloneInfo cloneInfo = new BackupJobCloneInfo();
        cloneInfo.setJobName(clonedJobName);
        cloneInfo.setFolderName(clonedJobName);
        cloneInfo.setRepositoryUid(repositoryRef.getUid());
        final JobCloneSpec cloneSpec = new JobCloneSpec(cloneInfo);
        final HttpResponse response = post(String.format("/jobs/%s?action=clone", parentJob.getId()), cloneSpec);
        return checkTaskStatus(response);
    } catch (final Exception e) {
        LOG.warn("Exception caught while trying to clone Veeam job:", e);
    }
    return false;
}
Also used : Ref(org.apache.cloudstack.backup.veeam.api.Ref) JobCloneSpec(org.apache.cloudstack.backup.veeam.api.JobCloneSpec) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HttpResponse(org.apache.http.HttpResponse) BackupJobCloneInfo(org.apache.cloudstack.backup.veeam.api.BackupJobCloneInfo) URISyntaxException(java.net.URISyntaxException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ServerApiException(org.apache.cloudstack.api.ServerApiException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException)

Example 4 with Ref

use of org.apache.cloudstack.backup.veeam.api.Ref 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 5 with Ref

use of org.apache.cloudstack.backup.veeam.api.Ref 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

IOException (java.io.IOException)5 Ref (org.apache.cloudstack.backup.veeam.api.Ref)5 HttpResponse (org.apache.http.HttpResponse)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)4 EntityReferences (org.apache.cloudstack.backup.veeam.api.EntityReferences)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 SocketTimeoutException (java.net.SocketTimeoutException)1 URISyntaxException (java.net.URISyntaxException)1 KeyManagementException (java.security.KeyManagementException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)1 ServerApiException (org.apache.cloudstack.api.ServerApiException)1 BackupOffering (org.apache.cloudstack.backup.BackupOffering)1 BackupJobCloneInfo (org.apache.cloudstack.backup.veeam.api.BackupJobCloneInfo)1 JobCloneSpec (org.apache.cloudstack.backup.veeam.api.JobCloneSpec)1 ConnectTimeoutException (org.apache.http.conn.ConnectTimeoutException)1