Search in sources :

Example 31 with IndyWorkflowException

use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.

the class StoreAdminHandler method create.

@ApiOperation("Create a new store")
@ApiResponses({ @ApiResponse(code = 201, response = ArtifactStore.class, message = "The store was created"), @ApiResponse(code = 409, message = "A store with the specified type and name already exists") })
@ApiImplicitParams({ @ApiImplicitParam(allowMultiple = false, paramType = "body", name = "body", required = true, dataType = "org.commonjava.indy.model.core.ArtifactStore", value = "The artifact store definition JSON") })
@POST
@Consumes(ApplicationContent.application_json)
@Produces(ApplicationContent.application_json)
public Response create(@PathParam("packageType") final String packageType, @ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @Context final UriInfo uriInfo, @Context final HttpServletRequest request, @Context final SecurityContext securityContext) {
    final StoreType st = StoreType.get(type);
    Response response = null;
    String json = null;
    try {
        json = IOUtils.toString(request.getInputStream());
        json = objectMapper.patchLegacyStoreJson(json);
    } catch (final IOException e) {
        final String message = "Failed to read " + st.getStoreClass().getSimpleName() + " from request body.";
        logger.error(message, e);
        response = formatResponse(e, message);
    }
    if (response != null) {
        return response;
    }
    ArtifactStore store = null;
    try {
        store = objectMapper.readValue(json, st.getStoreClass());
    } catch (final IOException e) {
        final String message = "Failed to parse " + st.getStoreClass().getSimpleName() + " from request body.";
        logger.error(message, e);
        response = formatResponse(e, message);
    }
    if (response != null) {
        return response;
    }
    logger.info("\n\nGot artifact store: {}\n\n", store);
    try {
        String user = securityManager.getUser(securityContext, request);
        if (adminController.store(store, user, false)) {
            final URI uri = uriInfo.getBaseUriBuilder().path("/api/admin/stores").path(store.getPackageType()).path(store.getType().singularEndpointName()).build(store.getName());
            response = formatCreatedResponseWithJsonEntity(uri, store, objectMapper);
        } else {
            response = status(CONFLICT).entity("{\"error\": \"Store already exists.\"}").type(application_json).build();
        }
    } catch (final IndyWorkflowException e) {
        logger.error(e.getMessage(), e);
        response = formatResponse(e);
    }
    return response;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) Response(javax.ws.rs.core.Response) ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) ApiResponse(io.swagger.annotations.ApiResponse) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) IOException(java.io.IOException) URI(java.net.URI) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 32 with IndyWorkflowException

use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.

the class StatsHandler method getAllEndpoints.

@ApiOperation("Retrieve a listing of the artifact stores available on the system. This is especially useful for setting up a network of Indy instances that reference one another")
@ApiResponse(code = 200, response = EndpointViewListing.class, message = "The artifact store listing")
@Path("/all-endpoints")
@GET
@Produces(ApplicationContent.application_json)
public Response getAllEndpoints(@Context final UriInfo uriInfo) {
    Response response;
    try {
        final String baseUri = uriInfo.getBaseUriBuilder().path(IndyDeployment.API_PREFIX).build().toString();
        final EndpointViewListing listing = statsController.getEndpointsListing(baseUri, uriFormatter);
        response = formatOkResponseWithJsonEntity(listing, objectMapper);
        logger.info("\n\n\n\n\n\n{} Sent all-endpoints:\n\n{}\n\n\n\n\n\n\n", new Date(), listing);
    } catch (final IndyWorkflowException e) {
        logger.error(String.format("Failed to retrieve endpoint listing: %s", formatEntity(e)), e);
        response = formatResponse(e);
    }
    return response;
}
Also used : ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) EndpointViewListing(org.commonjava.indy.model.core.dto.EndpointViewListing) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Date(java.util.Date) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponse(io.swagger.annotations.ApiResponse)

Example 33 with IndyWorkflowException

use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.

the class NfcResource method clearStore.

@Path("/{packageType}/{type: (hosted|group|remote)}/{name}{path: (/.+)?}")
@ApiOperation("Clear all not-found cache entries for a particular store (or optionally, a subpath within a store)")
@DELETE
public Response clearStore(@ApiParam(name = "packageType", required = true, value = "The type of package (eg. maven, npm, generic-http)") @PathParam("packageType") final String packageType, @ApiParam(allowableValues = "hosted,group,remote", name = "type", required = true, value = "The type of store") @PathParam("type") final String t, @ApiParam(name = "name", required = true, value = "The name of the store") @PathParam("name") final String name, @ApiParam(name = "path", required = false, value = "The sub-path to clear") @PathParam("path") final String p) {
    Response response;
    final StoreType type = StoreType.get(t);
    try {
        final StoreKey key = new StoreKey(packageType, type, name);
        if (isNotEmpty(p)) {
            controller.clear(key);
        } else {
            controller.clear(key, p);
        }
        response = Response.ok().build();
    } catch (final IndyWorkflowException e) {
        response = formatResponse(e);
    }
    return response;
}
Also used : ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) StoreType(org.commonjava.indy.model.core.StoreType) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) StoreKey(org.commonjava.indy.model.core.StoreKey) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ApiOperation(io.swagger.annotations.ApiOperation)

Example 34 with IndyWorkflowException

use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.

the class NfcResource method deprecatedGetStore.

@Path("/{type: (hosted|group|remote)}/{name}")
@ApiOperation("[Deprecated] Retrieve all not-found cache entries currently tracked for a given store")
@ApiResponses({ @ApiResponse(code = 200, response = NotFoundCacheDTO.class, message = "The not-found cache for the specified artifact store") })
@GET
@Produces(ApplicationContent.application_json)
public Response deprecatedGetStore(@ApiParam(allowableValues = "hosted,group,remote", name = "type", required = true, value = "The type of store") @PathParam("type") final String t, @ApiParam(name = "name", value = "The name of the store") @PathParam("name") final String name) {
    Response response;
    final StoreType type = StoreType.get(t);
    String altPath = Paths.get("/api/nfc", MAVEN_PKG_KEY, type.singularEndpointName(), name).toString();
    final StoreKey key = new StoreKey(type, name);
    try {
        final NotFoundCacheDTO dto = controller.getMissing(key);
        response = formatOkResponseWithJsonEntity(dto, serializer, rb -> markDeprecated(rb, altPath));
    } catch (final IndyWorkflowException e) {
        response = formatResponse(e, (rb) -> markDeprecated(rb, altPath));
    }
    return response;
}
Also used : ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) StoreType(org.commonjava.indy.model.core.StoreType) PathParam(javax.ws.rs.PathParam) NfcController(org.commonjava.indy.core.ctl.NfcController) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) StringUtils.isNotEmpty(org.apache.commons.lang.StringUtils.isNotEmpty) ApiParam(io.swagger.annotations.ApiParam) ApiResponses(io.swagger.annotations.ApiResponses) Inject(javax.inject.Inject) ApiOperation(io.swagger.annotations.ApiOperation) ResponseUtils.formatOkResponseWithJsonEntity(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatOkResponseWithJsonEntity) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Api(io.swagger.annotations.Api) StoreKey(org.commonjava.indy.model.core.StoreKey) MAVEN_PKG_KEY(org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor.MAVEN_PKG_KEY) DELETE(javax.ws.rs.DELETE) NotFoundCacheDTO(org.commonjava.indy.model.core.dto.NotFoundCacheDTO) ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) StoreType(org.commonjava.indy.model.core.StoreType) IndyResources(org.commonjava.indy.bind.jaxrs.IndyResources) ResponseUtils.markDeprecated(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.markDeprecated) ApplicationContent(org.commonjava.indy.util.ApplicationContent) Response(javax.ws.rs.core.Response) Paths(java.nio.file.Paths) ApiResponse(io.swagger.annotations.ApiResponse) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) StoreKey(org.commonjava.indy.model.core.StoreKey) NotFoundCacheDTO(org.commonjava.indy.model.core.dto.NotFoundCacheDTO) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 35 with IndyWorkflowException

use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.

the class DeprecatedStoreAdminHandler method getAll.

@ApiOperation("Retrieve the definitions of all artifact stores of a given type on the system")
@ApiResponses({ @ApiResponse(code = 200, response = StoreListingDTO.class, message = "The store definitions") })
@GET
@Produces(ApplicationContent.application_json)
public Response getAll(@ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type) {
    String altPath = Paths.get(MavenPackageTypeDescriptor.MAVEN_ADMIN_REST_BASE_PATH, type).toString();
    Consumer<Response.ResponseBuilder> modifier = (rb) -> markDeprecated(rb, altPath);
    final StoreType st = StoreType.get(type);
    Response response;
    try {
        final List<ArtifactStore> stores = adminController.getAllOfType(st);
        logger.info("Returning listing containing stores:\n\t{}", new JoinString("\n\t", stores));
        final StoreListingDTO<ArtifactStore> dto = new StoreListingDTO<>(stores);
        response = formatOkResponseWithJsonEntity(dto, objectMapper, modifier);
    } catch (final IndyWorkflowException e) {
        logger.error(e.getMessage(), e);
        response = formatResponse(e, modifier);
    }
    return response;
}
Also used : Produces(javax.ws.rs.Produces) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) SecurityContext(javax.ws.rs.core.SecurityContext) ApiParam(io.swagger.annotations.ApiParam) StoreListingDTO(org.commonjava.indy.model.core.dto.StoreListingDTO) ApiOperation(io.swagger.annotations.ApiOperation) Consumes(javax.ws.rs.Consumes) Response.noContent(javax.ws.rs.core.Response.noContent) Response.status(javax.ws.rs.core.Response.status) URI(java.net.URI) StoreKey(org.commonjava.indy.model.core.StoreKey) DELETE(javax.ws.rs.DELETE) Context(javax.ws.rs.core.Context) StringUtils.isEmpty(org.apache.commons.lang.StringUtils.isEmpty) IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam) CONFLICT(javax.ws.rs.core.Response.Status.CONFLICT) StoreType(org.commonjava.indy.model.core.StoreType) IndyResources(org.commonjava.indy.bind.jaxrs.IndyResources) ResponseUtils.markDeprecated(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.markDeprecated) Response.notModified(javax.ws.rs.core.Response.notModified) IOUtils(org.apache.commons.io.IOUtils) ApplicationContent(org.commonjava.indy.util.ApplicationContent) List(java.util.List) Response(javax.ws.rs.core.Response) Response.ok(javax.ws.rs.core.Response.ok) ApplicationScoped(javax.enterprise.context.ApplicationScoped) UriInfo(javax.ws.rs.core.UriInfo) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) HEAD(javax.ws.rs.HEAD) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) ApplicationContent.application_json(org.commonjava.indy.util.ApplicationContent.application_json) ApiResponses(io.swagger.annotations.ApiResponses) Inject(javax.inject.Inject) HttpServletRequest(javax.servlet.http.HttpServletRequest) MavenPackageTypeDescriptor(org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor) ResponseUtils.formatOkResponseWithJsonEntity(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatOkResponseWithJsonEntity) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) SecurityManager(org.commonjava.indy.bind.jaxrs.SecurityManager) ResponseUtils.formatCreatedResponseWithJsonEntity(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatCreatedResponseWithJsonEntity) Api(io.swagger.annotations.Api) Status(javax.ws.rs.core.Response.Status) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) METADATA_CHANGELOG(org.commonjava.indy.model.core.ArtifactStore.METADATA_CHANGELOG) IOException(java.io.IOException) Consumer(java.util.function.Consumer) Paths(java.nio.file.Paths) ApiResponse(io.swagger.annotations.ApiResponse) AdminController(org.commonjava.indy.core.ctl.AdminController) PUT(javax.ws.rs.PUT) StoreType(org.commonjava.indy.model.core.StoreType) Response(javax.ws.rs.core.Response) ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) ApiResponse(io.swagger.annotations.ApiResponse) StoreListingDTO(org.commonjava.indy.model.core.dto.StoreListingDTO) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)109 Response (javax.ws.rs.core.Response)40 Transfer (org.commonjava.maven.galley.model.Transfer)39 IOException (java.io.IOException)36 ResponseUtils.formatResponse (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse)36 StoreKey (org.commonjava.indy.model.core.StoreKey)36 ApiOperation (io.swagger.annotations.ApiOperation)35 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)34 ApiResponse (io.swagger.annotations.ApiResponse)33 Path (javax.ws.rs.Path)32 StoreType (org.commonjava.indy.model.core.StoreType)26 IndyDataException (org.commonjava.indy.data.IndyDataException)25 GET (javax.ws.rs.GET)24 Logger (org.slf4j.Logger)22 ApiResponses (io.swagger.annotations.ApiResponses)21 ArrayList (java.util.ArrayList)19 Produces (javax.ws.rs.Produces)18 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)18 InputStream (java.io.InputStream)15 List (java.util.List)13