Search in sources :

Example 16 with Destination

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

the class TaskExecutorEngineImpl method runTask.

/**
	 * Put the task into PROCESSING state and create workers for all
	 * destinations that have satisfied dependencies (or no dependencies at
	 * all).
	 * 
	 * @param task
	 *            Task to start.
	 * 
	 */
public void runTask(Task task) {
    schedulingPool.setTaskStatus(task, TaskStatus.PROCESSING);
    task.setStartTime(new Date(System.currentTimeMillis()));
    List<Task> dependencies = dependencyResolver.getDependencies(task);
    // TODO: handle GEN tasks with no destinations
    boolean started = false;
    for (Destination destination : taskStatusManager.getTaskStatus(task).getWaitingDestinations()) {
        // check if all the dependency destinations are done
        boolean proceed = true;
        try {
            for (Task dependency : dependencies) {
                if (taskStatusManager.getTaskStatus(dependency).getDestinationStatus(destination) != TaskDestinationStatus.DONE) {
                    log.debug("TASK " + task.toString() + " has unmet dependencies");
                    proceed = false;
                }
            }
        } catch (InternalErrorException e) {
            log.error("Error getting dependency status for task {}", task.toString());
        }
        if (proceed) {
            try {
                if (task.getExecService().getExecServiceType().equals(ExecServiceType.SEND)) {
                    taskStatusManager.getTaskStatus(task).setDestinationStatus(destination, TaskDestinationStatus.PROCESSING);
                }
            } catch (InternalErrorException e) {
                log.error("Error setting status for destination {} of task {}", destination, task.toString());
            }
            try {
                startWorker(task, destination);
                started = true;
            } catch (Exception e) {
                log.error("Error queuing worker for execution: " + e.toString());
            }
        }
    }
    if (!started) {
        log.warn("No worker started for task {}, setting to ERROR", task.getId());
        task.setEndTime(new Date(System.currentTimeMillis()));
        schedulingPool.setTaskStatus(task, TaskStatus.ERROR);
    }
}
Also used : Destination(cz.metacentrum.perun.core.api.Destination) Task(cz.metacentrum.perun.taskslib.model.Task) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Date(java.util.Date) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 17 with Destination

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

the class ServicesManagerEntryIntegrationTest method getDestinationsWithPerunSession.

@Test
public void getDestinationsWithPerunSession() throws Exception {
    System.out.println(CLASS_NAME + "getDestinations");
    Service service1 = setUpService();
    Facility facility1 = setUpFacility();
    Destination destination = setUpDestination();
    perun.getServicesManager().addDestination(sess, service1, facility1, destination);
    List<Destination> destinations = perun.getServicesManager().getDestinations(sess);
    assertTrue("there should be at least one destination", destinations.size() >= 1);
    assertTrue("our destination should be between all destinations", destinations.contains(destination));
}
Also used : Destination(cz.metacentrum.perun.core.api.Destination) RichDestination(cz.metacentrum.perun.core.api.RichDestination) Service(cz.metacentrum.perun.core.api.Service) Facility(cz.metacentrum.perun.core.api.Facility) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 18 with Destination

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

the class ServicesManagerEntryIntegrationTest method setUpDestination.

private Destination setUpDestination() throws Exception {
    Destination destination = new Destination();
    destination.setDestination("testDestination");
    destination.setType("service-specific");
    return destination;
}
Also used : Destination(cz.metacentrum.perun.core.api.Destination) RichDestination(cz.metacentrum.perun.core.api.RichDestination)

Example 19 with Destination

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

the class FacilitiesManagerEntryIntegrationTest method addHostSameDestinationDifferentAdmin.

@Test(expected = PrivilegeException.class)
public void addHostSameDestinationDifferentAdmin() throws Exception {
    System.out.println(CLASS_NAME + "addHostSameDestinationDifferentAdmin");
    // Initialize host, destination and service
    String hostName = "TestHost";
    Host host = new Host(0, hostName);
    Destination destination = new Destination(0, hostName, Destination.DESTINATIONHOSTTYPE);
    Service service = new Service(0, "testService");
    ServicesManager servicesManagerEntry = perun.getServicesManager();
    service = servicesManagerEntry.createService(sess, service);
    // Creates second facility
    Facility secondFacility = new Facility(0, "TestSecondFacility", "TestDescriptionText");
    assertNotNull(perun.getFacilitiesManager().createFacility(sess, secondFacility));
    // Set up two members
    Member memberOne = setUpMember(vo);
    Member memberTwo = setUpMember(vo);
    // Set users as admins of different facilities
    User userOne = perun.getUsersManagerBl().getUserByMember(sess, memberOne);
    facilitiesManagerEntry.addAdmin(sess, facility, userOne);
    User userTwo = perun.getUsersManagerBl().getUserByMember(sess, memberTwo);
    facilitiesManagerEntry.addAdmin(sess, secondFacility, userTwo);
    // Sets userOne as actor in this test with role facility admin for facility
    AuthzRoles authzRoles = new AuthzRoles(Role.FACILITYADMIN, facility);
    sess.getPerunPrincipal().setRoles(authzRoles);
    sess.getPerunPrincipal().setUser(userOne);
    // Adds destination to facility
    servicesManagerEntry.addDestination(sess, service, facility, destination);
    assertTrue(servicesManagerEntry.getDestinations(sess, service, facility).size() == 1);
    // Change actor in this test to userTwo
    authzRoles = new AuthzRoles(Role.FACILITYADMIN, secondFacility);
    sess.getPerunPrincipal().setRoles(authzRoles);
    sess.getPerunPrincipal().setUser(userTwo);
    // Adds same host as destination to secondFacility with different admin -> should throw exception
    facilitiesManagerEntry.addHost(sess, host, secondFacility);
}
Also used : Destination(cz.metacentrum.perun.core.api.Destination) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) ServicesManager(cz.metacentrum.perun.core.api.ServicesManager) AuthzRoles(cz.metacentrum.perun.core.impl.AuthzRoles) Service(cz.metacentrum.perun.core.api.Service) Host(cz.metacentrum.perun.core.api.Host) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) Facility(cz.metacentrum.perun.core.api.Facility) Member(cz.metacentrum.perun.core.api.Member) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 20 with Destination

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

the class FacilitiesManagerEntryIntegrationTest method addHostsStringsSameDestinationDifferentAdmin.

@Test(expected = PrivilegeException.class)
public void addHostsStringsSameDestinationDifferentAdmin() throws Exception {
    System.out.println(CLASS_NAME + "addHostsStringsSameDestinationDifferentAdmin");
    // Sets list of hostnames
    String hostName = "testHostOne";
    List<String> listOfHosts = new ArrayList<String>();
    listOfHosts.add(hostName);
    hostName = "testHostTwo";
    listOfHosts.add(hostName);
    // Initialize destination and service
    Destination destination = new Destination(0, hostName, Destination.DESTINATIONHOSTTYPE);
    Service service = new Service(0, "testService");
    ServicesManager servicesManagerEntry = perun.getServicesManager();
    service = servicesManagerEntry.createService(sess, service);
    // Creates second facility
    Facility secondFacility = new Facility(0, "TestSecondFacility", "TestDescriptionText");
    assertNotNull(perun.getFacilitiesManager().createFacility(sess, secondFacility));
    // Set up two members
    Member memberOne = setUpMember(vo);
    Member memberTwo = setUpMember(vo);
    // Set users as admins of different facilities
    User userOne = perun.getUsersManagerBl().getUserByMember(sess, memberOne);
    facilitiesManagerEntry.addAdmin(sess, facility, userOne);
    User userTwo = perun.getUsersManagerBl().getUserByMember(sess, memberTwo);
    facilitiesManagerEntry.addAdmin(sess, secondFacility, userTwo);
    // Sets userOne as actor in this test with role facility admin for facility
    AuthzRoles authzRoles = new AuthzRoles(Role.FACILITYADMIN, facility);
    sess.getPerunPrincipal().setRoles(authzRoles);
    sess.getPerunPrincipal().setUser(userOne);
    // Adds destination to facility
    servicesManagerEntry.addDestination(sess, service, facility, destination);
    assertTrue(servicesManagerEntry.getDestinations(sess, service, facility).size() == 1);
    // Change actor in this test to userTwo
    authzRoles = new AuthzRoles(Role.FACILITYADMIN, secondFacility);
    sess.getPerunPrincipal().setRoles(authzRoles);
    sess.getPerunPrincipal().setUser(userTwo);
    // Adds same host as destination to secondFacility with different admin -> should throw exception
    facilitiesManagerEntry.addHosts(sess, secondFacility, listOfHosts);
}
Also used : Destination(cz.metacentrum.perun.core.api.Destination) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) ServicesManager(cz.metacentrum.perun.core.api.ServicesManager) ArrayList(java.util.ArrayList) AuthzRoles(cz.metacentrum.perun.core.impl.AuthzRoles) Service(cz.metacentrum.perun.core.api.Service) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) Facility(cz.metacentrum.perun.core.api.Facility) Member(cz.metacentrum.perun.core.api.Member) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

Destination (cz.metacentrum.perun.core.api.Destination)21 Test (org.junit.Test)10 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)9 RichDestination (cz.metacentrum.perun.core.api.RichDestination)9 Service (cz.metacentrum.perun.core.api.Service)9 Facility (cz.metacentrum.perun.core.api.Facility)8 ArrayList (java.util.ArrayList)8 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)5 Host (cz.metacentrum.perun.core.api.Host)5 Member (cz.metacentrum.perun.core.api.Member)5 User (cz.metacentrum.perun.core.api.User)5 AuthzRoles (cz.metacentrum.perun.core.impl.AuthzRoles)5 RichUser (cz.metacentrum.perun.core.api.RichUser)4 ServicesManager (cz.metacentrum.perun.core.api.ServicesManager)4 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)4 Task (cz.metacentrum.perun.taskslib.model.Task)4 Date (java.util.Date)4 PerunBean (cz.metacentrum.perun.core.api.PerunBean)3 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)2 ServiceNotExistsException (cz.metacentrum.perun.core.api.exceptions.ServiceNotExistsException)2