TenantApplications implements RequestHandler, HostValidator<ApplicationId> { String appendOneLevelOfId(String baseIdSegment, String id) { if ("".equals(baseIdSegment)) return id.split("/")[0]; String theRest = id.substring(baseIdSegment.length()); if ("".equals(theRest)) return id; theRest = theRest.replaceFirst("/", ""); String theRestFirstSeg = theRest.split("/")[0]; return baseIdSegment+"/"+theRestFirstSeg; } 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 testAppendIdsInNonRecursiveListing() { assertEquals(applications.appendOneLevelOfId("search/music", "search/music/qrservers/default/qr.0"), "search/music/qrservers"); assertEquals(applications.appendOneLevelOfId("search", "search/music/qrservers/default/qr.0"), "search/music"); assertEquals(applications.appendOneLevelOfId("search/music/qrservers/default/qr.0", "search/music/qrservers/default/qr.0"), "search/music/qrservers/default/qr.0"); assertEquals(applications.appendOneLevelOfId("", "search/music/qrservers/default/qr.0"), "search"); }