public MessageInput getPersisted(String inputId) {
    for (MessageInput input : getAllPersisted()) {
      if (input.getId().equals(inputId)) return input;
    }

    return null;
  }
  public InputState stop(MessageInput input) {
    InputState inputState = getRunningInputState(input.getId());

    if (inputState != null) {
      try {
        input.stop();
      } catch (Exception e) {
        LOG.warn("Stopping input <{}> failed, removing anyway: {}", input.getId(), e);
      }
      removeFromRunning(input);
      inputState.setState(InputState.InputStateType.STOPPED);
      finishedStop(inputState);
    }

    return inputState;
  }
  @POST
  @Timed
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  @ApiOperation(value = "Add an extractor to an input", response = ExtractorCreated.class)
  @ApiResponses(
      value = {
        @ApiResponse(code = 404, message = "No such input on this node."),
        @ApiResponse(code = 400, message = "No such extractor type."),
        @ApiResponse(code = 400, message = "Field the extractor should write on is reserved."),
        @ApiResponse(code = 400, message = "Missing or invalid configuration.")
      })
  public Response create(
      @ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId,
      @ApiParam(name = "JSON body", required = true) @Valid @NotNull CreateExtractorRequest cer)
      throws NotFoundException {
    checkPermission(RestPermissions.INPUTS_EDIT, inputId);

    final MessageInput input = inputs.getRunningInput(inputId);
    if (input == null) {
      LOG.error("Input <{}> not found.", inputId);
      throw new javax.ws.rs.NotFoundException();
    }

    final Input mongoInput = inputService.find(input.getPersistId());
    final String id = new com.eaio.uuid.UUID().toString();
    final Extractor extractor = buildExtractorFromRequest(cer, id);

    try {
      inputService.addExtractor(mongoInput, extractor);
    } catch (ValidationException e) {
      LOG.error("Extractor persist validation failed.", e);
      throw new BadRequestException(e);
    }

    final String msg =
        "Added extractor <"
            + id
            + "> of type ["
            + cer.extractorType()
            + "] to input <"
            + inputId
            + ">.";
    LOG.info(msg);
    activityWriter.write(new Activity(msg, ExtractorsResource.class));

    final ExtractorCreated result = ExtractorCreated.create(id);
    final URI extractorUri =
        getUriBuilderToSelf().path(ExtractorsResource.class).path("{inputId}").build(input.getId());

    return Response.created(extractorUri).entity(result).build();
  }
  protected void handleLaunchException(Throwable e, MessageInput input, InputState inputState) {
    StringBuilder msg =
        new StringBuilder(
            "The ["
                + input.getClass().getCanonicalName()
                + "] input with ID <"
                + input.getId()
                + "> misfired. Reason: ");

    String causeMsg = extractMessageCause(e);

    msg.append(causeMsg);

    LOG.error(msg.toString(), e);

    // Clean up.
    // cleanInput(input);

    inputState.setState(InputState.InputStateType.FAILED);
    inputState.setDetailedMessage(causeMsg);
  }