[BugFix:
Fix add image with multi bs uuids
Avoid early return when one bs finish its upload
Update image to Ready status only if all bs report update success
@@ -70,6 +70,7 @@ import java.net.URISyntaxException;
import java.sql.Timestamp;
import java.util.*;
import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -1376,9 +1377,14 @@ public class ImageManagerImpl extends AbstractService implements ImageManager, M
new LoopAsyncBatch<DownloadImageMsg>(msgData.getNeedReplyMessage()) {
AtomicBoolean success = new AtomicBoolean(false);
UploadImageTracker tracker = new UploadImageTracker();
+ ConcurrentHashMap<String, AtomicBoolean> resultMap = new ConcurrentHashMap<>();
@Override
protected Collection<DownloadImageMsg> collect() {
+ for (DownloadImageMsg dmsg : dmsgs) {
+ AtomicBoolean success = new AtomicBoolean(false);
+ resultMap.put(dmsg.getBackupStorageUuid(), success);
+ }
return dmsgs;
}
@@ -1415,13 +1421,12 @@ public class ImageManagerImpl extends AbstractService implements ImageManager, M
dbf.update(ref);
- if (success.compareAndSet(false, true)) {
+ if (resultMap.get(ref.getBackupStorageUuid()).compareAndSet(false, true)) {
// In case 'Platform' etc. is changed.
ImageVO vo = dbf.reload(ivo);
vo.setMd5Sum(re.getMd5sum());
vo.setSize(re.getSize());
vo.setActualSize(re.getActualSize());
- vo.setStatus(ref.getStatus());
vo.setUrl(URLBuilder.hideUrlPassword(vo.getUrl()));
if (StringUtils.isNotEmpty(re.getFormat())) {
vo.setFormat(re.getFormat());
@@ -1434,6 +1439,11 @@ public class ImageManagerImpl extends AbstractService implements ImageManager, M
&& ImageMediaType.ISO.equals(vo.getMediaType())) {
vo.setMediaType(ImageMediaType.RootVolumeTemplate);
}
+
+ if (resultMap.entrySet().stream().allMatch(entry -> entry.getValue().get())) {
+ vo.setStatus(ref.getStatus());
+ }
+
dbf.update(vo);
}
@@ -1469,7 +1479,7 @@ public class ImageManagerImpl extends AbstractService implements ImageManager, M
return;
}
- if (success.get()) {
+ if (resultMap.entrySet().stream().allMatch(entry -> entry.getValue().get())) {
final ImageInventory einv = ImageInventory.valueOf(vo);
if (vo.getStatus() == ImageStatus.Ready) {
