use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.
the class AffectedStoreRecordTest method roundTripEmptyRecordToJson.
@Test
public void roundTripEmptyRecordToJson() throws Exception {
final StoreType type = StoreType.group;
final String name = "test-group";
final AffectedStoreRecord record = new AffectedStoreRecord(new StoreKey(type, name));
final String json = mapper.writeValueAsString(record);
System.out.println(json);
final AffectedStoreRecord result = mapper.readValue(json, AffectedStoreRecord.class);
assertThat(result, notNullValue());
assertThat(result.getKey(), equalTo(record.getKey()));
assertThat(result.getDownloadedPaths(), nullValue());
assertThat(result.getUploadedPaths(), nullValue());
}
use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.
the class AffectedStoreRecordTest method roundTripRecordWithTwoDownloadsToJson.
@Test
public void roundTripRecordWithTwoDownloadsToJson() throws Exception {
final StoreType type = StoreType.group;
final String name = "test-group";
final AffectedStoreRecord record = new AffectedStoreRecord(new StoreKey(type, name));
record.add("/path/one", StoreEffect.DOWNLOAD);
record.add("/path/two", StoreEffect.DOWNLOAD);
final String json = mapper.writeValueAsString(record);
System.out.println(json);
final AffectedStoreRecord result = mapper.readValue(json, AffectedStoreRecord.class);
assertThat(result, notNullValue());
assertThat(result.getKey(), equalTo(record.getKey()));
assertThat(result.getDownloadedPaths(), equalTo(record.getDownloadedPaths()));
assertThat(result.getUploadedPaths(), nullValue());
}
use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.
the class DataFileStoreDataManager method readDefinitions.
@PostConstruct
public void readDefinitions() {
final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Reading definitions from disk, culling invalid definition files.");
try {
DataFile[] packageDirs = manager.getDataFile(INDY_STORE).listFiles((f) -> true);
for (DataFile pkgDir : packageDirs) {
for (StoreType type : StoreType.values()) {
DataFile[] files = pkgDir.getChild(type.singularEndpointName()).listFiles(f -> true);
if (files != null) {
for (final DataFile f : files) {
try {
final String json = f.readString();
final ArtifactStore store = serializer.readValue(json, type.getStoreClass());
if (store == null) {
f.delete(summary);
} else {
storeArtifactStore(store, summary, false, false, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, LOAD_FROM_DISK));
}
} catch (final IOException e) {
logger.error(String.format("Failed to load %s store: %s. Reason: %s", type, f, e.getMessage()), e);
}
}
}
}
}
started = true;
} catch (final IndyDataException e) {
throw new IllegalStateException("Failed to start store data manager: " + e.getMessage(), e);
}
}
use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.
the class TimeoutEventListener method onFileAccessEvent.
public void onFileAccessEvent(@Observes final FileAccessEvent event) {
// TODO: handle this stuff in Weft somehow...
Map original = MDC.getCopyOfContextMap();
try {
MDC.setContextMap(event.getMDCMap());
final StoreKey key = getKey(event);
if (key != null) {
final Transfer transfer = event.getTransfer();
final StoreType type = key.getType();
if (type == StoreType.hosted) {
try {
scheduleManager.setSnapshotTimeouts(key, transfer.getPath());
} catch (final IndySchedulerException e) {
logger.error("Failed to set snapshot timeouts related to: " + transfer, e);
}
} else if (type == StoreType.remote) {
SpecialPathInfo info = specialPathManager.getSpecialPathInfo(transfer);
if (info == null || !info.isMetadata()) {
logger.debug("Accessed resource {} timeout will be reset.", transfer);
try {
scheduleManager.setProxyTimeouts(key, transfer.getPath());
} catch (final IndySchedulerException e) {
logger.error("Failed to set proxy-cache timeouts related to: " + transfer, e);
}
} else {
logger.debug("Accessed resource {} is metadata. NOT rescheduling timeout!", transfer);
}
}
}
} finally {
if (original != null && !original.isEmpty()) {
MDC.setContextMap(original);
} else {
MDC.setContextMap(Collections.emptyMap());
}
}
}
use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.
the class MaintenanceHandler method deprecatedRescan.
@ApiOperation("[Deprecated] Rescan all content in the specified repository to re-initialize metadata, capture missing index keys, etc.")
@ApiResponse(code = 200, message = "Rescan was started successfully. (NOTE: There currently is no way to determine when rescanning is complete.)")
@Path("/rescan/{type: (hosted|group|remote)}/{name}")
@GET
@Deprecated
public Response deprecatedRescan(@ApiParam(value = "The type of store / repository", allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @ApiParam("The name of the store / repository") @PathParam("name") final String name) {
final StoreType storeType = StoreType.get(type);
String altPath = Paths.get("/api/admin/maint", MAVEN_PKG_KEY, type, name).toString();
final StoreKey key = new StoreKey(storeType, name);
Response response;
try {
contentController.rescan(key);
response = markDeprecated(Response.ok(), altPath).build();
} catch (final IndyWorkflowException e) {
logger.error(String.format("Failed to rescan: %s. Reason: %s", key, e.getMessage()), e);
response = formatResponse(e, rb -> markDeprecated(rb, altPath));
}
return response;
}
Aggregations