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();
}
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);
}
}
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());
}
}
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();
}
}
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()]));
}
Aggregations