use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.
the class VirtualPoolService method deleteVirtualPool.
protected Response deleteVirtualPool(VirtualPool.Type type, URI id) {
ArgValidator.checkUri(id);
VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, id);
ArgValidator.checkEntityNotNull(vpool, id, isIdEmbeddedInURL(id));
// we need to remove before the virtual pool removal
if (vpool.getType().equalsIgnoreCase(Type.block.name())) {
List<URI> quotas = _dbClient.queryByType(QuotaOfCinder.class, true);
for (URI quota : quotas) {
QuotaOfCinder quotaObj = _dbClient.queryObject(QuotaOfCinder.class, quota);
if ((quotaObj.getVpool() != null) && (quotaObj.getVpool().toString().equalsIgnoreCase(vpool.getId().toString()))) {
_log.debug("Deleting related Vpool for quota object {}.", vpool.getId().toString());
_dbClient.removeObject(quotaObj);
}
}
}
if (vpool.getType().equalsIgnoreCase(Type.file.name())) {
// check if any file policies are assigned to the vpool
if ((vpool.getFilePolicies() != null) && !(vpool.getFilePolicies().isEmpty())) {
_log.error("Failed to update the name of virtual pool as a policy is assigned");
throw APIException.badRequests.cannotDeleteVpoolAssignedFilePolicy(vpool.getLabel());
}
// if file policy is assigned to project level then also it has file vpool associated with it.
// In this scenario association is only way.so need to iterate through all the policy to get vpool reference.
List<URI> filePolicyList = _dbClient.queryByType(FilePolicy.class, true);
for (URI filePolicy : filePolicyList) {
FilePolicy policyObj = _dbClient.queryObject(FilePolicy.class, filePolicy);
if ((policyObj.getAssignedResources() != null) && (policyObj.getFilePolicyVpool() != null) && (policyObj.getFilePolicyVpool().toString().equalsIgnoreCase(vpool.getId().toString()))) {
_log.error("Failed to update the name of virtual pool as a policy is assigned at higher level");
throw APIException.badRequests.cannotDeleteVpoolAssignedFilePolicy(vpool.getLabel());
}
}
}
if (!vpool.getType().equals(type.name())) {
throw APIException.badRequests.providedVirtualPoolNotCorrectType();
}
QosSpecification qosSpecification = null;
// Check if Virtual Pool type equals block type
if (vpool.getType().equalsIgnoreCase(Type.block.name())) {
// Get the QoS for the VirtualPool, otherwise throw exception
qosSpecification = QosService.getQos(vpool.getId(), _dbClient);
}
// make sure vpool is unused by volumes/fileshares
ArgValidator.checkReference(VirtualPool.class, id, checkForDelete(vpool));
// Check if vpool is set as a continuous copies vpool
checkIfVpoolIsSetAsContinuousCopiesVpool(vpool);
// Additional check for VirtualPool that may be hidden in another VirtualPool via the
// protection settings
URIQueryResultList settingsResultList = new URIQueryResultList();
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVpoolProtectionVarraySettingsConstraint(id.toString()), settingsResultList);
Iterator<URI> settingsListItr = settingsResultList.iterator();
while (settingsListItr.hasNext()) {
final URI settingId = settingsListItr.next();
VpoolProtectionVarraySettings setting = _dbClient.queryObject(VpoolProtectionVarraySettings.class, settingId);
ArgValidator.checkEntity(setting, settingId, isIdEmbeddedInURL(settingId));
}
if (vpool.getProtectionVarraySettings() != null) {
// Delete all settings associated with the protection settings
deleteVPoolProtectionVArraySettings(vpool);
}
if (vpool.getFileRemoteCopySettings() != null) {
// Delete all settings associated with the protection settings
deleteFileVPoolRemoteCopyProtectionSettings(vpool);
}
// We also check to see if this virtual pool is specified as the HA virtual pool
// for some other virtual pool that specifies VPLEX distributed high availability.
// If this is the case, we disallow the deletion.
List<URI> vpoolURIs = _dbClient.queryByType(VirtualPool.class, true);
Iterator<VirtualPool> vpoolsIter = _dbClient.queryIterativeObjects(VirtualPool.class, vpoolURIs);
while (vpoolsIter.hasNext()) {
VirtualPool activeVPool = vpoolsIter.next();
if (!activeVPool.getId().equals(id)) {
StringMap haMap = activeVPool.getHaVarrayVpoolMap();
if ((haMap != null) && (!haMap.isEmpty()) && (haMap.values().contains(id.toString()))) {
// is not allowed.
throw APIException.badRequests.cantDeleteVPlexHaVPool(activeVPool.getLabel());
}
}
}
if (vpool.getType().equalsIgnoreCase(Type.block.name()) && qosSpecification != null) {
// Remove Qos associated to this Virtual Pool
_dbClient.removeObject(qosSpecification);
}
_dbClient.markForDeletion(vpool);
recordOperation(OperationTypeEnum.DELETE_VPOOL, VPOOL_DELETED_DESCRIPTION, vpool);
return Response.ok().build();
}
use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.
the class FilePolicyServiceUtils method updatePolicyCapabilities.
/**
* update the replication policy capabilities into capabilities list from applicable replication policy
* only a single replication policy across vpool/prject/fs levels
* otherwise throw appropriate exception.
*
* @param dbClient
* @param currVArray
* @param vPool
* @param project
* @param fs
* @param capabilities
* @param errorMsg
* @return true/false
*/
public static boolean updatePolicyCapabilities(DbClient dbClient, VirtualArray currVArray, VirtualPool vPool, Project project, FileShare fs, VirtualPoolCapabilityValuesWrapper capabilities, StringBuilder errorMsg) {
List<FilePolicy> eligiblePolicies = FileOrchestrationUtils.getReplicationPolices(dbClient, vPool, project, fs);
if (eligiblePolicies != null && !eligiblePolicies.isEmpty()) {
if (eligiblePolicies.size() > 1) {
if (errorMsg == null) {
errorMsg = new StringBuilder();
}
// Single replication policy across vpool/project/fs
errorMsg.append("More than one replication policy could not be applied accross vpool/project/fs");
return false;
}
FilePolicy policy = eligiblePolicies.get(0);
// Update replication policy capabilities!!
capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_TYPE, policy.getFileReplicationType());
capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_COPY_MODE, policy.getFileReplicationCopyMode());
if (vPool.getFrRpoType() != null) {
// rpo type can be DAYS or HOURS
capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_RPO_TYPE, vPool.getFrRpoType());
}
if (vPool.getFrRpoValue() != null) {
capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_RPO_VALUE, vPool.getFrRpoValue());
}
capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_APPLIED_AT, policy.getApplyAt());
// Update target varrys for file placement!!
Set<String> targetVArrys = new HashSet<String>();
if (policy.getFileReplicationType().equalsIgnoreCase(FileReplicationType.REMOTE.name())) {
if (policy.getReplicationTopologies() != null && !policy.getReplicationTopologies().isEmpty()) {
for (String strTopology : policy.getReplicationTopologies()) {
FileReplicationTopology dbTopology = dbClient.queryObject(FileReplicationTopology.class, URI.create(strTopology));
if (currVArray.getId().toString().equalsIgnoreCase(dbTopology.getSourceVArray().toString())) {
targetVArrys.addAll(dbTopology.getTargetVArrays());
break;
}
}
if (targetVArrys.isEmpty()) {
errorMsg.append("Target VArry is not defined in replication topology for source varry " + currVArray.getId().toString());
return false;
}
capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_TARGET_VARRAYS, targetVArrys);
capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_TARGET_VPOOL, vPool.getId());
} else {
errorMsg.append("Replication Topology is not defined for policy " + policy.getFilePolicyName());
return false;
}
} else {
targetVArrys.add(currVArray.getId().toString());
}
return true;
} else if (vPool.getFileReplicationSupported()) {
capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_TYPE, FileReplicationType.NONE.name());
errorMsg.append("No replication policy assigned at any level for virtual pool ").append(vPool.getLabel());
_log.warn(errorMsg.toString());
return true;
}
return false;
}
use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.
the class FileSystemReplicationUtils method getEquivalentPolicyStorageResource.
public static PolicyStorageResource getEquivalentPolicyStorageResource(FileShare fs, DbClient dbClient) {
FilePolicy fp = getReplicationPolicyAppliedOnFS(fs, dbClient);
if (fp != null) {
StringSet policyStrResources = fp.getPolicyStorageResources();
List<URI> policyStrURIs = new ArrayList<>();
for (String policyStrResource : policyStrResources) {
policyStrURIs.add(URI.create(policyStrResource));
}
Iterator<PolicyStorageResource> iterator = dbClient.queryIterativeObjects(PolicyStorageResource.class, policyStrURIs, true);
while (iterator.hasNext()) {
PolicyStorageResource policyRes = iterator.next();
if (policyRes.getAppliedAt().equals(fs.getId()) && policyRes.getStorageSystem().equals(fs.getStorageDevice())) {
return policyRes;
}
}
}
return null;
}
use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.
the class FileSystemReplicationUtils method getReplicationPolicyAppliedOnFS.
public static FilePolicy getReplicationPolicyAppliedOnFS(FileShare fs, DbClient dbClient) {
StringSet existingFSPolicies = fs.getFilePolicies();
List<URI> existingFSPolicyURIs = new ArrayList<>();
for (String filePolicyURI : existingFSPolicies) {
existingFSPolicyURIs.add(URI.create(filePolicyURI));
}
Iterator<FilePolicy> iterator = dbClient.queryIterativeObjects(FilePolicy.class, existingFSPolicyURIs, true);
while (iterator.hasNext()) {
FilePolicy fp = iterator.next();
if (fp.getFilePolicyType().equals(FilePolicy.FilePolicyType.file_replication.name())) {
_log.info("Found replication policy :{} applied to the file system: {}.", fp.toString(), fs.getId());
return fp;
}
}
return null;
}
use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.
the class FileDeviceController method assignFileSnapshotPolicyToVirtualPools.
@Override
public void assignFileSnapshotPolicyToVirtualPools(URI storageSystemURI, URI vNASURI, URI filePolicyToAssign, URI vpoolURI, String opId) throws ControllerException {
StorageSystem storageObj = null;
FilePolicy filePolicy = null;
VirtualNAS vNAS = null;
VirtualPool vpool = null;
try {
WorkflowStepCompleter.stepExecuting(opId);
FileDeviceInputOutput args = new FileDeviceInputOutput();
storageObj = _dbClient.queryObject(StorageSystem.class, storageSystemURI);
filePolicy = _dbClient.queryObject(FilePolicy.class, filePolicyToAssign);
vpool = _dbClient.queryObject(VirtualPool.class, vpoolURI);
if (vNASURI != null) {
vNAS = _dbClient.queryObject(VirtualNAS.class, vNASURI);
args.setvNAS(vNAS);
}
args.setFileProtectionPolicy(filePolicy);
args.setVPool(vpool);
_log.info("Assigning file snapshot policy: {} to vpool: {}", filePolicyToAssign, vpoolURI);
BiosCommandResult result = getDevice(storageObj.getSystemType()).checkFilePolicyExistsOrCreate(storageObj, args);
if (result.getCommandPending()) {
return;
}
if (!result.isCommandSuccess() && !result.getCommandPending()) {
WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
}
if (result.isCommandSuccess()) {
WorkflowStepCompleter.stepSucceded(opId);
}
} catch (Exception e) {
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
WorkflowStepCompleter.stepFailed(opId, serviceError);
}
}
Aggregations