InternalConfigurationPersistenceService implements ConfigurationPersistenceService { public void loadSharedConfigurationFromDir(File configDir) throws IOException { if (!configDir.exists()) { throw new IOException("ConfigDir does not exist: " + configDir.toPath()); } lockSharedConfiguration(); try { File[] groupNames = configDir.listFiles((FileFilter) DirectoryFileFilter.INSTANCE); boolean needToCopyJars = true; if (configDir.getAbsolutePath().equals(configDirPath.toAbsolutePath().toString())) { needToCopyJars = false; } logger.info("loading the cluster configuration: "); Map<String, Configuration> sharedConfiguration = new HashMap<>(); for (File groupName : groupNames) { Configuration configuration = readConfiguration(groupName); logger.info(configuration.getConfigName() + " xml content: " + System.lineSeparator() + configuration.getCacheXmlContent()); logger.info(configuration.getConfigName() + " properties: " + configuration.getGemfireProperties().size()); logger.info(configuration.getConfigName() + " jars: " + Strings.join(configuration.getJarNames(), ", ")); sharedConfiguration.put(groupName.getName(), configuration); if (needToCopyJars && !configuration.getJarNames().isEmpty()) { Path groupDirPath = createConfigDirIfNecessary(configuration.getConfigName()).toPath(); for (String jarName : configuration.getJarNames()) { Files.copy(groupName.toPath().resolve(jarName), groupDirPath.resolve(jarName)); } } } Region<String, Configuration> clusterRegion = getConfigurationRegion(); clusterRegion.clear(); String memberId = cache.getMyId().getId(); clusterRegion.putAll(sharedConfiguration, memberId); persistSecuritySettings(clusterRegion); } finally { unlockSharedConfiguration(); } } InternalConfigurationPersistenceService(InternalCache cache, Path workingDirectory,
      JAXBService jaxbService); @VisibleForTesting  InternalConfigurationPersistenceService(JAXBService jaxbService); @VisibleForTesting  InternalConfigurationPersistenceService(InternalCache cache,
      DistributedLockService sharedConfigLockingService, JAXBService jaxbService,
      Path configDirPath, Path configDiskDirPath); JAXBService getJaxbService(); void addXmlEntity(XmlEntity xmlEntity, String[] groups); void deleteXmlEntity(XmlEntity xmlEntity, String[] groups); void modifyXmlAndProperties(Properties properties, XmlEntity xmlEntity, String[] groups); void addJarsToThisLocator(List<String> jarFullPaths, String[] groups); boolean removeJars(String[] jarNames, String[] groups); void downloadJarFromOtherLocators(String groupName, String jarName); void downloadJarFromLocator(String groupName, String jarName,
      DistributedMember sourceLocator); File downloadJar(DistributedMember locator, String groupName, String jarName); ConfigurationResponse createConfigurationResponse(Set<String> groups); void destroySharedConfiguration(); Path getPathToJarOnThisLocator(String groupName, String jarName); Configuration getConfiguration(String groupName); void setConfiguration(String groupName, Configuration configuration); boolean hasXmlConfiguration(); Map<String, Configuration> getEntireConfiguration(); Set<String> getGroups(); Path getClusterConfigDirPath(); SharedConfigurationStatus getStatus(); void loadSharedConfigurationFromDir(File configDir); void writeConfigToFile(Configuration configuration, File rootDir); boolean lockSharedConfiguration(); void unlockSharedConfiguration(); Region<String, Configuration> getConfigurationRegion(); @Override CacheConfig getCacheConfig(String group); @Override CacheConfig getCacheConfig(String group, boolean createNew); @Override void updateCacheConfig(String group, UnaryOperator<CacheConfig> mutator); static final String CLUSTER_CONFIG_ARTIFACTS_DIR_NAME; static final String CLUSTER_CONFIG_DISK_DIR_PREFIX; static final String CONFIG_REGION_NAME; }
@Test public void loadFromNonExistDir() { File configDir = new File(tempFolder.getRoot(), "NonExistDir"); assertThatThrownBy(() -> service.loadSharedConfigurationFromDir(configDir)) .isInstanceOf(IOException.class) .hasMessageContaining("ConfigDir does not exist:"); }