use of org.apache.accumulo.core.client.ClientConfiguration in project accumulo by apache.
the class ClientContextTest method loadSensitivePropertyFromCredentialProvider.
@Test
public void loadSensitivePropertyFromCredentialProvider() {
if (!isCredentialProviderAvailable) {
return;
}
String absPath = getKeyStoreUrl(keystore);
ClientConfiguration clientConf = ClientConfiguration.create().with(Property.GENERAL_SECURITY_CREDENTIAL_PROVIDER_PATHS.getKey(), absPath);
AccumuloConfiguration accClientConf = ClientContext.convertClientConfig(clientConf);
Assert.assertEquals("mysecret", accClientConf.get(Property.INSTANCE_SECRET));
}
use of org.apache.accumulo.core.client.ClientConfiguration in project accumulo by apache.
the class ConnectionInfoFactory method getClientConfiguration.
public static ClientConfiguration getClientConfiguration(ConnectionInfo info) {
ClientConfiguration config = ClientConfiguration.create();
for (Object keyObj : info.getProperties().keySet()) {
String key = (String) keyObj;
String val = info.getProperties().getProperty(key);
if (key.equals(ClientProperty.INSTANCE_ZOOKEEPERS.getKey())) {
config.setProperty(ClientConfiguration.ClientProperty.INSTANCE_ZK_HOST, val);
} else if (key.equals(ClientProperty.INSTANCE_ZOOKEEPERS_TIMEOUT_SEC.getKey())) {
config.setProperty(ClientConfiguration.ClientProperty.INSTANCE_ZK_TIMEOUT, val);
} else if (key.equals(ClientProperty.SSL_ENABLED.getKey())) {
config.setProperty(ClientConfiguration.ClientProperty.INSTANCE_RPC_SSL_ENABLED, val);
} else if (key.equals(ClientProperty.SSL_KEYSTORE_PATH.getKey())) {
config.setProperty(ClientConfiguration.ClientProperty.RPC_SSL_KEYSTORE_PATH, val);
config.setProperty(ClientConfiguration.ClientProperty.INSTANCE_RPC_SSL_CLIENT_AUTH, "true");
} else if (key.equals(ClientProperty.SSL_KEYSTORE_TYPE.getKey())) {
config.setProperty(ClientConfiguration.ClientProperty.RPC_SSL_KEYSTORE_TYPE, val);
} else if (key.equals(ClientProperty.SSL_KEYSTORE_PASSWORD.getKey())) {
config.setProperty(ClientConfiguration.ClientProperty.RPC_SSL_KEYSTORE_PASSWORD, val);
} else if (key.equals(ClientProperty.SSL_TRUSTSTORE_PATH.getKey())) {
config.setProperty(ClientConfiguration.ClientProperty.RPC_SSL_TRUSTSTORE_PATH, val);
} else if (key.equals(ClientProperty.SSL_TRUSTSTORE_TYPE.getKey())) {
config.setProperty(ClientConfiguration.ClientProperty.RPC_SSL_TRUSTSTORE_PATH, val);
} else if (key.equals(ClientProperty.SSL_TRUSTSTORE_PASSWORD.getKey())) {
config.setProperty(ClientConfiguration.ClientProperty.RPC_SSL_TRUSTSTORE_PATH, val);
} else if (key.equals(ClientProperty.SSL_USE_JSSE.getKey())) {
config.setProperty(ClientConfiguration.ClientProperty.RPC_USE_JSSE, val);
} else if (key.equals(ClientProperty.SASL_ENABLED.getKey())) {
config.setProperty(ClientConfiguration.ClientProperty.INSTANCE_RPC_SSL_ENABLED, val);
} else if (key.equals(ClientProperty.SASL_QOP.getKey())) {
config.setProperty(ClientConfiguration.ClientProperty.RPC_SASL_QOP, val);
} else if (key.equals(ClientProperty.SASL_KERBEROS_SERVER_PRIMARY.getKey())) {
config.setProperty(ClientConfiguration.ClientProperty.KERBEROS_SERVER_PRIMARY, val);
} else {
config.setProperty(key, val);
}
}
return config;
}
use of org.apache.accumulo.core.client.ClientConfiguration in project accumulo by apache.
the class ConditionalWriterIT method testFields.
@Test
public void testFields() throws Exception {
Connector conn = getConnector();
String tableName = getUniqueNames(1)[0];
String user = null;
ClientConfiguration clientConf = cluster.getClientConfig();
final boolean saslEnabled = clientConf.hasSasl();
ClusterUser user1 = getUser(0);
user = user1.getPrincipal();
if (saslEnabled) {
// The token is pointless for kerberos
conn.securityOperations().createLocalUser(user, null);
} else {
conn.securityOperations().createLocalUser(user, new PasswordToken(user1.getPassword()));
}
Authorizations auths = new Authorizations("A", "B");
conn.securityOperations().changeUserAuthorizations(user, auths);
conn.securityOperations().grantSystemPermission(user, SystemPermission.CREATE_TABLE);
conn = conn.getInstance().getConnector(user, user1.getToken());
conn.tableOperations().create(tableName);
try (ConditionalWriter cw = conn.createConditionalWriter(tableName, new ConditionalWriterConfig().setAuthorizations(auths));
Scanner scanner = conn.createScanner(tableName, auths)) {
ColumnVisibility cva = new ColumnVisibility("A");
ColumnVisibility cvb = new ColumnVisibility("B");
ConditionalMutation cm0 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cva));
cm0.put("name", "last", cva, "doe");
cm0.put("name", "first", cva, "john");
cm0.put("tx", "seq", cva, "1");
Assert.assertEquals(Status.ACCEPTED, cw.write(cm0).getStatus());
scanner.setRange(new Range("99006"));
// TODO verify all columns
scanner.fetchColumn(new Text("tx"), new Text("seq"));
Entry<Key, Value> entry = Iterables.getOnlyElement(scanner);
Assert.assertEquals("1", entry.getValue().toString());
long ts = entry.getKey().getTimestamp();
// test wrong colf
ConditionalMutation cm1 = new ConditionalMutation("99006", new Condition("txA", "seq").setVisibility(cva).setValue("1"));
cm1.put("name", "last", cva, "Doe");
cm1.put("name", "first", cva, "John");
cm1.put("tx", "seq", cva, "2");
Assert.assertEquals(Status.REJECTED, cw.write(cm1).getStatus());
// test wrong colq
ConditionalMutation cm2 = new ConditionalMutation("99006", new Condition("tx", "seqA").setVisibility(cva).setValue("1"));
cm2.put("name", "last", cva, "Doe");
cm2.put("name", "first", cva, "John");
cm2.put("tx", "seq", cva, "2");
Assert.assertEquals(Status.REJECTED, cw.write(cm2).getStatus());
// test wrong colv
ConditionalMutation cm3 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cvb).setValue("1"));
cm3.put("name", "last", cva, "Doe");
cm3.put("name", "first", cva, "John");
cm3.put("tx", "seq", cva, "2");
Assert.assertEquals(Status.REJECTED, cw.write(cm3).getStatus());
// test wrong timestamp
ConditionalMutation cm4 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cva).setTimestamp(ts + 1).setValue("1"));
cm4.put("name", "last", cva, "Doe");
cm4.put("name", "first", cva, "John");
cm4.put("tx", "seq", cva, "2");
Assert.assertEquals(Status.REJECTED, cw.write(cm4).getStatus());
// test wrong timestamp
ConditionalMutation cm5 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cva).setTimestamp(ts - 1).setValue("1"));
cm5.put("name", "last", cva, "Doe");
cm5.put("name", "first", cva, "John");
cm5.put("tx", "seq", cva, "2");
Assert.assertEquals(Status.REJECTED, cw.write(cm5).getStatus());
// ensure no updates were made
entry = Iterables.getOnlyElement(scanner);
Assert.assertEquals("1", entry.getValue().toString());
// set all columns correctly
ConditionalMutation cm6 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cva).setTimestamp(ts).setValue("1"));
cm6.put("name", "last", cva, "Doe");
cm6.put("name", "first", cva, "John");
cm6.put("tx", "seq", cva, "2");
Assert.assertEquals(Status.ACCEPTED, cw.write(cm6).getStatus());
entry = Iterables.getOnlyElement(scanner);
Assert.assertEquals("2", entry.getValue().toString());
}
}
use of org.apache.accumulo.core.client.ClientConfiguration in project incubator-rya by apache.
the class RyaGiraphUtils method initializeAccumuloInputFormat.
public static void initializeAccumuloInputFormat(Configuration conf) {
// get accumulo connect information
boolean mock = MRUtils.getACMock(conf, false);
String zk = MRUtils.getACZK(conf);
String instance = MRUtils.getACInstance(conf);
String userName = MRUtils.getACUserName(conf);
String pwd = MRUtils.getACPwd(conf);
String tablePrefix = MRUtils.getTablePrefix(conf);
TABLE_LAYOUT rdfTableLayout = MRUtils.getTableLayout(conf, TABLE_LAYOUT.SPO);
String authString = conf.get(MRUtils.AC_AUTH_PROP);
Authorizations authorizations;
if (authString != null && !authString.isEmpty()) {
authorizations = new Authorizations(authString.split(","));
// for consistency
conf.set(ConfigUtils.CLOUDBASE_AUTHS, authString);
} else {
authorizations = AccumuloRdfConstants.ALL_AUTHORIZATIONS;
}
// set up the accumulo input format so that we know what table to use and everything
try {
Job job = new Job(conf);
AccumuloInputFormat.setConnectorInfo(job, userName, new PasswordToken(pwd));
String tableName = RdfCloudTripleStoreUtils.layoutPrefixToTable(rdfTableLayout, tablePrefix);
AccumuloInputFormat.setInputTableName(job, tableName);
AccumuloInputFormat.setScanAuthorizations(job, authorizations);
if (mock) {
AccumuloInputFormat.setMockInstance(job, instance);
} else {
ClientConfiguration clientConfig = ClientConfiguration.loadDefault().withInstance(instance).withZkHosts(zk);
AccumuloInputFormat.setZooKeeperInstance(job, clientConfig);
}
} catch (IOException | AccumuloSecurityException e) {
// TODO better exception handling here
e.printStackTrace();
}
}
use of org.apache.accumulo.core.client.ClientConfiguration in project incubator-rya by apache.
the class GraphXGraphGenerator method getVertexRDD.
public RDD<Tuple2<Object, RyaTypeWritable>> getVertexRDD(SparkContext sc, Configuration conf) throws IOException, AccumuloSecurityException {
// Load configuration parameters
zk = MRUtils.getACZK(conf);
instance = MRUtils.getACInstance(conf);
userName = MRUtils.getACUserName(conf);
pwd = MRUtils.getACPwd(conf);
mock = MRUtils.getACMock(conf, false);
tablePrefix = MRUtils.getTablePrefix(conf);
// Set authorizations if specified
String authString = conf.get(MRUtils.AC_AUTH_PROP);
if (authString != null && !authString.isEmpty()) {
authorizations = new Authorizations(authString.split(","));
// for consistency
conf.set(ConfigUtils.CLOUDBASE_AUTHS, authString);
} else {
authorizations = AccumuloRdfConstants.ALL_AUTHORIZATIONS;
}
// Set table prefix to the default if not set
if (tablePrefix == null) {
tablePrefix = RdfCloudTripleStoreConstants.TBL_PRFX_DEF;
MRUtils.setTablePrefix(conf, tablePrefix);
}
// Check for required configuration parameters
Preconditions.checkNotNull(instance, "Accumulo instance name [" + MRUtils.AC_INSTANCE_PROP + "] not set.");
Preconditions.checkNotNull(userName, "Accumulo username [" + MRUtils.AC_USERNAME_PROP + "] not set.");
Preconditions.checkNotNull(pwd, "Accumulo password [" + MRUtils.AC_PWD_PROP + "] not set.");
Preconditions.checkNotNull(tablePrefix, "Table prefix [" + MRUtils.TABLE_PREFIX_PROPERTY + "] not set.");
RdfCloudTripleStoreConstants.prefixTables(tablePrefix);
// for consistency
if (!mock)
conf.set(ConfigUtils.CLOUDBASE_ZOOKEEPERS, zk);
// Ensure consistency between alternative configuration properties
conf.set(ConfigUtils.CLOUDBASE_INSTANCE, instance);
conf.set(ConfigUtils.CLOUDBASE_USER, userName);
conf.set(ConfigUtils.CLOUDBASE_PASSWORD, pwd);
conf.setBoolean(ConfigUtils.USE_MOCK_INSTANCE, mock);
conf.set(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX, tablePrefix);
Job job = Job.getInstance(conf, sc.appName());
ClientConfiguration clientConfig = new ClientConfiguration().with(ClientProperty.INSTANCE_NAME, instance).with(ClientProperty.INSTANCE_ZK_HOST, zk);
GraphXInputFormat.setInputTableName(job, EntityCentricIndex.getTableName(conf));
GraphXInputFormat.setConnectorInfo(job, userName, new PasswordToken(pwd));
GraphXInputFormat.setZooKeeperInstance(job, clientConfig);
GraphXInputFormat.setScanAuthorizations(job, authorizations);
return sc.newAPIHadoopRDD(job.getConfiguration(), GraphXInputFormat.class, Object.class, RyaTypeWritable.class);
}
Aggregations