Search in sources :

Example 66 with Job

use of org.opencastproject.job.api.Job in project opencast by opencast.

the class WaveformWorkflowOperationHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    handler = new WaveformWorkflowOperationHandler() {

        @Override
        protected JobBarrier.Result waitForStatus(Job... jobs) throws IllegalStateException, IllegalArgumentException {
            JobBarrier.Result result = EasyMock.createNiceMock(JobBarrier.Result.class);
            EasyMock.expect(result.isSuccess()).andReturn(true).anyTimes();
            EasyMock.replay(result);
            return result;
        }
    };
    track = new TrackImpl();
    track.setFlavor(MediaPackageElementFlavor.parseFlavor("xy/source"));
    track.setAudio(Arrays.asList(null, null));
    MediaPackageBuilder builder = new MediaPackageBuilderImpl();
    MediaPackage mediaPackage = builder.createNew();
    mediaPackage.setIdentifier(new IdImpl("123-456"));
    mediaPackage.add(track);
    instance = EasyMock.createNiceMock(WorkflowOperationInstanceImpl.class);
    EasyMock.expect(instance.getConfiguration("target-flavor")).andReturn("*/*").anyTimes();
    EasyMock.expect(instance.getConfiguration("target-tags")).andReturn("a,b,c").anyTimes();
    workflow = EasyMock.createNiceMock(WorkflowInstanceImpl.class);
    EasyMock.expect(workflow.getMediaPackage()).andReturn(mediaPackage).anyTimes();
    EasyMock.expect(workflow.getCurrentOperation()).andReturn(instance).anyTimes();
    Attachment payload = new AttachmentImpl();
    payload.setIdentifier("x");
    payload.setFlavor(MediaPackageElementFlavor.parseFlavor("xy/source"));
    Job job = new JobImpl(0);
    job.setPayload(MediaPackageElementParser.getAsXml(payload));
    WaveformService waveformService = EasyMock.createNiceMock(WaveformService.class);
    EasyMock.expect(waveformService.createWaveformImage(EasyMock.anyObject())).andReturn(job);
    Workspace workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.replay(waveformService, workspace, workflow);
    handler.setWaveformService(waveformService);
    handler.setWorkspace(workspace);
}
Also used : JobImpl(org.opencastproject.job.api.JobImpl) TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl) Attachment(org.opencastproject.mediapackage.Attachment) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) MediaPackageBuilderImpl(org.opencastproject.mediapackage.MediaPackageBuilderImpl) MediaPackage(org.opencastproject.mediapackage.MediaPackage) AttachmentImpl(org.opencastproject.mediapackage.attachment.AttachmentImpl) WaveformService(org.opencastproject.waveform.api.WaveformService) Job(org.opencastproject.job.api.Job) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 67 with Job

use of org.opencastproject.job.api.Job in project opencast by opencast.

the class VideoEditorServiceEndpoint method processSmil.

@POST
@Path("/process-smil")
@Produces({ MediaType.APPLICATION_XML })
@RestQuery(name = "processsmil", description = "Create smil processing jobs.", returnDescription = "Smil processing jobs.", restParameters = { @RestParameter(name = "smil", type = RestParameter.Type.TEXT, description = "Smil document to process.", isRequired = true) }, reponses = { @RestResponse(description = "Smil processing jobs created successfully.", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "Internal server error.", responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR) })
public Response processSmil(@FormParam("smil") String smilStr) {
    Smil smil;
    try {
        smil = smilService.fromXml(smilStr).getSmil();
        List<Job> jobs = videoEditorService.processSmil(smil);
        return Response.ok(new JaxbJobList(jobs)).build();
    } catch (Exception ex) {
        return Response.serverError().entity(ex.getMessage()).build();
    }
}
Also used : Smil(org.opencastproject.smil.entity.api.Smil) Job(org.opencastproject.job.api.Job) JaxbJobList(org.opencastproject.job.api.JaxbJobList) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 68 with Job

use of org.opencastproject.job.api.Job in project opencast by opencast.

the class VideoEditorTest method setUp.

/**
 * Setup for the video editor service, including creation of a mock workspace and all dependencies.
 *
 * @throws Exception
 *           if setup fails
 */
@Before
public void setUp() throws Exception {
    File tmpDir = folder.newFolder(getClass().getName());
    // output file
    tempFile1 = new File(tmpDir, "testoutput.mp4");
    /* mock the workspace for the input/output file */
    // workspace.get(new URI(sourceTrackUri));
    Workspace workspace = EasyMock.createMock(Workspace.class);
    EasyMock.expect(workspace.rootDirectory()).andReturn(tmpDir.getAbsolutePath());
    EasyMock.expect(workspace.get(track1.getURI())).andReturn(new File(track1.getURI())).anyTimes();
    EasyMock.expect(workspace.get(track2.getURI())).andReturn(new File(track2.getURI())).anyTimes();
    EasyMock.expect(workspace.putInCollection(EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyObject(InputStream.class))).andAnswer(() -> {
        InputStream in = (InputStream) EasyMock.getCurrentArguments()[2];
        IOUtils.copy(in, new FileOutputStream(tempFile1));
        return tempFile1.toURI();
    });
    /* mock the role/org/security dependencies */
    User anonymous = new JaxbUser("anonymous", "test", new DefaultOrganization(), new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, new DefaultOrganization()));
    UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
    EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(anonymous).anyTimes();
    Organization organization = new DefaultOrganization();
    OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
    EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(anonymous).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
    /* mock the osgi init for the video editor itself */
    BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
    File storageDir = folder.newFolder();
    logger.info("storageDir: {}", storageDir);
    EasyMock.expect(bc.getProperty("org.opencastproject.storage.dir")).andReturn(storageDir.getPath()).anyTimes();
    EasyMock.expect(bc.getProperty("org.opencastproject.composer.ffmpegpath")).andReturn(FFMPEG_BINARY).anyTimes();
    EasyMock.expect(bc.getProperty(FFmpegAnalyzer.FFPROBE_BINARY_CONFIG)).andReturn("ffprobe").anyTimes();
    ComponentContext cc = EasyMock.createNiceMock(ComponentContext.class);
    EasyMock.expect(cc.getBundleContext()).andReturn(bc).anyTimes();
    EasyMock.replay(bc, cc, workspace, userDirectoryService, organizationDirectoryService, securityService);
    /* mock inspector output so that the job will alway pass */
    String sourceTrackXml = "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" + "<track xmlns=\"http://mediapackage.opencastproject.org\" type='presentation/source' id='deadbeef-a926-4ba9-96d9-2fafbcc30d2a'>" + "<audio id='audio-1'><encoder type='MP3 (MPEG audio layer 3)'/><channels>2</channels>" + "<bitrate>96000.0</bitrate></audio><video id='video-1'><device/>" + "<encoder type='FLV / Sorenson Spark / Sorenson H.263 (Flash Video)'/>" + "<bitrate>512000.0</bitrate><framerate>15.0</framerate>" + "<resolution>854x480</resolution></video>" + "<mimetype>video/mpeg</mimetype><url>video.mp4</url></track>";
    inspectedTrack = (Track) MediaPackageElementParser.getFromXml(sourceTrackXml);
    veditor = new VideoEditorServiceImpl() {

        @Override
        protected Job inspect(Job job, URI workspaceURI) throws MediaInspectionException, ProcessFailedException {
            Job inspectionJob = EasyMock.createNiceMock(Job.class);
            try {
                EasyMock.expect(inspectionJob.getPayload()).andReturn(MediaPackageElementParser.getAsXml(inspectedTrack));
            } catch (MediaPackageException e) {
                throw new MediaInspectionException(e);
            }
            EasyMock.replay(inspectionJob);
            return inspectionJob;
        }
    };
    /* set up video editor */
    veditor.activate(cc);
    veditor.setWorkspace(workspace);
    veditor.setSecurityService(securityService);
    veditor.setUserDirectoryService(userDirectoryService);
    veditor.setSmilService(smilService);
    veditor.setOrganizationDirectoryService(organizationDirectoryService);
    serviceRegistry = EasyMock.createMock(ServiceRegistry.class);
    final Capture<String> type = EasyMock.newCapture();
    final Capture<String> operation = EasyMock.newCapture();
    final Capture<List<String>> args = EasyMock.newCapture();
    EasyMock.expect(serviceRegistry.createJob(capture(type), capture(operation), capture(args), EasyMock.anyFloat())).andAnswer(() -> {
        Job job = new JobImpl(0);
        logger.error("type: {}", type.getValue());
        job.setJobType(type.getValue());
        job.setOperation(operation.getValue());
        job.setArguments(args.getValue());
        job.setPayload(veditor.process(job));
        return job;
    }).anyTimes();
    EasyMock.replay(serviceRegistry);
    veditor.setServiceRegistry(serviceRegistry);
}
Also used : User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) JaxbUser(org.opencastproject.security.api.JaxbUser) URI(java.net.URI) MediaInspectionException(org.opencastproject.inspection.api.MediaInspectionException) SecurityService(org.opencastproject.security.api.SecurityService) List(java.util.List) ArrayList(java.util.ArrayList) Job(org.opencastproject.job.api.Job) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) JobImpl(org.opencastproject.job.api.JobImpl) ComponentContext(org.osgi.service.component.ComponentContext) InputStream(java.io.InputStream) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) JaxbRole(org.opencastproject.security.api.JaxbRole) FileOutputStream(java.io.FileOutputStream) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) ProcessFailedException(org.opencastproject.videoeditor.api.ProcessFailedException) File(java.io.File) Workspace(org.opencastproject.workspace.api.Workspace) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 69 with Job

use of org.opencastproject.job.api.Job in project opencast by opencast.

the class ServiceRegistryInMemoryImpl method getCurrentHostLoads.

@Override
public SystemLoad getCurrentHostLoads() {
    SystemLoad systemLoad = new SystemLoad();
    for (String host : hosts.keySet()) {
        NodeLoad node = new NodeLoad();
        node.setHost(host);
        for (ServiceRegistration service : services.get(host)) {
            if (service.isInMaintenanceMode() || !service.isOnline()) {
                continue;
            }
            Set<Job> hostJobs = jobHosts.get(service);
            float loadSum = 0.0f;
            if (hostJobs != null) {
                for (Job job : hostJobs) {
                    if (job.getStatus() != null && JOB_STATUSES_INFLUENCING_LOAD_BALANCING.contains(job.getStatus())) {
                        loadSum += job.getJobLoad();
                    }
                }
            }
            node.setLoadFactor(node.getLoadFactor() + loadSum);
        }
        systemLoad.addNodeLoad(node);
    }
    return systemLoad;
}
Also used : JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) NodeLoad(org.opencastproject.serviceregistry.api.SystemLoad.NodeLoad)

Example 70 with Job

use of org.opencastproject.job.api.Job in project opencast by opencast.

the class ServiceRegistryInMemoryImpl method updateInternal.

private Job updateInternal(Job job) {
    Date now = new Date();
    Status status = job.getStatus();
    if (job.getDateCreated() == null) {
        job.setDateCreated(now);
    }
    if (Status.RUNNING.equals(status)) {
        job.setDateStarted(now);
        job.setQueueTime(now.getTime() - job.getDateCreated().getTime());
    } else if (Status.FAILED.equals(status)) {
        // failed jobs may not have even started properly
        job.setDateCompleted(now);
        if (job.getDateStarted() != null) {
            job.setRunTime(now.getTime() - job.getDateStarted().getTime());
        }
    } else if (Status.FINISHED.equals(status)) {
        if (job.getDateStarted() == null) {
            // Some services (e.g. ingest) don't use job dispatching, since they start immediately and handle their own
            // lifecycle. In these cases, if the start date isn't set, use the date created as the start date
            job.setDateStarted(job.getDateCreated());
        }
        job.setDateCompleted(now);
        job.setRunTime(now.getTime() - job.getDateStarted().getTime());
        // Cleanup local list of jobs assigned to a specific service
        for (Entry<String, List<ServiceRegistrationInMemoryImpl>> service : services.entrySet()) {
            for (ServiceRegistrationInMemoryImpl srv : service.getValue()) {
                Set<Job> jobs = jobHosts.get(srv);
                if (jobs != null) {
                    Set<Job> updatedJobs = new HashSet<>();
                    for (Job savedJob : jobs) {
                        if (savedJob.getId() != job.getId())
                            updatedJobs.add(savedJob);
                    }
                    jobHosts.put(srv, updatedJobs);
                }
            }
        }
    }
    return job;
}
Also used : Status(org.opencastproject.job.api.Job.Status) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) Date(java.util.Date) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

Job (org.opencastproject.job.api.Job)282 MediaPackage (org.opencastproject.mediapackage.MediaPackage)89 ArrayList (java.util.ArrayList)82 Test (org.junit.Test)82 URI (java.net.URI)68 NotFoundException (org.opencastproject.util.NotFoundException)58 Track (org.opencastproject.mediapackage.Track)56 JaxbJob (org.opencastproject.job.api.JaxbJob)52 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)51 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)50 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)49 IOException (java.io.IOException)45 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)42 HttpPost (org.apache.http.client.methods.HttpPost)33 Path (javax.ws.rs.Path)31 Produces (javax.ws.rs.Produces)30 JobBarrier (org.opencastproject.job.api.JobBarrier)30 RestQuery (org.opencastproject.util.doc.rest.RestQuery)30 POST (javax.ws.rs.POST)29 HttpResponse (org.apache.http.HttpResponse)29