use of io.swagger.v3.oas.models.responses.ApiResponse in project atlasmap by atlasmap.
the class AtlasService method listMappingBuilderClasses.
/**
* List mapping builder classes which defines custom mapping logic.
* @param uriInfo URI info
* @return class names
*/
@GET
@Path("/mappingBuilders")
@Operation(summary = "List mapping builder classes", description = "List mapping builder classes which defines custom mapping logic")
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(type = "ArrayList<String>")), description = "Return a list of loadable class names"))
public Response listMappingBuilderClasses(@Context UriInfo uriInfo) {
ArrayList<String> classNames;
try {
classNames = libraryLoader.getSubTypesOf(AtlasMappingBuilder.class, false);
} catch (Exception e) {
if (LOG.isDebugEnabled()) {
LOG.error("Library class retrieval error.", e);
}
throw new WebApplicationException("Error retrieving class names from uploaded JARs.");
}
byte[] serialized = toJson(classNames);
if (LOG.isDebugEnabled()) {
LOG.debug(new String(serialized));
}
return Response.ok().entity(serialized).build();
}
use of io.swagger.v3.oas.models.responses.ApiResponse in project atlasmap by atlasmap.
the class AtlasService method updateMappingRequest.
/**
* Updates existing mapping file on the server.
* @param mapping mapping
* @param mappingDefinitionId mapping definition ID
* @param uriInfo URI info
* @return empty response
*/
@POST
@Path("/mapping/{mappingDefinitionId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Update Mapping", description = "Update existing mapping file on the server")
@RequestBody(description = "Mapping file content", content = @Content(schema = @Schema(implementation = AtlasMapping.class)))
@ApiResponses(@ApiResponse(responseCode = "200", description = "Succeeded"))
public Response updateMappingRequest(InputStream mapping, @Parameter(description = "Mapping Definition ID") @PathParam("mappingDefinitionId") Integer mappingDefinitionId, @Context UriInfo uriInfo) {
ADMArchiveHandler handler = loadExplodedMappingDirectory(mappingDefinitionId);
UriBuilder builder = uriInfo.getAbsolutePathBuilder();
try {
handler.setMappingDefinitionBytes(mapping);
handler.persist();
builder.path(handler.getMappingDefinition().getName());
} catch (AtlasException e) {
LOG.error("Error saving Mapping Definition file.\n" + e.getMessage(), e);
throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR);
}
return Response.ok().location(builder.build()).build();
}
use of io.swagger.v3.oas.models.responses.ApiResponse in project atlasmap by atlasmap.
the class AtlasService method createMappingRequest.
/**
* Saves a file on the server.
* @param mapping request payload
* @param mappingFormat file type
* @param mappingDefinitionId mapping definition ID
* @param uriInfo URI info
* @return empty response
*/
@PUT
@Path("/mapping/{mappingFormat}/{mappingDefinitionId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_OCTET_STREAM })
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Create Mapping", description = "Save a mapping file on the server")
@RequestBody(description = "Mapping file content", content = @Content(schema = @Schema(implementation = AtlasMapping.class)))
@ApiResponses({ @ApiResponse(responseCode = "200", description = "Succeeded"), @ApiResponse(responseCode = "500", description = "Mapping file save error") })
public Response createMappingRequest(InputStream mapping, @Parameter(description = "Mapping Format") @PathParam("mappingFormat") MappingFileType mappingFormat, @Parameter(description = "Mapping ID") @PathParam("mappingDefinitionId") Integer mappingDefinitionId, @Context UriInfo uriInfo) {
LOG.debug("createMappingRequest (save) with format '{}'", mappingFormat);
UriBuilder builder = uriInfo.getAbsolutePathBuilder();
ADMArchiveHandler admHandler = loadExplodedMappingDirectory(mappingDefinitionId);
switch(mappingFormat) {
case JSON:
try {
admHandler.setMappingDefinitionBytes(mapping);
admHandler.persist();
if (admHandler.getMappingDefinition() != null) {
builder.path(admHandler.getMappingDefinition().getName());
}
} catch (AtlasException e) {
LOG.error("Error saving Mapping Definition file.\n" + e.getMessage(), e);
throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR);
}
return Response.ok().location(builder.build()).build();
case GZ:
LOG.debug(" saveGzippedADMDigestRequest '{}' - ID: {}", admHandler.getGzippedADMDigestFileName(), mappingDefinitionId);
try {
admHandler.setGzippedADMDigest(mapping);
admHandler.persist();
} catch (AtlasException e) {
LOG.error("Error saving gzipped ADM digest file.\n" + e.getMessage(), e);
throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR);
}
builder.path(admHandler.getGzippedADMDigestFileName());
return Response.ok().location(builder.build()).build();
case ZIP:
LOG.debug(" importADMArchiveRequest - ID:'{}'", mappingDefinitionId);
try {
admHandler.setIgnoreLibrary(false);
admHandler.setLibraryDirectory(Paths.get(libFolder));
admHandler.load(mapping);
this.libraryLoader.reload();
admHandler.persist();
LOG.debug(" importADMArchiveRequest complete - ID:'{}'", mappingDefinitionId);
} catch (Exception e) {
LOG.error("Error importing ADM archive.\n" + e.getMessage(), e);
throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR);
}
builder.path("atlasmap-" + mappingDefinitionId + ".adm");
return Response.ok().location(builder.build()).build();
case XML:
throw new WebApplicationException("XML mapping format is no longer supported. Please use JSON format instead.");
default:
throw new WebApplicationException("Unrecognized mapping format: " + mappingFormat, Status.INTERNAL_SERVER_ERROR);
}
}
use of io.swagger.v3.oas.models.responses.ApiResponse in project atlasmap by atlasmap.
the class AtlasService method listMappings.
/**
* Retrieves a list of mapping file name saved with specified mapping definition ID.
* @param uriInfo URI info
* @param filter filter
* @param mappingDefinitionId mapping definition ID
* @return A list of mapping file name in {@link StringMap}
*/
@GET
@Path("/mappings/{mappingDefinitionId}")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "List Mappings", description = "Retrieves a list of mapping file name saved with specified mappingDefinitionId")
@ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = StringMap.class)), description = "Return a list of a pair of mapping file name and content"))
public Response listMappings(@Context UriInfo uriInfo, @QueryParam("filter") final String filter, @Parameter(description = "Mapping Definition ID") @PathParam("mappingDefinitionId") Integer mappingDefinitionId) {
StringMap sMap = new StringMap();
LOG.debug("listMappings with filter '{}'", filter);
ADMArchiveHandler handler = loadExplodedMappingDirectory(mappingDefinitionId);
AtlasMapping map = handler.getMappingDefinition();
if (map == null) {
return Response.ok().entity(toJson(sMap)).build();
}
StringMapEntry mapEntry = new StringMapEntry();
mapEntry.setName(map.getName());
UriBuilder builder = uriInfo.getBaseUriBuilder().path("v2").path("atlas").path("mapping").path(map.getName());
mapEntry.setValue(builder.build().toString());
sMap.getStringMapEntry().add(mapEntry);
byte[] serialized = toJson(sMap);
if (LOG.isDebugEnabled()) {
LOG.debug(new String(serialized));
}
return Response.ok().entity(serialized).build();
}
use of io.swagger.v3.oas.models.responses.ApiResponse in project Singularity by HubSpot.
the class SandboxResource method read.
@GET
@Path("/{taskId}/read")
@Operation(summary = "Retrieve part of the contents of a file in a specific task's sandbox", responses = { @ApiResponse(responseCode = "404", description = "An agent, task, or file with the specified id was not found") })
public MesosFileChunkObject read(@Parameter(hidden = true) @Auth SingularityUser user, @Parameter(required = true, description = "The task ID of the sandbox to read from") @PathParam("taskId") String taskId, @Parameter(required = true, description = "The path to the file to be read") @QueryParam("path") String path, @Parameter(description = "Optional string to grep for") @QueryParam("grep") Optional<String> grep, @Parameter(description = "Byte offset to start reading from") @QueryParam("offset") Optional<Long> offset, @Parameter(description = "Maximum number of bytes to read") @QueryParam("length") Optional<Long> length) {
authorizationHelper.checkForAuthorizationByTaskId(taskId, user, SingularityAuthorizationScope.READ);
final SingularityTaskHistory history = checkHistory(taskId, user);
checkBadRequest(!Strings.isNullOrEmpty(path), "Must specify 'path'");
final String hostname = history.getTask().getHostname();
final String fullPath = new File(history.getDirectory().get(), path).toString();
try {
final Optional<MesosFileChunkObject> maybeChunk = sandboxManager.read(hostname, fullPath, offset, length);
checkNotFound(maybeChunk.isPresent(), "File %s does not exist for task ID %s", fullPath, taskId);
if (grep.isPresent() && !Strings.isNullOrEmpty(grep.get())) {
final Pattern grepPattern = Pattern.compile(grep.get());
final StringBuilder strBuilder = new StringBuilder(maybeChunk.get().getData().length());
for (String line : Splitter.on("\n").split(maybeChunk.get().getData())) {
if (grepPattern.matcher(line).find()) {
strBuilder.append(line);
strBuilder.append("\n");
}
}
return new MesosFileChunkObject(strBuilder.toString(), maybeChunk.get().getOffset(), Optional.of(maybeChunk.get().getOffset() + maybeChunk.get().getData().length()));
}
return maybeChunk.get();
} catch (AgentNotFoundException snfe) {
throw notFound("Slave @ %s was not found, it is probably offline", hostname);
}
}
Aggregations