Skip to content

Commit 6e5c36d

Browse files
Address review comments
1 parent 21378f8 commit 6e5c36d

File tree

4 files changed

+21
-23
lines changed

4 files changed

+21
-23
lines changed

engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@
149149
import com.cloud.utils.exception.CloudRuntimeException;
150150
import com.cloud.vm.VirtualMachine;
151151

152+
import static com.cloud.storage.VolumeApiServiceImpl.AllowCheckAndRepairVolume;
153+
152154
@Component
153155
public class VolumeServiceImpl implements VolumeService {
154156
private static final Logger s_logger = Logger.getLogger(VolumeServiceImpl.class);
@@ -2768,7 +2770,7 @@ public SnapshotInfo takeSnapshot(VolumeInfo volume) {
27682770
@Override
27692771
public void checkAndRepairVolumeBasedOnConfig(DataObject dataObject, Host host) {
27702772
if (HypervisorType.KVM.equals(host.getHypervisorType()) && DataObjectType.VOLUME.equals(dataObject.getType())) {
2771-
if (com.cloud.storage.VolumeApiServiceImpl.AllowCheckAndRepairVolume.value()) {
2773+
if (AllowCheckAndRepairVolume.value()) {
27722774
s_logger.info(String.format("Trying to check and repair the volume %d", dataObject.getId()));
27732775
String repair = CheckAndRepairVolumeCmd.RepairValues.LEAKS.name().toLowerCase();
27742776
CheckAndRepairVolumePayload payload = new CheckAndRepairVolumePayload(repair);

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckAndRepairVolumeCommandWrapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public Answer execute(CheckAndRepairVolumeCommand command, LibvirtComputingResou
6666
QemuObject.EncryptFormat encryptFormat = QemuObject.EncryptFormat.enumValue(command.getEncryptFormat());
6767
byte[] passphrase = command.getPassphrase();
6868
try {
69-
String checkVolumeResult = checkAndRepairVolume(vol, repair, encryptFormat, passphrase, serverResource);
69+
String checkVolumeResult = checkAndRepairVolume(vol, null, encryptFormat, passphrase, serverResource);
7070
s_logger.info(String.format("Check Volume result for the volume %s is %s", vol.getName(), checkVolumeResult));
7171
CheckAndRepairVolumeAnswer answer = new CheckAndRepairVolumeAnswer(command, true, checkVolumeResult);
7272
answer.setVolumeCheckExecutionResult(checkVolumeResult);
@@ -77,7 +77,7 @@ public Answer execute(CheckAndRepairVolumeCommand command, LibvirtComputingResou
7777
JsonNode jsonNode = objectMapper.readTree(checkVolumeResult);
7878
JsonNode leaksNode = jsonNode.get("leaks");
7979
if (leaksNode != null) {
80-
leaks = jsonNode.asInt();
80+
leaks = leaksNode.asInt();
8181
}
8282

8383
if (leaks == 0) {

plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/qemu/QemuImg.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -824,29 +824,29 @@ protected static boolean helpSupportsImageFormat(String text, QemuImg.PhysicalDi
824824
* Boolean option whether to repair any leaks
825825
*/
826826
public String checkAndRepair(final QemuImgFile file, final QemuImageOptions imageOptions, final List<QemuObject> qemuObjects, final String repair) throws QemuImgException {
827-
final Script s = new Script(_qemuImgPath);
828-
s.add("check");
827+
final Script script = new Script(_qemuImgPath);
828+
script.add("check");
829829
if (imageOptions == null) {
830-
s.add(file.getFileName());
830+
script.add(file.getFileName());
831831
}
832832

833833
for (QemuObject o : qemuObjects) {
834-
s.add(o.toCommandFlag());
834+
script.add(o.toCommandFlag());
835835
}
836836

837837
if (imageOptions != null) {
838-
s.add(imageOptions.toCommandFlag());
838+
script.add(imageOptions.toCommandFlag());
839839
}
840840

841-
s.add("--output=json");
841+
script.add("--output=json");
842842

843843
if (StringUtils.isNotEmpty(repair)) {
844-
s.add("-r");
845-
s.add(repair);
844+
script.add("-r");
845+
script.add(repair);
846846
}
847847

848848
OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
849-
final String result = s.execute(parser);
849+
final String result = script.execute(parser);
850850
if (result != null) {
851851
throw new QemuImgException(result);
852852
}

server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ public VolumeVO resizeVolume(ResizeVolumeCmd cmd) throws ResourceAllocationExcep
13401340
outcome.get();
13411341
} catch (InterruptedException e) {
13421342
throw new RuntimeException("Operation was interrupted", e);
1343-
} catch (java.util.concurrent.ExecutionException e) {
1343+
} catch (ExecutionException e) {
13441344
throw new RuntimeException("Execution exception", e);
13451345
}
13461346

@@ -1853,7 +1853,7 @@ public Pair<String, String> checkAndRepairVolume(CheckAndRepairVolumeCmd cmd) th
18531853
outcome.get();
18541854
} catch (InterruptedException e) {
18551855
throw new RuntimeException("Operation is interrupted", e);
1856-
} catch (java.util.concurrent.ExecutionException e) {
1856+
} catch (ExecutionException e) {
18571857
throw new RuntimeException("Execution exception--", e);
18581858
}
18591859

@@ -1922,10 +1922,6 @@ private Pair<String, String> orchestrateCheckAndRepairVolume(Long volumeId, Stri
19221922
throw new InvalidParameterValueException("Checking volume and repairing failed due to volume:" + volumeId + " doesn't exist");
19231923
}
19241924

1925-
if (volume.getState() != Volume.State.Ready) {
1926-
throw new InvalidParameterValueException("VolumeId: " + volumeId + " is not in " + Volume.State.Ready + " state but " + volume.getState() + ". Cannot check and repair the volume.");
1927-
}
1928-
19291925
CheckAndRepairVolumePayload payload = new CheckAndRepairVolumePayload(repair);
19301926
volume.addPayload(payload);
19311927

@@ -2132,7 +2128,7 @@ private VolumeVO resizeVolumeInternal(VolumeVO volume, DiskOfferingVO newDiskOff
21322128
outcome.get();
21332129
} catch (InterruptedException e) {
21342130
throw new RuntimeException("Operation was interrupted", e);
2135-
} catch (java.util.concurrent.ExecutionException e) {
2131+
} catch (ExecutionException e) {
21362132
throw new RuntimeException("Execution exception", e);
21372133
}
21382134

@@ -2918,7 +2914,7 @@ public Volume detachVolumeFromVM(DetachVolumeCmd cmmd) {
29182914
outcome.get();
29192915
} catch (InterruptedException e) {
29202916
throw new RuntimeException("Operation is interrupted", e);
2921-
} catch (java.util.concurrent.ExecutionException e) {
2917+
} catch (ExecutionException e) {
29222918
throw new RuntimeException("Execution excetion", e);
29232919
}
29242920

@@ -3326,7 +3322,7 @@ public Volume migrateVolume(MigrateVolumeCmd cmd) {
33263322
outcome.get();
33273323
} catch (InterruptedException e) {
33283324
throw new RuntimeException("Operation is interrupted", e);
3329-
} catch (java.util.concurrent.ExecutionException e) {
3325+
} catch (ExecutionException e) {
33303326
throw new RuntimeException("Execution excetion", e);
33313327
}
33323328

@@ -3655,7 +3651,7 @@ private Snapshot takeSnapshotInternal(Long volumeId, Long policyId, Long snapsho
36553651
outcome.get();
36563652
} catch (InterruptedException e) {
36573653
throw new RuntimeException("Operation is interrupted", e);
3658-
} catch (java.util.concurrent.ExecutionException e) {
3654+
} catch (ExecutionException e) {
36593655
throw new RuntimeException("Execution excetion", e);
36603656
}
36613657

@@ -3972,7 +3968,7 @@ public String extractVolume(ExtractVolumeCmd cmd) {
39723968
outcome.get();
39733969
} catch (InterruptedException e) {
39743970
throw new RuntimeException("Operation is interrupted", e);
3975-
} catch (java.util.concurrent.ExecutionException e) {
3971+
} catch (ExecutionException e) {
39763972
throw new RuntimeException("Execution excetion", e);
39773973
}
39783974

0 commit comments

Comments
 (0)