use of com.emc.storageos.db.client.model.PolicyStorageResource in project coprhd-controller by CoprHD.
the class FileOrchestrationUtils method updatePolicyStorageResource.
/**
* Create/Update the File policy resource
*
* @param dbClient
* @param system
* @param filePolicy
* @param args
* @param sourcePath
* @return
*/
public static PolicyStorageResource updatePolicyStorageResource(DbClient dbClient, StorageSystem system, FilePolicy filePolicy, FileDeviceInputOutput args, String sourcePath, String name, String policyNativeId, StorageSystem targetSystem, NASServer targetNasServer, String targetPath) {
PolicyStorageResource policyStorageResource = new PolicyStorageResource();
policyStorageResource.setId(URIUtil.createId(PolicyStorageResource.class));
policyStorageResource.setFilePolicyId(filePolicy.getId());
policyStorageResource.setStorageSystem(system.getId());
policyStorageResource.setPolicyNativeId(policyNativeId);
policyStorageResource.setName(name);
policyStorageResource.setLabel(name);
policyStorageResource.setResourcePath(sourcePath);
NASServer nasServer = null;
if (args.getvNAS() != null) {
nasServer = args.getvNAS();
} else {
// Get the physical NAS for the storage system!!
PhysicalNAS pNAS = getSystemPhysicalNAS(dbClient, system);
if (pNAS != null) {
nasServer = pNAS;
}
}
policyStorageResource.setNasServer(nasServer.getId());
setPolicyStorageAppliedAt(filePolicy, args, policyStorageResource);
policyStorageResource.setNativeGuid(NativeGUIDGenerator.generateNativeGuidForFilePolicyResource(system, nasServer.getNasName(), filePolicy.getFilePolicyType(), sourcePath, NativeGUIDGenerator.FILE_STORAGE_RESOURCE));
if (filePolicy.getFilePolicyType().equalsIgnoreCase(FilePolicy.FilePolicyType.file_replication.name())) {
// Update the target resource details!!!
FileReplicaPolicyTargetMap fileReplicaPolicyTargetMap = new FileReplicaPolicyTargetMap();
FileReplicaPolicyTarget target = new FileReplicaPolicyTarget();
if (targetNasServer != null) {
target.setNasServer(targetNasServer.getId().toString());
} else {
PhysicalNAS pNAS = FileOrchestrationUtils.getSystemPhysicalNAS(dbClient, targetSystem);
if (pNAS != null) {
target.setNasServer(pNAS.getId().toString());
}
}
target.setAppliedAt(filePolicy.getApplyAt());
target.setStorageSystem(targetSystem.getId().toString());
target.setPath(targetPath);
String key = target.getFileTargetReplicaKey();
fileReplicaPolicyTargetMap.put(key, target);
policyStorageResource.setFileReplicaPolicyTargetMap(fileReplicaPolicyTargetMap);
}
dbClient.createObject(policyStorageResource);
filePolicy.addPolicyStorageResources(policyStorageResource.getId());
dbClient.updateObject(filePolicy);
_log.info("PolicyStorageResource object created successfully for {} ", system.getLabel() + policyStorageResource.getAppliedAt());
return policyStorageResource;
}
use of com.emc.storageos.db.client.model.PolicyStorageResource in project coprhd-controller by CoprHD.
the class FileDeviceController method updateStorageSystemFileProtectionPolicy.
@Override
public void updateStorageSystemFileProtectionPolicy(URI storage, URI policy, URI policyRes, FilePolicyUpdateParam policyUpdateParam, String opId) throws InternalException {
ControllerUtils.setThreadLocalLogData(policy, opId);
FileDeviceInputOutput args = new FileDeviceInputOutput();
try {
FilePolicy filePolicy = _dbClient.queryObject(FilePolicy.class, policy);
PolicyStorageResource policyResource = _dbClient.queryObject(PolicyStorageResource.class, policyRes);
if (filePolicy != null && policyResource != null) {
StorageSystem storageObj = _dbClient.queryObject(StorageSystem.class, storage);
_log.info("Updating File protection ile Policy {}", policy);
args.setFileProtectionPolicy(filePolicy);
args.setPolicyStorageResource(policyResource);
args.setFileProtectionPolicyUpdateParam(policyUpdateParam);
args.setFileOperation(true);
args.setOpId(opId);
// Do the Operation on device.
BiosCommandResult result = getDevice(storageObj.getSystemType()).updateStorageSystemFileProtectionPolicy(storageObj, args);
if (!result.isCommandSuccess() && !result.getCommandPending()) {
WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
}
if (result.isCommandSuccess()) {
WorkflowStepCompleter.stepSucceded(opId);
}
} else {
throw DeviceControllerException.exceptions.invalidObjectNull();
}
} catch (Exception e) {
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
WorkflowStepCompleter.stepFailed(opId, serviceError);
}
}
use of com.emc.storageos.db.client.model.PolicyStorageResource in project coprhd-controller by CoprHD.
the class IsilonFileStorageDevice method doStartMirrorLink.
@Override
public BiosCommandResult doStartMirrorLink(StorageSystem system, FileShare fs, TaskCompleter completer) {
FileShare sourceFS = null;
FileShare targetFS = null;
StorageSystem sourceSystem = null;
StorageSystem targetSystem = null;
boolean isMirrorPolicy = false;
if (fs.getPersonality().equals(PersonalityTypes.TARGET.name())) {
sourceFS = _dbClient.queryObject(FileShare.class, fs.getParentFileShare());
targetFS = fs;
isMirrorPolicy = true;
} else if (fs.getPersonality().equals(PersonalityTypes.SOURCE.name())) {
sourceFS = fs;
List<String> targetfileUris = new ArrayList<String>();
targetfileUris.addAll(fs.getMirrorfsTargets());
if (!targetfileUris.isEmpty()) {
targetFS = _dbClient.queryObject(FileShare.class, URI.create(targetfileUris.get(0)));
} else {
ServiceError serviceError = DeviceControllerErrors.isilon.unableToGetTargetFileSystem(sourceFS.getLabel());
return BiosCommandResult.createErrorResult(serviceError);
}
}
sourceSystem = _dbClient.queryObject(StorageSystem.class, sourceFS.getStorageDevice());
targetSystem = _dbClient.queryObject(StorageSystem.class, targetFS.getStorageDevice());
PolicyStorageResource policyStrRes = getEquivalentPolicyStorageResource(sourceFS, _dbClient);
if (policyStrRes != null) {
// get the policy details by policy native id
IsilonSyncPolicy syncPolicy = policyNativeIdValidation(sourceSystem, policyStrRes);
String policyName = syncPolicy.getName();
// In case of fail back we need to append _mirror name since we are starting the target FS mirror policy
if (isMirrorPolicy) {
String mirrorPolicyName = syncPolicy.getName();
mirrorPolicyName = mirrorPolicyName.concat(MIRROR_POLICY);
// call start operation on mirror policy from target system to source system
return doStartTargetMirrorPolicy(sourceSystem, policyName, targetSystem, mirrorPolicyName, completer);
} else {
// call action 'start' on source policy
return mirrorOperations.doStartReplicationPolicy(system, policyName, completer);
}
}
ServiceError serviceError = DeviceControllerErrors.isilon.unableToCreateFileShare();
return BiosCommandResult.createErrorResult(serviceError);
}
use of com.emc.storageos.db.client.model.PolicyStorageResource in project coprhd-controller by CoprHD.
the class IsilonFileStorageDevice method doApplyFileReplicationPolicy.
private BiosCommandResult doApplyFileReplicationPolicy(FilePolicy filePolicy, FileDeviceInputOutput args, FileShare fs, StorageSystem storageObj) {
IsilonApi isi = getIsilonDevice(storageObj);
FileShare targetFS = null;
String sourcePath = generatePathForPolicy(filePolicy, fs, args);
String scheduleValue = getIsilonPolicySchedule(filePolicy);
String targetPath = null;
String targetHost = null;
StorageSystem targetSystem = null;
NASServer targetNasServer = null;
if (fs.getPersonality() != null && PersonalityTypes.SOURCE.name().equalsIgnoreCase(fs.getPersonality())) {
String targetFs = fs.getMirrorfsTargets().iterator().next();
targetFS = _dbClient.queryObject(FileShare.class, URI.create(targetFs));
targetPath = generatePathForPolicy(filePolicy, targetFS, args);
// Add the suffix only for local replication policy at higher level
if (filePolicy.getFileReplicationType().equalsIgnoreCase(FileReplicationType.LOCAL.name()) && !FilePolicyApplyLevel.file_system.name().equalsIgnoreCase(filePolicy.getApplyAt())) {
targetPath = targetPath + "_localTarget";
}
// Get the target smart connect zone!!
targetHost = FileOrchestrationUtils.getTargetHostPortForReplication(_dbClient, targetFS);
targetSystem = _dbClient.queryObject(StorageSystem.class, targetFS.getStorageDevice());
if (targetFS.getVirtualNAS() != null) {
targetNasServer = _dbClient.queryObject(VirtualNAS.class, targetFS.getVirtualNAS());
}
}
IsilonApi isiApiOfTarget = getIsilonDevice(targetSystem);
String targetClusterName = isiApiOfTarget.getClusterConfig().getName();
String sourceClustername = isi.getClusterConfig().getName();
String policyName = FileOrchestrationUtils.generateNameForSyncIQPolicy(sourceClustername, targetClusterName, filePolicy, fs, args, sourcePath);
IsilonSyncPolicy isiSynIQPolicy = getEquivalentIsilonSyncIQPolicy(isi, sourcePath);
PolicyStorageResource policyStorageResource = null;
if (isiSynIQPolicy != null) {
boolean validPolicy = validateIsilonReplicationPolicy(isiSynIQPolicy, filePolicy, targetPath, targetSystem, storageObj);
if (validPolicy) {
_log.info("File Policy {} is already applied and running.", filePolicy.toString());
// Verify the policy was mapped to FileStorageResource
if (null == FileOrchestrationUtils.findPolicyStorageResourceByNativeId(_dbClient, storageObj, filePolicy, args, sourcePath)) {
_log.info("Isilon policy found for {}, creating policy storage resouce to further management", filePolicy.getFilePolicyName());
// update the policy object in DB
policyStorageResource = FileOrchestrationUtils.updatePolicyStorageResource(_dbClient, storageObj, filePolicy, args, sourcePath, isiSynIQPolicy.getName(), isiSynIQPolicy.getId(), targetSystem, targetNasServer, targetPath);
// for existing policy's on device
// label - label is generated from ViPR
policyStorageResource.setLabel(policyName);
_dbClient.updateObject(policyStorageResource);
}
return BiosCommandResult.createSuccessfulResult();
} else {
throw DeviceControllerException.exceptions.assignFilePolicyFailed(filePolicy.getFilePolicyName(), filePolicy.getApplyAt(), "File policy and Isilon syncIQ policy differs for path: " + sourcePath);
}
} else {
IsilonSyncPolicy policy = new IsilonSyncPolicy(policyName, sourcePath, targetPath, targetHost, IsilonSyncPolicy.Action.sync);
IsilonSyncPolicy8Above policycopy = new IsilonSyncPolicy8Above();
if (scheduleValue != null && !scheduleValue.isEmpty()) {
policy.setSchedule(scheduleValue);
}
if (filePolicy.getFilePolicyDescription() != null) {
policy.setDescription(filePolicy.getFilePolicyDescription());
}
if (filePolicy.getNumWorkerThreads() != null && filePolicy.getNumWorkerThreads() > 0) {
policy.setWorkersPerNode(filePolicy.getNumWorkerThreads().intValue());
}
policy.setEnabled(true);
String policyId = null;
if (VersionChecker.verifyVersionDetails(ONEFS_V8, storageObj.getFirmwareVersion()) >= 0) {
if (filePolicy.getPriority() != null) {
policycopy = policycopy.copy(policy);
policycopy.setPriority(FilePolicyPriority.valueOf(filePolicy.getPriority()).ordinal());
}
policyId = isi.createReplicationPolicy8above(policycopy);
} else {
policyId = isi.createReplicationPolicy(policy);
}
if (policyId != null) {
_log.info("Isilon File Policy {} created successfully with id {}", policyName, policyId);
// update the policy object in DB
FileOrchestrationUtils.updatePolicyStorageResource(_dbClient, storageObj, filePolicy, args, sourcePath, policyName, policyId, targetSystem, targetNasServer, targetPath);
return BiosCommandResult.createSuccessfulResult();
}
}
return BiosCommandResult.createSuccessfulResult();
}
use of com.emc.storageos.db.client.model.PolicyStorageResource 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;
}
Aggregations