Search in sources :

Example 1 with ServiceState

use of cz.metacentrum.perun.controller.model.ServiceState in project perun by CESNET.

the class PropagationStatsReaderImpl method getFacilityServicesState.

@Override
public List<ServiceState> getFacilityServicesState(PerunSession sess, Facility facility) throws ServiceNotExistsException, InternalErrorException, PrivilegeException {
    if (!AuthzResolver.isAuthorized(sess, Role.FACILITYADMIN, facility)) {
        throw new PrivilegeException("getFacilityServicesState");
    }
    Map<Service, ServiceState> serviceStates = new HashMap<Service, ServiceState>();
    // fill states for all services which are currently on facility
    for (Service service : perun.getServicesManagerBl().getAssignedServices(sess, facility)) {
        serviceStates.put(service, new ServiceState(service, facility));
        try {
            // fill global allowance state based on existing exec services
            List<ExecService> execs = getGeneralServiceManager().listExecServices(sess, service.getId());
            for (ExecService ex : execs) {
                if (!ex.isEnabled())
                    serviceStates.get(service).setBlockedGlobally(true);
                // fill facility allowance state based on existing exec services
                if (getGeneralServiceManager().isExecServiceDeniedOnFacility(ex, facility))
                    serviceStates.get(service).setBlockedOnFacility(true);
            }
        } catch (EmptyResultDataAccessException ex) {
            // service has no exec services -> blocked globally
            serviceStates.get(service).setBlockedGlobally(true);
        }
        // service has destination on facility
        serviceStates.get(service).setHasDestinations(!perun.getServicesManagerBl().getDestinations(sess, service, facility).isEmpty());
    }
    // fill states for all tasks on facility
    List<Task> tasks = taskDao.listAllTasksForFacility(facility.getId());
    for (Task task : tasks) {
        Service taskService = task.getExecService().getService();
        ServiceState serviceState = serviceStates.get(taskService);
        if (serviceState == null) {
            serviceState = new ServiceState(taskService, facility);
            serviceStates.put(taskService, serviceState);
            // fill destinations if service was not assigned
            serviceStates.get(taskService).setHasDestinations(!perun.getServicesManagerBl().getDestinations(sess, taskService, facility).isEmpty());
        }
        // fill service state
        if (ExecService.ExecServiceType.GENERATE.equals(task.getExecService().getExecServiceType())) {
            serviceState.setGenTask(task);
        } else {
            serviceState.setSendTask(task);
        }
        if (!task.getExecService().isEnabled()) {
            serviceStates.get(taskService).setBlockedGlobally(true);
        }
        if (getGeneralServiceManager().isExecServiceDeniedOnFacility(task.getExecService(), facility))
            serviceStates.get(taskService).setBlockedOnFacility(true);
    }
    return new ArrayList<ServiceState>(serviceStates.values());
}
Also used : Task(cz.metacentrum.perun.taskslib.model.Task) ServiceState(cz.metacentrum.perun.controller.model.ServiceState) ExecService(cz.metacentrum.perun.taskslib.model.ExecService) ExecService(cz.metacentrum.perun.taskslib.model.ExecService) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Aggregations

ServiceState (cz.metacentrum.perun.controller.model.ServiceState)1 ExecService (cz.metacentrum.perun.taskslib.model.ExecService)1 Task (cz.metacentrum.perun.taskslib.model.Task)1 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)1