Search in sources :

Example 21 with PrivilegeException

use of cz.metacentrum.perun.core.api.exceptions.PrivilegeException in project perun by CESNET.

the class GroupsManagerEntry method addMember.

public void addMember(PerunSession sess, Group group, Member member) throws InternalErrorException, MemberNotExistsException, PrivilegeException, AlreadyMemberException, GroupNotExistsException, WrongAttributeValueException, WrongReferenceAttributeValueException, NotMemberOfParentGroupException, WrongAttributeAssignmentException, AttributeNotExistsException, ExternallyManagedException, GroupOperationsException {
    Utils.checkPerunSession(sess);
    getGroupsManagerBl().checkGroupExists(sess, group);
    getPerunBl().getMembersManagerBl().checkMemberExists(sess, member);
    // Authorization
    if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, group) && !AuthzResolver.isAuthorized(sess, Role.GROUPADMIN, group)) {
        throw new PrivilegeException(sess, "addMember");
    }
    // Check if the member and group are from the same VO
    if (member.getVoId() != (group.getVoId())) {
        throw new MembershipMismatchException("Member and group are form the different VO");
    }
    // Check if the group is externally synchronized
    Attribute attrSynchronizeEnabled = getPerunBl().getAttributesManagerBl().getAttribute(sess, group, GROUPSYNCHROENABLED_ATTRNAME);
    if (Objects.equals("true", (String) attrSynchronizeEnabled.getValue())) {
        throw new ExternallyManagedException("Adding of member is not allowed. Group is externally managed.");
    }
    getGroupsManagerBl().addMember(sess, group, member);
}
Also used : MembershipMismatchException(cz.metacentrum.perun.core.api.exceptions.MembershipMismatchException) ExternallyManagedException(cz.metacentrum.perun.core.api.exceptions.ExternallyManagedException) Attribute(cz.metacentrum.perun.core.api.Attribute) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException)

Example 22 with PrivilegeException

use of cz.metacentrum.perun.core.api.exceptions.PrivilegeException in project perun by CESNET.

the class FacilitiesManagerEntry method getBan.

public BanOnFacility getBan(PerunSession sess, int userId, int faclityId) throws InternalErrorException, BanNotExistsException, PrivilegeException, UserNotExistsException, FacilityNotExistsException {
    Utils.checkPerunSession(sess);
    User user = getPerunBl().getUsersManagerBl().getUserById(sess, userId);
    Facility facility = getPerunBl().getFacilitiesManagerBl().getFacilityById(sess, faclityId);
    // Authorization
    if (!AuthzResolver.isAuthorized(sess, Role.FACILITYADMIN, facility)) {
        throw new PrivilegeException(sess, "getBan");
    }
    return getFacilitiesManagerBl().getBan(sess, userId, faclityId);
}
Also used : User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) Facility(cz.metacentrum.perun.core.api.Facility) RichFacility(cz.metacentrum.perun.core.api.RichFacility)

Example 23 with PrivilegeException

use of cz.metacentrum.perun.core.api.exceptions.PrivilegeException in project perun by CESNET.

the class FacilitiesManagerEntry method getFacilityByName.

public Facility getFacilityByName(PerunSession sess, String name) throws InternalErrorException, FacilityNotExistsException, PrivilegeException {
    Utils.checkPerunSession(sess);
    Utils.notNull(name, "name");
    Facility facility = getFacilitiesManagerBl().getFacilityByName(sess, name);
    // Authorization
    if (!AuthzResolver.isAuthorized(sess, Role.FACILITYADMIN, facility) && !AuthzResolver.isAuthorized(sess, Role.ENGINE) && !AuthzResolver.isAuthorized(sess, Role.RPC)) {
        throw new PrivilegeException(sess, "getFacilityByName");
    }
    return facility;
}
Also used : PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) Facility(cz.metacentrum.perun.core.api.Facility) RichFacility(cz.metacentrum.perun.core.api.RichFacility)

Example 24 with PrivilegeException

use of cz.metacentrum.perun.core.api.exceptions.PrivilegeException in project perun by CESNET.

the class PropagationMaintainerImpl method rescheduleErrorTasks.

private void rescheduleErrorTasks() {
    log.info("I am gonna list tasks in ERROR and reschedule if necessary...");
    for (Task task : schedulingPool.getErrorTasks()) {
        if (task.getEndTime() == null) {
            log.error("RECOVERY FROM INCONSISTENT STATE: ERROR task does not have end_time! Setting end_time to task.getDelay + 1.");
            // getDelay is in minutes, therefore we multiply it with 60*1000
            Date endTime = new Date(System.currentTimeMillis() - ((task.getDelay() + 1) * 60000));
            task.setEndTime(endTime);
        }
        int howManyMinutesAgo = (int) (System.currentTimeMillis() - task.getEndTime().getTime()) / 1000 / 60;
        if (howManyMinutesAgo < 0) {
            log.error("RECOVERY FROM INCONSISTENT STATE: ERROR task appears to have ended in future.");
            Date endTime = new Date(System.currentTimeMillis() - ((task.getDelay() + 1) * 60000));
            task.setEndTime(endTime);
            howManyMinutesAgo = task.getDelay() + 1;
        }
        log.info("TASK [" + task + "] in ERROR state completed " + howManyMinutesAgo + " minutes ago.");
        // XXX - apparently this is not what the authors had in mind,
        // commented out
        // check and set recurrence
        // int recurrence = task.getRecurrence() - 1;
        // if(recurrence < 0) {
        // // no more retries, sorry
        // log.info("TASK [ " + task +
        // "] in ERROR state has no more retries, bailing out.");
        // continue;
        // }
        // task.setRecurrence(recurrence);
        // If DELAY time has passed, we reschedule...
        int recurrence = task.getRecurrence() + 1;
        if (recurrence > task.getExecService().getDefaultRecurrence() && howManyMinutesAgo < 60 * 12 && !task.isSourceUpdated()) {
            log.info("TASK [ " + task + "] in ERROR state has no more retries, bailing out.");
        } else if (howManyMinutesAgo >= recurrence * task.getDelay() || task.isSourceUpdated()) {
            // check if service is still assigned on facility
            try {
                List<Service> assignedServices = perun.getServicesManager().getAssignedServices(perunSession, task.getFacility());
                if (assignedServices.contains(task.getExecService().getService())) {
                    ExecService execService = task.getExecService();
                    Facility facility = task.getFacility();
                    if (recurrence > execService.getDefaultRecurrence()) {
                        // this ERROR task is rescheduled for being here too long
                        task.setRecurrence(0);
                        task.setDestinations(null);
                        log.info("TASK id " + task.getId() + " is in ERROR state long enough, ");
                    }
                    task.setRecurrence(recurrence);
                    log.info("TASK [" + task + "] in ERROR state is going to be rescheduled: taskScheduler.propagateService(execService:ID " + execService.getId() + ", new Date(System.currentTimeMillis()), facility:ID " + facility.getId() + ");");
                    // taskScheduler.propagateService(task, new
                    // Date(System.currentTimeMillis()));
                    taskScheduler.scheduleTask(task);
                    log.info("TASK [" + task + "] in ERROR state has been rescheduled.");
                    // Also (to be sure) reschedule all Tasks that depend on
                    // this Task
                    //
                    // While engine starts in state GEN = ERROR, SEND = DONE
                    // => GEN will be rescheduled but without this SEND will
                    // never be propagated
                    List<ExecService> dependantServices = dependenciesResolver.listDependantServices(execService);
                    for (ExecService dependantService : dependantServices) {
                        Task dependantTask = schedulingPool.getTask(dependantService, facility);
                        if (dependantTask == null) {
                            dependantTask = new Task();
                            dependantTask.setExecService(dependantService);
                            dependantTask.setFacility(facility);
                            dependantTask.setRecurrence(dependantService.getDefaultRecurrence());
                            schedulingPool.addToPool(dependantTask, schedulingPool.getQueueForTask(task));
                            taskScheduler.scheduleTask(dependantTask);
                            log.info("{} was rescheduled because it depends on {}", dependantTask, task);
                        }
                    }
                } else {
                    // delete this tasks (SEND and GEN) because service is
                    // no longer assigned to facility
                    schedulingPool.removeTask(task);
                    log.warn("Removed TASK {} from database, beacuse service is no longer assigned to this facility.", task.toString());
                }
            } catch (FacilityNotExistsException e) {
                schedulingPool.removeTask(task);
                log.error("Removed TASK {} from database, facility no longer exists.", task.getId());
            } catch (InternalErrorException e) {
                log.error("{}", e);
            } catch (PrivilegeException e) {
                log.error("Consistency error. {}", e);
            }
        }
    }
/*
		 * Original implementation:
		 *
		 * //TODO: Take into account Recurrence! for (Task task :
		 * taskManager.listAllTasksInState(TaskStatus.ERROR,
		 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id")))) {
		 * if (task.getEndTime() == null) { log.error(
		 * "RECOVERY FROM INCONSISTATE STATE: ERROR task does not have end_time! Setting end_time to task.getDelay + 1."
		 * ); // getDelay is in minutes, therefore we multiply it with 60*1000
		 * Date endTime = new Date(System.currentTimeMillis() -
		 * ((task.getDelay() + 1) * 60000)); task.setEndTime(endTime);
		 * taskManager.updateTask(task,
		 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); }
		 * int howManyMinutesAgo = (int) (System.currentTimeMillis() -
		 * task.getEndTime().getTime()) / 1000 / 60; log.info("TASK [" + task +
		 * "] in ERROR state completed " + howManyMinutesAgo + " minutes ago.");
		 * //If DELAY time has passed, we reschedule... if (howManyMinutesAgo >=
		 * task.getDelay()) { //check if service is still assigned on facility
		 * try { List<Service> assignedServices =
		 * Rpc.ServicesManager.getAssignedServices(engineManager.getRpcCaller(),
		 * task.getFacility());
		 * if(assignedServices.contains(task.getExecService().getService())) {
		 * try { taskManager.updateTask(task,
		 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id")));
		 * ExecService execService = task.getExecService(); Facility facility =
		 * task.getFacility(); log.info("TASK [" + task +
		 * "] in ERROR state is going to be rescheduled: taskScheduler.propagateService(execService:ID "
		 * + execService.getId() +
		 * ", new Date(System.currentTimeMillis()), facility:ID " +
		 * facility.getId() + ");"); taskScheduler.propagateService(execService,
		 * new Date(System.currentTimeMillis()), facility); log.info("TASK [" +
		 * task + "] in ERROR state has been rescheduled.");
		 *
		 * //Also (to be sure) reschedule all execServices which depends on this
		 * exec service // //While engine starts in state GEN = ERROR, SEND =
		 * DONE => GEN will be rescheduled but without this SEND will never be
		 * propagated List<ExecService> dependentExecServices =
		 * Rpc.GeneralServiceManager
		 * .listExecServicesDependingOn(engineManager.getRpcCaller(),
		 * execService); if(dependentExecServices != null) { for(ExecService
		 * dependantExecService : dependentExecServices) {
		 * taskScheduler.propagateService(dependantExecService, new
		 * Date(System.currentTimeMillis()), facility);
		 * log.info("{} was rescheduled because it depends on {}",
		 * dependantExecService, execService); } }
		 *
		 * } catch (InternalErrorException e) { log.error(e.toString(), e); } }
		 * else { //delete this tasks (SEND and GEN) because service is no
		 * longer assigned to facility List<ExecService> execServicesGenAndSend
		 * =
		 * Rpc.GeneralServiceManager.listExecServices(engineManager.getRpcCaller
		 * (), task.getExecService().getService().getId()); for(ExecService
		 * execService : execServicesGenAndSend) { Task taskToDelete =
		 * taskManager.getTask(execService, task.getFacility(),
		 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id")));
		 * if(taskToDelete!= null) {
		 * resultManager.clearByTask(taskToDelete.getId(),
		 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id")));
		 * taskManager.removeTask(taskToDelete.getId(),
		 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); }
		 * } } } catch(PrivilegeException ex) {
		 * log.error("Consistency error. {}", ex); }
		 * catch(FacilityNotExistsException ex) {
		 * log.error("Consistency error - found task for non-existing facility. {}"
		 * , ex); } catch(ServiceNotExistsException ex) {
		 * log.error("Consistency error - found task for non-existing service. {}"
		 * , ex); } catch(InternalErrorException ex) { log.error("{}", ex); } }
		 * }
		 */
}
Also used : Task(cz.metacentrum.perun.taskslib.model.Task) ExecService(cz.metacentrum.perun.taskslib.model.ExecService) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) ArrayList(java.util.ArrayList) List(java.util.List) FacilityNotExistsException(cz.metacentrum.perun.core.api.exceptions.FacilityNotExistsException) Facility(cz.metacentrum.perun.core.api.Facility) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Date(java.util.Date)

Example 25 with PrivilegeException

use of cz.metacentrum.perun.core.api.exceptions.PrivilegeException in project perun by CESNET.

the class EventProcessorImpl method receiveEvent.

@Override
public void receiveEvent(String event) {
    log.info("Current pool size BEFORE event processing:" + schedulingPool.getSize());
    log.debug("Event " + event + " is going to be resolved...");
    Task task = null;
    try {
        task = eventParser.parseEvent(event);
    } catch (InvalidEventMessageException e) {
        log.error(e.toString());
    } catch (ServiceNotExistsException e) {
        log.error(e.toString());
    } catch (InternalErrorException e) {
        log.error(e.toString());
    } catch (PrivilegeException e) {
        log.error(e.toString());
    }
    if (task == null) {
        return;
    }
    // FIXME: Disabled because it can cause race condition. See RT#33803
    if (false) {
        // if (event.contains("forceit")) { // TODO: Move string constant to
        // a properties file
        log.debug("\t Facility[" + task.getFacility() + "]");
        log.debug("\t Resolved ExecService[" + task.getExecService() + "]");
        if (task != null && task.getFacility() != null && task.getExecService() != null) {
            // log.debug("SCHEDULING vie Force Service Propagation: ExecService["
            // + execService.getId() + "] : Facility[" + results.getRight()
            // + "]");
            schedulingPool.addToPool(task);
            final Task ntask = task;
            taskExecutorEventProcessor.execute(new Runnable() {

                @Override
                public void run() {
                    try {
                        taskScheduler.propagateService(ntask, new Date(System.currentTimeMillis()));
                    } catch (InternalErrorException e) {
                        log.error(e.toString());
                    }
                }
            });
        }
        log.debug("POOL SIZE:" + schedulingPool.getSize());
    }
    log.debug("\t Facility[" + task.getFacility() + "]");
    log.debug("\t Resolved ExecService[" + task.getExecService() + "]");
    if (task.getFacility() != null && task.getExecService() != null) {
        // log.debug("ADD to POOL: ExecService[" +
        // results.getLeft().getId() + "] : Facility[" +
        // results.getRight() + "]");
        Task currentTask = schedulingPool.getTaskById(task.getId());
        if (currentTask == null) {
            // task.setSourceUpdated(false);
            schedulingPool.addToPool(task);
            currentTask = task;
        } else {
            // currentTask.setSourceUpdated(true);
            log.debug("Resetting current task destination list to {}", task.getDestinations());
            currentTask.setDestinations(task.getDestinations());
            currentTask.setPropagationForced(task.isPropagationForced());
        }
        if (currentTask.isPropagationForced()) {
            final Task ntask = currentTask;
            try {
                taskExecutorEventProcessor.execute(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            taskScheduler.propagateService(ntask, new Date(System.currentTimeMillis()));
                        } catch (InternalErrorException e) {
                            log.error(e.toString());
                        }
                    }
                });
            } catch (Exception e) {
                log.error("Error queuing task to executor: " + e.toString());
            }
        }
    }
    log.debug("POOL SIZE:" + schedulingPool.getSize());
    log.info("Current pool size AFTER event processing:" + schedulingPool.getSize());
}
Also used : ServiceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ServiceNotExistsException) Task(cz.metacentrum.perun.taskslib.model.Task) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) InvalidEventMessageException(cz.metacentrum.perun.engine.exceptions.InvalidEventMessageException) Date(java.util.Date) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) ServiceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ServiceNotExistsException) InvalidEventMessageException(cz.metacentrum.perun.engine.exceptions.InvalidEventMessageException) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException)

Aggregations

PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)66 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)22 Facility (cz.metacentrum.perun.core.api.Facility)18 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)13 Group (cz.metacentrum.perun.core.api.Group)13 RichFacility (cz.metacentrum.perun.core.api.RichFacility)13 Vo (cz.metacentrum.perun.core.api.Vo)8 RichGroup (cz.metacentrum.perun.core.api.RichGroup)7 ArrayList (java.util.ArrayList)7 User (cz.metacentrum.perun.core.api.User)6 Service (cz.metacentrum.perun.core.api.Service)5 FacilityNotExistsException (cz.metacentrum.perun.core.api.exceptions.FacilityNotExistsException)5 ServiceNotExistsException (cz.metacentrum.perun.core.api.exceptions.ServiceNotExistsException)5 Member (cz.metacentrum.perun.core.api.Member)4 RichMember (cz.metacentrum.perun.core.api.RichMember)4 IllegalArgumentException (cz.metacentrum.perun.core.api.exceptions.IllegalArgumentException)4 ExecService (cz.metacentrum.perun.taskslib.model.ExecService)4 Task (cz.metacentrum.perun.taskslib.model.Task)4 RichUser (cz.metacentrum.perun.core.api.RichUser)3 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)3