Search in sources :

Example 1 with PcapStatus

use of org.apache.metron.rest.model.pcap.PcapStatus in project metron by apache.

the class PcapServiceImpl method submit.

@Override
public PcapStatus submit(String username, PcapRequest pcapRequest) throws RestException {
    List<PcapStatus> runningJobs = getJobStatus(username, JobStatus.State.RUNNING);
    Integer userJobLimit = environment.getProperty(MetronRestConstants.USER_JOB_LIMIT_SPRING_PROPERTY, Integer.class, 1);
    if (runningJobs != null && runningJobs.size() >= userJobLimit) {
        String jobIds = runningJobs.stream().map(PcapStatus::getJobId).collect(Collectors.joining(", "));
        String message = String.format("Cannot submit job because a job is already running.  " + "Please contact the administrator to cancel job(s) with id(s) %s", jobIds);
        throw new RestException(message);
    }
    try {
        setPcapOptions(username, pcapRequest);
        pcapRequest.setFields();
        pcapJobSupplier.setPcapRequest(pcapRequest);
        JobStatus jobStatus = jobManager.submit(pcapJobSupplier, username);
        return jobStatusToPcapStatus(jobStatus);
    } catch (IOException | JobException e) {
        throw new RestException(e);
    }
}
Also used : JobStatus(org.apache.metron.job.JobStatus) JobException(org.apache.metron.job.JobException) RestException(org.apache.metron.rest.RestException) IOException(java.io.IOException) PcapStatus(org.apache.metron.rest.model.pcap.PcapStatus)

Example 2 with PcapStatus

use of org.apache.metron.rest.model.pcap.PcapStatus in project metron by apache.

the class PcapServiceImpl method jobStatusToPcapStatus.

protected PcapStatus jobStatusToPcapStatus(JobStatus jobStatus) {
    PcapStatus pcapStatus = new PcapStatus();
    pcapStatus.setJobId(jobStatus.getJobId());
    pcapStatus.setJobStatus(jobStatus.getState().toString());
    pcapStatus.setDescription(jobStatus.getDescription());
    pcapStatus.setPercentComplete(jobStatus.getPercentComplete());
    return pcapStatus;
}
Also used : PcapStatus(org.apache.metron.rest.model.pcap.PcapStatus)

Aggregations

PcapStatus (org.apache.metron.rest.model.pcap.PcapStatus)2 IOException (java.io.IOException)1 JobException (org.apache.metron.job.JobException)1 JobStatus (org.apache.metron.job.JobStatus)1 RestException (org.apache.metron.rest.RestException)1