Search in sources :

Example 11 with SchedulePolicy

use of com.emc.storageos.db.client.model.SchedulePolicy in project coprhd-controller by CoprHD.

the class SchedulePolicyService method updateSchedulePolicy.

/**
 * Update info for schedule policy including name, schedule, snapshot expire etc.
 *
 * @param policyId the URN of a schedule policy
 * @param param schedule policy update parameters
 * @brief Update schedule policy
 * @return No data returned in response body
 * @throws BadRequestException
 */
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.TENANT_ADMIN })
public Response updateSchedulePolicy(@PathParam("id") URI policyId, PolicyParam param) {
    // check policy
    ArgValidator.checkFieldUriType(policyId, SchedulePolicy.class, "policyId");
    // Check policy is associated with FS before update
    SchedulePolicy schedulePolicy = getPolicyById(policyId, true);
    StringSet resources = schedulePolicy.getAssignedResources();
    if (resources != null && !resources.isEmpty()) {
        _log.error("Unable to update schedule policy {} as it is already associated with resources", schedulePolicy.getPolicyName());
        throw APIException.badRequests.unableToUpdateSchedulePolicy(schedulePolicy.getPolicyName());
    }
    // check schedule policy type is valid or not
    if (!ArgValidator.isValidEnum(param.getPolicyType(), SchedulePolicyType.class)) {
        throw APIException.badRequests.invalidSchedulePolicyType(param.getPolicyType());
    }
    _log.info("Schedule policy {} update started", schedulePolicy.getPolicyName());
    if (null != param.getPolicyName() && !param.getPolicyName().isEmpty() && !schedulePolicy.getLabel().equalsIgnoreCase(param.getPolicyName())) {
        checkForDuplicateName(param.getPolicyName(), SchedulePolicy.class, schedulePolicy.getTenantOrg().getURI(), "tenantOrg", _dbClient);
        NamedURI tenant = schedulePolicy.getTenantOrg();
        if (tenant != null) {
            tenant.setName(param.getPolicyName());
            schedulePolicy.setTenantOrg(tenant);
        }
    }
    // Validate Schedule policy parameters
    StringBuilder errorMsg = new StringBuilder();
    boolean isValidSchedule = validateSchedulePolicyParam(param.getPolicySchedule(), schedulePolicy, errorMsg);
    if (!isValidSchedule && errorMsg != null && errorMsg.length() > 0) {
        _log.error("Failed to update schedule policy due to {} ", errorMsg.toString());
        throw APIException.badRequests.invalidSchedulePolicyParam(param.getPolicyName(), errorMsg.toString());
    }
    // Validate snapshot expire parameters
    boolean isValidSnapshotExpire = false;
    if (param.getSnapshotExpire() != null) {
        String expireType = param.getSnapshotExpire().getExpireType();
        if (!ArgValidator.isValidEnum(expireType, SnapshotExpireType.class)) {
            _log.error("Invalid schedule snapshot expire type {}. Valid Snapshot expire types are hours, days, weeks, months and never", expireType);
            throw APIException.badRequests.invalidScheduleSnapshotExpireType(expireType);
        }
        isValidSnapshotExpire = validateSnapshotExpireParam(param.getSnapshotExpire());
        if (!isValidSnapshotExpire) {
            int expireTime = param.getSnapshotExpire().getExpireValue();
            int minExpireTime = 2;
            int maxExpireTime = 10;
            _log.error("Invalid schedule snapshot expire time {}. Try an expire time between {} hours to {} years", expireTime, minExpireTime, maxExpireTime);
            throw APIException.badRequests.invalidScheduleSnapshotExpireValue(expireTime, minExpireTime, maxExpireTime);
        }
    } else {
        if (param.getPolicyType().equalsIgnoreCase(SchedulePolicyType.file_snapshot.toString())) {
            errorMsg.append("Required parameter snapshot_expire was missing or empty");
            _log.error("Failed to update schedule policy due to {} ", errorMsg.toString());
            throw APIException.badRequests.invalidSchedulePolicyParam(param.getPolicyName(), errorMsg.toString());
        }
    }
    if (isValidSchedule) {
        schedulePolicy.setPolicyType(param.getPolicyType());
        schedulePolicy.setLabel(param.getPolicyName());
        schedulePolicy.setPolicyName(param.getPolicyName());
        schedulePolicy.setScheduleFrequency(param.getPolicySchedule().getScheduleFrequency().toLowerCase());
        if (isValidSnapshotExpire) {
            schedulePolicy.setSnapshotExpireType(param.getSnapshotExpire().getExpireType().toLowerCase());
            if (!param.getSnapshotExpire().getExpireType().equalsIgnoreCase(SnapshotExpireType.NEVER.toString())) {
                schedulePolicy.setSnapshotExpireTime((long) param.getSnapshotExpire().getExpireValue());
            } else {
                schedulePolicy.setSnapshotExpireTime(0L);
            }
        }
        _dbClient.updateObject(schedulePolicy);
        _log.info("Schedule policy {} updated successfully", schedulePolicy.getPolicyName());
    }
    return Response.ok().build();
}
Also used : NamedURI(com.emc.storageos.db.client.model.NamedURI) StringSet(com.emc.storageos.db.client.model.StringSet) SchedulePolicyType(com.emc.storageos.db.client.model.SchedulePolicy.SchedulePolicyType) MapSchedulePolicy(com.emc.storageos.api.mapper.functions.MapSchedulePolicy) SchedulePolicy(com.emc.storageos.db.client.model.SchedulePolicy) SnapshotExpireType(com.emc.storageos.db.client.model.SchedulePolicy.SnapshotExpireType) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 12 with SchedulePolicy

use of com.emc.storageos.db.client.model.SchedulePolicy in project coprhd-controller by CoprHD.

the class FileService method getFileSystemPolicy.

/**
 * Get Policy for file system
 *
 * @param id
 *            the URN of a ViPR File system
 * @brief Show file system
 * @return File system Policy details
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/file-policies")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public FilePolicyList getFileSystemPolicy(@PathParam("id") URI id) {
    FilePolicyList fpList = new FilePolicyList();
    List<FilePolicyRestRep> fpRestList = new ArrayList<FilePolicyRestRep>();
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    FileShare fs = queryResource(id);
    StringSet fpolicies = fs.getFilePolicies();
    for (String fpolicy : fpolicies) {
        FilePolicyRestRep fpRest = new FilePolicyRestRep();
        URI fpURI = URI.create(fpolicy);
        if (fpURI != null) {
            SchedulePolicy fp = _permissionsHelper.getObjectById(fpURI, SchedulePolicy.class);
            if (fp != null) {
                ArgValidator.checkEntityNotNull(fp, fpURI, isIdEmbeddedInURL(fpURI));
                getFilePolicyRestRep(fpRest, fp, fs);
            }
        }
        fpRestList.add(fpRest);
    }
    fpList.setFilePolicies(fpRestList);
    return fpList;
}
Also used : FilePolicyList(com.emc.storageos.model.file.FilePolicyList) FilePolicyRestRep(com.emc.storageos.model.file.FilePolicyRestRep) ArrayList(java.util.ArrayList) StringSet(com.emc.storageos.db.client.model.StringSet) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) SchedulePolicy(com.emc.storageos.db.client.model.SchedulePolicy) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 13 with SchedulePolicy

use of com.emc.storageos.db.client.model.SchedulePolicy in project coprhd-controller by CoprHD.

the class FileDeviceController method recordFileDeviceOperation.

public static void recordFileDeviceOperation(DbClient dbClient, OperationTypeEnum opType, boolean opStatus, String evDesc, String extensions, Object... extParam) {
    String evType;
    if (evDesc == null || evDesc.isEmpty()) {
        evDesc = opType.getDescription();
    }
    evType = opType.getEvType(opStatus);
    String opStage = AuditLogManager.AUDITOP_END;
    _log.info("opType: {} detail: {}", opType.toString(), evType + ':' + evDesc);
    FileShare fs = null;
    Snapshot snapshotObj = null;
    QuotaDirectory quotaDirObj = null;
    if (extParam[0] instanceof Snapshot) {
        snapshotObj = (Snapshot) extParam[0];
        fs = (FileShare) extParam[1];
        recordSnapshotEvent(dbClient, snapshotObj, fs, evType, evDesc, extensions);
    } else if (extParam[0] instanceof QuotaDirectory) {
        quotaDirObj = (QuotaDirectory) extParam[0];
        fs = (FileShare) extParam[1];
        recordQuotaDirectoryEvent(dbClient, quotaDirObj, fs, evType, evDesc, extensions);
    } else if (extParam[0] instanceof FileShare) {
        fs = (FileShare) extParam[0];
        recordFsEvent(dbClient, fs, evType, evDesc, extensions);
    } else {
        _log.error("unrecognized param list");
    }
    FileSMBShare smbShare = null;
    switch(opType) {
        case CREATE_FILE_SYSTEM:
            auditFile(dbClient, opType, opStatus, opStage, fs.getLabel(), fs.getVirtualArray().toString(), (fs.getProject() != null) ? fs.getProject().toString() : null);
            break;
        case DELETE_FILE_SYSTEM:
            auditFile(dbClient, opType, opStatus, opStage, fs.getId().toString(), ((StorageSystem) extParam[1]).getId().toString());
            break;
        case DELETE_FILE_SNAPSHOT:
            auditFile(dbClient, opType, opStatus, opStage, snapshotObj.getId().toString(), ((StorageSystem) extParam[2]).getId().toString());
            break;
        case EXPORT_FILE_SYSTEM:
        case UPDATE_EXPORT_RULES_FILE_SYSTEM:
        case UPDATE_FILE_SYSTEM_SHARE_ACL:
        case UNEXPORT_FILE_SYSTEM:
            auditFile(dbClient, opType, opStatus, opStage, fs.getId().toString(), ((StorageSystem) extParam[1]).getId().toString(), extensions);
            break;
        case EXPAND_FILE_SYSTEM:
        case REDUCE_FILE_SYSTEM:
            auditFile(dbClient, opType, opStatus, opStage, fs.getId().toString(), extParam[1]);
            break;
        case CREATE_FILE_SYSTEM_SHARE:
        case DELETE_FILE_SYSTEM_SHARE:
            smbShare = (FileSMBShare) extParam[1];
            auditFile(dbClient, opType, opStatus, opStage, smbShare.getName(), smbShare.getPermissionType(), smbShare.getPermission(), smbShare.getMaxUsers(), smbShare.getDescription(), fs.getId().toString());
            break;
        case RESTORE_FILE_SNAPSHOT:
            URI snapshot = (URI) extParam[1];
            auditFile(dbClient, opType, opStatus, opStage, snapshot, fs.getId().toString());
            break;
        case CREATE_FILE_SYSTEM_SNAPSHOT:
            auditFile(dbClient, opType, opStatus, opStage, snapshotObj.getLabel(), snapshotObj.getId(), fs.getId().toString());
            break;
        case EXPORT_FILE_SNAPSHOT:
        case UPDATE_EXPORT_RULES_FILE_SNAPSHOT:
        case UPDATE_FILE_SNAPSHOT_SHARE_ACL:
        case UNEXPORT_FILE_SNAPSHOT:
            auditFile(dbClient, opType, opStatus, opStage, snapshotObj.getId().toString(), ((StorageSystem) extParam[2]).getId().toString(), extensions);
            break;
        case CREATE_FILE_SNAPSHOT_SHARE:
        case DELETE_FILE_SNAPSHOT_SHARE:
            smbShare = (FileSMBShare) extParam[2];
            auditFile(dbClient, opType, opStatus, opStage, smbShare.getName(), smbShare.getPermissionType(), smbShare.getPermission(), smbShare.getMaxUsers(), smbShare.getDescription(), snapshotObj.getId().toString());
            break;
        case CREATE_FILE_SYSTEM_QUOTA_DIR:
        case DELETE_FILE_SYSTEM_QUOTA_DIR:
        case UPDATE_FILE_SYSTEM_QUOTA_DIR:
            auditFile(dbClient, opType, opStatus, opStage, quotaDirObj.getLabel(), quotaDirObj.getId(), fs.getId().toString());
            break;
        case DELETE_FILE_SYSTEM_SHARE_ACL:
            auditFile(dbClient, opType, opStatus, opStage, fs.getId().toString(), ((StorageSystem) extParam[1]).getId().toString(), extensions);
            break;
        case DELETE_FILE_SNAPSHOT_SHARE_ACL:
            auditFile(dbClient, opType, opStatus, opStage, snapshotObj.getId().toString(), ((StorageSystem) extParam[2]).getId().toString(), extensions);
            break;
        case ASSIGN_FILE_SYSTEM_SNAPSHOT_SCHEDULE:
        case UNASSIGN_FILE_SYSTEM_SNAPSHOT_SCHEDULE:
            auditFile(dbClient, opType, opStatus, opStage, fs.getId().toString(), ((SchedulePolicy) extParam[1]).getId().toString(), extensions);
            break;
        default:
            _log.error("unrecognized fileshare operation type");
    }
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) FileShareQuotaDirectory(com.emc.storageos.volumecontroller.FileShareQuotaDirectory) FileSMBShare(com.emc.storageos.volumecontroller.FileSMBShare) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) URI(java.net.URI) SchedulePolicy(com.emc.storageos.db.client.model.SchedulePolicy) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 14 with SchedulePolicy

use of com.emc.storageos.db.client.model.SchedulePolicy in project coprhd-controller by CoprHD.

the class FileDeviceController method unassignFileSystemSnapshotPolicy.

@Override
public void unassignFileSystemSnapshotPolicy(URI storage, URI fsURI, URI policy, String opId) throws InternalException {
    ControllerUtils.setThreadLocalLogData(fsURI, opId);
    FileDeviceInputOutput args = new FileDeviceInputOutput();
    FileShare fs = null;
    try {
        fs = _dbClient.queryObject(FileShare.class, fsURI);
        SchedulePolicy fp = _dbClient.queryObject(SchedulePolicy.class, policy);
        if (fs != null && fp != null) {
            StorageSystem storageObj = _dbClient.queryObject(StorageSystem.class, storage);
            _log.info("Controller Recieved File Policy  {}", policy);
            args.addFSFileObject(fs);
            args.setFileSystemPath(fs.getPath());
            StoragePool pool = _dbClient.queryObject(StoragePool.class, fs.getPool());
            args.addStoragePool(pool);
            args.addFilePolicy(fp);
            args.setFileOperation(true);
            args.setOpId(opId);
            // Do the Operation on device.
            BiosCommandResult result = getDevice(storageObj.getSystemType()).unassignFilePolicy(storageObj, args);
            if (result.isCommandSuccess()) {
                // Update FS database
                StringSet fpolicies = fs.getFilePolicies();
                if (fpolicies != null && fpolicies.contains(policy.toString())) {
                    fpolicies.remove(policy.toString());
                    fs.setFilePolicies(fpolicies);
                }
                // Update SchedulePolicy database
                StringSet resources = fp.getAssignedResources();
                if (resources != null && resources.contains(fs.getId().toString())) {
                    resources.remove(fs.getId().toString());
                    fp.setAssignedResources(resources);
                }
            }
            if (result.getCommandPending()) {
                return;
            }
            // Audit & Update the task status
            OperationTypeEnum auditType = null;
            auditType = OperationTypeEnum.UNASSIGN_FILE_SYSTEM_SNAPSHOT_SCHEDULE;
            fs.getOpStatus().updateTaskStatus(opId, result.toOperation());
            // Monitoring - Event Processing
            String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
            recordFileDeviceOperation(_dbClient, auditType, result.isCommandSuccess(), eventMsg, args.getFileSystemPath(), fs, fp);
            _dbClient.updateObject(fs);
            _dbClient.updateObject(fp);
        } else {
            throw DeviceControllerException.exceptions.invalidObjectNull();
        }
    } catch (Exception e) {
        String[] params = { storage.toString(), fsURI.toString(), e.getMessage() };
        _log.error("Unable to Unassign policy : storage {}, FS URI {},: Error {}", params);
        updateTaskStatus(opId, fs, e);
    }
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) OperationTypeEnum(com.emc.storageos.services.OperationTypeEnum) StringSet(com.emc.storageos.db.client.model.StringSet) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) SchedulePolicy(com.emc.storageos.db.client.model.SchedulePolicy) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

SchedulePolicy (com.emc.storageos.db.client.model.SchedulePolicy)14 StringSet (com.emc.storageos.db.client.model.StringSet)8 FileShare (com.emc.storageos.db.client.model.FileShare)5 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)5 Path (javax.ws.rs.Path)5 MapSchedulePolicy (com.emc.storageos.api.mapper.functions.MapSchedulePolicy)4 NamedURI (com.emc.storageos.db.client.model.NamedURI)4 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)4 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)4 URI (java.net.URI)4 Produces (javax.ws.rs.Produces)4 ArrayList (java.util.ArrayList)3 GET (javax.ws.rs.GET)3 SchedulePolicyType (com.emc.storageos.db.client.model.SchedulePolicy.SchedulePolicyType)2 SnapshotExpireType (com.emc.storageos.db.client.model.SchedulePolicy.SnapshotExpireType)2 StoragePool (com.emc.storageos.db.client.model.StoragePool)2 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)2 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)2 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)2 IsilonApi (com.emc.storageos.isilon.restapi.IsilonApi)2