StateMachineResource { @PUT @Path("/{stateMachineId}/cancel") @Produces(MediaType.APPLICATION_JSON) @Transactional @SelectDataSource(type = DataSourceType.READ_WRITE, storage = Storage.SHARDED) public Response cancelWorkflow(@PathParam("stateMachineId") String stateMachineId, @QueryParam("searchField") String searchField) { StateMachine stateMachine = null; stateMachine = stateMachinesDAO.findById(stateMachineId); if (stateMachine == null) { return Response.status(Response.Status.NOT_FOUND).entity("State machine with id: " + stateMachineId + " not found").build(); } workFlowExecutionController.cancelWorkflow(stateMachine); return Response.status(Response.Status.ACCEPTED).build(); } @Inject  StateMachineResource(EventsDAO eventsDAO, StateMachinePersistenceService stateMachinePersistenceService,
                                AuditDAO auditDAO, StateMachinesDAO stateMachinesDAO, StatesDAO statesDAO,
                                WorkFlowExecutionController workFlowExecutionController, MetricsClient metricsClient,
                                ParallelScatterGatherQueryHelper parallelScatterGatherQueryHelper,
                                EventSchedulerRegistry eventSchedulerRegistry,
                                EventProxyConnector eventProxyConnector,
                                @Named("eventProxyForMigration.enabled") String eventProxyEnabled); @POST @Consumes(MediaType.APPLICATION_JSON) @Timed Response createStateMachine(StateMachineDefinition stateMachineDefinition); @POST @Path("/{machineId}/context/events") @Timed Response submitEvent(@PathParam("machineId") String machineId,
                                @QueryParam("searchField") String searchField,
                                @QueryParam("triggerTime") Long triggerTime,
                                EventData eventData
    ); @POST @Path("/{machineId}/context/eventandstatus") @Timed Response submitEvent(@PathParam("machineId") String machineId,
                                EventAndExecutionData eventAndExecutionData
    ); @POST @Path("/{machineId}/context/eventupdate") @Timed Response updateEvent(@PathParam("machineId") String machineId,
                                EventData eventData
    ); boolean validateEventUpdate(List<Object[]> states); @POST @Path("/{machineId}/{stateId}/status") @Timed Response updateStatus(@PathParam("machineId") String machineId,
                                 @PathParam("stateId") Long stateId,
                                 ExecutionUpdateData executionUpdateData
    ); @POST @Path("/{machineId}/{stateId}/retries/inc") @Transactional @SelectDataSource(type = DataSourceType.READ_WRITE, storage = Storage.SHARDED) Response incrementRetry(@PathParam("machineId") String machineId,
                                   @PathParam("stateId") Long stateId
    ); @POST @Produces(MediaType.APPLICATION_JSON) @Path("/redrivetask/{machineId}/taskId/{taskId}") @Timed Response redriveTask(@PathParam("machineId") String machineId, @PathParam("taskId") Long taskId); @GET @Path("/{machineId}/fsmdata") @Produces(MediaType.APPLICATION_JSON) Response getFsmGraphData(@PathParam("machineId") String machineId); @GET @Path("/{stateMachineName}/states/errored") @Produces(MediaType.APPLICATION_JSON) Response getErroredStates(@PathParam("stateMachineName") String stateMachineName,
                                     @QueryParam("fromTime") String fromTime,
                                     @QueryParam("toTime") String toTime); @GET @Path("/{stateMachineName}/states/listbytime") @Produces(MediaType.APPLICATION_JSON) Response getStatesByTime(@PathParam("stateMachineName") String stateMachineName,
                                    @QueryParam("fromTime") String fromTime,
                                    @QueryParam("toTime") String toTime,
                                    @QueryParam("stateName") String stateName,
                                    @QueryParam("statuses") final List<String> statusStrings); @PUT @Path("/{stateMachineId}/{stateId}/unsideline") @Produces(MediaType.APPLICATION_JSON) @Transactional @SelectDataSource(type = DataSourceType.READ_WRITE, storage = Storage.SHARDED) Response unsidelineState(@PathParam("stateMachineId") String stateMachineId, @PathParam("stateId") Long stateId); @PUT @Path("/{stateMachineId}/cancel") @Produces(MediaType.APPLICATION_JSON) @Transactional @SelectDataSource(type = DataSourceType.READ_WRITE, storage = Storage.SHARDED) Response cancelWorkflow(@PathParam("stateMachineId") String stateMachineId,
                                   @QueryParam("searchField") String searchField); @GET @Path("/{stateMachineId}/info") @Produces(MediaType.APPLICATION_JSON) @Transactional @SelectDataSource(type = DataSourceType.READ_WRITE, storage = Storage.SHARDED) Response getStateMachine(@PathParam("stateMachineId") String stateMachineId,
                                    @QueryParam("searchField") String searchField);  }
@Test public void testCancelWorkflow() throws Exception { final StateMachine sm = stateMachinePersistenceService.createStateMachine("magic_number_1", objectMapper.readValue(this.getClass().getClassLoader().getResource("state_machine_definition.json"), StateMachineDefinition.class)); final String stateMachineId = sm.getId(); State state = sm.getStates().stream().findFirst().get(); state.setStatus(Status.running); statesDAO.updateState(stateMachineId, state); Unirest.put(STATE_MACHINE_RESOURCE_URL + SLASH + stateMachineId + "/cancel").asString(); Thread.sleep(200); StateMachine cancelledSM = stateMachinesDAO.findById(stateMachineId); assertThat(cancelledSM.getStatus()).isEqualTo(StateMachineStatus.cancelled); int cancelledStateCount = 0; for (State st : cancelledSM.getStates()) { if (st.getStatus() == Status.cancelled) cancelledStateCount++; } assertThat(cancelledStateCount).isEqualTo(3); }