Search in sources :

Example 11 with ClientContext

use of org.apache.accumulo.core.client.impl.ClientContext in project accumulo by apache.

the class MasterRepairsDualAssignmentIT method test.

@Test
public void test() throws Exception {
    // make some tablets, spread 'em around
    Connector c = getConnector();
    ClientContext context = new ClientContext(c.getInstance(), new Credentials("root", new PasswordToken(ROOT_PASSWORD)), getClientConfig());
    String table = this.getUniqueNames(1)[0];
    c.securityOperations().grantTablePermission("root", MetadataTable.NAME, TablePermission.WRITE);
    c.securityOperations().grantTablePermission("root", RootTable.NAME, TablePermission.WRITE);
    c.tableOperations().create(table);
    SortedSet<Text> partitions = new TreeSet<>();
    for (String part : "a b c d e f g h i j k l m n o p q r s t u v w x y z".split(" ")) {
        partitions.add(new Text(part));
    }
    c.tableOperations().addSplits(table, partitions);
    // scan the metadata table and get the two table location states
    Set<TServerInstance> states = new HashSet<>();
    Set<TabletLocationState> oldLocations = new HashSet<>();
    MetaDataStateStore store = new MetaDataStateStore(context, null);
    while (states.size() < 2) {
        UtilWaitThread.sleep(250);
        oldLocations.clear();
        for (TabletLocationState tls : store) {
            if (tls.current != null) {
                states.add(tls.current);
                oldLocations.add(tls);
            }
        }
    }
    assertEquals(2, states.size());
    // Kill a tablet server... we don't care which one... wait for everything to be reassigned
    cluster.killProcess(ServerType.TABLET_SERVER, cluster.getProcesses().get(ServerType.TABLET_SERVER).iterator().next());
    Set<TServerInstance> replStates = new HashSet<>();
    // Find out which tablet server remains
    while (true) {
        UtilWaitThread.sleep(1000);
        states.clear();
        replStates.clear();
        boolean allAssigned = true;
        for (TabletLocationState tls : store) {
            if (tls != null && tls.current != null) {
                states.add(tls.current);
            } else if (tls != null && tls.extent.equals(new KeyExtent(ReplicationTable.ID, null, null))) {
                replStates.add(tls.current);
            } else {
                allAssigned = false;
            }
        }
        System.out.println(states + " size " + states.size() + " allAssigned " + allAssigned);
        if (states.size() != 2 && allAssigned)
            break;
    }
    assertEquals(1, replStates.size());
    assertEquals(1, states.size());
    // pick an assigned tablet and assign it to the old tablet
    TabletLocationState moved = null;
    for (TabletLocationState old : oldLocations) {
        if (!states.contains(old.current)) {
            moved = old;
        }
    }
    assertNotEquals(null, moved);
    // throw a mutation in as if we were the dying tablet
    BatchWriter bw = c.createBatchWriter(MetadataTable.NAME, new BatchWriterConfig());
    Mutation assignment = new Mutation(moved.extent.getMetadataEntry());
    moved.current.putLocation(assignment);
    bw.addMutation(assignment);
    bw.close();
    // wait for the master to fix the problem
    waitForCleanStore(store);
    // now jam up the metadata table
    bw = c.createBatchWriter(MetadataTable.NAME, new BatchWriterConfig());
    assignment = new Mutation(new KeyExtent(MetadataTable.ID, null, null).getMetadataEntry());
    moved.current.putLocation(assignment);
    bw.addMutation(assignment);
    bw.close();
    waitForCleanStore(new RootTabletStateStore(context, null));
}
Also used : Connector(org.apache.accumulo.core.client.Connector) ClientContext(org.apache.accumulo.core.client.impl.ClientContext) Text(org.apache.hadoop.io.Text) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance) MetaDataStateStore(org.apache.accumulo.server.master.state.MetaDataStateStore) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) TreeSet(java.util.TreeSet) RootTabletStateStore(org.apache.accumulo.server.master.state.RootTabletStateStore) TabletLocationState(org.apache.accumulo.server.master.state.TabletLocationState) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Credentials(org.apache.accumulo.core.client.impl.Credentials) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with ClientContext

use of org.apache.accumulo.core.client.impl.ClientContext in project accumulo by apache.

the class MetaConstraintRetryIT method test.

// a test for ACCUMULO-3096
@Test(expected = ConstraintViolationException.class)
public void test() throws Exception {
    getConnector().securityOperations().grantTablePermission(getAdminPrincipal(), MetadataTable.NAME, TablePermission.WRITE);
    Credentials credentials = new Credentials(getAdminPrincipal(), getAdminToken());
    ClientContext context = new ClientContext(getConnector().getInstance(), credentials, cluster.getClientConfig());
    Writer w = new Writer(context, MetadataTable.ID);
    KeyExtent extent = new KeyExtent(Table.ID.of("5"), null, null);
    Mutation m = new Mutation(extent.getMetadataEntry());
    // unknown columns should cause contraint violation
    m.put("badcolfam", "badcolqual", "3");
    try {
        MetadataTableUtil.update(w, null, m);
    } catch (RuntimeException e) {
        if (e.getCause().getClass().equals(ConstraintViolationException.class)) {
            throw (ConstraintViolationException) e.getCause();
        }
    }
}
Also used : ClientContext(org.apache.accumulo.core.client.impl.ClientContext) ConstraintViolationException(org.apache.accumulo.core.tabletserver.thrift.ConstraintViolationException) Mutation(org.apache.accumulo.core.data.Mutation) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) Credentials(org.apache.accumulo.core.client.impl.Credentials) Writer(org.apache.accumulo.core.client.impl.Writer) Test(org.junit.Test)

Example 13 with ClientContext

use of org.apache.accumulo.core.client.impl.ClientContext in project accumulo by apache.

the class ReplicationTableUtilTest method properPathInRow.

@Test
public void properPathInRow() throws Exception {
    Writer writer = EasyMock.createNiceMock(Writer.class);
    writer.update(EasyMock.anyObject(Mutation.class));
    final List<Mutation> mutations = new ArrayList<>();
    // Mock a Writer to just add the mutation to a list
    EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {

        @Override
        public Object answer() {
            mutations.add(((Mutation) EasyMock.getCurrentArguments()[0]));
            return null;
        }
    });
    EasyMock.replay(writer);
    Credentials creds = new Credentials("root", new PasswordToken(""));
    ClientContext context = EasyMock.createMock(ClientContext.class);
    EasyMock.expect(context.getCredentials()).andReturn(creds).anyTimes();
    EasyMock.replay(context);
    // Magic hook to create a Writer
    ReplicationTableUtil.addWriter(creds, writer);
    // Example file seen coming out of LogEntry
    UUID uuid = UUID.randomUUID();
    String myFile = "file:////home/user/accumulo/wal/server+port/" + uuid;
    long createdTime = System.currentTimeMillis();
    ReplicationTableUtil.updateFiles(context, new KeyExtent(Table.ID.of("1"), null, null), myFile, StatusUtil.fileCreated(createdTime));
    verify(writer);
    Assert.assertEquals(1, mutations.size());
    Mutation m = mutations.get(0);
    Assert.assertEquals(MetadataSchema.ReplicationSection.getRowPrefix() + "file:/home/user/accumulo/wal/server+port/" + uuid, new Text(m.getRow()).toString());
    List<ColumnUpdate> updates = m.getUpdates();
    Assert.assertEquals(1, updates.size());
    ColumnUpdate update = updates.get(0);
    Assert.assertEquals(MetadataSchema.ReplicationSection.COLF, new Text(update.getColumnFamily()));
    Assert.assertEquals("1", new Text(update.getColumnQualifier()).toString());
    Assert.assertEquals(StatusUtil.fileCreatedValue(createdTime), new Value(update.getValue()));
}
Also used : ColumnUpdate(org.apache.accumulo.core.data.ColumnUpdate) ClientContext(org.apache.accumulo.core.client.impl.ClientContext) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) Value(org.apache.accumulo.core.data.Value) Mutation(org.apache.accumulo.core.data.Mutation) UUID(java.util.UUID) Writer(org.apache.accumulo.core.client.impl.Writer) Credentials(org.apache.accumulo.core.client.impl.Credentials) Test(org.junit.Test)

Example 14 with ClientContext

use of org.apache.accumulo.core.client.impl.ClientContext in project accumulo by apache.

the class AccumuloReplicaSystem method getContextForPeer.

protected ClientContext getContextForPeer(AccumuloConfiguration localConf, ReplicationTarget target, String principal, AuthenticationToken token) {
    requireNonNull(localConf);
    requireNonNull(target);
    requireNonNull(principal);
    requireNonNull(token);
    return new ClientContext(getPeerInstance(target), new Credentials(principal, token), localConf);
}
Also used : ClientContext(org.apache.accumulo.core.client.impl.ClientContext) TCredentials(org.apache.accumulo.core.security.thrift.TCredentials) Credentials(org.apache.accumulo.core.client.impl.Credentials)

Example 15 with ClientContext

use of org.apache.accumulo.core.client.impl.ClientContext in project accumulo by apache.

the class ReplicationProcessorTest method noPeerConfigurationThrowsAnException.

@Test(expected = IllegalArgumentException.class)
public void noPeerConfigurationThrowsAnException() {
    Instance inst = EasyMock.createMock(Instance.class);
    VolumeManager fs = EasyMock.createMock(VolumeManager.class);
    Credentials creds = new Credentials("foo", new PasswordToken("bar"));
    ClientContext context = new ClientContext(inst, creds, ClientConfiguration.create());
    Map<String, String> data = new HashMap<>();
    ConfigurationCopy conf = new ConfigurationCopy(data);
    ReplicationProcessor proc = new ReplicationProcessor(context, conf, fs);
    proc.getPeerType("foo");
}
Also used : VolumeManager(org.apache.accumulo.server.fs.VolumeManager) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) Instance(org.apache.accumulo.core.client.Instance) HashMap(java.util.HashMap) ClientContext(org.apache.accumulo.core.client.impl.ClientContext) Credentials(org.apache.accumulo.core.client.impl.Credentials) Test(org.junit.Test)

Aggregations

ClientContext (org.apache.accumulo.core.client.impl.ClientContext)31 Credentials (org.apache.accumulo.core.client.impl.Credentials)26 Instance (org.apache.accumulo.core.client.Instance)14 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)14 Test (org.junit.Test)12 KeyExtent (org.apache.accumulo.core.data.impl.KeyExtent)10 ArrayList (java.util.ArrayList)9 Connector (org.apache.accumulo.core.client.Connector)9 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)8 Text (org.apache.hadoop.io.Text)8 AccumuloException (org.apache.accumulo.core.client.AccumuloException)7 ThriftNotActiveServiceException (org.apache.accumulo.core.client.impl.thrift.ThriftNotActiveServiceException)7 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 MasterClientService (org.apache.accumulo.core.master.thrift.MasterClientService)6 List (java.util.List)5 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)5 Mutation (org.apache.accumulo.core.data.Mutation)5 MasterMonitorInfo (org.apache.accumulo.core.master.thrift.MasterMonitorInfo)5 TableInfo (org.apache.accumulo.core.master.thrift.TableInfo)5