Repository: geode Updated Branches: refs/heads/feature/GEODE-3062 d15934fcb -> 9cd3ef2e1
Rename Shared Config to Cluster Config Cleanup Cluster Config classes Project: http://git-wip-us.apache.org/repos/asf/geode/repo Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/9cd3ef2e Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/9cd3ef2e Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/9cd3ef2e Branch: refs/heads/feature/GEODE-3062 Commit: 9cd3ef2e191fd55cae9a4b5335ca89ba5cbd0220 Parents: d15934f Author: Kirk Lund <[email protected]> Authored: Fri Jun 9 17:10:53 2017 -0700 Committer: Kirk Lund <[email protected]> Committed: Fri Jun 9 17:10:53 2017 -0700 ---------------------------------------------------------------------- .../internal/ClusterConfigurationService.java | 379 +++++++++++-------- .../distributed/internal/InternalLocator.java | 32 +- .../cache/ClusterConfigurationLoader.java | 143 +++---- .../geode/internal/cache/GemFireCacheImpl.java | 13 +- ...xportImportClusterConfigurationCommands.java | 2 +- .../internal/cli/commands/StatusCommands.java | 5 +- .../FetchSharedConfigurationStatusFunction.java | 4 +- .../domain/ClusterConfigurationStatus.java | 19 + .../domain/SharedConfigurationStatus.java | 19 - .../ClusterConfigurationStatusResponse.java | 67 ++++ .../messages/ConfigurationResponse.java | 63 ++- .../SharedConfigurationStatusResponse.java | 74 ---- .../ClusterConfigurationStatusRetriever.java | 16 +- 13 files changed, 426 insertions(+), 410 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode/blob/9cd3ef2e/geode-core/src/main/java/org/apache/geode/distributed/internal/ClusterConfigurationService.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/ClusterConfigurationService.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/ClusterConfigurationService.java index d990015..66eab57 100644 --- a/geode-core/src/main/java/org/apache/geode/distributed/internal/ClusterConfigurationService.java +++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/ClusterConfigurationService.java @@ -35,7 +35,6 @@ import org.apache.geode.distributed.DistributedLockService; import org.apache.geode.distributed.DistributedMember; import org.apache.geode.distributed.DistributedSystem; import org.apache.geode.distributed.LeaseExpiredException; -import org.apache.geode.distributed.internal.locks.DLockService; import org.apache.geode.internal.cache.InternalCache; import org.apache.geode.internal.cache.InternalRegionArguments; import org.apache.geode.internal.cache.persistence.PersistentMemberID; @@ -45,13 +44,13 @@ import org.apache.geode.internal.cache.xmlcache.CacheXmlGenerator; import org.apache.geode.internal.logging.LogService; import org.apache.geode.management.internal.cli.CliUtil; import org.apache.geode.management.internal.configuration.callbacks.ConfigurationChangeListener; +import org.apache.geode.management.internal.configuration.domain.ClusterConfigurationStatus; import org.apache.geode.management.internal.configuration.domain.Configuration; -import org.apache.geode.management.internal.configuration.domain.SharedConfigurationStatus; import org.apache.geode.management.internal.configuration.domain.XmlEntity; import org.apache.geode.management.internal.configuration.functions.UploadJarFunction; +import org.apache.geode.management.internal.configuration.messages.ClusterConfigurationStatusResponse; import org.apache.geode.management.internal.configuration.messages.ConfigurationRequest; import org.apache.geode.management.internal.configuration.messages.ConfigurationResponse; -import org.apache.geode.management.internal.configuration.messages.SharedConfigurationStatusResponse; import org.apache.geode.management.internal.configuration.utils.XmlUtils; import org.apache.logging.log4j.Logger; import org.w3c.dom.Document; @@ -82,7 +81,6 @@ import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactoryConfigurationError; -@SuppressWarnings({"deprecation", "unchecked"}) public class ClusterConfigurationService { private static final Logger logger = LogService.getLogger(); @@ -91,21 +89,21 @@ public class ClusterConfigurationService { */ public static final String CLUSTER_CONFIG_ARTIFACTS_DIR_NAME = "cluster_config"; - private static final String CLUSTER_CONFIG_DISK_STORE_NAME = "cluster_config"; - public static final String CLUSTER_CONFIG_DISK_DIR_PREFIX = "ConfigDiskDir_"; public static final String CLUSTER_CONFIG = "cluster"; + private static final String CLUSTER_CONFIG_DISK_STORE_NAME = "cluster_config"; + /** * Name of the lock service used for shared configuration */ - private static final String SHARED_CONFIG_LOCK_SERVICE_NAME = "__CLUSTER_CONFIG_LS"; + private static final String CLUSTER_CONFIG_LOCK_SERVICE_NAME = "__CLUSTER_CONFIG_LS"; /** * Name of the lock for locking the shared configuration */ - private static final String SHARED_CONFIG_LOCK_NAME = "__CLUSTER_CONFIG_LOCK"; + private static final String CLUSTER_CONFIG_LOCK_NAME = "__CLUSTER_CONFIG_LOCK"; /** * Name of the region which is used to store the configuration information @@ -116,14 +114,15 @@ public class ClusterConfigurationService { private final String configDiskDirPath; private final Set<PersistentMemberPattern> newerSharedConfigurationLocatorInfo = new HashSet<>(); - private final AtomicReference<SharedConfigurationStatus> status = new AtomicReference<>(); + private final AtomicReference<ClusterConfigurationStatus> status = new AtomicReference<>(); private final InternalCache cache; private final DistributedLockService sharedConfigLockingService; - public ClusterConfigurationService(InternalCache cache) throws IOException { + public ClusterConfigurationService(final InternalCache cache) throws IOException { this.cache = cache; Properties properties = cache.getDistributedSystem().getProperties(); + // resolve the cluster config dir String clusterConfigRootDir = properties.getProperty(CLUSTER_CONFIGURATION_DIR); @@ -132,7 +131,7 @@ public class ClusterConfigurationService { } else { File diskDir = new File(clusterConfigRootDir); if (!diskDir.exists() && !diskDir.mkdirs()) { - throw new IOException("Cannot create directory : " + clusterConfigRootDir); + throw new IOException("Cannot create directory: " + clusterConfigRootDir); } clusterConfigRootDir = diskDir.getCanonicalPath(); } @@ -145,31 +144,30 @@ public class ClusterConfigurationService { FilenameUtils.concat(clusterConfigRootDir, CLUSTER_CONFIG_ARTIFACTS_DIR_NAME); this.configDiskDirPath = FilenameUtils.concat(clusterConfigRootDir, configDiskDirName); this.sharedConfigLockingService = getSharedConfigLockService(cache.getDistributedSystem()); - this.status.set(SharedConfigurationStatus.NOT_STARTED); + this.status.set(ClusterConfigurationStatus.NOT_STARTED); } /** * Gets or creates (if not created) shared configuration lock service */ - private DistributedLockService getSharedConfigLockService(DistributedSystem ds) { - DistributedLockService sharedConfigDls = - DLockService.getServiceNamed(SHARED_CONFIG_LOCK_SERVICE_NAME); + private DistributedLockService getSharedConfigLockService(final DistributedSystem system) { + DistributedLockService dls = + DistributedLockService.getServiceNamed(CLUSTER_CONFIG_LOCK_SERVICE_NAME); try { - if (sharedConfigDls == null) { - sharedConfigDls = DLockService.create(SHARED_CONFIG_LOCK_SERVICE_NAME, - (InternalDistributedSystem) ds, true, true); + if (dls == null) { + dls = DistributedLockService.create(CLUSTER_CONFIG_LOCK_SERVICE_NAME, system); } } catch (IllegalArgumentException ignore) { - return DLockService.getServiceNamed(SHARED_CONFIG_LOCK_SERVICE_NAME); + return DistributedLockService.getServiceNamed(CLUSTER_CONFIG_LOCK_SERVICE_NAME); } - return sharedConfigDls; + return dls; } /** * Adds/replaces the xml entity in the shared configuration we don't need to trigger the change * listener for this modification, so it's ok to operate on the original configuration object */ - public void addXmlEntity(XmlEntity xmlEntity, String[] groups) { + public void addXmlEntity(final XmlEntity xmlEntity, String[] groups) { lockSharedConfiguration(); try { Region<String, Configuration> configRegion = getConfigurationRegion(); @@ -177,31 +175,38 @@ public class ClusterConfigurationService { groups = new String[] {ClusterConfigurationService.CLUSTER_CONFIG}; } for (String group : groups) { - Configuration configuration = configRegion.get(group); - if (configuration == null) { - configuration = new Configuration(group); - } - String xmlContent = configuration.getCacheXmlContent(); - if (xmlContent == null || xmlContent.isEmpty()) { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - CacheXmlGenerator.generateDefault(pw); - xmlContent = sw.toString(); - } - try { - final Document doc = XmlUtils.createAndUpgradeDocumentFromXml(xmlContent); - XmlUtils.addNewNode(doc, xmlEntity); - configuration.setCacheXmlContent(XmlUtils.prettyXml(doc)); - configRegion.put(group, configuration); - } catch (Exception e) { - logger.error("error updating cluster configuration for group {}", group, e); - } + addXmlEntity(xmlEntity, group, configRegion); } } finally { unlockSharedConfiguration(); } } + private void addXmlEntity(final XmlEntity xmlEntity, final String group, + final Region<String, Configuration> configRegion) { + Configuration groupConfig = configRegion.get(group); + if (groupConfig == null) { + groupConfig = new Configuration(group); + } + + String xmlContent = groupConfig.getCacheXmlContent(); + if (xmlContent == null || xmlContent.isEmpty()) { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + CacheXmlGenerator.generateDefault(pw); + xmlContent = sw.toString(); + } + + try { + Document doc = XmlUtils.createAndUpgradeDocumentFromXml(xmlContent); + XmlUtils.addNewNode(doc, xmlEntity); + groupConfig.setCacheXmlContent(XmlUtils.prettyXml(doc)); + configRegion.put(group, groupConfig); + } catch (Exception e) { + logger.error("Failed to update cluster configuration for group {}", group, e); + } + } + /** * Deletes the xml entity from the shared configuration. */ @@ -215,31 +220,39 @@ public class ClusterConfigurationService { groups = groupSet.toArray(new String[groupSet.size()]); } for (String group : groups) { - Configuration configuration = configRegion.get(group); - if (configuration != null) { - String xmlContent = configuration.getCacheXmlContent(); - try { - if (xmlContent != null && !xmlContent.isEmpty()) { - Document doc = XmlUtils.createAndUpgradeDocumentFromXml(xmlContent); - XmlUtils.deleteNode(doc, xmlEntity); - configuration.setCacheXmlContent(XmlUtils.prettyXml(doc)); - configRegion.put(group, configuration); - } - } catch (Exception e) { - logger.error("error updating cluster configuration for group {}", group, e); - } - } + deleteXmlEntity(xmlEntity, group, configRegion); } } finally { unlockSharedConfiguration(); } } + private void deleteXmlEntity(final XmlEntity xmlEntity, final String group, + final Region<String, Configuration> configRegion) { + Configuration groupConfig = configRegion.get(group); + if (groupConfig == null) { + return; + } + + String xmlContent = groupConfig.getCacheXmlContent(); + try { + if (xmlContent != null && !xmlContent.isEmpty()) { + Document doc = XmlUtils.createAndUpgradeDocumentFromXml(xmlContent); + XmlUtils.deleteNode(doc, xmlEntity); + groupConfig.setCacheXmlContent(XmlUtils.prettyXml(doc)); + configRegion.put(group, groupConfig); + } + } catch (Exception e) { + logger.error("Failed to update cluster configuration for group {}", group, e); + } + } + /** * we don't need to trigger the change listener for this modification, so it's ok to operate on * the original configuration object */ - public void modifyXmlAndProperties(Properties properties, XmlEntity xmlEntity, String[] groups) { + public void modifyXmlAndProperties(final Properties properties, final XmlEntity xmlEntity, + String[] groups) { lockSharedConfiguration(); try { if (groups == null) { @@ -247,47 +260,64 @@ public class ClusterConfigurationService { } Region<String, Configuration> configRegion = getConfigurationRegion(); for (String group : groups) { - Configuration configuration = configRegion.get(group); - if (configuration == null) { - configuration = new Configuration(group); - } - - if (xmlEntity != null) { - String xmlContent = configuration.getCacheXmlContent(); - if (xmlContent == null || xmlContent.isEmpty()) { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - CacheXmlGenerator.generateDefault(pw); - xmlContent = sw.toString(); - } - try { - Document doc = XmlUtils.createAndUpgradeDocumentFromXml(xmlContent); - // Modify the cache attributes - XmlUtils.modifyRootAttributes(doc, xmlEntity); - // Change the xml content of the configuration and put it the config region - configuration.setCacheXmlContent(XmlUtils.prettyXml(doc)); - } catch (Exception e) { - logger.error("error updating cluster configuration for group {}", group, e); - } - } - - if (properties != null) { - configuration.getGemfireProperties().putAll(properties); - } - configRegion.put(group, configuration); + modifyXmlAndProperties(properties, xmlEntity, group, configRegion); } } finally { unlockSharedConfiguration(); } } + private void modifyXmlAndProperties(final Properties properties, final XmlEntity xmlEntity, + final String group, final Region<String, Configuration> configRegion) { + Configuration groupConfig = configRegion.get(group); + if (groupConfig == null) { + groupConfig = new Configuration(group); + } + + if (xmlEntity != null) { + modifyXml(xmlEntity, group, groupConfig); + } + + if (properties != null) { + modifyProperties(properties, groupConfig); + } + + configRegion.put(group, groupConfig); + } + + private void modifyXml(final XmlEntity xmlEntity, final String group, + final Configuration configuration) { + String xmlContent = configuration.getCacheXmlContent(); + if (xmlContent == null || xmlContent.isEmpty()) { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + CacheXmlGenerator.generateDefault(pw); + xmlContent = sw.toString(); + } + + try { + Document doc = XmlUtils.createAndUpgradeDocumentFromXml(xmlContent); + // Modify the cache attributes + XmlUtils.modifyRootAttributes(doc, xmlEntity); + // Change the xml content of the configuration and put it the config region + configuration.setCacheXmlContent(XmlUtils.prettyXml(doc)); + } catch (Exception e) { + logger.error("error updating cluster configuration for group {}", group, e); + } + } + + private void modifyProperties(final Properties properties, final Configuration configuration) { + configuration.getGemfireProperties().putAll(properties); + } + /** * Add jar information into the shared configuration and save the jars in the file system used * when deploying jars - * + * * @return true on success */ - public boolean addJarsToThisLocator(String[] jarNames, byte[][] jarBytes, String[] groups) { + public boolean addJarsToThisLocator(final String[] jarNames, final byte[][] jarBytes, + String[] groups) { lockSharedConfiguration(); boolean success = true; try { @@ -296,31 +326,7 @@ public class ClusterConfigurationService { } Region<String, Configuration> configRegion = getConfigurationRegion(); for (String group : groups) { - Configuration configuration = configRegion.get(group); - - if (configuration == null) { - configuration = new Configuration(group); - createConfigDirIfNecessary(group); - } - - String groupDir = FilenameUtils.concat(this.configDirPath, group); - for (int i = 0; i < jarNames.length; i++) { - String filePath = FilenameUtils.concat(groupDir, jarNames[i]); - try { - File jarFile = new File(filePath); - FileUtils.writeByteArrayToFile(jarFile, jarBytes[i]); - } catch (IOException e) { - logger.info(e); - } - } - - // update the record after writing the jars to the file system, since the listener - // will need the jars on file to upload to other locators. Need to update the jars - // using a new copy of the Configuration so that the change listener will pick up the jar - // name changes. - Configuration configurationCopy = new Configuration(configuration); - configurationCopy.addJarNames(jarNames); - configRegion.put(group, configurationCopy); + success = success && addJarsToThisLocator(jarNames, jarBytes, group, configRegion); } } catch (Exception e) { success = false; @@ -331,6 +337,39 @@ public class ClusterConfigurationService { return success; } + private boolean addJarsToThisLocator(final String[] jarNames, final byte[][] jarBytes, + final String group, final Region<String, Configuration> configRegion) throws IOException { + Configuration configuration = configRegion.get(group); + + if (configuration == null) { + configuration = new Configuration(group); + createConfigDirIfNecessary(group); + } + + String groupDir = FilenameUtils.concat(this.configDirPath, group); + int jarNamesLength = jarNames.length; + for (int i = 0; i < jarNamesLength; i++) { + String filePath = FilenameUtils.concat(groupDir, jarNames[i]); + try { + File jarFile = new File(filePath); + FileUtils.writeByteArrayToFile(jarFile, jarBytes[i]); + } catch (IOException e) { + logger.info(e); + } + } + + // update the record after writing the jars to the file system, since the listener + // will need the jars on file to upload to other locators. Need to update the jars + // using a new copy of the Configuration so that the change listener will pick up the jar + // name changes. + + Configuration configurationCopy = new Configuration(configuration); + configurationCopy.addJarNames(jarNames); + configRegion.put(group, configurationCopy); + + return true; + } + /** * Removes the jar files from the shared configuration. used when undeploy jars * @@ -369,7 +408,8 @@ public class ClusterConfigurationService { * <p> * used when creating cluster config response and used when uploading the jars to another locator */ - public byte[] getJarBytesFromThisLocator(String group, String jarName) throws IOException { + public byte[] getJarBytesFromThisLocator(final String group, final String jarName) + throws IOException { Configuration configuration = getConfiguration(group); File jar = getPathToJarOnThisLocator(group, jarName).toFile(); @@ -381,10 +421,12 @@ public class ClusterConfigurationService { return FileUtils.readFileToByteArray(jar); } - // used in the cluster config change listener when jarnames are changed in the internal region - public void downloadJarFromOtherLocators(String groupName, String jarName) + // used in the cluster config change listener when jarNames are changed in the internal region + public void downloadJarFromOtherLocators(final String groupName, final String jarName) throws IllegalStateException, IOException { + logger.info("Getting Jar files from other locators"); + DM dm = this.cache.getDistributionManager(); DistributedMember me = this.cache.getMyId(); Set<DistributedMember> locators = @@ -403,7 +445,8 @@ public class ClusterConfigurationService { } // used when creating cluster config response - public Map<String, byte[]> getAllJarsFromThisLocator(Set<String> groups) throws IOException { + public Map<String, byte[]> getAllJarsFromThisLocator(final Set<String> groups) + throws IOException { Map<String, byte[]> jarNamesToJarBytes = new HashMap<>(); for (String group : groups) { @@ -424,21 +467,23 @@ public class ClusterConfigurationService { /** * Creates the shared configuration service - * + * * @param loadSharedConfigFromDir when set to true, loads the configuration from the share_config * directory */ - void initSharedConfiguration(boolean loadSharedConfigFromDir) + void initSharedConfiguration(final boolean loadSharedConfigFromDir) throws CacheLoaderException, TimeoutException, IllegalStateException, IOException, TransformerException, SAXException, ParserConfigurationException { - this.status.set(SharedConfigurationStatus.STARTED); + + this.status.set(ClusterConfigurationStatus.STARTED); Region<String, Configuration> configRegion = this.getConfigurationRegion(); + lockSharedConfiguration(); try { if (loadSharedConfigFromDir) { logger.info("Reading cluster configuration from '{}' directory", ClusterConfigurationService.CLUSTER_CONFIG_ARTIFACTS_DIR_NAME); - loadSharedConfigurationFromDisk(); + loadClusterConfigurationFromDisk(); } else { persistSecuritySettings(configRegion); // for those groups that have jar files, need to download the jars from other locators @@ -457,7 +502,7 @@ public class ClusterConfigurationService { unlockSharedConfiguration(); } - this.status.set(SharedConfigurationStatus.RUNNING); + this.status.set(ClusterConfigurationStatus.RUNNING); } private void persistSecuritySettings(final Region<String, Configuration> configRegion) { @@ -469,12 +514,14 @@ public class ClusterConfigurationService { clusterPropertiesConfig = new Configuration(ClusterConfigurationService.CLUSTER_CONFIG); configRegion.put(ClusterConfigurationService.CLUSTER_CONFIG, clusterPropertiesConfig); } + // put security-manager and security-post-processor in the cluster config Properties clusterProperties = clusterPropertiesConfig.getGemfireProperties(); if (securityProps.containsKey(SECURITY_MANAGER)) { clusterProperties.setProperty(SECURITY_MANAGER, securityProps.getProperty(SECURITY_MANAGER)); } + if (securityProps.containsKey(SECURITY_POST_PROCESSOR)) { clusterProperties.setProperty(SECURITY_POST_PROCESSOR, securityProps.getProperty(SECURITY_POST_PROCESSOR)); @@ -491,7 +538,8 @@ public class ClusterConfigurationService { ConfigurationResponse configResponse = new ConfigurationResponse(); for (int i = 0; i < configRequest.getNumAttempts(); i++) { - boolean isLocked = this.sharedConfigLockingService.lock(SHARED_CONFIG_LOCK_NAME, 5000, 5000); + // TODO: these lock millis are probably way too short and why is this in a retry loop? + boolean isLocked = this.sharedConfigLockingService.lock(CLUSTER_CONFIG_LOCK_NAME, 5000, 5000); try { if (isLocked) { Set<String> groups = configRequest.getGroups(); @@ -509,27 +557,27 @@ public class ClusterConfigurationService { byte[][] jarBytes = jarNamesToJarBytes.values().toArray(new byte[jarNames.length][]); configResponse.addJarsToBeDeployed(jarNames, jarBytes); - configResponse.setFailedToGetSharedConfig(false); + configResponse.setFailedToGetClusterConfig(false); return configResponse; } } finally { - this.sharedConfigLockingService.unlock(SHARED_CONFIG_LOCK_NAME); + this.sharedConfigLockingService.unlock(CLUSTER_CONFIG_LOCK_NAME); } - } - configResponse.setFailedToGetSharedConfig(true); + + configResponse.setFailedToGetClusterConfig(true); return configResponse; } /** * Create a response containing the status of the Shared configuration and information about other * locators containing newer shared configuration data (if at all) - * - * @return {@link SharedConfigurationStatusResponse} containing the - * {@link SharedConfigurationStatus} + * + * @return {@link ClusterConfigurationStatusResponse} containing the + * {@link ClusterConfigurationStatus} */ - SharedConfigurationStatusResponse createStatusResponse() { - SharedConfigurationStatusResponse response = new SharedConfigurationStatusResponse(); + ClusterConfigurationStatusResponse createStatusResponse() { + ClusterConfigurationStatusResponse response = new ClusterConfigurationStatusResponse(); response.setStatus(getStatus()); response.addWaitingLocatorInfo(this.newerSharedConfigurationLocatorInfo); return response; @@ -553,12 +601,12 @@ public class ClusterConfigurationService { FileUtils.deleteDirectory(file); } FileUtils.deleteDirectory(new File(this.configDirPath)); - } catch (Exception exception) { - throw new AssertionError(exception); + } catch (Exception e) { + throw new AssertionError(e); } } - public Path getPathToJarOnThisLocator(String groupName, String jarName) { + public Path getPathToJarOnThisLocator(final String groupName, final String jarName) { return new File(this.configDirPath).toPath().resolve(groupName).resolve(jarName); } @@ -573,33 +621,34 @@ public class ClusterConfigurationService { /** * Returns the path of Shared configuration directory - * + * * @return {@link String} path of the shared configuration directory */ public String getSharedConfigurationDirPath() { - return configDirPath; + return this.configDirPath; } /** * Gets the current status of the ClusterConfigurationService If the status is started , it * determines if the shared configuration is waiting for new configuration on other locators - * - * @return {@link SharedConfigurationStatus} */ - public SharedConfigurationStatus getStatus() { - SharedConfigurationStatus scStatus = this.status.get(); - if (scStatus == SharedConfigurationStatus.STARTED) { + public ClusterConfigurationStatus getStatus() { + ClusterConfigurationStatus scStatus = this.status.get(); + if (scStatus == ClusterConfigurationStatus.STARTED) { PersistentMemberManager pmm = this.cache.getPersistentMemberManager(); Map<String, Set<PersistentMemberID>> waitingRegions = pmm.getWaitingRegions(); + if (!waitingRegions.isEmpty()) { - this.status.compareAndSet(SharedConfigurationStatus.STARTED, - SharedConfigurationStatus.WAITING); + this.status.compareAndSet(ClusterConfigurationStatus.STARTED, + ClusterConfigurationStatus.WAITING); Set<PersistentMemberID> persMemIds = waitingRegions.get(Region.SEPARATOR_CHAR + CONFIG_REGION_NAME); + for (PersistentMemberID persMemId : persMemIds) { this.newerSharedConfigurationLocatorInfo.add(new PersistentMemberPattern(persMemId)); } } + } return this.status.get(); } @@ -607,8 +656,9 @@ public class ClusterConfigurationService { /** * Loads the internal region with the configuration in the configDirPath */ - public void loadSharedConfigurationFromDisk() + public void loadClusterConfigurationFromDisk() throws SAXException, ParserConfigurationException, TransformerException, IOException { + lockSharedConfiguration(); File[] groupNames = new File(this.configDirPath).listFiles((FileFilter) DirectoryFileFilter.INSTANCE); @@ -619,12 +669,12 @@ public class ClusterConfigurationService { Configuration configuration = readConfiguration(groupName); sharedConfiguration.put(groupName.getName(), configuration); } + Region<String, Configuration> clusterRegion = getConfigurationRegion(); clusterRegion.clear(); clusterRegion.putAll(sharedConfiguration); - // Overwrite the security settings using the locator's properties, ignoring whatever - // in the import + // Overwrite the security settings using the locator's properties persistSecuritySettings(clusterRegion); } finally { @@ -646,15 +696,16 @@ public class ClusterConfigurationService { } } - - // Write the content of xml and properties into the file system for exporting purpose + /** + * Write the content of xml and properties into the file system for exporting purpose + */ public void writeConfigToFile(final Configuration configuration) throws IOException { File configDir = createConfigDirIfNecessary(configuration.getConfigName()); - File propsFile = new File(configDir, configuration.getPropertiesFileName()); - BufferedWriter bw = new BufferedWriter(new FileWriter(propsFile)); - configuration.getGemfireProperties().store(bw, null); - bw.close(); + + try (BufferedWriter bw = new BufferedWriter(new FileWriter(propsFile))) { + configuration.getGemfireProperties().store(bw, null); + } File xmlFile = new File(configDir, configuration.getCacheXmlFileName()); FileUtils.writeStringToFile(xmlFile, configuration.getCacheXmlContent(), "UTF-8"); @@ -662,15 +713,15 @@ public class ClusterConfigurationService { // TODO: return value is never used private boolean lockSharedConfiguration() { - return this.sharedConfigLockingService.lock(SHARED_CONFIG_LOCK_NAME, -1, -1); + return this.sharedConfigLockingService.lock(CLUSTER_CONFIG_LOCK_NAME, -1, -1); } private void unlockSharedConfiguration() { - this.sharedConfigLockingService.unlock(SHARED_CONFIG_LOCK_NAME); + this.sharedConfigLockingService.unlock(CLUSTER_CONFIG_LOCK_NAME); } - private byte[] downloadJarFromLocator(DistributedMember locator, String groupName, - String jarName) { + private byte[] downloadJarFromLocator(final DistributedMember locator, final String groupName, + final String jarName) { ResultCollector<byte[], List<byte[]>> rc = (ResultCollector<byte[], List<byte[]>>) CliUtil .executeFunction(new UploadJarFunction(), new Object[] {groupName, jarName}, locator); @@ -684,7 +735,7 @@ public class ClusterConfigurationService { * Gets the region containing the shared configuration data. The region is created , if it does * not exist already. Note : this could block if this locator contains stale persistent * configuration data. - * + * * @return {@link Region} ConfigurationRegion, this should never be null */ private Region<String, Configuration> getConfigurationRegion() { @@ -696,7 +747,7 @@ public class ClusterConfigurationService { if (!diskDir.exists()) { if (!diskDir.mkdirs()) { - // TODO: throw caught by containing try statement + // TODO: throw is caught by containing try statement throw new IOException("Cannot create directory at " + this.configDiskDirPath); } } @@ -719,16 +770,13 @@ public class ClusterConfigurationService { } } catch (CancelException e) { - if (configRegion == null) { - this.status.set(SharedConfigurationStatus.STOPPED); - } + this.status.set(ClusterConfigurationStatus.STOPPED); // CONFIG: don't rethrow as Exception, keep it a subclass of CancelException throw e; } catch (Exception e) { - if (configRegion == null) { - this.status.set(SharedConfigurationStatus.STOPPED); - } + this.status.set(ClusterConfigurationStatus.STOPPED); + // TODO: throw something other than RuntimeException throw new RuntimeException("Error occurred while initializing cluster configuration", e); } @@ -738,12 +786,13 @@ public class ClusterConfigurationService { /** * Reads the configuration information from the shared configuration directory and returns a * {@link Configuration} object - * + * * @return {@link Configuration} */ - private Configuration readConfiguration(File groupConfigDir) + private Configuration readConfiguration(final File groupConfigDir) throws SAXException, ParserConfigurationException, TransformerFactoryConfigurationError, TransformerException, IOException { + Configuration configuration = new Configuration(groupConfigDir.getName()); File cacheXmlFull = new File(groupConfigDir, configuration.getCacheXmlFileName()); File propertiesFull = new File(groupConfigDir, configuration.getPropertiesFileName()); @@ -767,6 +816,8 @@ public class ClusterConfigurationService { throw new IOException("Cannot create directory : " + getSharedConfigurationDirPath()); } } + + // TODO: this.configDirPath already exists -- just use it instead? Path configDirPath = clusterConfigDir.toPath().resolve(configName); File configDir = configDirPath.toFile(); http://git-wip-us.apache.org/repos/asf/geode/blob/9cd3ef2e/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java index c299dd0..bd4531c 100644 --- a/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java +++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java @@ -59,12 +59,12 @@ import org.apache.geode.internal.net.SocketCreatorFactory; import org.apache.geode.management.internal.JmxManagerLocator; import org.apache.geode.management.internal.JmxManagerLocatorRequest; import org.apache.geode.management.internal.cli.CliUtil; -import org.apache.geode.management.internal.configuration.domain.SharedConfigurationStatus; +import org.apache.geode.management.internal.configuration.domain.ClusterConfigurationStatus; import org.apache.geode.management.internal.configuration.handlers.ConfigurationRequestHandler; import org.apache.geode.management.internal.configuration.handlers.SharedConfigurationStatusRequestHandler; +import org.apache.geode.management.internal.configuration.messages.ClusterConfigurationStatusResponse; import org.apache.geode.management.internal.configuration.messages.ConfigurationRequest; import org.apache.geode.management.internal.configuration.messages.SharedConfigurationStatusRequest; -import org.apache.geode.management.internal.configuration.messages.SharedConfigurationStatusResponse; import org.apache.logging.log4j.Logger; import java.io.File; @@ -195,7 +195,7 @@ public class InternalLocator extends Locator implements ConnectListener { public boolean isSharedConfigurationRunning() { return this.sharedConfig != null - && this.sharedConfig.getStatus() == SharedConfigurationStatus.RUNNING; + && this.sharedConfig.getStatus() == ClusterConfigurationStatus.RUNNING; } /** @@ -1156,48 +1156,48 @@ public class InternalLocator extends Locator implements ConnectListener { return null; } - class FetchSharedConfigStatus implements Callable<SharedConfigurationStatusResponse> { + class FetchSharedConfigStatus implements Callable<ClusterConfigurationStatusResponse> { static final int SLEEPTIME = 1000; static final byte MAX_RETRIES = 5; @Override - public SharedConfigurationStatusResponse call() throws InterruptedException { + public ClusterConfigurationStatusResponse call() throws InterruptedException { final InternalLocator locator = InternalLocator.this; // TODO: this for-loop is probably not necessary as the if to break is always true for (int i = 0; i < MAX_RETRIES; i++) { if (locator.sharedConfig != null) { - SharedConfigurationStatus status = locator.sharedConfig.getStatus(); - if (status != SharedConfigurationStatus.STARTED - || status != SharedConfigurationStatus.NOT_STARTED) { + ClusterConfigurationStatus status = locator.sharedConfig.getStatus(); + if (status != ClusterConfigurationStatus.STARTED + || status != ClusterConfigurationStatus.NOT_STARTED) { break; } } Thread.sleep(SLEEPTIME); } - SharedConfigurationStatusResponse response; + ClusterConfigurationStatusResponse response; if (locator.sharedConfig != null) { response = locator.sharedConfig.createStatusResponse(); } else { - response = new SharedConfigurationStatusResponse(); - response.setStatus(SharedConfigurationStatus.UNDETERMINED); + response = new ClusterConfigurationStatusResponse(); + response.setStatus(ClusterConfigurationStatus.UNDETERMINED); } return response; } } - public SharedConfigurationStatusResponse getSharedConfigurationStatus() { + public ClusterConfigurationStatusResponse getSharedConfigurationStatus() { ExecutorService es = this.myCache.getDistributionManager().getWaitingThreadPool(); - Future<SharedConfigurationStatusResponse> statusFuture = + Future<ClusterConfigurationStatusResponse> statusFuture = es.submit(new FetchSharedConfigStatus()); - SharedConfigurationStatusResponse response; + ClusterConfigurationStatusResponse response; try { response = statusFuture.get(5, TimeUnit.SECONDS); } catch (Exception e) { logger.info("Exception occurred while fetching the status {}", CliUtil.stackTraceAsString(e)); - response = new SharedConfigurationStatusResponse(); - response.setStatus(SharedConfigurationStatus.UNDETERMINED); + response = new ClusterConfigurationStatusResponse(); + response.setStatus(ClusterConfigurationStatus.UNDETERMINED); } return response; } http://git-wip-us.apache.org/repos/asf/geode/blob/9cd3ef2e/geode-core/src/main/java/org/apache/geode/internal/cache/ClusterConfigurationLoader.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/ClusterConfigurationLoader.java b/geode-core/src/main/java/org/apache/geode/internal/cache/ClusterConfigurationLoader.java index 4f4881f..34d3083 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/cache/ClusterConfigurationLoader.java +++ b/geode-core/src/main/java/org/apache/geode/internal/cache/ClusterConfigurationLoader.java @@ -19,7 +19,6 @@ import static java.util.stream.Collectors.toList; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; -import org.apache.geode.UnmodifiableException; import org.apache.geode.cache.Cache; import org.apache.geode.distributed.internal.ClusterConfigurationService; import org.apache.geode.distributed.internal.DistributionConfig; @@ -57,15 +56,13 @@ public class ClusterConfigurationLoader { private static final Logger logger = LogService.getLogger(); /** - * Deploys the jars received from shared configuration, it undeploys any other jars that were not - * part of shared configuration - * - * @param cache Cache of this member - * @param response {@link ConfigurationResponse} received from the locators + * Deploys the jars received from cluster configuration. Undeploys any other jars that were not + * part of cluster configuration. + * + * @param response {@link ConfigurationResponse} containing the requested {@link Configuration} */ - public static void deployJarsReceivedFromClusterConfiguration(Cache cache, - ConfigurationResponse response) throws IOException, ClassNotFoundException { - logger.info("Requesting cluster configuration"); + static void deployJars(ConfigurationResponse response) + throws IOException, ClassNotFoundException { if (response == null) { return; } @@ -73,38 +70,43 @@ public class ClusterConfigurationLoader { String[] jarFileNames = response.getJarNames(); byte[][] jarBytes = response.getJars(); - if (jarFileNames != null && jarBytes != null) { - logger.info("Got response with jars: {}", Stream.of(jarFileNames).collect(joining(","))); - JarDeployer jarDeployer = ClassPathLoader.getLatest().getJarDeployer(); - jarDeployer.suspendAll(); - try { - List<String> extraJarsOnServer = - jarDeployer.findDeployedJars().stream().map(DeployedJar::getJarName) - .filter(jarName -> !ArrayUtils.contains(jarFileNames, jarName)).collect(toList()); + if (jarFileNames == null || jarBytes == null) { + return; + } - for (String extraJar : extraJarsOnServer) { - logger.info("Removing jar not present in cluster configuration: {}", extraJar); - jarDeployer.deleteAllVersionsOfJar(extraJar); - } + logger.info("Deploying jars from cluster configuration: {}", + Stream.of(jarFileNames).collect(joining(","))); + + JarDeployer jarDeployer = ClassPathLoader.getLatest().getJarDeployer(); + jarDeployer.suspendAll(); + try { + List<String> extraJarsOnServer = + jarDeployer.findDeployedJars().stream().map(DeployedJar::getJarName) + .filter(jarName -> !ArrayUtils.contains(jarFileNames, jarName)).collect(toList()); - List<DeployedJar> deployedJars = jarDeployer.deploy(jarFileNames, jarBytes); + for (String extraJar : extraJarsOnServer) { + logger.info("Removing jar not present in cluster configuration: {}", extraJar); - deployedJars.stream().filter(Objects::nonNull) - .forEach((jar) -> logger.info("Deployed: {}", jar.getFile().getAbsolutePath())); - } finally { - jarDeployer.resumeAll(); + jarDeployer.deleteAllVersionsOfJar(extraJar); } + + List<DeployedJar> deployedJars = jarDeployer.deploy(jarFileNames, jarBytes); + + deployedJars.stream().filter(Objects::nonNull) + .forEach(jar -> logger.info("Deployed: {}", jar.getFile().getAbsolutePath())); + } finally { + jarDeployer.resumeAll(); } } - /*** - * Apply the cache-xml cluster configuration on this member + /** + * Applies the cache-xml from cluster configuration. * * @param cache Cache created for this member * @param response {@link ConfigurationResponse} containing the requested {@link Configuration} * @param config this member's config. */ - public static void applyClusterXmlConfiguration(Cache cache, ConfigurationResponse response, + static void applyCacheXml(Cache cache, ConfigurationResponse response, DistributionConfig config) { if (response == null || response.getRequestedConfiguration().isEmpty()) { return; @@ -113,7 +115,7 @@ public class ClusterConfigurationLoader { List<String> groups = getGroups(config); Map<String, Configuration> requestedConfiguration = response.getRequestedConfiguration(); - List<String> cacheXmlContentList = new LinkedList<String>(); + List<String> cacheXmlContentList = new LinkedList<>(); // apply the cluster config first Configuration clusterConfiguration = @@ -138,27 +140,22 @@ public class ClusterConfigurationLoader { // apply the requested cache xml for (String cacheXmlContent : cacheXmlContentList) { - InputStream is = new ByteArrayInputStream(cacheXmlContent.getBytes()); - try { + try (InputStream is = new ByteArrayInputStream(cacheXmlContent.getBytes())) { cache.loadCacheXml(is); - } finally { - try { - is.close(); - } catch (IOException e) { - } + } catch (IOException e) { + // TODO: all of these catch-blocks should be deleted to favor fail-fast + logger.error(e); } } } - /*** - * Apply the gemfire properties cluster configuration on this member + /** + * Apply the gemfire properties from cluster configuration. * - * @param cache Cache created for this member * @param response {@link ConfigurationResponse} containing the requested {@link Configuration} * @param config this member's config */ - public static void applyClusterPropertiesConfiguration(Cache cache, - ConfigurationResponse response, DistributionConfig config) { + static void applyProperties(ConfigurationResponse response, DistributionConfig config) { if (response == null || response.getRequestedConfiguration().isEmpty()) { return; } @@ -166,7 +163,7 @@ public class ClusterConfigurationLoader { List<String> groups = getGroups(config); Map<String, Configuration> requestedConfiguration = response.getRequestedConfiguration(); - final Properties runtimeProps = new Properties(); + Properties runtimeProps = new Properties(); // apply the cluster config first Configuration clusterConfiguration = @@ -187,13 +184,7 @@ public class ClusterConfigurationLoader { for (Object attNameObj : attNames) { String attName = (String) attNameObj; String attValue = runtimeProps.getProperty(attName); - try { - config.setAttribute(attName, attValue, ConfigSource.runtime()); - } catch (IllegalArgumentException e) { - logger.info(e.getMessage()); - } catch (UnmodifiableException e) { - logger.info(e.getMessage()); - } + config.setAttribute(attName, attValue, ConfigSource.runtime()); } } @@ -205,55 +196,47 @@ public class ClusterConfigurationLoader { * @param config this member's configuration. * @return {@link ConfigurationResponse} */ - public static ConfigurationResponse requestConfigurationFromLocators(DistributionConfig config, + static ConfigurationResponse requestConfiguration(DistributionConfig config, List<String> locatorList) throws ClusterConfigurationNotAvailableException, UnknownHostException { - List<String> groups = ClusterConfigurationLoader.getGroups(config); + ConfigurationRequest request = new ConfigurationRequest(); + request.setNumAttempts(10); + List<String> groups = ClusterConfigurationLoader.getGroups(config); request.addGroups(ClusterConfigurationService.CLUSTER_CONFIG); for (String group : groups) { request.addGroups(group); } - request.setNumAttempts(10); - - ConfigurationResponse response = null; - // Try talking to all the locators in the list - // to get the shared configuration. - TcpClient client = new TcpClient(); + ConfigurationResponse response = null; + // Try talking to all the locators in the list to get the cluster configuration for (String locatorInfo : locatorList) { - DistributionLocatorId dlId = new DistributionLocatorId(locatorInfo); - String ipaddress = dlId.getBindAddress(); - InetAddress locatorInetAddress = null; + DistributionLocatorId locatorId = new DistributionLocatorId(locatorInfo); + String address = locatorId.getBindAddress(); - if (StringUtils.isNotBlank(ipaddress)) { - locatorInetAddress = InetAddress.getByName(ipaddress); + InetAddress inetAddress; + if (StringUtils.isNotBlank(address)) { + inetAddress = InetAddress.getByName(address); } else { - locatorInetAddress = dlId.getHost(); + inetAddress = locatorId.getHost(); } - int port = dlId.getPort(); + int port = locatorId.getPort(); try { - response = (ConfigurationResponse) client.requestToServer(locatorInetAddress, port, request, - 10000); - } catch (UnknownHostException e) { - e.printStackTrace(); - } catch (IOException e) { - // TODO Log - e.printStackTrace(); - } catch (ClassNotFoundException e) { - e.printStackTrace(); + response = + (ConfigurationResponse) client.requestToServer(inetAddress, port, request, 10000); + } catch (IOException | ClassNotFoundException e) { + logger.error(e); } } - // if the response is null , that means Shared Configuration service is not installed on the - // locator - // and hence it returns null - if (response == null || response.failedToGetSharedConfig()) { + // if the response is null, then Cluster Configuration service is not installed on locator + + if (response == null || response.failedToGetClusterConfig()) { throw new ClusterConfigurationNotAvailableException( LocalizedStrings.Launcher_Command_FAILED_TO_GET_SHARED_CONFIGURATION.toLocalizedString()); } @@ -263,9 +246,9 @@ public class ClusterConfigurationLoader { private static List<String> getGroups(DistributionConfig config) { String groupString = config.getGroups(); - List<String> groups = new ArrayList<String>(); + List<String> groups = new ArrayList<>(); if (StringUtils.isNotBlank(groupString)) { - groups.addAll((Arrays.asList(groupString.split(",")))); + groups.addAll(Arrays.asList(groupString.split(","))); } return groups; } http://git-wip-us.apache.org/repos/asf/geode/blob/9cd3ef2e/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java index 40df0c7..539302b 100755 --- a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java +++ b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java @@ -126,7 +126,6 @@ import org.apache.geode.cache.client.PoolFactory; import org.apache.geode.cache.client.PoolManager; import org.apache.geode.cache.client.internal.ClientMetadataService; import org.apache.geode.cache.client.internal.ClientRegionFactoryImpl; -import org.apache.geode.cache.client.internal.ConnectionImpl; import org.apache.geode.cache.client.internal.InternalClientCache; import org.apache.geode.cache.client.internal.PoolImpl; import org.apache.geode.cache.control.ResourceManager; @@ -213,7 +212,6 @@ import org.apache.geode.internal.net.SocketCreator; import org.apache.geode.internal.offheap.MemoryAllocator; import org.apache.geode.internal.process.ClusterConfigurationNotAvailableException; import org.apache.geode.internal.security.SecurityService; -import org.apache.geode.internal.security.SecurityServiceFactory; import org.apache.geode.internal.sequencelog.SequenceLoggerImpl; import org.apache.geode.internal.tcp.ConnectionTable; import org.apache.geode.internal.util.concurrent.FutureResult; @@ -959,6 +957,8 @@ public class GemFireCacheImpl implements InternalCache, InternalClientCache, Has /** * Request the shared configuration from the locator(s) which have the Cluster config service * running + * <p> + * Uses this.dm, this.isClient, this.system */ private ConfigurationResponse requestSharedConfiguration() { final DistributionConfig config = this.system.getConfig(); @@ -994,7 +994,7 @@ public class GemFireCacheImpl implements InternalCache, InternalClientCache, Has try { ConfigurationResponse response = ClusterConfigurationLoader - .requestConfigurationFromLocators(this.system.getConfig(), locatorConnectionStrings); + .requestConfiguration(this.system.getConfig(), locatorConnectionStrings); // log the configuration received from the locator logger.info(LocalizedMessage @@ -1039,7 +1039,7 @@ public class GemFireCacheImpl implements InternalCache, InternalClientCache, Has private void deployJarsReceivedFromClusterConfiguration(ConfigurationResponse response) { try { - ClusterConfigurationLoader.deployJarsReceivedFromClusterConfiguration(this, response); + ClusterConfigurationLoader.deployJars(response); } catch (IOException | ClassNotFoundException e) { throw new GemFireConfigException( LocalizedStrings.GemFireCache_EXCEPTION_OCCURRED_WHILE_DEPLOYING_JARS_FROM_SHARED_CONDFIGURATION @@ -1159,8 +1159,7 @@ public class GemFireCacheImpl implements InternalCache, InternalClientCache, Has deployJarsReceivedFromClusterConfiguration(configurationResponse); // apply the cluster's properties configuration and initialize security using that configuration - ClusterConfigurationLoader.applyClusterPropertiesConfiguration(this, configurationResponse, - this.system.getConfig()); + ClusterConfigurationLoader.applyProperties(configurationResponse, this.system.getConfig()); SystemMemberCacheEventProcessor.send(this, Operation.CACHE_CREATE); this.resourceAdvisor.initializationGate(); @@ -1188,7 +1187,7 @@ public class GemFireCacheImpl implements InternalCache, InternalClientCache, Has // Deploy all the jars from the deploy working dir. ClassPathLoader.getLatest().getJarDeployer().loadPreviouslyDeployedJarsFromDisk(); } - ClusterConfigurationLoader.applyClusterXmlConfiguration(this, configurationResponse, + ClusterConfigurationLoader.applyCacheXml(this, configurationResponse, this.system.getConfig()); initializeDeclarativeCache(); completedCacheXml = true; http://git-wip-us.apache.org/repos/asf/geode/blob/9cd3ef2e/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java index 9d263d1..70e2c01 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportImportClusterConfigurationCommands.java @@ -167,7 +167,7 @@ public class ExportImportClusterConfigurationCommands implements GfshCommand { ZipUtils.unzip(zipFileName, sc.getSharedConfigurationDirPath()); // load it from the disk - sc.loadSharedConfigurationFromDisk(); + sc.loadClusterConfigurationFromDisk(); infoData.addLine(CliStrings.IMPORT_SHARED_CONFIG__SUCCESS__MSG); } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/geode/blob/9cd3ef2e/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StatusCommands.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StatusCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StatusCommands.java index fffb964..a7a55c0 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StatusCommands.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StatusCommands.java @@ -18,7 +18,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import org.springframework.shell.core.CommandMarker; +import org.apache.geode.management.internal.configuration.domain.ClusterConfigurationStatus; import org.springframework.shell.core.annotation.CliAvailabilityIndicator; import org.springframework.shell.core.annotation.CliCommand; @@ -35,7 +35,6 @@ import org.apache.geode.management.internal.cli.functions.FetchSharedConfigurati import org.apache.geode.management.internal.cli.i18n.CliStrings; import org.apache.geode.management.internal.cli.result.ResultBuilder; import org.apache.geode.management.internal.cli.result.TabularResultData; -import org.apache.geode.management.internal.configuration.domain.SharedConfigurationStatus; import org.apache.geode.management.internal.security.ResourceOperation; import org.apache.geode.security.ResourcePermission.Operation; import org.apache.geode.security.ResourcePermission.Resource; @@ -71,7 +70,7 @@ public class StatusCommands implements GfshCommand { table.accumulate(CliStrings.STATUS_SHARED_CONFIG_NAME_HEADER, result.getMemberIdOrName()); String status = (String) result.getSerializables()[0]; table.accumulate(CliStrings.STATUS_SHARED_CONFIG_STATUS, status); - if (SharedConfigurationStatus.RUNNING.name().equals(status)) { + if (ClusterConfigurationStatus.RUNNING.name().equals(status)) { isSharedConfigRunning = true; } } http://git-wip-us.apache.org/repos/asf/geode/blob/9cd3ef2e/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/FetchSharedConfigurationStatusFunction.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/FetchSharedConfigurationStatusFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/FetchSharedConfigurationStatusFunction.java index c688d7a..d7d70b5 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/FetchSharedConfigurationStatusFunction.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/FetchSharedConfigurationStatusFunction.java @@ -22,7 +22,7 @@ import org.apache.geode.distributed.internal.InternalLocator; import org.apache.geode.internal.InternalEntity; import org.apache.geode.internal.cache.GemFireCacheImpl; import org.apache.geode.internal.cache.InternalCache; -import org.apache.geode.management.internal.configuration.domain.SharedConfigurationStatus; +import org.apache.geode.management.internal.configuration.domain.ClusterConfigurationStatus; public class FetchSharedConfigurationStatusFunction extends FunctionAdapter implements InternalEntity { @@ -34,7 +34,7 @@ public class FetchSharedConfigurationStatusFunction extends FunctionAdapter InternalLocator locator = InternalLocator.getLocator(); InternalCache cache = GemFireCacheImpl.getInstance(); DistributedMember member = cache.getDistributedSystem().getDistributedMember(); - SharedConfigurationStatus status = locator.getSharedConfigurationStatus().getStatus(); + ClusterConfigurationStatus status = locator.getSharedConfigurationStatus().getStatus(); String memberId = member.getName(); if (StringUtils.isBlank(memberId)) { http://git-wip-us.apache.org/repos/asf/geode/blob/9cd3ef2e/geode-core/src/main/java/org/apache/geode/management/internal/configuration/domain/ClusterConfigurationStatus.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/domain/ClusterConfigurationStatus.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/domain/ClusterConfigurationStatus.java new file mode 100644 index 0000000..55bf372 --- /dev/null +++ b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/domain/ClusterConfigurationStatus.java @@ -0,0 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.geode.management.internal.configuration.domain; + +public enum ClusterConfigurationStatus { + NOT_STARTED, STARTED, RUNNING, STOPPED, WAITING, UNDETERMINED +} http://git-wip-us.apache.org/repos/asf/geode/blob/9cd3ef2e/geode-core/src/main/java/org/apache/geode/management/internal/configuration/domain/SharedConfigurationStatus.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/domain/SharedConfigurationStatus.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/domain/SharedConfigurationStatus.java deleted file mode 100644 index 3f93b6c..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/domain/SharedConfigurationStatus.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.geode.management.internal.configuration.domain; - -public enum SharedConfigurationStatus { - NOT_STARTED, STARTED, RUNNING, STOPPED, WAITING, UNDETERMINED -} http://git-wip-us.apache.org/repos/asf/geode/blob/9cd3ef2e/geode-core/src/main/java/org/apache/geode/management/internal/configuration/messages/ClusterConfigurationStatusResponse.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/messages/ClusterConfigurationStatusResponse.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/messages/ClusterConfigurationStatusResponse.java new file mode 100644 index 0000000..e811b71 --- /dev/null +++ b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/messages/ClusterConfigurationStatusResponse.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.geode.management.internal.configuration.messages; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.HashSet; +import java.util.Set; + +import org.apache.geode.DataSerializable; +import org.apache.geode.DataSerializer; +import org.apache.geode.internal.cache.persistence.PersistentMemberPattern; +import org.apache.geode.management.internal.configuration.domain.ClusterConfigurationStatus; + +public class ClusterConfigurationStatusResponse implements DataSerializable { + private static final long serialVersionUID = 1L; + + private ClusterConfigurationStatus status; + + private Set<PersistentMemberPattern> waitingLocatorsInfo; + + public ClusterConfigurationStatusResponse() { + // nothing + } + + public void setStatus(ClusterConfigurationStatus status) { + this.status = status; + } + + public ClusterConfigurationStatus getStatus() { + return this.status; + } + + public void addWaitingLocatorInfo(Set<PersistentMemberPattern> waitingLocatorsInfo) { + this.waitingLocatorsInfo = waitingLocatorsInfo; + } + + public Set<PersistentMemberPattern> getOtherLocatorInformation() { + return this.waitingLocatorsInfo; + } + + @Override + public void toData(DataOutput out) throws IOException { + DataSerializer.writeEnum(status, out); + DataSerializer.writeHashSet((HashSet<?>) waitingLocatorsInfo, out); + } + + @Override + public void fromData(DataInput in) throws IOException, ClassNotFoundException { + this.status = DataSerializer.readEnum(ClusterConfigurationStatus.class, in); + this.waitingLocatorsInfo = DataSerializer.readHashSet(in); + } + +} http://git-wip-us.apache.org/repos/asf/geode/blob/9cd3ef2e/geode-core/src/main/java/org/apache/geode/management/internal/configuration/messages/ConfigurationResponse.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/messages/ConfigurationResponse.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/messages/ConfigurationResponse.java index cb9951f..d29ccfe 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/messages/ConfigurationResponse.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/messages/ConfigurationResponse.java @@ -27,7 +27,6 @@ import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import java.util.Set; @@ -35,18 +34,18 @@ import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactoryConfigurationError; -/*** +/** * Response containing the configuration requested by the {@link ConfigurationRequest} */ public class ConfigurationResponse implements DataSerializableFixedID { - private Map<String, Configuration> requestedConfiguration = new HashMap<String, Configuration>(); + private Map<String, Configuration> requestedConfiguration = new HashMap<>(); private byte[][] jarBytes; private String[] jarNames; - private boolean failedToGetSharedConfig = false; + private boolean failedToGetClusterConfig = false; public ConfigurationResponse() { - + // nothing } public ConfigurationResponse(Map<String, Configuration> requestedConfiguration) { @@ -60,10 +59,10 @@ public class ConfigurationResponse implements DataSerializableFixedID { @Override public void toData(DataOutput out) throws IOException { - DataSerializer.writeHashMap((HashMap<?, ?>) requestedConfiguration, out); - DataSerializer.writeStringArray(jarNames, out); - DataSerializer.writeArrayOfByteArrays(jarBytes, out); - DataSerializer.writeBoolean(Boolean.valueOf(failedToGetSharedConfig), out); + DataSerializer.writeHashMap(this.requestedConfiguration, out); + DataSerializer.writeStringArray(this.jarNames, out); + DataSerializer.writeArrayOfByteArrays(this.jarBytes, out); + DataSerializer.writeBoolean(this.failedToGetClusterConfig, out); } @Override @@ -71,62 +70,57 @@ public class ConfigurationResponse implements DataSerializableFixedID { this.requestedConfiguration = DataSerializer.readHashMap(in); this.jarNames = DataSerializer.readStringArray(in); this.jarBytes = DataSerializer.readArrayOfByteArrays(in); - this.failedToGetSharedConfig = DataSerializer.readBoolean(in); + this.failedToGetClusterConfig = DataSerializer.readBoolean(in); } public Map<String, Configuration> getRequestedConfiguration() { return this.requestedConfiguration; } - public void setRequestedConfiguration(Map<String, Configuration> requestedConfiguration) { - this.requestedConfiguration = requestedConfiguration; - } - public void addConfiguration(Configuration configuration) { if (configuration != null) { this.requestedConfiguration.put(configuration.getConfigName(), configuration); } } + @Override public String toString() { - StringBuffer sb = new StringBuffer(); - Set<String> configNames = requestedConfiguration.keySet(); + StringBuilder sb = new StringBuilder(); + Set<String> configNames = this.requestedConfiguration.keySet(); for (String configName : configNames) { - sb.append("\n" + requestedConfiguration.get(configName)); + sb.append("\n").append(this.requestedConfiguration.get(configName)); } return sb.toString(); } public String describeConfig() { - StringBuffer sb = new StringBuffer(); - if (requestedConfiguration.isEmpty()) { - sb.append("Received an empty shared configuration"); + StringBuilder sb = new StringBuilder(); + if (this.requestedConfiguration.isEmpty()) { + sb.append("Received an empty cluster configuration"); } else { - Set<Entry<String, Configuration>> entries = requestedConfiguration.entrySet(); - Iterator<Entry<String, Configuration>> iter = entries.iterator(); + Set<Entry<String, Configuration>> entries = this.requestedConfiguration.entrySet(); - while (iter.hasNext()) { - Entry<String, Configuration> entry = iter.next(); + for (Entry<String, Configuration> entry : entries) { String configType = entry.getKey(); Configuration config = entry.getValue(); if (config != null) { sb.append("\n***************************************************************"); - sb.append("\nConfiguration for '" + configType + "'"); + sb.append("\nConfiguration for '").append(configType).append("'"); sb.append("\n\nJar files to deployed"); Set<String> jarNames = config.getJarNames(); - Iterator<String> jarIter = jarNames.iterator(); + int jarCounter = 0; - while (jarIter.hasNext()) { - sb.append("\n" + ++jarCounter + "." + jarIter.next()); + for (final String jarName : jarNames) { + sb.append("\n").append(++jarCounter).append(".").append(jarName); } try { String cacheXmlContent = config.getCacheXmlContent(); if (StringUtils.isNotBlank(cacheXmlContent)) { - sb.append("\n" + XmlUtils.prettyXml(cacheXmlContent)); + sb.append("\n").append(XmlUtils.prettyXml(cacheXmlContent)); } } catch (IOException | TransformerFactoryConfigurationError | TransformerException | SAXException | ParserConfigurationException e) { @@ -139,7 +133,6 @@ public class ConfigurationResponse implements DataSerializableFixedID { return sb.toString(); } - public String[] getJarNames() { return this.jarNames; } @@ -153,17 +146,17 @@ public class ConfigurationResponse implements DataSerializableFixedID { this.jarBytes = jarBytes; } - // TODO Sourabh, please review for correctness + @Override public Version[] getSerializationVersions() { return new Version[] {Version.CURRENT}; } - public boolean failedToGetSharedConfig() { - return failedToGetSharedConfig; + public boolean failedToGetClusterConfig() { + return this.failedToGetClusterConfig; } - public void setFailedToGetSharedConfig(boolean failedToGetSharedConfig) { - this.failedToGetSharedConfig = failedToGetSharedConfig; + public void setFailedToGetClusterConfig(boolean failedToGetClusterConfig) { + this.failedToGetClusterConfig = failedToGetClusterConfig; } } http://git-wip-us.apache.org/repos/asf/geode/blob/9cd3ef2e/geode-core/src/main/java/org/apache/geode/management/internal/configuration/messages/SharedConfigurationStatusResponse.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/messages/SharedConfigurationStatusResponse.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/messages/SharedConfigurationStatusResponse.java deleted file mode 100644 index 89b769b..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/messages/SharedConfigurationStatusResponse.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.geode.management.internal.configuration.messages; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.Callable; -import java.util.concurrent.Future; -import java.util.concurrent.FutureTask; - -import org.apache.geode.DataSerializable; -import org.apache.geode.DataSerializer; -import org.apache.geode.internal.cache.persistence.PersistentMemberPattern; -import org.apache.geode.management.internal.configuration.domain.SharedConfigurationStatus; - -/***** - * - * - */ -public class SharedConfigurationStatusResponse implements DataSerializable { - - - private SharedConfigurationStatus status; - private static final long serialVersionUID = 1L; - - private Set<PersistentMemberPattern> waitingLocatorsInfo; - - public SharedConfigurationStatusResponse() {} - - public void setStatus(SharedConfigurationStatus status) { - this.status = status; - } - - public SharedConfigurationStatus getStatus() { - return this.status; - } - - public void addWaitingLocatorInfo(Set<PersistentMemberPattern> waitingLocatorsInfo) { - this.waitingLocatorsInfo = waitingLocatorsInfo; - } - - public Set<PersistentMemberPattern> getOtherLocatorInformation() { - return this.waitingLocatorsInfo; - } - - @Override - public void toData(DataOutput out) throws IOException { - DataSerializer.writeEnum(status, out); - DataSerializer.writeHashSet((HashSet<?>) waitingLocatorsInfo, out); - } - - @Override - public void fromData(DataInput in) throws IOException, ClassNotFoundException { - this.status = DataSerializer.readEnum(SharedConfigurationStatus.class, in); - this.waitingLocatorsInfo = DataSerializer.readHashSet(in); - } - - -} http://git-wip-us.apache.org/repos/asf/geode/blob/9cd3ef2e/geode-core/src/main/java/org/apache/geode/management/internal/configuration/utils/ClusterConfigurationStatusRetriever.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/utils/ClusterConfigurationStatusRetriever.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/utils/ClusterConfigurationStatusRetriever.java index 3080809..77fc8cd 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/utils/ClusterConfigurationStatusRetriever.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/utils/ClusterConfigurationStatusRetriever.java @@ -18,12 +18,12 @@ import org.apache.geode.distributed.LocatorLauncher; import org.apache.geode.distributed.internal.tcpserver.TcpClient; import org.apache.geode.internal.cache.persistence.PersistentMemberPattern; import org.apache.geode.management.internal.cli.shell.Gfsh; +import org.apache.geode.management.internal.configuration.domain.ClusterConfigurationStatus; +import org.apache.geode.management.internal.configuration.messages.ClusterConfigurationStatusResponse; import org.apache.geode.management.internal.configuration.messages.SharedConfigurationStatusRequest; -import org.apache.geode.management.internal.configuration.messages.SharedConfigurationStatusResponse; import java.io.IOException; import java.net.InetAddress; -import java.net.InetSocketAddress; import java.util.Set; public class ClusterConfigurationStatusRetriever { @@ -37,19 +37,17 @@ public class ClusterConfigurationStatusRetriever { final InetAddress networkAddress = InetAddress.getByName(locatorHostName); TcpClient client = new TcpClient(); - SharedConfigurationStatusResponse statusResponse = - (SharedConfigurationStatusResponse) client.requestToServer(networkAddress, locatorPort, + ClusterConfigurationStatusResponse statusResponse = + (ClusterConfigurationStatusResponse) client.requestToServer(networkAddress, locatorPort, new SharedConfigurationStatusRequest(), 10000, true); for (int i = 0; i < NUM_ATTEMPTS_FOR_SHARED_CONFIGURATION_STATUS; i++) { - if (statusResponse.getStatus().equals( - org.apache.geode.management.internal.configuration.domain.SharedConfigurationStatus.STARTED) - || statusResponse.getStatus().equals( - org.apache.geode.management.internal.configuration.domain.SharedConfigurationStatus.NOT_STARTED)) { + if (statusResponse.getStatus().equals(ClusterConfigurationStatus.STARTED) + || statusResponse.getStatus().equals(ClusterConfigurationStatus.NOT_STARTED)) { statusResponse = - (SharedConfigurationStatusResponse) client.requestToServer(networkAddress, + (ClusterConfigurationStatusResponse) client.requestToServer(networkAddress, locatorPort, new SharedConfigurationStatusRequest(), 10000, true); try { Thread.sleep(5000);
