Search in sources :

Example 36 with TaskResourceRep

use of com.emc.storageos.model.TaskResourceRep in project coprhd-controller by CoprHD.

the class FileMirrorServiceApiImpl method failFileShareCreateRequest.

private void failFileShareCreateRequest(String task, TaskList taskList, List<FileShare> preparedFileShares, String errorMsg) {
    String errorMessage = String.format("Controller error: %s", errorMsg);
    for (TaskResourceRep fileShareTask : taskList.getTaskList()) {
        fileShareTask.setState(Operation.Status.error.name());
        fileShareTask.setMessage(errorMessage);
        Operation statusUpdate = new Operation(Operation.Status.error.name(), errorMessage);
        _dbClient.updateTaskOpStatus(FileShare.class, fileShareTask.getResource().getId(), task, statusUpdate);
    }
    for (FileShare fileShare : preparedFileShares) {
        fileShare.setInactive(true);
        _dbClient.updateObject(fileShare);
    }
}
Also used : TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Operation(com.emc.storageos.db.client.model.Operation) FileShare(com.emc.storageos.db.client.model.FileShare)

Example 37 with TaskResourceRep

use of com.emc.storageos.model.TaskResourceRep in project coprhd-controller by CoprHD.

the class FilePolicyService method assignFilePolicyToProjects.

/**
 * Assign policy at project level
 *
 * @param param
 * @param filepolicy
 */
private TaskResourceRep assignFilePolicyToProjects(FilePolicyAssignParam param, FilePolicy filePolicy) {
    StringBuilder errorMsg = new StringBuilder();
    StringBuilder recommendationErrorMsg = new StringBuilder();
    ArgValidator.checkFieldNotNull(param.getProjectAssignParams(), "project_assign_param");
    ArgValidator.checkFieldUriType(param.getProjectAssignParams().getVpool(), VirtualPool.class, "vpool");
    URI vpoolURI = param.getProjectAssignParams().getVpool();
    VirtualPool vpool = null;
    if (NullColumnValueGetter.isNullURI(filePolicy.getFilePolicyVpool())) {
        ArgValidator.checkFieldUriType(vpoolURI, VirtualPool.class, "vpool");
        vpool = _permissionsHelper.getObjectById(vpoolURI, VirtualPool.class);
        ArgValidator.checkEntity(vpool, vpoolURI, false);
        // Check if the vpool supports provided policy type..
        FilePolicyServiceUtils.validateVpoolSupportPolicyType(filePolicy, vpool);
        // Check if the vpool supports policy at project level..
        if (!vpool.getAllowFilePolicyAtProjectLevel()) {
            errorMsg.append("Provided vpool :" + vpool.getLabel() + " doesn't support policy at project level");
            _log.error(errorMsg.toString());
            throw APIException.badRequests.invalidFilePolicyAssignParam(filePolicy.getFilePolicyName(), errorMsg.toString());
        }
    } else if (vpoolURI != null) {
        vpool = _dbClient.queryObject(VirtualPool.class, filePolicy.getFilePolicyVpool());
        if (!vpoolURI.equals(filePolicy.getFilePolicyVpool())) {
            errorMsg.append("File policy: " + filePolicy.getFilePolicyName() + " is already assigned at project level under the vpool: " + vpool.getLabel());
            _log.error(errorMsg.toString());
            throw APIException.badRequests.invalidFilePolicyAssignParam(filePolicy.getFilePolicyName(), errorMsg.toString());
        }
    }
    ArgValidator.checkFieldNotEmpty(param.getProjectAssignParams().getAssigntoProjects(), "assign_to_projects");
    Set<URI> projectURIs = param.getProjectAssignParams().getAssigntoProjects();
    List<URI> filteredProjectURIs = new ArrayList<URI>();
    for (URI projectURI : projectURIs) {
        ArgValidator.checkFieldUriType(projectURI, Project.class, "project");
        Project project = _permissionsHelper.getObjectById(projectURI, Project.class);
        ArgValidator.checkEntity(project, projectURI, false);
        if (filePolicy.getAssignedResources() != null && filePolicy.getAssignedResources().contains(project.getId().toString())) {
            _log.info("Policy {} is already assigned to project {} ", filePolicy.getFilePolicyName(), project.getLabel());
            continue;
        }
        // only single replication policy per vpool-project combination.
        if (filePolicy.getFilePolicyType().equalsIgnoreCase(FilePolicyType.file_replication.name()) && FilePolicyServiceUtils.projectHasReplicationPolicy(_dbClient, projectURI, vpool.getId())) {
            errorMsg.append("Virtual pool " + vpool.getLabel() + " project " + project.getLabel() + "pair is already assigned with replication policy.");
            _log.error(errorMsg.toString());
            throw APIException.badRequests.invalidFilePolicyAssignParam(filePolicy.getFilePolicyName(), errorMsg.toString());
        }
        if (filePolicy.getFilePolicyType().equalsIgnoreCase(FilePolicyType.file_snapshot.name()) && FilePolicyServiceUtils.projectHasSnapshotPolicyWithSameSchedule(_dbClient, projectURI, vpool.getId(), filePolicy)) {
            errorMsg.append("Snapshot policy with similar schedule is already present on project " + project.getLabel());
            _log.error(errorMsg.toString());
            throw APIException.badRequests.invalidFilePolicyAssignParam(filePolicy.getFilePolicyName(), errorMsg.toString());
        }
        filteredProjectURIs.add(projectURI);
    }
    if (param.getApplyOnTargetSite() != null) {
        filePolicy.setApplyOnTargetSite(param.getApplyOnTargetSite());
    }
    // Verify the virtual pool has storage pools!!!
    List<URI> storageSystems = getAssociatedStorageSystemsByVPool(vpool);
    if (storageSystems == null || storageSystems.isEmpty()) {
        String errorMessage = "No matching storage pools exists for given vpools ";
        _log.error(errorMessage);
        throw APIException.badRequests.noStoragePoolsExists(vpool.getLabel());
    }
    String task = UUID.randomUUID().toString();
    TaskResourceRep taskResponse = createAssignFilePolicyTask(filePolicy, task);
    FileServiceApi fileServiceApi = getDefaultFileServiceApi();
    FilePolicyType policyType = FilePolicyType.valueOf(filePolicy.getFilePolicyType());
    switch(policyType) {
        case file_snapshot:
            Map<URI, List<URI>> vpoolToStorageSystemMap = new HashMap<URI, List<URI>>();
            vpoolToStorageSystemMap.put(vpoolURI, getAssociatedStorageSystemsByVPool(vpool));
            AssignFileSnapshotPolicyToProjectSchedulingThread.executeApiTask(this, _asyncTaskService.getExecutorService(), _dbClient, filePolicy.getId(), vpoolToStorageSystemMap, filteredProjectURIs, fileServiceApi, taskResponse, task);
            break;
        case file_replication:
            if (filteredProjectURIs.isEmpty()) {
                throw APIException.badRequests.invalidFilePolicyAssignParam(filePolicy.getFilePolicyName(), "No projects to assign to policy.");
            }
            // update replication topology info
            updateFileReplicationTopologyInfo(param, filePolicy);
            List<URI> validRecommendationProjects = new ArrayList<URI>();
            List<FileStorageSystemAssociation> associations = new ArrayList<FileStorageSystemAssociation>();
            VirtualPoolCapabilityValuesWrapper capabilities = new VirtualPoolCapabilityValuesWrapper();
            StringSet sourceVArraysSet = getSourceVArraySet(vpool, filePolicy);
            updatePolicyCapabilities(_dbClient, sourceVArraysSet, vpool, filePolicy, capabilities, errorMsg);
            // Replication policy has to be created on each applicable source storage system!!
            if (storageSystems != null && !storageSystems.isEmpty()) {
                for (Iterator<String> iterator = sourceVArraysSet.iterator(); iterator.hasNext(); ) {
                    String vArrayURI = iterator.next();
                    for (URI projectURI : filteredProjectURIs) {
                        List<FileStorageSystemAssociation> projectAssociations = new ArrayList<FileStorageSystemAssociation>();
                        Project project = _dbClient.queryObject(Project.class, projectURI);
                        VirtualArray srcVarray = _dbClient.queryObject(VirtualArray.class, URI.create(vArrayURI));
                        for (URI storageSystem : storageSystems) {
                            capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_PROTECTION_SOURCE_STORAGE_SYSTEM, storageSystem);
                            try {
                                List<FileRecommendation> newRecs = _filePlacementManager.getRecommendationsForFileCreateRequest(srcVarray, project, vpool, capabilities);
                                if (newRecs != null && !newRecs.isEmpty()) {
                                    projectAssociations.addAll(convertRecommendationsToStorageSystemAssociations(newRecs, filePolicy.getApplyAt(), vpool.getId(), projectURI));
                                }
                            } catch (Exception ex) {
                                _log.error("No recommendations found for storage system {} and virtualArray {} with error {} ", storageSystem, srcVarray.getLabel(), ex.getMessage());
                                if (ex.getMessage() != null) {
                                    recommendationErrorMsg.append(ex.getMessage());
                                }
                                // Continue to get the recommedations for next storage system!!
                                continue;
                            }
                        }
                        if (!projectAssociations.isEmpty()) {
                            associations.addAll(projectAssociations);
                            validRecommendationProjects.add(projectURI);
                        }
                    }
                }
            } else {
                String errorMessage = "No matching storage pools exists for vpool " + vpool.getLabel();
                _log.error(errorMessage);
                recommendationErrorMsg.append(errorMessage);
            }
            // Throw an exception!!
            if (associations == null || associations.isEmpty()) {
                // If no other resources are assigned to replication policy
                // Remove the replication topology from the policy
                FileOrchestrationUtils.removeTopologyInfo(filePolicy, _dbClient);
                _log.error("No matching storage pools recommendations found for policy {} with due to {}", filePolicy.getFilePolicyName(), recommendationErrorMsg.toString());
                throw APIException.badRequests.noFileStorageRecommendationsFound(filePolicy.getFilePolicyName());
            }
            fileServiceApi.assignFileReplicationPolicyToProjects(associations, vpoolURI, validRecommendationProjects, filePolicy.getId(), task);
            break;
        default:
            break;
    }
    auditOp(OperationTypeEnum.ASSIGN_FILE_POLICY, true, AuditLogManager.AUDITOP_BEGIN, filePolicy.getLabel());
    if (taskResponse != null) {
        // As the action done by system admin
        // Set system uri as task's tenant!!!
        Task taskObj = _dbClient.queryObject(Task.class, taskResponse.getId());
        StorageOSUser user = getUserFromContext();
        URI userTenantUri = URI.create(user.getTenantId());
        FilePolicyServiceUtils.updateTaskTenant(_dbClient, filePolicy, "assign", taskObj, userTenantUri);
    }
    return taskResponse;
}
Also used : VirtualPoolCapabilityValuesWrapper(com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) Task(com.emc.storageos.db.client.model.Task) TaskMapper.toTask(com.emc.storageos.api.mapper.TaskMapper.toTask) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) FileStorageSystemAssociation(com.emc.storageos.fileorchestrationcontroller.FileStorageSystemAssociation) FilePolicyType(com.emc.storageos.db.client.model.FilePolicy.FilePolicyType) FileRecommendation(com.emc.storageos.api.service.impl.placement.FileRecommendation) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) StringSet(com.emc.storageos.db.client.model.StringSet) List(java.util.List) ArrayList(java.util.ArrayList) BulkList(com.emc.storageos.api.service.impl.response.BulkList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) Project(com.emc.storageos.db.client.model.Project)

Example 38 with TaskResourceRep

use of com.emc.storageos.model.TaskResourceRep in project coprhd-controller by CoprHD.

the class FilePolicyService method assignFilePolicyToVpools.

/**
 * Assigning policy at vpool level
 *
 * @param param
 * @param filepolicy
 */
private TaskResourceRep assignFilePolicyToVpools(FilePolicyAssignParam param, FilePolicy filePolicy) {
    StringBuilder errorMsg = new StringBuilder();
    StringBuilder recommendationErrorMsg = new StringBuilder();
    ArgValidator.checkFieldNotNull(param.getVpoolAssignParams(), "vpool_assign_param");
    // Policy has to be applied on specified file vpools..
    ArgValidator.checkFieldNotEmpty(param.getVpoolAssignParams().getAssigntoVpools(), "assign_to_vpools");
    Set<URI> vpoolURIs = param.getVpoolAssignParams().getAssigntoVpools();
    Map<URI, List<URI>> vpoolToStorageSystemMap = new HashMap<URI, List<URI>>();
    List<URI> filteredVpoolURIs = new ArrayList<URI>();
    StringBuffer vPoolWithNoStoragePools = new StringBuffer();
    for (URI vpoolURI : vpoolURIs) {
        ArgValidator.checkFieldUriType(vpoolURI, VirtualPool.class, "vpool");
        VirtualPool virtualPool = _permissionsHelper.getObjectById(vpoolURI, VirtualPool.class);
        ArgValidator.checkEntity(virtualPool, vpoolURI, false);
        if (filePolicy.getAssignedResources() != null && filePolicy.getAssignedResources().contains(virtualPool.getId().toString())) {
            _log.info("File policy: {} has already been assigned to vpool: {} ", filePolicy.getFilePolicyName(), virtualPool.getLabel());
            continue;
        }
        // only single replication policy per vpool.
        if (filePolicy.getFilePolicyType().equalsIgnoreCase(FilePolicyType.file_replication.name()) && (FilePolicyServiceUtils.vPoolHasReplicationPolicy(_dbClient, vpoolURI) || FilePolicyServiceUtils.vPoolHasReplicationPolicyAtProjectLevel(_dbClient, vpoolURI))) {
            errorMsg.append("Provided vpool : " + virtualPool.getLabel() + " already assigned with replication policy");
            _log.error(errorMsg.toString());
            throw APIException.badRequests.invalidFilePolicyAssignParam(filePolicy.getFilePolicyName(), errorMsg.toString());
        }
        if (filePolicy.getFilePolicyType().equalsIgnoreCase(FilePolicyType.file_snapshot.name()) && FilePolicyServiceUtils.vPoolHasSnapshotPolicyWithSameSchedule(_dbClient, vpoolURI, filePolicy)) {
            errorMsg.append("Snapshot policy with similar schedule is already present on vpool " + virtualPool.getLabel());
            _log.error(errorMsg.toString());
            throw APIException.badRequests.invalidFilePolicyAssignParam(filePolicy.getFilePolicyName(), errorMsg.toString());
        }
        FilePolicyServiceUtils.validateVpoolSupportPolicyType(filePolicy, virtualPool);
        List<URI> storageSystems = getAssociatedStorageSystemsByVPool(virtualPool);
        if (storageSystems != null && !storageSystems.isEmpty()) {
            vpoolToStorageSystemMap.put(vpoolURI, storageSystems);
            filteredVpoolURIs.add(vpoolURI);
        } else {
            vPoolWithNoStoragePools.append(virtualPool.getLabel()).append(",");
        }
    }
    if (filteredVpoolURIs.isEmpty()) {
        String errorMessage = "No matching storage pools exists for given vpools ";
        _log.error(errorMessage);
        throw APIException.badRequests.noStoragePoolsExists(vPoolWithNoStoragePools.toString());
    }
    if (param.getApplyOnTargetSite() != null) {
        filePolicy.setApplyOnTargetSite(param.getApplyOnTargetSite());
    }
    FileServiceApi fileServiceApi = getDefaultFileServiceApi();
    FilePolicyType policyType = FilePolicyType.valueOf(filePolicy.getFilePolicyType());
    String task = UUID.randomUUID().toString();
    TaskResourceRep taskResponse = null;
    switch(policyType) {
        case file_snapshot:
            taskResponse = createAssignFilePolicyTask(filePolicy, task);
            AssignFileSnapshotPolicyToVpoolSchedulingThread.executeApiTask(this, _asyncTaskService.getExecutorService(), _dbClient, filePolicy.getId(), vpoolToStorageSystemMap, fileServiceApi, taskResponse, task);
            break;
        case file_replication:
            // update replication topology info
            updateFileReplicationTopologyInfo(param, filePolicy);
            List<URI> validRecommendationVpools = new ArrayList<URI>();
            List<FileStorageSystemAssociation> associations = new ArrayList<FileStorageSystemAssociation>();
            for (URI vpoolURI : filteredVpoolURIs) {
                VirtualPool vpool = _permissionsHelper.getObjectById(vpoolURI, VirtualPool.class);
                StringSet sourceVArraysSet = getSourceVArraySet(vpool, filePolicy);
                VirtualPoolCapabilityValuesWrapper capabilities = new VirtualPoolCapabilityValuesWrapper();
                updatePolicyCapabilities(_dbClient, sourceVArraysSet, vpool, filePolicy, capabilities, errorMsg);
                // Replication policy has to be created on each applicable source storage system!!
                List<URI> storageSystems = getAssociatedStorageSystemsByVPool(vpool);
                if (storageSystems != null && !storageSystems.isEmpty()) {
                    List<FileStorageSystemAssociation> vpoolAssociations = new ArrayList<FileStorageSystemAssociation>();
                    for (URI storageSystem : storageSystems) {
                        capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_PROTECTION_SOURCE_STORAGE_SYSTEM, storageSystem);
                        for (Iterator<String> iterator = sourceVArraysSet.iterator(); iterator.hasNext(); ) {
                            String vArrayURI = iterator.next();
                            VirtualArray srcVarray = _dbClient.queryObject(VirtualArray.class, URI.create(vArrayURI));
                            try {
                                List<FileRecommendation> newRecs = _filePlacementManager.getRecommendationsForFileCreateRequest(srcVarray, null, vpool, capabilities);
                                if (newRecs != null && !newRecs.isEmpty()) {
                                    vpoolAssociations.addAll(convertRecommendationsToStorageSystemAssociations(newRecs, filePolicy.getApplyAt(), vpool.getId(), null));
                                }
                            } catch (Exception ex) {
                                _log.error("No recommendations found for storage system {} and virtualArray {} with error {} ", storageSystem, srcVarray.getLabel(), ex.getMessage());
                                if (ex.getMessage() != null) {
                                    recommendationErrorMsg.append(ex.getMessage());
                                }
                                // Continue to get the recommendations for next storage system!!
                                continue;
                            }
                        }
                    }
                    if (!vpoolAssociations.isEmpty()) {
                        validRecommendationVpools.add(vpoolURI);
                        associations.addAll(vpoolAssociations);
                    }
                } else {
                    String errorMessage = "No matching storage pools exists for vpool " + vpool.getLabel();
                    _log.error(errorMessage);
                    recommendationErrorMsg.append(errorMessage);
                }
            }
            // Throw an exception!!
            if (associations == null || associations.isEmpty()) {
                // If no other resources are assigned to replication policy
                // Remove the replication topology from the policy
                FileOrchestrationUtils.removeTopologyInfo(filePolicy, _dbClient);
                _log.error("No matching storage pools recommendations found for policy {} with due to {}", filePolicy.getFilePolicyName(), recommendationErrorMsg.toString());
                throw APIException.badRequests.noFileStorageRecommendationsFound(filePolicy.getFilePolicyName());
            }
            taskResponse = createAssignFilePolicyTask(filePolicy, task);
            fileServiceApi.assignFileReplicationPolicyToVirtualPools(associations, validRecommendationVpools, filePolicy.getId(), task);
            break;
        default:
            break;
    }
    auditOp(OperationTypeEnum.ASSIGN_FILE_POLICY, true, AuditLogManager.AUDITOP_BEGIN, filePolicy.getLabel());
    if (taskResponse != null) {
        // As the action done by system admin
        // Set system uri as task's tenant!!!
        Task taskObj = _dbClient.queryObject(Task.class, taskResponse.getId());
        StorageOSUser user = getUserFromContext();
        URI userTenantUri = URI.create(user.getTenantId());
        FilePolicyServiceUtils.updateTaskTenant(_dbClient, filePolicy, "assign", taskObj, userTenantUri);
    }
    return taskResponse;
}
Also used : VirtualPoolCapabilityValuesWrapper(com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) Task(com.emc.storageos.db.client.model.Task) TaskMapper.toTask(com.emc.storageos.api.mapper.TaskMapper.toTask) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) FileStorageSystemAssociation(com.emc.storageos.fileorchestrationcontroller.FileStorageSystemAssociation) FilePolicyType(com.emc.storageos.db.client.model.FilePolicy.FilePolicyType) FileRecommendation(com.emc.storageos.api.service.impl.placement.FileRecommendation) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) StringSet(com.emc.storageos.db.client.model.StringSet) List(java.util.List) ArrayList(java.util.ArrayList) BulkList(com.emc.storageos.api.service.impl.response.BulkList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException)

Example 39 with TaskResourceRep

use of com.emc.storageos.model.TaskResourceRep in project coprhd-controller by CoprHD.

the class CreateFileSystemSchedulingThread method run.

@Override
public void run() {
    _log.info("Starting scheduling placement thread for task {}", task);
    try {
        // Call out placementManager to get the recommendation for placement.
        List recommendations = this.fileService._filePlacementManager.getRecommendationsForFileCreateRequest(varray, project, vpool, capabilities);
        if (recommendations == null || recommendations.isEmpty()) {
            throw APIException.badRequests.noMatchingStoragePoolsForVpoolAndVarray(vpool.getLabel(), varray.getLabel());
        } else {
            // Call out to the respective file service implementation to prepare
            // and create the fileshares based on the recommendations.
            fileServiceImpl.createFileSystems(param, project, varray, vpool, tenantOrg, flags, recommendations, taskList, task, capabilities);
        }
    } catch (Exception ex) {
        for (TaskResourceRep taskObj : taskList.getTaskList()) {
            if (ex instanceof ServiceCoded) {
                this.fileService._dbClient.error(FileShare.class, taskObj.getResource().getId(), taskObj.getOpId(), (ServiceCoded) ex);
            } else {
                this.fileService._dbClient.error(FileShare.class, taskObj.getResource().getId(), taskObj.getOpId(), InternalServerErrorException.internalServerErrors.unexpectedErrorVolumePlacement(ex));
            }
            _log.error(ex.getMessage(), ex);
            taskObj.setMessage(ex.getMessage());
            // Set the fileshare to inactive
            FileShare file = this.fileService._dbClient.queryObject(FileShare.class, taskObj.getResource().getId());
            file.setInactive(true);
            this.fileService._dbClient.updateObject(file);
        }
    }
    _log.info("Ending scheduling/placement thread...");
}
Also used : ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) List(java.util.List) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)

Example 40 with TaskResourceRep

use of com.emc.storageos.model.TaskResourceRep in project coprhd-controller by CoprHD.

the class EventService method executeEventMethod.

/**
 * Executes an actionable event method
 *
 * @param event the event to execute
 * @param approve if true, the action is to approve, if false the action is to decline
 * @return list of tasks
 */
public TaskList executeEventMethod(ActionableEvent event, boolean approve) {
    TaskList taskList = new TaskList();
    byte[] method = approve ? event.getApproveMethod() : event.getDeclineMethod();
    String eventStatus = approve ? ActionableEvent.Status.approved.name() : ActionableEvent.Status.declined.name();
    event.setEventExecutionTime(Calendar.getInstance());
    event.setApproveDetails(new StringSet(getEventDetails(event, true)));
    event.setDeclineDetails(new StringSet(getEventDetails(event, false)));
    if (method == null || method.length == 0) {
        _log.info("Method is null or empty for event " + event.getId());
        event.setEventStatus(eventStatus);
        _dbClient.updateObject(event);
        return taskList;
    }
    ActionableEvent.Method eventMethod = ActionableEvent.Method.deserialize(method);
    if (eventMethod == null) {
        _log.info("Event method is null or empty for event " + event.getId());
        event.setEventStatus(eventStatus);
        _dbClient.updateObject(event);
        return taskList;
    }
    try {
        Method classMethod = getMethod(ActionableEventExecutor.class, eventMethod.getMethodName());
        ComputeSystemController controller = getController(ComputeSystemController.class, null);
        ActionableEventExecutor executor = new ActionableEventExecutor(_dbClient, controller);
        Object[] parameters = Arrays.copyOf(eventMethod.getArgs(), eventMethod.getArgs().length + 1);
        parameters[parameters.length - 1] = event.getId();
        event.setEventStatus(eventStatus);
        _dbClient.updateObject(event);
        TaskResourceRep result = (TaskResourceRep) classMethod.invoke(executor, parameters);
        if (result != null && result.getId() != null) {
            Collection<String> taskCollection = Lists.newArrayList(result.getId().toString());
            ActionableEvent updatedEvent = _dbClient.queryObject(ActionableEvent.class, event.getId());
            updatedEvent.setTaskIds(new StringSet(taskCollection));
            _dbClient.updateObject(updatedEvent);
        }
        taskList.addTask(result);
        return taskList;
    } catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        _log.error(e.getMessage(), e.getCause());
        throw APIException.badRequests.errorInvokingEventMethod(event.getId(), eventMethod.getMethodName());
    }
}
Also used : ActionableEvent(com.emc.storageos.db.client.model.ActionableEvent) TaskList(com.emc.storageos.model.TaskList) ComputeSystemController(com.emc.storageos.computesystemcontroller.ComputeSystemController) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) StringSet(com.emc.storageos.db.client.model.StringSet) DataObject(com.emc.storageos.db.client.model.DataObject)

Aggregations

TaskResourceRep (com.emc.storageos.model.TaskResourceRep)160 URI (java.net.URI)85 TaskList (com.emc.storageos.model.TaskList)82 Operation (com.emc.storageos.db.client.model.Operation)68 Produces (javax.ws.rs.Produces)59 ArrayList (java.util.ArrayList)56 Volume (com.emc.storageos.db.client.model.Volume)55 Path (javax.ws.rs.Path)54 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)53 POST (javax.ws.rs.POST)50 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)49 Consumes (javax.ws.rs.Consumes)36 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)35 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)32 NamedURI (com.emc.storageos.db.client.model.NamedURI)30 NullColumnValueGetter.isNullURI (com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI)23 Project (com.emc.storageos.db.client.model.Project)20 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)18 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)17 Copy (com.emc.storageos.model.block.Copy)17