use of com.emc.storageos.isilon.restapi.IsilonSnapshotSchedule in project coprhd-controller by CoprHD.
the class IsilonFileStorageDevice method doApplyFileSnapshotPolicy.
private BiosCommandResult doApplyFileSnapshotPolicy(FilePolicy filePolicy, FileDeviceInputOutput args, FileShare fs, StorageSystem storageObj) {
IsilonApi isi = getIsilonDevice(storageObj);
String path = generatePathForPolicy(filePolicy, fs, args);
String clusterName = isi.getClusterConfig().getName();
String snapshotScheduleName = FileOrchestrationUtils.generateNameForSnapshotIQPolicy(clusterName, filePolicy, fs, args, path);
IsilonSnapshotSchedule isiSnapshotSchedule = getEquivalentIsilonSnapshotSchedule(isi, path);
if (isiSnapshotSchedule != null) {
String filePolicySnapshotSchedule = getIsilonPolicySchedule(filePolicy);
_log.info("Comparing snapshot schedule between CoprHD policy: {} and Isilon policy: {}.", filePolicySnapshotSchedule, isiSnapshotSchedule.getSchedule());
if (isiSnapshotSchedule.getSchedule() != null && isiSnapshotSchedule.getSchedule().equalsIgnoreCase(filePolicySnapshotSchedule)) {
// Verify the policy was mapped to FileStorageResource
if (null == FileOrchestrationUtils.findPolicyStorageResourceByNativeId(_dbClient, storageObj, filePolicy, args, path)) {
_log.info("Isilon snapshot policy found for {}, creating policy storage resouce to further management", filePolicy.getFilePolicyName());
PolicyStorageResource policyResource = FileOrchestrationUtils.updatePolicyStorageResource(_dbClient, storageObj, filePolicy, args, path, isiSnapshotSchedule.getName(), isiSnapshotSchedule.getId().toString(), null, null, null);
// for existing policy vipr generated label
policyResource.setLabel(filePolicySnapshotSchedule);
_dbClient.updateObject(policyResource);
_log.info("File Policy {} is already applied and running.", filePolicy.getFilePolicyName());
}
return BiosCommandResult.createSuccessfulResult();
} else {
_log.info("Snapshot schedule differs between Isilon policy and CoprHD file policy. So, create policy in Isilon...");
// Create snapshot policy.
createIsilonSnapshotPolicySchedule(storageObj, filePolicy, path, snapshotScheduleName, args, path);
return BiosCommandResult.createSuccessfulResult();
}
} else {
// Create snapshot policy.
createIsilonSnapshotPolicySchedule(storageObj, filePolicy, path, snapshotScheduleName, args, path);
return BiosCommandResult.createSuccessfulResult();
}
}
use of com.emc.storageos.isilon.restapi.IsilonSnapshotSchedule in project coprhd-controller by CoprHD.
the class IsilonFileStorageDevice method doUnassignFilePolicy.
@Override
public BiosCommandResult doUnassignFilePolicy(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
try {
IsilonApi isi = getIsilonDevice(storage);
FilePolicy filePolicy = args.getFileProtectionPolicy();
PolicyStorageResource policyResource = args.getPolicyStorageResource();
if (filePolicy.getFilePolicyType().equals(FilePolicyType.file_replication.name())) {
// Get the policy details by id
IsilonSyncPolicy isiSyncPolicy = isi.getReplicationPolicy(policyResource.getPolicyNativeId());
if (isiSyncPolicy != null) {
_log.info("deleting Isilon replication policy: {}", isiSyncPolicy.toString());
String policyName = isiSyncPolicy.getName();
JobState policyState = isiSyncPolicy.getLastJobState();
if (policyState.equals(JobState.running) || policyState.equals(JobState.paused)) {
_log.info("Canceling Replication Policy -{} because policy is in - {} state ", policyName, policyState);
// If the policy is running, Cancel the job before unassign policy!!
BiosCommandResult cmdResult = mirrorOperations.doCancelReplicationPolicy(isi, isiSyncPolicy.getName());
if (!cmdResult.isCommandSuccess()) {
return cmdResult;
} else {
// If the replication job still running through exception
isiSyncPolicy = isi.getReplicationPolicy(isiSyncPolicy.getName());
if (isiSyncPolicy.getLastJobState().equals(JobState.running)) {
ServiceError error = DeviceControllerErrors.isilon.jobFailed("Unable Stop Replication policy and policy state :" + isiSyncPolicy.getLastJobState().toString());
return BiosCommandResult.createErrorResult(error);
}
}
}
// delete replication policy using policy id
isi.deleteReplicationPolicy(isiSyncPolicy.getId());
} else {
_log.info("replication policy: {} doesn't exists on storage system", filePolicy.toString());
}
return BiosCommandResult.createSuccessfulResult();
} else if (filePolicy.getFilePolicyType().equals(FilePolicyType.file_snapshot.name())) {
IsilonSnapshotSchedule isiSchedulePolicy = getEquivalentIsilonSnapshotSchedule(isi, policyResource.getResourcePath());
if (isiSchedulePolicy != null) {
_log.info("deleting Isilon Snapshot schedule: {}", isiSchedulePolicy.toString());
isi.deleteSnapshotSchedule(policyResource.getPolicyNativeId());
} else {
_log.info("snapshot schedule: {} doesn't exists on storage system", filePolicy.toString());
}
return BiosCommandResult.createSuccessfulResult();
}
return BiosCommandResult.createSuccessfulResult();
} catch (IsilonException e) {
_log.error("unassign file policy failed.", e);
return BiosCommandResult.createErrorResult(e);
}
}
use of com.emc.storageos.isilon.restapi.IsilonSnapshotSchedule in project coprhd-controller by CoprHD.
the class IsilonFileStorageDevice method checkFilePolicyExistsOrCreate.
@Override
public BiosCommandResult checkFilePolicyExistsOrCreate(StorageSystem storageObj, FileDeviceInputOutput args) {
FilePolicy filePolicy = args.getFileProtectionPolicy();
BiosCommandResult result = null;
try {
IsilonApi isi = getIsilonDevice(storageObj);
String clusterName = isi.getClusterConfig().getName();
String filePolicyBasePath = getFilePolicyPath(storageObj, filePolicy.getApplyAt(), args);
checkAppliedResourceNamePartOfFilePolicyPath(filePolicyBasePath, filePolicy, args);
String snapshotPolicyScheduleName = FileOrchestrationUtils.generateNameForSnapshotIQPolicy(clusterName, filePolicy, null, args, filePolicyBasePath);
IsilonSnapshotSchedule isilonSnapshotSchedule = getEquivalentIsilonSnapshotSchedule(isi, filePolicyBasePath);
if (isilonSnapshotSchedule != null) {
String filePolicySnapshotSchedule = getIsilonPolicySchedule(filePolicy);
_log.info("Comparing snapshot schedule between CoprHD policy: {} and Isilon policy: {}.", filePolicySnapshotSchedule, isilonSnapshotSchedule.getSchedule());
if (isilonSnapshotSchedule.getSchedule().equalsIgnoreCase(filePolicySnapshotSchedule)) {
// Verify the policy was mapped to FileStorageResource
if (null == FileOrchestrationUtils.findPolicyStorageResourceByNativeId(_dbClient, storageObj, filePolicy, args, filePolicyBasePath)) {
_log.info("Isilon policy found for {}, creating policy storage resouce to further management", filePolicy.getFilePolicyName());
FileOrchestrationUtils.updatePolicyStorageResource(_dbClient, storageObj, filePolicy, args, filePolicyBasePath, isilonSnapshotSchedule.getName(), isilonSnapshotSchedule.getId().toString(), null, null, null);
}
result = BiosCommandResult.createSuccessfulResult();
} else {
_log.info("Snapshot schedule differs between Isilon policy and CoprHD file policy. So, create policy in Isilon...");
// Create snapshot policy.
createIsilonSnapshotPolicySchedule(storageObj, filePolicy, filePolicyBasePath, snapshotPolicyScheduleName, args, filePolicyBasePath);
result = BiosCommandResult.createSuccessfulResult();
}
} else {
// Create snapshot policy.
createIsilonSnapshotPolicySchedule(storageObj, filePolicy, filePolicyBasePath, snapshotPolicyScheduleName, args, filePolicyBasePath);
result = BiosCommandResult.createSuccessfulResult();
}
} catch (IsilonException e) {
_log.error("Assigning file policy failed.", e);
result = BiosCommandResult.createErrorResult(e);
}
return result;
}
use of com.emc.storageos.isilon.restapi.IsilonSnapshotSchedule in project coprhd-controller by CoprHD.
the class IsilonFileStorageDevice method updateStorageSystemFileSnapshotPolicy.
private BiosCommandResult updateStorageSystemFileSnapshotPolicy(IsilonApi isi, PolicyStorageResource policyRes, FilePolicy viprPolicy, FilePolicyUpdateParam policyUpdateParam) {
try {
ArrayList<IsilonSnapshotSchedule> isiSnapshotPolicies = isi.getSnapshotSchedules().getList();
IsilonSnapshotSchedule snapPolicyAtPath = null;
_log.info("Checking the right snapshotIQ policy ...");
for (IsilonSnapshotSchedule snapPolicy : isiSnapshotPolicies) {
// Hence identify the storage system policy in either way
if (snapPolicy.getPath() != null && snapPolicy.getPath().equalsIgnoreCase(policyRes.getResourcePath()) && policyRes.getPolicyNativeId() != null && (policyRes.getPolicyNativeId().equalsIgnoreCase(snapPolicy.getName()) || policyRes.getPolicyNativeId().equalsIgnoreCase(snapPolicy.getId().toString()))) {
snapPolicyAtPath = snapPolicy;
break;
}
}
if (snapPolicyAtPath != null) {
_log.info("Found SnapshotIQ policy{} for path {} ", snapPolicyAtPath.getName(), snapPolicyAtPath.getPath());
boolean bModifyPolicy = false;
// Temp policy to store modified values.
IsilonSnapshotSchedule modifiedPolicy = new IsilonSnapshotSchedule();
modifiedPolicy.setName(snapPolicyAtPath.getName());
if (policyUpdateParam.getSnapshotPolicyPrams() != null) {
FileSnapshotPolicyParam snapParam = policyUpdateParam.getSnapshotPolicyPrams();
if (snapParam.getSnapshotExpireParams() != null) {
Integer expireTime = getSnapshotExpireValue(snapParam.getSnapshotExpireParams());
if (expireTime != null && snapPolicyAtPath.getDuration() != null) {
if (snapPolicyAtPath.getDuration().intValue() != expireTime.intValue()) {
modifiedPolicy.setDuration(expireTime);
bModifyPolicy = true;
}
} else if (expireTime != null && snapPolicyAtPath.getDuration() == null) {
modifiedPolicy.setDuration(expireTime);
bModifyPolicy = true;
} else if (snapPolicyAtPath.getDuration() != null) {
modifiedPolicy.setDuration(0);
bModifyPolicy = true;
}
}
if (snapParam.getPolicySchedule() != null) {
String strSchedule = getIsilonPolicySchedule(snapParam.getPolicySchedule());
if (strSchedule != null && !strSchedule.isEmpty() && !strSchedule.equalsIgnoreCase(snapPolicyAtPath.getSchedule())) {
modifiedPolicy.setSchedule(strSchedule);
bModifyPolicy = true;
}
}
}
if (bModifyPolicy) {
isi.modifySnapshotSchedule(snapPolicyAtPath.getName(), modifiedPolicy);
// if the existing policy is modified save policy details in db
policyRes.setPolicyNativeId(snapPolicyAtPath.getId().toString());
policyRes.setName(snapPolicyAtPath.getName());
_dbClient.updateObject(policyRes);
_log.info("Modify Snapshot Policy- {} finished successfully", snapPolicyAtPath.getName());
return BiosCommandResult.createSuccessfulResult();
} else {
_log.info("No parameters changed to modify Snapshot Policy- {} finished successfully", snapPolicyAtPath.getName());
return BiosCommandResult.createSuccessfulResult();
}
} else {
_log.error("No SnapshotIQ policy found at path {} , Hence can't be MODIFIED", policyRes.getResourcePath());
ServiceError error = DeviceControllerErrors.isilon.jobFailed("Modify Snapshot policy Failed as : No SnapshotIQ policy found at given path.");
return BiosCommandResult.createErrorResult(error);
}
} catch (IsilonException e) {
return BiosCommandResult.createErrorResult(e);
}
}
use of com.emc.storageos.isilon.restapi.IsilonSnapshotSchedule in project coprhd-controller by CoprHD.
the class IsilonFileStorageDevice method getEquivalentIsilonSnapshotSchedule.
private static IsilonSnapshotSchedule getEquivalentIsilonSnapshotSchedule(IsilonApi isi, String path) {
IsilonSnapshotSchedule isiSchedule = null;
ArrayList<IsilonSnapshotSchedule> isiSnapshotPolicies = isi.getSnapshotSchedules().getList();
if (isiSnapshotPolicies != null && !isiSnapshotPolicies.isEmpty()) {
for (IsilonSnapshotSchedule isiSnapshotPolicy : isiSnapshotPolicies) {
if (isiSnapshotPolicy.getPath().equals(path)) {
isiSchedule = isiSnapshotPolicy;
break;
}
}
}
return isiSchedule;
}
Aggregations