Search in sources :

Example 61 with ServerContext

use of org.apache.accumulo.server.ServerContext in project accumulo by apache.

the class ZKAuthenticatorTest method testUserAuthentication.

@Test
public void testUserAuthentication() throws Exception {
    // testing the usecase when trying to authenticate with the new hash type
    String principal = "myTestUser";
    byte[] rawPass = "myPassword".getBytes(UTF_8);
    // creating hash with up to date algorithm
    byte[] newHash = ZKSecurityTool.createPass(rawPass.clone());
    // mocking zk interaction
    ServerContext context = MockServerContext.getWithZK(InstanceId.of("example"), "", 30_000);
    ZooReaderWriter zr = createMock(ZooReaderWriter.class);
    expect(context.getZooReaderWriter()).andReturn(zr).anyTimes();
    ZooKeeper zk = createMock(ZooKeeper.class);
    expect(zk.getChildren(EasyMock.anyObject(), EasyMock.anyObject())).andReturn(Arrays.asList(principal)).anyTimes();
    expect(zk.exists(EasyMock.matches("/accumulo/example/users/" + principal), EasyMock.anyObject(Watcher.class))).andReturn(new Stat()).anyTimes();
    expect(zr.getZooKeeper()).andReturn(zk).anyTimes();
    expect(zk.getData(EasyMock.matches("/accumulo/example/users/" + principal), EasyMock.anyObject(), EasyMock.anyObject())).andReturn(newHash).once();
    replay(context, zr, zk);
    // creating authenticator
    ZKAuthenticator auth = new ZKAuthenticator();
    auth.initialize(context);
    PasswordToken token = new PasswordToken(rawPass.clone());
    // verifying that if the new type of hash is stored in zk authentication works as expected
    assertTrue(auth.authenticateUser(principal, token));
    verify(context, zr, zk);
}
Also used : PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) ZooKeeper(org.apache.zookeeper.ZooKeeper) Stat(org.apache.zookeeper.data.Stat) MockServerContext(org.apache.accumulo.server.MockServerContext) ServerContext(org.apache.accumulo.server.ServerContext) ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) Test(org.junit.Test)

Example 62 with ServerContext

use of org.apache.accumulo.server.ServerContext in project accumulo by apache.

the class BaseHostRegexTableLoadBalancerTest method createMockContext.

protected ServerContext createMockContext() {
    ServerContext mockContext = EasyMock.createMock(ServerContext.class);
    expect(mockContext.getProperties()).andReturn(new Properties()).anyTimes();
    expect(mockContext.getZooKeepers()).andReturn("").anyTimes();
    expect(mockContext.getInstanceName()).andReturn("test").anyTimes();
    expect(mockContext.getZooKeepersSessionTimeOut()).andReturn(30).anyTimes();
    expect(mockContext.getInstanceID()).andReturn(InstanceId.of("1111")).anyTimes();
    expect(mockContext.getZooKeeperRoot()).andReturn(Constants.ZROOT + "/1111").anyTimes();
    return mockContext;
}
Also used : ServerContext(org.apache.accumulo.server.ServerContext) Properties(java.util.Properties)

Example 63 with ServerContext

use of org.apache.accumulo.server.ServerContext in project accumulo by apache.

the class HostRegexTableLoadBalancerTest method testSplitCurrentByRegexUsingOverlappingPools.

@Test
public void testSplitCurrentByRegexUsingOverlappingPools() {
    ServerContext context = createMockContext();
    replay(context);
    initFactory(new TestServerConfigurationFactory(context) {

        @Override
        public synchronized AccumuloConfiguration getSystemConfiguration() {
            HashMap<String, String> props = new HashMap<>(DEFAULT_TABLE_PROPERTIES);
            props.put(HostRegexTableLoadBalancer.HOST_BALANCER_PREFIX + FOO.getTableName(), "r.*");
            props.put(HostRegexTableLoadBalancer.HOST_BALANCER_PREFIX + BAR.getTableName(), "r01.*|r02.*");
            return new ConfigurationCopy(props);
        }
    });
    Map<String, SortedMap<TServerInstance, TabletServerStatus>> groups = this.splitCurrentByRegex(createCurrent(15));
    // Groups foo, bar, and the default pool which contains all known hosts
    assertEquals(3, groups.size());
    assertTrue(groups.containsKey(FOO.getTableName()));
    assertTrue(groups.containsKey(DEFAULT_POOL));
    for (String pool : new String[] { FOO.getTableName(), DEFAULT_POOL }) {
        SortedMap<TServerInstance, TabletServerStatus> fooHosts = groups.get(pool);
        assertEquals(15, fooHosts.size());
        assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.1:9997", 1)));
        assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.2:9997", 1)));
        assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.3:9997", 1)));
        assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.4:9997", 1)));
        assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.5:9997", 1)));
        assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.6:9997", 1)));
        assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.7:9997", 1)));
        assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.8:9997", 1)));
        assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.9:9997", 1)));
        assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.10:9997", 1)));
        assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.11:9997", 1)));
        assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.12:9997", 1)));
        assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.13:9997", 1)));
        assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.14:9997", 1)));
        assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.15:9997", 1)));
    }
    assertTrue(groups.containsKey(BAR.getTableName()));
    SortedMap<TServerInstance, TabletServerStatus> barHosts = groups.get(BAR.getTableName());
    assertEquals(10, barHosts.size());
    assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.1:9997", 1)));
    assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.2:9997", 1)));
    assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.3:9997", 1)));
    assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.4:9997", 1)));
    assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.5:9997", 1)));
    assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.6:9997", 1)));
    assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.7:9997", 1)));
    assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.8:9997", 1)));
    assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.9:9997", 1)));
    assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.10:9997", 1)));
}
Also used : ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) HashMap(java.util.HashMap) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) ServerContext(org.apache.accumulo.server.ServerContext) SortedMap(java.util.SortedMap) TabletServerStatus(org.apache.accumulo.core.master.thrift.TabletServerStatus) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) Test(org.junit.Test)

Example 64 with ServerContext

use of org.apache.accumulo.server.ServerContext in project accumulo by apache.

the class HostRegexTableLoadBalancerTest method initFactory.

private void initFactory(ServerConfigurationFactory factory) {
    ServerContext context = createMockContext();
    expect(context.getConfiguration()).andReturn(factory.getSystemConfiguration()).anyTimes();
    expect(context.getTableConfiguration(FOO.getId())).andReturn(factory.getTableConfiguration(FOO.getId())).anyTimes();
    expect(context.getTableConfiguration(BAR.getId())).andReturn(factory.getTableConfiguration(BAR.getId())).anyTimes();
    expect(context.getTableConfiguration(BAZ.getId())).andReturn(factory.getTableConfiguration(BAZ.getId())).anyTimes();
    replay(context);
    init(context);
}
Also used : ServerContext(org.apache.accumulo.server.ServerContext)

Example 65 with ServerContext

use of org.apache.accumulo.server.ServerContext in project accumulo by apache.

the class HostRegexTableLoadBalancerTest method testSplitCurrentByRegexUsingIP.

@Test
public void testSplitCurrentByRegexUsingIP() {
    ServerContext context = createMockContext();
    replay(context);
    initFactory(new TestServerConfigurationFactory(context) {

        @Override
        public synchronized AccumuloConfiguration getSystemConfiguration() {
            HashMap<String, String> props = new HashMap<>();
            props.put(HostRegexTableLoadBalancer.HOST_BALANCER_OOB_CHECK_KEY, "30s");
            props.put(HostRegexTableLoadBalancer.HOST_BALANCER_REGEX_USING_IPS_KEY, "true");
            props.put(HostRegexTableLoadBalancer.HOST_BALANCER_PREFIX + FOO.getTableName(), "192\\.168\\.0\\.[1-5]");
            props.put(HostRegexTableLoadBalancer.HOST_BALANCER_PREFIX + BAR.getTableName(), "192\\.168\\.0\\.[6-9]|192\\.168\\.0\\.10");
            return new ConfigurationCopy(props);
        }
    });
    assertTrue(isIpBasedRegex());
    Map<String, SortedMap<TServerInstance, TabletServerStatus>> groups = this.splitCurrentByRegex(createCurrent(15));
    assertEquals(3, groups.size());
    assertTrue(groups.containsKey(FOO.getTableName()));
    SortedMap<TServerInstance, TabletServerStatus> fooHosts = groups.get(FOO.getTableName());
    assertEquals(5, fooHosts.size());
    assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.1:9997", 1)));
    assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.2:9997", 1)));
    assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.3:9997", 1)));
    assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.4:9997", 1)));
    assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.5:9997", 1)));
    assertTrue(groups.containsKey(BAR.getTableName()));
    SortedMap<TServerInstance, TabletServerStatus> barHosts = groups.get(BAR.getTableName());
    assertEquals(5, barHosts.size());
    assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.6:9997", 1)));
    assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.7:9997", 1)));
    assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.8:9997", 1)));
    assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.9:9997", 1)));
    assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.10:9997", 1)));
    assertTrue(groups.containsKey(DEFAULT_POOL));
    SortedMap<TServerInstance, TabletServerStatus> defHosts = groups.get(DEFAULT_POOL);
    assertEquals(5, defHosts.size());
    assertTrue(defHosts.containsKey(new TServerInstance("192.168.0.11:9997", 1)));
    assertTrue(defHosts.containsKey(new TServerInstance("192.168.0.12:9997", 1)));
    assertTrue(defHosts.containsKey(new TServerInstance("192.168.0.13:9997", 1)));
    assertTrue(defHosts.containsKey(new TServerInstance("192.168.0.14:9997", 1)));
    assertTrue(defHosts.containsKey(new TServerInstance("192.168.0.15:9997", 1)));
}
Also used : ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) HashMap(java.util.HashMap) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) ServerContext(org.apache.accumulo.server.ServerContext) SortedMap(java.util.SortedMap) TabletServerStatus(org.apache.accumulo.core.master.thrift.TabletServerStatus) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) Test(org.junit.Test)

Aggregations

ServerContext (org.apache.accumulo.server.ServerContext)87 Test (org.junit.Test)41 ZooReaderWriter (org.apache.accumulo.fate.zookeeper.ZooReaderWriter)18 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)15 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)15 TServerInstance (org.apache.accumulo.core.metadata.TServerInstance)15 HostAndPort (org.apache.accumulo.core.util.HostAndPort)15 Path (org.apache.hadoop.fs.Path)15 ArrayList (java.util.ArrayList)14 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)14 VolumeManager (org.apache.accumulo.server.fs.VolumeManager)13 KeeperException (org.apache.zookeeper.KeeperException)13 ServerAddress (org.apache.accumulo.server.rpc.ServerAddress)12 TableId (org.apache.accumulo.core.data.TableId)11 LiveTServerSet (org.apache.accumulo.server.manager.LiveTServerSet)11 Value (org.apache.accumulo.core.data.Value)10 IOException (java.io.IOException)9 UUID (java.util.UUID)9 ConfigurationCopy (org.apache.accumulo.core.conf.ConfigurationCopy)9 Client (org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Client)9