Search in sources :

Example 51 with WorkflowInstance

use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.

the class IngestServiceImplTest method testThickClientOldMP.

@Test
public void testThickClientOldMP() throws Exception {
    FileUtils.copyURLToFile(urlPackageOld.toURL(), packageFile);
    InputStream packageStream = null;
    try {
        packageStream = urlPackageOld.toURL().openStream();
        WorkflowInstance instance = service.addZippedMediaPackage(packageStream);
        // Assert.assertEquals(2, mediaPackage.getTracks().length);
        // Assert.assertEquals(3, mediaPackage.getCatalogs().length);
        Assert.assertEquals(workflowInstanceID, instance.getId());
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    } finally {
        IOUtils.closeQuietly(packageStream);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) Test(org.junit.Test)

Example 52 with WorkflowInstance

use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.

the class AbstractEventEndpoint method deleteWorkflow.

@DELETE
@Path("{eventId}/workflows/{workflowId}")
@RestQuery(name = "deleteWorkflow", description = "Deletes a workflow", returnDescription = "The method doesn't return any content", pathParameters = { @RestParameter(name = "eventId", isRequired = true, description = "The event identifier", type = RestParameter.Type.STRING), @RestParameter(name = "workflowId", isRequired = true, description = "The workflow identifier", type = RestParameter.Type.INTEGER) }, reponses = { @RestResponse(responseCode = SC_BAD_REQUEST, description = "When trying to delete the latest workflow of the event."), @RestResponse(responseCode = SC_NOT_FOUND, description = "If the event or the workflow has not been found."), @RestResponse(responseCode = SC_NO_CONTENT, description = "The method does not return any content") })
public Response deleteWorkflow(@PathParam("eventId") String id, @PathParam("workflowId") long wfId) throws SearchIndexException {
    final Opt<Event> optEvent = getIndexService().getEvent(id, getIndex());
    try {
        if (optEvent.isNone()) {
            return notFound("Cannot find an event with id '%s'.", id);
        }
        final WorkflowInstance wfInstance = getWorkflowService().getWorkflowById(wfId);
        if (!wfInstance.getMediaPackage().getIdentifier().toString().equals(id)) {
            return badRequest(String.format("Workflow %s is not associated to event %s", wfId, id));
        }
        if (wfId == optEvent.get().getWorkflowId()) {
            return badRequest(String.format("Cannot delete current workflow %s from event %s." + " Only older workflows can be deleted.", wfId, id));
        }
        getWorkflowService().remove(wfId);
        return Response.noContent().build();
    } catch (WorkflowStateException e) {
        return badRequest("Deleting is not allowed for current workflow state. EventId: " + id);
    } catch (NotFoundException e) {
        return notFound("Workflow not found: '%d'.", wfId);
    } catch (UnauthorizedException e) {
        return forbidden();
    } catch (Exception e) {
        return serverError();
    }
}
Also used : WorkflowStateException(org.opencastproject.workflow.api.WorkflowStateException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) Event(org.opencastproject.index.service.impl.index.event.Event) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) WebApplicationException(javax.ws.rs.WebApplicationException) EventCommentException(org.opencastproject.event.comment.EventCommentException) JSONException(org.codehaus.jettison.json.JSONException) JobEndpointException(org.opencastproject.adminui.exception.JobEndpointException) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) ParseException(java.text.ParseException) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException) UrlSigningException(org.opencastproject.security.urlsigning.exception.UrlSigningException) AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) WorkflowStateException(org.opencastproject.workflow.api.WorkflowStateException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 53 with WorkflowInstance

use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.

the class JobEndpoint method getTasksAsJSON.

/**
 * Returns the single task with the given Id as JSON Object
 *
 * @param id
 * @return The job as JSON Object
 * @throws JobEndpointException
 * @throws NotFoundException
 */
public JObject getTasksAsJSON(long id) throws JobEndpointException, NotFoundException {
    WorkflowInstance instance = getWorkflowById(id);
    // Retrieve submission date with the workflow instance main job
    Date created;
    long duration = 0;
    try {
        Job job = serviceRegistry.getJob(id);
        created = job.getDateCreated();
        Date completed = job.getDateCompleted();
        if (completed == null)
            completed = new Date();
        duration = (completed.getTime() - created.getTime());
    } catch (ServiceRegistryException e) {
        throw new JobEndpointException(String.format("Error when retrieving job %s from the service registry: %s", id, e), e.getCause());
    }
    MediaPackage mp = instance.getMediaPackage();
    List<Field> fields = new ArrayList<>();
    for (String key : instance.getConfigurationKeys()) {
        fields.add(f(key, v(instance.getConfiguration(key), Jsons.BLANK)));
    }
    return obj(f("start", v(created != null ? toUTC(created.getTime()) : "", Jsons.BLANK)), f("state", v(instance.getState(), Jsons.BLANK)), f("description", v(instance.getDescription(), Jsons.BLANK)), f("duration", v(duration, Jsons.BLANK)), f("id", v(instance.getId(), Jsons.BLANK)), f("workflow", v(instance.getTitle(), Jsons.BLANK)), f("workflowId", v(instance.getTemplate(), Jsons.BLANK)), f("title", v(mp.getTitle(), Jsons.BLANK)), f("series", v(mp.getSeries(), Jsons.BLANK)), f("series_title", v(mp.getSeriesTitle(), Jsons.BLANK)), f("license", v(mp.getLicense(), Jsons.BLANK)), f("configuration", obj(fields)));
}
Also used : Field(com.entwinemedia.fn.data.json.Field) JobEndpointException(org.opencastproject.adminui.exception.JobEndpointException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) ArrayList(java.util.ArrayList) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) Job(org.opencastproject.job.api.Job) Date(java.util.Date) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 54 with WorkflowInstance

use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.

the class ExecuteOnceWorkflowOperationHandlerTest method setUp.

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    // Mocking just about everything, just testing the mediapackage parse
    String expectedTypeString = "catalog";
    String catalogId = "catalog-id";
    URI catUri = new URI("http://api.com/catalog");
    catalog = CatalogImpl.newInstance();
    catalog.addTag("engage-download");
    catalog.setIdentifier(catalogId);
    catalog.setURI(catUri);
    WorkflowOperationInstance operation = EasyMock.createMock(WorkflowOperationInstance.class);
    EasyMock.expect(operation.getId()).andReturn(123L).anyTimes();
    EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.EXEC_PROPERTY)).andReturn(null).anyTimes();
    EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.PARAMS_PROPERTY)).andReturn(null).anyTimes();
    EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.LOAD_PROPERTY)).andReturn("123").anyTimes();
    EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.TARGET_FLAVOR_PROPERTY)).andReturn(null).anyTimes();
    EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.TARGET_TAGS_PROPERTY)).andReturn(null).anyTimes();
    EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.OUTPUT_FILENAME_PROPERTY)).andReturn(null).anyTimes();
    EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.SET_WF_PROPS_PROPERTY)).andReturn("false").anyTimes();
    // these two need to supply a real string
    EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.EXPECTED_TYPE_PROPERTY)).andReturn(expectedTypeString).anyTimes();
    EasyMock.replay(operation);
    Id mpId = EasyMock.createMock(Id.class);
    MediaPackage mediaPackage = EasyMock.createMock(MediaPackage.class);
    mediaPackage.add((MediaPackageElement) EasyMock.anyObject());
    EasyMock.expect(mediaPackage.getIdentifier()).andReturn(mpId).anyTimes();
    EasyMock.replay(mediaPackage);
    workspaceService = EasyMock.createMock(Workspace.class);
    EasyMock.expect(workspaceService.moveTo((URI) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(catUri).anyTimes();
    EasyMock.replay(workspaceService);
    workflowInstance = EasyMock.createMock(WorkflowInstance.class);
    EasyMock.expect(workflowInstance.getMediaPackage()).andReturn(mediaPackage).anyTimes();
    EasyMock.expect(workflowInstance.getCurrentOperation()).andStubReturn(operation);
    EasyMock.replay(workflowInstance);
    // Override the waitForStatus method to not block the jobs
    execOnceWOH = new ExecuteOnceWorkflowOperationHandler() {

        @Override
        protected Result waitForStatus(long timeout, Job... jobs) {
            HashMap<Job, Status> map = Stream.mk(jobs).foldl(new HashMap<Job, Status>(), new Fn2<HashMap<Job, Status>, Job, HashMap<Job, Status>>() {

                @Override
                public HashMap<Job, Status> apply(HashMap<Job, Status> a, Job b) {
                    a.put(b, Status.FINISHED);
                    return a;
                }
            });
            return new Result(map);
        }
    };
    execOnceWOH.setWorkspace(workspaceService);
}
Also used : Status(org.opencastproject.job.api.Job.Status) HashMap(java.util.HashMap) Fn2(com.entwinemedia.fn.Fn2) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) URI(java.net.URI) Result(org.opencastproject.job.api.JobBarrier.Result) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Id(org.opencastproject.mediapackage.identifier.Id) Job(org.opencastproject.job.api.Job) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 55 with WorkflowInstance

use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.

the class ConfigurablePublishWorkflowOperationHandlerTest method testNoChannelIdThrowsException.

@Test(expected = WorkflowOperationException.class)
public void testNoChannelIdThrowsException() throws WorkflowOperationException {
    MediaPackage mediapackage = EasyMock.createNiceMock(MediaPackage.class);
    WorkflowOperationInstance workflowOperationInstance = EasyMock.createNiceMock(WorkflowOperationInstance.class);
    WorkflowInstance workflowInstance = EasyMock.createNiceMock(WorkflowInstance.class);
    EasyMock.expect(workflowInstance.getMediaPackage()).andStubReturn(mediapackage);
    EasyMock.expect(workflowInstance.getCurrentOperation()).andStubReturn(workflowOperationInstance);
    JobContext jobContext = EasyMock.createNiceMock(JobContext.class);
    EasyMock.replay(jobContext, mediapackage, workflowInstance, workflowOperationInstance);
    ConfigurablePublishWorkflowOperationHandler configurePublish = new ConfigurablePublishWorkflowOperationHandler();
    configurePublish.start(workflowInstance, jobContext);
}
Also used : WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) MediaPackage(org.opencastproject.mediapackage.MediaPackage) JobContext(org.opencastproject.job.api.JobContext) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) Test(org.junit.Test)

Aggregations

WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)94 Test (org.junit.Test)48 MediaPackage (org.opencastproject.mediapackage.MediaPackage)40 NotFoundException (org.opencastproject.util.NotFoundException)26 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)24 HashMap (java.util.HashMap)22 WorkflowDatabaseException (org.opencastproject.workflow.api.WorkflowDatabaseException)20 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)19 ArrayList (java.util.ArrayList)16 WorkflowQuery (org.opencastproject.workflow.api.WorkflowQuery)16 IOException (java.io.IOException)15 Organization (org.opencastproject.security.api.Organization)15 WorkflowSet (org.opencastproject.workflow.api.WorkflowSet)14 WorkflowException (org.opencastproject.workflow.api.WorkflowException)13 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)12 WorkflowDefinitionImpl (org.opencastproject.workflow.api.WorkflowDefinitionImpl)12 WorkflowOperationResult (org.opencastproject.workflow.api.WorkflowOperationResult)11 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)10 IndexServiceException (org.opencastproject.index.service.exception.IndexServiceException)9 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)9