use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class StoreAdminHandler method revalidateArtifactStore.
@ApiOperation("Revalidation of Artifact Stored on demand based on package, type and name")
@ApiResponses({ @ApiResponse(code = 200, response = ArtifactStore.class, message = "Revalidation for Remote Repository was successfull"), @ApiResponse(code = 404, message = "Revalidation is not successfull") })
@Path("/{name}/revalidate")
@POST
public Response revalidateArtifactStore(@PathParam("packageType") final String packageType, @ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @ApiParam(required = true) @PathParam("name") final String name) {
ArtifactStoreValidateData result = null;
Response response;
try {
final StoreType st = StoreType.get(type);
final StoreKey key = new StoreKey(packageType, st, name);
final ArtifactStore store = adminController.get(key);
logger.info("=> Returning repository: {}", store);
// Validate this Store
result = adminController.validateStore(store);
logger.warn("=> Result from Validating Store: " + result);
if (result == null) {
response = Response.status(Status.NOT_FOUND).build();
} else {
response = responseHelper.formatOkResponseWithJsonEntity(result);
}
} catch (IndyDataException ide) {
logger.warn("=> [IndyDataException] exception message: " + ide.getMessage());
response = responseHelper.formatResponse(ide);
} catch (MalformedURLException mue) {
logger.warn("=> [MalformedURLException] Invalid URL exception message: " + mue.getMessage());
response = responseHelper.formatResponse(mue);
} catch (IndyWorkflowException iwe) {
logger.warn("=> [IndyWorkflowException] exception message: " + iwe.getMessage());
response = responseHelper.formatResponse(iwe);
}
return response;
}
use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class IndyLocationResolver method resolve.
@Override
public Location resolve(final String spec) throws TransferException {
ArtifactStore store;
try {
final StoreKey source = StoreKey.fromString(spec);
if (source == null) {
throw new TransferException("Failed to parse StoreKey (format: '[remote|hosted|group]:name') from: '%s'.");
}
store = dataManager.getArtifactStore(source);
} catch (final IndyDataException e) {
throw new TransferException("Cannot find ArtifactStore to match source key: %s. Reason: %s", e, spec, e.getMessage());
}
if (store == null) {
throw new TransferException("Cannot find ArtifactStore to match source key: %s.", spec);
}
final KeyedLocation location = LocationUtils.toLocation(store);
logger.debug("resolved source location: '{}' to: '{}'", spec, location);
return location;
}
use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class PrefetchManager method registerPrefetchStores.
public void registerPrefetchStores(@Observes final ArtifactStorePostUpdateEvent updateEvent) {
if (config.isEnabled()) {
logger.trace("Post update triggered for scheduling of prefetch: {}", updateEvent);
final Collection<ArtifactStore> stores = updateEvent.getStores();
boolean scheduled = false;
for (ArtifactStore changedStore : stores) {
if (changedStore.getType() == StoreType.remote) {
ArtifactStore origStore = updateEvent.getOriginal(changedStore);
final RemoteRepository changedRemote = (RemoteRepository) changedStore;
final RemoteRepository origRemote = (RemoteRepository) origStore;
final boolean remotePrefetchEnabled = (origRemote != null && !origRemote.getPrefetchPriority().equals(changedRemote.getPrefetchPriority())) && changedRemote.getPrefetchPriority() > 0;
if (remotePrefetchEnabled) {
List<RescanablePath> paths = frontier.buildPaths(changedRemote, false);
logger.trace("Schedule resources: repo: {}, paths {}", changedRemote, paths);
frontier.scheduleRepo(changedRemote, paths);
scheduled = true;
}
}
}
if (scheduled) {
triggerWorkers();
}
}
}
use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class RepositoryDataManagerTCK method createTwoReposAndRetrieveAll.
@Test
public void createTwoReposAndRetrieveAll() throws Exception {
final StoreDataManager manager = getFixtureProvider().getDataManager();
final RemoteRepository repo = new RemoteRepository("central", "http://repo1.maven.apache.org/maven2/");
storeRemoteRepository(repo);
final RemoteRepository repo2 = new RemoteRepository("test", "http://www.google.com");
storeRemoteRepository(repo2);
final List<RemoteRepository> repositories = manager.query().getAllRemoteRepositories(MAVEN_PKG_KEY);
assertThat(repositories, notNullValue());
assertThat(repositories.size(), equalTo(2));
Collections.sort(repositories, new Comparator<RemoteRepository>() {
@Override
public int compare(final RemoteRepository r1, final RemoteRepository r2) {
return r1.getName().compareTo(r2.getName());
}
});
ArtifactStore r = repositories.get(0);
assertThat(r.getName(), equalTo(repo.getName()));
r = repositories.get(1);
assertThat(r.getName(), equalTo(repo2.getName()));
}
use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.
the class KojiRepairManager method repairPathMask.
public KojiRepairResult repairPathMask(KojiRepairRequest request, String user, boolean skipLock) throws KojiRepairException {
KojiRepairResult ret = new KojiRepairResult(request);
if (skipLock || opLock.tryLock()) {
try {
ArtifactStore store = getRequestedStore(request, ret);
if (store == null) {
return ret;
}
store = store.copyOf();
StoreKey remoteKey = request.getSource();
if (remoteKey.getType() == remote) {
final String nvr = kojiUtils.getBuildNvr(remoteKey);
if (nvr == null) {
String error = String.format("Not a koji store: %s", remoteKey);
return ret.withError(error);
}
try {
KojiSessionInfo session = null;
KojiBuildInfo build = kojiCachedClient.getBuildInfo(nvr, session);
List<KojiArchiveInfo> archives = kojiCachedClient.listArchivesForBuild(build.getId(), session);
ArtifactRef artifactRef = SimpleArtifactRef.parse(store.getMetadata(CREATION_TRIGGER_GAV));
if (artifactRef == null) {
String error = String.format("Koji remote repository: %s does not have %s metadata. Cannot retrieve accurate path masks.", remoteKey, CREATION_TRIGGER_GAV);
return ret.withError(error);
}
// set pathMaskPatterns using build output paths
Set<String> patterns = kojiPathFormatter.getPatterns(store.getKey(), artifactRef, archives, true);
logger.debug("For repo: {}, resetting path_mask_patterns to:\n\n{}\n\n", store.getKey(), patterns);
KojiRepairResult.RepairResult repairResult = new KojiRepairResult.RepairResult(remoteKey);
repairResult.withPropertyChange("path_mask_patterns", store.getPathMaskPatterns(), patterns);
ret.withResult(repairResult);
store.setPathMaskPatterns(patterns);
final ChangeSummary changeSummary = new ChangeSummary(user, "Repairing remote repository path masks to Koji build: " + build.getNvr());
storeManager.storeArtifactStore(store, changeSummary, false, true, new EventMetadata());
} catch (KojiClientException e) {
String error = String.format("Cannot getBuildInfo: %s, error: %s", remoteKey, e);
logger.debug(error, e);
return ret.withError(error, e);
} catch (IndyDataException e) {
String error = String.format("Failed to store changed remote repository: %s, error: %s", remoteKey, e);
logger.debug(error, e);
return ret.withError(error, e);
}
} else {
String error = String.format("Not a remote koji repository: %s", remoteKey);
return ret.withError(error);
}
} finally {
if (!skipLock) {
opLock.unlock();
}
}
} else {
throw new KojiRepairException("Koji repair manager is busy.");
}
return ret;
}
Aggregations