Search in sources :

Example 1 with Timed

use of org.talend.dataprep.metrics.Timed in project data-prep by Talend.

the class CommonAPI method listErrors.

/**
 * Describe the supported error codes.
 *
 * @param output the http response.
 */
@RequestMapping(value = "/api/errors", method = RequestMethod.GET, produces = APPLICATION_JSON_VALUE)
@ApiOperation(value = "Get all supported errors.", notes = "Returns the list of all supported errors.")
@Timed
public void listErrors(final OutputStream output) throws IOException {
    LOG.debug("Listing supported error codes");
    JsonFactory factory = new JsonFactory();
    JsonGenerator generator = factory.createGenerator(output);
    generator.setCodec(mapper);
    // start the errors array
    generator.writeStartArray();
    // write the direct known errors
    writeErrorsFromEnum(generator, CommonErrorCodes.values());
    writeErrorsFromEnum(generator, APIErrorCodes.values());
    // get dataset api errors
    HystrixCommand<InputStream> datasetErrors = getCommand(ErrorList.class, GenericCommand.DATASET_GROUP, DATASET);
    try (InputStream errorsInput = datasetErrors.execute()) {
        writeErrorsFromApi(generator, errorsInput);
    }
    // get preparation api errors
    HystrixCommand<InputStream> preparationErrors = getCommand(ErrorList.class, GenericCommand.PREPARATION_GROUP, PREPARATION);
    try (InputStream errorsInput = preparationErrors.execute()) {
        writeErrorsFromApi(generator, errorsInput);
    }
    // get transformation api errors
    HystrixCommand<InputStream> transformationErrors = getCommand(ErrorList.class, GenericCommand.TRANSFORM_GROUP, TRANSFORMATION);
    try (InputStream errorsInput = transformationErrors.execute()) {
        writeErrorsFromApi(generator, errorsInput);
    }
    // close the errors array
    generator.writeEndArray();
    generator.flush();
}
Also used : InputStream(java.io.InputStream) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) Timed(org.talend.dataprep.metrics.Timed) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Timed

use of org.talend.dataprep.metrics.Timed in project data-prep by Talend.

the class MailServiceAPI method mailTo.

@RequestMapping(value = "/api/mail", method = PUT)
@ApiOperation(value = "Send feedback to Talend")
@Timed
public void mailTo(@RequestBody MailDetails mailDetails) {
    if (mailDetails.isEmpty()) {
        throw new TDPException(APIErrorCodes.UNABLE_TO_GET_MAIL_DETAILS);
    }
    try {
        final HystrixCommand<Void> sendFeedback = getCommand(MailToCommand.class, mailDetails);
        sendFeedback.execute();
    } catch (Exception e) {
        throw new TDPException(APIErrorCodes.UNABLE_TO_SEND_MAIL, e);
    }
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) TDPException(org.talend.dataprep.exception.TDPException) Timed(org.talend.dataprep.metrics.Timed) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Timed

use of org.talend.dataprep.metrics.Timed in project data-prep by Talend.

the class PreparationAPI method updatePreparationAction.

// @formatter:off
@RequestMapping(value = "/api/preparations/{preparationId}/actions/{stepId}", method = PUT, produces = APPLICATION_JSON_VALUE)
@ApiOperation(value = "Updates an action in the preparation.", notes = "Does not return any value, client may expect successful operation based on HTTP status code.")
@Timed
public void updatePreparationAction(@ApiParam(name = "preparationId", value = "Preparation id.") @PathVariable(value = "preparationId") final String preparationId, @ApiParam(name = "stepId", value = "Step id in the preparation.") @PathVariable(value = "stepId") final String stepId, @ApiParam("New content for the action.") @RequestBody final AppendStep step) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Updating preparation action at step #{} (pool: {} )...", stepId, getConnectionStats());
    }
    // get the preparation
    Preparation preparation = internalGetPreparation(preparationId);
    // get the preparation actions for up to the updated action
    final int stepIndex = preparation.getSteps().stream().map(Step::getId).collect(toList()).indexOf(stepId);
    final String parentStepId = preparation.getSteps().get(stepIndex - 1).id();
    final PreparationGetActions getActionsCommand = getCommand(PreparationGetActions.class, preparationId, parentStepId);
    // get the diff
    final DiffMetadata diffCommand = getCommand(DiffMetadata.class, preparation.getDataSetId(), preparationId, step.getActions(), getActionsCommand);
    // get the update action command and execute it
    final HystrixCommand<Void> command = getCommand(PreparationUpdateAction.class, preparationId, stepId, step, diffCommand);
    command.execute();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Updated preparation action at step #{} (pool: {} )...", stepId, getConnectionStats());
    }
}
Also used : PreparationGetActions(org.talend.dataprep.command.preparation.PreparationGetActions) Timed(org.talend.dataprep.metrics.Timed) ApiOperation(io.swagger.annotations.ApiOperation)

Example 4 with Timed

use of org.talend.dataprep.metrics.Timed in project data-prep by Talend.

the class UpgradeAPI method check.

@RequestMapping(value = "/api/upgrade/check", method = GET)
@ApiOperation(value = "Checks if a newer versions are available and returns them as JSON.", produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
@PublicAPI
public Stream<UpgradeServerVersion> check() {
    // defensive programming
    if (StringUtils.isBlank(upgradeVersionLocation)) {
        return Stream.empty();
    }
    try {
        // Get current version
        final Version parsedCurrentVersion = fromInternal(service.version());
        // POST to URL that serves a JSON Version object
        LOGGER.debug("Contacting upgrade server @ '{}'", upgradeVersionLocation);
        List<UpgradeServerVersion> versions = fetchServerUpgradeVersions(service.version());
        LOGGER.debug("{} available version(s) returned by update server: {}", versions.size(), toString(versions));
        // Compare current version with available and filter new versions
        return versions.stream().filter(v -> Version.valueOf(v.getVersion()).greaterThan(parsedCurrentVersion));
    } catch (Exception e) {
        LOGGER.error("Unable to check for new version (message: {}).", e.getMessage());
        LOGGER.debug("Exception occurred during new version check. ", e);
        return Stream.empty();
    }
}
Also used : Version(com.github.zafarkhaja.semver.Version) UpgradeServerVersion(org.talend.dataprep.api.service.upgrade.UpgradeServerVersion) UpgradeServerVersion(org.talend.dataprep.api.service.upgrade.UpgradeServerVersion) IOException(java.io.IOException) Timed(org.talend.dataprep.metrics.Timed) ApiOperation(io.swagger.annotations.ApiOperation) PublicAPI(org.talend.dataprep.security.PublicAPI) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Timed

use of org.talend.dataprep.metrics.Timed in project data-prep by Talend.

the class VersionServiceAPI method allVersions.

/**
 * Returns all the versions of the different services (api, dataset, preparation and transformation) and the global
 * application version.
 *
 * @return an array of service versions
 */
@RequestMapping(value = "/api/version", method = GET)
@ApiOperation(value = "Get the version of all services (including underlying low level services)", produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
@PublicAPI
public BuildDetails allVersions() {
    List<Version> versions = new ArrayList<>();
    for (VersionsSupplier versionsSupplier : versionsSuppliers) {
        versions.addAll(versionsSupplier.getVersions());
    }
    CollectionUtils.filter(versions, PredicateUtils.notNullPredicate());
    return new BuildDetails(applicationVersion, versions.toArray(new Version[versions.size()]));
}
Also used : BuildDetails(org.talend.dataprep.info.BuildDetails) Version(org.talend.dataprep.info.Version) ArrayList(java.util.ArrayList) VersionsSupplier(org.talend.dataprep.api.service.version.VersionsSupplier) Timed(org.talend.dataprep.metrics.Timed) ApiOperation(io.swagger.annotations.ApiOperation) PublicAPI(org.talend.dataprep.security.PublicAPI) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Timed (org.talend.dataprep.metrics.Timed)30 ApiOperation (io.swagger.annotations.ApiOperation)29 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)24 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)17 TDPException (org.talend.dataprep.exception.TDPException)16 InputStream (java.io.InputStream)9 IOException (java.io.IOException)8 PublicAPI (org.talend.dataprep.security.PublicAPI)8 Stream (java.util.stream.Stream)7 ApiParam (io.swagger.annotations.ApiParam)6 OutputStream (java.io.OutputStream)6 PipedInputStream (java.io.PipedInputStream)6 List (java.util.List)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 Marker (org.slf4j.Marker)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 PathVariable (org.springframework.web.bind.annotation.PathVariable)6 GET (org.springframework.web.bind.annotation.RequestMethod.GET)6 PUT (org.springframework.web.bind.annotation.RequestMethod.PUT)6