Search in sources :

Example 51 with Task

use of cz.metacentrum.perun.taskslib.model.Task in project perun by CESNET.

the class TaskSchedulerImpl method processPool.

@Override
public void processPool() throws InternalErrorException {
    for (Task task : schedulingPool.getNewTasks()) {
        if (task.isPropagationForced()) {
            // this can happen only as a race between this thread and thread created for force-scheduled task
            log.info("Found force-scheduled task {} during normal schedule cycle, resetting force flag", task.getId());
            // may not be the best behavior...
            task.setPropagationForced(false);
        }
        log.debug("Propagating task {}, ExecService:Facility : " + task.getExecServiceId() + ":" + task.getFacilityId(), task.getId());
        propagateService(task, new Date(System.currentTimeMillis()));
    }
}
Also used : Task(cz.metacentrum.perun.taskslib.model.Task) Date(java.util.Date)

Example 52 with Task

use of cz.metacentrum.perun.taskslib.model.Task in project perun by CESNET.

the class EngineManagerImpl method switchUnfinishedTasksToERROR.

@Override
public void switchUnfinishedTasksToERROR() {
    log.info("I am going to switched all unfinished tasks to ERROR and finished GEN tasks which data wasn't send to ERROR as well");
    /* we set everything found to error to report it back to dispatcher */
    for (Task task : schedulingPool.getDoneTasks()) {
        ExecService execService = task.getExecService();
        if (execService.getExecServiceType().equals(ExecServiceType.GENERATE)) {
            log.debug("Setting task " + task.toString() + " to ERROR");
            schedulingPool.setTaskStatus(task, TaskStatus.ERROR);
        }
    }
    for (Task task : schedulingPool.getProcessingTasks()) {
        log.debug("Setting task " + task.toString() + " to ERROR");
        schedulingPool.setTaskStatus(task, TaskStatus.ERROR);
    }
    for (Task task : schedulingPool.getPlannedTasks()) {
        log.debug("Setting task " + task.toString() + " to ERROR");
        schedulingPool.setTaskStatus(task, TaskStatus.ERROR);
    }
    log.info("I'm done with it.");
}
Also used : Task(cz.metacentrum.perun.taskslib.model.Task) ExecService(cz.metacentrum.perun.taskslib.model.ExecService)

Example 53 with Task

use of cz.metacentrum.perun.taskslib.model.Task in project perun by CESNET.

the class ExecutorEngineWorkerImplTest method runGenTest.

@Test
public void runGenTest() throws Exception {
    System.out.println("ExecutorEngineWorkerImpl.runGenTest");
    ExecutorEngineWorker worker = (ExecutorEngineWorker) beanFactory.getBean("executorEngineWorker");
    log.debug("task " + task_gen.toString());
    schedulingPool.addToPool(task_gen);
    for (Task task : taskManager.listAllTasks(engineId)) {
        log.debug("task in db " + ((task == null) ? "null" : task.toString()));
    }
    count = 0;
    // for test there is no send subfolder, let's fake root
    ((ExecutorEngineWorkerImpl) worker).setGenDirectory(new File("/"));
    worker.setTask(task_gen);
    worker.setExecService(task_gen.getExecService());
    worker.setFacility(task_gen.getFacility());
    worker.setDestination(destination1);
    worker.setResultListener(this);
    worker.run();
    Assert.isTrue(count == 1, "count 1");
}
Also used : Task(cz.metacentrum.perun.taskslib.model.Task) ExecutorEngineWorker(cz.metacentrum.perun.engine.scheduling.ExecutorEngineWorker) File(java.io.File) ExecutorEngineWorkerImpl(cz.metacentrum.perun.engine.scheduling.impl.ExecutorEngineWorkerImpl) Test(org.junit.Test) AbstractEngineTest(cz.metacentrum.perun.engine.AbstractEngineTest)

Example 54 with Task

use of cz.metacentrum.perun.taskslib.model.Task in project perun by CESNET.

the class ExecutorEngineWorkerImplTest method runSendTest.

@Test
public void runSendTest() throws Exception {
    System.out.println("ExecutorEngineWorkerImpl.runSendTest");
    ExecutorEngineWorker worker = (ExecutorEngineWorker) beanFactory.getBean("executorEngineWorker");
    log.debug("task " + task1.toString());
    // add task to local db
    schedulingPool.addToPool(task1);
    for (Task task : taskManager.listAllTasks(engineId)) {
        log.debug("task in db " + ((task == null) ? "null" : task.toString()));
    }
    count = 0;
    // for test there is no send subfolder, let's fake root
    ((ExecutorEngineWorkerImpl) worker).setSendDirectory(new File("/"));
    worker.setTask(task1);
    worker.setExecService(task1.getExecService());
    worker.setFacility(task1.getFacility());
    worker.setDestination(destination1);
    worker.setResultListener(this);
    worker.run();
    Assert.isTrue(count == 1, "count 1");
}
Also used : Task(cz.metacentrum.perun.taskslib.model.Task) ExecutorEngineWorker(cz.metacentrum.perun.engine.scheduling.ExecutorEngineWorker) File(java.io.File) ExecutorEngineWorkerImpl(cz.metacentrum.perun.engine.scheduling.impl.ExecutorEngineWorkerImpl) Test(org.junit.Test) AbstractEngineTest(cz.metacentrum.perun.engine.AbstractEngineTest)

Example 55 with Task

use of cz.metacentrum.perun.taskslib.model.Task in project perun by CESNET.

the class FacilitiesManagerBlImpl method deleteFacility.

@Override
public void deleteFacility(PerunSession sess, Facility facility, Boolean force) throws RelationExistsException, FacilityAlreadyRemovedException, HostAlreadyRemovedException, ResourceAlreadyRemovedException, GroupAlreadyRemovedFromResourceException {
    if (force) {
        List<Resource> resources = this.getAssignedResources(sess, facility);
        for (Resource resource : resources) {
            getPerunBl().getResourcesManagerBl().deleteResource(sess, resource);
        }
        List<Task> tasks = perunBl.getTasksManagerBl().listAllTasksForFacility(sess, facility.getId());
        for (Task task : tasks) {
            perunBl.getTasksManagerBl().deleteTaskResults(sess, task.getId());
            perunBl.getTasksManagerBl().removeTask(sess, task.getId());
        }
    } else {
        if (getFacilitiesManagerImpl().getAssignedResources(sess, facility).size() > 0) {
            throw new RelationExistsException("Facility is still used as a resource");
        }
    }
    // remove admins of this facility
    List<Group> adminGroups = getFacilitiesManagerImpl().getAdminGroups(sess, facility);
    for (Group adminGroup : adminGroups) {
        try {
            AuthzResolverBlImpl.unsetRole(sess, adminGroup, facility, Role.FACILITYADMIN);
        } catch (GroupNotAdminException e) {
            log.warn("When trying to unsetRole FacilityAdmin for group {} in the facility {} the exception was thrown {}", adminGroup, facility, e);
        // skip and log as warning
        } catch (RoleCannotBeManagedException e) {
            throw new InternalErrorException(e);
        }
    }
    List<User> adminUsers = getFacilitiesManagerImpl().getAdmins(sess, facility);
    for (User adminUser : adminUsers) {
        try {
            AuthzResolverBlImpl.unsetRole(sess, adminUser, facility, Role.FACILITYADMIN);
        } catch (UserNotAdminException e) {
            log.warn("When trying to unsetRole FacilityAdmin for user {} in the facility {} the exception was thrown {}", adminUser, facility, e);
        // skip and log as warning
        } catch (RoleCannotBeManagedException e) {
            throw new InternalErrorException(e);
        }
    }
    // remove hosts
    List<Host> hosts = this.getHosts(sess, facility);
    for (Host host : hosts) {
        this.removeHost(sess, host, facility);
    }
    // remove destinations
    getPerunBl().getServicesManagerBl().removeAllDestinations(sess, facility);
    // remove assigned security teams
    List<SecurityTeam> teams = getAssignedSecurityTeams(sess, facility);
    for (SecurityTeam team : teams) {
        removeSecurityTeam(sess, facility, team);
    }
    // remove associated attributes
    try {
        getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, facility);
    } catch (WrongAttributeValueException | WrongReferenceAttributeValueException e) {
        throw new InternalErrorException(e);
    }
    // Remove all facility bans
    List<BanOnFacility> bansOnFacility = this.getBansForFacility(sess, facility.getId());
    for (BanOnFacility banOnFacility : bansOnFacility) {
        try {
            this.removeBan(sess, banOnFacility.getId());
        } catch (BanNotExistsException ex) {
        // it is ok, we just want to remove it anyway
        }
    }
    // Remove all service denials
    getFacilitiesManagerImpl().removeAllServiceDenials(facility.getId());
    // delete facility
    getFacilitiesManagerImpl().deleteFacilityOwners(sess, facility);
    getFacilitiesManagerImpl().deleteFacility(sess, facility);
    getPerunBl().getAuditer().log(sess, new FacilityDeleted(facility));
}
Also used : Group(cz.metacentrum.perun.core.api.Group) RichGroup(cz.metacentrum.perun.core.api.RichGroup) Task(cz.metacentrum.perun.taskslib.model.Task) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) Resource(cz.metacentrum.perun.core.api.Resource) RichResource(cz.metacentrum.perun.core.api.RichResource) FacilityDeleted(cz.metacentrum.perun.audit.events.FacilityManagerEvents.FacilityDeleted) GroupNotAdminException(cz.metacentrum.perun.core.api.exceptions.GroupNotAdminException) Host(cz.metacentrum.perun.core.api.Host) SecurityTeam(cz.metacentrum.perun.core.api.SecurityTeam) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) UserNotAdminException(cz.metacentrum.perun.core.api.exceptions.UserNotAdminException) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) RoleCannotBeManagedException(cz.metacentrum.perun.core.api.exceptions.RoleCannotBeManagedException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) BanNotExistsException(cz.metacentrum.perun.core.api.exceptions.BanNotExistsException)

Aggregations

Task (cz.metacentrum.perun.taskslib.model.Task)77 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)16 Date (java.util.Date)16 Test (org.junit.Test)15 Facility (cz.metacentrum.perun.core.api.Facility)14 Destination (cz.metacentrum.perun.core.api.Destination)11 Service (cz.metacentrum.perun.core.api.Service)10 TaskStoreException (cz.metacentrum.perun.taskslib.exceptions.TaskStoreException)10 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)9 ExecService (cz.metacentrum.perun.taskslib.model.ExecService)9 ArrayList (java.util.ArrayList)9 AbstractDispatcherTest (cz.metacentrum.perun.dispatcher.AbstractDispatcherTest)6 SendTask (cz.metacentrum.perun.taskslib.model.SendTask)6 TaskResult (cz.metacentrum.perun.taskslib.model.TaskResult)6 JMSException (javax.jms.JMSException)6 Pair (cz.metacentrum.perun.core.api.Pair)5 AbstractEngineTest (cz.metacentrum.perun.engine.AbstractEngineTest)5 TaskExecutionException (cz.metacentrum.perun.engine.exceptions.TaskExecutionException)5 LocalDateTime (java.time.LocalDateTime)5 Resource (cz.metacentrum.perun.core.api.Resource)4