• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Commonjava / indy-tracking-service / 44786446415

20 Nov 2026 05:46PM UTC coverage: 37.562% (-29.5%) from 67.036%
44786446415

push

github

rnc
Bump org.commonjava.atlas:atlas-relationships-api from 1.2.2 to 1.2.3

Bumps [org.commonjava.atlas:atlas-relationships-api](https://github.com/Commonjava/atlas) from 1.2.2 to 1.2.3.
- [Release notes](https://github.com/Commonjava/atlas/releases)
- [Commits](https://github.com/Commonjava/atlas/compare/atlas-parent-1.2.2...atlas-parent-1.2.3)

---
updated-dependencies:
- dependency-name: org.commonjava.atlas:atlas-relationships-api
  dependency-version: 1.2.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

678 of 1805 relevant lines covered (37.56%)

0.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/org/commonjava/indy/service/tracking/change/FoloTrackingListener.java
1
/**
2
 * Copyright (C) 2022-2023 Red Hat, Inc. (https://github.com/Commonjava/indy-tracking-service)
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *         http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package org.commonjava.indy.service.tracking.change;
17

18
import io.smallrye.common.annotation.Blocking;
19
import org.apache.commons.lang3.StringUtils;
20
import org.commonjava.event.common.EventMetadata;
21
import org.commonjava.event.file.FileEvent;
22
import org.commonjava.event.file.FileEventType;
23
import org.commonjava.event.file.TransferOperation;
24
import org.commonjava.indy.service.tracking.Constants;
25
import org.commonjava.indy.service.tracking.config.IndyTrackingConfiguration;
26
import org.commonjava.indy.service.tracking.data.cassandra.CassandraTrackingQuery;
27
import org.commonjava.indy.service.tracking.exception.ContentException;
28
import org.commonjava.indy.service.tracking.exception.IndyWorkflowException;
29
import org.commonjava.indy.service.tracking.model.AccessChannel;
30
import org.commonjava.indy.service.tracking.model.StoreKey;
31
import org.commonjava.indy.service.tracking.model.TrackedContentEntry;
32
import org.commonjava.indy.service.tracking.model.TrackingKey;
33
import org.commonjava.indy.service.tracking.util.UrlUtils;
34
import org.eclipse.microprofile.reactive.messaging.Incoming;
35
import org.eclipse.microprofile.reactive.messaging.Message;
36
import org.slf4j.Logger;
37
import org.slf4j.LoggerFactory;
38

39
import jakarta.enterprise.context.ApplicationScoped;
40
import jakarta.inject.Inject;
41
import java.net.MalformedURLException;
42
import java.util.concurrent.CompletionStage;
43

44
import static org.commonjava.indy.service.tracking.Constants.ORIGIN_PATH;
45
import static org.commonjava.indy.service.tracking.model.StoreEffect.DOWNLOAD;
46
import static org.commonjava.indy.service.tracking.model.StoreEffect.UPLOAD;
47
import static org.commonjava.indy.service.tracking.model.StoreType.group;
48

49
@ApplicationScoped
50
public class FoloTrackingListener
×
51
{
52

53
    private final Logger logger = LoggerFactory.getLogger( getClass() );
×
54

55
    @Inject
56
    private IndyTrackingConfiguration trackingConfig;
57

58
    @Inject
59
    private CassandraTrackingQuery recordManager;
60

61
    public void handleFileAccessEvent( final FileEvent event ) throws IndyWorkflowException
62
    {
63
        logger.info( "FILE ACCESS: {}", event );
×
64

65
        EventMetadata metadata = event.getEventMetadata();
×
66

67
        final String originPath = (String) metadata.get( ORIGIN_PATH );
×
68
        /*
69
         * If a build makes a request to indy-admin service, pnc sends it through generic proxy
70
         * where it gets tracked once and then it gets tracked second time on the indy-admin service.
71
         * We should avoid the tracker if it sends request through generic proxy and the target is
72
         * indy instance,
73
         */
74
        if ( originPath != null && originPath.contains( "api/folo/track" ) )
×
75
        {
76
            logger.trace( "NOT tracking content requests from indy itself, path: {}", originPath );
×
77
            return;
×
78
        }
79

80
        String trackingId = event.getSessionId();
×
81

82
        final TrackingKey trackingKey = StringUtils.isNotBlank( trackingId ) ? new TrackingKey( trackingId ) : null;
×
83
        if ( trackingKey == null )
×
84
        {
85
            logger.trace( "No tracking key for access to: {}", event.getTargetPath() );
×
86
            return;
×
87
        }
88
        final AccessChannel accessChannel = AccessChannel.valueOf( (String) metadata.get( Constants.ACCESS_CHANNEL ) );
×
89

90
        try
91
        {
92
            String keyString = event.getStoreKey();
×
93
            if (StringUtils.isBlank( keyString )) {
×
94
                logger.trace( "NOT tracking content without StoreKey" );
×
95
                return;
×
96
            }
97
            StoreKey storeKey = StoreKey.fromString( event.getStoreKey() );
×
98
            if ( !trackingConfig.trackGroupContent() && storeKey.getType() == group )
×
99
            {
100
                logger.trace( "NOT tracking content stored directly in group: {}. This content is generally aggregated metadata, and can be recalculated. Groups may not be stable in some build environments",
×
101
                              storeKey );
102
                return;
×
103
            }
104

105
            final String trackingPath = originPath == null ? event.getTargetPath() : originPath;
×
106

107
            logger.trace( "Tracking report: {} += {} in {} (DOWNLOAD)", trackingKey, trackingPath, storeKey );
×
108

109
            //Here we need to think about npm metadata retrieving case. As almost all npm metadata retrieving is through
110
            // /$pkg from remote, but we use STORAGE_PATH in EventMetadata with /$pkg/package.json to store this metadata,
111
            //so the real path for this transfer should be /$pkg but its current path is /$pkg/package.json. We need to
112
            //think about if need to do the replacement here, especially for the originalUrl.
113
            String remoteUrl = null;
×
114
            String sourceLocation = event.getSourceLocation();
×
115
            String path = event.getSourcePath();
×
116
            if (sourceLocation != null && path != null)
×
117
            {
118
                remoteUrl = UrlUtils.buildUrl( sourceLocation, path );
×
119
            }
120
            TrackedContentEntry entry =
×
121
                            new TrackedContentEntry( trackingKey, storeKey, accessChannel, remoteUrl,
122
                                                     trackingPath, DOWNLOAD, event.getSize(), event.getMd5(),
×
123
                                                     event.getSha1(), event.getChecksum() );
×
124
            recordManager.recordArtifact( entry );
×
125
        }
126
        catch ( final ContentException | IndyWorkflowException e )
×
127
        {
128
            logger.error( String.format( "Failed to record download: %s. Reason: %s", event.getSourcePath(),
×
129
                                         e.getMessage() ), e );
×
130
        }
131
        catch ( final MalformedURLException e )
×
132
        {
133
            throw new IndyWorkflowException( "Cannot format URL. Reason: %s", e, e.getMessage() );
×
134
        }
×
135
    }
×
136

137
    public void handleFileStorageEvent( final FileEvent event ) throws IndyWorkflowException
138
    {
139
        logger.info( "FILE STORAGE: {}", event );
×
140

141
        if ( TransferOperation.UPLOAD != event.getOperation() )
×
142
        {
143
            logger.trace( "Not a file upload from client; skipping tracking of storage" );
×
144
            return;
×
145
        }
146

147
        EventMetadata metadata = event.getEventMetadata();
×
148

149
        String trackingId = event.getSessionId();
×
150

151
        final TrackingKey trackingKey = StringUtils.isNotBlank( trackingId ) ? new TrackingKey( trackingId ) : null;
×
152
        if ( trackingKey == null )
×
153
        {
154
            logger.trace( "No tracking key. Not recording." );
×
155
            return;
×
156
        }
157
        final AccessChannel accessChannel = AccessChannel.valueOf( (String) metadata.get( Constants.ACCESS_CHANNEL ) );
×
158
        String keyString = event.getStoreKey();
×
159
        if (StringUtils.isBlank( keyString )) {
×
160
            logger.trace( "NOT tracking content without StoreKey" );
×
161
            return;
×
162
        }
163
        StoreKey storeKey = StoreKey.fromString( event.getStoreKey() );
×
164

165
        if ( !trackingConfig.trackGroupContent() && storeKey.getType() == group )
×
166
        {
167
            logger.trace( "NOT tracking content stored directly in group: {}. This content is generally aggregated metadata, and can be recalculated. Groups may not be stable in some build environments",
×
168
                          storeKey );
169
            return;
×
170
        }
171

172
        try
173
        {
174

175
            logger.trace( "Tracking report: {} += {} in {} ({})", trackingKey, event.getTargetPath(), storeKey,
×
176
                          UPLOAD );
177
                        String remoteUrl = null;
×
178
            String sourceLocation = event.getSourceLocation();
×
179
            String path = event.getSourcePath();
×
180
            if (sourceLocation != null && path != null)
×
181
            {
182
                remoteUrl = UrlUtils.buildUrl( sourceLocation, path );
×
183
            }
184
            TrackedContentEntry entry =
×
185
                            new TrackedContentEntry( trackingKey, storeKey, accessChannel, remoteUrl,
186
                                                     event.getTargetPath(), UPLOAD, event.getSize(), event.getMd5(),
×
187
                                                     event.getSha1(), event.getChecksum() );
×
188

189
            recordManager.recordArtifact( entry );
×
190
        }
191
        catch ( final ContentException | IndyWorkflowException e )
×
192
        {
193
            logger.error( String.format( "Failed to record download: %s. Reason: %s", event.getSourcePath(),
×
194
                                         e.getMessage() ), e );
×
195
        }
196
        catch ( final MalformedURLException e )
×
197
        {
198
            throw new IndyWorkflowException( "Cannot format URL. Reason: %s", e, e.getMessage() );
×
199
        }
×
200
    }
×
201

202
    @Blocking
203
    @Incoming( "file-event-in" )
204
    public CompletionStage<Void> handleFileEvent( Message<FileEvent> message )
205
    {
206
        FileEvent event = message.getPayload();
×
207
        if ( event.getEventType().equals( FileEventType.ACCESS ) )
×
208
        {
209
            try
210
            {
211
                handleFileAccessEvent( event );
×
212
            }
213
            catch ( Throwable e )
×
214
            {
215
                logger.error( "Failed to handle the file access event", e );
×
216
            }
×
217
        }
218
        else if ( event.getEventType().equals( FileEventType.STORAGE ) )
×
219
        {
220
            try
221
            {
222
                handleFileStorageEvent( event );
×
223
            }
224
            catch ( Throwable e )
×
225
            {
226
                logger.error( "Failed to handle the file storage event", e );
×
227
            }
×
228
        }
229
        return message.ack();
×
230
    }
231

232
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc