use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.
the class HttpProxyTest method proxy404.
@Test
public void proxy404() throws Exception {
final String testRepo = "test";
final PomRef pom = loadPom("simple.pom", Collections.<String, String>emptyMap());
final String url = server.formatUrl(testRepo, pom.path);
final HttpGet get = new HttpGet(url);
final CloseableHttpClient client = proxiedHttp();
CloseableHttpResponse response = null;
final InputStream stream = null;
try {
response = client.execute(get, proxyContext(USER, PASS));
assertThat(response.getStatusLine().getStatusCode(), equalTo(HttpStatus.SC_NOT_FOUND));
} finally {
IOUtils.closeQuietly(stream);
HttpUtil.cleanupResources(client, get, response);
}
final RemoteRepository remoteRepo = (RemoteRepository) storeManager.getArtifactStore(new StoreKey(GENERIC_PKG_KEY, StoreType.remote, "httprox_127-0-0-1_" + server.getPort()));
assertThat(remoteRepo, notNullValue());
assertThat(remoteRepo.getUrl(), equalTo(server.getBaseUri()));
}
use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.
the class AutoCreateRepoAndRetrievePomTest 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);
final HttpGet get = new HttpGet(url);
CloseableHttpClient client = proxiedHttp();
CloseableHttpResponse response = null;
InputStream stream = null;
try {
response = client.execute(get, proxyContext(USER, PASS));
stream = response.getEntity().getContent();
final String resultingPom = IOUtils.toString(stream);
assertThat(resultingPom, notNullValue());
assertThat(resultingPom, equalTo(pom.pom));
} finally {
IOUtils.closeQuietly(stream);
HttpResources.cleanupResources(get, response, client);
}
final RemoteRepository remoteRepo = this.client.stores().load(new StoreKey(GENERIC_PKG_KEY, StoreType.remote, "httprox_127-0-0-1_" + server.getPort()), RemoteRepository.class);
assertThat(remoteRepo, notNullValue());
assertThat(remoteRepo.getUrl(), equalTo(server.getBaseUri()));
String pomUrl = this.client.content().contentUrl(remoteRepo.getKey(), testRepo, pom.path) + "?cache-only=true";
HttpHead head = new HttpHead(pomUrl);
client = HttpClients.createDefault();
try {
response = client.execute(head);
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
} finally {
HttpResources.cleanupResources(head, response, client);
}
}
use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.
the class StoreDataSetupAction method migrate.
@Override
public boolean migrate() throws IndyLifecycleException {
final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Initializing default data.");
boolean changed = false;
try {
logger.info("Verfiying that Indy basic stores are installed...");
storeManager.install();
if (!storeManager.query().packageType(MAVEN_PKG_KEY).storeType(RemoteRepository.class).containsByName("central")) {
final RemoteRepository central = new RemoteRepository(MAVEN_PKG_KEY, "central", "http://repo.maven.apache.org/maven2/");
central.setCacheTimeoutSeconds(86400);
storeManager.storeArtifactStore(central, summary, true, true, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, DEFAULT_SETUP));
changed = true;
}
if (!storeManager.query().packageType(MAVEN_PKG_KEY).storeType(HostedRepository.class).containsByName("local-deployments")) {
final HostedRepository local = new HostedRepository(MAVEN_PKG_KEY, "local-deployments");
local.setAllowReleases(true);
local.setAllowSnapshots(true);
local.setSnapshotTimeoutSeconds(86400);
storeManager.storeArtifactStore(local, summary, true, true, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, DEFAULT_SETUP));
changed = true;
}
if (!storeManager.query().packageType(MAVEN_PKG_KEY).storeType(Group.class).containsByName("public")) {
final Group pub = new Group(MAVEN_PKG_KEY, "public");
pub.addConstituent(new StoreKey(MAVEN_PKG_KEY, StoreType.remote, "central"));
pub.addConstituent(new StoreKey(MAVEN_PKG_KEY, StoreType.hosted, "local-deployments"));
storeManager.storeArtifactStore(pub, summary, true, true, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, DEFAULT_SETUP));
changed = true;
}
} catch (final IndyDataException e) {
throw new RuntimeException("Failed to boot indy components: " + e.getMessage(), e);
}
return changed;
}
use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.
the class ScheduleManager method setProxyTimeouts.
public synchronized void setProxyTimeouts(final StoreKey key, final String path) throws IndySchedulerException {
if (!schedulerConfig.isEnabled()) {
logger.debug("Scheduler disabled.");
return;
}
RemoteRepository repo = null;
try {
repo = (RemoteRepository) dataManager.getArtifactStore(key);
} catch (final IndyDataException e) {
logger.error(String.format("Failed to retrieve store for: %s. Reason: %s", key, e.getMessage()), e);
}
if (repo == null) {
return;
}
int timeout = config.getPassthroughTimeoutSeconds();
final ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(repo), path);
final SpecialPathInfo info = specialPathManager.getSpecialPathInfo(resource);
if (!repo.isPassthrough()) {
if ((info != null && info.isMetadata()) && repo.getMetadataTimeoutSeconds() > 0) {
logger.debug("Using metadata timeout for: {}", resource);
timeout = repo.getMetadataTimeoutSeconds();
} else {
if (info == null) {
logger.debug("No special path info for: {}", resource);
} else {
logger.debug("{} is a special path, but not metadata.", resource);
}
timeout = repo.getCacheTimeoutSeconds();
}
}
if (timeout > 0) {
// logger.info( "[PROXY TIMEOUT SET] {}/{}; {}", repo.getKey(), path, new Date( System.currentTimeMillis()
// + timeout ) );
cancel(new StoreKeyMatcher(key, CONTENT_JOB_TYPE), path);
scheduleContentExpiration(key, path, timeout);
}
}
use of org.commonjava.indy.model.core.RemoteRepository 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());
}
Aggregations