/** * Ensures the truth of an condition involving one or more parameters to the calling method. * * @param condition a boolean expression * @param errorMessage The exception message use if the input condition is not valid * @throws com.netflix.conductor.core.execution.ApplicationException if input condition is not valid */ public static void checkArgument(boolean condition, String errorMessage){ if(!condition) { throw new ApplicationException(ApplicationException.Code.INVALID_INPUT, errorMessage); } }
/** * Used to determine if the exception is thrown due to a transient failure * and the operation is expected to succeed upon retrying. * * @param throwableException the exception that is thrown * @return true - if the exception is a transient failure * false - if the exception is non-transient */ private boolean isTransientException(Throwable throwableException) { if (throwableException != null) { return !((throwableException instanceof UnsupportedOperationException) || (throwableException instanceof ApplicationException && ((ApplicationException) throwableException).getCode() != ApplicationException.Code.BACKEND_ERROR)); } return true; }
@Override public Response toResponse(Throwable exception) { LOGGER.error(String.format("Error %s url: '%s'", exception.getClass().getSimpleName(), uriInfo.getPath()), exception); Monitors.error("error", "error"); ApplicationException applicationException = null; if (exception instanceof IllegalArgumentException || exception instanceof InvalidFormatException) { applicationException = new ApplicationException(Code.INVALID_INPUT, exception.getMessage(), exception); } else { applicationException = new ApplicationException(Code.INTERNAL_ERROR, exception.getMessage(), exception); } Map<String, Object> entityMap = applicationException.toMap(); entityMap.put("instance", host); return Response.status(applicationException.getHttpStatusCode()).entity(entityMap).type(MediaType.APPLICATION_JSON_TYPE).build(); }
@Override public Response toResponse(ApplicationException e) { logException(e); Response.ResponseBuilder responseBuilder = Response.status(e.getHttpStatusCode()); if(e.getHttpStatusCode() == 500) { Monitors.error("error", "error"); } Map<String, Object> entityMap = e.toMap(); entityMap.put("instance", host); responseBuilder.type(MediaType.APPLICATION_JSON_TYPE); responseBuilder.entity(entityMap); return responseBuilder.build(); }
if(e.getCode().equals(Code.NOT_FOUND)) { logger.error("Workflow ID specified is not valid for this environment: " + e.getMessage()); queue.ack(Arrays.asList(msg)); logger.error(e.getMessage(), e); } catch(Exception e) { logger.error(e.getMessage(), e);
@Test(expected = ApplicationException.class) public void testApplicationExceptionStartWorkflowMessageParam() { try { when(mockMetadata.getWorkflowDef(anyString(), anyInt())).thenReturn(null); Map<String, Object> input = new HashMap<>(); input.put("1", "abc"); workflowService.startWorkflow("test", 1, "c123", input); } catch (ApplicationException ex) { String message = "No such workflow found by name: test, version: 1"; assertEquals(message, ex.getMessage()); throw ex; } fail("ApplicationException did not throw!"); }
public String getTrace(){ ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); this.printStackTrace(ps); ps.flush(); return new String(baos.toByteArray()); }
public Map<String, Object> toMap(){ HashMap<String, Object> map = new LinkedHashMap<>(); map.put("code", code.name()); map.put("message", super.getMessage()); map.put("retryable", isRetryable()); return map; } }
if(e.getCode().equals(Code.NOT_FOUND)) { logger.error("Workflow ID specified is not valid for this environment: " + e.getMessage()); queue.ack(Arrays.asList(msg)); logger.error(e.getMessage(), e); } catch(Exception e) { logger.error(e.getMessage(), e);
@Override public Response toResponse(ApplicationException e) { logException(e); Response.ResponseBuilder responseBuilder = Response.status(e.getHttpStatusCode()); if(e.getHttpStatusCode() == 500) { Monitors.error("error", "error"); } Map<String, Object> entityMap = e.toMap(); entityMap.put("instance", host); responseBuilder.type(MediaType.APPLICATION_JSON_TYPE); responseBuilder.entity(entityMap); return responseBuilder.build(); }
@Test(expected = ApplicationException.class) public void testApplicationExceptionGetExecutionStatus() { try { when(mockExecutionService.getExecutionStatus(anyString(), anyBoolean())).thenReturn(null); workflowService.getExecutionStatus("w123", true); } catch (ApplicationException ex) { String message = "Workflow with Id: w123 not found."; assertEquals(message, ex.getMessage()); throw ex; } fail("ApplicationException did not throw!"); }
public String getTrace(){ ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); this.printStackTrace(ps); ps.flush(); return new String(baos.toByteArray()); }
public Map<String, Object> toMap(){ HashMap<String, Object> map = new LinkedHashMap<>(); map.put("code", code.name()); map.put("message", super.getMessage()); map.put("retryable", isRetryable()); return map; } }
public static void checkNotNullOrEmpty(Collection<?> collection, String errorMessage){ if(collection == null || collection.isEmpty()) { throw new ApplicationException(ApplicationException.Code.INVALID_INPUT, errorMessage); } }
private TaskDef notFoundSafeGetTaskDef(String name) { try { return metadataService.getTaskDef(name); } catch (ApplicationException e) { if (e.getCode() == ApplicationException.Code.NOT_FOUND) { return null; } else { throw e; } } }
@Override public Response toResponse(Throwable exception) { LOGGER.error(String.format("Error %s url: '%s'", exception.getClass().getSimpleName(), uriInfo.getPath()), exception); Monitors.error("error", "error"); ApplicationException applicationException = null; if (exception instanceof IllegalArgumentException || exception instanceof InvalidFormatException) { applicationException = new ApplicationException(Code.INVALID_INPUT, exception.getMessage(), exception); } else { applicationException = new ApplicationException(Code.INTERNAL_ERROR, exception.getMessage(), exception); } Map<String, Object> entityMap = applicationException.toMap(); entityMap.put("instance", host); return Response.status(applicationException.getHttpStatusCode()).entity(entityMap).type(MediaType.APPLICATION_JSON_TYPE).build(); }
protected <T> T readValue(String json, Class<T> tClass) { try { return objectMapper.readValue(json, tClass); } catch (IOException ex) { throw new ApplicationException(ApplicationException.Code.INTERNAL_ERROR, ex); } }
@Override public List<EventHandler> getEventHandlersForEvent(String event, boolean activeOnly) { String key = nsKey(EVENT_HANDLERS_BY_EVENT, event); Set<String> names = dynoClient.smembers(key); List<EventHandler> handlers = new LinkedList<>(); for(String name : names) { try { EventHandler eventHandler = getEventHandler(name); recordRedisDaoEventRequests("getEventHandler", event); if(eventHandler.getEvent().equals(event) && (!activeOnly || eventHandler.isActive())) { handlers.add(eventHandler); } } catch (ApplicationException ae) { if(ae.getCode() == Code.NOT_FOUND) {} throw ae; } } return handlers; }
protected String toJson(Object value) { try { return objectMapper.writeValueAsString(value); } catch (JsonProcessingException ex) { throw new ApplicationException(ApplicationException.Code.INTERNAL_ERROR, ex); } }
if(e.getCode().equals(Code.NOT_FOUND)) { logger.error("Workflow NOT found for id: " + workflowId, e); queueDAO.remove(WorkflowExecutor.DECIDER_QUEUE, workflowId);