use of com.emc.storageos.db.client.model.FileReplicationTopology in project coprhd-controller by CoprHD.
the class FilePolicyService method updateFileReplicationTopologyInfo.
private void updateFileReplicationTopologyInfo(FilePolicyAssignParam param, FilePolicy filepolicy) {
if (FilePolicyType.file_replication.name().equalsIgnoreCase(filepolicy.getFilePolicyType()) && filepolicy.getFileReplicationType().equalsIgnoreCase(FileReplicationType.REMOTE.name())) {
if (param.getFileReplicationtopologies() != null && !param.getFileReplicationtopologies().isEmpty()) {
List<FileReplicationTopology> dbTopologies = queryDBReplicationTopologies(filepolicy);
for (FileReplicationTopologyParam topologyParam : param.getFileReplicationtopologies()) {
// Get existing topologies for given policy
Boolean foundExistingTopology = false;
if (dbTopologies != null && !dbTopologies.isEmpty()) {
for (FileReplicationTopology topology : dbTopologies) {
if (topology.getSourceVArray() != null && topology.getSourceVArray().toString().equalsIgnoreCase(topologyParam.getSourceVArray().toString())) {
_log.info("Updating the existing topology...");
if (topologyParam.getTargetVArrays() != null && !topologyParam.getTargetVArrays().isEmpty()) {
StringSet requestTargetVarraySet = new StringSet();
for (Iterator<URI> iterator = topologyParam.getTargetVArrays().iterator(); iterator.hasNext(); ) {
URI targetVArray = iterator.next();
requestTargetVarraySet.add(targetVArray.toString());
}
// Thow an error if admin want to change the topology for policy with resources!!
if (filepolicy.getPolicyStorageResources() != null && !filepolicy.getPolicyStorageResources().isEmpty()) {
if (topology.getTargetVArrays() != null && !topology.getTargetVArrays().containsAll(requestTargetVarraySet)) {
StringBuffer errorMsg = new StringBuffer();
errorMsg.append("Topology can not be changed for policy {} with existing resources " + filepolicy.getFilePolicyName());
_log.error(errorMsg.toString());
throw APIException.badRequests.invalidFilePolicyAssignParam(filepolicy.getFilePolicyName(), errorMsg.toString());
}
}
topology.setTargetVArrays(requestTargetVarraySet);
_dbClient.updateObject(topology);
}
if (filepolicy.getReplicationTopologies() == null || !filepolicy.getReplicationTopologies().contains(topology.getId().toString())) {
filepolicy.addReplicationTopology(topology.getId().toString());
_dbClient.updateObject(filepolicy);
}
foundExistingTopology = true;
break;
}
}
}
if (!foundExistingTopology) {
// Create DB entry for Replication topology
FileReplicationTopology dbReplTopology = new FileReplicationTopology();
dbReplTopology.setId(URIUtil.createId(FileReplicationTopology.class));
dbReplTopology.setPolicy(filepolicy.getId());
dbReplTopology.setSourceVArray(topologyParam.getSourceVArray());
StringSet targetArrays = new StringSet();
if (topologyParam.getTargetVArrays() != null && !topologyParam.getTargetVArrays().isEmpty()) {
for (URI uriTargetArray : topologyParam.getTargetVArrays()) {
targetArrays.add(uriTargetArray.toString());
}
dbReplTopology.setTargetVArrays(targetArrays);
}
_dbClient.createObject(dbReplTopology);
if (filepolicy.getReplicationTopologies() == null || !filepolicy.getReplicationTopologies().contains(dbReplTopology.getId().toString())) {
filepolicy.addReplicationTopology(dbReplTopology.getId().toString());
_dbClient.updateObject(filepolicy);
}
}
}
}
}
}
use of com.emc.storageos.db.client.model.FileReplicationTopology in project coprhd-controller by CoprHD.
the class FilePolicyService method updatePolicyCapabilities.
private static boolean updatePolicyCapabilities(DbClient dbClient, StringSet sourceVArraySet, VirtualPool vPool, FilePolicy policy, VirtualPoolCapabilityValuesWrapper capabilities, StringBuilder errorMsg) {
// Update replication policy capabilities!!
capabilities.put(VirtualPoolCapabilityValuesWrapper.VPOOL_PROJECT_POLICY_ASSIGN, true);
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 varrays for file placement!!
if (policy.getFileReplicationType() != null && policy.getFileReplicationType().equalsIgnoreCase(FileReplicationType.REMOTE.name())) {
if (policy.getReplicationTopologies() != null && !policy.getReplicationTopologies().isEmpty()) {
Set<String> targetVArrays = new HashSet<String>();
for (String strTopology : policy.getReplicationTopologies()) {
FileReplicationTopology dbTopology = dbClient.queryObject(FileReplicationTopology.class, URI.create(strTopology));
if (sourceVArraySet.contains(dbTopology.getSourceVArray().toString())) {
targetVArrays.addAll(dbTopology.getTargetVArrays());
break;
}
}
if (targetVArrays.isEmpty()) {
errorMsg.append("Target Varrays are not defined in replication topology for source varrays " + sourceVArraySet + ". ");
return false;
}
capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_TARGET_VARRAYS, targetVArrays);
capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_TARGET_VPOOL, vPool.getId());
} else {
errorMsg.append("Replication Topology is not defined for policy " + policy.getFilePolicyName() + ". ");
return false;
}
}
return true;
}
use of com.emc.storageos.db.client.model.FileReplicationTopology in project coprhd-controller by CoprHD.
the class FilePolicyService method getSourceVArraySet.
private StringSet getSourceVArraySet(VirtualPool vpool, FilePolicy filePolicy) {
StringSet vpoolVArraySet = vpool.getVirtualArrays();
if (filePolicy.getFileReplicationType() != null && filePolicy.getFileReplicationType().equalsIgnoreCase(FileReplicationType.REMOTE.name())) {
Set<String> topologyVArraySet = new HashSet<String>();
List<FileReplicationTopology> dbTopologies = queryDBReplicationTopologies(filePolicy);
if (dbTopologies != null && !dbTopologies.isEmpty()) {
for (Iterator<FileReplicationTopology> iterator = dbTopologies.iterator(); iterator.hasNext(); ) {
FileReplicationTopology fileReplicationTopology = iterator.next();
topologyVArraySet.add(fileReplicationTopology.getSourceVArray().toString());
}
}
vpoolVArraySet.retainAll(topologyVArraySet);
}
return vpoolVArraySet;
}
use of com.emc.storageos.db.client.model.FileReplicationTopology in project coprhd-controller by CoprHD.
the class FileReplicationPolicyUpdateTargetPoolMigration method queryDBReplicationTopologies.
private List<FileReplicationTopology> queryDBReplicationTopologies(FilePolicy policy) {
try {
ContainmentConstraint containmentConstraint = ContainmentConstraint.Factory.getFileReplicationPolicyTopologyConstraint(policy.getId());
List<FileReplicationTopology> topologies = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, FileReplicationTopology.class, containmentConstraint);
return topologies;
} catch (Exception e) {
logger.error("Error while querying {}", e);
}
return null;
}
use of com.emc.storageos.db.client.model.FileReplicationTopology in project coprhd-controller by CoprHD.
the class FileReplicationPolicyUpdateTargetPoolMigration method process.
@Override
public void process() throws MigrationCallbackException {
logger.info("File replication policy to update it's target pool in topology migration START");
DbClient dbClient = getDbClient();
try {
List<URI> virtualPoolURIs = dbClient.queryByType(VirtualPool.class, true);
Iterator<VirtualPool> virtualPools = dbClient.queryIterativeObjects(VirtualPool.class, virtualPoolURIs, true);
List<FileReplicationTopology> replPolicyTopologies = new ArrayList<FileReplicationTopology>();
Map<String, FilePolicy> replicationPolicies = getRemoteReplicationPolicies();
if (replicationPolicies.isEmpty()) {
logger.info("No remote replication policies found in system... ");
return;
}
// Update the target vpool in topology for that policy
while (virtualPools.hasNext()) {
VirtualPool virtualPool = virtualPools.next();
if (VirtualPool.Type.file.name().equals(virtualPool.getType()) && virtualPool.getFileReplicationType() != null && FileReplicationType.REMOTE.name().equalsIgnoreCase(virtualPool.getFileReplicationType())) {
logger.info("Getting replicaiton policies associated with vpool {} ", virtualPool.getLabel());
// Get the existing replication policy
// which was created with vpool name followed by _Replication_Policy
String polName = virtualPool.getLabel() + "_Replication_Policy";
FilePolicy replPolicy = replicationPolicies.get(polName);
if (replPolicy != null) {
// Get the replication topologies for the policy!!
List<FileReplicationTopology> policyTopologies = queryDBReplicationTopologies(replPolicy);
if (policyTopologies != null && !policyTopologies.isEmpty()) {
// Get the target vpool from the vpool!
String targetVarray = null;
String targetVPool = null;
Map<URI, VpoolRemoteCopyProtectionSettings> remoteSettings = virtualPool.getFileRemoteProtectionSettings(virtualPool, dbClient);
if (remoteSettings != null && !remoteSettings.isEmpty()) {
// till now CoprHD supports only single target!!
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;
}
}
}
for (FileReplicationTopology topology : policyTopologies) {
if (virtualPool.getVirtualArrays().contains(topology.getSourceVArray().toASCIIString()) && topology.getTargetVArrays().contains(targetVarray)) {
if (targetVarray != null && targetVPool != null) {
topology.setTargetVAVPool(targetVarray + SEPARATOR + targetVPool);
replPolicyTopologies.add(topology);
}
}
}
}
} else {
logger.info("No remote replication policy with name {} ", polName);
}
}
}
// Udate DB
if (!replPolicyTopologies.isEmpty()) {
logger.info("Modified {} topologies ", replPolicyTopologies.size());
dbClient.updateObject(replPolicyTopologies);
}
} catch (Exception ex) {
logger.error("Exception occured while migrating file replication policy topology ");
logger.error(ex.getMessage(), ex);
}
logger.info("File replication policy to update it's target pool in topology migration END");
}
Aggregations