use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.
the class FileVirtualPoolService method updateFileVirtualPool.
/**
* Update File VirtualPool only allows if there are no resources associated and
* list of attributes changed not changed.
*
* List of attributes can updated if it satisfies above constraint:
* assignedStoragePools & useMatchedStoragePools flag.
*
* @param param
* VirtualPool parameters
* @brief Update description of file store VirtualPool
* @return VirtualPool details
*/
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public FileVirtualPoolRestRep updateFileVirtualPool(@PathParam("id") URI id, FileVirtualPoolUpdateParam param) {
VirtualPool cos = null;
ArgValidator.checkFieldUriType(id, VirtualPool.class, "id");
cos = _dbClient.queryObject(VirtualPool.class, id);
ArgValidator.checkEntity(cos, id, isIdEmbeddedInURL(id));
if (!cos.getType().equals(VirtualPool.Type.file.name())) {
throw APIException.badRequests.unexpectedValueForProperty("VPool type", VirtualPool.Type.file.name(), cos.getType());
}
VirtualPoolUtil.validateFileVirtualPoolUpdateParams(cos, param, _dbClient);
URIQueryResultList resultList = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getVirtualPoolFileshareConstraint(id), resultList);
for (Iterator<URI> fileShareItr = resultList.iterator(); fileShareItr.hasNext(); ) {
FileShare fileShare = _dbClient.queryObject(FileShare.class, fileShareItr.next());
if (!fileShare.getInactive() && checkAttributeValuesChanged(param, cos)) {
throw APIException.badRequests.vPoolUpdateNotAllowed("FileShares");
}
}
if (param.getProtection() != null && checkProtectionChanged(cos, param.getProtection())) {
// need to iterate over all the policy and see if policy is associated with vpool .
// if policy is associated with vpool we can not modify the protection attribute
List<URI> filePolicyList = _dbClient.queryByType(FilePolicy.class, true);
for (URI filePolicy : filePolicyList) {
FilePolicy policyObj = _dbClient.queryObject(FilePolicy.class, filePolicy);
if (policyObj.getAssignedResources() != null) {
if (policyObj.getApplyAt().equalsIgnoreCase(FilePolicyApplyLevel.project.name()) && (policyObj.getFilePolicyVpool() != null)) {
if (policyObj.getFilePolicyVpool().toString().equalsIgnoreCase(id.toString())) {
checkProtectAttributeAginstPolicy(param.getProtection(), policyObj);
}
} else if (policyObj.getApplyAt().equalsIgnoreCase(FilePolicyApplyLevel.vpool.name())) {
StringSet assignedResources = policyObj.getAssignedResources();
if (assignedResources.contains(id.toString())) {
checkProtectAttributeAginstPolicy(param.getProtection(), policyObj);
}
}
}
}
}
// set common update VirtualPool Params here.
populateCommonVirtualPoolUpdateParams(cos, param);
if (null != param.getSystemType()) {
if (cos.getArrayInfo() != null && cos.getArrayInfo().containsKey(VirtualPoolCapabilityValuesWrapper.SYSTEM_TYPE)) {
for (String systemType : cos.getArrayInfo().get(VirtualPoolCapabilityValuesWrapper.SYSTEM_TYPE)) {
cos.getArrayInfo().remove(VirtualPoolCapabilityValuesWrapper.SYSTEM_TYPE, systemType);
}
}
if (!(VirtualPool.SystemType.NONE.name().equalsIgnoreCase(param.getSystemType()) || VirtualPool.SystemType.isFileTypeSystem(param.getSystemType()))) {
throw APIException.badRequests.invalidSystemType("File");
}
if (cos.getArrayInfo() == null) {
cos.setArrayInfo(new StringSetMap());
}
cos.getArrayInfo().put(VirtualPoolCapabilityValuesWrapper.SYSTEM_TYPE, param.getSystemType());
}
// Update file protection parameters!!!
if (null != param.getProtection()) {
updateFileProtectionParamsForVirtualPool(cos, param.getProtection());
}
if (null != param.getLongTermRetention()) {
cos.setLongTermRetention(param.getLongTermRetention());
}
StringBuffer errorMessage = new StringBuffer();
// invokes implicit pool matching algorithm.
ImplicitPoolMatcher.matchVirtualPoolWithAllStoragePools(cos, _dbClient, _coordinator, errorMessage);
if (null != cos.getMatchedStoragePools() || null != cos.getInvalidMatchedPools()) {
ImplicitUnManagedObjectsMatcher.matchVirtualPoolsWithUnManagedFileSystems(cos, _dbClient);
}
_dbClient.updateObject(cos);
recordOperation(OperationTypeEnum.UPDATE_VPOOL, VPOOL_UPDATED_DESCRIPTION, cos);
return toFileVirtualPool(cos);
}
use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.
the class FilePolicyService method getAclsOnPolicy.
protected ACLAssignments getAclsOnPolicy(URI id) {
FilePolicy policy = queryResource(id);
ArgValidator.checkEntityNotNull(policy, id, isIdEmbeddedInURL(id));
ACLAssignments response = new ACLAssignments();
response.setAssignments(_permissionsHelper.convertToACLEntries(policy.getAcls()));
return response;
}
use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.
the class FilePolicyService method createFileReplicationPolicy.
/**
* Validate and create replication policy.
*
* @param param
* @return
*/
private FilePolicyCreateResp createFileReplicationPolicy(FilePolicyCreateParam param) {
StringBuilder errorMsg = new StringBuilder();
FilePolicy fileReplicationPolicy = new FilePolicy();
if (param.getReplicationPolicyParams() == null) {
errorMsg.append("Required parameter replication_params was missing or empty");
_log.error("Failed to create snapshot policy due to {} ", errorMsg.toString());
throw APIException.badRequests.invalidFileReplicationPolicyParam(param.getPolicyName(), errorMsg.toString());
}
// Make sure replication type and copy mode are provided
ArgValidator.checkFieldNotNull(param.getReplicationPolicyParams().getReplicationCopyMode(), "replication_copy_mode");
ArgValidator.checkFieldNotNull(param.getReplicationPolicyParams().getReplicationType(), "replication_type");
// Validate replication policy schedule parameters
boolean isValidSchedule = FilePolicyServiceUtils.validateAndUpdatePolicyScheduleParam(param.getReplicationPolicyParams().getPolicySchedule(), fileReplicationPolicy, errorMsg);
if (!isValidSchedule && errorMsg.length() > 0) {
_log.error("Failed to create file replication policy due to {} ", errorMsg.toString());
throw APIException.badRequests.invalidFilePolicyScheduleParam(param.getPolicyName(), errorMsg.toString());
}
// validate replication type and copy mode parameters
ArgValidator.checkFieldValueFromEnum(param.getReplicationPolicyParams().getReplicationType(), "replicationType", EnumSet.allOf(FilePolicy.FileReplicationType.class));
ArgValidator.checkFieldValueFromEnum(param.getReplicationPolicyParams().getReplicationCopyMode(), "replicationCopyMode", EnumSet.allOf(FilePolicy.FileReplicationCopyMode.class));
fileReplicationPolicy.setId(URIUtil.createId(FilePolicy.class));
fileReplicationPolicy.setFilePolicyName(param.getPolicyName());
fileReplicationPolicy.setLabel(param.getPolicyName());
fileReplicationPolicy.setFilePolicyType(param.getPolicyType());
if (param.getPriority() != null) {
ArgValidator.checkFieldValueFromEnum(param.getPriority(), "priority", EnumSet.allOf(FilePolicyPriority.class));
fileReplicationPolicy.setPriority(param.getPriority());
}
fileReplicationPolicy.setNumWorkerThreads((long) param.getNumWorkerThreads());
if (param.getPolicyDescription() != null && !param.getPolicyDescription().isEmpty()) {
fileReplicationPolicy.setFilePolicyDescription(param.getPolicyDescription());
}
fileReplicationPolicy.setScheduleFrequency(param.getReplicationPolicyParams().getPolicySchedule().getScheduleFrequency());
fileReplicationPolicy.setFileReplicationType(param.getReplicationPolicyParams().getReplicationType());
fileReplicationPolicy.setFileReplicationCopyMode(param.getReplicationPolicyParams().getReplicationCopyMode());
fileReplicationPolicy.setApplyAt(param.getApplyAt());
_dbClient.createObject(fileReplicationPolicy);
_log.info("Policy {} created successfully", fileReplicationPolicy);
return new FilePolicyCreateResp(fileReplicationPolicy.getId(), toLink(ResourceTypeEnum.FILE_POLICY, fileReplicationPolicy.getId()), fileReplicationPolicy.getLabel());
}
use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.
the class FilePolicyService method queryResource.
@Override
protected FilePolicy queryResource(URI id) {
ArgValidator.checkUri(id);
FilePolicy filePolicy = _permissionsHelper.getObjectById(id, FilePolicy.class);
ArgValidator.checkEntityNotNull(filePolicy, id, isIdEmbeddedInURL(id));
return filePolicy;
}
use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.
the class FilePolicyService method unassignFilePolicy.
/**
* Unassign File Policy
*
* @param id
* of the file policy.
* @param FilePolicyUnAssignParam
* @brief Unassign file policy from vpool, project, file system
* @return TaskResourceRep
*/
@POST
@Path("/{id}/unassign-policy")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.TENANT_ADMIN })
public TaskResourceRep unassignFilePolicy(@PathParam("id") URI id, FilePolicyUnAssignParam param) {
_log.info("Unassign File Policy :{} request received.", id);
String task = UUID.randomUUID().toString();
ArgValidator.checkFieldUriType(id, FilePolicy.class, "id");
FilePolicy filepolicy = this._dbClient.queryObject(FilePolicy.class, id);
ArgValidator.checkEntity(filepolicy, id, true);
StringBuilder errorMsg = new StringBuilder();
Operation op = _dbClient.createTaskOpStatus(FilePolicy.class, filepolicy.getId(), task, ResourceOperationTypeEnum.UNASSIGN_FILE_POLICY);
op.setDescription("unassign File Policy from resources ");
// As the action done by tenant/system admin
// Set corresponding tenant uri as task's tenant!!!
Task taskObj = op.getTask(filepolicy.getId());
StorageOSUser user = getUserFromContext();
URI userTenantUri = URI.create(user.getTenantId());
FilePolicyServiceUtils.updateTaskTenant(_dbClient, filepolicy, "unassign", taskObj, userTenantUri);
if (filepolicy.getAssignedResources() == null || filepolicy.getAssignedResources().isEmpty()) {
_log.info("File Policy: " + id + " doesn't have any assigned resources.");
_dbClient.ready(FilePolicy.class, filepolicy.getId(), task);
return toTask(filepolicy, task, op);
}
ArgValidator.checkFieldNotNull(param.getUnassignfrom(), "unassign_from");
Set<URI> unassignFrom = param.getUnassignfrom();
if (unassignFrom != null) {
for (URI uri : unassignFrom) {
canUserUnAssignPolicyAtGivenLevel(filepolicy, uri);
if (!filepolicy.getAssignedResources().contains(uri.toString())) {
errorMsg.append("Provided resource URI is either being not assigned to the file policy:" + filepolicy.getId() + " or it is a invalid URI");
_log.error(errorMsg.toString());
throw APIException.badRequests.invalidFilePolicyUnAssignParam(filepolicy.getFilePolicyName(), errorMsg.toString());
}
}
}
FileOrchestrationController controller = getController(FileOrchestrationController.class, FileOrchestrationController.FILE_ORCHESTRATION_DEVICE);
try {
controller.unassignFilePolicy(filepolicy.getId(), unassignFrom, task);
auditOp(OperationTypeEnum.UNASSIGN_FILE_POLICY, true, "BEGIN", filepolicy.getId().toString(), filepolicy.getLabel());
} catch (BadRequestException e) {
op = _dbClient.error(FilePolicy.class, filepolicy.getId(), task, e);
_log.error("Error Unassigning File policy {}, {}", e.getMessage(), e);
throw e;
} catch (Exception e) {
_log.error("Error Unassigning Files Policy {}, {}", e.getMessage(), e);
throw APIException.badRequests.unableToProcessRequest(e.getMessage());
}
return toTask(filepolicy, task, op);
}
Aggregations