use of org.commonjava.maven.galley.event.FileStorageEvent in project galley by Commonjava.
the class Transfer method openOutputStream.
public OutputStream openOutputStream(final TransferOperation accessType, final boolean fireEvents, final EventMetadata eventMetadata, boolean deleteFilesOnPath) throws IOException {
provider.waitForWriteUnlock(resource);
try {
provider.lockWrite(resource);
if (deleteFilesOnPath) {
deleteFilesOnPath();
}
OutputStream stream = provider.openOutputStream(resource);
if (stream == null) {
return null;
}
final TransferUnlocker unlocker = new TransferUnlocker(resource, provider);
if (fireEvents) {
logger.info("Wrapping output stream to: {} using event metadata: {}", this, eventMetadata);
stream = new TransferOutputStream(stream, unlocker, new FileStorageEvent(accessType, this, eventMetadata), fileEventManager);
} else {
logger.info("Wrapping output stream to: {} WITHOUT event metadata", this);
stream = new TransferOutputStream(stream, unlocker);
}
stream = decorator == null ? stream : decorator.decorateWrite(stream, this, accessType, eventMetadata);
return stream;
} catch (final IOException e) {
if (fireEvents) {
fileEventManager.fire(new FileErrorEvent(this, e, eventMetadata));
}
throw e;
}
}
use of org.commonjava.maven.galley.event.FileStorageEvent in project indy by Commonjava.
the class EventAuditListener method transformFileEvent.
private void transformFileEvent(org.commonjava.maven.galley.event.FileEvent event, FileEvent fileEvent) {
EventMetadata metadata = event.getEventMetadata();
final TrackingKey trackingKey = (TrackingKey) metadata.get(EventConstants.TRACKING_KEY);
if (trackingKey == null) {
logger.trace("No tracking key. Skip audit.");
return;
}
Transfer transfer = event.getTransfer();
if (transfer == null) {
logger.trace("No transfer. Skip audit.");
return;
}
final Location location = transfer.getLocation();
if (!(location instanceof KeyedLocation)) {
logger.trace("Not in a keyed location: {}", transfer);
return;
}
try {
final KeyedLocation keyedLocation = (KeyedLocation) location;
final StoreKey affectedStore = keyedLocation.getKey();
if (affectedStore.getType() == group) {
logger.trace("Not auditing content stored directly in group: {}. This content is generally aggregated metadata, and can be recalculated. Groups may not be stable in some build environments", affectedStore);
return;
}
final String path = transfer.getPath();
fileEvent.setTargetPath(path);
// TODO figure out what's the NodeId
fileEvent.setNodeId(indyConfig.getNodeId());
fileEvent.setSessionId(trackingKey.getId());
fileEvent.setTimestamp(new Date());
TransferMetadata artifactData = contentDigester.digest(affectedStore, path, metadata);
fileEvent.setMd5(artifactData.getDigests().get(ContentDigest.MD5));
fileEvent.setSha1(artifactData.getDigests().get(ContentDigest.SHA_1));
fileEvent.setChecksum(artifactData.getDigests().get(ContentDigest.SHA_256));
fileEvent.setSize(artifactData.getSize());
fileEvent.setStoreKey(affectedStore.toString());
Map<String, String> extra = new HashMap<>();
if (event instanceof FileStorageEvent) {
extra.put(EventConstants.STORE_EFFECT, ((FileStorageEvent) event).getType().name());
}
if (StoreType.remote == affectedStore.getType()) {
final RemoteRepository repo = (RemoteRepository) storeManager.getArtifactStore(affectedStore);
if (repo != null) {
fileEvent.setSourceLocation(repo.getUrl());
fileEvent.setSourcePath(transfer.getPath());
}
}
// TODO fix this, it should be the url of indy, or recalculate it in AuditQuery side.
fileEvent.setTargetLocation("");
fileEvent.setExtra(extra);
} catch (final IndyWorkflowException | IndyDataException e) {
logger.error(String.format("Failed to transform file event. Reason: %s", e.getMessage()), e);
}
}
use of org.commonjava.maven.galley.event.FileStorageEvent in project indy by Commonjava.
the class ImpliedRepositoryDetectorTest method addRepositoryFromPomStorageEvent.
// @Test
// public void idWithSpaceInIt_ConvertToDashes()
// {
// String in = "my id";
// String out = detector.formatId( in );
// assertThat( out, equalTo( "i-my-id" ) );
// }
//
// @Test
// public void idWithPlusInIt_ConvertToDashes()
// {
// String in = "my+id";
// String out = detector.formatId( in );
// assertThat( out, equalTo( "i-my-id" ) );
// }
@Test
public void addRepositoryFromPomStorageEvent() throws Exception {
Transfer txfr = writeTransfer("one-repo.pom");
final FileStorageEvent event = new FileStorageEvent(TransferOperation.DOWNLOAD, txfr, new EventMetadata());
detector.detectRepos(event);
synchronized (detector) {
detector.wait();
}
assertThat(storeManager.query().getRemoteRepository(MAVEN_PKG_KEY, "i-repo-one"), notNullValue());
assertThat(getGroup().getConstituents().contains(new StoreKey(MAVEN_PKG_KEY, StoreType.remote, "i-repo-one")), equalTo(true));
}
use of org.commonjava.maven.galley.event.FileStorageEvent in project indy by Commonjava.
the class ImpliedRepositoryDetectorTest method addImpliedPluginRepositoryToNewGroup.
@Test
public void addImpliedPluginRepositoryToNewGroup() throws Exception {
Transfer txfr = writeTransfer("one-plugin-repo.pom");
final FileStorageEvent event = new FileStorageEvent(TransferOperation.DOWNLOAD, txfr, new EventMetadata());
detector.detectRepos(event);
synchronized (detector) {
detector.wait();
}
assertThat(storeManager.query().getRemoteRepository(MAVEN_PKG_KEY, "i-repo-one"), notNullValue());
assertThat(getGroup().getConstituents().contains(new StoreKey(StoreType.remote, "i-repo-one")), equalTo(true));
}
Aggregations