Search in sources :

Example 11 with Destination

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

the class ServicesManagerEntryIntegrationTest method setUpHostDestination.

private Destination setUpHostDestination() throws Exception {
    Destination destination = new Destination();
    destination.setDestination("test.test");
    destination.setType(Destination.DESTINATIONHOSTTYPE);
    return destination;
}
Also used : Destination(cz.metacentrum.perun.core.api.Destination) RichDestination(cz.metacentrum.perun.core.api.RichDestination)

Example 12 with Destination

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

the class ServicesManagerBlImpl method addDestinationsForAllServicesOnFacility.

@Override
public List<Destination> addDestinationsForAllServicesOnFacility(PerunSession sess, Facility facility, Destination destination) throws InternalErrorException, DestinationAlreadyAssignedException {
    List<Service> services = this.getAssignedServices(sess, facility);
    List<Destination> destinations = new ArrayList<Destination>();
    for (Service service : services) {
        destinations.add(this.addDestination(sess, 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)

Example 13 with Destination

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

the class ApiCaller method getDestination.

public Destination getDestination(String destination, String type) throws PerunException {
    Destination d = new Destination();
    d.setDestination(destination);
    d.setType(type);
    return d;
}
Also used : Destination(cz.metacentrum.perun.core.api.Destination)

Example 14 with Destination

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

the class PropagationMaintainerImpl method onTaskComplete.

@Override
public void onTaskComplete(int taskId, int clientID, String status_s, String endTimestamp, String string) {
    Task completedTask = schedulingPool.getTaskById(taskId);
    if (completedTask == null) {
        // eh? how would that be possible?
        log.error("TASK id {} reported as complete, but we do not know it... (yet?)", taskId);
        return;
    }
    TaskStatus status = TaskStatus.NONE;
    if (status_s.equals("ERROR")) {
        status = TaskStatus.ERROR;
    } else if (status_s.equals("DONE")) {
        status = TaskStatus.DONE;
    } else {
        log.error("Engine reported unexpected status {} for task id {}, setting to ERROR", status_s, taskId);
        status = TaskStatus.ERROR;
    }
    try {
        Date endTime = new Date(Long.parseLong(endTimestamp));
        completedTask.setEndTime(endTime);
    } catch (NumberFormatException e) {
        log.error("Engine reported unparsable end time {} for task id {}, setting to current time", endTimestamp, taskId);
        completedTask.setEndTime(new Date(System.currentTimeMillis()));
    }
    // date data
    if (completedTask.getExecService().getExecServiceType().equals(ExecServiceType.SEND)) {
        try {
            schedulingPool.setQueueForTask(completedTask, null);
        } catch (InternalErrorException e) {
            log.error("Could not set destination queue for task {}: {}", completedTask.getId(), e.getMessage());
        }
        this.setAllGenerateDependenciesToNone(completedTask);
    }
    if (status.equals(TaskStatus.DONE)) {
        // task completed successfully
        // set destination list to null to refetch them later
        completedTask.setDestinations(null);
        schedulingPool.setTaskStatus(completedTask, TaskStatus.DONE);
        completedTask.setRecurrence(0);
        log.debug("TASK {} reported as DONE", completedTask.toString());
        // for GEN tasks, signal SENDs that source data are updated
        if (completedTask.getExecService().getExecServiceType().equals(ExecServiceType.GENERATE)) {
            List<ExecService> dependantServices = dependenciesResolver.listDependantServices(completedTask.getExecService());
            for (ExecService dependantService : dependantServices) {
                Task dependantTask = schedulingPool.getTask(dependantService, completedTask.getFacility());
                if (dependantTask != null && dependantService.getExecServiceType().equals(ExecServiceType.SEND)) {
                    dependantTask.setSourceUpdated(false);
                }
                if (completedTask.isPropagationForced() && dependantTask.isPropagationForced()) {
                    log.debug("Going to force schedule dependant task " + dependantTask.getId());
                    taskScheduler.scheduleTask(dependantTask);
                }
            }
        }
        completedTask.setPropagationForced(false);
    } else {
        if (string.isEmpty()) {
            // weird - task is in error and no destinations reported as
            // failed...
            log.warn("TASK {} ended in ERROR state with no remaining destinations.", completedTask.toString());
        } else {
            // task failed, some destinations remain
            // resolve list of destinations
            List<PerunBean> listOfBeans;
            List<Destination> destinationList = new ArrayList<Destination>();
            try {
                listOfBeans = AuditParser.parseLog(string);
                log.debug("Found list of destination beans: " + listOfBeans);
                for (PerunBean bean : listOfBeans) {
                    destinationList.add((Destination) bean);
                }
            } catch (InternalErrorException e) {
                log.error("Could not resolve destination from destination list");
            }
            if (completedTask.getDestinations() != null && !completedTask.getDestinations().isEmpty()) {
                completedTask.setDestinations(destinationList);
            }
        }
        schedulingPool.setTaskStatus(completedTask, TaskStatus.ERROR);
        completedTask.setPropagationForced(false);
        log.debug("Task set to ERROR state with remaining destinations: " + completedTask.getDestinations());
    }
}
Also used : Destination(cz.metacentrum.perun.core.api.Destination) Task(cz.metacentrum.perun.taskslib.model.Task) PerunBean(cz.metacentrum.perun.core.api.PerunBean) ExecService(cz.metacentrum.perun.taskslib.model.ExecService) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) TaskStatus(cz.metacentrum.perun.taskslib.model.Task.TaskStatus) Date(java.util.Date)

Example 15 with Destination

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

the class EventParserImpl method parseEvent.

@Override
public Task parseEvent(String event) throws InvalidEventMessageException, ServiceNotExistsException, InternalErrorException, PrivilegeException {
    log.info("I am going to process event:" + event);
    /**
		 * Expected string format as on:
		 * https://projekty.ics.muni.cz/perunv3/trac
		 * /wiki/PerunEngineDispatcherController event|x|[timestamp][Event
		 * header][Event data] New format:
		 * "task|[engine_id]|[task_id][is_forced]|[exec_service]|[facility]|[destination_list]|[dependency_list]"
		 * 
		 */
    // String eventParsingPattern =
    // "^event\\|([0-9]{1,6})\\|\\[([a-zA-Z0-9: ]+)\\]\\[([^\\]]+)\\]\\[(.*)\\]$";
    String eventParsingPattern = "^task\\|([0-9]{1,6})\\|\\[([0-9]+)\\]\\[([^\\]]+)\\]\\|\\[([^\\|]+)\\]\\|\\[([^\\|]+)\\]\\|\\[([^\\|]+)\\]\\|\\[(.*)\\]$";
    Pattern pattern = Pattern.compile(eventParsingPattern);
    Matcher matcher = pattern.matcher(event);
    boolean matchFound = matcher.find();
    if (matchFound) {
        log.debug("Message format matched ok...");
        String thisEngineID = matcher.group(1);
        // compare it...
        try {
            if (Integer.parseInt(thisEngineID) != Integer.parseInt((String) propertiesBean.get("engine.unique.id"))) {
                throw new InvalidEventMessageException("Wrong Engine ID. Was:" + thisEngineID + ", Expected:" + propertiesBean.get("engine.unique.id"));
            }
        } catch (Exception e) {
            throw new InvalidEventMessageException("Wrong Engine ID: parse exception", e);
        }
        // Data should provide information regarding the target ExecService
        // (Processing rule).
        String eventTaskId = matcher.group(2);
        String eventIsForced = matcher.group(3);
        String eventExecService = matcher.group(4);
        String eventFacility = matcher.group(5);
        String eventDestinationList = matcher.group(6);
        String eventDependencyList = matcher.group(7);
        // check possible enconding
        if (!eventExecService.startsWith("ExecService")) {
            eventExecService = new String(Base64.decodeBase64(eventExecService));
        }
        if (!eventExecService.startsWith("ExecService")) {
            throw new InvalidEventMessageException("Wrong exec service: parse exception");
        }
        if (!eventFacility.startsWith("Facility")) {
            eventFacility = new String(Base64.decodeBase64(eventFacility));
        }
        if (!eventFacility.startsWith("Facility")) {
            throw new InvalidEventMessageException("Wrong facility: parse exception");
        }
        if (!eventDestinationList.startsWith("Destinations")) {
            eventDestinationList = new String(Base64.decodeBase64(eventDestinationList));
        }
        if (!eventDestinationList.startsWith("Destinations")) {
            throw new InvalidEventMessageException("Wrong destination list: parse exception");
        }
        log.debug("Event data to be parsed: task id " + eventTaskId + ", forced " + eventIsForced + ", facility " + eventFacility + ", exec service " + eventExecService + ", destination list " + eventDestinationList + ", dependency list " + eventDependencyList);
        // Prepare variables
        Facility facility;
        ExecService execService;
        List<Destination> destinationList = new ArrayList<Destination>();
        // resolve facility
        // deserialize event data
        List<PerunBean> listOfBeans = AuditParser.parseLog(eventFacility);
        try {
            facility = (Facility) listOfBeans.get(0);
        } catch (Exception e) {
            throw new InvalidEventMessageException("Could not resolve facility from event [" + eventFacility + "]", e);
        }
        // resolve exec service
        // deserialize event data
        listOfBeans = AuditParser.parseLog(eventExecService);
        try {
            execService = (ExecService) listOfBeans.get(0);
        } catch (Exception e) {
            throw new InvalidEventMessageException("Could not resolve exec service from event [" + eventExecService + "]", e);
        }
        // resolve list of destinations
        listOfBeans = AuditParser.parseLog(eventDestinationList);
        log.debug("Found list of destination beans: " + listOfBeans);
        // return new Pair<ExecService, Facility>(execService, facility);
        try {
            for (PerunBean bean : listOfBeans) {
                destinationList.add((Destination) bean);
            }
        } catch (Exception e) {
            throw new InvalidEventMessageException("Could not resolve list of destinations from event.", e);
        }
        Task task = new Task();
        task.setId(Integer.parseInt(eventTaskId));
        task.setFacility(facility);
        task.setExecService(execService);
        task.setDestinations(destinationList);
        task.setDelay(execService.getDefaultDelay());
        task.setRecurrence(execService.getDefaultRecurrence());
        task.setPropagationForced(Boolean.parseBoolean(eventIsForced));
        // resolve list of dependencies
        if (eventDependencyList != null) {
            for (String token : eventDependencyList.split("[\t ]*,[\t ]*")) {
                if (token.length() > 0) {
                    try {
                        dependenciesResolver.addDependency(task, Integer.parseInt(token));
                    } catch (Exception e) {
                        throw new InvalidEventMessageException("Invalid dependency in event: " + token);
                    }
                }
            }
        }
        return task;
    } else {
        throw new InvalidEventMessageException("Invalid message format: Message[" + event + "]");
    }
}
Also used : Pattern(java.util.regex.Pattern) Destination(cz.metacentrum.perun.core.api.Destination) Task(cz.metacentrum.perun.taskslib.model.Task) Matcher(java.util.regex.Matcher) ExecService(cz.metacentrum.perun.taskslib.model.ExecService) ArrayList(java.util.ArrayList) 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) PerunBean(cz.metacentrum.perun.core.api.PerunBean) Facility(cz.metacentrum.perun.core.api.Facility) InvalidEventMessageException(cz.metacentrum.perun.engine.exceptions.InvalidEventMessageException)

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