mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Check if datastore is complaince with the storagepolicy provided in the disk offering.
Added corresponding manager objects from PBM sdk to do the job. Made dao layer changes to read the storage policy in diskoffering
This commit is contained in:
parent
27e5dfa633
commit
fb0a96e7fb
@ -21,6 +21,7 @@ package com.cloud.storage.resource;
|
||||
|
||||
import org.apache.cloudstack.agent.directdownload.DirectDownloadCommand;
|
||||
import org.apache.cloudstack.storage.command.AttachCommand;
|
||||
import org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand;
|
||||
import org.apache.cloudstack.storage.command.CopyCommand;
|
||||
import org.apache.cloudstack.storage.command.CreateObjectCommand;
|
||||
import org.apache.cloudstack.storage.command.DeleteCommand;
|
||||
@ -76,4 +77,6 @@ public interface StorageProcessor {
|
||||
public Answer handleDownloadTemplateToPrimaryStorage(DirectDownloadCommand cmd);
|
||||
|
||||
Answer copyVolumeFromPrimaryToPrimary(CopyCommand cmd);
|
||||
|
||||
public Answer CheckDataStoreStoragePolicyComplaince(CheckDataStoreStoragePolicyComplainceCommand cmd);
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ package com.cloud.storage.resource;
|
||||
|
||||
import org.apache.cloudstack.agent.directdownload.DirectDownloadCommand;
|
||||
import org.apache.cloudstack.storage.to.VolumeObjectTO;
|
||||
import org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.storage.command.AttachCommand;
|
||||
@ -71,6 +72,8 @@ public class StorageSubsystemCommandHandlerBase implements StorageSubsystemComma
|
||||
return processor.resignature((ResignatureCommand) command);
|
||||
} else if (command instanceof DirectDownloadCommand) {
|
||||
return processor.handleDownloadTemplateToPrimaryStorage((DirectDownloadCommand) command);
|
||||
} else if (command instanceof CheckDataStoreStoragePolicyComplainceCommand) {
|
||||
return processor.CheckDataStoreStoragePolicyComplaince((CheckDataStoreStoragePolicyComplainceCommand) command);
|
||||
}
|
||||
|
||||
return new Answer((Command)command, false, "not implemented yet");
|
||||
|
||||
@ -0,0 +1,61 @@
|
||||
//
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
//
|
||||
|
||||
package org.apache.cloudstack.storage.command;
|
||||
|
||||
import com.cloud.agent.api.to.StorageFilerTO;
|
||||
|
||||
public class CheckDataStoreStoragePolicyComplainceCommand extends StorageSubSystemCommand {
|
||||
|
||||
String storagePolicyId;
|
||||
private StorageFilerTO storagePool;
|
||||
|
||||
public CheckDataStoreStoragePolicyComplainceCommand(String storagePolicyId, StorageFilerTO storagePool) {
|
||||
super();
|
||||
|
||||
this.storagePolicyId = storagePolicyId;
|
||||
this.storagePool = storagePool;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExecuteInSequence(boolean inSeq) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeInSequence() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public String getStoragePolicyId() {
|
||||
return storagePolicyId;
|
||||
}
|
||||
|
||||
public void setStoragePolicyId(String storagePolicyId) {
|
||||
this.storagePolicyId = storagePolicyId;
|
||||
}
|
||||
|
||||
public StorageFilerTO getStoragePool() {
|
||||
return storagePool;
|
||||
}
|
||||
|
||||
public void setStoragePool(StorageFilerTO storagePool) {
|
||||
this.storagePool = storagePool;
|
||||
}
|
||||
}
|
||||
@ -212,6 +212,8 @@ public interface StorageManager extends StorageService {
|
||||
|
||||
boolean storagePoolHasEnoughSpaceForResize(StoragePool pool, long currentSize, long newSiz);
|
||||
|
||||
boolean isStoragePoolComplaintWithStoragePolicy(List<Volume> volumes, StoragePool pool) throws StorageUnavailableException;
|
||||
|
||||
boolean registerHostListener(String providerUuid, HypervisorHostListener listener);
|
||||
|
||||
void connectHostToSharedPool(long hostId, long poolId) throws StorageUnavailableException, StorageConflictException;
|
||||
|
||||
@ -26,4 +26,5 @@ import com.cloud.utils.db.GenericDao;
|
||||
public interface DiskOfferingDetailsDao extends GenericDao<DiskOfferingDetailVO, Long>, ResourceDetailsDao<DiskOfferingDetailVO> {
|
||||
List<Long> findDomainIds(final long resourceId);
|
||||
List<Long> findZoneIds(final long resourceId);
|
||||
String getDetail(Long diskOfferingId, String key);
|
||||
}
|
||||
@ -56,4 +56,14 @@ public class DiskOfferingDetailsDaoImpl extends ResourceDetailsDaoBase<DiskOffer
|
||||
}
|
||||
return zoneIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDetail(Long diskOfferingId, String key) {
|
||||
String detailValue = null;
|
||||
DiskOfferingDetailVO diskOfferingDetail = findDetail(diskOfferingId, key);
|
||||
if (diskOfferingDetail != null) {
|
||||
detailValue = diskOfferingDetail.getValue();
|
||||
}
|
||||
return detailValue;
|
||||
}
|
||||
}
|
||||
@ -26,6 +26,7 @@ import java.util.Map;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import com.cloud.exception.StorageUnavailableException;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
|
||||
@ -215,6 +216,17 @@ public abstract class AbstractStoragePoolAllocator extends AdapterBase implement
|
||||
Volume volume = volumeDao.findById(dskCh.getVolumeId());
|
||||
List<Volume> requestVolumes = new ArrayList<>();
|
||||
requestVolumes.add(volume);
|
||||
if (dskCh.getHypervisorType() == HypervisorType.VMware) {
|
||||
try {
|
||||
boolean isStoragePoolStoragepolicyComplaince = storageMgr.isStoragePoolComplaintWithStoragePolicy(requestVolumes, pool);
|
||||
if (!isStoragePoolStoragepolicyComplaince) {
|
||||
return false;
|
||||
}
|
||||
} catch (StorageUnavailableException e) {
|
||||
s_logger.warn(String.format("Could not verify storage policy complaince against storage pool %s due to exception %s", pool.getUuid(), e.getMessage()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return storageMgr.storagePoolHasEnoughIops(requestVolumes, pool) && storageMgr.storagePoolHasEnoughSpace(requestVolumes, pool, plan.getClusterId());
|
||||
}
|
||||
|
||||
|
||||
@ -46,6 +46,7 @@ import org.apache.cloudstack.agent.directdownload.MetalinkDirectDownloadCommand;
|
||||
import org.apache.cloudstack.agent.directdownload.NfsDirectDownloadCommand;
|
||||
import org.apache.cloudstack.storage.command.AttachAnswer;
|
||||
import org.apache.cloudstack.storage.command.AttachCommand;
|
||||
import org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand;
|
||||
import org.apache.cloudstack.storage.command.CopyCmdAnswer;
|
||||
import org.apache.cloudstack.storage.command.CopyCommand;
|
||||
import org.apache.cloudstack.storage.command.CreateObjectAnswer;
|
||||
@ -1833,4 +1834,10 @@ public class KVMStorageProcessor implements StorageProcessor {
|
||||
}
|
||||
return availableBytes >= templateSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer CheckDataStoreStoragePolicyComplaince(CheckDataStoreStoragePolicyComplainceCommand cmd) {
|
||||
s_logger.info("'CheckDataStoreStoragePolicyComplainceCommand' not currently applicable for KVMStorageProcessor");
|
||||
return new Answer(cmd,false,"Not currently applicable for KVMStorageProcessor");
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ import java.util.UUID;
|
||||
import org.apache.cloudstack.agent.directdownload.DirectDownloadCommand;
|
||||
import org.apache.cloudstack.storage.command.AttachAnswer;
|
||||
import org.apache.cloudstack.storage.command.AttachCommand;
|
||||
import org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand;
|
||||
import org.apache.cloudstack.storage.command.CopyCmdAnswer;
|
||||
import org.apache.cloudstack.storage.command.CopyCommand;
|
||||
import org.apache.cloudstack.storage.command.CreateObjectAnswer;
|
||||
@ -826,6 +827,12 @@ public class Ovm3StorageProcessor implements StorageProcessor {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer CheckDataStoreStoragePolicyComplaince(CheckDataStoreStoragePolicyComplainceCommand cmd) {
|
||||
LOGGER.info("'CheckDataStoreStoragePolicyComplainceCommand' not applicable used for Ovm3StorageProcessor");
|
||||
return new Answer(cmd,false,"Not applicable used for Ovm3StorageProcessor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer copyVolumeFromPrimaryToPrimary(CopyCommand cmd) {
|
||||
return null;
|
||||
|
||||
@ -37,6 +37,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.apache.cloudstack.agent.directdownload.DirectDownloadCommand;
|
||||
import org.apache.cloudstack.storage.command.AttachAnswer;
|
||||
import org.apache.cloudstack.storage.command.AttachCommand;
|
||||
import org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand;
|
||||
import org.apache.cloudstack.storage.command.CopyCmdAnswer;
|
||||
import org.apache.cloudstack.storage.command.CopyCommand;
|
||||
import org.apache.cloudstack.storage.command.CreateObjectAnswer;
|
||||
@ -3580,6 +3581,38 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer CheckDataStoreStoragePolicyComplaince(CheckDataStoreStoragePolicyComplainceCommand cmd) {
|
||||
String primaryStorageNameLabel = cmd.getStoragePool().getUuid();
|
||||
String storagePolicyId = cmd.getStoragePolicyId();
|
||||
VmwareContext context = hostService.getServiceContext(cmd);
|
||||
try {
|
||||
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd);
|
||||
ManagedObjectReference morPrimaryDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, primaryStorageNameLabel);
|
||||
if (morPrimaryDs == null) {
|
||||
String msg = "Unable to find datastore: " + primaryStorageNameLabel;
|
||||
s_logger.error(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
DatastoreMO primaryDsMo = new DatastoreMO(hyperHost.getContext(), morPrimaryDs);
|
||||
boolean isDatastoreStoragePolicyComplaint = primaryDsMo.isDatastoreStoragePolicyComplaint(storagePolicyId);
|
||||
|
||||
String failedMessage = String.format("DataStore %s is not complaince with storage policy id %s", primaryStorageNameLabel, storagePolicyId);
|
||||
if (!isDatastoreStoragePolicyComplaint)
|
||||
return new Answer(cmd, isDatastoreStoragePolicyComplaint, failedMessage);
|
||||
else
|
||||
return new Answer(cmd, isDatastoreStoragePolicyComplaint, null);
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof RemoteException) {
|
||||
hostService.invalidateServiceContext(context);
|
||||
}
|
||||
String details = String.format("Exception while checking if datastore %s is storage policy %s complaince : %s", primaryStorageNameLabel, storagePolicyId, VmwareHelper.getExceptionMessage(e));
|
||||
s_logger.error(details, e);
|
||||
return new Answer(cmd, false, details);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer copyVolumeFromPrimaryToPrimary(CopyCommand cmd) {
|
||||
return null;
|
||||
|
||||
@ -35,6 +35,7 @@ import java.util.UUID;
|
||||
import org.apache.cloudstack.agent.directdownload.DirectDownloadCommand;
|
||||
import org.apache.cloudstack.storage.command.AttachAnswer;
|
||||
import org.apache.cloudstack.storage.command.AttachCommand;
|
||||
import org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand;
|
||||
import org.apache.cloudstack.storage.command.CopyCmdAnswer;
|
||||
import org.apache.cloudstack.storage.command.CopyCommand;
|
||||
import org.apache.cloudstack.storage.command.CreateObjectAnswer;
|
||||
@ -215,6 +216,12 @@ public class XenServerStorageProcessor implements StorageProcessor {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer CheckDataStoreStoragePolicyComplaince(CheckDataStoreStoragePolicyComplainceCommand cmd) {
|
||||
s_logger.info("'CheckDataStoreStoragePolicyComplainceCommand' not applicable used for XenServerStorageProcessor");
|
||||
return new Answer(cmd,false,"Not applicable used for XenServerStorageProcessor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttachAnswer attachIso(final AttachCommand cmd) {
|
||||
final DiskTO disk = cmd.getDisk();
|
||||
|
||||
@ -27,6 +27,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand;
|
||||
import org.apache.cloudstack.storage.command.CopyCmdAnswer;
|
||||
import org.apache.cloudstack.storage.command.CopyCommand;
|
||||
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
||||
@ -912,6 +913,12 @@ public class Xenserver625StorageProcessor extends XenServerStorageProcessor {
|
||||
return new CopyCmdAnswer(details);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer CheckDataStoreStoragePolicyComplaince(CheckDataStoreStoragePolicyComplainceCommand cmd) {
|
||||
s_logger.info("'CheckDataStoreStoragePolicyComplainceCommand' not applicable used for XenServerStorageProcessor");
|
||||
return new Answer(cmd,false,"Not applicable used for XenServerStorageProcessor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer copyVolumeFromPrimaryToSecondary(final CopyCommand cmd) {
|
||||
final Connection conn = hypervisorResource.getConnection();
|
||||
|
||||
@ -31,6 +31,7 @@ import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import com.cloud.utils.StringUtils;
|
||||
import com.cloud.exception.StorageUnavailableException;
|
||||
import com.cloud.utils.db.Filter;
|
||||
import com.cloud.utils.fsm.StateMachine2;
|
||||
|
||||
@ -1291,6 +1292,18 @@ StateListener<State, VirtualMachine.Event, VirtualMachine> {
|
||||
requestVolumes = new ArrayList<Volume>();
|
||||
requestVolumes.add(vol);
|
||||
|
||||
if (potentialHost.getHypervisorType() == HypervisorType.VMware) {
|
||||
try {
|
||||
boolean isStoragePoolStoragepolicyComplaince = _storageMgr.isStoragePoolComplaintWithStoragePolicy(requestVolumes, potentialSPool);
|
||||
if (!isStoragePoolStoragepolicyComplaince) {
|
||||
continue;
|
||||
}
|
||||
} catch (StorageUnavailableException e) {
|
||||
s_logger.warn(String.format("Could not verify storage policy complaince against storage pool %s due to exception %s", potentialSPool.getUuid(), e.getMessage()));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_storageMgr.storagePoolHasEnoughIops(requestVolumes, potentialSPool) ||
|
||||
!_storageMgr.storagePoolHasEnoughSpace(requestVolumes, potentialSPool, potentialHost.getClusterId()))
|
||||
continue;
|
||||
|
||||
@ -39,6 +39,11 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import com.cloud.agent.api.to.StorageFilerTO;
|
||||
import com.cloud.dc.VsphereStoragePolicyVO;
|
||||
import com.cloud.dc.dao.VsphereStoragePolicyDao;
|
||||
import com.cloud.utils.StringUtils;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.command.admin.storage.CancelPrimaryStorageMaintenanceCmd;
|
||||
import org.apache.cloudstack.api.command.admin.storage.CreateSecondaryStagingStoreCmd;
|
||||
import org.apache.cloudstack.api.command.admin.storage.CreateStoragePoolCmd;
|
||||
@ -81,6 +86,8 @@ import org.apache.cloudstack.framework.config.Configurable;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
|
||||
import org.apache.cloudstack.management.ManagementServerHost;
|
||||
import org.apache.cloudstack.resourcedetail.dao.DiskOfferingDetailsDao;
|
||||
import org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand;
|
||||
import org.apache.cloudstack.storage.command.DettachCommand;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
|
||||
@ -175,7 +182,6 @@ import com.cloud.user.dao.UserDao;
|
||||
import com.cloud.utils.DateUtil;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.StringUtils;
|
||||
import com.cloud.utils.UriUtils;
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
import com.cloud.utils.component.ManagerBase;
|
||||
@ -298,6 +304,10 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
||||
SnapshotService _snapshotService;
|
||||
@Inject
|
||||
StoragePoolTagsDao _storagePoolTagsDao;
|
||||
@Inject
|
||||
DiskOfferingDetailsDao _diskOfferingDetailsDao;
|
||||
@Inject
|
||||
VsphereStoragePolicyDao _vsphereStoragePolicyDao;
|
||||
|
||||
protected List<StoragePoolDiscoverer> _discoverers;
|
||||
|
||||
@ -1872,6 +1882,48 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStoragePoolComplaintWithStoragePolicy(List<Volume> volumes, StoragePool pool) throws StorageUnavailableException {
|
||||
if (volumes == null || volumes.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
List<Pair<Volume, Answer>> answers = new ArrayList<Pair<Volume, Answer>>();
|
||||
|
||||
for (Volume volume : volumes) {
|
||||
String storagePolicyId = _diskOfferingDetailsDao.getDetail(volume.getDiskOfferingId(), ApiConstants.STORAGE_POLICY);
|
||||
if (org.apache.commons.lang.StringUtils.isNotEmpty(storagePolicyId)) {
|
||||
VsphereStoragePolicyVO storagePolicyVO = _vsphereStoragePolicyDao.findById(Long.parseLong(storagePolicyId));
|
||||
List<Long> hostIds = getUpHostsInPool(pool.getId());
|
||||
Collections.shuffle(hostIds);
|
||||
|
||||
if (hostIds == null || hostIds.isEmpty()) {
|
||||
throw new StorageUnavailableException("Unable to send command to the pool " + pool.getName() + " due to there is no enabled hosts up in this cluster", pool.getId());
|
||||
}
|
||||
try {
|
||||
StorageFilerTO storageFilerTO = new StorageFilerTO(pool);
|
||||
CheckDataStoreStoragePolicyComplainceCommand cmd = new CheckDataStoreStoragePolicyComplainceCommand(storagePolicyVO.getPolicyId(), storageFilerTO);
|
||||
long targetHostId = _hvGuruMgr.getGuruProcessedCommandTargetHost(hostIds.get(0), cmd);
|
||||
Answer answer = _agentMgr.send(targetHostId, cmd);
|
||||
answers.add(new Pair<>(volume, answer));
|
||||
} catch (AgentUnavailableException e) {
|
||||
s_logger.debug("Unable to send storage pool command to " + pool + " via " + hostIds.get(0), e);
|
||||
throw new StorageUnavailableException("Unable to send command to the pool ", pool.getId());
|
||||
} catch (OperationTimedoutException e) {
|
||||
s_logger.debug("Failed to process storage pool command to " + pool + " via " + hostIds.get(0), e);
|
||||
throw new StorageUnavailableException("Failed to process storage command to the pool ", pool.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
// check cummilative result for all volumes
|
||||
for (Pair<Volume, Answer> answer : answers) {
|
||||
if (!answer.second().getResult()) {
|
||||
s_logger.debug(String.format("Storage pool %s is not complaince with storage policy for volume %s", pool.getName(), answer.first().getName()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean checkPoolforSpace(StoragePool pool, long allocatedSizeWithTemplate, long totalAskingSize) {
|
||||
// allocated space includes templates
|
||||
StoragePoolVO poolVO = _storagePoolDao.findById(pool.getId());
|
||||
|
||||
@ -186,6 +186,20 @@ public class DatacenterMO extends BaseMO {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ManagedObjectReference listDatastore(String name) throws Exception {
|
||||
assert (name != null);
|
||||
|
||||
List<ObjectContent> ocs = getDatastorePropertiesOnDatacenter(new String[] {"name"});
|
||||
if (ocs != null) {
|
||||
for (ObjectContent oc : ocs) {
|
||||
if (oc.getPropSet().get(0).getVal().toString().equals(name)) {
|
||||
return oc.getObj();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ManagedObjectReference findHost(String name) throws Exception {
|
||||
List<ObjectContent> ocs = getHostPropertiesOnDatacenterHostFolder(new String[] {"name"});
|
||||
|
||||
|
||||
@ -19,6 +19,7 @@ package com.cloud.hypervisor.vmware.mo;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.vmware.pbm.PbmProfile;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.vmware.vim25.DatastoreHostMount;
|
||||
@ -471,4 +472,14 @@ public class DatastoreMO extends BaseMO {
|
||||
}
|
||||
return isAccessible;
|
||||
}
|
||||
|
||||
public boolean isDatastoreStoragePolicyComplaint(String storagePolicyId) throws Exception {
|
||||
PbmProfileManagerMO profMgrMo = new PbmProfileManagerMO(_context);
|
||||
PbmProfile profile = profMgrMo.getStorageProfile(storagePolicyId);
|
||||
|
||||
PbmPlacementSolverMO placementSolverMo = new PbmPlacementSolverMO(_context);
|
||||
boolean isDatastoreCompatible = placementSolverMo.isDatastoreCompatibleWithStorageProfile(_mor, profile);
|
||||
|
||||
return isDatastoreCompatible;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,68 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.hypervisor.vmware.mo;
|
||||
|
||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
import com.vmware.pbm.PbmPlacementCompatibilityResult;
|
||||
import com.vmware.pbm.PbmPlacementHub;
|
||||
import com.vmware.pbm.PbmProfile;
|
||||
import com.vmware.pbm.PbmProfileId;
|
||||
import com.vmware.vim25.ManagedObjectReference;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PbmPlacementSolverMO extends BaseMO {
|
||||
|
||||
private static final Logger s_logger = Logger.getLogger(PbmPlacementSolverMO.class);
|
||||
|
||||
public PbmPlacementSolverMO (VmwareContext context) {
|
||||
super(context, context.getPbmServiceContent().getPlacementSolver());
|
||||
}
|
||||
|
||||
public PbmPlacementSolverMO(VmwareContext context, ManagedObjectReference morPlacementSolver) {
|
||||
super(context, morPlacementSolver);
|
||||
}
|
||||
|
||||
public PbmPlacementSolverMO(VmwareContext context, String morType, String morValue) {
|
||||
super(context, morType, morValue);
|
||||
}
|
||||
|
||||
public boolean isDatastoreCompatibleWithStorageProfile(ManagedObjectReference dsMor, PbmProfile profile) throws Exception {
|
||||
boolean isDatastoreCompatibleWithStorageProfile = false;
|
||||
|
||||
PbmPlacementHub placementHub = new PbmPlacementHub();
|
||||
placementHub.setHubId(dsMor.getValue());
|
||||
placementHub.setHubType(dsMor.getType());
|
||||
|
||||
List<PbmPlacementHub> placementHubList = new ArrayList<PbmPlacementHub>();
|
||||
placementHubList.add(placementHub);
|
||||
PbmProfileId profileId = profile.getProfileId();
|
||||
List<PbmPlacementCompatibilityResult> placementCompatibilityResultList = _context.getPbmService().pbmCheckCompatibility(_mor, placementHubList, profileId);
|
||||
if (CollectionUtils.isNotEmpty(placementCompatibilityResultList)) {
|
||||
for (PbmPlacementCompatibilityResult placementResult : placementCompatibilityResultList) {
|
||||
// Check for error and warning
|
||||
if (CollectionUtils.isEmpty(placementResult.getError()) && CollectionUtils.isEmpty(placementResult.getWarning())) {
|
||||
isDatastoreCompatibleWithStorageProfile = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return isDatastoreCompatibleWithStorageProfile;
|
||||
}
|
||||
}
|
||||
@ -18,6 +18,7 @@ package com.cloud.hypervisor.vmware.mo;
|
||||
|
||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.vmware.pbm.PbmProfile;
|
||||
import com.vmware.pbm.PbmProfileId;
|
||||
import com.vmware.pbm.PbmProfileResourceType;
|
||||
@ -26,6 +27,7 @@ import com.vmware.vim25.ManagedObjectReference;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class PbmProfileManagerMO extends BaseMO {
|
||||
@ -58,6 +60,19 @@ public class PbmProfileManagerMO extends BaseMO {
|
||||
return profiles;
|
||||
}
|
||||
|
||||
public PbmProfile getStorageProfile(String storageProfileId) throws Exception {
|
||||
List<PbmProfileId> profileIds = getStorageProfileIds();
|
||||
for (PbmProfileId profileId : profileIds) {
|
||||
if (storageProfileId.equals(profileId.getUniqueId())) {
|
||||
List<PbmProfile> profile = _context.getPbmService().pbmRetrieveContent(_mor, Collections.singletonList(profileId));
|
||||
return profile.get(0);
|
||||
}
|
||||
}
|
||||
String errMsg = String.format("Storage profile with id %s not found", storageProfileId);
|
||||
s_logger.debug(errMsg);
|
||||
throw new CloudRuntimeException(errMsg);
|
||||
}
|
||||
|
||||
private PbmProfileResourceType getStorageResourceType() {
|
||||
PbmProfileResourceType resourceType = new PbmProfileResourceType();
|
||||
resourceType.setResourceType(PbmProfileResourceTypeEnum.STORAGE.value());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user