Search in sources :

Example 1 with ProxyCache

use of org.apache.geode.cache.client.internal.ProxyCache in project geode by apache.

the class CQClientAuthDUnitTest method testPostProcess.

@Test
public void testPostProcess() {
    String query = "select * from /" + REGION_NAME;
    client1.invoke(() -> {
        Properties props = new Properties();
        props.setProperty(LOCATORS, "");
        props.setProperty(MCAST_PORT, "0");
        props.setProperty(SECURITY_CLIENT_AUTH_INIT, UserPasswordAuthInit.class.getName() + ".create");
        ClientCacheFactory factory = new ClientCacheFactory(props);
        factory.addPoolServer("localhost", server.getPort());
        factory.setPoolThreadLocalConnections(false);
        factory.setPoolMinConnections(5);
        factory.setPoolSubscriptionEnabled(true);
        factory.setPoolMultiuserAuthentication(true);
        ClientCache clientCache = factory.create();
        Region region = clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
        Pool pool = PoolManager.find(region);
        Properties userProps = new Properties();
        userProps.setProperty("security-username", "super-user");
        userProps.setProperty("security-password", "1234567");
        ProxyCache cache = (ProxyCache) clientCache.createAuthenticatedView(userProps, pool.getName());
        QueryService qs = cache.getQueryService();
        CqAttributesFactory cqAttributesFactory = new CqAttributesFactory();
        CqAttributes cqa = cqAttributesFactory.create();
        // Create the CqQuery
        CqQuery cq = qs.newCq("CQ1", query, cqa, true);
        cq.execute();
    });
}
Also used : QueryService(org.apache.geode.cache.query.QueryService) CqAttributes(org.apache.geode.cache.query.CqAttributes) ProxyCache(org.apache.geode.cache.client.internal.ProxyCache) Region(org.apache.geode.cache.Region) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) Pool(org.apache.geode.cache.client.Pool) ClientCache(org.apache.geode.cache.client.ClientCache) CqQuery(org.apache.geode.cache.query.CqQuery) Properties(java.util.Properties) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 2 with ProxyCache

use of org.apache.geode.cache.client.internal.ProxyCache in project geode by apache.

the class FunctionServiceManager method onRegion.

/**
   * Returns an {@link Execution} object that can be used to execute a data dependent function on
   * the specified Region.<br>
   * When invoked from a GemFire client, the method returns an Execution instance that sends a
   * message to one of the connected servers as specified by the {@link Pool} for the region. <br>
   * Depending on the filters setup on the {@link Execution}, the function is executed on all
   * GemFire members that define the data region, or a subset of members.
   * {@link Execution#withFilter(Set)}).
   * 
   * For DistributedRegions with DataPolicy.NORMAL, it throws UnsupportedOperationException. For
   * DistributedRegions with DataPolicy.EMPTY, execute the function on any random member which has
   * DataPolicy.REPLICATE <br>
   * . For DistributedRegions with DataPolicy.REPLICATE, execute the function locally. For Regions
   * with DataPolicy.PARTITION, it executes on members where the data resides as specified by the
   * filter.
   * 
   * @return Execution
   * @throws FunctionException if the region passed in is null
   * @since GemFire 6.0
   */
public Execution onRegion(Region region) {
    if (region == null) {
        throw new FunctionException(LocalizedStrings.FunctionService_0_PASSED_IS_NULL.toLocalizedString("Region instance "));
    }
    ProxyCache proxyCache = null;
    String poolName = region.getAttributes().getPoolName();
    if (poolName != null) {
        Pool pool = PoolManager.find(poolName);
        if (pool.getMultiuserAuthentication()) {
            if (region instanceof ProxyRegion) {
                ProxyRegion proxyRegion = (ProxyRegion) region;
                region = proxyRegion.getRealRegion();
                proxyCache = proxyRegion.getAuthenticatedCache();
            } else {
                throw new UnsupportedOperationException();
            }
        }
    }
    if (isClientRegion(region)) {
        return new ServerRegionFunctionExecutor(region, proxyCache);
    }
    if (PartitionRegionHelper.isPartitionedRegion(region)) {
        return new PartitionedRegionFunctionExecutor(region);
    }
    return new DistributedRegionFunctionExecutor(region);
}
Also used : PartitionedRegionFunctionExecutor(org.apache.geode.internal.cache.execute.PartitionedRegionFunctionExecutor) ProxyRegion(org.apache.geode.cache.client.internal.ProxyRegion) ProxyCache(org.apache.geode.cache.client.internal.ProxyCache) FunctionException(org.apache.geode.cache.execute.FunctionException) ServerRegionFunctionExecutor(org.apache.geode.internal.cache.execute.ServerRegionFunctionExecutor) Pool(org.apache.geode.cache.client.Pool) DistributedRegionFunctionExecutor(org.apache.geode.internal.cache.execute.DistributedRegionFunctionExecutor)

Example 3 with ProxyCache

use of org.apache.geode.cache.client.internal.ProxyCache in project geode by apache.

the class ClientCacheFactoryJUnitTest method test003DPmultiplePool.

/**
   * Make sure if we have more than one pool that we do not have a default
   */
@Test
public void test003DPmultiplePool() throws Exception {
    Properties dsProps = new Properties();
    dsProps.setProperty(MCAST_PORT, "0");
    DistributedSystem ds = DistributedSystem.connect(dsProps);
    PoolManager.createFactory().addServer(InetAddress.getLocalHost().getHostName(), 7777).create("p7");
    PoolManager.createFactory().addServer(InetAddress.getLocalHost().getHostName(), 6666).create("p6");
    this.cc = new ClientCacheFactory().create();
    GemFireCacheImpl gfc = (GemFireCacheImpl) this.cc;
    assertEquals(true, gfc.isClient());
    Pool defPool = gfc.getDefaultPool();
    assertEquals(null, defPool);
    // exists that is not multiuser enabled
    try {
        Properties suProps = new Properties();
        suProps.setProperty("user", "foo");
        RegionService cc = this.cc.createAuthenticatedView(suProps);
        fail("expected IllegalStateException");
    } catch (IllegalStateException ignore) {
    }
    // however we should be to to create it by configuring a pool
    {
        Properties suProps = new Properties();
        suProps.setProperty("user", "foo");
        Pool pool = PoolManager.createFactory().addServer(InetAddress.getLocalHost().getHostName(), CacheServer.DEFAULT_PORT).setMultiuserAuthentication(true).create("pool1");
        RegionService cc = this.cc.createAuthenticatedView(suProps, pool.getName());
        ProxyCache pc = (ProxyCache) cc;
        UserAttributes ua = pc.getUserAttributes();
        Pool proxyDefPool = ua.getPool();
        assertEquals(Collections.singletonList(new InetSocketAddress(InetAddress.getLocalHost(), CacheServer.DEFAULT_PORT)), proxyDefPool.getServers());
        assertEquals(true, proxyDefPool.getMultiuserAuthentication());
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ProxyCache(org.apache.geode.cache.client.internal.ProxyCache) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) RegionService(org.apache.geode.cache.RegionService) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) UserAttributes(org.apache.geode.cache.client.internal.UserAttributes) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 4 with ProxyCache

use of org.apache.geode.cache.client.internal.ProxyCache in project geode by apache.

the class ClientCacheFactoryJUnitTest method test002DPsinglePool.

/**
   * Make sure if we have a single pool that it will be used as the default
   */
@Test
public void test002DPsinglePool() throws Exception {
    Properties dsProps = new Properties();
    dsProps.setProperty(MCAST_PORT, "0");
    DistributedSystem ds = DistributedSystem.connect(dsProps);
    Pool p = PoolManager.createFactory().addServer(InetAddress.getLocalHost().getHostName(), 7777).create("singlePool");
    this.cc = new ClientCacheFactory().create();
    GemFireCacheImpl gfc = (GemFireCacheImpl) this.cc;
    assertEquals(true, gfc.isClient());
    Pool defPool = gfc.getDefaultPool();
    assertEquals(p, defPool);
    // exists that is not multiuser enabled
    try {
        Properties suProps = new Properties();
        suProps.setProperty("user", "foo");
        RegionService cc = this.cc.createAuthenticatedView(suProps);
        fail("expected IllegalStateException");
    } catch (IllegalStateException ignore) {
    }
    // however we should be to to create it by configuring a pool
    {
        Properties suProps = new Properties();
        suProps.setProperty("user", "foo");
        Pool pool = PoolManager.createFactory().addServer(InetAddress.getLocalHost().getHostName(), CacheServer.DEFAULT_PORT).setMultiuserAuthentication(true).create("pool1");
        RegionService cc = this.cc.createAuthenticatedView(suProps, pool.getName());
        ProxyCache pc = (ProxyCache) cc;
        UserAttributes ua = pc.getUserAttributes();
        Pool proxyDefPool = ua.getPool();
        assertEquals(Collections.singletonList(new InetSocketAddress(InetAddress.getLocalHost(), CacheServer.DEFAULT_PORT)), proxyDefPool.getServers());
        assertEquals(true, proxyDefPool.getMultiuserAuthentication());
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ProxyCache(org.apache.geode.cache.client.internal.ProxyCache) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) RegionService(org.apache.geode.cache.RegionService) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) UserAttributes(org.apache.geode.cache.client.internal.UserAttributes) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

ProxyCache (org.apache.geode.cache.client.internal.ProxyCache)4 Properties (java.util.Properties)3 Test (org.junit.Test)3 InetSocketAddress (java.net.InetSocketAddress)2 RegionService (org.apache.geode.cache.RegionService)2 Pool (org.apache.geode.cache.client.Pool)2 UserAttributes (org.apache.geode.cache.client.internal.UserAttributes)2 DistributedSystem (org.apache.geode.distributed.DistributedSystem)2 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)2 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)2 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)2 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2 Region (org.apache.geode.cache.Region)1 ClientCache (org.apache.geode.cache.client.ClientCache)1 ClientCacheFactory (org.apache.geode.cache.client.ClientCacheFactory)1 ProxyRegion (org.apache.geode.cache.client.internal.ProxyRegion)1 FunctionException (org.apache.geode.cache.execute.FunctionException)1 CqAttributes (org.apache.geode.cache.query.CqAttributes)1 CqAttributesFactory (org.apache.geode.cache.query.CqAttributesFactory)1 CqQuery (org.apache.geode.cache.query.CqQuery)1