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);
}
}
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();
}
}
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)));
}
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);
}
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);
}
Aggregations