Skip to content

Commit 1c26b2e

Browse files
committed
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>
2 parents fe44a0a + 0befb2c commit 1c26b2e

4 files changed

Lines changed: 22 additions & 39 deletions

File tree

agent/src/main/java/com/cloud/agent/direct/download/DirectTemplateDownloaderImpl.java

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@
2020

2121
import com.cloud.utils.exception.CloudRuntimeException;
2222
import com.cloud.utils.script.Script;
23-
import org.apache.cloudstack.utils.security.ChecksumValue;
23+
import org.apache.cloudstack.utils.security.DigestHelper;
2424
import org.apache.commons.lang.StringUtils;
2525

2626
import java.io.File;
27+
import java.io.FileInputStream;
28+
import java.io.IOException;
29+
import java.security.NoSuchAlgorithmException;
2730
import java.util.UUID;
2831

2932
public abstract class DirectTemplateDownloaderImpl implements DirectTemplateDownloader {
@@ -149,36 +152,16 @@ public DirectTemplateInformation getTemplateInformation() {
149152
return new DirectTemplateInformation(installPath, size, checksum);
150153
}
151154

152-
/**
153-
* Return checksum command from algorithm
154-
*/
155-
private String getChecksumCommandFromAlgorithm(String algorithm) {
156-
if (algorithm.equalsIgnoreCase("MD5")) {
157-
return "md5sum";
158-
} else if (algorithm.equalsIgnoreCase("SHA-1")) {
159-
return "sha1sum";
160-
} else if (algorithm.equalsIgnoreCase("SHA-224")) {
161-
return "sha224sum";
162-
} else if (algorithm.equalsIgnoreCase("SHA-256")) {
163-
return "sha256sum";
164-
} else if (algorithm.equalsIgnoreCase("SHA-384")) {
165-
return "sha384sum";
166-
} else if (algorithm.equalsIgnoreCase("SHA-512")) {
167-
return "sha512sum";
168-
} else {
169-
throw new CloudRuntimeException("Unknown checksum algorithm: " + algorithm);
170-
}
171-
}
172-
173155
@Override
174156
public boolean validateChecksum() {
175157
if (StringUtils.isNotBlank(checksum)) {
176-
ChecksumValue providedChecksum = new ChecksumValue(checksum);
177-
String algorithm = providedChecksum.getAlgorithm();
178-
String checksumCommand = "echo '%s %s' | %s -c --quiet";
179-
String cmd = String.format(checksumCommand, providedChecksum.getChecksum(), downloadedFilePath, getChecksumCommandFromAlgorithm(algorithm));
180-
int result = Script.runSimpleBashScriptForExitValue(cmd);
181-
return result == 0;
158+
try {
159+
return DigestHelper.check(checksum, new FileInputStream(downloadedFilePath));
160+
} catch (IOException e) {
161+
throw new CloudRuntimeException("could not check sum for file: " + downloadedFilePath,e);
162+
} catch (NoSuchAlgorithmException e) {
163+
throw new CloudRuntimeException("Unknown checksum algorithm: " + checksum, e);
164+
}
182165
}
183166
return true;
184167
}

plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServerStorageProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ protected boolean destroySnapshotOnPrimaryStorageExceptThis(final Connection con
10711071
return false;
10721072
}
10731073

1074-
private boolean destroySnapshotOnPrimaryStorage(final Connection conn, final String lastSnapshotUuid) {
1074+
protected boolean destroySnapshotOnPrimaryStorage(final Connection conn, final String lastSnapshotUuid) {
10751075
try {
10761076
final VDI snapshot = getVDIbyUuid(conn, lastSnapshotUuid);
10771077
if (snapshot == null) {

plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/Xenserver625StorageProcessor.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -559,12 +559,12 @@ public Answer backupSnapshot(final CopyCommand cmd) {
559559
physicalSize = Long.parseLong(tmp[1]);
560560
finalPath = folder + File.separator + snapshotBackupUuid + ".vhd";
561561
}
562-
563-
final String volumeUuid = snapshotTO.getVolume().getPath();
564-
565-
destroySnapshotOnPrimaryStorageExceptThis(conn, volumeUuid, snapshotUuid);
566562
}
567563

564+
// remove every snapshot except this one from primary storage
565+
final String volumeUuid = snapshotTO.getVolume().getPath();
566+
destroySnapshotOnPrimaryStorageExceptThis(conn, volumeUuid, snapshotUuid);
567+
568568
final SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
569569
newSnapshot.setPath(finalPath);
570570
newSnapshot.setPhysicalSize(physicalSize);
@@ -577,12 +577,13 @@ public Answer backupSnapshot(final CopyCommand cmd) {
577577
s_logger.info("New snapshot physical utilization: "+physicalSize);
578578

579579
return new CopyCmdAnswer(newSnapshot);
580-
} catch (final Types.XenAPIException e) {
581-
details = "BackupSnapshot Failed due to " + e.toString();
582-
s_logger.warn(details, e);
583580
} catch (final Exception e) {
584-
details = "BackupSnapshot Failed due to " + e.getMessage();
581+
final String reason = e instanceof Types.XenAPIException ? e.toString() : e.getMessage();
582+
details = "BackupSnapshot Failed due to " + reason;
585583
s_logger.warn(details, e);
584+
585+
// remove last bad primary snapshot when exception happens
586+
destroySnapshotOnPrimaryStorage(conn, snapshotUuid);
586587
}
587588

588589
return new CopyCmdAnswer(details);

server/src/main/java/org/apache/cloudstack/acl/RoleManagerImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.util.ArrayList;
2020
import java.util.Collections;
21-
import java.util.Date;
2221
import java.util.List;
2322

2423
import javax.inject.Inject;
@@ -172,7 +171,7 @@ public Boolean doInTransaction(TransactionStatus status) {
172171
}
173172
if (roleDao.remove(role.getId())) {
174173
RoleVO roleVO = roleDao.findByIdIncludingRemoved(role.getId());
175-
roleVO.setName(role.getName() + "-deleted-" + new Date());
174+
roleVO.setName(null);
176175
return roleDao.update(role.getId(), roleVO);
177176
}
178177
return false;

0 commit comments

Comments
 (0)