Class TrackerMethods


  • public final class TrackerMethods
    extends Object

    Contains one-liners for searching, adding, and updating (type/properties/state) Tracker documents.

    • Constructor Detail

      • TrackerMethods

        TrackerMethods​(io.toro.martini.tracker.TrackerService trackerService,
                       @Qualifier("autoSynchronizeTrackerFactory")
                       BiFunction<String,​Document,​Tracker> asyncTrackerFactory,
                       io.toro.martini.tracker.TrackerFactory trackerFactory,
                       io.toro.martini.tracker.TrackerIndexSearchService trackerSearchService,
                       io.toro.martini.tracker.TrackerSearch trackerSearch,
                       @Qualifier("syncMartiniTrackerRepository")
                       io.toro.martini.tracker.TrackerRepository trackerRepository,
                       io.toro.martini.tracker.DocumentMapper documentMapper)
    • Method Detail

      • getDocument

        public static Document getDocument​(String internalId)

        Get a Tracker document.

        Example usage:

         def document = 'fc9430b7-0b2f-11ea-a17f-e95de32a2b5f'.getDocument()
         

        Parameters:
        internalId - ID of the document to fetch
        Returns:
        the document; null if not found
        Since:
        1.0
      • getDocumentsFromDocType

        public static List<Document> getDocumentsFromDocType​(String documentTypeName)

        Get a list of Tracker documents under a specific document type.

        Example usage:

         def documents = 'HTTP'.getDocumentsFromDocType()
         

        Parameters:
        documentTypeName - ID of the document type
        Returns:
        list of documents under a specified document type
        Since:
        1.0
      • getDocumentType

        public static Document.Type getDocumentType​(String documentTypeName)

        Get a Tracker document type.

        Example usage:

         def type = 'HTTP'.getDocumentType()
         

        Parameters:
        documentTypeName - ID of the document type
        Returns:
        the document type; null if not found
        Since:
        1.0
      • getDocumentState

        public static Document.State getDocumentState​(String stateId)

        Get a Tracker document state.

        Example usage:

         def state = 112019.getDocumentState()
         

        Parameters:
        stateId - ID of the document state
        Returns:
        the document state; null if not found
        Since:
        1.0
      • getDocumentStateByStateId

        @GloopObjectParameter("output{\n documentState#io.toro.martini.tracker.DocumentState{\n}\n}")
        public static GloopModel getDocumentStateByStateId​(String stateId)

        Get a Tracker document state by state id.

        Parameters:
        stateId - ID of the document state
        Returns:
        the gloop model containing the result; null if not found
        Since:
        1.0
      • addDocumentState

        public static String addDocumentState​(@GloopParameter(allowNull=false)
                                              String internalId,
                                              @GloopParameter(allowNull=false)
                                              String stateName)

        Add a new state to a Tracker document.

        Example usage:

         'fc9430b7-0b2f-11ea-a17f-e95de32a2b5f'.addDocumentState( 'Started' )
         

        Standard state names in Martini are:

        • Started
        • Stopped
        • Error
        • Finished
        • Received
        • Request Sent
        • Response Received
        • the HTTP response code of the tracked transaction

        Parameters:
        internalId - ID of the document
        stateName - the name of the state to add
        Returns:
        the modified document's ID
        Throws:
        IllegalStateException - if there's no document found with the provided ID
        Since:
        1.0
      • addDocumentState

        public static String addDocumentState​(@GloopParameter(allowNull=false)
                                              String internalId,
                                              @GloopParameter(allowNull=false)
                                              String stateName,
                                              @GloopParameter(allowNull=false)
                                              String content)

        Add a new state to a Tracker document. The state will be indexed.

        Example usage:

         String stateContent = writeAttributes( response )
         'fc9430b7-0b2f-11ea-a17f-e95de32a2b5f'.addDocumentState( 'Response Received', stateContent )
         

        Parameters:
        internalId - ID of the document
        stateName - the name of the state to add
        content - content of the state to add
        Returns:
        the modified document's ID
        Throws:
        IllegalStateException - if there's no document found with the provided ID
        Since:
        1.0
      • addDocumentState

        public static String addDocumentState​(@GloopParameter(allowNull=false)
                                              String internalId,
                                              @GloopParameter(allowNull=false)
                                              String stateName,
                                              @GloopParameter(allowNull=false)
                                              String filename,
                                              @GloopParameter(allowNull=false)
                                              String content)

        Add a new state to a Tracker document. The state will be indexed.

        Example usage:

         String stateContent = writeAttributes( response )
         'fc9430b7-0b2f-11ea-a17f-e95de32a2b5f'.addDocumentState( 'Response Received', 'sample-output.xml', stateContent )
         

        Parameters:
        internalId - ID of the document
        stateName - the name of the state to add
        content - content of the state to add
        filename - the file name of the content
        Returns:
        the modified document's ID
        Throws:
        IllegalStateException - if there's no document found with the provided ID
        Since:
        1.1
      • addDocumentState

        public static String addDocumentState​(@GloopParameter(allowNull=false)
                                              String internalId,
                                              @GloopParameter(allowNull=false)
                                              String stateName,
                                              byte[] content)

        Add a new state to a Tracker document. The state will be indexed.

        Example usage:

         byte[] stateContent = writeAttributes( response ).getBytes()
         'fc9430b7-0b2f-11ea-a17f-e95de32a2b5f'.addDocumentState( 'Response Received', stateContent )
         

        Parameters:
        internalId - ID of the document
        stateName - the name of the state to add
        content - content of the state to add in bytes
        Returns:
        the modified document's ID
        Throws:
        IllegalStateException - if there's no document found with the provided ID
        Since:
        1.0
      • addDocumentState

        public static String addDocumentState​(@GloopParameter(allowNull=false)
                                              String internalId,
                                              @GloopParameter(allowNull=false)
                                              String stateName,
                                              byte[] content,
                                              @GloopParameter(allowNull=false,defaultValue="false")
                                              boolean index)

        Add a new state to a Tracker document.

        Example usage:

         byte[] stateContent = writeAttributes( response ).getBytes()
         'fc9430b7-0b2f-11ea-a17f-e95de32a2b5f'.addDocumentState( 'Response Received', stateContent, true )
         

        Parameters:
        internalId - ID of the document
        stateName - the name of the state to add
        content - content of the state to add in bytes
        index - flag determining whether or not the state will be indexed
        Returns:
        the modified document's ID
        Throws:
        IllegalStateException - if there's no document found with the provided ID
        Since:
        1.0
      • addDocumentState

        public static String addDocumentState​(@GloopParameter(allowNull=false)
                                              String internalId,
                                              @GloopParameter(allowNull=false)
                                              String stateName,
                                              @GloopParameter(allowNull=false)
                                              String filename,
                                              byte[] content,
                                              @GloopParameter(allowNull=false,defaultValue="false")
                                              boolean index)

        Add a new state to a Tracker document.

        Example usage:

         byte[] stateContent = writeAttributes( response ).getBytes()
         'fc9430b7-0b2f-11ea-a17f-e95de32a2b5f'.addDocumentState( 'Response Received', stateContent, 'output.xml', true )
         

        Parameters:
        internalId - ID of the document
        stateName - the name of the state to add
        filename - the file name of the content
        content - content of the state to add in bytes
        index - flag determining whether or not the state will be indexed
        Returns:
        the modified document's ID
        Throws:
        IllegalStateException - if there's no document found with the provided ID
        Since:
        1.1
      • addDocumentException

        public static String addDocumentException​(@GloopParameter(allowNull=false)
                                                  String internalId,
                                                  Exception ex)

        Add a new Error state to a Tracker document, with the provided exception as the state's content. The exception message and stacktrace are written into a simple XML format, and indexed in Tracker.

        Example usage:

         try {
             // ...
         } catch ( Exception exception ) {
             'fc9430b7-0b2f-11ea-a17f-e95de32a2b5f'.addDocumentException( exception )
         }
         

        Parameters:
        internalId - ID of the document
        ex - the exception to save as a state; may be null
        Returns:
        the modified document's ID
        Since:
        1.0
      • addDocumentLog

        public static String addDocumentLog​(@GloopParameter(allowNull=false)
                                            String internalId,
                                            @GloopParameter(allowNull=false)
                                            String message)

        Add a new log message to a Tracker document. Message is assumed to be at the INFO level.

        Example usage:

         'fc9430b7-0b2f-11ea-a17f-e95de32a2b5f'.addDocumentLog( "Startup completed in ${duration}" )
         

        Parameters:
        internalId - ID of the document
        message - the message to log
        Returns:
        the modified document's ID
        Since:
        1.0
      • addDocumentLog

        public static String addDocumentLog​(@GloopParameter(allowNull=false)
                                            String internalId,
                                            @GloopParameter(choices={"TRACE","DEBUG","INFO","WARN","ERROR"},allowNull=false)
                                            String messageType,
                                            @GloopParameter(allowNull=false)
                                            String message)

        Add a new log message to a Tracker document.

        Example usage:

         'fc9430b7-0b2f-11ea-a17f-e95de32a2b5f'.addDocumentLog( 'INFO', "Startup completed in ${duration}" )
         

        Parameters:
        internalId - ID of the document
        message - the message to log
        messageType - the type of the message to log; choose from the following types: TRACE, DEBUG, INFO, WARN, ERROR.
        Returns:
        the modified document's ID
        Throws:
        IllegalStateException - if there's no document found with the provided ID
        Since:
        1.0
      • addDocumentProperty

        public static String addDocumentProperty​(Document document,
                                                 String propertyName,
                                                 String propertyValue)

        Add a new property to a Tracker document.

        Example usage:

         document.addDocumentProperty( 'Martini_Server', 'Martini Runtime@21ebef48dc84:8080 (172.18.0.9)' )
         

        Parameters:
        document - the Tracker document
        propertyName - the name of the property to add
        propertyValue - the value of the property to add
        Returns:
        the modified document's ID
        Throws:
        IllegalArgumentException - if document is null
        IllegalStateException - if document does not exist within Martini
        Since:
        1.0
      • addDocumentProperty

        public static String addDocumentProperty​(@GloopParameter(allowNull=false)
                                                 String internalId,
                                                 @GloopParameter(allowNull=false)
                                                 String propertyName,
                                                 @GloopParameter(allowNull=false)
                                                 String propertyValue)

        Add a new property to a Tracker document.

        Example usage:

         'fc9430b7-0b2f-11ea-a17f-e95de32a2b5f'.addDocumentProperty( 'Martini_Server',
                                                                     'Martini Runtime@21ebef48dc84:8080 (172.18.0.9)' )
         

        Parameters:
        internalId - ID of the document
        propertyName - the name of the property to add
        propertyValue - the value of the property to add
        Returns:
        the modified document's ID
        Throws:
        IllegalArgumentException - if document is null
        IllegalStateException - if document does not exist within Martini
        Since:
        1.0
      • getDocumentProperty

        public static String getDocumentProperty​(@GloopParameter(allowNull=false)
                                                 String internalId,
                                                 @GloopParameter(allowNull=false)
                                                 String propertyName)
        Get the value of a named property stored under a Tracker document.
        Parameters:
        internalId - the ID of the document
        propertyName - the name of the property to get
        Returns:
        the value of the property; null if not found
        Since:
        1.0.2
      • getDocumentProperties

        @GloopObjectParameter("documentProperties{\n  documentProperties#io.toro.martini.tracker.DocumentProperty[]{\n  }\n}")
        public static GloopModel getDocumentProperties​(@GloopParameter(allowNull=false)
                                                       String internalId)
        Get all the properties of a particular Tracker document.
        Parameters:
        internalId - the ID of the document
        Returns:
        the document properties, or empty if none found
        Since:
        1.0.2
      • addParentDocument

        public static void addParentDocument​(@GloopParameter(allowNull=false)
                                             String internalId,
                                             @GloopParameter(allowNull=false)
                                             String parentInternalId)

        Add another document as a parent to a document.

        Example usage:

         def childId = ...
         def parentId = ...
         childId.addParentDocument( parentId )
         

        Parameters:
        internalId - the ID of the child document
        parentInternalId - the ID of the parent document
        Since:
        1.0
      • removeParentDocument

        public static boolean removeParentDocument​(String internalId,
                                                   String parentInternalId)

        Remove the parent document of a document.

        Example usage:

         def childId = ...
         def parentId = ...
         childId.removeParentDocument( parentId )
         

        Parameters:
        internalId - the ID of the child document
        parentInternalId - the ID of the parent document to remove
        Returns:
        true if a parent document has been removed; false otherwise
        Since:
        1.0
      • addChildDocument

        public static void addChildDocument​(@GloopParameter(allowNull=false)
                                            String internalId,
                                            @GloopParameter(allowNull=false)
                                            String childInternalId)

        Add a document as a child of another document.

        Example usage:

         def childId = ...
         def parentId = ...
         parentId.addChildDocument( childId )
         

        Parameters:
        internalId - the ID of the parent document
        childInternalId - the ID of the child document
      • removeChildDocument

        public static boolean removeChildDocument​(String internalId,
                                                  String childInternalId)

        Remove the child document of a document.

        Example usage:

         def childId = ...
         def parentId = ...
         parentId.removeChildDocument( childId )
         

        Parameters:
        internalId - the ID of the parent document
        childInternalId - the ID of the child document
        Returns:
        true if a child document has been removed; false otherwise
        Since:
        1.0
      • addDocument

        public static String addDocument​(@GloopParameter(allowNull=false)
                                         String internalId,
                                         @GloopParameter(allowNull=false)
                                         String externalId,
                                         @GloopParameter(allowNull=false)
                                         String documentTypeId,
                                         @GloopParameter(allowNull=false,defaultValue="Anonymous")
                                         String senderId,
                                         @GloopParameter(allowNull=false,defaultValue="Anonymous")
                                         String receiverId,
                                         @GloopParameter(allowNull=false)
                                         String stateName,
                                         byte[] content,
                                         Map<String,​String> properties)

        Add a new Tracker document.

        Example usage:

         byte[] stateContent = ...
         def properties = writeAttributes( endpoint )
         'fc9430b7-0b2f-11ea-a17f-e95de32a2b5f'.addDocument( '1574210862581',
                                                             'Scheduler',
                                                             'local',
                                                             'Unset',
                                                             'Started',
                                                             stateContent,
                                                             properties )
         

        Parameters:
        internalId - the internal ID of the document
        externalId - the external ID of the document
        documentTypeId - the ID of the document type to use for the document
        senderId - the ID of the sender
        receiverId - the ID of the receiver
        stateName - the name of the document's initial state
        content - content of the initial state in bytes
        properties - the properties of the document
        Returns:
        the added document's internal ID
        Since:
        1.0
      • addDocument

        public static String addDocument​(@GloopParameter(allowNull=false)
                                         String internalId,
                                         @GloopParameter(allowNull=false)
                                         String externalId,
                                         @GloopParameter(allowNull=false)
                                         String documentTypeId,
                                         @GloopParameter(allowNull=false,defaultValue="Anonymous")
                                         String senderId,
                                         @GloopParameter(allowNull=false,defaultValue="Anonymous")
                                         String receiverId,
                                         @GloopParameter(allowNull=false)
                                         String stateName,
                                         @GloopParameter(allowNull=false)
                                         String filename,
                                         @GloopParameter("true")
                                         boolean async,
                                         byte[] content,
                                         Map<String,​String> properties)

        Add a new Tracker document.

        Example usage:

         byte[] stateContent = ...
         def properties = writeAttributes( endpoint )
         'fc9430b7-0b2f-11ea-a17f-e95de32a2b5f'.addDocument( '1574210862581',
                                                             'Scheduler',
                                                             'local',
                                                             'Unset',
                                                             'Started',
                                                             stateContent,
                                                             'output.xml',
                                                             properties )
         

        Parameters:
        internalId - the internal ID of the document
        externalId - the external ID of the document
        documentTypeId - the ID of the document type to use for the document
        senderId - the ID of the sender
        receiverId - the ID of the receiver
        stateName - the name of the document's initial state
        filename - the file name of the content
        async - whether to persist the tracker document on a separate thread
        content - content of the initial state in bytes
        properties - the properties of the document
        Returns:
        the added document's internal ID
        Since:
        1.4
      • getTrackerDocument

        @GloopObjectParameter("output{\n  trackerDocument#io.toro.martini.tracker.Document{\n  }\n}")
        public static GloopModel getTrackerDocument​(@GloopParameter(allowNull=false)
                                                    String internalId)
        Get a Tracker document.
        Parameters:
        internalId - ID of the document to fetch
        Returns:
        the document; null if not found
      • getTrackerDocumentStateContent

        @GloopObjectParameter("output{\ntrackerDocumentStateContent#io.toro.martini.tracker.DocumentStateContent{\n}\n}")
        public static GloopModel getTrackerDocumentStateContent​(@GloopParameter(allowNull=false)
                                                                String documentStateId)
        Get the content of a Tracker document state.
        Parameters:
        documentStateId - the ID of the document state
        Returns:
        the content of the document state
      • searchTracker

        public static io.toro.martini.tracker.DocumentSearchResult searchTracker​(String query)

        Execute a search against the Tracker search index.

        Example usage:

         def query = '*:*'
         def results = query.searchTracker()
         

        Parameters:
        query - the search query to use
        Returns:
        the search results
      • searchTracker

        public static io.toro.martini.tracker.DocumentSearchResult searchTracker​(String query,
                                                                                 String... facets)

        Execute a search against the Tracker search index, with facets.

        Example usage:

         def query = '*:*'
         def results = query.searchTracker('documentTypeId', 'senderId', 'receiverId')
         

        Parameters:
        query - the search query to use
        facets - the facets to include in the search results
        Returns:
        the search results
      • searchTracker

        @GloopObjectParameter("output{\nsearchResult#io.toro.martini.tracker.SearchResult{\n}\n}")
        public static GloopModel searchTracker​(@GloopParameter(defaultValue="*:*",allowNull=false)
                                               String query,
                                               String[] externalId,
                                               String[] documentTypeId,
                                               String[] stateName,
                                               String[] senderId,
                                               String[] receiverId,
                                               Date startDate,
                                               Date endDate,
                                               String[] year,
                                               String[] month,
                                               String[] day,
                                               String[] userName,
                                               @GloopParameter(defaultValue="10",allowNull=false)
                                               int pageSize,
                                               @GloopParameter(defaultValue="0",allowNull=false)
                                               int page)
        Use search tracker when solr indexing is enabled. Search for indexed tracker documents on based on the given query and search parameters.
        Parameters:
        query - Solr query to be performed; default value is *:*, which selects all documents
        externalId - externalIds of documents to find
        documentTypeId - documentTypeIds of documents to find
        stateName - stateNames of documents to find
        senderId - senderIds of documents to find
        receiverId - receiverIds of documents to find
        startDate - display documents containing timestamp from this date
        endDate - display documents containing timestamps till this date
        year - years of documents to find
        month - string representation of months of documents to find, may be short name (e.g. JAN, FEB) or full month name (e.g. JANUARY, FEBRUARY)
        day - days of documents to find
        userName - usernames of documents to find
        pageSize - number of results to display in a page
        page - page number of results to display
        Returns:
        gloop model representing the results
      • searchTracker

        @GloopObjectParameter("output{\nsearchResult#io.toro.martini.tracker.SearchResult{\n}\n}")
        public static GloopModel searchTracker​(String internalId,
                                               String externalId,
                                               String documentTypeId,
                                               String stateName,
                                               String senderId,
                                               String receiverId,
                                               LocalDateTime startDate,
                                               LocalDateTime endDate,
                                               String userName,
                                               @GloopParameter(defaultValue="10",allowNull=false)
                                               int pageSize,
                                               @GloopParameter(defaultValue="0",allowNull=false)
                                               int page,
                                               String pagingState)
        Use to search for tracker documents on Cassandra, DynamoDB and Nitrite Datastore based on the given search parameters
        Parameters:
        internalId - internalId of document to find
        externalId - externalId of document to find
        documentTypeId - documentTypeId of document to find
        stateName - stateName of document to find
        senderId - senderId of document to find
        receiverId - receiverId of document to find
        startDate - display document containing local date and time from this date. (e.g format * yyyy-MM-ddTHH:mm:ss )
        endDate - display document containing local date and time till this date. (e.g format yyyy-MM-ddTHH:mm:ss )
        userName - username of document to find
        pageSize - number of results to display in a page
        page - page number of results to display
        pagingState - paging state for next page
        Returns:
        gloop model representing the results
      • updateDocument

        @GloopObjectParameter("output{\n  trackerDocument#io.toro.martini.tracker.Document{\n  }\n}")
        public static GloopModel updateDocument​(@GloopObjectParameter("document#io.toro.martini.tracker.Document{\n}")
                                                GloopModel document)
        Updates an existing document's properties based on whether the property is populated or not. This method will only update the properties that are populated in the input and will leave the existing value of those properties that are not populated.
        Parameters:
        document - the document holding the new values. The document's internalId is required.
        Returns:
        the updated document with the new values
        Since:
        1.1
      • deleteDocument

        public static void deleteDocument​(String internalId)
        Delete a Tracker document by ID.
        Parameters:
        internalId - the ID of the document to delete
        Since:
        1.0
      • deleteDocuments

        public static long deleteDocuments​(LocalDateTime start,
                                           LocalDateTime end)
        Deletes Tracker documents that are created between the provided start and end.
        Parameters:
        start - the start limit of the search query, defaults to no limit if null
        end - the end limit of the search query, defaults to no limit if null
        Returns:
        number of documents deleted
        Since:
        1.1