|
25 | 25 | import com.cloud.agent.api.Command; |
26 | 26 | import com.cloud.agent.api.StartupCommand; |
27 | 27 | import com.cloud.agent.api.StartupRoutingCommand; |
| 28 | +import com.cloud.agent.api.to.StorageFilerTO; |
28 | 29 | import com.cloud.api.query.dao.TemplateJoinDao; |
29 | 30 | import com.cloud.cluster.ClusterManager; |
30 | 31 | import com.cloud.cluster.dao.ManagementServerHostPeerDao; |
|
41 | 42 | import com.cloud.dc.dao.VsphereStoragePolicyDao; |
42 | 43 | import com.cloud.event.ActionEvent; |
43 | 44 | import com.cloud.event.EventTypes; |
| 45 | +import com.cloud.exception.AgentUnavailableException; |
44 | 46 | import com.cloud.exception.DiscoveredWithErrorException; |
45 | 47 | import com.cloud.exception.DiscoveryException; |
46 | 48 | import com.cloud.exception.InvalidParameterValueException; |
| 49 | +import com.cloud.exception.OperationTimedoutException; |
47 | 50 | import com.cloud.exception.ResourceInUseException; |
48 | 51 | import com.cloud.host.Host; |
49 | 52 | import com.cloud.host.Status; |
50 | 53 | import com.cloud.host.dao.HostDao; |
51 | 54 | import com.cloud.host.dao.HostDetailsDao; |
52 | 55 | import com.cloud.hypervisor.Hypervisor; |
53 | 56 | import com.cloud.hypervisor.Hypervisor.HypervisorType; |
| 57 | +import com.cloud.hypervisor.HypervisorGuruManager; |
54 | 58 | import com.cloud.hypervisor.dao.HypervisorCapabilitiesDao; |
55 | 59 | import com.cloud.hypervisor.vmware.LegacyZoneVO; |
56 | 60 | import com.cloud.hypervisor.vmware.VmwareCleanupMaid; |
|
89 | 93 | import com.cloud.storage.JavaStorageLayer; |
90 | 94 | import com.cloud.storage.StorageLayer; |
91 | 95 | import com.cloud.storage.StorageManager; |
| 96 | +import com.cloud.storage.StoragePool; |
| 97 | +import com.cloud.storage.StoragePoolStatus; |
92 | 98 | import com.cloud.storage.dao.VMTemplatePoolDao; |
93 | 99 | import com.cloud.template.TemplateManager; |
94 | 100 | import com.cloud.utils.FileUtil; |
|
116 | 122 | import org.apache.cloudstack.api.command.admin.zone.ImportVsphereStoragePoliciesCmd; |
117 | 123 | import org.apache.cloudstack.api.command.admin.zone.ListVmwareDcsCmd; |
118 | 124 | import org.apache.cloudstack.api.command.admin.zone.ListVsphereStoragePoliciesCmd; |
| 125 | +import org.apache.cloudstack.api.command.admin.zone.ListVsphereStoragePolicyCompatiblePoolsCmd; |
119 | 126 | import org.apache.cloudstack.api.command.admin.zone.RemoveVmwareDcCmd; |
120 | 127 | import org.apache.cloudstack.api.command.admin.zone.UpdateVmwareDcCmd; |
121 | 128 | import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; |
|
125 | 132 | import org.apache.cloudstack.framework.config.dao.ConfigurationDao; |
126 | 133 | import org.apache.cloudstack.framework.jobs.impl.AsyncJobManagerImpl; |
127 | 134 | import org.apache.cloudstack.management.ManagementServerHost; |
| 135 | +import org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand; |
128 | 136 | import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; |
| 137 | +import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; |
129 | 138 | import org.apache.cloudstack.utils.identity.ManagementServerNode; |
130 | 139 | import org.apache.log4j.Logger; |
131 | 140 |
|
@@ -217,6 +226,10 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw |
217 | 226 | private TemplateManager templateManager; |
218 | 227 | @Inject |
219 | 228 | private VsphereStoragePolicyDao vsphereStoragePolicyDao; |
| 229 | + @Inject |
| 230 | + private StorageManager storageManager; |
| 231 | + @Inject |
| 232 | + private HypervisorGuruManager hypervisorGuruManager; |
220 | 233 |
|
221 | 234 | private String _mountParent; |
222 | 235 | private StorageLayer _storage; |
@@ -1057,6 +1070,7 @@ public List<Class<?>> getCommands() { |
1057 | 1070 | cmdList.add(ListVmwareDcsCmd.class); |
1058 | 1071 | cmdList.add(ImportVsphereStoragePoliciesCmd.class); |
1059 | 1072 | cmdList.add(ListVsphereStoragePoliciesCmd.class); |
| 1073 | + cmdList.add(ListVsphereStoragePolicyCompatiblePoolsCmd.class); |
1060 | 1074 | return cmdList; |
1061 | 1075 | } |
1062 | 1076 |
|
@@ -1469,6 +1483,35 @@ public List<? extends VsphereStoragePolicy> listVsphereStoragePolicies(ListVsphe |
1469 | 1483 | return Collections.emptyList(); |
1470 | 1484 | } |
1471 | 1485 |
|
| 1486 | + @Override |
| 1487 | + public List<StoragePool> listVsphereStoragePolicyCompatibleStoragePools(ListVsphereStoragePolicyCompatiblePoolsCmd cmd) { |
| 1488 | + Long policyId = cmd.getPolicyId(); |
| 1489 | + VsphereStoragePolicyVO storagePolicy = vsphereStoragePolicyDao.findById(policyId); |
| 1490 | + if (storagePolicy == null) { |
| 1491 | + throw new CloudRuntimeException("Storage policy with ID = " + policyId + " was not found"); |
| 1492 | + } |
| 1493 | + long zoneId = storagePolicy.getZoneId(); |
| 1494 | + List<StoragePoolVO> poolsInZone = primaryStorageDao.listByStatusInZone(zoneId, StoragePoolStatus.Up); |
| 1495 | + List<StoragePool> compatiblePools = new ArrayList<>(); |
| 1496 | + for (StoragePoolVO pool : poolsInZone) { |
| 1497 | + StorageFilerTO storageFilerTO = new StorageFilerTO(pool); |
| 1498 | + List<Long> hostIds = storageManager.getUpHostsInPool(pool.getId()); |
| 1499 | + Collections.shuffle(hostIds); |
| 1500 | + CheckDataStoreStoragePolicyComplainceCommand command = new CheckDataStoreStoragePolicyComplainceCommand(storagePolicy.getPolicyId(), storageFilerTO); |
| 1501 | + long targetHostId = hypervisorGuruManager.getGuruProcessedCommandTargetHost(hostIds.get(0), command); |
| 1502 | + try { |
| 1503 | + Answer answer = _agentMgr.send(targetHostId, command); |
| 1504 | + boolean result = answer != null && answer.getResult(); |
| 1505 | + if (result) { |
| 1506 | + compatiblePools.add(pool); |
| 1507 | + } |
| 1508 | + } catch (AgentUnavailableException | OperationTimedoutException e) { |
| 1509 | + s_logger.error("Could not verify if storage policy " + storagePolicy.getName() + " is compatible with storage pool " + pool.getName()); |
| 1510 | + } |
| 1511 | + } |
| 1512 | + return compatiblePools; |
| 1513 | + } |
| 1514 | + |
1472 | 1515 | @Override |
1473 | 1516 | public boolean hasNexusVSM(Long clusterId) { |
1474 | 1517 | ClusterVSMMapVO vsmMapVo = null; |
|
0 commit comments