use of org.commonjava.indy.audit.ChangeSummary 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.audit.ChangeSummary in project indy by Commonjava.
the class ImpliedRepositoryDetector method updateExistingGroups.
private boolean updateExistingGroups(final ImplicationsJob job) {
final StoreKey key = job.store.getKey();
boolean anyChanged = false;
try {
final Set<Group> groups = storeManager.query().packageType(MAVEN_PKG_KEY).getGroupsContaining(key);
if (groups != null) {
logger.debug("{} groups contain: {}\n {}", groups.size(), key, new JoinString("\n ", groups));
final String message = String.format("Adding repositories implied by: %s\n\n %s", key, StringUtils.join(job.implied, "\n "));
final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, message);
for (final Group g : groups) {
Group group = g.copyOf();
boolean changed = false;
for (final ArtifactStore implied : job.implied) {
boolean groupChanged = group.addConstituent(implied);
changed = groupChanged || changed;
logger.debug("After attempting to add: {} to group: {}, changed status is: {}", implied, group, changed);
}
if (changed) {
storeManager.storeArtifactStore(group, summary, false, false, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, IMPLIED_REPOS_DETECTION).set(IMPLIED_REPOS, job.implied));
}
anyChanged = changed || anyChanged;
}
}
} catch (final IndyDataException e) {
logger.error("Failed to lookup groups containing: " + key, e);
}
return anyChanged;
}
use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.
the class ImpliedReposOriginMigrationAction method migrate.
@Override
public boolean migrate() throws IndyLifecycleException {
List<RemoteRepository> remoteRepositories;
try {
remoteRepositories = storeDataManager.query().getAllRemoteRepositories();
} catch (IndyDataException e) {
throw new IndyLifecycleException("Cannot retrieve all remote repositories. Reason: %s", e, e.getMessage());
}
List<RemoteRepository> toStore = new ArrayList<>();
remoteRepositories.forEach((repo) -> {
if (repo.getName().startsWith("i-")) {
repo.setMetadata(METADATA_ORIGIN, IMPLIED_REPO_ORIGIN);
toStore.add(repo);
}
});
for (RemoteRepository repo : toStore) {
try {
storeDataManager.storeArtifactStore(repo, new ChangeSummary(ChangeSummary.SYSTEM_USER, "Adding implied-repository origin metadata"), false, true, new EventMetadata());
} catch (IndyDataException e) {
throw new IndyLifecycleException("Failed to store %s with implied-repos origin metadata. Reason: %s", e, repo == null ? "NULL REPO" : repo.getKey(), e.getMessage());
}
}
return !toStore.isEmpty();
}
use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.
the class PromotionManagerTest method promoteAllByPath_PushTwoArtifactsToHostedRepo_VerifyCopiedToOtherHostedRepo.
@Test
public void promoteAllByPath_PushTwoArtifactsToHostedRepo_VerifyCopiedToOtherHostedRepo() throws Exception {
final HostedRepository source = new HostedRepository(MAVEN_PKG_KEY, "source");
storeManager.storeArtifactStore(source, new ChangeSummary(ChangeSummary.SYSTEM_USER, "test setup"), false, true, new EventMetadata());
final String first = "/first/path";
final String second = "/second/path";
contentManager.store(source, first, new ByteArrayInputStream("This is a test".getBytes()), TransferOperation.UPLOAD, new EventMetadata());
contentManager.store(source, second, new ByteArrayInputStream("This is a test".getBytes()), TransferOperation.UPLOAD, new EventMetadata());
final HostedRepository target = new HostedRepository(MAVEN_PKG_KEY, "target");
storeManager.storeArtifactStore(target, new ChangeSummary(ChangeSummary.SYSTEM_USER, "test setup"), false, true, new EventMetadata());
final PathsPromoteResult result = manager.promotePaths(new PathsPromoteRequest(source.getKey(), target.getKey()), FAKE_BASE_URL);
assertThat(result.getRequest().getSource(), equalTo(source.getKey()));
assertThat(result.getRequest().getTarget(), equalTo(target.getKey()));
final Set<String> pending = result.getPendingPaths();
assertThat(pending == null || pending.isEmpty(), equalTo(true));
final Set<String> completed = result.getCompletedPaths();
assertThat(completed, notNullValue());
assertThat(completed.size(), equalTo(2));
assertThat(result.getError(), nullValue());
Transfer ref = downloadManager.getStorageReference(target, first);
assertThat(ref.exists(), equalTo(true));
ref = downloadManager.getStorageReference(target, second);
assertThat(ref.exists(), equalTo(true));
}
use of org.commonjava.indy.audit.ChangeSummary in project indy by Commonjava.
the class KojiContentManagerDecorator method createRemoteRepository.
private RemoteRepository createRemoteRepository(StoreKey inStore, ArtifactRef artifactRef, final KojiBuildInfo build, final KojiSessionInfo session) throws KojiClientException {
Logger logger = LoggerFactory.getLogger(getClass());
try {
KojiBuildArchiveCollection archiveCollection = kojiClient.listArchivesForBuild(build, session);
boolean isBinaryBuild = isBinaryBuild(build);
String name = getRepositoryName(build, isBinaryBuild);
// Using a RemoteRepository allows us to use the higher-level APIs in Indy, as opposed to TransferManager
final KojiRepositoryCreator creator = createRepoCreator();
if (creator == null) {
throw new KojiClientException("Cannot proceed without a valid KojiRepositoryCreator instance.");
}
RemoteRepository remote = creator.createRemoteRepository(inStore.getPackageType(), name, formatStorageUrl(build), config.getDownloadTimeoutSeconds());
remote.setServerCertPem(config.getServerPemContent());
if (isBinaryBuild) {
remote.setMetadata(ArtifactStore.METADATA_ORIGIN, KOJI_ORIGIN_BINARY);
} else {
remote.setMetadata(ArtifactStore.METADATA_ORIGIN, KOJI_ORIGIN);
}
// set pathMaskPatterns using build output paths
Set<String> patterns = new HashSet<>();
patterns.addAll(archiveCollection.getArchives().stream().map(a -> a.getGroupId().replace('.', '/') + "/" + a.getArtifactId() + "/" + a.getVersion() + "/" + a.getFilename()).collect(Collectors.toSet()));
remote.setPathMaskPatterns(patterns);
remote.setMetadata(CREATION_TRIGGER_GAV, artifactRef.toString());
remote.setMetadata(NVR, build.getNvr());
final ChangeSummary changeSummary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Creating remote repository for Koji build: " + build.getNvr());
storeDataManager.storeArtifactStore(remote, changeSummary, false, true, new EventMetadata());
logger.debug("Koji {}, add pathMaskPatterns: {}", name, patterns);
return remote;
} catch (MalformedURLException e) {
throw new KojiClientException("Koji add-on seems misconifigured. Could not generate URL to repo for " + "build: %s\nBase URL: %s\nError: %s", e, build.getNvr(), config.getStorageRootUrl(), e.getMessage());
} catch (IOException e) {
throw new KojiClientException("Failed to read server SSL PEM information from Koji configuration for new hosted repo: %s", e, e.getMessage());
} catch (IndyDataException e) {
throw new KojiClientException("Failed to store temporary remote repo: %s", e, e.getMessage());
}
}
Aggregations