Search in sources :

Example 31 with FilePolicy

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");
}
Also used : VpoolRemoteCopyProtectionSettings(com.emc.storageos.db.client.model.VpoolRemoteCopyProtectionSettings) DbClient(com.emc.storageos.db.client.DbClient) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) ArrayList(java.util.ArrayList) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException) HashMap(java.util.HashMap) Map(java.util.Map) FileReplicationTopology(com.emc.storageos.db.client.model.FileReplicationTopology)

Example 32 with FilePolicy

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);
        }
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) FilePolicy(com.emc.storageos.db.client.model.FilePolicy)

Example 33 with FilePolicy

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);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 34 with FilePolicy

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);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) WorkflowStep(com.emc.storageos.db.client.model.WorkflowStep) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint)

Example 35 with FilePolicy

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);
        }
    }
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) ArrayList(java.util.ArrayList) StringSet(com.emc.storageos.db.client.model.StringSet) FileShare(com.emc.storageos.db.client.model.FileShare)

Aggregations

FilePolicy (com.emc.storageos.db.client.model.FilePolicy)70 URI (java.net.URI)25 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)21 FileShare (com.emc.storageos.db.client.model.FileShare)18 StringSet (com.emc.storageos.db.client.model.StringSet)18 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)18 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)18 ControllerException (com.emc.storageos.volumecontroller.ControllerException)18 ArrayList (java.util.ArrayList)18 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)16 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)15 WorkflowException (com.emc.storageos.workflow.WorkflowException)15 PolicyStorageResource (com.emc.storageos.db.client.model.PolicyStorageResource)14 MapFilePolicy (com.emc.storageos.api.mapper.functions.MapFilePolicy)13 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)13 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)13 Path (javax.ws.rs.Path)13 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)12 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)12 URISyntaxException (java.net.URISyntaxException)12