use of com.emc.storageos.db.client.model.SchedulePolicy in project coprhd-controller by CoprHD.
the class IsilonFileStorageDevice method isiDeleteSnapshotSchedules.
/**
* Deleting snapshots: - deletes snapshots of a file system
*
* @param isi
* IsilonApi object
* @param args
* FileDeviceInputOutput
* @throws IsilonException
*/
private void isiDeleteSnapshotSchedules(IsilonApi isi, FileDeviceInputOutput args) throws IsilonException {
StringSet policies = args.getFs().getFilePolicies();
for (String policy : policies) {
SchedulePolicy fp = _dbClient.queryObject(SchedulePolicy.class, URI.create(policy));
String snapshotScheduleName = fp.getPolicyName() + "_" + args.getFsName();
isi.deleteSnapshotSchedule(snapshotScheduleName);
}
}
use of com.emc.storageos.db.client.model.SchedulePolicy in project coprhd-controller by CoprHD.
the class IsilonFileStorageDevice method unassignFilePolicy.
@Deprecated
@Override
public BiosCommandResult unassignFilePolicy(StorageSystem storageObj, FileDeviceInputOutput args) {
SchedulePolicy fp = args.getFilePolicy();
String snapshotScheduleName = fp.getPolicyName() + "_" + args.getFsName();
IsilonApi isi = getIsilonDevice(storageObj);
try {
isi.deleteSnapshotSchedule(snapshotScheduleName);
} catch (IsilonException e) {
_log.error("unassign file policy failed.", e);
return BiosCommandResult.createErrorResult(e);
}
return BiosCommandResult.createSuccessfulResult();
}
use of com.emc.storageos.db.client.model.SchedulePolicy in project coprhd-controller by CoprHD.
the class FileSnapshotPolicyMigration method process.
@Override
public void process() throws MigrationCallbackException {
logger.info("File snapshot schedule policy to file policy migration START");
DbClient dbClient = getDbClient();
try {
List<URI> schedulePolicyURIs = dbClient.queryByType(SchedulePolicy.class, true);
Iterator<SchedulePolicy> schedulePolicies = dbClient.queryIterativeObjects(SchedulePolicy.class, schedulePolicyURIs, true);
List<FilePolicy> filePolicies = new ArrayList<FilePolicy>();
List<VirtualPool> modifiedVpools = new ArrayList<VirtualPool>();
while (schedulePolicies.hasNext()) {
SchedulePolicy schedulePolicy = schedulePolicies.next();
FilePolicy fileSnapshotPolicy = new FilePolicy();
VirtualPool associatedVP = new VirtualPool();
fileSnapshotPolicy.setId(URIUtil.createId(FilePolicy.class));
if (schedulePolicy.getAssignedResources() != null && !schedulePolicy.getAssignedResources().isEmpty()) {
for (String assignedResource : schedulePolicy.getAssignedResources()) {
logger.info("assigning resource to fileSnapshotPolicy from schedulePolicy : {}", schedulePolicy.getAssignedResources());
fileSnapshotPolicy.addAssignedResources(resourceURI(assignedResource));
logger.info("Assigned resources from fileSnapshotPolicy : {}", fileSnapshotPolicy.getAssignedResources());
}
}
fileSnapshotPolicy.setFilePolicyDescription("Policy created from Schedule Policy " + schedulePolicy.getLabel() + " while system upgrade");
String polName = schedulePolicy.getLabel() + "_File_Snapshot_Policy";
fileSnapshotPolicy.setLabel(polName);
fileSnapshotPolicy.setFilePolicyName(schedulePolicy.getLabel());
fileSnapshotPolicy.setFilePolicyType(FilePolicyType.file_snapshot.name());
fileSnapshotPolicy.setScheduleFrequency(schedulePolicy.getScheduleFrequency());
fileSnapshotPolicy.setScheduleRepeat(schedulePolicy.getScheduleRepeat());
fileSnapshotPolicy.setScheduleTime(schedulePolicy.getScheduleTime());
fileSnapshotPolicy.setScheduleDayOfWeek(schedulePolicy.getScheduleDayOfWeek());
fileSnapshotPolicy.setScheduleDayOfMonth(schedulePolicy.getScheduleDayOfMonth());
fileSnapshotPolicy.setSnapshotExpireTime(schedulePolicy.getSnapshotExpireTime());
fileSnapshotPolicy.setSnapshotExpireType(schedulePolicy.getSnapshotExpireType());
// snapshot policy apply at file system level
fileSnapshotPolicy.setApplyAt(FilePolicyApplyLevel.file_system.name());
if (schedulePolicy.getAssignedResources() != null && !schedulePolicy.getAssignedResources().isEmpty()) {
List<URI> fileShareURIs = getAssignedResourcesURIs(schedulePolicy.getAssignedResources());
for (URI fsURI : fileShareURIs) {
FileShare fs = dbClient.queryObject(FileShare.class, fsURI);
if (!fs.getInactive()) {
StorageSystem system = dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
updatePolicyStorageResouce(system, fileSnapshotPolicy, fs);
// Remove the existing schedule policy from fs
// add new file policy to fs!!
StringSet fsExistingPolicies = fs.getFilePolicies();
if (fsExistingPolicies != null && !fsExistingPolicies.isEmpty()) {
Set<String> snapSchedulesToRemove = new HashSet<String>();
for (String existingSnapPolicyId : fsExistingPolicies) {
if (URIUtil.isType(URI.create(existingSnapPolicyId), SchedulePolicy.class)) {
snapSchedulesToRemove.add(existingSnapPolicyId);
}
}
if (!snapSchedulesToRemove.isEmpty()) {
/*
* StringSet.removeAll() does not work if the set has only one entry.
* Hence the logic below
*/
if (fsExistingPolicies.size() == 1 && snapSchedulesToRemove.size() == 1) {
fsExistingPolicies.clear();
} else {
fsExistingPolicies.removeAll(snapSchedulesToRemove);
}
}
} else {
fsExistingPolicies = new StringSet();
}
fsExistingPolicies.add(fileSnapshotPolicy.getId().toString());
fs.setFilePolicies(fsExistingPolicies);
dbClient.updateObject(fs);
URI associatedVPId = fs.getVirtualPool();
associatedVP = dbClient.queryObject(VirtualPool.class, associatedVPId);
associatedVP.setAllowFilePolicyAtFSLevel(true);
modifiedVpools.add(associatedVP);
}
}
}
filePolicies.add(fileSnapshotPolicy);
}
// Update DB
if (!filePolicies.isEmpty()) {
logger.info("Created {} file snapshot policies", filePolicies.size());
dbClient.createObject(filePolicies);
}
if (!modifiedVpools.isEmpty()) {
logger.info("Modified {} vpools ", modifiedVpools.size());
dbClient.updateObject(modifiedVpools);
}
} catch (Exception ex) {
logger.error("Exception occured while migrating file replication policy for Virtual pools");
logger.error(ex.getMessage(), ex);
}
}
use of com.emc.storageos.db.client.model.SchedulePolicy in project coprhd-controller by CoprHD.
the class SchedulePolicyService method getPolicyById.
/**
* Get schedule policy object from id
*
* @param id the URN of a CoprHD Schedule Policy
* @return
*/
private SchedulePolicy getPolicyById(URI id, boolean checkInactive) {
if (id == null) {
return null;
}
SchedulePolicy schedulePolicy = _permissionsHelper.getObjectById(id, SchedulePolicy.class);
ArgValidator.checkEntity(schedulePolicy, id, isIdEmbeddedInURL(id));
return schedulePolicy;
}
use of com.emc.storageos.db.client.model.SchedulePolicy in project coprhd-controller by CoprHD.
the class SchedulePolicyService method getSchedulePolicy.
/**
* Get the details of a schedule policy.
*
* @param policyId the URN of a schedule policy.
*
* @brief Show schedule policy
* @return A SchedulePolicyRestRep reference specifying the data for the
* schedule policy with the passed policyId.
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN })
public SchedulePolicyRestRep getSchedulePolicy(@PathParam("id") URI policyId) {
ArgValidator.checkFieldUriType(policyId, SchedulePolicy.class, "policyId");
SchedulePolicy schedulePolicy = queryResource(policyId);
return map(schedulePolicy);
}
Aggregations