Search in sources :

Example 6 with Destination

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

the class FacilitiesManagerEntryIntegrationTest method addHostsSameDestinationDifferentAdmin.

@Test(expected = PrivilegeException.class)
public void addHostsSameDestinationDifferentAdmin() throws Exception {
    System.out.println(CLASS_NAME + "addHostsStringsSameDestinationDifferentAdmin");
    // Sets list of hosts
    List<Host> listOfHosts = new ArrayList<Host>();
    Host testHost = new Host(0, "testHostOne");
    listOfHosts.add(testHost);
    String hostName = "testHostTwo";
    testHost = new Host(0, hostName);
    listOfHosts.add(testHost);
    // 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, listOfHosts, 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) ArrayList(java.util.ArrayList) 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 7 with Destination

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

the class PropagationMaintainerImpl method checkFinishedTasks.

/*
	 * private void checkProcessingTasks() {
	 * log.info("Gonna list tasks in PROCESSING...");
	 *
	 * for(Task task: schedulingPool.getProcessingTasks()) {
	 * if(task.getExecService
	 * ().getExecServiceType().equals(ExecService.ExecServiceType.GENERATE))
	 * continue; log.info("Gonna check results for Task ID:" + task.getId());
	 *
	 * }
	 *
	 * for (Task task : taskManager.listAllTasksInState(TaskStatus.PROCESSING,
	 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id")))) {
	 * //skip GEN tasks
	 * if(task.getExecService().getExecServiceType().equals(ExecService
	 * .ExecServiceType.GENERATE)) continue;
	 * log.info("Gonna check results for Task ID:" + task.getId());
	 *
	 * List<TaskResult> taskResults =
	 * taskResultDao.getTaskResultsByTask(task.getId());
	 *
	 * List<Destination> destinations = null; try { destinations =
	 * Rpc.ServicesManager.getDestinations(engineManager.getRpcCaller(),
	 * task.getExecService().getService(), task.getFacility()); }
	 * catch(InternalErrorException ex) {
	 * log.error("Can't get destinations. Switching task to ERROR. Cause: {}",
	 * ex); task.setStatus(TaskStatus.ERROR); task.setEndTime(new
	 * Date(System.currentTimeMillis())); taskManager.updateTask(task,
	 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); }
	 * catch(PrivilegeException ex) {
	 * log.error("Can't get destinations. Switching task to ERROR. Cause: {}",
	 * ex); task.setStatus(TaskStatus.ERROR); task.setEndTime(new
	 * Date(System.currentTimeMillis())); taskManager.updateTask(task,
	 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); }
	 * catch(ServiceNotExistsException ex) {
	 * log.error("Service for the task no longer exists. Removing task", ex);
	 * taskManager.removeTask(task.getId(),
	 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); }
	 * catch(FacilityNotExistsException ex) {
	 * log.error("Facility for the task no longer exists. Removing task", ex);
	 * taskManager.removeTask(task.getId(),
	 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); }
	 *
	 * switch(task.getType()) {
	 *
	 * case SERIAL: collectSerialTaskResults(task, taskResults, destinations);
	 * break;
	 *
	 * case PARALLEL: collectParallelTaskResults(task, taskResults,
	 * destinations); break;
	 *
	 * default: log.error("Unknown task type. Assuming parallel.");
	 * collectParallelTaskResults(task, taskResults, destinations); break; } } }
	 *
	 *
	 * private void collectSerialTaskResults(Task task, List<TaskResult>
	 * taskResults, List<Destination> destinations) { if (taskResults.size() <=
	 * destinations.size()) { // Let's check whether they are all DONE or not...
	 * int amountDone = 0; int amountDenied = 0; int amountError = 0; int
	 * amountFatalError = 0; for (TaskResult taskResult : taskResults) { switch
	 * (taskResult.getStatus()) { case DONE: amountDone++; break; case DENIED:
	 * amountDenied++; break; case ERROR: amountError++; break; case
	 * FATAL_ERROR: amountFatalError++; break; default: throw new
	 * IllegalArgumentException("WTF?! " + taskResult.getStatus().toString()); }
	 * }
	 *
	 * if (amountDone > 0) { // Super, at least one task is DONE.
	 * log.info("Task ID " + task.getId() +
	 * " has one Tasks_result DONE, so we set it as DONE.");
	 * task.setStatus(TaskStatus.DONE); task.setEndTime(new
	 * Date(System.currentTimeMillis())); taskManager.updateTask(task,
	 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id")));
	 *
	 * //Set its GENERATE dependencies as dirty //TODO: Hmm...what to do in case
	 * of exceptions?
	 *
	 * try { log.info("I am going to set all ExecService " +
	 * task.getExecServiceId() + " dependencies (the GENERATE ones) to NONE.");
	 * setAllGenerateDependenciesToNone
	 * (dependenciesResolver.listDependencies(task.getExecServiceId()),
	 * task.getFacilityId()); } catch (ServiceNotExistsException e) {
	 * log.error(e.toString(), e); } catch (InternalErrorException e) {
	 * log.error(e.toString(), e); } catch (PrivilegeException e) {
	 * log.error(e.toString(), e); } } else { //TODO Now FATAL_ERROR and ERROR
	 * are being treated exactly the same. Is FATAL_ERROR really necessary? //
	 * Not DONE yet, are there any destinations left? if (taskResults.size() ==
	 * destinations.size()) { // Well, we ended in ERROR... log.info(
	 * "There has been no DONE state Tasks_results, so I am going to set the Task ID"
	 * + task.getId() + " to ERROR."); task.setStatus(TaskStatus.ERROR);
	 * task.setEndTime(new Date(System.currentTimeMillis()));
	 * taskManager.updateTask(task,
	 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); //Set
	 * its GENERATE dependencies as dirty //TODO: Hmm...what to do in case of
	 * exceptions?
	 *
	 * try {
	 * setAllGenerateDependenciesToNone(dependenciesResolver.listDependencies
	 * (task.getExecServiceId()), task.getFacilityId()); } catch
	 * (ServiceNotExistsException e) { log.error(e.toString(), e); } catch
	 * (InternalErrorException e) { log.error(e.toString(), e); } catch
	 * (PrivilegeException e) { log.error(e.toString(), e); } } else { // There
	 * are some destinations left to try, schedule it back
	 * task.setStatus(TaskStatus.PLANNED); task.setSchedule(new
	 * Date(System.currentTimeMillis())); taskManager.updateTask(task,
	 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); } } }
	 * else if (taskResults.size() > destinations.size()) { log.error(
	 * "There are more Task_results then destinations. so I am going to set the Task ID"
	 * + task.getId() + " to ERROR."); task.setStatus(TaskStatus.ERROR);
	 * task.setEndTime(new Date(System.currentTimeMillis()));
	 * taskManager.updateTask(task,
	 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); //Set
	 * its GENERATE dependencies as dirty //TODO: Hmm...what to do in case of
	 * exceptions? try {
	 * setAllGenerateDependenciesToNone(dependenciesResolver.listDependencies
	 * (task.getExecServiceId()), task.getFacilityId()); } catch
	 * (ServiceNotExistsException e) { log.error(e.toString(), e); } catch
	 * (InternalErrorException e) { log.error(e.toString(), e); } catch
	 * (PrivilegeException e) { log.error(e.toString(), e); } }
	 *
	 * if(false) { final long THREE_HOUR = 1000 * 60 * 60 * 3; long
	 * timeDifference = System.currentTimeMillis() -
	 * task.getStartTime().getTime(); if(timeDifference > THREE_HOUR) { // //
	 * WARNING!! // // This can be dangerous. We are not sure if there isn't any
	 * slave script running for this task. // log.error("There are only " +
	 * taskResults.size() + " Task_results for Task ID" + task.getId() +
	 * ", but task is in processing too long, so switch task to ERROR");
	 * task.setStatus(TaskStatus.ERROR); task.setEndTime(new
	 * Date(System.currentTimeMillis())); taskManager.updateTask(task,
	 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); //Set
	 * its GENERATE dependencies as dirty //TODO: Hmm...what to do in case of
	 * exceptions? try {
	 * setAllGenerateDependenciesToNone(dependenciesResolver.listDependencies
	 * (task.getExecServiceId()), task.getFacilityId()); } catch
	 * (ServiceNotExistsException e) { log.error(e.toString(), e); } catch
	 * (InternalErrorException e) { log.error(e.toString(), e); } catch
	 * (PrivilegeException e) { log.error(e.toString(), e); } }
	 *
	 * log.info("There are only " + taskResults.size() +
	 * " Task_results for Task ID" + task.getId() +
	 * ", so we ain't gonna do anything."); // Well, we ain't gonna do anything
	 * bro... // TODO: Time out... } }
	 *
	 * private void collectParallelTaskResults(Task task, List<TaskResult>
	 * taskResults, List<Destination> destinations) { // Do we have the same
	 * number of Destinations as we have TaskResults? if (taskResults.size() ==
	 * destinations.size()) { // Let's check whether they are all DONE or not...
	 * int amountDone = 0; int amountDenied = 0; int amountError = 0; int
	 * amountFatalError = 0; for (TaskResult taskResult : taskResults) { switch
	 * (taskResult.getStatus()) { case DONE: amountDone++; break; case DENIED:
	 * amountDenied++; break; case ERROR: amountError++; break; case
	 * FATAL_ERROR: amountFatalError++; break; default: throw new
	 * IllegalArgumentException("WTF?! " + taskResult.getStatus().toString()); }
	 * }
	 *
	 * if (amountDone + amountDenied == taskResults.size()) { // Super, all is
	 * DONE or we don't care (DENIED) :-) log.info("Task ID " + task.getId() +
	 * " has all Tasks_results either DONE or DENIED, so we set it as DONE.");
	 * task.setStatus(TaskStatus.DONE); task.setEndTime(new
	 * Date(System.currentTimeMillis())); taskManager.updateTask(task,
	 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id")));
	 *
	 * //Set its GENERATE dependencies as dirty //TODO: Hmm...what to do in case
	 * of exceptions? try { log.info("I am going to set all ExecService " +
	 * task.getExecServiceId() + " dependencies (the GENERATE ones) to NONE.");
	 *
	 * setAllGenerateDependenciesToNone(dependenciesResolver.listDependencies(task
	 * .getExecServiceId()), task.getFacilityId()); } catch
	 * (ServiceNotExistsException e) { log.error(e.toString(), e); } catch
	 * (InternalErrorException e) { log.error(e.toString(), e); } catch
	 * (PrivilegeException e) { log.error(e.toString(), e); } } else { final
	 * long TWO_HOUR = 1000 * 60 * 60 * 2; long timeDifference =
	 * System.currentTimeMillis() - task.getStartTime().getTime();
	 * if(timeDifference > TWO_HOUR) { // // WARNING!! // // This can be
	 * dangerous. We are not sure if there isn't any slave script running for
	 * this task. // log.error("There are only " + taskResults.size() +
	 * " Task_results for Task ID" + task.getId() +
	 * ", but task is in processing too long, so switch task to ERROR");
	 * task.setStatus(TaskStatus.ERROR); task.setEndTime(new
	 * Date(System.currentTimeMillis())); taskManager.updateTask(task,
	 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); //Set
	 * its GENERATE dependencies as dirty //TODO: Hmm...what to do in case of
	 * exceptions? try {
	 * setAllGenerateDependenciesToNone(dependenciesResolver.listDependencies
	 * (task.getExecServiceId()), task.getFacilityId()); } catch
	 * (ServiceNotExistsException e) { log.error(e.toString(), e); } catch
	 * (InternalErrorException e) { log.error(e.toString(), e); } catch
	 * (PrivilegeException e) { log.error(e.toString(), e); } } } } else if
	 * (taskResults.size() > destinations.size()) { log.error(
	 * "There are more Task_results then destinations. so I am going to set the Task ID"
	 * + task.getId() + " to ERROR."); task.setStatus(TaskStatus.ERROR);
	 * task.setEndTime(new Date(System.currentTimeMillis()));
	 * taskManager.updateTask(task,
	 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); //Set
	 * its GENERATE dependencies as dirty //TODO: Hmm...what to do in case of
	 * exceptions? try {
	 * setAllGenerateDependenciesToNone(dependenciesResolver.listDependencies
	 * (task.getExecServiceId()), task.getFacilityId()); } catch
	 * (ServiceNotExistsException e) { log.error(e.toString(), e); } catch
	 * (InternalErrorException e) { log.error(e.toString(), e); } catch
	 * (PrivilegeException e) { log.error(e.toString(), e); } } else { final
	 * long THREE_HOUR = 1000 * 60 * 60 * 3; long timeDifference =
	 * System.currentTimeMillis() - task.getStartTime().getTime();
	 * if(timeDifference > THREE_HOUR) { // // WARNING!! // // This can be
	 * dangerous. We are not sure if there isn't any slave script running for
	 * this task. // log.error("There are only " + taskResults.size() +
	 * " Task_results for Task ID" + task.getId() +
	 * ", but task is in processing too long, so switch task to ERROR");
	 * task.setStatus(TaskStatus.ERROR); task.setEndTime(new
	 * Date(System.currentTimeMillis())); taskManager.updateTask(task,
	 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); //Set
	 * its GENERATE dependencies as dirty //TODO: Hmm...what to do in case of
	 * exceptions? try {
	 * setAllGenerateDependenciesToNone(dependenciesResolver.listDependencies
	 * (task.getExecServiceId()), task.getFacilityId()); } catch
	 * (ServiceNotExistsException e) { log.error(e.toString(), e); } catch
	 * (InternalErrorException e) { log.error(e.toString(), e); } catch
	 * (PrivilegeException e) { log.error(e.toString(), e); } }
	 *
	 * log.info("There are only " + taskResults.size() +
	 * " Task_results for Task ID" + task.getId() +
	 * ", so we ain't gonna do anything."); // Well, we ain't gonna do anything
	 * bro... // TODO: Time out... } }
	 */
private void checkFinishedTasks() {
    // report finished tasks back to scheduler
    // clear all tasks we are done with (ie. DONE, ERROR with no recurrence
    // left)
    List<Task> tasklist = schedulingPool.getDoneTasks();
    log.debug("There are {} DONE tasks", tasklist.size());
    for (Task task : tasklist) {
        if (task.getEndTime() == null) {
            log.error("RECOVERY FROM INCONSISTENT STATE: DONE task does not have end_time! Setting end_time to now.");
            Date endTime = new Date(System.currentTimeMillis());
            task.setEndTime(endTime);
        }
        log.debug("TASK " + task.toString() + " finished");
        try {
            log.debug("TASK reported as finished at " + System.currentTimeMillis());
            jmsQueueManager.reportFinishedTask(task, "Destinations []");
            schedulingPool.removeTask(task);
            log.debug("TASK {} removed from database.", task.getId());
        } catch (JMSException e) {
            log.error("Failed to report finished task " + task.toString() + ": " + e.getMessage());
        }
    }
    tasklist = schedulingPool.getErrorTasks();
    log.debug("There are {} ERROR tasks", tasklist.size());
    for (Task task : tasklist) {
        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);
        }
        List<Destination> destinations = taskStatusManager.getTaskStatus(task).getSuccessfulDestinations();
        List<Destination> failedDestinations = task.getDestinations();
        failedDestinations.removeAll(destinations);
        StringBuilder destinations_s = new StringBuilder("Destinations [");
        if (!failedDestinations.isEmpty()) {
            destinations_s.append(failedDestinations.remove(0).serializeToString());
            for (Destination destination : failedDestinations) {
                destinations_s.append(",");
                destinations_s.append(destination.serializeToString());
            }
        }
        destinations_s.append("]");
        log.debug("TASK " + task.toString() + " finished in error, remaining destinations: " + destinations_s);
        try {
            jmsQueueManager.reportFinishedTask(task, destinations_s.toString());
            schedulingPool.removeTask(task);
            log.debug("TASK {} removed from database.", task.getId());
        } catch (JMSException e) {
            log.error("Failed to report finished task " + task.toString() + ": " + e.getMessage());
        }
    }
}
Also used : Destination(cz.metacentrum.perun.core.api.Destination) Task(cz.metacentrum.perun.taskslib.model.Task) JMSException(javax.jms.JMSException) Date(java.util.Date)

Example 8 with Destination

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

the class TaskSchedulerImpl method sendToEngine.

private void sendToEngine(Task task) {
    DispatcherQueue dispatcherQueue;
    try {
        dispatcherQueue = schedulingPool.getQueueForTask(task);
    } catch (InternalErrorException e1) {
        log.error("No engine set for task " + task.toString() + ", could not send it!");
        return;
    }
    if (dispatcherQueue == null) {
        // where should we send the task?
        if (dispatcherQueuePool.poolSize() > 0) {
            dispatcherQueue = dispatcherQueuePool.getPool().iterator().next();
            try {
                schedulingPool.setQueueForTask(task, dispatcherQueue);
            } catch (InternalErrorException e) {
                log.error("Could not assign new queue for task {}: {}", task.getId(), e);
                return;
            }
            log.debug("Assigned new queue " + dispatcherQueue.getQueueName() + " to task " + task.getId());
        } else {
            // bad luck...
            log.error("Task " + task.toString() + " has no engine assigned and there are no engines registered...");
            return;
        }
    }
    // task|[engine_id]|[task_id][is_forced][exec_service_id][facility]|[destination_list]|[dependency_list]
    // - the task|[engine_id] part is added by dispatcherQueue
    List<Destination> destinations = task.getDestinations();
    if (destinations == null || destinations.isEmpty()) {
        log.debug("No destinations for task " + task.toString() + ", trying to query the database...");
        try {
            initPerunSession();
            destinations = perun.getServicesManager().getDestinations(perunSession, task.getExecService().getService(), task.getFacility());
        } catch (ServiceNotExistsException e) {
            log.error("No destinations found for task " + task.getId());
            task.setEndTime(new Date(System.currentTimeMillis()));
            schedulingPool.setTaskStatus(task, TaskStatus.ERROR);
            return;
        } catch (FacilityNotExistsException e) {
            log.error("Facility for task {} does not exist...", task.getId());
            task.setEndTime(new Date(System.currentTimeMillis()));
            schedulingPool.setTaskStatus(task, TaskStatus.ERROR);
            return;
        } catch (PrivilegeException e) {
            log.error("Privilege error accessing the database: " + e.getMessage());
            task.setEndTime(new Date(System.currentTimeMillis()));
            schedulingPool.setTaskStatus(task, TaskStatus.ERROR);
            return;
        } catch (InternalErrorException e) {
            log.error("Internal error: " + e.getMessage());
            task.setEndTime(new Date(System.currentTimeMillis()));
            schedulingPool.setTaskStatus(task, TaskStatus.ERROR);
            return;
        }
    }
    log.debug("Fetched destinations: " + ((destinations == null) ? "[]" : destinations.toString()));
    task.setDestinations(destinations);
    StringBuilder destinations_s = new StringBuilder("Destinations [");
    if (destinations != null) {
        for (Destination destination : destinations) {
            destinations_s.append(destination.serializeToString() + ", ");
        }
    }
    destinations_s.append("]");
    String dependencies = "";
    dispatcherQueue.sendMessage("[" + task.getId() + "][" + task.isPropagationForced() + "]|[" + fixStringSeparators(task.getExecService().serializeToString()) + "]|[" + fixStringSeparators(task.getFacility().serializeToString()) + "]|[" + fixStringSeparators(destinations_s.toString()) + "]|[" + dependencies + "]");
    task.setStartTime(new Date(System.currentTimeMillis()));
    task.setEndTime(null);
    schedulingPool.setTaskStatus(task, TaskStatus.PROCESSING);
}
Also used : Destination(cz.metacentrum.perun.core.api.Destination) ServiceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ServiceNotExistsException) DispatcherQueue(cz.metacentrum.perun.dispatcher.jms.DispatcherQueue) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) FacilityNotExistsException(cz.metacentrum.perun.core.api.exceptions.FacilityNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Date(java.util.Date)

Example 9 with Destination

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

the class ServicesManagerBlImpl method addDestinationsDefinedByHostsOnFacility.

public List<Destination> addDestinationsDefinedByHostsOnFacility(PerunSession perunSession, List<Service> services, Facility facility) throws InternalErrorException {
    List<Host> hosts = getPerunBl().getFacilitiesManagerBl().getHosts(perunSession, facility);
    List<Destination> destinations = new ArrayList<Destination>();
    for (Service service : services) {
        for (Host host : hosts) {
            if (host.getHostname() != null && !host.getHostname().isEmpty()) {
                Destination destination = new Destination();
                destination.setDestination(host.getHostname());
                destination.setType(Destination.DESTINATIONHOSTTYPE);
                destinations.add(this.addDestinationEvenIfAlreadyExists(perunSession, service, facility, destination));
            }
        }
    }
    return destinations;
}
Also used : RichDestination(cz.metacentrum.perun.core.api.RichDestination) Destination(cz.metacentrum.perun.core.api.Destination) ArrayList(java.util.ArrayList) Service(cz.metacentrum.perun.core.api.Service) Host(cz.metacentrum.perun.core.api.Host)

Example 10 with Destination

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

the class ServicesManagerBlImpl method addDestinationsDefinedByHostsOnFacility.

public List<Destination> addDestinationsDefinedByHostsOnFacility(PerunSession perunSession, Service service, Facility facility) throws InternalErrorException, DestinationAlreadyAssignedException {
    // Get all hosts
    List<Host> hosts = getPerunBl().getFacilitiesManagerBl().getHosts(perunSession, facility);
    List<Destination> destinations = new ArrayList<Destination>();
    for (Host host : hosts) {
        if (host.getHostname() != null && !host.getHostname().isEmpty()) {
            Destination destination = new Destination();
            destination.setDestination(host.getHostname());
            destination.setType(Destination.DESTINATIONHOSTTYPE);
            destinations.add(this.addDestination(perunSession, service, facility, destination));
        }
    }
    return destinations;
}
Also used : RichDestination(cz.metacentrum.perun.core.api.RichDestination) Destination(cz.metacentrum.perun.core.api.Destination) ArrayList(java.util.ArrayList) Host(cz.metacentrum.perun.core.api.Host)

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