Search in sources :

Example 6 with Configuration

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

the class ClusterConfigurationService method initSharedConfiguration.

/**
   * Creates the shared configuration service
   * 
   * @param loadSharedConfigFromDir when set to true, loads the configuration from the share_config
   *        directory
   */
void initSharedConfiguration(boolean loadSharedConfigFromDir) throws CacheLoaderException, TimeoutException, IllegalStateException, IOException, TransformerException, SAXException, ParserConfigurationException {
    this.status.set(SharedConfigurationStatus.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();
        } else {
            persistSecuritySettings(configRegion);
            // if it doesn't exist yet
            for (Entry<String, Configuration> stringConfigurationEntry : configRegion.entrySet()) {
                Configuration config = stringConfigurationEntry.getValue();
                for (String jar : config.getJarNames()) {
                    if (!getPathToJarOnThisLocator(stringConfigurationEntry.getKey(), jar).toFile().exists()) {
                        downloadJarFromOtherLocators(stringConfigurationEntry.getKey(), jar);
                    }
                }
            }
        }
    } finally {
        unlockSharedConfiguration();
    }
    this.status.set(SharedConfigurationStatus.RUNNING);
}
Also used : Configuration(org.apache.geode.management.internal.configuration.domain.Configuration)

Example 7 with Configuration

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

the class ClusterConfigurationService method destroySharedConfiguration.

/**
   * For tests only. TODO: clean this up and remove from production code
   * <p>
   * Throws {@code AssertionError} wrapping any exception thrown by operation.
   */
public void destroySharedConfiguration() {
    try {
        Region<String, Configuration> configRegion = getConfigurationRegion();
        if (configRegion != null) {
            configRegion.destroyRegion();
        }
        DiskStore configDiskStore = this.cache.findDiskStore(CLUSTER_CONFIG_ARTIFACTS_DIR_NAME);
        if (configDiskStore != null) {
            configDiskStore.destroy();
            File file = new File(this.configDiskDirPath);
            FileUtils.deleteDirectory(file);
        }
        FileUtils.deleteDirectory(new File(this.configDirPath));
    } catch (Exception exception) {
        throw new AssertionError(exception);
    }
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) Configuration(org.apache.geode.management.internal.configuration.domain.Configuration) File(java.io.File) TimeoutException(org.apache.geode.cache.TimeoutException) CancelException(org.apache.geode.CancelException) SAXException(org.xml.sax.SAXException) TransformerException(javax.xml.transform.TransformerException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) IOException(java.io.IOException) LeaseExpiredException(org.apache.geode.distributed.LeaseExpiredException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 8 with Configuration

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

the class ClusterConfigurationLoader method applyClusterPropertiesConfiguration.

/***
   * Apply the gemfire properties 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 applyClusterPropertiesConfiguration(Cache cache, ConfigurationResponse response, DistributionConfig config) {
    if (response == null || response.getRequestedConfiguration().isEmpty()) {
        return;
    }
    List<String> groups = getGroups(config);
    Map<String, Configuration> requestedConfiguration = response.getRequestedConfiguration();
    final Properties runtimeProps = new Properties();
    // apply the cluster config first
    Configuration clusterConfiguration = requestedConfiguration.get(ClusterConfigurationService.CLUSTER_CONFIG);
    if (clusterConfiguration != null) {
        runtimeProps.putAll(clusterConfiguration.getGemfireProperties());
    }
    // then apply the group config
    for (String group : groups) {
        Configuration groupConfiguration = requestedConfiguration.get(group);
        if (groupConfiguration != null) {
            runtimeProps.putAll(groupConfiguration.getGemfireProperties());
        }
    }
    Set<Object> attNames = runtimeProps.keySet();
    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());
        }
    }
}
Also used : UnmodifiableException(org.apache.geode.UnmodifiableException) Configuration(org.apache.geode.management.internal.configuration.domain.Configuration) Properties(java.util.Properties)

Example 9 with Configuration

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

the class ExportImportClusterConfigurationCommands method importSharedConfig.

@CliCommand(value = { CliStrings.IMPORT_SHARED_CONFIG }, help = CliStrings.IMPORT_SHARED_CONFIG__HELP)
@CliMetaData(interceptor = "org.apache.geode.management.internal.cli.commands.ExportImportClusterConfigurationCommands$ImportInterceptor", relatedTopic = { CliStrings.TOPIC_GEODE_CONFIG })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.MANAGE)
@SuppressWarnings("unchecked")
public Result importSharedConfig(@CliOption(key = { CliStrings.IMPORT_SHARED_CONFIG__ZIP }, mandatory = true, help = CliStrings.IMPORT_SHARED_CONFIG__ZIP__HELP) String zip) {
    InternalLocator locator = InternalLocator.getLocator();
    if (!locator.isSharedConfigurationRunning()) {
        ErrorResultData errorData = ResultBuilder.createErrorResultData();
        errorData.addLine(CliStrings.SHARED_CONFIGURATION_NOT_STARTED);
        return ResultBuilder.buildResult(errorData);
    }
    InternalCache cache = getCache();
    Set<DistributedMember> servers = CliUtil.getAllNormalMembers(cache);
    Set<String> regionsWithData = servers.stream().map(this::getRegionNamesOnServer).flatMap(Collection::stream).collect(toSet());
    if (!regionsWithData.isEmpty()) {
        return ResultBuilder.createGemFireErrorResult("Cannot import cluster configuration with existing regions: " + regionsWithData.stream().collect(joining(",")));
    }
    byte[][] shellBytesData = CommandExecutionContext.getBytesFromShell();
    String zipFileName = CliUtil.bytesToNames(shellBytesData)[0];
    byte[] zipBytes = CliUtil.bytesToData(shellBytesData)[0];
    Result result;
    InfoResultData infoData = ResultBuilder.createInfoResultData();
    File zipFile = new File(zipFileName);
    try {
        ClusterConfigurationService sc = locator.getSharedConfiguration();
        // backup the old config
        for (Configuration config : sc.getEntireConfiguration().values()) {
            sc.writeConfigToFile(config);
        }
        sc.renameExistingSharedConfigDirectory();
        FileUtils.writeByteArrayToFile(zipFile, zipBytes);
        ZipUtils.unzip(zipFileName, sc.getSharedConfigurationDirPath());
        // load it from the disk
        sc.loadSharedConfigurationFromDisk();
        infoData.addLine(CliStrings.IMPORT_SHARED_CONFIG__SUCCESS__MSG);
    } catch (Exception e) {
        ErrorResultData errorData = ResultBuilder.createErrorResultData();
        errorData.addLine("Import failed");
        logSevere(e);
        result = ResultBuilder.buildResult(errorData);
        // if import is unsuccessful, don't need to bounce the server.
        return result;
    } finally {
        FileUtils.deleteQuietly(zipFile);
    }
    // Bounce the cache of each member
    Set<CliFunctionResult> functionResults = servers.stream().map(this::reCreateCache).collect(toSet());
    for (CliFunctionResult functionResult : functionResults) {
        if (functionResult.isSuccessful()) {
            infoData.addLine("Successfully applied the imported cluster configuration on " + functionResult.getMemberIdOrName());
        } else {
            infoData.addLine("Failed to apply the imported cluster configuration on " + functionResult.getMemberIdOrName() + " due to " + functionResult.getMessage());
        }
    }
    result = ResultBuilder.buildResult(infoData);
    return result;
}
Also used : InfoResultData(org.apache.geode.management.internal.cli.result.InfoResultData) Configuration(org.apache.geode.management.internal.configuration.domain.Configuration) InternalCache(org.apache.geode.internal.cache.InternalCache) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) GfshParseResult(org.apache.geode.management.internal.cli.GfshParseResult) Result(org.apache.geode.management.cli.Result) FileResult(org.apache.geode.management.internal.cli.result.FileResult) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) ClusterConfigurationService(org.apache.geode.distributed.internal.ClusterConfigurationService) DistributedMember(org.apache.geode.distributed.DistributedMember) ErrorResultData(org.apache.geode.management.internal.cli.result.ErrorResultData) File(java.io.File) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 10 with Configuration

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

the class ExportImportClusterConfigurationCommands method exportSharedConfig.

@CliCommand(value = { CliStrings.EXPORT_SHARED_CONFIG }, help = CliStrings.EXPORT_SHARED_CONFIG__HELP)
@CliMetaData(interceptor = "org.apache.geode.management.internal.cli.commands.ExportImportClusterConfigurationCommands$ExportInterceptor", relatedTopic = { CliStrings.TOPIC_GEODE_CONFIG })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result exportSharedConfig(@CliOption(key = { CliStrings.EXPORT_SHARED_CONFIG__FILE }, mandatory = true, help = CliStrings.EXPORT_SHARED_CONFIG__FILE__HELP) String zipFileName) {
    InternalLocator locator = InternalLocator.getLocator();
    if (!locator.isSharedConfigurationRunning()) {
        return ResultBuilder.createGemFireErrorResult(CliStrings.SHARED_CONFIGURATION_NOT_STARTED);
    }
    Path tempDir;
    try {
        tempDir = Files.createTempDirectory("clusterConfig");
    } catch (IOException e) {
        logSevere(e);
        ErrorResultData errorData = ResultBuilder.createErrorResultData().addLine("Unable to create temp directory");
        return ResultBuilder.buildResult(errorData);
    }
    File zipFile = tempDir.resolve("exportedCC.zip").toFile();
    ClusterConfigurationService sc = locator.getSharedConfiguration();
    Result result;
    try {
        for (Configuration config : sc.getEntireConfiguration().values()) {
            sc.writeConfigToFile(config);
        }
        ZipUtils.zipDirectory(sc.getSharedConfigurationDirPath(), zipFile.getCanonicalPath());
        InfoResultData infoData = ResultBuilder.createInfoResultData();
        byte[] byteData = FileUtils.readFileToByteArray(zipFile);
        infoData.addAsFile(zipFileName, byteData, InfoResultData.FILE_TYPE_BINARY, CliStrings.EXPORT_SHARED_CONFIG__DOWNLOAD__MSG, false);
        result = ResultBuilder.buildResult(infoData);
    } catch (Exception e) {
        ErrorResultData errorData = ResultBuilder.createErrorResultData();
        errorData.addLine("Export failed");
        logSevere(e);
        result = ResultBuilder.buildResult(errorData);
    } finally {
        zipFile.delete();
    }
    return result;
}
Also used : Path(java.nio.file.Path) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) ClusterConfigurationService(org.apache.geode.distributed.internal.ClusterConfigurationService) Configuration(org.apache.geode.management.internal.configuration.domain.Configuration) InfoResultData(org.apache.geode.management.internal.cli.result.InfoResultData) IOException(java.io.IOException) ErrorResultData(org.apache.geode.management.internal.cli.result.ErrorResultData) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) GfshParseResult(org.apache.geode.management.internal.cli.GfshParseResult) Result(org.apache.geode.management.cli.Result) FileResult(org.apache.geode.management.internal.cli.result.FileResult) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

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