use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.
the class ImpliedRepositoryDetector method initJob.
private boolean initJob(final ImplicationsJob job) {
switch(job.event.getType()) {
case DOWNLOAD:
case UPLOAD:
break;
default:
// we're not interested in these.
return false;
}
final Transfer transfer = job.transfer;
if (!transfer.getPath().endsWith(".pom")) {
return false;
}
final Location location = transfer.getLocation();
if (!(location instanceof KeyedLocation)) {
return false;
}
final StoreKey key = ((KeyedLocation) location).getKey();
try {
job.store = storeManager.getArtifactStore(key);
} catch (final IndyDataException e) {
logger.error(String.format("Cannot retrieve artifact store for: %s. Failed to process implied repositories.", key), e);
}
if (job.store == null) {
return false;
}
job.pathInfo = ArtifactPathInfo.parse(transfer.getPath());
if (job.pathInfo == null) {
return false;
}
try {
logger.debug("Parsing: {}", transfer);
job.pomView = pomReader.readLocalPom(job.pathInfo.getProjectId(), transfer, MavenPomView.ALL_PROFILES);
} catch (final GalleyMavenException e) {
logger.error(String.format("Cannot parse: %s from: %s. Failed to process implied repositories.", job.pathInfo.getProjectId(), transfer), e);
}
return job.pomView != null;
}
use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.
the class ImpliedRepositoryDetector method addImpliedRepositories.
private void addImpliedRepositories(final ImplicationsJob job) {
job.implied = new ArrayList<>();
logger.debug("Retrieving repository/pluginRepository declarations from:\n {}", new JoinString("\n ", job.pomView.getDocRefStack()));
final List<List<RepositoryView>> repoLists = Arrays.asList(job.pomView.getNonProfileRepositories(), job.pomView.getAllPluginRepositories());
final ImpliedRepositoryCreator creator = createRepoCreator();
if (creator == null) {
logger.error("Cannot proceed without a valid ImpliedRepositoryCreator instance. Aborting detection.");
return;
}
for (final List<RepositoryView> repos : repoLists) {
if (repos == null || repos.isEmpty()) {
continue;
}
for (final RepositoryView repo : repos) {
final ProjectVersionRef gav = job.pathInfo.getProjectId();
try {
if (config.isBlacklisted(repo.getUrl())) {
logger.debug("Discarding blacklisted repository: {}", repo);
continue;
} else if (!config.isIncludeSnapshotRepos() && !repo.isReleasesEnabled()) {
logger.debug("Discarding snapshot repository: {}", repo);
continue;
}
} catch (final MalformedURLException e) {
logger.error(String.format("Cannot add implied remote repo: %s from: %s (transfer: %s). Failed to check if repository is blacklisted.", repo.getUrl(), gav, job.transfer), e);
}
logger.debug("Detected POM-declared repository: {}", repo);
RemoteRepository rr = null;
try {
rr = storeManager.query().packageType(MAVEN_PKG_KEY).getRemoteRepositoryByUrl(repo.getUrl());
} catch (IndyDataException e) {
logger.error(String.format("Cannot lookup remote repositories by URL: %s. Reason: %s", e.getMessage()), e);
}
if (rr == null) {
logger.debug("Creating new RemoteRepository for: {}", repo);
rr = creator.createFrom(gav, repo, LoggerFactory.getLogger(creator.getClass()));
if (rr == null) {
logger.warn("ImpliedRepositoryCreator didn't create anything for repo: {}, specified in: {}. Skipping.", repo.getId(), gav);
continue;
}
rr.setMetadata(METADATA_ORIGIN, IMPLIED_REPO_ORIGIN);
if (!remoteValidator.isValid(rr)) {
logger.warn("Implied repository to: {} is invalid! Repository created was: {}", repo.getUrl(), rr);
continue;
}
final String changelog = String.format("Adding remote repository: %s (url: %s, name: %s), which is implied by the POM: %s (at: %s/%s)", repo.getId(), repo.getUrl(), repo.getName(), gav, job.transfer.getLocation().getUri(), job.transfer.getPath());
final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, changelog);
try {
final boolean result = storeManager.storeArtifactStore(rr, summary, true, false, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, IMPLIED_REPOS_DETECTION).set(IMPLIED_BY_POM_TRANSFER, job.transfer));
logger.debug("Stored new RemoteRepository: {}. (successful? {})", rr, result);
job.implied.add(rr);
} catch (final IndyDataException e) {
logger.error(String.format("Cannot add implied remote repo: %s from: %s (transfer: %s). Failed to store new remote repository.", repo.getUrl(), gav, job.transfer), e);
}
} else {
logger.debug("Found existing RemoteRepository: {}", rr);
}
}
}
}
use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.
the class MergedFileUploadListener method reMergeUploaded.
// NOTE: Disabling @Observes on this because I'm pretty sure the ContentManager is handling it now.
public void reMergeUploaded(/*@Observes*/
final FileEvent event) {
if (event instanceof FileAccessEvent) {
return;
}
final String path = event.getTransfer().getPath();
final StoreKey key = getKey(event);
if (!path.endsWith(MavenMetadataMerger.METADATA_NAME) && !path.endsWith(ArchetypeCatalogMerger.CATALOG_NAME)) {
return;
}
try {
final Set<Group> groups = dataManager.query().getGroupsContaining(key);
if (groups != null) {
for (final Group group : groups) {
try {
reMerge(group, path);
} catch (final IOException e) {
logger.error(String.format("Failed to delete: %s from group: %s. Error: %s", path, group, e.getMessage()), e);
}
}
}
} catch (final IndyDataException e) {
logger.warn("Failed to regenerate maven-metadata.xml for groups after deployment to: {}" + "\nCannot retrieve associated groups: {}", e, key, e.getMessage());
}
}
use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.
the class PromotionManager method rollbackGroupPromote.
public GroupPromoteResult rollbackGroupPromote(GroupPromoteResult result, String user) throws PromotionException {
GroupPromoteRequest request = result.getRequest();
if (!storeManager.hasArtifactStore(request.getSource())) {
String error = String.format("No such source/member store: %s", request.getSource());
logger.warn(error);
return new GroupPromoteResult(request, error);
}
Group target;
try {
target = (Group) storeManager.getArtifactStore(request.getTargetKey());
} catch (IndyDataException e) {
throw new PromotionException("Cannot retrieve target group: %s. Reason: %s", e, request.getTargetGroup(), e.getMessage());
}
if (target == null) {
String error = String.format("No such target group: %s.", request.getTargetGroup());
logger.warn(error);
return new GroupPromoteResult(request, error);
}
if (target.getConstituents().contains(request.getSource())) {
// give the preUpdate event a different object to compare vs. the original group.
target = target.copyOf();
target.removeConstituent(request.getSource());
try {
final ChangeSummary changeSummary = new ChangeSummary(user, "Removing " + request.getSource() + " from membership of group: " + target.getKey());
storeManager.storeArtifactStore(target, changeSummary, false, true, new EventMetadata());
} catch (IndyDataException e) {
throw new PromotionException("Failed to store group: %s with additional member: %s. Reason: %s", e, target.getKey(), request.getSource(), e.getMessage());
}
} else {
return new GroupPromoteResult(request, "Group: " + target.getKey() + " does not contain member: " + request.getSource());
}
return new GroupPromoteResult(request);
}
use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.
the class PromotionManager method rollbackPathsPromote.
/**
* Attempt to rollbackPathsPromote a previously failing {@link PathsPromoteResult}. This is meant to handle cases where an unrecoverable error
* occurs on the server side, and promotion can NOT proceed afterward. All paths in the completed paths set are deleted from the target, if
* possible. The output {@link PathsPromoteResult} contains the previous content, with any successfully removed target paths moved back from the
* completed-paths list to the pending-paths list. If an error occurs during rollbackPathsPromote, the error field will be set...otherwise, it will be null.
*
* @param result The result to rollbackPathsPromote
*
* @return The same result, with any successful deletions moved from the completed to pending paths list, and the error cleared (or set to a
* new error)
*
* @throws PromotionException
* @throws IndyWorkflowException
*/
public PathsPromoteResult rollbackPathsPromote(final PathsPromoteResult result) throws PromotionException, IndyWorkflowException {
StoreKey targetKey = result.getRequest().getTarget();
ReentrantLock lock;
synchronized (byPathTargetLocks) {
lock = byPathTargetLocks.get(targetKey);
if (lock == null) {
lock = new ReentrantLock();
byPathTargetLocks.put(targetKey, lock);
}
}
final List<Transfer> contents = getTransfersForPaths(targetKey, result.getCompletedPaths());
final Set<String> completed = result.getCompletedPaths();
final Set<String> skipped = result.getSkippedPaths();
if (completed == null || completed.isEmpty()) {
result.setError(null);
return result;
}
Set<String> pending = result.getPendingPaths();
pending = pending == null ? new HashSet<String>() : new HashSet<String>(pending);
String error = null;
final boolean copyToSource = result.getRequest().isPurgeSource();
ArtifactStore source = null;
try {
source = storeManager.getArtifactStore(result.getRequest().getSource());
} catch (final IndyDataException e) {
error = String.format("Failed to retrieve artifact store: %s. Reason: %s", result.getRequest().getSource(), e.getMessage());
logger.error(error, e);
}
boolean locked = false;
try {
if (error == null) {
locked = lock.tryLock(config.getLockTimeoutSeconds(), TimeUnit.SECONDS);
if (!locked) {
error = String.format("Failed to acquire promotion lock on target: %s in %d seconds.", targetKey, config.getLockTimeoutSeconds());
logger.warn(error);
}
}
if (error == null) {
for (final Transfer transfer : contents) {
if (transfer != null && transfer.exists()) {
InputStream stream = null;
try {
if (copyToSource) {
stream = transfer.openInputStream(true);
final String path = transfer.getPath();
contentManager.store(source, path, stream, TransferOperation.UPLOAD, new EventMetadata());
stream.close();
}
transfer.delete(true);
completed.remove(transfer.getPath());
pending.add(transfer.getPath());
} catch (final IOException e) {
error = String.format("Failed to rollback path promotion of: %s from: %s. Reason: %s", transfer, result.getRequest().getSource(), e.getMessage());
logger.error(error, e);
} finally {
closeQuietly(stream);
}
}
}
}
} catch (InterruptedException e) {
error = String.format("Interrupted waiting for promotion lock on target: %s", targetKey);
logger.warn(error);
} finally {
if (locked) {
lock.unlock();
}
}
return new PathsPromoteResult(result.getRequest(), pending, completed, skipped, error, new ValidationResult());
}
Aggregations