use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.
the class FileSystemAssignPolicyWorkflowCompleter method updateFilePolicyResource.
private void updateFilePolicyResource(DbClient dbClient) {
FilePolicy filePolicy = dbClient.queryObject(FilePolicy.class, filePolicyURI);
if (filePolicy.getFilePolicyType().equals(FilePolicyType.file_snapshot.name())) {
filePolicy.addAssignedResources(getIds().get(0));
FileShare fileSystem = dbClient.queryObject(FileShare.class, getIds().get(0));
fileSystem.addFilePolicy(filePolicyURI);
dbClient.updateObject(filePolicy);
dbClient.updateObject(fileSystem);
} else {
FileShare fileSystem = getSourceFileSystem(dbClient);
if (fileSystem != null) {
filePolicy.addAssignedResources(fileSystem.getId());
fileSystem.addFilePolicy(filePolicyURI);
dbClient.updateObject(filePolicy);
dbClient.updateObject(fileSystem);
}
}
}
use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.
the class FileSnapshotPolicyMigration method process.
@Override
public void process() throws MigrationCallbackException {
logger.info("File snapshot schedule policy to file policy migration START");
DbClient dbClient = getDbClient();
try {
List<URI> schedulePolicyURIs = dbClient.queryByType(SchedulePolicy.class, true);
Iterator<SchedulePolicy> schedulePolicies = dbClient.queryIterativeObjects(SchedulePolicy.class, schedulePolicyURIs, true);
List<FilePolicy> filePolicies = new ArrayList<FilePolicy>();
List<VirtualPool> modifiedVpools = new ArrayList<VirtualPool>();
while (schedulePolicies.hasNext()) {
SchedulePolicy schedulePolicy = schedulePolicies.next();
FilePolicy fileSnapshotPolicy = new FilePolicy();
VirtualPool associatedVP = new VirtualPool();
fileSnapshotPolicy.setId(URIUtil.createId(FilePolicy.class));
if (schedulePolicy.getAssignedResources() != null && !schedulePolicy.getAssignedResources().isEmpty()) {
for (String assignedResource : schedulePolicy.getAssignedResources()) {
logger.info("assigning resource to fileSnapshotPolicy from schedulePolicy : {}", schedulePolicy.getAssignedResources());
fileSnapshotPolicy.addAssignedResources(resourceURI(assignedResource));
logger.info("Assigned resources from fileSnapshotPolicy : {}", fileSnapshotPolicy.getAssignedResources());
}
}
fileSnapshotPolicy.setFilePolicyDescription("Policy created from Schedule Policy " + schedulePolicy.getLabel() + " while system upgrade");
String polName = schedulePolicy.getLabel() + "_File_Snapshot_Policy";
fileSnapshotPolicy.setLabel(polName);
fileSnapshotPolicy.setFilePolicyName(schedulePolicy.getLabel());
fileSnapshotPolicy.setFilePolicyType(FilePolicyType.file_snapshot.name());
fileSnapshotPolicy.setScheduleFrequency(schedulePolicy.getScheduleFrequency());
fileSnapshotPolicy.setScheduleRepeat(schedulePolicy.getScheduleRepeat());
fileSnapshotPolicy.setScheduleTime(schedulePolicy.getScheduleTime());
fileSnapshotPolicy.setScheduleDayOfWeek(schedulePolicy.getScheduleDayOfWeek());
fileSnapshotPolicy.setScheduleDayOfMonth(schedulePolicy.getScheduleDayOfMonth());
fileSnapshotPolicy.setSnapshotExpireTime(schedulePolicy.getSnapshotExpireTime());
fileSnapshotPolicy.setSnapshotExpireType(schedulePolicy.getSnapshotExpireType());
// snapshot policy apply at file system level
fileSnapshotPolicy.setApplyAt(FilePolicyApplyLevel.file_system.name());
if (schedulePolicy.getAssignedResources() != null && !schedulePolicy.getAssignedResources().isEmpty()) {
List<URI> fileShareURIs = getAssignedResourcesURIs(schedulePolicy.getAssignedResources());
for (URI fsURI : fileShareURIs) {
FileShare fs = dbClient.queryObject(FileShare.class, fsURI);
if (!fs.getInactive()) {
StorageSystem system = dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
updatePolicyStorageResouce(system, fileSnapshotPolicy, fs);
// Remove the existing schedule policy from fs
// add new file policy to fs!!
StringSet fsExistingPolicies = fs.getFilePolicies();
if (fsExistingPolicies != null && !fsExistingPolicies.isEmpty()) {
Set<String> snapSchedulesToRemove = new HashSet<String>();
for (String existingSnapPolicyId : fsExistingPolicies) {
if (URIUtil.isType(URI.create(existingSnapPolicyId), SchedulePolicy.class)) {
snapSchedulesToRemove.add(existingSnapPolicyId);
}
}
if (!snapSchedulesToRemove.isEmpty()) {
/*
* StringSet.removeAll() does not work if the set has only one entry.
* Hence the logic below
*/
if (fsExistingPolicies.size() == 1 && snapSchedulesToRemove.size() == 1) {
fsExistingPolicies.clear();
} else {
fsExistingPolicies.removeAll(snapSchedulesToRemove);
}
}
} else {
fsExistingPolicies = new StringSet();
}
fsExistingPolicies.add(fileSnapshotPolicy.getId().toString());
fs.setFilePolicies(fsExistingPolicies);
dbClient.updateObject(fs);
URI associatedVPId = fs.getVirtualPool();
associatedVP = dbClient.queryObject(VirtualPool.class, associatedVPId);
associatedVP.setAllowFilePolicyAtFSLevel(true);
modifiedVpools.add(associatedVP);
}
}
}
filePolicies.add(fileSnapshotPolicy);
}
// Update DB
if (!filePolicies.isEmpty()) {
logger.info("Created {} file snapshot policies", filePolicies.size());
dbClient.createObject(filePolicies);
}
if (!modifiedVpools.isEmpty()) {
logger.info("Modified {} vpools ", modifiedVpools.size());
dbClient.updateObject(modifiedVpools);
}
} catch (Exception ex) {
logger.error("Exception occured while migrating file replication policy for Virtual pools");
logger.error(ex.getMessage(), ex);
}
}
use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.
the class VirtualPoolFileReplicationPolicyMigration method process.
@Override
public void process() throws MigrationCallbackException {
logger.info("File Virtual pool to file replication policy migration START");
DbClient dbClient = getDbClient();
try {
List<URI> virtualPoolURIs = dbClient.queryByType(VirtualPool.class, true);
Iterator<VirtualPool> virtualPools = dbClient.queryIterativeObjects(VirtualPool.class, virtualPoolURIs, true);
List<VirtualPool> modifiedVpools = new ArrayList<VirtualPool>();
List<FilePolicy> replPolicies = new ArrayList<FilePolicy>();
// Establish relation from policy to FilePolicyResource
while (virtualPools.hasNext()) {
VirtualPool virtualPool = virtualPools.next();
if (VirtualPool.Type.file.name().equals(virtualPool.getType()) && virtualPool.getFileReplicationType() != null && !FileReplicationType.NONE.name().equalsIgnoreCase(virtualPool.getFileReplicationType())) {
logger.info("vpool {} has enabled with replication, Creating appropriate file policy.....", virtualPool.getLabel());
// Create replication policy
FilePolicy replPolicy = new FilePolicy();
replPolicy.setId(URIUtil.createId(FilePolicy.class));
replPolicy.setFilePolicyDescription("Policy created from virtual pool " + virtualPool.getLabel() + " while system upgrade");
String polName = virtualPool.getLabel() + "_Replication_Policy";
replPolicy.setLabel(polName);
replPolicy.setFilePolicyName(polName);
replPolicy.setLabel(polName);
replPolicy.setFilePolicyType(FilePolicyType.file_replication.name());
replPolicy.setFilePolicyVpool(virtualPool.getId());
// Replication policy was created always at file system level!!
replPolicy.setApplyAt(FilePolicyApplyLevel.file_system.name());
if (virtualPool.getFileReplicationCopyMode().equals(VirtualPool.RPCopyMode.ASYNCHRONOUS.name())) {
replPolicy.setFileReplicationCopyMode(FilePolicy.FileReplicationCopyMode.ASYNC.name());
} else {
replPolicy.setFileReplicationCopyMode(FilePolicy.FileReplicationCopyMode.SYNC.name());
}
replPolicy.setFileReplicationType(virtualPool.getFileReplicationType());
replPolicy.setPriority(FilePolicyPriority.Normal.toString());
// Set the policy schedule based on vPool RPO
if (virtualPool.getFrRpoValue() != null && virtualPool.getFrRpoType() != null) {
replPolicy.setScheduleRepeat((long) virtualPool.getFrRpoValue());
replPolicy.setScheduleTime("00:00AM");
replPolicy.setScheduleFrequency(virtualPool.getFrRpoType().toLowerCase());
// Virtual pool was supporting only Minutes/Hours/Days for RPO type
// Day of the week and month is not applicable!!
replPolicy.setScheduleDayOfWeek(NullColumnValueGetter.getNullStr());
replPolicy.setScheduleDayOfMonth(0L);
}
// set topology reference to policy
if (FileReplicationType.REMOTE.name().equalsIgnoreCase(virtualPool.getFileReplicationType())) {
logger.info("Creating replication topology for remote replication vpool {} .....", virtualPool.getLabel());
StringSet replicationTopologies = new StringSet();
StringSet targetVarrays = new StringSet();
String targetVarray = null;
String targetVPool = null;
Map<URI, VpoolRemoteCopyProtectionSettings> remoteSettings = virtualPool.getFileRemoteProtectionSettings(virtualPool, dbClient);
if (remoteSettings != null && !remoteSettings.isEmpty()) {
for (Map.Entry<URI, VpoolRemoteCopyProtectionSettings> entry : remoteSettings.entrySet()) {
if (entry != null) {
targetVarray = entry.getKey().toString();
if (entry.getValue() != null && entry.getValue().getVirtualPool() != null) {
targetVPool = entry.getValue().getVirtualPool().toString();
}
break;
}
}
if (targetVarray != null) {
targetVarrays.add(targetVarray);
}
}
if (virtualPool.getVirtualArrays() != null && !virtualPool.getVirtualArrays().isEmpty()) {
for (String srcvArray : virtualPool.getVirtualArrays()) {
FileReplicationTopology dbReplTopology = new FileReplicationTopology();
dbReplTopology.setId(URIUtil.createId(FileReplicationTopology.class));
dbReplTopology.setPolicy(replPolicy.getId());
dbReplTopology.setSourceVArray(URI.create(srcvArray));
dbReplTopology.setTargetVArrays(targetVarrays);
if (targetVarray != null && targetVPool != null) {
dbReplTopology.setTargetVAVPool(targetVarray + SEPARATOR + targetVPool);
}
dbClient.createObject(dbReplTopology);
replicationTopologies.add(dbReplTopology.getId().toString());
}
replPolicy.setReplicationTopologies(replicationTopologies);
logger.info("Created {} replication topologies from vpool {}", replicationTopologies.size(), virtualPool.getLabel().toString());
}
}
// Fetch if there are any file system were provisioned with the vpool
// if present, link them to replication policy!!
URIQueryResultList resultList = new URIQueryResultList();
dbClient.queryByConstraint(ContainmentConstraint.Factory.getVirtualPoolFileshareConstraint(virtualPool.getId()), resultList);
for (Iterator<URI> fileShareItr = resultList.iterator(); fileShareItr.hasNext(); ) {
FileShare fs = dbClient.queryObject(FileShare.class, fileShareItr.next());
if (!fs.getInactive() && fs.getPersonality() != null && fs.getPersonality().equalsIgnoreCase(PersonalityTypes.SOURCE.name())) {
StorageSystem system = dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
updatePolicyStorageResouce(system, replPolicy, fs);
fs.addFilePolicy(replPolicy.getId());
dbClient.updateObject(fs);
}
}
replPolicies.add(replPolicy);
virtualPool.setAllowFilePolicyAtFSLevel(true);
virtualPool.setFileReplicationSupported(true);
modifiedVpools.add(virtualPool);
}
}
// Udate DB
if (!replPolicies.isEmpty()) {
logger.info("Created {} replication policies ", replPolicies.size());
dbClient.createObject(replPolicies);
}
if (!modifiedVpools.isEmpty()) {
logger.info("Modified {} vpools ", modifiedVpools.size());
dbClient.updateObject(modifiedVpools);
}
} catch (Exception ex) {
logger.error("Exception occured while migrating file replication policy for Virtual pools");
logger.error(ex.getMessage(), ex);
}
logger.info("Virtual pool file replication policy migration END");
}
use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.
the class IsilonFileStorageDevice method checkPolicyAppliedOnPath.
/**
* This method checks these entries for existing policy
* return true, if the policy is already applied on the path, otherwise false.
*
* Policy storage resource is storing all storage system paths
* on which the policy template is applied.
*
* @param storageObj - The storage system on which the policy is to be checked
* @param args
* @param policyPath
* @return
*/
private boolean checkPolicyAppliedOnPath(StorageSystem storageObj, FileDeviceInputOutput args, String policyPath) {
//
FilePolicy filePolicy = args.getFileProtectionPolicy();
if (filePolicy != null && !filePolicy.getInactive()) {
StringSet policyStrRes = filePolicy.getPolicyStorageResources();
if (policyStrRes != null && !policyStrRes.isEmpty()) {
for (String policyStrRe : policyStrRes) {
PolicyStorageResource strRes = _dbClient.queryObject(PolicyStorageResource.class, URIUtil.uri(policyStrRe));
if (strRes != null && strRes.getStorageSystem().toString().equals(storageObj.getId().toString()) && strRes.getResourcePath().equalsIgnoreCase(policyPath)) {
return true;
}
}
}
}
String msg = String.format("File Policy template %s was not applied on storage system %s path %s", filePolicy.getFilePolicyName(), storageObj.getLabel(), policyPath);
_log.info(msg);
return false;
}
use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.
the class IsilonFileStorageDevice method checkFilePolicyPathHasResourceLabel.
@Override
public BiosCommandResult checkFilePolicyPathHasResourceLabel(StorageSystem system, FileDeviceInputOutput args) {
_log.info("Inside checkFilePolicyPathHasResourceLabel()");
try {
FilePolicy filePolicy = args.getFileProtectionPolicy();
String filePolicyBasePath = getFilePolicyPath(system, filePolicy.getApplyAt(), args);
checkAppliedResourceNamePartOfFilePolicyPath(filePolicyBasePath, filePolicy, args);
_log.info("checkFilePolicyPathHasResourceLabel successful.");
return BiosCommandResult.createSuccessfulResult();
} catch (IsilonException e) {
_log.error("checkFilePolicyPathHasResourceLabel failed.", e);
return BiosCommandResult.createErrorResult(e);
}
}
Aggregations