Search in sources :

Example 1 with Writer

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

the class MetadataTableUtil method getMetadataTable.

public static synchronized Writer getMetadataTable(ClientContext context) {
    Credentials credentials = context.getCredentials();
    Writer metadataTable = metadata_tables.get(credentials);
    if (metadataTable == null) {
        metadataTable = new Writer(context, MetadataTable.ID);
        metadata_tables.put(credentials, metadataTable);
    }
    return metadataTable;
}
Also used : Credentials(org.apache.accumulo.core.client.impl.Credentials) ZooReaderWriter(org.apache.accumulo.server.zookeeper.ZooReaderWriter) Writer(org.apache.accumulo.core.client.impl.Writer) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) BatchWriter(org.apache.accumulo.core.client.BatchWriter)

Example 2 with Writer

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

the class MetadataTableUtil method getRootTable.

public static synchronized Writer getRootTable(ClientContext context) {
    Credentials credentials = context.getCredentials();
    Writer rootTable = root_tables.get(credentials);
    if (rootTable == null) {
        rootTable = new Writer(context, RootTable.ID);
        root_tables.put(credentials, rootTable);
    }
    return rootTable;
}
Also used : Credentials(org.apache.accumulo.core.client.impl.Credentials) ZooReaderWriter(org.apache.accumulo.server.zookeeper.ZooReaderWriter) Writer(org.apache.accumulo.core.client.impl.Writer) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) BatchWriter(org.apache.accumulo.core.client.BatchWriter)

Example 3 with Writer

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

the class ReplicationTableUtil method getWriter.

static synchronized Writer getWriter(ClientContext context) {
    Writer replicationTable = writers.get(context.getCredentials());
    if (replicationTable == null) {
        Connector conn;
        try {
            conn = context.getConnector();
        } catch (AccumuloException | AccumuloSecurityException e) {
            throw new RuntimeException(e);
        }
        configureMetadataTable(conn, MetadataTable.NAME);
        replicationTable = new Writer(context, MetadataTable.ID);
        writers.put(context.getCredentials(), replicationTable);
    }
    return replicationTable;
}
Also used : Connector(org.apache.accumulo.core.client.Connector) AccumuloException(org.apache.accumulo.core.client.AccumuloException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Writer(org.apache.accumulo.core.client.impl.Writer)

Example 4 with Writer

use of org.apache.accumulo.core.client.impl.Writer 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 5 with Writer

use of org.apache.accumulo.core.client.impl.Writer 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)

Aggregations

Writer (org.apache.accumulo.core.client.impl.Writer)7 Credentials (org.apache.accumulo.core.client.impl.Credentials)4 IZooReaderWriter (org.apache.accumulo.fate.zookeeper.IZooReaderWriter)4 ZooReaderWriter (org.apache.accumulo.server.zookeeper.ZooReaderWriter)4 BatchWriter (org.apache.accumulo.core.client.BatchWriter)3 Mutation (org.apache.accumulo.core.data.Mutation)3 ArrayList (java.util.ArrayList)2 ClientContext (org.apache.accumulo.core.client.impl.ClientContext)2 KeyExtent (org.apache.accumulo.core.data.impl.KeyExtent)2 Test (org.junit.Test)2 TreeMap (java.util.TreeMap)1 UUID (java.util.UUID)1 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1 Connector (org.apache.accumulo.core.client.Connector)1 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)1 ColumnUpdate (org.apache.accumulo.core.data.ColumnUpdate)1 Value (org.apache.accumulo.core.data.Value)1 DataFileValue (org.apache.accumulo.core.metadata.schema.DataFileValue)1 ConstraintViolationException (org.apache.accumulo.core.tabletserver.thrift.ConstraintViolationException)1