use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.
the class StoreEnablementManager method onDisableTimeout.
public void onDisableTimeout(@Observes SchedulerEvent evt) {
Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("Checking for store-reenable event in: {} (trigger? {} Disable-Timeout? {})", evt, evt instanceof SchedulerTriggerEvent, DISABLE_TIMEOUT.equals(evt.getJobType()));
if ((evt instanceof SchedulerTriggerEvent) && DISABLE_TIMEOUT.equals(evt.getJobType())) {
String keystr = evt.getPayload();
StoreKey key = null;
try {
key = objectMapper.readValue(keystr, StoreKey.class);
} catch (IOException e) {
logger.warn("Failed to read StoreKey from JSON string: '{}' in event payload.", keystr);
}
logger.debug("Read key: {} from JSON string: '{}' in event payload.", key, keystr);
if (key != null) {
try {
ArtifactStore store = storeDataManager.getArtifactStore(key);
if (store.isDisabled()) {
store.setDisabled(false);
storeDataManager.storeArtifactStore(store, new ChangeSummary(ChangeSummary.SYSTEM_USER, "Re-enabling " + key), false, true, new EventMetadata());
cancelReEnablementTimeout(key);
}
} catch (IndyDataException e) {
logger.error(String.format("Failed to re-enable %s", key), e);
} catch (IndySchedulerException e) {
logger.error(String.format("Failed to delete re-enablement job for %s.", key), e);
}
}
}
}
use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.
the class AdminController method store.
public boolean store(final ArtifactStore store, final String user, final boolean skipExisting) throws IndyWorkflowException {
try {
String changelog = store.getMetadata(ArtifactStore.METADATA_CHANGELOG);
if (changelog == null) {
changelog = "Changelog not provided";
}
final ChangeSummary summary = new ChangeSummary(user, changelog);
logger.info("Persisting artifact store: {} using: {}", store, storeManager);
return storeManager.storeArtifactStore(store, summary, skipExisting, true, new EventMetadata());
} catch (final IndyDataException e) {
throw new IndyWorkflowException(ApplicationStatus.SERVER_ERROR.code(), "Failed to store: {}. Reason: {}", e, store.getKey(), e.getMessage());
}
}
use of org.commonjava.maven.galley.event.EventMetadata 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.maven.galley.event.EventMetadata 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.maven.galley.event.EventMetadata 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();
}
Aggregations