use of com.emc.storageos.db.client.model.FileReplicationTopology 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.FileReplicationTopology in project coprhd-controller by CoprHD.
the class FileOrchestrationUtils method removeTopologyInfo.
/**
* Remove replication topology info from policy
* if no assigned resources with the policy
*
* @param filePolicy the file policy template
* @param dbClient
*/
public static void removeTopologyInfo(FilePolicy filePolicy, DbClient dbClient) {
// Remove the replication topology from the policy
if (filePolicy.getFilePolicyType().equalsIgnoreCase(FilePolicyType.file_replication.name()) && (filePolicy.getAssignedResources() == null || filePolicy.getAssignedResources().isEmpty())) {
if (filePolicy.getReplicationTopologies() != null && !filePolicy.getReplicationTopologies().isEmpty()) {
for (String uriTopology : filePolicy.getReplicationTopologies()) {
FileReplicationTopology topology = dbClient.queryObject(FileReplicationTopology.class, URI.create(uriTopology));
if (topology != null) {
topology.setInactive(true);
filePolicy.removeReplicationTopology(uriTopology);
dbClient.updateObject(topology);
}
}
_log.info("Removed replication topology from policy {}", filePolicy.getFilePolicyName());
}
}
dbClient.updateObject(filePolicy);
}
use of com.emc.storageos.db.client.model.FileReplicationTopology in project coprhd-controller by CoprHD.
the class FileService method assignFileReplicationPolicyToFS.
private TaskResourceRep assignFileReplicationPolicyToFS(FileShare fs, FilePolicy filePolicy, FilePolicyFileSystemAssignParam param, String task) {
StringBuffer notSuppReasonBuff = new StringBuffer();
// Verify the fs has replication attributes!!!
if (fs.getPersonality() != null && PersonalityTypes.SOURCE.name().equalsIgnoreCase(fs.getPersonality()) && fs.getMirrorfsTargets() != null && !fs.getMirrorfsTargets().isEmpty()) {
notSuppReasonBuff.append(String.format("File system %s has active target file systems", fs.getLabel()));
_log.error(notSuppReasonBuff.toString());
throw APIException.badRequests.unableToProcessRequest(notSuppReasonBuff.toString());
}
// File system should not be the target file system..
if (fs.getPersonality() != null && fs.getPersonality().equalsIgnoreCase(PersonalityTypes.TARGET.name())) {
notSuppReasonBuff.append(String.format("File system - %s given in request is an active Target file system.", fs.getLabel()));
_log.error(notSuppReasonBuff.toString());
throw APIException.badRequests.unableToProcessRequest(notSuppReasonBuff.toString());
}
ArgValidator.checkFieldNotNull(param.getTargetVArrays(), "target_varrays");
Set<URI> targertVarrayURIs = param.getTargetVArrays();
for (URI targertVarrayURI : targertVarrayURIs) {
ArgValidator.checkFieldUriType(targertVarrayURI, VirtualArray.class, "target_varray");
VirtualArray targetVarray = _permissionsHelper.getObjectById(targertVarrayURI, VirtualArray.class);
ArgValidator.checkEntity(targetVarray, targertVarrayURI, false);
}
VirtualArray sourceVarray = _dbClient.queryObject(VirtualArray.class, fs.getVirtualArray());
// Get the project.
URI projectURI = fs.getProject().getURI();
Project project = _permissionsHelper.getObjectById(projectURI, Project.class);
VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, fs.getVirtualPool());
// New operation
TaskList taskList = new TaskList();
Operation op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.ASSIGN_FILE_POLICY_TO_FILE_SYSTEM);
op.setDescription("assign file policy to file system");
// As the action done by tenant admin
// Set current tenant as task's tenant!!!
Task taskObj = op.getTask(fs.getId());
FilePolicyServiceUtils.updateTaskTenant(_dbClient, filePolicy, "assign", taskObj, fs.getTenant().getURI());
TaskResourceRep fileShareTask = toTask(fs, task, op);
taskList.getTaskList().add(fileShareTask);
StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
// prepare vpool capability values
VirtualPoolCapabilityValuesWrapper capabilities = new VirtualPoolCapabilityValuesWrapper();
capabilities.put(VirtualPoolCapabilityValuesWrapper.SIZE, fs.getCapacity());
capabilities.put(VirtualPoolCapabilityValuesWrapper.RESOURCE_COUNT, new Integer(1));
if (VirtualPool.ProvisioningType.Thin.toString().equalsIgnoreCase(vpool.getSupportedProvisioningType())) {
capabilities.put(VirtualPoolCapabilityValuesWrapper.THIN_PROVISIONING, Boolean.TRUE);
}
// Set the source file system details
// source fs details used in finding recommendations for target fs!!
capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_SYSTEM_CREATE_MIRROR_COPY, Boolean.TRUE);
capabilities.put(VirtualPoolCapabilityValuesWrapper.EXISTING_SOURCE_FILE_SYSTEM, fs);
capabilities.put(VirtualPoolCapabilityValuesWrapper.SOURCE_STORAGE_SYSTEM, device);
capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_TYPE, filePolicy.getFileReplicationType());
capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_COPY_MODE, filePolicy.getFileReplicationCopyMode());
Set<String> targetVArrys = new HashSet<String>();
if (filePolicy.getFileReplicationType().equalsIgnoreCase(FileReplicationType.REMOTE.name())) {
for (URI targertVarrayURI : targertVarrayURIs) {
targetVArrys.add(targertVarrayURI.toString());
}
} else {
targetVArrys.add(sourceVarray.getId().toString());
}
URI targetvPool = null;
// Get the existing topologies for the policy
if (filePolicy.getReplicationTopologies() != null && !filePolicy.getReplicationTopologies().isEmpty()) {
for (String strTopology : filePolicy.getReplicationTopologies()) {
FileReplicationTopology dbTopology = _dbClient.queryObject(FileReplicationTopology.class, URI.create(strTopology));
Set<String> dbTargetVArrys = new HashSet<String>();
if (dbTopology != null && sourceVarray.getId().toString().equalsIgnoreCase(dbTopology.getSourceVArray().toString())) {
dbTargetVArrys.addAll(dbTopology.getTargetVArrays());
if (dbTargetVArrys.containsAll(targetVArrys)) {
// which are created from older release remote replication vpool
for (String targetVarray : targetVArrys) {
if (dbTopology.getTargetVAVPool() != null && !dbTopology.getTargetVAVPool().isEmpty()) {
String[] vavPool = dbTopology.getTargetVAVPool().split(SEPARATOR);
if (vavPool != null && vavPool.length > 1 && targetVarray.equalsIgnoreCase(vavPool[0])) {
String strvPool = vavPool[1];
VirtualPool vPool = _dbClient.queryObject(VirtualPool.class, URI.create(strvPool));
if (vPool != null && !vPool.getInactive()) {
targetvPool = vPool.getId();
}
}
}
}
}
break;
}
}
}
capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_TARGET_VARRAYS, targetVArrys);
if (targetvPool != null) {
capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_TARGET_VPOOL, targetvPool);
} else {
capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_TARGET_VPOOL, vpool.getId());
}
FileServiceApi fileServiceApi = getFileShareServiceImpl(capabilities, _dbClient);
try {
// Call out placementManager to get the recommendation for placement.
List recommendations = _filePlacementManager.getRecommendationsForFileCreateRequest(sourceVarray, project, vpool, capabilities);
fileServiceApi.assignFilePolicyToFileSystem(fs, filePolicy, project, vpool, sourceVarray, taskList, task, recommendations, capabilities);
} catch (BadRequestException e) {
_dbClient.error(FileShare.class, fs.getId(), task, e);
_log.error("Error Assigning Filesystem policy {}, {}", e.getMessage(), e);
throw e;
} catch (Exception e) {
_log.error("Error Assigning Filesystem policy {}, {}", e.getMessage(), e);
throw APIException.badRequests.unableToProcessRequest(e.getMessage());
}
return fileShareTask;
}
use of com.emc.storageos.db.client.model.FileReplicationTopology in project coprhd-controller by CoprHD.
the class FilePolicyService method queryDBReplicationTopologies.
private List<FileReplicationTopology> queryDBReplicationTopologies(FilePolicy policy) {
_log.info("Querying all DB replication topologies Using policy Id {}", policy.getId());
try {
ContainmentConstraint containmentConstraint = ContainmentConstraint.Factory.getFileReplicationPolicyTopologyConstraint(policy.getId());
List<FileReplicationTopology> topologies = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, FileReplicationTopology.class, containmentConstraint);
return topologies;
} catch (Exception e) {
_log.error("Error while querying {}", e);
}
return null;
}
use of com.emc.storageos.db.client.model.FileReplicationTopology 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;
}
Aggregations