Search in sources :

Example 76 with StoreKey

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

the class StoreFileAndVerifyExistenceInGroupTest method storeFileInConstituentAndVerifyExistenceInGroup.

@Test
public void storeFileInConstituentAndVerifyExistenceInGroup() throws Exception {
    final Group g = client.stores().load(group, PUBLIC, Group.class);
    System.out.printf("\n\nGroup constituents are:\n  %s\n\n", StringUtils.join(g.getConstituents(), "\n  "));
    assertThat(g.getConstituents().contains(new StoreKey(hosted, STORE)), equalTo(true));
    final InputStream stream = new ByteArrayInputStream(("This is a test: " + System.nanoTime()).getBytes());
    final String path = "/path/to/foo.class";
    assertThat(client.content().exists(hosted, STORE, path), equalTo(false));
    client.content().store(hosted, STORE, path, stream);
    assertThat(client.content().exists(group, PUBLIC, path), equalTo(true));
}
Also used : Group(org.commonjava.indy.model.core.Group) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 77 with StoreKey

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

the class StoreThenGetUnSuffixedDirAndDownloadTest method run.

@Test
public void run() throws Exception {
    final String content = "This is a test: " + System.nanoTime();
    final InputStream stream = new ByteArrayInputStream(content.getBytes());
    final String dirPath = "/org/foo/bar/1";
    final String path = dirPath + "/bar-1.pom";
    assertThat(client.content().exists(hosted, STORE, path), equalTo(false));
    client.content().store(hosted, STORE, path, stream);
    assertThat(client.content().exists(hosted, STORE, path), equalTo(true));
    try (InputStream htmlIn = client.content().get(new StoreKey(hosted, STORE), dirPath)) {
        assertThat(htmlIn, notNullValue());
        String html = IOUtils.toString(htmlIn);
        assertThat(html.contains("<html>"), equalTo(true));
        assertThat(html.contains("bar-1.pom"), equalTo(true));
    }
    assertThat(client.content().exists(hosted, STORE, path), equalTo(true));
    final URL url = new URL(client.content().contentUrl(hosted, STORE, path));
    final InputStream is = url.openStream();
    final String result = IOUtils.toString(is);
    is.close();
    assertThat(result, equalTo(content));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StoreKey(org.commonjava.indy.model.core.StoreKey) URL(java.net.URL) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 78 with StoreKey

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

the class RemoteRepoTimeoutDisablesStoreAndShowsInDisabledTimeoutsMapTest method assertResult.

@Override
protected void assertResult(RemoteRepository remoteRepo) throws Exception {
    assertThat(remoteRepo.isDisabled(), equalTo(true));
    Map<StoreKey, Date> storeTimeouts = client.schedules().getDisabledStoreTimeouts();
    Date timeout = storeTimeouts.get(new StoreKey(remote, remoteRepo.getName()));
    assertThat(timeout, notNullValue());
    assertThat(timeout.after(new Date()), equalTo(true));
}
Also used : StoreKey(org.commonjava.indy.model.core.StoreKey) Date(java.util.Date)

Example 79 with StoreKey

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

the class NfcResource method getStore.

@Path("/{packageType}/{type: (hosted|group|remote)}/{name}")
@ApiOperation("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 getStore(@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", value = "The name of the store") @PathParam("name") final String name) {
    Response response;
    final StoreType type = StoreType.get(t);
    final StoreKey key = new StoreKey(packageType, type, name);
    try {
        final NotFoundCacheDTO dto = controller.getMissing(key);
        response = formatOkResponseWithJsonEntity(dto, serializer);
    } 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) 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 80 with StoreKey

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

the class NfcResource method deprecatedClearStore.

@Path("/{type: (hosted|group|remote)}/{name}{path: (/.+)?}")
@ApiOperation("[Deprecated] Clear all not-found cache entries for a particular store (or optionally, a subpath within a store)")
@DELETE
@Deprecated
public Response deprecatedClearStore(@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);
    String altPath = Paths.get("/api/nfc", MAVEN_PKG_KEY, type.singularEndpointName(), name).toString();
    final StoreKey key = new StoreKey(type, name);
    try {
        if (isNotEmpty(p)) {
            controller.clear(key);
        } else {
            controller.clear(key, p);
        }
        response = markDeprecated(Response.ok(), altPath).build();
    } 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) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) StoreKey(org.commonjava.indy.model.core.StoreKey) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ResponseUtils.markDeprecated(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.markDeprecated) ApiOperation(io.swagger.annotations.ApiOperation)

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