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:
Rohit Yadav 2018-02-09 11:53:02 +01:00
commit 1c26b2ec2e
4 changed files with 22 additions and 39 deletions

View File

@ -20,10 +20,13 @@ package com.cloud.agent.direct.download;
import com.cloud.utils.exception.CloudRuntimeException;
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 java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;
public abstract class DirectTemplateDownloaderImpl implements DirectTemplateDownloader {
@ -149,36 +152,16 @@ public abstract class DirectTemplateDownloaderImpl implements DirectTemplateDown
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
public boolean validateChecksum() {
if (StringUtils.isNotBlank(checksum)) {
ChecksumValue providedChecksum = new ChecksumValue(checksum);
String algorithm = providedChecksum.getAlgorithm();
String checksumCommand = "echo '%s %s' | %s -c --quiet";
String cmd = String.format(checksumCommand, providedChecksum.getChecksum(), downloadedFilePath, getChecksumCommandFromAlgorithm(algorithm));
int result = Script.runSimpleBashScriptForExitValue(cmd);
return result == 0;
try {
return DigestHelper.check(checksum, new FileInputStream(downloadedFilePath));
} catch (IOException e) {
throw new CloudRuntimeException("could not check sum for file: " + downloadedFilePath,e);
} catch (NoSuchAlgorithmException e) {
throw new CloudRuntimeException("Unknown checksum algorithm: " + checksum, e);
}
}
return true;
}

View File

@ -1071,7 +1071,7 @@ public class XenServerStorageProcessor implements StorageProcessor {
return false;
}
private boolean destroySnapshotOnPrimaryStorage(final Connection conn, final String lastSnapshotUuid) {
protected boolean destroySnapshotOnPrimaryStorage(final Connection conn, final String lastSnapshotUuid) {
try {
final VDI snapshot = getVDIbyUuid(conn, lastSnapshotUuid);
if (snapshot == null) {

View File

@ -559,12 +559,12 @@ public class Xenserver625StorageProcessor extends XenServerStorageProcessor {
physicalSize = Long.parseLong(tmp[1]);
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();
newSnapshot.setPath(finalPath);
newSnapshot.setPhysicalSize(physicalSize);
@ -577,12 +577,13 @@ public class Xenserver625StorageProcessor extends XenServerStorageProcessor {
s_logger.info("New snapshot physical utilization: "+physicalSize);
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) {
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);
// remove last bad primary snapshot when exception happens
destroySnapshotOnPrimaryStorage(conn, snapshotUuid);
}
return new CopyCmdAnswer(details);

View File

@ -18,7 +18,6 @@ package org.apache.cloudstack.acl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import javax.inject.Inject;
@ -172,7 +171,7 @@ public class RoleManagerImpl extends ManagerBase implements RoleService, Configu
}
if (roleDao.remove(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 false;