TenantApplications implements RequestHandler, HostValidator<ApplicationId> { private Set<ConfigKey<?>> listConfigs(Application application, ConfigKey<?> keyToMatch, boolean recursive) { Set<ConfigKey<?>> ret = new LinkedHashSet<>(); for (ConfigKey<?> key : application.allConfigsProduced()) { String configId = key.getConfigId(); if (recursive) { key = new ConfigKey<>(key.getName(), configId, key.getNamespace()); } else { key = new ConfigKey<>(key.getName(), configId.split("/")[0], key.getNamespace()); } if (keyToMatch != null) { String n = key.getName(); String ns = key.getNamespace(); if (n.equals(keyToMatch.getName()) && ns.equals(keyToMatch.getNamespace()) && configId.startsWith(keyToMatch.getConfigId()) && !(configId.equals(keyToMatch.getConfigId()))) { if (!recursive) { key = new ConfigKey<>(key.getName(), appendOneLevelOfId(keyToMatch.getConfigId(), configId), key.getNamespace()); } ret.add(key); } } else { ret.add(key); } } return ret; } TenantApplications(TenantName tenant, Curator curator, StripedExecutor<TenantName> zkWatcherExecutor,
                              ExecutorService zkCacheExecutor, Metrics metrics, ReloadListener reloadListener,
                              ConfigserverConfig configserverConfig, HostRegistry<ApplicationId> hostRegistry,
                              TenantFileSystemDirs tenantFileSystemDirs); static TenantApplications create(GlobalComponentRegistry componentRegistry, TenantName tenantName); List<ApplicationId> activeApplications(); boolean exists(ApplicationId id); Optional<Long> activeSessionOf(ApplicationId id); boolean hasLocalSession(long sessionId); Transaction createPutTransaction(ApplicationId applicationId, long sessionId); void createApplication(ApplicationId id); long requireActiveSessionOf(ApplicationId applicationId); CuratorTransaction createDeleteTransaction(ApplicationId applicationId); void removeUnusedApplications(); void close(); Lock lock(ApplicationId id); @Override ConfigResponse resolveConfig(ApplicationId appId, GetConfigRequest req, Optional<Version> vespaVersion); void reloadConfig(ApplicationSet applicationSet); void removeApplication(ApplicationId applicationId); void removeApplicationsExcept(Set<ApplicationId> applications); @Override Set<ConfigKey<?>> listNamedConfigs(ApplicationId appId, Optional<Version> vespaVersion, ConfigKey<?> keyToMatch, boolean recursive); @Override Set<ConfigKey<?>> listConfigs(ApplicationId appId, Optional<Version> vespaVersion, boolean recursive); @Override Set<ConfigKey<?>> allConfigsProduced(ApplicationId appId, Optional<Version> vespaVersion); @Override Set<String> allConfigIds(ApplicationId appId, Optional<Version> vespaVersion); @Override boolean hasApplication(ApplicationId appId, Optional<Version> vespaVersion); @Override ApplicationId resolveApplicationId(String hostName); @Override Set<FileReference> listFileReferences(ApplicationId applicationId); @Override void verifyHosts(ApplicationId key, Collection<String> newHosts); HostValidator<ApplicationId> getHostValidator(); ApplicationId getApplicationIdForHostName(String hostname); TenantFileSystemDirs getTenantFileSystemDirs();  }
@Test public void testListConfigs() throws IOException, SAXException { applications = TenantApplications.create(componentRegistry, TenantName.defaultName()); assertdefaultAppNotFound(); VespaModel model = new VespaModel(FilesApplicationPackage.fromFile(new File("src/test/apps/app"))); ApplicationId applicationId = ApplicationId.defaultId(); applications.createApplication(applicationId); applications.createPutTransaction(applicationId, 1).commit(); applications.reloadConfig(ApplicationSet.fromSingle(new Application(model, new ServerCache(), 1, false, vespaVersion, MetricUpdater.createTestUpdater(), applicationId))); Set<ConfigKey<?>> configNames = applications.listConfigs(applicationId, Optional.of(vespaVersion), false); assertTrue(configNames.contains(new ConfigKey<>("sentinel", "hosts", "cloud.config"))); configNames = applications.listConfigs(ApplicationId.defaultId(), Optional.of(vespaVersion), true); assertTrue(configNames.contains(new ConfigKey<>("documentmanager", "container", "document.config"))); assertTrue(configNames.contains(new ConfigKey<>("documentmanager", "", "document.config"))); assertTrue(configNames.contains(new ConfigKey<>("documenttypes", "", "document"))); assertTrue(configNames.contains(new ConfigKey<>("documentmanager", "container", "document.config"))); assertTrue(configNames.contains(new ConfigKey<>("health-monitor", "container", "container.jdisc.config"))); assertTrue(configNames.contains(new ConfigKey<>("specific", "container", "project"))); }