Search in sources :

Example 46 with StoreKey

use of org.commonjava.indy.model.core.StoreKey in project indy by Commonjava.

the class MaintenanceHandler method rescan.

@ApiOperation("Rescan all content in the specified repository to re-initialize metadata, capture missing index keys, etc.")
@ApiResponse(code = 200, message = "Rescan was started successfully. (NOTE: There currently is no way to determine when rescanning is complete.)")
@Path("/rescan/{packageType}/{type: (hosted|group|remote)}/{name}")
@GET
public Response rescan(@ApiParam(value = "The package type (eg. maven, npm, generic-http)", required = true) @PathParam("packageType") final String packageType, @ApiParam(value = "The type of store / repository", allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @ApiParam("The name of the store / repository") @PathParam("name") final String name) {
    final StoreKey key = new StoreKey(packageType, StoreType.get(type), name);
    Response response;
    try {
        contentController.rescan(key);
        response = Response.ok().build();
    } catch (final IndyWorkflowException e) {
        logger.error(String.format("Failed to rescan: %s. Reason: %s", key, e.getMessage()), 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) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) StoreKey(org.commonjava.indy.model.core.StoreKey) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponse(io.swagger.annotations.ApiResponse)

Example 47 with StoreKey

use of org.commonjava.indy.model.core.StoreKey in project indy by Commonjava.

the class ReplicationHandler method replicate.

@ApiOperation("Replicate the stores of a remote Indy")
@ApiImplicitParams({ @ApiImplicitParam(paramType = "body", name = "body", dataType = "org.commonjava.indy.model.core.dto.ReplicationDTO", required = true, value = "The configuration determining how replication should be handled, and what remote site to replicate.") })
@POST
@Produces(ApplicationContent.application_json)
public Response replicate(@Context final HttpServletRequest request, @Context final SecurityContext securityContext) {
    Response response;
    try {
        String user = securityManager.getUser(securityContext, request);
        final ReplicationDTO dto = serializer.readValue(request.getInputStream(), ReplicationDTO.class);
        final Set<StoreKey> replicated = controller.replicate(dto, user);
        final Map<String, Object> params = new LinkedHashMap<String, Object>();
        params.put("replicationCount", replicated.size());
        params.put("items", replicated);
        response = formatOkResponseWithJsonEntity(params, serializer);
    } catch (final IndyWorkflowException | IOException e) {
        logger.error(String.format("Replication failed: %s", e.getMessage()), e);
        response = formatResponse(e);
    }
    return response;
}
Also used : ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) ReplicationDTO(org.commonjava.indy.model.core.dto.ReplicationDTO) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) IOException(java.io.IOException) StoreKey(org.commonjava.indy.model.core.StoreKey) LinkedHashMap(java.util.LinkedHashMap) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation)

Example 48 with StoreKey

use of org.commonjava.indy.model.core.StoreKey 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 49 with StoreKey

use of org.commonjava.indy.model.core.StoreKey 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 50 with StoreKey

use of org.commonjava.indy.model.core.StoreKey in project indy by Commonjava.

the class SetBackSettingsManager method deleteStoreSettings.

public boolean deleteStoreSettings(final ArtifactStore store) throws SetBackDataException {
    if (!config.isEnabled()) {
        throw new SetBackDataException("SetBack is disabled!");
    }
    final StoreKey key = store.getKey();
    if (StoreType.hosted == key.getType()) {
        return false;
    }
    final DataFile settingsXml = getSettingsXml(key);
    if (settingsXml.exists()) {
        try {
            settingsXml.delete(new ChangeSummary(ChangeSummary.SYSTEM_USER, "SETBACK: Deleting generated SetBack settings.xml for: " + store));
        } catch (final IOException e) {
            throw new SetBackDataException("Failed to delete SetBack settings.xml for: %s.\n  at: %s\n  Reason: %s", e, store, settingsXml, e.getMessage());
        }
        return true;
    }
    return false;
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) IOException(java.io.IOException) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey)

Aggregations

StoreKey (org.commonjava.indy.model.core.StoreKey)186 Test (org.junit.Test)92 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)40 StoreType (org.commonjava.indy.model.core.StoreType)39 InputStream (java.io.InputStream)33 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)32 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)31 IndyDataException (org.commonjava.indy.data.IndyDataException)30 Group (org.commonjava.indy.model.core.Group)29 Transfer (org.commonjava.maven.galley.model.Transfer)27 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)24 Response (javax.ws.rs.core.Response)23 IOException (java.io.IOException)22 Logger (org.slf4j.Logger)21 ApiOperation (io.swagger.annotations.ApiOperation)20 ResponseUtils.formatResponse (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse)20 ArrayList (java.util.ArrayList)19 Path (javax.ws.rs.Path)19 ApiResponse (io.swagger.annotations.ApiResponse)18 IndyObjectMapper (org.commonjava.indy.model.core.io.IndyObjectMapper)18