Search in sources :

Example 1 with InternalLocator

use of org.apache.geode.distributed.internal.InternalLocator in project geode by apache.

the class DistributionLocator method main.

public static void main(String[] args) {
    if (args.length == 0 || args.length > 6) {
        System.err.println(LocalizedStrings.DistributionLocator_USAGE.toLocalizedString() + ": port [bind-address] [peerLocator] [serverLocator] [hostname-for-clients]");
        System.err.println(LocalizedStrings.DistributionLocator_A_ZEROLENGTH_ADDRESS_WILL_BIND_TO_LOCALHOST.toLocalizedString());
        System.err.println(LocalizedStrings.DistributionLocator_A_ZEROLENGTH_GEMFIREPROPERTIESFILE_WILL_MEAN_USE_THE_DEFAULT_SEARCH_PATH.toLocalizedString());
        System.err.println(LocalizedStrings.DistributionLocator_PEERLOCATOR_AND_SERVERLOCATOR_BOTH_DEFAULT_TO_TRUE.toLocalizedString());
        System.err.println(LocalizedStrings.DistributionLocator_A_ZEROLENGTH_HOSTNAMEFORCLIENTS_WILL_DEFAULT_TO_BINDADDRESS.toLocalizedString());
        System.exit(1);
    } else {
        shutdown = false;
    }
    SystemFailure.loadEmergencyClasses();
    // log.info(Banner.getString(args));
    final int port = parsePort(args[0]);
    InetAddress address = null;
    boolean peerLocator = true;
    boolean serverLocator = true;
    String hostnameForClients = null;
    try {
        if (args.length > 1 && !args[1].equals("")) {
            if (!SystemAdmin.validLocalAddress(args[1])) {
                System.err.println(LocalizedStrings.DistributionLocator__0_IS_NOT_A_VALID_IP_ADDRESS_FOR_THIS_MACHINE.toLocalizedString(args[1]));
                System.exit(1);
            }
            address = InetAddress.getByName(args[1]);
        } else {
        // address = null; // was InetAddress.getLocalHost(); (redundant assignment)
        }
        if (args.length > 2) {
            peerLocator = "true".equalsIgnoreCase(args[2]);
        }
        if (args.length > 3) {
            serverLocator = "true".equalsIgnoreCase(args[3]);
        }
        if (args.length > 4) {
            hostnameForClients = args[4];
        }
        if (!Boolean.getBoolean(InternalDistributedSystem.DISABLE_SHUTDOWN_HOOK_PROPERTY)) {
            final InetAddress faddress = address;
            Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

                public void run() {
                    try {
                        DistributionLocator.shutdown(port, faddress);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }));
        }
        lockFile = ManagerInfo.setLocatorStarting(directory, port, address);
        lockFile.deleteOnExit();
        try {
            InternalLocator locator = InternalLocator.startLocator(port, new File(DEFAULT_LOG_FILE), null, null, null, address, true, (Properties) null, hostnameForClients);
            ManagerInfo.setLocatorStarted(directory, port, address);
            locator.waitToStop();
        } finally {
            shutdown(port, address);
        }
    } catch (InterruptedException ex) {
    // We were interrupted while waiting for the locator to stop.
    // No big deal.
    } catch (java.net.BindException ex) {
        logger.fatal(LocalizedMessage.create(LocalizedStrings.DistributionLocator_COULD_NOT_BIND_LOCATOR_TO__0__1, new Object[] { address, Integer.valueOf(port) }));
        System.exit(1);
    } catch (Exception ex) {
        logger.fatal(LocalizedMessage.create(LocalizedStrings.DistributionLocator_COULD_NOT_START_LOCATOR), ex);
        System.exit(1);
    }
}
Also used : IOException(java.io.IOException) IOException(java.io.IOException) ConnectException(java.net.ConnectException) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) InetAddress(java.net.InetAddress) File(java.io.File)

Example 2 with InternalLocator

use of org.apache.geode.distributed.internal.InternalLocator in project geode by apache.

the class Services method start.

protected void start() {
    boolean started = false;
    try {
        logger.info("Starting membership services");
        logger.debug("starting Authenticator");
        this.auth.start();
        logger.debug("starting Messenger");
        this.messenger.start();
        logger.debug("starting JoinLeave");
        this.joinLeave.start();
        logger.debug("starting HealthMonitor");
        this.healthMon.start();
        logger.debug("starting Manager");
        this.manager.start();
        started = true;
    } catch (RuntimeException e) {
        logger.fatal("Unexpected exception while booting membership services", e);
        throw e;
    } finally {
        if (!started) {
            this.manager.stop();
            this.healthMon.stop();
            this.joinLeave.stop();
            this.messenger.stop();
            this.auth.stop();
            this.timer.cancel();
        }
    }
    this.auth.started();
    this.messenger.started();
    this.joinLeave.started();
    this.healthMon.started();
    this.manager.started();
    InternalLocator l = (InternalLocator) org.apache.geode.distributed.Locator.getLocator();
    if (l != null && l.getLocatorHandler() != null) {
        if (l.getLocatorHandler().setMembershipManager((MembershipManager) this.manager)) {
            this.locator = (Locator) l.getLocatorHandler();
        }
    }
    logger.debug("All membership services have been started");
    try {
        this.manager.joinDistributedSystem();
    } catch (Throwable e) {
        stop();
        throw e;
    }
}
Also used : InternalLocator(org.apache.geode.distributed.internal.InternalLocator)

Example 3 with InternalLocator

use of org.apache.geode.distributed.internal.InternalLocator 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 4 with InternalLocator

use of org.apache.geode.distributed.internal.InternalLocator 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)

Example 5 with InternalLocator

use of org.apache.geode.distributed.internal.InternalLocator in project geode by apache.

the class LocatorLoadBalancingDUnitTest method checkLocatorLoad.

public void checkLocatorLoad(final Map expected) {
    List locators = Locator.getLocators();
    Assert.assertEquals(1, locators.size());
    InternalLocator locator = (InternalLocator) locators.get(0);
    final ServerLocator sl = locator.getServerLocatorAdvisee();
    InternalLogWriter log = new LocalLogWriter(InternalLogWriter.FINEST_LEVEL, System.out);
    sl.getDistributionAdvisor().dumpProfiles("PROFILES= ");
    Awaitility.await().pollDelay(100, TimeUnit.MILLISECONDS).pollInterval(100, TimeUnit.MILLISECONDS).timeout(300, TimeUnit.SECONDS).until(() -> expected.equals(sl.getLoadMap()));
}
Also used : InternalLocator(org.apache.geode.distributed.internal.InternalLocator) InternalLogWriter(org.apache.geode.internal.logging.InternalLogWriter) List(java.util.List) LocalLogWriter(org.apache.geode.internal.logging.LocalLogWriter) ServerLocator(org.apache.geode.distributed.internal.ServerLocator)

Aggregations

InternalLocator (org.apache.geode.distributed.internal.InternalLocator)41 File (java.io.File)21 IOException (java.io.IOException)18 Properties (java.util.Properties)18 Test (org.junit.Test)17 VM (org.apache.geode.test.dunit.VM)16 ClusterConfigurationService (org.apache.geode.distributed.internal.ClusterConfigurationService)15 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)15 Cache (org.apache.geode.cache.Cache)9 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)9 UnknownHostException (java.net.UnknownHostException)8 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)8 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)8 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)7 Locator (org.apache.geode.distributed.Locator)6 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)6 CommandStringBuilder (org.apache.geode.management.internal.cli.util.CommandStringBuilder)6 List (java.util.List)5 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)5 Set (java.util.Set)4