|
27 | 27 | import java.util.List; |
28 | 28 | import java.util.Map; |
29 | 29 | import java.util.UUID; |
| 30 | +import java.util.function.Predicate; |
30 | 31 |
|
31 | 32 | import com.cloud.agent.api.PrepareStorageClientCommand; |
32 | 33 | import org.apache.cloudstack.storage.datastore.client.ScaleIOGatewayClient; |
@@ -644,18 +645,30 @@ public Ternary<Boolean, Map<String, String>, String> prepareStorageClient(String |
644 | 645 | // Assuming SDC service is started, add mdms |
645 | 646 | String mdms = details.get(ScaleIOGatewayClient.STORAGE_POOL_MDMS); |
646 | 647 | String[] mdmAddresses = mdms.split(","); |
647 | | - if (mdmAddresses.length > 0) { |
648 | | - if (ScaleIOUtil.isMdmPresent(mdmAddresses[0])) { |
649 | | - return new Ternary<>(true, getSDCDetails(details), "MDM added, no need to prepare the SDC client"); |
650 | | - } |
651 | | - |
652 | | - ScaleIOUtil.addMdms(mdmAddresses); |
653 | | - if (!ScaleIOUtil.isMdmPresent(mdmAddresses[0])) { |
654 | | - return new Ternary<>(false, null, "Failed to add MDMs"); |
| 648 | + // remove MDMs already present in the config and added to the SDC |
| 649 | + String[] mdmAddressesToAdd = Arrays.stream(mdmAddresses) |
| 650 | + .filter(Predicate.not(ScaleIOUtil::isMdmPresent)) |
| 651 | + .toArray(String[]::new); |
| 652 | + // if all MDMs are already in the config and added to the SDC |
| 653 | + if (mdmAddressesToAdd.length < 1 && mdmAddresses.length > 0) { |
| 654 | + String msg = String.format("MDMs %s of the storage pool %s are already added", mdms, uuid); |
| 655 | + logger.debug(msg); |
| 656 | + return new Ternary<>(true, getSDCDetails(details), msg); |
| 657 | + } else if (mdmAddressesToAdd.length > 0) { |
| 658 | + ScaleIOUtil.addMdms(mdmAddressesToAdd); |
| 659 | + String[] missingMdmAddresses = Arrays.stream(mdmAddressesToAdd) |
| 660 | + .filter(Predicate.not(ScaleIOUtil::isMdmPresent)) |
| 661 | + .toArray(String[]::new); |
| 662 | + if (missingMdmAddresses.length > 0) { |
| 663 | + String msg = String.format("Failed to add MDMs %s of the storage pool %s", String.join(", ", missingMdmAddresses), uuid); |
| 664 | + logger.debug(msg); |
| 665 | + return new Ternary<>(false, null, msg); |
655 | 666 | } else { |
656 | | - logger.debug(String.format("MDMs %s added to storage pool %s", mdms, uuid)); |
| 667 | + logger.debug("MDMs {} of the storage pool {} are added", mdmAddressesToAdd, uuid); |
657 | 668 | applyMdmsChangeWaitTime(details); |
658 | 669 | } |
| 670 | + } else { |
| 671 | + return new Ternary<>(false, getSDCDetails(details), "No MDM addresses provided"); |
659 | 672 | } |
660 | 673 | } |
661 | 674 |
|
|
0 commit comments