use of org.commonjava.indy.data.IndyDataException 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.data.IndyDataException in project indy by Commonjava.
the class ScheduleManager method rescheduleDisableTimeout.
public synchronized void rescheduleDisableTimeout(final StoreKey key) throws IndySchedulerException {
if (!schedulerConfig.isEnabled()) {
logger.debug("Scheduler disabled.");
return;
}
ArtifactStore store = null;
try {
store = dataManager.getArtifactStore(key);
} catch (final IndyDataException e) {
logger.error(String.format("Failed to retrieve store for: %s. Reason: %s", key, e.getMessage()), e);
}
if (store == null) {
return;
}
int timeout = store.getDisableTimeout();
if (timeout == TIMEOUT_USE_DEFAULT) {
// case TIMEOUT_USE_DEFAULT: will use default timeout configuration
timeout = config.getStoreDisableTimeoutSeconds();
}
if (timeout > TIMEOUT_USE_DEFAULT && store.isDisabled()) {
final StoreKey sk = store.getKey();
logger.debug("Set/Reschedule disable timeout for store:{}", sk);
scheduleForStore(sk, DISABLE_TIMEOUT, DISABLE_TIMEOUT, sk, timeout);
}
// Will never consider the TIMEOUT_NEVER_DISABLE case here, will consider this in the calling object(StoreEnablementManager)
}
use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.
the class StoreContentListener method removeAllSupercededMemberContent.
// TODO: If we find points where a new HostedRepository is added, we should be using its comprehensive index to minimize the index damage to the group.
private void removeAllSupercededMemberContent(final ArtifactStore store, final Map<ArtifactStore, ArtifactStore> changeMap) {
Logger logger = LoggerFactory.getLogger(getClass());
StoreKey key = store.getKey();
// we're only interested in groups, since only adjustments to group memberships can invalidate indexed content.
if (StoreType.group == key.getType()) {
List<StoreKey> newMembers = ((Group) store).getConstituents();
logger.debug("New members of: {} are: {}", store, newMembers);
Group group = (Group) changeMap.get(store);
List<StoreKey> oldMembers = group.getConstituents();
logger.debug("Old members of: {} are: {}", group, oldMembers);
int commonSize = Math.min(newMembers.size(), oldMembers.size());
int divergencePoint;
// look in the members that overlap in new/old groups and see if there are changes that would
// indicate member reordering. If so, it might lead previously suppressed results to be prioritized,
// which would invalidate part of the content index for the group.
boolean foundDivergence = false;
for (divergencePoint = 0; divergencePoint < commonSize; divergencePoint++) {
logger.debug("Checking for common member at index: {}", divergencePoint);
if (!oldMembers.get(divergencePoint).equals(newMembers.get(divergencePoint))) {
foundDivergence = true;
break;
}
}
// that include the one we're affecting directly here...using clearIndexedPathFrom() to do this.
if (!foundDivergence) {
if (newMembers.size() < oldMembers.size()) {
divergencePoint = commonSize;
} else {
divergencePoint = newMembers.size();
}
}
logger.debug("group membership divergence point: {}", divergencePoint);
Set<StoreKey> affectedMembers = new HashSet<>();
boolean removeMergableOnly = divergencePoint >= oldMembers.size();
// group content index entries for those.
if (divergencePoint < oldMembers.size()) {
for (int i = divergencePoint; i < oldMembers.size(); i++) {
affectedMembers.add(oldMembers.get(i));
}
} else {
// See [NOS-128]
for (int i = divergencePoint - 1; i >= commonSize; i--) {
affectedMembers.add(newMembers.get(i));
}
}
logger.debug("Got members affected by membership divergence: {}", affectedMembers);
if (!affectedMembers.isEmpty()) {
Set<Group> groups = new HashSet<>();
groups.add(group);
try {
groups.addAll(storeDataManager.query().packageType(group.getPackageType()).getGroupsAffectedBy(group.getKey()));
} catch (IndyDataException e) {
logger.error(String.format("Cannot retrieve groups affected by: %s. Reason: %s", group.getKey(), e.getMessage()), e);
}
logger.debug("Got affected groups: {}", groups);
affectedMembers.parallelStream().forEach((memberKey) -> {
logger.debug("Listing all {}paths in: {}", (removeMergableOnly ? "mergeable " : ""), memberKey);
Set<String> paths = listPaths(memberKey, removeMergableOnly ? mergablePathStrings() : (p) -> true);
logger.debug("Got mergable transfers from diverged portion of membership: {}", paths);
clearPaths(paths, memberKey, groups, false);
});
}
}
}
use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.
the class DefaultContentManager method store.
@Override
public Transfer store(final ArtifactStore store, final String path, final InputStream stream, final TransferOperation op, final EventMetadata eventMetadata) throws IndyWorkflowException {
if (group == store.getKey().getType()) {
try {
final List<ArtifactStore> allMembers = storeManager.query().packageType(store.getPackageType()).enabledState(true).getOrderedConcreteStoresInGroup(store.getName());
final Transfer txfr = store(allMembers, store.getKey(), path, stream, op, eventMetadata);
logger.info("Stored: {} for group: {} in: {}", path, store.getKey(), txfr);
return txfr;
} catch (final IndyDataException e) {
throw new IndyWorkflowException("Failed to lookup concrete members of: %s. Reason: %s", e, store, e.getMessage());
}
}
logger.info("Storing: {} for: {} with event metadata: {}", path, store.getKey(), eventMetadata);
final Transfer txfr = downloadManager.store(store, path, stream, op, eventMetadata);
if (txfr != null) {
final KeyedLocation kl = (KeyedLocation) txfr.getLocation();
ArtifactStore transferStore;
try {
transferStore = storeManager.getArtifactStore(kl.getKey());
} catch (final IndyDataException e) {
throw new IndyWorkflowException("Failed to lookup store: %s. Reason: %s", e, kl.getKey(), e.getMessage());
}
for (final ContentGenerator generator : contentGenerators) {
generator.handleContentStorage(transferStore, path, txfr, eventMetadata);
}
if (!store.equals(transferStore)) {
for (final ContentGenerator generator : contentGenerators) {
generator.handleContentStorage(transferStore, path, txfr, eventMetadata);
}
}
}
return txfr;
}
use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.
the class DefaultContentManager method store.
// @Override
// public Transfer store( final List<? extends ArtifactStore> stores, final String path, final InputStream stream,
// final TransferOperation op )
// throws IndyWorkflowException
// {
// return store( stores, path, stream, op, new EventMetadata() );
// }
@Override
public Transfer store(final List<? extends ArtifactStore> stores, final StoreKey topKey, final String path, final InputStream stream, final TransferOperation op, final EventMetadata eventMetadata) throws IndyWorkflowException {
logger.info("Storing: {} in: {} with event metadata: {}", path, stores, eventMetadata);
final Transfer txfr = downloadManager.store(stores, path, stream, op, eventMetadata);
if (txfr != null) {
final KeyedLocation kl = (KeyedLocation) txfr.getLocation();
ArtifactStore transferStore;
try {
transferStore = storeManager.getArtifactStore(kl.getKey());
} catch (final IndyDataException e) {
throw new IndyWorkflowException("Failed to lookup store: %s. Reason: %s", e, kl.getKey(), e.getMessage());
}
for (final ContentGenerator generator : contentGenerators) {
logger.info("{} Handling content storage of: {} in: {}", generator, path, transferStore.getKey());
generator.handleContentStorage(transferStore, path, txfr, eventMetadata);
}
}
return txfr;
}
Aggregations