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());
}
}
}
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()));
}
}
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);
}
}
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());
}
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());
}
Aggregations