Search in sources :

Example 11 with Configuration

use of org.apache.geode.management.internal.configuration.domain.Configuration in project geode by apache.

the class ExportLogsFunction method createOrGetExistingExportLogsRegion.

public static Region createOrGetExistingExportLogsRegion(boolean isInitiatingMember, InternalCache cache) throws IOException, ClassNotFoundException {
    Region exportLogsRegion = cache.getRegion(EXPORT_LOGS_REGION);
    if (exportLogsRegion == null) {
        AttributesFactory<String, Configuration> regionAttrsFactory = new AttributesFactory<>();
        regionAttrsFactory.setDataPolicy(DataPolicy.EMPTY);
        regionAttrsFactory.setScope(Scope.DISTRIBUTED_ACK);
        if (isInitiatingMember) {
            regionAttrsFactory.setCacheWriter(new ExportLogsCacheWriter());
        }
        InternalRegionArguments internalArgs = new InternalRegionArguments();
        internalArgs.setIsUsedForMetaRegion(true);
        exportLogsRegion = cache.createVMRegion(EXPORT_LOGS_REGION, regionAttrsFactory.create(), internalArgs);
    }
    return exportLogsRegion;
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) Configuration(org.apache.geode.management.internal.configuration.domain.Configuration) ExportLogsCacheWriter(org.apache.geode.management.internal.cli.util.ExportLogsCacheWriter) Region(org.apache.geode.cache.Region) InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments)

Example 12 with Configuration

use of org.apache.geode.management.internal.configuration.domain.Configuration in project geode by apache.

the class ClusterConfigurationLoader method applyClusterXmlConfiguration.

/***
   * Apply the cache-xml cluster configuration on this member
   *
   * @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, DistributionConfig config) {
    if (response == null || response.getRequestedConfiguration().isEmpty()) {
        return;
    }
    List<String> groups = getGroups(config);
    Map<String, Configuration> requestedConfiguration = response.getRequestedConfiguration();
    List<String> cacheXmlContentList = new LinkedList<String>();
    // apply the cluster config first
    Configuration clusterConfiguration = requestedConfiguration.get(ClusterConfigurationService.CLUSTER_CONFIG);
    if (clusterConfiguration != null) {
        String cacheXmlContent = clusterConfiguration.getCacheXmlContent();
        if (StringUtils.isNotBlank(cacheXmlContent)) {
            cacheXmlContentList.add(cacheXmlContent);
        }
    }
    // then apply the groups config
    for (String group : groups) {
        Configuration groupConfiguration = requestedConfiguration.get(group);
        if (groupConfiguration != null) {
            String cacheXmlContent = groupConfiguration.getCacheXmlContent();
            if (StringUtils.isNotBlank(cacheXmlContent)) {
                cacheXmlContentList.add(cacheXmlContent);
            }
        }
    }
    // apply the requested cache xml
    for (String cacheXmlContent : cacheXmlContentList) {
        InputStream is = new ByteArrayInputStream(cacheXmlContent.getBytes());
        try {
            cache.loadCacheXml(is);
        } finally {
            try {
                is.close();
            } catch (IOException e) {
            }
        }
    }
}
Also used : Configuration(org.apache.geode.management.internal.configuration.domain.Configuration) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) LinkedList(java.util.LinkedList)

Example 13 with Configuration

use of org.apache.geode.management.internal.configuration.domain.Configuration in project geode by apache.

the class ClusterConfigurationLoader method deployJarsReceivedFromClusterConfiguration.

/**
   * 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
   */
public static void deployJarsReceivedFromClusterConfiguration(Cache cache, ConfigurationResponse response) throws IOException, ClassNotFoundException {
    logger.info("Requesting cluster configuration");
    if (response == null) {
        return;
    }
    String[] jarFileNames = response.getJarNames();
    byte[][] jarBytes = response.getJars();
    logger.info("Got response with jars: {}", Stream.of(jarFileNames).collect(joining(",")));
    if (jarFileNames != null && jarBytes != null) {
        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());
            for (String extraJar : extraJarsOnServer) {
                logger.info("Removing jar not present in cluster configuration: {}", extraJar);
                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();
        }
    }
}
Also used : ClassPathLoader(org.apache.geode.internal.ClassPathLoader) StringUtils(org.apache.commons.lang.StringUtils) Arrays(java.util.Arrays) ClusterConfigurationService(org.apache.geode.distributed.internal.ClusterConfigurationService) DeployedJar(org.apache.geode.internal.DeployedJar) JarDeployer(org.apache.geode.internal.JarDeployer) LocalizedStrings(org.apache.geode.internal.i18n.LocalizedStrings) DistributionLocatorId(org.apache.geode.internal.admin.remote.DistributionLocatorId) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) Cache(org.apache.geode.cache.Cache) ConfigSource(org.apache.geode.internal.ConfigSource) ConfigurationRequest(org.apache.geode.management.internal.configuration.messages.ConfigurationRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) UnmodifiableException(org.apache.geode.UnmodifiableException) LogService(org.apache.geode.internal.logging.LogService) Map(java.util.Map) LinkedList(java.util.LinkedList) ClusterConfigurationNotAvailableException(org.apache.geode.internal.process.ClusterConfigurationNotAvailableException) Properties(java.util.Properties) TcpClient(org.apache.geode.distributed.internal.tcpserver.TcpClient) Set(java.util.Set) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) Collectors.joining(java.util.stream.Collectors.joining) Objects(java.util.Objects) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) Logger(org.apache.logging.log4j.Logger) Stream(java.util.stream.Stream) Configuration(org.apache.geode.management.internal.configuration.domain.Configuration) ConfigurationResponse(org.apache.geode.management.internal.configuration.messages.ConfigurationResponse) ArrayUtils(org.apache.commons.lang.ArrayUtils) InputStream(java.io.InputStream) DeployedJar(org.apache.geode.internal.DeployedJar) JarDeployer(org.apache.geode.internal.JarDeployer)

Example 14 with Configuration

use of org.apache.geode.management.internal.configuration.domain.Configuration in project geode by apache.

the class GemFireCacheImpl method requestSharedConfiguration.

/**
   * Request the shared configuration from the locator(s) which have the Cluster config service
   * running
   */
private ConfigurationResponse requestSharedConfiguration() {
    final DistributionConfig config = this.system.getConfig();
    if (!(this.dm instanceof DistributionManager)) {
        return null;
    }
    // do nothing if this vm is/has locator or this is a client
    if (this.dm.getDMType() == DistributionManager.LOCATOR_DM_TYPE || this.isClient || Locator.getLocator() != null) {
        return null;
    }
    // can't simply return null if server is not using shared configuration, since we need to find
    // out
    // if the locator is running in secure mode or not, if yes, then we need to throw an exception
    // if server is not using cluster config
    Map<InternalDistributedMember, Collection<String>> scl = getDistributionManager().getAllHostedLocatorsWithSharedConfiguration();
    // then do not make requests to the locators
    if (scl.isEmpty()) {
        logger.info(LocalizedMessage.create(LocalizedStrings.GemFireCache_NO_LOCATORS_FOUND_WITH_SHARED_CONFIGURATION));
        return null;
    }
    List<String> locatorConnectionStrings = getSharedConfigLocatorConnectionStringList();
    try {
        ConfigurationResponse response = ClusterConfigurationLoader.requestConfigurationFromLocators(this.system.getConfig(), locatorConnectionStrings);
        // log the configuration received from the locator
        logger.info(LocalizedMessage.create(LocalizedStrings.GemFireCache_RECEIVED_SHARED_CONFIGURATION_FROM_LOCATORS));
        logger.info(response.describeConfig());
        Configuration clusterConfig = response.getRequestedConfiguration().get(ClusterConfigurationService.CLUSTER_CONFIG);
        Properties clusterSecProperties = clusterConfig == null ? new Properties() : clusterConfig.getGemfireProperties();
        // If not using shared configuration, return null or throw an exception is locator is secured
        if (!config.getUseSharedConfiguration()) {
            if (clusterSecProperties.containsKey(ConfigurationProperties.SECURITY_MANAGER)) {
                throw new GemFireConfigException(LocalizedStrings.GEMFIRE_CACHE_SECURITY_MISCONFIGURATION_2.toLocalizedString());
            } else {
                logger.info(LocalizedMessage.create(LocalizedStrings.GemFireCache_NOT_USING_SHARED_CONFIGURATION));
                return null;
            }
        }
        Properties serverSecProperties = config.getSecurityProps();
        // check for possible mis-configuration
        if (isMisConfigured(clusterSecProperties, serverSecProperties, ConfigurationProperties.SECURITY_MANAGER) || isMisConfigured(clusterSecProperties, serverSecProperties, ConfigurationProperties.SECURITY_POST_PROCESSOR)) {
            throw new GemFireConfigException(LocalizedStrings.GEMFIRE_CACHE_SECURITY_MISCONFIGURATION.toLocalizedString());
        }
        return response;
    } catch (ClusterConfigurationNotAvailableException e) {
        throw new GemFireConfigException(LocalizedStrings.GemFireCache_SHARED_CONFIGURATION_NOT_AVAILABLE.toLocalizedString(), e);
    } catch (UnknownHostException e) {
        throw new GemFireConfigException(e.getLocalizedMessage(), e);
    }
}
Also used : ConfigurationResponse(org.apache.geode.management.internal.configuration.messages.ConfigurationResponse) Configuration(org.apache.geode.management.internal.configuration.domain.Configuration) UnknownHostException(java.net.UnknownHostException) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) GemFireConfigException(org.apache.geode.GemFireConfigException) Collection(java.util.Collection) ClusterConfigurationNotAvailableException(org.apache.geode.internal.process.ClusterConfigurationNotAvailableException) DistributionManager(org.apache.geode.distributed.internal.DistributionManager)

Example 15 with Configuration

use of org.apache.geode.management.internal.configuration.domain.Configuration in project geode by apache.

the class ConfigurationResponse method describeConfig.

public String describeConfig() {
    StringBuffer sb = new StringBuffer();
    if (requestedConfiguration.isEmpty()) {
        sb.append("Received an empty shared configuration");
    } else {
        Set<Entry<String, Configuration>> entries = requestedConfiguration.entrySet();
        Iterator<Entry<String, Configuration>> iter = entries.iterator();
        while (iter.hasNext()) {
            Entry<String, Configuration> entry = iter.next();
            String configType = entry.getKey();
            Configuration config = entry.getValue();
            if (config != null) {
                sb.append("\n***************************************************************");
                sb.append("\nConfiguration for  '" + configType + "'");
                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());
                }
                try {
                    String cacheXmlContent = config.getCacheXmlContent();
                    if (StringUtils.isNotBlank(cacheXmlContent)) {
                        sb.append("\n" + XmlUtils.prettyXml(cacheXmlContent));
                    }
                } catch (IOException | TransformerFactoryConfigurationError | TransformerException | SAXException | ParserConfigurationException e) {
                    throw new InternalGemFireError(e);
                }
            }
        }
    }
    return sb.toString();
}
Also used : TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) Configuration(org.apache.geode.management.internal.configuration.domain.Configuration) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) Entry(java.util.Map.Entry) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TransformerException(javax.xml.transform.TransformerException) InternalGemFireError(org.apache.geode.InternalGemFireError)

Aggregations

Configuration (org.apache.geode.management.internal.configuration.domain.Configuration)25 IOException (java.io.IOException)14 File (java.io.File)11 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)8 TransformerException (javax.xml.transform.TransformerException)8 SAXException (org.xml.sax.SAXException)8 CancelException (org.apache.geode.CancelException)7 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)7 TimeoutException (org.apache.geode.cache.TimeoutException)7 LeaseExpiredException (org.apache.geode.distributed.LeaseExpiredException)7 Properties (java.util.Properties)5 ClusterConfigurationService (org.apache.geode.distributed.internal.ClusterConfigurationService)5 InternalLocator (org.apache.geode.distributed.internal.InternalLocator)4 ConfigurationResponse (org.apache.geode.management.internal.configuration.messages.ConfigurationResponse)4 Document (org.w3c.dom.Document)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2