use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.
the class TimeoutEventListener method onStoreUpdate.
public void onStoreUpdate(@Observes final ArtifactStorePostUpdateEvent event) {
final ArtifactStoreUpdateType eventType = event.getType();
if (eventType == ArtifactStoreUpdateType.UPDATE) {
for (final ArtifactStore store : event) {
final StoreKey key = store.getKey();
final StoreType type = key.getType();
if (type == StoreType.hosted) {
logger.info("[ADJUST TIMEOUTS] Adjusting snapshot expirations in: {}", store.getKey());
try {
scheduleManager.rescheduleSnapshotTimeouts((HostedRepository) store);
} catch (final IndySchedulerException e) {
logger.error("Failed to update snapshot timeouts in: " + store.getKey(), e);
}
} else if (type == StoreType.remote) {
logger.info("[ADJUST TIMEOUTS] Adjusting proxied-file expirations in: {}", store.getKey());
try {
scheduleManager.rescheduleProxyTimeouts((RemoteRepository) store);
} catch (final IndySchedulerException e) {
logger.error("Failed to update proxy-cache timeouts in: " + store.getKey(), e);
}
}
}
}
}
use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.
the class LegacyDataMigrationAction method migrate.
@Override
public boolean migrate() throws IndyLifecycleException {
if (!(storeDataManager instanceof DataFileStoreDataManager)) {
logger.info("Store manager: {} is not based on DataFile's. Skipping migration.", storeDataManager.getClass().getName());
return false;
}
final DataFile basedir = dataFileManager.getDataFile(INDY_STORE);
final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Migrating legacy store definitions.");
if (!basedir.exists()) {
return false;
}
StoreType[] storeTypes = StoreType.values();
final String[] dirs = basedir.list();
if (dirs == null || dirs.length < 1) {
return false;
}
Map<String, String> migrationCandidates = new HashMap<>();
//noinspection ConstantConditions
Stream.of(storeTypes).forEach(type -> {
File[] files = basedir.getDetachedFile().toPath().resolve(type.singularEndpointName()).toFile().listFiles((dir, fname) -> fname.endsWith(".json"));
if (files != null) {
Stream.of(files).forEach((f) -> {
String src = Paths.get(type.singularEndpointName(), f.getName()).toString();
String target = Paths.get(MAVEN_PKG_KEY, type.singularEndpointName(), f.getName()).toString();
migrationCandidates.put(src, target);
});
}
});
boolean changed = false;
for (Map.Entry<String, String> entry : migrationCandidates.entrySet()) {
DataFile src = dataFileManager.getDataFile(INDY_STORE, entry.getKey());
DataFile target = dataFileManager.getDataFile(INDY_STORE, entry.getValue());
if (target.exists()) {
continue;
}
DataFile targetDir = target.getParent();
if (!targetDir.exists() && !targetDir.mkdirs()) {
throw new IndyLifecycleException("Cannot make directory: %s.", targetDir.getPath());
} else if (!targetDir.isDirectory()) {
throw new IndyLifecycleException("Not a directory: %s.", targetDir.getPath());
}
try {
logger.info("Migrating definition {}", src.getPath());
final String json = src.readString();
final String migrated = objectMapper.patchLegacyStoreJson(json);
target.writeString(migrated, summary);
changed = true;
} catch (final IOException e) {
throw new IndyLifecycleException("Failed to migrate artifact-store definition from: %s to: %s. Reason: %s", e, src, target, e.getMessage(), e);
}
}
if (changed) {
try {
storeDataManager.reload();
} catch (IndyDataException e) {
throw new IndyLifecycleException("Failed to reload migrated store definitions: %s", e, e.getMessage());
}
}
return changed;
}
use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.
the class StoreURIMatcher method getStoreFolderStoreType.
public StoreType getStoreFolderStoreType(final String uri) {
if (!matches()) {
return null;
}
if (hasStoreType()) {
final String typePart = matcher.group(STORE_TYPE_GRP);
// logger.info( "Type part of name is: '{}'", typePart );
final StoreType type = StoreType.get(typePart);
return type;
}
return null;
}
use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.
the class TrackedContentEntry method readExternal.
@Override
public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
trackingKey = (TrackingKey) in.readObject();
final String storeKeyName = (String) in.readObject();
final StoreType storeType = StoreType.get((String) in.readObject());
storeKey = new StoreKey(storeType, storeKeyName);
final String accessChannelStr = (String) in.readObject();
accessChannel = "".equals(accessChannelStr) ? null : AccessChannel.valueOf(accessChannelStr);
final String pathStr = (String) in.readObject();
path = "".equals(pathStr) ? null : pathStr;
final String originUrlStr = (String) in.readObject();
originUrl = "".equals(originUrlStr) ? null : originUrlStr;
final String effectStr = (String) in.readObject();
effect = "".equals(effectStr) ? null : StoreEffect.valueOf(effectStr);
final String md5Str = (String) in.readObject();
md5 = "".equals(md5Str) ? null : md5Str;
final String sha1Str = (String) in.readObject();
sha1 = "".equals(sha1Str) ? null : sha1Str;
final String sha256Str = (String) in.readObject();
sha256 = "".equals(sha256Str) ? null : sha256Str;
size = (Long) in.readObject();
index = in.readLong();
}
use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.
the class AffectedStoreRecordTest method recordUploadsSorted.
@Test
public void recordUploadsSorted() throws Exception {
final StoreType type = StoreType.group;
final String name = "test-group";
final AffectedStoreRecord record = new AffectedStoreRecord(new StoreKey(type, name));
record.add("/path/two", StoreEffect.UPLOAD);
record.add("/path/one", StoreEffect.UPLOAD);
assertThat(record.getUploadedPaths().iterator().next(), equalTo("/path/one"));
}
Aggregations