Search in sources :

Example 41 with DistributionManager

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

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

the class DistributedSystemDUnitTest method testSpecificTcpPort.

/**
   * test the ability to set the port used to listen for tcp/ip connections
   */
@Test
public void testSpecificTcpPort() throws Exception {
    Properties config = new Properties();
    config.put(LOCATORS, "localhost[" + getDUnitLocatorPort() + "]");
    config.setProperty(TCP_PORT, String.valueOf(this.tcpPort));
    InternalDistributedSystem system = getSystem(config);
    DistributionManager dm = (DistributionManager) system.getDistributionManager();
    GMSMembershipManager mgr = (GMSMembershipManager) dm.getMembershipManager();
    assertThat(mgr.getDirectChannelPort()).isEqualTo(this.tcpPort);
}
Also used : GMSMembershipManager(org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 43 with DistributionManager

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

the class DistributedSystemDUnitTest method testUDPPortRange.

@Test
public void testUDPPortRange() throws Exception {
    Properties config = new Properties();
    config.put(LOCATORS, "localhost[" + getDUnitLocatorPort() + "]");
    config.setProperty(MEMBERSHIP_PORT_RANGE, this.lowerBoundOfPortRange + "-" + this.upperBoundOfPortRange);
    InternalDistributedSystem system = getSystem(config);
    DistributionManager dm = (DistributionManager) system.getDistributionManager();
    InternalDistributedMember member = dm.getDistributionManagerId();
    verifyMembershipPortsInRange(member, this.lowerBoundOfPortRange, this.upperBoundOfPortRange);
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 44 with DistributionManager

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

the class DistributedLockServiceDUnitTest method testDestroyLockServiceAfterGrantResponse.

@Test
public void testDestroyLockServiceAfterGrantResponse() throws Throwable {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    final String serviceName = getUniqueName();
    vm0.invoke(new SerializableRunnable("Create the grantor") {

        public void run() {
            connectDistributedSystem();
            final DistributedLockService service = DistributedLockService.create(serviceName, dlstSystem);
            // lock and unlock to make sure this vm is grantor
            assertTrue(service.lock("obj", -1, -1));
            service.unlock("obj");
        }
    });
    DistributionMessageObserver.setInstance(new DistributionMessageObserver() {

        @Override
        public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
            if (message instanceof DLockResponseMessage) {
                DistributedLockService.destroy(serviceName);
            }
        }
    });
    connectDistributedSystem();
    final DistributedLockService service = DistributedLockService.create(serviceName, dlstSystem);
    try {
        service.lock("obj", -1, -1);
        fail("The lock service should have been destroyed");
    } catch (LockServiceDestroyedException expected) {
    // Do nothing
    }
    vm0.invoke(new SerializableRunnable("check to make sure the lock is not orphaned") {

        public void run() {
            final DistributedLockService service = DistributedLockService.getServiceNamed(serviceName);
            // lock and unlock to make sure this vm is grantor
            assertTrue(service.lock("obj", -1, -1));
            service.unlock("obj");
        }
    });
}
Also used : DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) DLockResponseMessage(org.apache.geode.distributed.internal.locks.DLockRequestProcessor.DLockResponseMessage) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) DLockTest(org.apache.geode.test.junit.categories.DLockTest)

Example 45 with DistributionManager

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

the class AbstractExecution method executeFunctionOnLocalNode.

// Bug41118 : in case of lonerDistribuedSystem do local execution through
// main thread otherwise give execution to FunctionExecutor from
// DistributionManager
public void executeFunctionOnLocalNode(final Function fn, final FunctionContext cx, final ResultSender sender, DM dm, final boolean isTx) {
    if (dm instanceof DistributionManager && !isTx) {
        final DistributionManager newDM = (DistributionManager) dm;
        newDM.getFunctionExcecutor().execute(new Runnable() {

            public void run() {
                executeFunctionLocally(fn, cx, sender, newDM);
                if (!((InternalResultSender) sender).isLastResultReceived() && fn.hasResult()) {
                    ((InternalResultSender) sender).setException(new FunctionException(LocalizedStrings.ExecuteFunction_THE_FUNCTION_0_DID_NOT_SENT_LAST_RESULT.toString(fn.getId())));
                }
            }
        });
    } else {
        executeFunctionLocally(fn, cx, sender, dm);
        if (!((InternalResultSender) sender).isLastResultReceived() && fn.hasResult()) {
            ((InternalResultSender) sender).setException(new FunctionException(LocalizedStrings.ExecuteFunction_THE_FUNCTION_0_DID_NOT_SENT_LAST_RESULT.toString(fn.getId())));
        }
    }
}
Also used : FunctionException(org.apache.geode.cache.execute.FunctionException) DistributionManager(org.apache.geode.distributed.internal.DistributionManager)

Aggregations

DistributionManager (org.apache.geode.distributed.internal.DistributionManager)60 Test (org.junit.Test)44 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)36 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)29 DistributionMessageObserver (org.apache.geode.distributed.internal.DistributionMessageObserver)29 VM (org.apache.geode.test.dunit.VM)29 Host (org.apache.geode.test.dunit.Host)28 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)25 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)15 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)12 Cache (org.apache.geode.cache.Cache)11 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)11 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)11 IOException (java.io.IOException)9 IgnoredException (org.apache.geode.test.dunit.IgnoredException)9 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)9 Properties (java.util.Properties)8 UnitTest (org.apache.geode.test.junit.categories.UnitTest)8 RequestImageMessage (org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage)7 Region (org.apache.geode.cache.Region)6