mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Merge remote-tracking branch 'origin/4.11'
CLOUDSTACK-10269: On deletion of role set name to null (#2444) CLOUDSTACK-10146 checksum in java instead of script (#2405) CLOUDSTACK-10222: Clean snaphosts from primary storage when taking (#2398) Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
commit
1c26b2ec2e
@ -20,10 +20,13 @@ package com.cloud.agent.direct.download;
|
|||||||
|
|
||||||
import com.cloud.utils.exception.CloudRuntimeException;
|
import com.cloud.utils.exception.CloudRuntimeException;
|
||||||
import com.cloud.utils.script.Script;
|
import com.cloud.utils.script.Script;
|
||||||
import org.apache.cloudstack.utils.security.ChecksumValue;
|
import org.apache.cloudstack.utils.security.DigestHelper;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public abstract class DirectTemplateDownloaderImpl implements DirectTemplateDownloader {
|
public abstract class DirectTemplateDownloaderImpl implements DirectTemplateDownloader {
|
||||||
@ -149,36 +152,16 @@ public abstract class DirectTemplateDownloaderImpl implements DirectTemplateDown
|
|||||||
return new DirectTemplateInformation(installPath, size, checksum);
|
return new DirectTemplateInformation(installPath, size, checksum);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return checksum command from algorithm
|
|
||||||
*/
|
|
||||||
private String getChecksumCommandFromAlgorithm(String algorithm) {
|
|
||||||
if (algorithm.equalsIgnoreCase("MD5")) {
|
|
||||||
return "md5sum";
|
|
||||||
} else if (algorithm.equalsIgnoreCase("SHA-1")) {
|
|
||||||
return "sha1sum";
|
|
||||||
} else if (algorithm.equalsIgnoreCase("SHA-224")) {
|
|
||||||
return "sha224sum";
|
|
||||||
} else if (algorithm.equalsIgnoreCase("SHA-256")) {
|
|
||||||
return "sha256sum";
|
|
||||||
} else if (algorithm.equalsIgnoreCase("SHA-384")) {
|
|
||||||
return "sha384sum";
|
|
||||||
} else if (algorithm.equalsIgnoreCase("SHA-512")) {
|
|
||||||
return "sha512sum";
|
|
||||||
} else {
|
|
||||||
throw new CloudRuntimeException("Unknown checksum algorithm: " + algorithm);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean validateChecksum() {
|
public boolean validateChecksum() {
|
||||||
if (StringUtils.isNotBlank(checksum)) {
|
if (StringUtils.isNotBlank(checksum)) {
|
||||||
ChecksumValue providedChecksum = new ChecksumValue(checksum);
|
try {
|
||||||
String algorithm = providedChecksum.getAlgorithm();
|
return DigestHelper.check(checksum, new FileInputStream(downloadedFilePath));
|
||||||
String checksumCommand = "echo '%s %s' | %s -c --quiet";
|
} catch (IOException e) {
|
||||||
String cmd = String.format(checksumCommand, providedChecksum.getChecksum(), downloadedFilePath, getChecksumCommandFromAlgorithm(algorithm));
|
throw new CloudRuntimeException("could not check sum for file: " + downloadedFilePath,e);
|
||||||
int result = Script.runSimpleBashScriptForExitValue(cmd);
|
} catch (NoSuchAlgorithmException e) {
|
||||||
return result == 0;
|
throw new CloudRuntimeException("Unknown checksum algorithm: " + checksum, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1071,7 +1071,7 @@ public class XenServerStorageProcessor implements StorageProcessor {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean destroySnapshotOnPrimaryStorage(final Connection conn, final String lastSnapshotUuid) {
|
protected boolean destroySnapshotOnPrimaryStorage(final Connection conn, final String lastSnapshotUuid) {
|
||||||
try {
|
try {
|
||||||
final VDI snapshot = getVDIbyUuid(conn, lastSnapshotUuid);
|
final VDI snapshot = getVDIbyUuid(conn, lastSnapshotUuid);
|
||||||
if (snapshot == null) {
|
if (snapshot == null) {
|
||||||
|
|||||||
@ -559,12 +559,12 @@ public class Xenserver625StorageProcessor extends XenServerStorageProcessor {
|
|||||||
physicalSize = Long.parseLong(tmp[1]);
|
physicalSize = Long.parseLong(tmp[1]);
|
||||||
finalPath = folder + File.separator + snapshotBackupUuid + ".vhd";
|
finalPath = folder + File.separator + snapshotBackupUuid + ".vhd";
|
||||||
}
|
}
|
||||||
|
|
||||||
final String volumeUuid = snapshotTO.getVolume().getPath();
|
|
||||||
|
|
||||||
destroySnapshotOnPrimaryStorageExceptThis(conn, volumeUuid, snapshotUuid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove every snapshot except this one from primary storage
|
||||||
|
final String volumeUuid = snapshotTO.getVolume().getPath();
|
||||||
|
destroySnapshotOnPrimaryStorageExceptThis(conn, volumeUuid, snapshotUuid);
|
||||||
|
|
||||||
final SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
|
final SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
|
||||||
newSnapshot.setPath(finalPath);
|
newSnapshot.setPath(finalPath);
|
||||||
newSnapshot.setPhysicalSize(physicalSize);
|
newSnapshot.setPhysicalSize(physicalSize);
|
||||||
@ -577,12 +577,13 @@ public class Xenserver625StorageProcessor extends XenServerStorageProcessor {
|
|||||||
s_logger.info("New snapshot physical utilization: "+physicalSize);
|
s_logger.info("New snapshot physical utilization: "+physicalSize);
|
||||||
|
|
||||||
return new CopyCmdAnswer(newSnapshot);
|
return new CopyCmdAnswer(newSnapshot);
|
||||||
} catch (final Types.XenAPIException e) {
|
|
||||||
details = "BackupSnapshot Failed due to " + e.toString();
|
|
||||||
s_logger.warn(details, e);
|
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
details = "BackupSnapshot Failed due to " + e.getMessage();
|
final String reason = e instanceof Types.XenAPIException ? e.toString() : e.getMessage();
|
||||||
|
details = "BackupSnapshot Failed due to " + reason;
|
||||||
s_logger.warn(details, e);
|
s_logger.warn(details, e);
|
||||||
|
|
||||||
|
// remove last bad primary snapshot when exception happens
|
||||||
|
destroySnapshotOnPrimaryStorage(conn, snapshotUuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CopyCmdAnswer(details);
|
return new CopyCmdAnswer(details);
|
||||||
|
|||||||
@ -18,7 +18,6 @@ package org.apache.cloudstack.acl;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@ -172,7 +171,7 @@ public class RoleManagerImpl extends ManagerBase implements RoleService, Configu
|
|||||||
}
|
}
|
||||||
if (roleDao.remove(role.getId())) {
|
if (roleDao.remove(role.getId())) {
|
||||||
RoleVO roleVO = roleDao.findByIdIncludingRemoved(role.getId());
|
RoleVO roleVO = roleDao.findByIdIncludingRemoved(role.getId());
|
||||||
roleVO.setName(role.getName() + "-deleted-" + new Date());
|
roleVO.setName(null);
|
||||||
return roleDao.update(role.getId(), roleVO);
|
return roleDao.update(role.getId(), roleVO);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user