Search in sources :

Example 6 with IndyClientException

use of org.commonjava.indy.client.core.IndyClientException in project indy by Commonjava.

the class IndyHostedByArchiveClientModule method createRepo.

public HostedRepository createRepo(final File zipFile, final String repoName, final String ignorePathPrefix) throws IndyClientException {
    final String endPath = StringUtils.isBlank(ignorePathPrefix) ? "compressed-content" : "compressed-content?pathPrefixToIgnore=" + ignorePathPrefix;
    final String urlPath = UrlUtils.buildUrl(http.getBaseUrl(), HOSTED_BY_ARC_PATH, repoName, endPath);
    HttpPost postRequest = new HttpPost(urlPath);
    HttpResources resources = null;
    try {
        postRequest.setHeader("Content-Type", CONTENT_TYPE_ZIP.getMimeType());
        try (InputStream in = new FileInputStream(zipFile)) {
            InputStreamEntity entity = new InputStreamEntity(in, CONTENT_TYPE_ZIP);
            postRequest.setEntity(entity);
            resources = http.execute(postRequest);
            if (resources != null) {
                HttpResponse response = resources.getResponse();
                final StatusLine sl = response.getStatusLine();
                if (sl.getStatusCode() != SC_OK && sl.getStatusCode() != SC_CREATED) {
                    if (sl.getStatusCode() == SC_NOT_FOUND) {
                        return null;
                    }
                    throw new IndyClientException(sl.getStatusCode(), "Error create %s with file: %s", repoName, zipFile.getName());
                }
                final String json = entityToString(response);
                logger.debug("Got JSON:\n\n{}\n\n", json);
                final HostedRepository value = http.getObjectMapper().readValue(json, HostedRepository.class);
                logger.debug("Got result object: {}", value);
                return value;
            }
            return null;
        }
    } catch (IOException e) {
        throw new IndyClientException("Indy request failed: %s", e);
    } finally {
        if (resources != null) {
            cleanupResources(postRequest, resources.getResponse(), (CloseableHttpClient) resources.getClient());
        }
    }
}
Also used : StatusLine(org.apache.http.StatusLine) HttpPost(org.apache.http.client.methods.HttpPost) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) HttpResources(org.commonjava.indy.client.core.helper.HttpResources) HttpResponse(org.apache.http.HttpResponse) HttpResources.entityToString(org.commonjava.indy.client.core.helper.HttpResources.entityToString) IndyClientException(org.commonjava.indy.client.core.IndyClientException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) InputStreamEntity(org.apache.http.entity.InputStreamEntity) HostedRepository(org.commonjava.indy.model.core.HostedRepository)

Example 7 with IndyClientException

use of org.commonjava.indy.client.core.IndyClientException in project indy by Commonjava.

the class HostedByArcConflictTest method testUploadZipAndCreate.

@Test
public void testUploadZipAndCreate() throws Exception {
    final String hostedRepoName = "test";
    HostedRepository hosted = client.stores().create(new HostedRepository(MavenPackageTypeDescriptor.MAVEN_PKG_KEY, hostedRepoName), "create first", HostedRepository.class);
    waitForEventPropagation();
    assertThat(client.stores().exists(hosted.getKey()), equalTo(true));
    IndyHostedByArchiveClientModule module = client.module(IndyHostedByArchiveClientModule.class);
    try {
        module.createRepo(getZipFile(), hostedRepoName);
    } catch (IndyClientException e) {
        logger.info(e.getMessage());
        assertThat(e.getStatusCode(), equalTo(ApplicationStatus.CONFLICT.code()));
    }
}
Also used : IndyHostedByArchiveClientModule(org.commonjava.indy.hostedbyarc.client.IndyHostedByArchiveClientModule) IndyClientException(org.commonjava.indy.client.core.IndyClientException) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test)

Example 8 with IndyClientException

use of org.commonjava.indy.client.core.IndyClientException in project indy by Commonjava.

the class ImpliedRepoClientModule method setStoresImpliedBy.

public void setStoresImpliedBy(final ArtifactStore store, final List<StoreKey> implied, final String changelog) throws IndyClientException {
    final List<ArtifactStore> stores = new ArrayList<>();
    for (final StoreKey storeKey : implied) {
        final ArtifactStore is = getClient().stores().load(storeKey.getType(), storeKey.getName(), storeKey.getType().getStoreClass());
        if (is == null) {
            throw new IndyClientException("No such store: %s. Cannot add to the implied-store list for: %s", storeKey, store.getKey());
        }
        stores.add(is);
    }
    try {
        metadataManager.addImpliedMetadata(store, stores);
    } catch (final ImpliedReposException e) {
        throw new IndyClientException("Failed to set implied-store metadata: %s", e, e.getMessage());
    }
    stores.add(store);
    for (final ArtifactStore toSave : stores) {
        logger.info("Updating implied-store metadata in: {} triggered by adding implications to: {}", toSave.getKey(), store.getKey());
        getClient().stores().update(toSave, changelog);
    }
}
Also used : ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ArrayList(java.util.ArrayList) IndyClientException(org.commonjava.indy.client.core.IndyClientException) StoreKey(org.commonjava.indy.model.core.StoreKey) ImpliedReposException(org.commonjava.indy.implrepo.ImpliedReposException)

Example 9 with IndyClientException

use of org.commonjava.indy.client.core.IndyClientException in project indy by Commonjava.

the class SuccessiveRetrievalWithRemoteRepoDeletionBetweenTest method run.

@Test
public void run() throws Exception {
    final String testRepo = "test";
    final PomRef pom = loadPom("simple.pom", Collections.<String, String>emptyMap());
    final String url = server.formatUrl(testRepo, pom.path);
    server.expect(url, 200, pom.pom);
    Stream.of(1, 2).forEach((currentTry) -> {
        CloseableHttpResponse response = null;
        InputStream stream = null;
        final HttpGet get = new HttpGet(url);
        CloseableHttpClient httpClient = null;
        try {
            httpClient = proxiedHttp();
            response = httpClient.execute(get);
            stream = response.getEntity().getContent();
            final String resultingPom = IOUtils.toString(stream);
            assertThat(currentTry + ": retrieved POM was null!", resultingPom, notNullValue());
            assertThat(currentTry + ": retrieved POM contains wrong content!", resultingPom, equalTo(pom.pom));
        } catch (Exception e) {
            e.printStackTrace();
            fail(currentTry + ": Failed to retrieve file: " + url);
        } finally {
            IOUtils.closeQuietly(stream);
            HttpResources.cleanupResources(get, response, httpClient);
        }
        try {
            client.stores().delete(new StoreKey(GENERIC_PKG_KEY, StoreType.remote, REMOTE_NAME), "Deleting for pass: " + currentTry);
        } catch (IndyClientException e) {
            fail("Failed to delete remote repo: " + REMOTE_NAME);
        }
    });
    final RemoteRepository remoteRepo = this.client.stores().load(new StoreKey(GENERIC_PKG_KEY, StoreType.remote, REMOTE_NAME), RemoteRepository.class);
    assertThat(remoteRepo, nullValue());
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) IndyClientException(org.commonjava.indy.client.core.IndyClientException) StoreKey(org.commonjava.indy.model.core.StoreKey) IndyClientException(org.commonjava.indy.client.core.IndyClientException) Test(org.junit.Test)

Example 10 with IndyClientException

use of org.commonjava.indy.client.core.IndyClientException in project indy by Commonjava.

the class ExportAndImportTrackingReportTest method checkIdsDTO.

static void checkIdsDTO(TrackingIdsDTO idsDTO, List<String> expectedIds, IndyFoloAdminClientModule adminClientModule) {
    // **/ Disabled behawior  because it is  affeecting  auditing  for folo records
    // Set<String> sealed = idsDTO.getSealed();
    // assertTrue( sealed.containsAll( expectedIds ) );
    // assertEquals( 2, sealed.stream().distinct().collect(Collectors.toSet()).size() );
    final List<Exception> ex = new ArrayList<>();
    idsDTO.getSealed().forEach((id) -> {
        try {
            TrackedContentDTO report = adminClientModule.getTrackingReport(id);
            assertNotNull(report);
            System.out.println(">>>> " + report.getKey() + ", " + report.getDownloads());
            assertTrue(expectedIds.contains(report.getKey().getId()));
            assertTrue(!report.getDownloads().isEmpty());
            // **/ Disabled behawior  because it is  affeecting  auditing  for folo records
            // assertEquals( 1, report.getDownloads().size() );
            List<TrackedContentEntryDTO> list = new ArrayList(report.getDownloads());
            TrackedContentEntryDTO entryDTO = list.get(0);
            assertTrue(entryDTO.getPath().contains(path1) || entryDTO.getPath().contains(path2));
            assertTrue(entryDTO.getStoreKey().getName().equals(repoId));
        } catch (IndyClientException e) {
            ex.add(e);
        }
    });
    assertTrue(ex.isEmpty());
}
Also used : TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) ArrayList(java.util.ArrayList) IndyClientException(org.commonjava.indy.client.core.IndyClientException) IndyClientException(org.commonjava.indy.client.core.IndyClientException) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO)

Aggregations

IndyClientException (org.commonjava.indy.client.core.IndyClientException)31 Test (org.junit.Test)21 InputStream (java.io.InputStream)17 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)13 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)12 HostedRepository (org.commonjava.indy.model.core.HostedRepository)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 StoreKey (org.commonjava.indy.model.core.StoreKey)9 IOException (java.io.IOException)6 HttpResources (org.commonjava.indy.client.core.helper.HttpResources)5 HttpResponse (org.apache.http.HttpResponse)3 StatusLine (org.apache.http.StatusLine)3 AbstractIndyFunctionalTest (org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest)3 Logger (org.slf4j.Logger)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ArrayList (java.util.ArrayList)2 CountingInputStream (org.apache.commons.io.input.CountingInputStream)2 HttpGet (org.apache.http.client.methods.HttpGet)2 HttpPost (org.apache.http.client.methods.HttpPost)2 IndyClientHttp (org.commonjava.indy.client.core.IndyClientHttp)2