Search in sources :

Example 1 with CopyToSecondaryStorageAnswer

use of org.apache.cloudstack.diagnostics.CopyToSecondaryStorageAnswer in project cloudstack by apache.

the class CitrixResourceBase method copyDiagnosticsFileToSecondaryStorage.

/**
 * Get Diagnostics Data API
 * Copy zip file from system vm and copy file directly to secondary storage
 */
public Answer copyDiagnosticsFileToSecondaryStorage(Connection conn, CopyToSecondaryStorageCommand cmd) {
    String secondaryStorageUrl = cmd.getSecondaryStorageUrl();
    String vmIP = cmd.getSystemVmIp();
    String diagnosticsZipFile = cmd.getFileName();
    String nfsVersion = cmd.getNfsVersion();
    String localDir = null;
    boolean success;
    // Mount Secondary storage
    String secondaryStorageMountPath = null;
    try {
        URI uri = new URI(secondaryStorageUrl);
        secondaryStorageMountPath = uri.getHost() + ":" + uri.getPath();
        localDir = BASE_MOUNT_POINT_ON_REMOTE + UUID.nameUUIDFromBytes(secondaryStorageMountPath.getBytes());
        String mountPoint = mountNfs(conn, secondaryStorageMountPath, localDir, nfsVersion);
        if (StringUtils.isBlank(mountPoint)) {
            return new CopyToSecondaryStorageAnswer(cmd, false, "Could not mount secondary storage " + secondaryStorageMountPath + " on host " + localDir);
        }
        String dataDirectoryInSecondaryStore = localDir + File.separator + DiagnosticsService.DIAGNOSTICS_DIRECTORY;
        final CopyToSecondaryStorageAnswer answer;
        final String scpResult = callHostPlugin(conn, "vmops", "secureCopyToHost", "hostfilepath", dataDirectoryInSecondaryStore, "srcip", vmIP, "srcfilepath", cmd.getFileName()).toLowerCase();
        if (scpResult.contains("success")) {
            answer = new CopyToSecondaryStorageAnswer(cmd, true, "File copied to secondary storage successfully.");
        } else {
            answer = new CopyToSecondaryStorageAnswer(cmd, false, "Zip file " + diagnosticsZipFile.replace("/root/", "") + "could not be copied to secondary storage due to " + scpResult);
        }
        umountNfs(conn, secondaryStorageMountPath, localDir);
        localDir = null;
        return answer;
    } catch (Exception e) {
        String msg = "Exception caught zip file copy to secondary storage URI: " + secondaryStorageUrl + "Exception : " + e;
        s_logger.error(msg, e);
        return new CopyToSecondaryStorageAnswer(cmd, false, msg);
    } finally {
        if (localDir != null)
            umountNfs(conn, secondaryStorageMountPath, localDir);
    }
}
Also used : CopyToSecondaryStorageAnswer(org.apache.cloudstack.diagnostics.CopyToSecondaryStorageAnswer) URI(java.net.URI) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) SAXException(org.xml.sax.SAXException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) MalformedURLException(java.net.MalformedURLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 2 with CopyToSecondaryStorageAnswer

use of org.apache.cloudstack.diagnostics.CopyToSecondaryStorageAnswer in project cloudstack by apache.

the class LibvirtCopyToSecondaryStorageWrapper method execute.

@Override
public Answer execute(CopyToSecondaryStorageCommand command, LibvirtComputingResource libvirtResource) {
    String diagnosticsZipFile = command.getFileName();
    String vmSshIp = command.getSystemVmIp();
    String secondaryStorageUrl = command.getSecondaryStorageUrl();
    KVMStoragePoolManager storagePoolMgr = libvirtResource.getStoragePoolMgr();
    KVMStoragePool secondaryPool;
    boolean success;
    secondaryPool = storagePoolMgr.getStoragePoolByURI(secondaryStorageUrl);
    String mountPoint = secondaryPool.getLocalPath();
    // /mnt/SecStorage/uuid/diagnostics_data
    String dataDirectoryInSecondaryStore = String.format("%s/%s", mountPoint, DiagnosticsService.DIAGNOSTICS_DIRECTORY);
    try {
        File dataDirectory = new File(dataDirectoryInSecondaryStore);
        boolean existsInSecondaryStore = dataDirectory.exists() || dataDirectory.mkdir();
        // Modify directory file permissions
        Path path = Paths.get(dataDirectory.getAbsolutePath());
        setDirFilePermissions(path);
        if (existsInSecondaryStore) {
            LOGGER.info(String.format("Copying %s from %s to secondary store %s", diagnosticsZipFile, vmSshIp, secondaryStorageUrl));
            int port = Integer.valueOf(LibvirtComputingResource.DEFAULTDOMRSSHPORT);
            File permKey = new File(LibvirtComputingResource.SSHPRVKEYPATH);
            SshHelper.scpFrom(vmSshIp, port, "root", permKey, dataDirectoryInSecondaryStore, diagnosticsZipFile);
        }
        // Verify File copy to Secondary Storage
        File fileInSecondaryStore = new File(dataDirectoryInSecondaryStore + diagnosticsZipFile.replace("/root", ""));
        if (fileInSecondaryStore.exists()) {
            return new CopyToSecondaryStorageAnswer(command, true, "File copied to secondary storage successfully");
        } else {
            return new CopyToSecondaryStorageAnswer(command, false, "Zip file " + diagnosticsZipFile.replace("/root/", "") + "not found in secondary storage");
        }
    } catch (Exception e) {
        return new CopyToSecondaryStorageAnswer(command, false, e.getMessage());
    } finally {
        // unmount secondary storage from hypervisor host
        secondaryPool.delete();
    }
}
Also used : Path(java.nio.file.Path) KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) CopyToSecondaryStorageAnswer(org.apache.cloudstack.diagnostics.CopyToSecondaryStorageAnswer) File(java.io.File)

Aggregations

CopyToSecondaryStorageAnswer (org.apache.cloudstack.diagnostics.CopyToSecondaryStorageAnswer)2 InternalErrorException (com.cloud.exception.InternalErrorException)1 KVMStoragePool (com.cloud.hypervisor.kvm.storage.KVMStoragePool)1 KVMStoragePoolManager (com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 XenAPIException (com.xensource.xenapi.Types.XenAPIException)1 File (java.io.File)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Path (java.nio.file.Path)1 TimeoutException (java.util.concurrent.TimeoutException)1 ConfigurationException (javax.naming.ConfigurationException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 XmlRpcException (org.apache.xmlrpc.XmlRpcException)1 SAXException (org.xml.sax.SAXException)1