use of com.emc.storageos.db.client.model.FilePolicy 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");
}
use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.
the class FilePolicyAssignWorkflowCompleter method complete.
@Override
protected void complete(DbClient dbClient, Status status, ServiceCoded coded) throws DeviceControllerException {
FilePolicy filePolicy = dbClient.queryObject(FilePolicy.class, getId());
if (Operation.Status.ready.equals(status)) {
updatePolicyAssignedResources(dbClient, filePolicy, status, coded);
setStatus(dbClient, status, coded);
} else {
StringBuffer strErrorMsg = new StringBuffer();
Integer totalWFSteps = 0;
int numFailedSteps = getWorkFlowFailedSteps(dbClient, getWorkFlowId(), strErrorMsg);
if (numFailedSteps > 0) {
totalWFSteps = getWorkFlowSteps(dbClient, getWorkFlowId()).size();
int successPolicies = totalWFSteps - numFailedSteps;
// In case of partial success, Update the policy assignment attributes!!
if (totalWFSteps != numFailedSteps) {
updatePolicyAssignedResources(dbClient, filePolicy, status, coded);
}
_log.error(String.format(" %s number of storage policies assigned successful and %s failed due to %s ", successPolicies, numFailedSteps, strErrorMsg.toString()));
ServiceError serviceError = DeviceControllerException.errors.deviceProtectionPolicyOperationFailed(filePolicy.getId().toString(), "assign", numFailedSteps, successPolicies);
setStatus(dbClient, status, serviceError);
}
}
}
use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.
the class FilePolicyUnAssignWorkflowCompleter method complete.
@Override
protected void complete(DbClient dbClient, Status status, ServiceCoded coded) throws DeviceControllerException {
try {
FilePolicy filePolicy = dbClient.queryObject(FilePolicy.class, getId());
if (Operation.Status.ready.equals(status)) {
updatePolicyUnAssignedResources(dbClient, filePolicy, status, coded);
setStatus(dbClient, status, coded);
} else {
StringBuffer strErrorMsg = new StringBuffer();
Integer totalWFSteps = 0;
int numFailedSteps = getWorkFlowFailedSteps(dbClient, getWorkFlowId(), strErrorMsg);
if (numFailedSteps > 0) {
totalWFSteps = getWorkFlowSteps(dbClient, getWorkFlowId()).size();
int successPolicies = totalWFSteps - numFailedSteps;
// In case of partial success, Do not update policy assignment attributes!!
// as there are some more storage system policy resources!!
_log.error(String.format(" %s number of storage policies assigned successful and %s failed due to %s ", successPolicies, numFailedSteps, strErrorMsg.toString()));
ServiceError serviceError = DeviceControllerException.errors.deviceProtectionPolicyOperationFailed(filePolicy.getId().toString(), "unassign", numFailedSteps, successPolicies);
setStatus(dbClient, status, serviceError);
}
}
} catch (Exception e) {
_log.info("Unassign file policy: and its resource DB object failed", getId(), e);
}
}
use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.
the class FileProtectionPolicyUpdateCompleter method complete.
@Override
protected void complete(DbClient dbClient, Status status, ServiceCoded coded) throws DeviceControllerException {
FilePolicy filePolicy = dbClient.queryObject(FilePolicy.class, getId());
int numStepsFailed = 0;
int numPolicies = 0;
List<WorkflowStep> workFlowSteps = getWorkFlowSteps(dbClient);
if (workFlowSteps != null && !workFlowSteps.isEmpty()) {
StringBuffer strErrorMsg = new StringBuffer();
strErrorMsg.append("The following workflow step(s) failed :");
numPolicies = workFlowSteps.size();
for (WorkflowStep workFlowStep : workFlowSteps) {
if (workFlowStep.getState() != null && workFlowStep.getState().equalsIgnoreCase("error")) {
numStepsFailed++;
strErrorMsg.append(workFlowStep.getDescription());
}
}
if (numStepsFailed > 0) {
_log.error("Update file protection policy failed with {}" + strErrorMsg.toString());
}
}
dbClient.updateObject(filePolicy);
// Update the task error, if the task failed!!!
if (numStepsFailed > 0) {
int successPolicies = numPolicies - numStepsFailed;
_log.error(String.format("Failed to Update %s storage policies and successfully updated %s policies", numStepsFailed, successPolicies));
ServiceError serviceError = DeviceControllerException.errors.deviceProtectionPolicyOperationFailed(filePolicy.getId().toString(), "update", numStepsFailed, successPolicies);
setStatus(dbClient, status, serviceError);
} else {
setStatus(dbClient, status, coded);
}
}
use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.
the class FileSystemAssignPolicyWorkflowCompleter method removeFileSystemReplicationAttrs.
private void removeFileSystemReplicationAttrs(DbClient dbClient, FileShare fileshare) {
FilePolicy filePolicy = dbClient.queryObject(FilePolicy.class, filePolicyURI);
if (filePolicy.getFilePolicyType().equals(FilePolicyType.file_replication.name()) && fileshare != null) {
List<FileShare> modifiedFileshares = new ArrayList<>();
// Remove source file share attributes!!
fileshare.setMirrorStatus(NullColumnValueGetter.getNullStr());
fileshare.setAccessState(NullColumnValueGetter.getNullStr());
fileshare.setPersonality(NullColumnValueGetter.getNullStr());
if (fileshare.getMirrorfsTargets() != null && !fileshare.getMirrorfsTargets().isEmpty()) {
StringSet targets = fileshare.getMirrorfsTargets();
for (String strTargetFs : targets) {
FileShare targetFs = dbClient.queryObject(FileShare.class, URI.create(strTargetFs));
targetFs.setMirrorStatus(NullColumnValueGetter.getNullStr());
targetFs.setAccessState(NullColumnValueGetter.getNullStr());
targetFs.setParentFileShare(NullColumnValueGetter.getNullNamedURI());
modifiedFileshares.add(targetFs);
}
targets.clear();
fileshare.setMirrorfsTargets(targets);
}
modifiedFileshares.add(fileshare);
if (!modifiedFileshares.isEmpty()) {
dbClient.updateObject(modifiedFileshares);
}
}
}
Aggregations