static Collection<ClientIdentifier> getManageableClients(IMonitoringConsumer consumer) { return consumer .getChildNamesForNode("management", "clients") .orElse(Collections.emptyList()) .stream() .map(ClientIdentifier::valueOf) .collect(Collectors.toSet()); }
// return the PlatformConnectedClient object representing the connection used by this // clientDescriptor private static Optional<Map.Entry<String, PlatformConnectedClient>> getPlatformConnectedClient( IMonitoringConsumer consumer, Object clientDescriptor) { return getPlatformClientFetchedEntity(consumer, clientDescriptor) .flatMap( entry -> consumer .getValueForNode( CLIENTS_PATH, entry.getValue().clientIdentifier, PlatformConnectedClient.class) .map( platformConnectedClient -> new AbstractMap.SimpleEntry<>( entry.getValue().clientIdentifier, platformConnectedClient))); }
// return the PlatformClientFetchedEntity object linked to this clientDescriptor private static Optional<? extends Map.Entry<String, PlatformClientFetchedEntity>> getPlatformClientFetchedEntity(IMonitoringConsumer consumer, Object clientDescriptor) { return consumer .getChildValuesForNode(FETCHED_PATH) .flatMap( children -> children .entrySet() .stream() .filter(entry -> entry.getValue() instanceof PlatformClientFetchedEntity) .map( entry -> new AbstractMap.SimpleEntry<>( entry.getKey(), (PlatformClientFetchedEntity) entry.getValue())) .filter(entry -> entry.getValue().clientDescriptor.equals(clientDescriptor)) .findFirst()); }
static Optional<ClientDescriptor> getClientDescriptor( IMonitoringConsumer consumer, ClientIdentifier clientIdentifier) { return consumer .getChildValuesForNode(CLIENTS_PATH) // walk on all platform clients having same client identifier .flatMap( children -> children .entrySet() .stream() .filter(entry -> entry.getValue() instanceof PlatformConnectedClient) .map( entry -> new AbstractMap.SimpleEntry<>( entry.getKey(), (PlatformConnectedClient) entry.getValue())) .filter(entry -> toClientIdentifier(entry.getValue()).equals(clientIdentifier)) .map(Map.Entry::getKey) .findFirst()) // then find all fetches for this client .flatMap( voltronConnectionId -> consumer .getChildValuesForNode(FETCHED_PATH) .flatMap( children -> children .entrySet() .stream() .filter( entry -> entry.getValue() instanceof PlatformClientFetchedEntity) .map( entry -> new AbstractMap.SimpleEntry<>( entry.getKey(), (PlatformClientFetchedEntity) entry.getValue())) .filter( entry -> entry .getValue() .clientIdentifier .equals(voltronConnectionId)) .map(Map.Entry::getValue) // only interested in the fetch for the management entity .filter( platformClientFetchedEntity -> consumer .getValueForNode( ENTITIES_PATH, platformClientFetchedEntity.entityIdentifier, PlatformEntity.class) .filter( platformEntity -> platformEntity.typeName.equals( ManagementAgentConfig.ENTITY_TYPE)) .isPresent()) // return the client descriptor for the client that has fetched the // management entity .map( platformClientFetchedEntity -> platformClientFetchedEntity.clientDescriptor) .findFirst())); }
static boolean isManageableClient(IMonitoringConsumer consumer, ClientIdentifier to) { return consumer.getChildNamesForNode("management", "clients", to.getClientId()).isPresent(); }