use of org.commonjava.indy.model.core.HostedRepository in project indy by Commonjava.
the class AutoProxCalculationTest method jsonRoundTrip_GroupCreation.
@Test
public void jsonRoundTrip_GroupCreation() throws IOException {
HostedRepository first = new HostedRepository("first");
HostedRepository second = new HostedRepository("second");
Group repo = new Group("test", first.getKey(), second.getKey());
AutoProxCalculation in = new AutoProxCalculation(repo, Arrays.asList(first, second), "test-rule.groovy");
IndyObjectMapper mapper = new IndyObjectMapper(true);
String json = mapper.writeValueAsString(in);
AutoProxCalculation out = mapper.readValue(json, AutoProxCalculation.class);
assertThat(out, notNullValue());
assertThat(out.getRuleName(), equalTo(in.getRuleName()));
assertThat(out.getStore(), equalTo(in.getStore()));
assertThat(out, equalTo(in));
List<ArtifactStore> supplementalStores = out.getSupplementalStores();
assertThat(supplementalStores, notNullValue());
assertThat(supplementalStores.size(), equalTo(2));
assertThat(supplementalStores.get(0), equalTo(first));
assertThat(supplementalStores.get(1), equalTo(second));
}
use of org.commonjava.indy.model.core.HostedRepository in project indy by Commonjava.
the class DeleteHostedRepoWithContentTest method deleteHostedRepoWithContent_RepoNotReCreatedWhenContentIsDeleted.
@Test
@Category(EventDependent.class)
public void deleteHostedRepoWithContent_RepoNotReCreatedWhenContentIsDeleted() throws Exception {
final String named = "test";
final String path = "path/to/foo.txt";
final String content = "This is a test";
client.content().store(StoreType.hosted, named, path, new ByteArrayInputStream(content.getBytes()));
final InputStream stream = client.content().get(StoreType.hosted, named, path);
final String retrieved = IOUtils.toString(stream);
stream.close();
assertThat(retrieved, equalTo(content));
System.out.println("Waiting for server events to clear...");
waitForEventPropagation();
client.stores().delete(StoreType.hosted, named, "Removing test repo");
System.out.println("Waiting for server events to clear...");
waitForEventPropagation();
final StoreListingDTO<HostedRepository> repos = client.stores().listHostedRepositories();
boolean found = false;
for (final HostedRepository repo : repos) {
if (repo.getName().equals(named)) {
found = true;
break;
}
}
assertThat(found, equalTo(false));
}
use of org.commonjava.indy.model.core.HostedRepository in project indy by Commonjava.
the class ScheduleManager method setSnapshotTimeouts.
public synchronized void setSnapshotTimeouts(final StoreKey key, final String path) throws IndySchedulerException {
if (!schedulerConfig.isEnabled()) {
logger.debug("Scheduler disabled.");
return;
}
HostedRepository deploy = null;
try {
final ArtifactStore store = dataManager.getArtifactStore(key);
if (store == null) {
return;
}
if (store instanceof HostedRepository) {
deploy = (HostedRepository) store;
} else if (store instanceof Group) {
final Group group = (Group) store;
deploy = findDeployPoint(group);
}
} catch (final IndyDataException e) {
logger.error(String.format("Failed to retrieve deploy point for: %s. Reason: %s", key, e.getMessage()), e);
}
if (deploy == null) {
return;
}
final ContentAdvisor advisor = StreamSupport.stream(Spliterators.spliteratorUnknownSize(contentAdvisor.iterator(), Spliterator.ORDERED), false).filter(Objects::nonNull).findFirst().orElse(null);
final ContentQuality quality = advisor == null ? null : advisor.getContentQuality(path);
if (quality == null) {
return;
}
if (ContentQuality.SNAPSHOT == quality && deploy.getSnapshotTimeoutSeconds() > 0) {
final int timeout = deploy.getSnapshotTimeoutSeconds();
// // logger.info( "[SNAPSHOT TIMEOUT SET] {}/{}; {}", deploy.getKey(), path, new Date( timeout ) );
// cancel( new StoreKeyMatcher( key, CONTENT_JOB_TYPE ), path );
scheduleContentExpiration(key, path, timeout);
}
}
use of org.commonjava.indy.model.core.HostedRepository in project indy by Commonjava.
the class DefaultDownloadManagerTest method getTransferFromStoreList_DownloadOp_SkipIfDoesntExist.
@Test
public void getTransferFromStoreList_DownloadOp_SkipIfDoesntExist() throws IndyDataException, IndyWorkflowException {
ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Test setup");
HostedRepository hosted1 = new HostedRepository(MAVEN_PKG_KEY, "one");
HostedRepository hosted2 = new HostedRepository(MAVEN_PKG_KEY, "two");
storeManager.storeArtifactStore(hosted1, summary, false, true, new EventMetadata());
storeManager.storeArtifactStore(hosted2, summary, false, true, new EventMetadata());
String path = "/some/path.txt";
Transfer transfer = downloadManager.getStorageReference(Arrays.asList(hosted1, hosted2), path, TransferOperation.DOWNLOAD);
assertThat(transfer, nullValue());
}
use of org.commonjava.indy.model.core.HostedRepository in project indy by Commonjava.
the class DefaultDownloadManager method store.
/*
* (non-Javadoc)
* @see org.commonjava.indy.core.rest.util.FileManager#upload(java.util.List, java.lang.String,
* java.io.InputStream)
*/
@Override
public Transfer store(final List<? extends ArtifactStore> stores, final String path, final InputStream stream, final TransferOperation op, final EventMetadata eventMetadata) throws IndyWorkflowException {
final ContentQuality quality = getQuality(path);
HostedRepository selected = null;
for (final ArtifactStore store : stores) {
if (storeManager.isReadonly(store)) {
logger.info("The store {} is readonly, store operation not allowed");
continue;
}
if (storeIsSuitableFor(store, quality, op)) {
selected = (HostedRepository) store;
break;
}
}
if (selected == null) {
logger.warn("Cannot deploy. No valid deploy points in group.");
throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "No deployment locations available.");
}
logger.info("Storing: {} in selected: {} with event metadata: {}", path, selected, eventMetadata);
store(selected, path, stream, op, eventMetadata);
return getStorageReference(selected.getKey(), path);
}
Aggregations