public < N , S extends Session < L > > void discoverChildren ( Resource < L > parent , ResourceType < L > childType , Session < L > session , EndpointService < L , S > service , Consumer < Resource < L > > resourceConsumer ) { try { L parentLocation = parent != null ? parent . getLocation ( ) : null ; log . debugf ( "Discovering children of [%s] of type [%s]" , parent , childType ) ; final L childQuery = session . getLocationResolver ( ) . absolutize ( parentLocation , childType . getLocation ( ) ) ; Map < L , N > nativeResources = session . getDriver ( ) . fetchNodes ( childQuery ) ; for ( Map . Entry < L , N > entry : nativeResources . entrySet ( ) ) { L location = entry . getKey ( ) ; // this is the unique DMR address for this resource String resourceName = session . getLocationResolver ( ) . applyTemplate ( childType . getResourceNameTemplate ( ) , location , session . getEndpoint ( ) . getName ( ) ) ; ID id = InventoryIdUtil . generateResourceId ( session . getFeedId ( ) , session . getEndpoint ( ) , location . toString ( ) ) ; Builder < L > builder = Resource . < L > builder ( ) . id ( id ) . name ( new Name ( resourceName ) ) . location ( location ) . type ( childType ) ; if ( parent != null ) { builder . parent ( parent ) ; } // get the configuration of the resource discoverResourceConfiguration ( id , childType , location , entry . getValue ( ) , builder , session ) ; // populate the metrics based on the resource's type addMetricInstances ( id , childType , location , entry . getValue ( ) , builder , session ) ; // build the resource now - we might need it to generate metric IDs Resource < L > resource = builder . build ( ) ; // The resource is built (and measurement instances assigned to it) so we can generate family names/labels for ( MeasurementInstance < L , MetricType < L > > instance : resource . getMetrics ( ) ) { instance . setMetricFamily ( service . generateMetricFamily ( instance ) ) ; instance . setMetricLabels ( service . generateMetricLabels ( instance ) ) ; } log . debugf ( "Discovered resource [%s]" , resource ) ; // tell our consumer about our new resource if ( resourceConsumer != null ) { resourceConsumer . accept ( resource ) ; } // recursively discover children of child types Set < ResourceType < L > > childTypes = session . getResourceTypeManager ( ) . getChildren ( childType ) ; for ( ResourceType < L > nextLevelChildType : childTypes ) { discoverChildren ( resource , nextLevelChildType , session , service , resourceConsumer ) ; } } } catch ( Exception e ) { log . errorFailedToDiscoverResources ( e , session . getEndpoint ( ) ) ; resourceConsumer . report ( e ) ; } }
Discovers children of the given type underneath the given parent .