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);
}
}
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();
}
}
Aggregations