Search in sources :

Example 86 with PasswordToken

use of org.apache.accumulo.core.client.security.tokens.PasswordToken in project accumulo by apache.

the class MiniClusterHarness method create.

public MiniAccumuloClusterImpl create(String testClassName, String testMethodName, AuthenticationToken token, MiniClusterConfigurationCallback configCallback, TestingKdc kdc) throws Exception {
    requireNonNull(token);
    checkArgument(token instanceof PasswordToken || token instanceof KerberosToken, "A PasswordToken or KerberosToken is required");
    String rootPasswd;
    if (token instanceof PasswordToken) {
        rootPasswd = new String(((PasswordToken) token).getPassword(), UTF_8);
    } else {
        rootPasswd = UUID.randomUUID().toString();
    }
    File baseDir = AccumuloClusterHarness.createTestDir(testClassName + "_" + testMethodName);
    MiniAccumuloConfigImpl cfg = new MiniAccumuloConfigImpl(baseDir, rootPasswd);
    // Enable native maps by default
    cfg.setNativeLibPaths(NativeMapIT.nativeMapLocation().getAbsolutePath());
    cfg.setProperty(Property.TSERV_NATIVEMAP_ENABLED, Boolean.TRUE.toString());
    Configuration coreSite = new Configuration(false);
    // Setup SSL and credential providers if the properties request such
    configureForEnvironment(cfg, getClass(), AccumuloClusterHarness.getSslDir(baseDir), coreSite, kdc);
    // Invoke the callback for tests to configure MAC before it starts
    configCallback.configureMiniCluster(cfg, coreSite);
    MiniAccumuloClusterImpl miniCluster = new MiniAccumuloClusterImpl(cfg);
    // Write out any configuration items to a file so HDFS will pick them up automatically (from the classpath)
    if (coreSite.size() > 0) {
        File csFile = new File(miniCluster.getConfig().getConfDir(), "core-site.xml");
        if (csFile.exists())
            throw new RuntimeException(csFile + " already exist");
        OutputStream out = new BufferedOutputStream(new FileOutputStream(new File(miniCluster.getConfig().getConfDir(), "core-site.xml")));
        coreSite.writeXml(out);
        out.close();
    }
    return miniCluster;
}
Also used : PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) Configuration(org.apache.hadoop.conf.Configuration) KerberosToken(org.apache.accumulo.core.client.security.tokens.KerberosToken) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) MiniAccumuloClusterImpl(org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) MiniAccumuloConfigImpl(org.apache.accumulo.minicluster.impl.MiniAccumuloConfigImpl)

Example 87 with PasswordToken

use of org.apache.accumulo.core.client.security.tokens.PasswordToken in project accumulo by apache.

the class ExistingMacIT method testExistingInstance.

@Test
public void testExistingInstance() throws Exception {
    Connector conn = getCluster().getConnector("root", new PasswordToken(ROOT_PASSWORD));
    conn.tableOperations().create("table1");
    BatchWriter bw = conn.createBatchWriter("table1", new BatchWriterConfig());
    Mutation m1 = new Mutation("00081");
    m1.put("math", "sqroot", "9");
    m1.put("math", "sq", "6560");
    bw.addMutation(m1);
    bw.close();
    conn.tableOperations().flush("table1", null, null, true);
    // TOOD use constants
    conn.tableOperations().flush(MetadataTable.NAME, null, null, true);
    conn.tableOperations().flush(RootTable.NAME, null, null, true);
    Set<Entry<ServerType, Collection<ProcessReference>>> procs = getCluster().getProcesses().entrySet();
    for (Entry<ServerType, Collection<ProcessReference>> entry : procs) {
        if (entry.getKey() == ServerType.ZOOKEEPER)
            continue;
        for (ProcessReference pr : entry.getValue()) getCluster().killProcess(entry.getKey(), pr);
    }
    final DefaultConfiguration defaultConfig = DefaultConfiguration.getInstance();
    final long zkTimeout = ConfigurationTypeHelper.getTimeInMillis(getCluster().getConfig().getSiteConfig().get(Property.INSTANCE_ZK_TIMEOUT.getKey()));
    IZooReaderWriter zrw = new ZooReaderWriterFactory().getZooReaderWriter(getCluster().getZooKeepers(), (int) zkTimeout, defaultConfig.get(Property.INSTANCE_SECRET));
    final String zInstanceRoot = Constants.ZROOT + "/" + conn.getInstance().getInstanceID();
    while (!AccumuloStatus.isAccumuloOffline(zrw, zInstanceRoot)) {
        log.debug("Accumulo services still have their ZK locks held");
        Thread.sleep(1000);
    }
    File hadoopConfDir = createTestDir(ExistingMacIT.class.getSimpleName() + "_hadoop_conf");
    FileUtils.deleteQuietly(hadoopConfDir);
    assertTrue(hadoopConfDir.mkdirs());
    createEmptyConfig(new File(hadoopConfDir, "core-site.xml"));
    createEmptyConfig(new File(hadoopConfDir, "hdfs-site.xml"));
    File testDir2 = createTestDir(ExistingMacIT.class.getSimpleName() + "_2");
    FileUtils.deleteQuietly(testDir2);
    MiniAccumuloConfigImpl macConfig2 = new MiniAccumuloConfigImpl(testDir2, "notused");
    macConfig2.useExistingInstance(new File(getCluster().getConfig().getConfDir(), "accumulo-site.xml"), hadoopConfDir);
    MiniAccumuloClusterImpl accumulo2 = new MiniAccumuloClusterImpl(macConfig2);
    accumulo2.start();
    conn = accumulo2.getConnector("root", new PasswordToken(ROOT_PASSWORD));
    try (Scanner scanner = conn.createScanner("table1", Authorizations.EMPTY)) {
        int sum = 0;
        for (Entry<Key, Value> entry : scanner) {
            sum += Integer.parseInt(entry.getValue().toString());
        }
        Assert.assertEquals(6569, sum);
    }
    accumulo2.stop();
}
Also used : Connector(org.apache.accumulo.core.client.Connector) ServerType(org.apache.accumulo.minicluster.ServerType) Scanner(org.apache.accumulo.core.client.Scanner) ProcessReference(org.apache.accumulo.minicluster.impl.ProcessReference) DefaultConfiguration(org.apache.accumulo.core.conf.DefaultConfiguration) ZooReaderWriterFactory(org.apache.accumulo.server.zookeeper.ZooReaderWriterFactory) MiniAccumuloConfigImpl(org.apache.accumulo.minicluster.impl.MiniAccumuloConfigImpl) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) Entry(java.util.Map.Entry) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) Value(org.apache.accumulo.core.data.Value) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) Collection(java.util.Collection) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) MiniAccumuloClusterImpl(org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl) File(java.io.File) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 88 with PasswordToken

use of org.apache.accumulo.core.client.security.tokens.PasswordToken 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 89 with PasswordToken

use of org.apache.accumulo.core.client.security.tokens.PasswordToken in project accumulo-examples by apache.

the class ExamplesIT method getClusterInfo.

@Before
public void getClusterInfo() throws Exception {
    c = getConnector();
    String user = getAdminPrincipal();
    String instance = c.getInstance().getInstanceName();
    String keepers = c.getInstance().getZooKeepers();
    AuthenticationToken token = getAdminToken();
    if (token instanceof PasswordToken) {
        String passwd = new String(((PasswordToken) getAdminToken()).getPassword(), UTF_8);
        writeConnectionFile(getConnectionFile(), instance, keepers, user, passwd);
    } else {
        Assert.fail("Unknown token type: " + token);
    }
    fs = getCluster().getFileSystem();
    dir = new Path(cluster.getTemporaryPath(), getClass().getName()).toString();
    origAuths = c.securityOperations().getUserAuthorizations(user);
    c.securityOperations().changeUserAuthorizations(user, new Authorizations(auths.split(",")));
}
Also used : Path(org.apache.hadoop.fs.Path) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) Authorizations(org.apache.accumulo.core.security.Authorizations) AuthenticationToken(org.apache.accumulo.core.client.security.tokens.AuthenticationToken) Before(org.junit.Before)

Example 90 with PasswordToken

use of org.apache.accumulo.core.client.security.tokens.PasswordToken in project accumulo-examples by apache.

the class ExamplesIT method testTeraSortAndRead.

@Test
public void testTeraSortAndRead() throws Exception {
    // TODO Figure out a way to run M/R with Kerberos
    assumeTrue(getAdminToken() instanceof PasswordToken);
    String tableName = getUniqueNames(1)[0];
    String[] args = new String[] { "--count", (1000 * 1000) + "", "-nk", "10", "-xk", "10", "-nv", "10", "-xv", "10", "-t", tableName, "-c", getConnectionFile(), "--splits", "4" };
    goodExec(TeraSortIngest.class, args);
    Path output = new Path(dir, "tmp/nines");
    if (fs.exists(output)) {
        fs.delete(output, true);
    }
    args = new String[] { "-c", getConnectionFile(), "-t", tableName, "--rowRegex", ".*999.*", "--output", output.toString() };
    goodExec(RegexExample.class, args);
    args = new String[] { "-c", getConnectionFile(), "-t", tableName, "--column", "c:" };
    goodExec(RowHash.class, args);
    output = new Path(dir, "tmp/tableFile");
    if (fs.exists(output)) {
        fs.delete(output, true);
    }
    args = new String[] { "-c", getConnectionFile(), "-t", tableName, "--output", output.toString() };
    goodExec(TableToFile.class, args);
}
Also used : Path(org.apache.hadoop.fs.Path) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) InterferenceTest(org.apache.accumulo.examples.isolation.InterferenceTest) Test(org.junit.Test)

Aggregations

PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)232 Test (org.junit.Test)104 Connector (org.apache.accumulo.core.client.Connector)96 MockInstance (org.apache.accumulo.core.client.mock.MockInstance)53 Instance (org.apache.accumulo.core.client.Instance)46 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)43 ZooKeeperInstance (org.apache.accumulo.core.client.ZooKeeperInstance)40 Authorizations (org.apache.accumulo.core.security.Authorizations)38 AuthenticationToken (org.apache.accumulo.core.client.security.tokens.AuthenticationToken)32 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)31 ClientConfiguration (org.apache.accumulo.core.client.ClientConfiguration)30 Value (org.apache.accumulo.core.data.Value)30 Key (org.apache.accumulo.core.data.Key)29 Mutation (org.apache.accumulo.core.data.Mutation)29 AccumuloException (org.apache.accumulo.core.client.AccumuloException)27 Scanner (org.apache.accumulo.core.client.Scanner)27 Configuration (org.apache.hadoop.conf.Configuration)27 IOException (java.io.IOException)26 BatchWriter (org.apache.accumulo.core.client.BatchWriter)26 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)24