Search in sources :

Example 41 with TrackingKey

use of org.commonjava.indy.folo.model.TrackingKey in project indy by Commonjava.

the class FoloAdminController method renderReport.

public TrackedContentDTO renderReport(final String id, final String apiBaseUrl) throws IndyWorkflowException {
    final TrackingKey tk = new TrackingKey(id);
    logger.debug("Retrieving tracking record for: {}", tk);
    final TrackedContentDTO record = constructContentDTO(recordManager.get(tk), apiBaseUrl);
    logger.debug("Got: {}", record);
    return record;
}
Also used : TrackingKey(org.commonjava.indy.folo.model.TrackingKey) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO)

Example 42 with TrackingKey

use of org.commonjava.indy.folo.model.TrackingKey in project indy by Commonjava.

the class KafkaEventPublisher method transformFileEvent.

private void transformFileEvent(org.commonjava.maven.galley.event.FileEvent event, FileEvent fileEvent) {
    Transfer transfer = event.getTransfer();
    if (transfer == null) {
        logger.trace("No transfer.");
        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();
        final String path = transfer.getPath();
        fileEvent.setTargetPath(path);
        fileEvent.setNodeId(indyConfig.getNodeId());
        EventMetadata metadata = event.getEventMetadata();
        final TrackingKey trackingKey = (TrackingKey) metadata.get("tracking-id");
        if (trackingKey != null) {
            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());
        if (StoreType.remote == affectedStore.getType()) {
            final RemoteRepository repo = (RemoteRepository) storeManager.getArtifactStore(affectedStore);
            if (repo != null) {
                fileEvent.setSourceLocation(repo.getUrl());
                fileEvent.setSourcePath(transfer.getPath());
            }
        }
    } catch (final IndyWorkflowException | IndyDataException e) {
        logger.error(String.format("Failed to transform file event. Reason: %s", e.getMessage()), e);
    }
}
Also used : KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StoreKey(org.commonjava.indy.model.core.StoreKey) Date(java.util.Date) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) TrackingKey(org.commonjava.indy.folo.model.TrackingKey) IndyDataException(org.commonjava.indy.data.IndyDataException) TransferMetadata(org.commonjava.maven.galley.io.checksum.TransferMetadata) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) Location(org.commonjava.maven.galley.model.Location)

Example 43 with TrackingKey

use of org.commonjava.indy.folo.model.TrackingKey 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);
    }
}
Also used : KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) FileStorageEvent(org.commonjava.maven.galley.event.FileStorageEvent) HashMap(java.util.HashMap) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StoreKey(org.commonjava.indy.model.core.StoreKey) Date(java.util.Date) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) TrackingKey(org.commonjava.indy.folo.model.TrackingKey) IndyDataException(org.commonjava.indy.data.IndyDataException) TransferMetadata(org.commonjava.maven.galley.io.checksum.TransferMetadata) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) Location(org.commonjava.maven.galley.model.Location)

Example 44 with TrackingKey

use of org.commonjava.indy.folo.model.TrackingKey in project indy by Commonjava.

the class DtxTrackingRecord method toTrackingContentEntry.

public static TrackedContentEntry toTrackingContentEntry(DtxTrackingRecord record) {
    TrackedContentEntry trackedContentEntry = new TrackedContentEntry();
    trackedContentEntry.setTrackingKey(new TrackingKey(record.getTrackingKey()));
    if (record.getAccessChannel() == null || record.getAccessChannel().isEmpty()) {
        trackedContentEntry.setAccessChannel(AccessChannel.NATIVE);
    } else {
        trackedContentEntry.setAccessChannel(AccessChannel.valueOf(record.getAccessChannel()));
    }
    trackedContentEntry.setEffect(StoreEffect.valueOf(record.getStoreEffect()));
    trackedContentEntry.setMd5(record.getMd5());
    trackedContentEntry.setSha1(record.getSha1());
    trackedContentEntry.setSha256(record.getSha256());
    trackedContentEntry.setSize(record.getSize());
    trackedContentEntry.setStoreKey(StoreKey.fromString(record.getStoreKey()));
    trackedContentEntry.setOriginUrl(record.getOriginUrl());
    trackedContentEntry.setPath(record.getPath());
    trackedContentEntry.setTimestamps(record.getTimestamps());
    return trackedContentEntry;
}
Also used : TrackedContentEntry(org.commonjava.indy.folo.model.TrackedContentEntry) TrackingKey(org.commonjava.indy.folo.model.TrackingKey)

Example 45 with TrackingKey

use of org.commonjava.indy.folo.model.TrackingKey in project indy by Commonjava.

the class FoloRecordCassandra method getTrackingKeys.

private Set<TrackingKey> getTrackingKeys() {
    BoundStatement statement = getTrackingKeys.bind();
    ResultSet resultSet = session.execute(statement);
    List<Row> all = resultSet.all();
    Iterator<Row> iterator = all.iterator();
    Set<TrackingKey> trackingKeys = new HashSet<>();
    while (iterator.hasNext()) {
        Row next = iterator.next();
        String tracking_key = next.getString("tracking_key");
        trackingKeys.add(new TrackingKey(tracking_key));
    }
    return trackingKeys.stream().collect(Collectors.toSet());
}
Also used : DtxTrackingRecord.fromCassandraRow(org.commonjava.indy.folo.data.DtxTrackingRecord.fromCassandraRow) TrackingKey(org.commonjava.indy.folo.model.TrackingKey)

Aggregations

TrackingKey (org.commonjava.indy.folo.model.TrackingKey)46 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)18 ApiOperation (io.swagger.annotations.ApiOperation)12 ApiResponses (io.swagger.annotations.ApiResponses)12 Path (javax.ws.rs.Path)12 StoreKey (org.commonjava.indy.model.core.StoreKey)11 Test (org.junit.Test)11 TrackedContent (org.commonjava.indy.folo.model.TrackedContent)10 TrackedContentEntry (org.commonjava.indy.folo.model.TrackedContentEntry)10 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)8 GET (javax.ws.rs.GET)6 HEAD (javax.ws.rs.HEAD)6 PUT (javax.ws.rs.PUT)6 AccessChannel (org.commonjava.indy.model.core.AccessChannel)6 Inject (javax.inject.Inject)4 Context (javax.ws.rs.core.Context)4 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)4 Location (org.commonjava.maven.galley.model.Location)4 Transfer (org.commonjava.maven.galley.model.Transfer)4 Logger (org.slf4j.Logger)4