Search in sources :

Example 36 with TDPException

use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.

the class AsyncAspect method runAsynchronously.

/**
 * Intercept all the calls to a @RequestMapping method annotated with @AsyncOperation.
 *
 * @param pjp the proceeding join point.
 */
@Around(value = "@annotation(org.springframework.web.bind.annotation.RequestMapping) && @annotation(org.talend.dataprep.async.AsyncOperation)")
public Object runAsynchronously(final ProceedingJoinPoint pjp) {
    String executionId = getExecutionId(pjp);
    AsyncExecution asyncExecution = repository.get(executionId);
    if (asyncExecution == null || asyncExecution.getStatus() != AsyncExecution.Status.RUNNING) {
        // the method is not running actually
        if (executeAsynchronously(pjp) || (asyncExecution != null && asyncExecution.getStatus() == AsyncExecution.Status.NEW)) {
            // we need to launch it asynchronously or asyncMethod is on NEW status (we can  resume it)
            AsyncExecution future = scheduleAsynchroneTask(pjp, asyncExecution != null && asyncExecution.getStatus() == AsyncExecution.Status.NEW);
            LOGGER.debug("Scheduling done, Redirecting to execution queue...");
            // return at once with an HTTP 202 + location to get the progress
            set202HeaderInformation(future);
            LOGGER.debug("Redirection done.");
        } else {
            try {
                return pjp.proceed();
            } catch (Throwable throwable) {
                throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, throwable);
            }
        }
    } else {
        LOGGER.debug("Async Method with id {} is already running", asyncExecution.getId());
        set202HeaderInformation(asyncExecution);
    }
    return null;
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) Around(org.aspectj.lang.annotation.Around)

Example 37 with TDPException

use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.

the class SimpleManagedTaskExecutor method resume.

@Override
public AsyncExecution resume(ManagedTaskCallable task, String executionId, AsyncExecutionResult resultUrl) {
    LOGGER.debug("Resuming execution '{}' from repository '{}'", executionId, repository);
    final AsyncExecution execution = repository.get(executionId);
    if (execution == null) {
        LOGGER.error("Execution #{} can be resumed (not found).", executionId);
        throw new TDPException(TransformationErrorCodes.UNABLE_TO_RESUME_EXECUTION, ExceptionContext.withBuilder().put("id", executionId).build());
    } else if (execution.getStatus() != AsyncExecution.Status.RUNNING) {
        // Execution is expected to be created as "RUNNING" before the dispatcher resumes it.
        LOGGER.error("Execution #{} can be resumed (status is {}).", execution.getStatus());
        throw new TDPException(TransformationErrorCodes.UNABLE_TO_RESUME_EXECUTION, ExceptionContext.withBuilder().put("id", executionId).build());
    }
    // Wrap callable to get the running status.
    final Callable wrapper = wrapTaskWithProgressInformation(task, execution);
    execution.setResult(resultUrl);
    ListenableFuture future = delegate.submitListenable(wrapper);
    future.addCallback(new AsyncListenableFutureCallback(execution));
    futures.put(execution.getId(), future);
    LOGGER.debug("Execution {} resumed for execution.", execution.getId());
    return execution;
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) ListenableFuture(org.springframework.util.concurrent.ListenableFuture) Callable(java.util.concurrent.Callable)

Example 38 with TDPException

use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.

the class MailToCommand method run.

@Override
protected Void run() throws Exception {
    try {
        String body = "";
        body += "Sender=" + mailDetails.getMail() + "<br/>";
        body += "Type=" + mailDetails.getType() + "<br/>";
        body += "Severity=" + mailDetails.getSeverity() + "<br/>";
        body += "Description=" + mailDetails.getDescription() + "<br/>";
        body += "Version=" + versionService.version() + "<br/>";
        feedbackSender.send(mailDetails.getTitle(), body, mailDetails.getMail());
    } catch (Exception e) {
        throw new TDPException(APIErrorCodes.UNABLE_TO_SEND_MAIL, e);
    }
    return null;
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) TDPException(org.talend.dataprep.exception.TDPException)

Example 39 with TDPException

use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.

the class OneNotBlankValidator method isValid.

@Override
public boolean isValid(final Object value, final ConstraintValidatorContext context) {
    try {
        for (final String name : fieldsName) {
            final String prop = BeanUtils.getProperty(value, name);
            if (isNotBlank(prop)) {
                return true;
            }
        }
    } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
        throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
    }
    context.disableDefaultConstraintViolation();
    context.buildConstraintViolationWithTemplate(context.getDefaultConstraintMessageTemplate()).addPropertyNode(fieldsName[0]).addConstraintViolation();
    return false;
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 40 with TDPException

use of org.talend.dataprep.exception.TDPException in project data-prep by Talend.

the class ErrorMessageTest method shouldReturnRightErrorMessageWhenHttpStatusIs500.

@Test
public void shouldReturnRightErrorMessageWhenHttpStatusIs500() {
    // given
    ErrorCode errorCode = new ErrorCode() {

        @Override
        public String getProduct() {
            return "TDP";
        }

        @Override
        public String getGroup() {
            return "API";
        }

        @Override
        public int getHttpStatus() {
            return 500;
        }

        @Override
        public Collection<String> getExpectedContextEntries() {
            return Collections.emptyList();
        }

        @Override
        public String getCode() {
            return null;
        }
    };
    TDPException exception = new TDPException(errorCode, null, null);
    // then
    assertEquals(errorCode, exception.getCode());
    assertEquals("An unexpected error occurred and we could not complete your last operation. You can continue to use Data Preparation", exception.getMessage());
    assertEquals("An error has occurred", exception.getMessageTitle());
    assertFalse(exception.getContext().entries().iterator().hasNext());
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) ErrorCode(org.talend.daikon.exception.error.ErrorCode) Test(org.junit.Test) ServiceBaseTest(org.talend.ServiceBaseTest)

Aggregations

TDPException (org.talend.dataprep.exception.TDPException)123 IOException (java.io.IOException)43 InputStream (java.io.InputStream)25 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)21 Test (org.junit.Test)17 ApiOperation (io.swagger.annotations.ApiOperation)16 Timed (org.talend.dataprep.metrics.Timed)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 DataSet (org.talend.dataprep.api.dataset.DataSet)13 ServiceBaseTest (org.talend.ServiceBaseTest)11 StringEntity (org.apache.http.entity.StringEntity)10 JsonParser (com.fasterxml.jackson.core.JsonParser)9 URISyntaxException (java.net.URISyntaxException)9 HttpPost (org.apache.http.client.methods.HttpPost)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)9 List (java.util.List)8 URIBuilder (org.apache.http.client.utils.URIBuilder)8 Marker (org.slf4j.Marker)8 ErrorCode (org.talend.daikon.exception.error.ErrorCode)8