Java Code Examples for org.apache.accumulo.core.client.mock.MockInstance#getConnector()

The following examples show how to use org.apache.accumulo.core.client.mock.MockInstance#getConnector() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RdfCloudTripleStoreSelectivityEvaluationStatisticsTest.java    From rya with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException {

    mock = new MockInstance("accumulo");
    PasswordToken pToken = new PasswordToken("pass".getBytes());
    conn = mock.getConnector("user", pToken);

    config = new BatchWriterConfig();
    config.setMaxMemory(1000);
    config.setMaxLatency(1000, TimeUnit.SECONDS);
    config.setMaxWriteThreads(10);

    if (conn.tableOperations().exists("rya_prospects")) {
        conn.tableOperations().delete("rya_prospects");
    }
    if (conn.tableOperations().exists("rya_selectivity")) {
        conn.tableOperations().delete("rya_selectivity");
    }

    arc = new AccumuloRdfConfiguration();
    arc.setTableLayoutStrategy(new TablePrefixLayoutStrategy());
    arc.setMaxRangesForScanner(300);

}
 
Example 2
Source File: QueryJoinSelectOptimizerTest.java    From rya with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException {

  mock = new MockInstance("accumulo");
  PasswordToken pToken = new PasswordToken("pass".getBytes());
  conn = mock.getConnector("user", pToken);

  config = new BatchWriterConfig();
  config.setMaxMemory(1000);
  config.setMaxLatency(1000, TimeUnit.SECONDS);
  config.setMaxWriteThreads(10);

  if (conn.tableOperations().exists("rya_prospects")) {
    conn.tableOperations().delete("rya_prospects");
  }
  if (conn.tableOperations().exists("rya_selectivity")) {
    conn.tableOperations().delete("rya_selectivity");
  }

  arc = new AccumuloRdfConfiguration();
  arc.setTableLayoutStrategy(new TablePrefixLayoutStrategy());
  arc.setMaxRangesForScanner(300);
  res = new ProspectorServiceEvalStatsDAO(conn, arc);

}
 
Example 3
Source File: TextOutputExample.java    From rya with Apache License 2.0 6 votes vote down vote up
static void setUpRya() throws AccumuloException, AccumuloSecurityException, RyaDAOException {
    MockInstance mock = new MockInstance(INSTANCE_NAME);
    Connector conn = mock.getConnector(USERNAME, new PasswordToken(USERP));
    AccumuloRyaDAO dao = new AccumuloRyaDAO();
    dao.setConnector(conn);
    AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration();
    conf.setTablePrefix(PREFIX);
    dao.setConf(conf);
    dao.init();
    String ns = "http://example.com/";
    dao.add(new RyaStatement(new RyaIRI(ns+"s1"), new RyaIRI(ns+"p1"), new RyaIRI(ns+"o1")));
    dao.add(new RyaStatement(new RyaIRI(ns+"s1"), new RyaIRI(ns+"p2"), new RyaIRI(ns+"o2")));
    dao.add(new RyaStatement(new RyaIRI(ns+"s2"), new RyaIRI(ns+"p1"), new RyaIRI(ns+"o3"),
            new RyaIRI(ns+"g1")));
    dao.add(new RyaStatement(new RyaIRI(ns+"s3"), new RyaIRI(ns+"p3"), new RyaIRI(ns+"o3"),
            new RyaIRI(ns+"g2")));
    dao.destroy();
}
 
Example 4
Source File: RyaOutputFormatTest.java    From rya with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    MRUtils.setACMock(conf, true);
    MRUtils.setACInstance(conf, INSTANCE_NAME);
    MRUtils.setACUserName(conf, USERNAME);
    MRUtils.setACPwd(conf, PASSWORD);
    MRUtils.setTablePrefix(conf, PREFIX);
    conf.setTablePrefix(PREFIX);
    conf.setAuths(CV);
    conf.set(ConfigUtils.CLOUDBASE_INSTANCE, INSTANCE_NAME);
    conf.set(ConfigUtils.CLOUDBASE_USER, USERNAME);
    conf.set(ConfigUtils.CLOUDBASE_PASSWORD, PASSWORD);
    conf.setBoolean(ConfigUtils.USE_MOCK_INSTANCE, true);
    conf.setClass(ConfigUtils.TOKENIZER_CLASS, SimpleTokenizer.class, Tokenizer.class);
    ryaContext = RyaTripleContext.getInstance(conf);
    instance = new MockInstance(INSTANCE_NAME);
    connector = instance.getConnector(USERNAME, new PasswordToken(PASSWORD));
    job = Job.getInstance(conf);
    RyaOutputFormat.setMockInstance(job, instance.getInstanceName());
    AccumuloOutputFormat.setConnectorInfo(job, USERNAME, new PasswordToken(PASSWORD));
    AccumuloOutputFormat.setCreateTables(job, true);
    AccumuloOutputFormat.setDefaultTableName(job, PREFIX + "default");
    RyaOutputFormat.setTablePrefix(job, PREFIX);
}
 
Example 5
Source File: GraphXInputFormatTest.java    From rya with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    instance = new MockInstance(GraphXInputFormatTest.class.getName() + ".mock_instance");
    final Connector connector = instance.getConnector(username, password);
    connector.tableOperations().create(table);

    final AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration();
    conf.setTablePrefix("rya_");
    conf.setDisplayQueryPlan(false);
    conf.setBoolean("sc.use_entity", true);

    apiImpl = new AccumuloRyaDAO();
    apiImpl.setConf(conf);
    apiImpl.setConnector(connector);
    apiImpl.init();
}
 
Example 6
Source File: JoinSelectStatisticsTest.java    From rya with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException {
  
    MockInstance mockInstance = new MockInstance(INSTANCE_NAME);
    c = mockInstance.getConnector("root", new PasswordToken(""));
    
    if (c.tableOperations().exists("rya_prospects")) {
        c.tableOperations().delete("rya_prospects");
    } 
    if (c.tableOperations().exists("rya_selectivity")) {
        c.tableOperations().delete("rya_selectivity");
    }
    if (c.tableOperations().exists("rya_spo")) {
        c.tableOperations().delete("rya_spo");
    } 
    
    
    c.tableOperations().create("rya_spo");
    c.tableOperations().create("rya_prospects");
    c.tableOperations().create("rya_selectivity");
    ryaContext = RyaTripleContext.getInstance(new AccumuloRdfConfiguration(getConfig()));
}
 
Example 7
Source File: AccumuloSelectivityEvalDAOTest.java    From rya with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException {

    mock = new MockInstance("accumulo");
    PasswordToken pToken = new PasswordToken("pass".getBytes());
    conn = mock.getConnector("user", pToken);

    config = new BatchWriterConfig();
    config.setMaxMemory(1000);
    config.setMaxLatency(1000, TimeUnit.SECONDS);
    config.setMaxWriteThreads(10);

    if (conn.tableOperations().exists("rya_prospects")) {
        conn.tableOperations().delete("rya_prospects");
    }
    if (conn.tableOperations().exists("rya_selectivity")) {
        conn.tableOperations().delete("rya_selectivity");
    }

    arc = new AccumuloRdfConfiguration();
    res = new ProspectorServiceEvalStatsDAO(conn, arc);
    arc.setTableLayoutStrategy(new TablePrefixLayoutStrategy());
    arc.setMaxRangesForScanner(300);

}
 
Example 8
Source File: AccumuloRangeQueryTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Before
public void ingestGeometries() throws AccumuloException, AccumuloSecurityException, IOException {
  final MockInstance mockInstance = new MockInstance();
  final Connector mockConnector =
      mockInstance.getConnector("root", new PasswordToken(new byte[0]));

  final AccumuloOptions options = new AccumuloOptions();
  mockDataStore = new AccumuloDataStore(new AccumuloOperations(mockConnector, options), options);

  index = new SpatialDimensionalityTypeProvider().createIndex(new SpatialOptions());
  adapter = new TestGeometryAdapter();
  mockDataStore.addType(adapter, index);
  try (Writer writer = mockDataStore.createWriter(adapter.getTypeName())) {
    writer.write(testdata);
  }
}
 
Example 9
Source File: AccumuloDataStoreStatsTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws AccumuloException, AccumuloSecurityException {
  final MockInstance mockInstance = new MockInstance();
  Connector mockConnector = null;
  try {
    mockConnector = mockInstance.getConnector("root", new PasswordToken(new byte[0]));
  } catch (AccumuloException | AccumuloSecurityException e) {
    LOGGER.error("Failed to create mock accumulo connection", e);
  }
  final AccumuloOptions options = new AccumuloOptions();

  accumuloOperations = new AccumuloOperations(mockConnector, options);

  statsStore = new DataStatisticsStoreImpl(accumuloOperations, options);

  internalAdapterStore = new InternalAdapterStoreImpl(accumuloOperations);

  mockDataStore = new AccumuloDataStore(accumuloOperations, options);
}
 
Example 10
Source File: AccumuloOptionsTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
  final MockInstance mockInstance = new MockInstance();
  Connector mockConnector = null;
  try {
    mockConnector = mockInstance.getConnector("root", new PasswordToken(new byte[0]));
  } catch (AccumuloException | AccumuloSecurityException e) {
    LOGGER.error("Failed to create mock accumulo connection", e);
  }
  final AccumuloOptions options = new AccumuloOptions();
  accumuloOperations = new AccumuloOperations(mockConnector, accumuloOptions);

  indexStore = new IndexStoreImpl(accumuloOperations, accumuloOptions);

  adapterStore = new AdapterStoreImpl(accumuloOperations, accumuloOptions);

  internalAdapterStore = new InternalAdapterStoreImpl(accumuloOperations);

  mockDataStore = new AccumuloDataStore(accumuloOperations, options);
}
 
Example 11
Source File: GraphXEdgeInputFormatTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws Exception {
    instance = new MockInstance(GraphXEdgeInputFormatTest.class.getName() + ".mock_instance");
    Connector connector = instance.getConnector(username, password);
    connector.tableOperations().create(table);

    AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration();
    conf.setTablePrefix("rya_");
    conf.setDisplayQueryPlan(false);

    apiImpl = new AccumuloRyaDAO();
    apiImpl.setConf(conf);
    apiImpl.setConnector(connector);
    apiImpl.init();
}
 
Example 12
Source File: RyaInputFormatTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void init() throws Exception {
    instance = new MockInstance(RyaInputFormatTest.class.getName() + ".mock_instance");
    Connector connector = instance.getConnector(username, password);
    connector.tableOperations().create(table);

    AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration();
    conf.setTablePrefix("rya_");
    conf.setDisplayQueryPlan(false);

    apiImpl = new AccumuloRyaDAO();
    apiImpl.setConf(conf);
    apiImpl.setConnector(connector);
}
 
Example 13
Source File: AccumuloInstanceDriver.java    From rya with Apache License 2.0 5 votes vote down vote up
/**
 * Sets up the {@link MiniAccumuloCluster} or the {@link MockInstance}.
 * @throws Exception
 */
public void setUpInstance() throws Exception {
    if (!isMock) {
        log.info("Setting up " + driverName + " MiniAccumulo cluster...");
        // Create and Run MiniAccumulo Cluster
        tempDir = Files.createTempDir();
        tempDir.deleteOnExit();
        miniAccumuloCluster = new MiniAccumuloCluster(tempDir, userpwd);
        copyHadoopHomeToTemp();
        miniAccumuloCluster.getConfig().setInstanceName(instanceName);
        log.info(driverName + " MiniAccumulo instance starting up...");
        miniAccumuloCluster.start();
        Thread.sleep(1000);
        log.info(driverName + " MiniAccumulo instance started");
        log.info("Creating connector to " + driverName + " MiniAccumulo instance...");
        zooKeeperInstance = new ZooKeeperInstance(miniAccumuloCluster.getClientConfig());
        instance = zooKeeperInstance;
        connector = zooKeeperInstance.getConnector(user, new PasswordToken(userpwd));
        log.info("Created connector to " + driverName + " MiniAccumulo instance");
    } else {
        log.info("Setting up " + driverName + " mock instance...");
        mockInstance = new MockInstance(instanceName);
        instance = mockInstance;
        connector = mockInstance.getConnector(user, new PasswordToken(userpwd));
        log.info("Created connector to " + driverName + " mock instance");
    }
    zooKeepers = instance.getZooKeepers();
}
 
Example 14
Source File: AccumuloDataIndexWriterTest.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  final MockInstance mockInstance = new MockInstance();
  Connector mockConnector = null;
  try {
    mockConnector = mockInstance.getConnector("root", new PasswordToken(new byte[0]));
  } catch (AccumuloException | AccumuloSecurityException e) {
    LOGGER.error("Failed to create mock accumulo connection", e);
  }
  accumuloOperations = new AccumuloOperations(mockConnector, accumuloOptions);
}
 
Example 15
Source File: AccumuloInstanceDriver.java    From rya with Apache License 2.0 4 votes vote down vote up
/**
 * Sets up the {@link MiniAccumuloCluster} or the {@link MockInstance} or
 * distribution instance
 * @throws Exception
 */
public void setUpInstance() throws Exception {
    switch (instanceType) {
        case DISTRIBUTION:
            log.info("Setting up " + driverName + " distribution instance...");
            if (instanceName == null) {
                throw new IllegalArgumentException("Must specify instance name for distributed mode");
            } else if (zooKeepers == null) {
                throw new IllegalArgumentException("Must specify ZooKeeper hosts for distributed mode");
            }
            instance = new ZooKeeperInstance(instanceName, zooKeepers);
            connector = instance.getConnector(user, new PasswordToken(userpwd));
            log.info("Created connector to " + driverName + " distribution instance");
            break;
        case MINI:
            log.info("Setting up " + driverName + " MiniAccumulo cluster...");
            // Create and Run MiniAccumulo Cluster
            tempDir = Files.createTempDir();
            tempDir.deleteOnExit();
            miniAccumuloCluster = new MiniAccumuloCluster(tempDir, userpwd);
            copyHadoopHomeToTemp();
            miniAccumuloCluster.getConfig().setInstanceName(instanceName);
            log.info(driverName + " MiniAccumulo instance starting up...");
            miniAccumuloCluster.start();
            Thread.sleep(1000);
            log.info(driverName + " MiniAccumulo instance started");
            log.info("Creating connector to " + driverName + " MiniAccumulo instance...");
            zooKeeperInstance = new ZooKeeperInstance(miniAccumuloCluster.getClientConfig());
            instance = zooKeeperInstance;
            connector = zooKeeperInstance.getConnector(user, new PasswordToken(userpwd));
            log.info("Created connector to " + driverName + " MiniAccumulo instance");
            break;
        case MOCK:
            log.info("Setting up " + driverName + " mock instance...");
            mockInstance = new MockInstance(instanceName);
            instance = mockInstance;
            connector = mockInstance.getConnector(user, new PasswordToken(userpwd));
            log.info("Created connector to " + driverName + " mock instance");
            break;
        default:
            throw new AccumuloException("Unexpected instance type: " + instanceType);
    }
    zooKeepers = instance.getZooKeepers();
}
 
Example 16
Source File: AccumuloMrsImageReader.java    From mrgeo with Apache License 2.0 4 votes vote down vote up
/**
 * Prepare the scanners that end up being used for getting items out of Accumulo
 */
private void initializeScanners()
{

  if (AMTR_props != null)
  {

    String authsStr = AMTR_props.getProperty(MrGeoAccumuloConstants.MRGEO_ACC_KEY_AUTHS);
    this.auths = AccumuloUtils.createAuthorizationsFromDelimitedString(authsStr);

    if (AMTR_props.getProperty(MrGeoAccumuloConstants.MRGEO_ACC_KEY_COMPRESS) != null)
    {
      //String tmp = AMTR_props.getProperty(MrGeoAccumuloConstants.MRGEO_ACC_KEY_COMPRESS);
      useCompression = Boolean.parseBoolean(AMTR_props.getProperty(MrGeoAccumuloConstants.MRGEO_ACC_KEY_COMPRESS));
    }

  }

  try
  {

    if (useCompression)
    {
      codec = HadoopUtils.getCodec(HadoopUtils.createConfiguration());
      decompressor = CodecPool.getDecompressor(codec);
    }
    else
    {
      codec = null;
      decompressor = null;
    }

    // see if we are in a test state
    if (mock)
    {

      // in test mode - use a mock connector
      final MockInstance mi = new MockInstance(this.instance);
      connector = mi.getConnector(this.user, this.pass.getBytes());
      connector.tableOperations().create(this.table);

    }
    else if (this.instance != null)
    {

      // get a real connector
      connector = AccumuloConnector.getConnector(this.instance,
          this.zooServers,
          this.user,
          this.pass);
      if (useCompression)
      {
        codec = HadoopUtils.getCodec(HadoopUtils.createConfiguration());
        decompressor = CodecPool.getDecompressor(codec);
      }
      else
      {
        codec = null;
        decompressor = null;
      }

    }
    else
    {

      // we did not get the information needed from the properties objects - so use the configs from the install

      connector = AccumuloConnector.getConnector();

      // TODO: compression items need to be worked out
      codec = null;
      decompressor = null;

    }

    // establish the scanners
    scanner = connector.createScanner(this.table, this.auths);
    batchScanner = connector.createBatchScanner(this.table, this.auths, numQueryThreads);

  }
  catch (final TableNotFoundException | TableExistsException | AccumuloException | AccumuloSecurityException | IOException e)
  {
    throw new MrsImageException(e);
  }

}