本文整理匯總了Java中org.apache.sqoop.mapreduce.db.DBConfiguration類的典型用法代碼示例。如果您正苦於以下問題:Java DBConfiguration類的具體用法?Java DBConfiguration怎麽用?Java DBConfiguration使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DBConfiguration類屬於org.apache.sqoop.mapreduce.db包,在下文中一共展示了DBConfiguration類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: writePasswordFile
import org.apache.sqoop.mapreduce.db.DBConfiguration; //導入依賴的package包/類
/**
* Writes the user's password to a tmp file with 0600 permissions.
* @return the filename used.
*/
public static String writePasswordFile(Configuration conf)
throws IOException {
// Create the temp file to hold the user's password.
String tmpDir = conf.get(
ConfigurationConstants.PROP_JOB_LOCAL_DIRECTORY, "/tmp/");
File tempFile = File.createTempFile("mysql-cnf", ".cnf", new File(tmpDir));
// Make the password file only private readable.
DirectImportUtils.setFilePermissions(tempFile, "0600");
// If we're here, the password file is believed to be ours alone. The
// inability to set chmod 0600 inside Java is troublesome. We have to
// trust that the external 'chmod' program in the path does the right
// thing, and returns the correct exit status. But given our inability to
// re-read the permissions associated with a file, we'll have to make do
// with this.
String password = DBConfiguration.getPassword((JobConf) conf);
BufferedWriter w = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(tempFile)));
w.write("[client]\n");
w.write("password=" + password + "\n");
w.close();
return tempFile.toString();
}
示例2: configureInputFormat
import org.apache.sqoop.mapreduce.db.DBConfiguration; //導入依賴的package包/類
@Override
protected void configureInputFormat(Job job, String tableName,
String tableClassName, String splitByCol)
throws ClassNotFoundException, IOException {
super.configureInputFormat(job, tableName, tableClassName, splitByCol);
ConnManager mgr = context.getConnManager();
String username = options.getUsername();
if (null == username || username.length() == 0) {
DBConfiguration.configureDB(job.getConfiguration(),
mgr.getDriverClass(),
options.getConnectString(),
options.getFetchSize(),
options.getConnectionParams());
} else {
DBConfiguration.configureDB(job.getConfiguration(),
mgr.getDriverClass(),
options.getConnectString(),
username, options.getPassword(),
options.getFetchSize(),
options.getConnectionParams());
}
}
示例3: checkOutputSpecs
import org.apache.sqoop.mapreduce.db.DBConfiguration; //導入依賴的package包/類
@Override
/** {@inheritDoc} */
public void checkOutputSpecs(JobContext context)
throws IOException, InterruptedException {
Configuration conf = context.getConfiguration();
DBConfiguration dbConf = new DBConfiguration(conf);
// Sanity check all the configuration values we need.
if (null == conf.get(DBConfiguration.URL_PROPERTY)) {
throw new IOException("Database connection URL is not set.");
} else if (null == dbConf.getOutputTableName()) {
throw new IOException("Procedure name is not set for export");
} else if (null == dbConf.getOutputFieldNames()
&& 0 == dbConf.getOutputFieldCount()) {
throw new IOException(
"Output field names are null and zero output field count set.");
}
}
示例4: checkOutputSpecs
import org.apache.sqoop.mapreduce.db.DBConfiguration; //導入依賴的package包/類
@Override
/** {@inheritDoc} */
public void checkOutputSpecs(JobContext context)
throws IOException, InterruptedException {
Configuration conf = context.getConfiguration();
DBConfiguration dbConf = new DBConfiguration(conf);
// Sanity check all the configuration values we need.
if (null == conf.get(DBConfiguration.URL_PROPERTY)) {
throw new IOException("Database connection URL is not set.");
} else if (null == dbConf.getOutputTableName()) {
throw new IOException("Table name is not set for export.");
} else if (null == dbConf.getOutputFieldNames()) {
throw new IOException(
"Output field names are null.");
} else if (null == conf.get(ExportJobBase.SQOOP_EXPORT_UPDATE_COL_KEY)) {
throw new IOException("Update key column is not set for export.");
}
}
開發者ID:aliyun,項目名稱:aliyun-maxcompute-data-collectors,代碼行數:20,代碼來源:SQLServerResilientUpdateOutputFormat.java
示例5: checkOutputSpecs
import org.apache.sqoop.mapreduce.db.DBConfiguration; //導入依賴的package包/類
@Override
/** {@inheritDoc} */
public void checkOutputSpecs(JobContext context)
throws IOException, InterruptedException {
Configuration conf = context.getConfiguration();
DBConfiguration dbConf = new DBConfiguration(conf);
// Sanity check all the configuration values we need.
if (null == conf.get(DBConfiguration.URL_PROPERTY)) {
throw new IOException("Database connection URL is not set.");
} else if (null == dbConf.getOutputTableName()) {
throw new IOException("Table name is not set for export");
} else if (null == dbConf.getOutputFieldNames()
&& 0 == dbConf.getOutputFieldCount()) {
throw new IOException(
"Output field names are null and zero output field count set.");
}
}
開發者ID:aliyun,項目名稱:aliyun-maxcompute-data-collectors,代碼行數:19,代碼來源:SQLServerResilientExportOutputFormat.java
示例6: testRetrieveDatasets
import org.apache.sqoop.mapreduce.db.DBConfiguration; //導入依賴的package包/類
@Test
public void testRetrieveDatasets() throws IOException {
JobConf conf = new JobConf();
conf.set(DBConfiguration.URL_PROPERTY, "localhost:12345");
conf.set(DBConfiguration.USERNAME_PROPERTY, "user");
conf.set(DBConfiguration.PASSWORD_PROPERTY, "pssword");
// set the password in the secure credentials object
Text PASSWORD_SECRET_KEY = new Text(DBConfiguration.PASSWORD_PROPERTY);
conf.getCredentials().addSecretKey(PASSWORD_SECRET_KEY,
"pssword".getBytes());
String dsName = "dsName1";
conf.set(MainframeConfiguration.MAINFRAME_INPUT_DATASET_NAME, dsName);
Job job = new Job(conf);
ConfigurationHelper.setJobNumMaps(job, 2);
//format.getSplits(job);
List<InputSplit> splits = new ArrayList<InputSplit>();
splits = ((MainframeDatasetInputFormat<SqoopRecord>) format).getSplits(job);
Assert.assertEquals("test1", ((MainframeDatasetInputSplit) splits.get(0))
.getNextDataset().toString());
Assert.assertEquals("test2", ((MainframeDatasetInputSplit) splits.get(1))
.getNextDataset().toString());
}
開發者ID:aliyun,項目名稱:aliyun-maxcompute-data-collectors,代碼行數:25,代碼來源:TestMainframeDatasetInputFormat.java
示例7: testAnonymous_VERBOSE_IllegelPort
import org.apache.sqoop.mapreduce.db.DBConfiguration; //導入依賴的package包/類
@Test
public void testAnonymous_VERBOSE_IllegelPort() {
try {
when(mockFTPClient.login("anonymous", "")).thenReturn(true);
when(mockFTPClient.logout()).thenReturn(true);
when(mockFTPClient.isConnected()).thenReturn(false);
when(mockFTPClient.getReplyCode()).thenReturn(200);
} catch (IOException e) {
fail("No IOException should be thrown!");
}
conf.set(DBConfiguration.URL_PROPERTY, "localhost:testPort");
conf.setBoolean(JobBase.PROPERTY_VERBOSE, true);
FTPClient ftp = null;
boolean success = false;
try {
ftp = MainframeFTPClientUtils.getFTPConnection(conf);
} catch (IOException ioe) {
fail("No IOException should be thrown!");
} finally {
success = MainframeFTPClientUtils.closeFTPConnection(ftp);
}
Assert.assertTrue(success);
}
示例8: testPasswordInDBConfiguration
import org.apache.sqoop.mapreduce.db.DBConfiguration; //導入依賴的package包/類
public void testPasswordInDBConfiguration() throws Exception {
JobConf jobConf = new JobConf(getConf());
DBConfiguration.configureDB(jobConf, "org.hsqldb.jdbcDriver",
getConnectString(), "username", "password", null, null);
assertNotNull(jobConf.getCredentials().getSecretKey(
new Text(DBConfiguration.PASSWORD_PROPERTY)));
assertEquals("password", new String(jobConf.getCredentials().getSecretKey(
new Text(DBConfiguration.PASSWORD_PROPERTY))));
// necessary to wipe the state of previous call to configureDB
jobConf = new JobConf();
DBConfiguration.configureDB(jobConf, "org.hsqldb.jdbcDriver",
getConnectString(), null, null, null, null);
DBConfiguration dbConfiguration = new DBConfiguration(jobConf);
Connection connection = dbConfiguration.getConnection();
assertNotNull(connection);
}
示例9: initialize
import org.apache.sqoop.mapreduce.db.DBConfiguration; //導入依賴的package包/類
/**
* Initialize the writer thread with Job Configuration.
*/
public void initialize(Configuration c) throws IOException {
// Create a DBConf from the given Configuration
this.conf = c;
this.dbConf = new DBConfiguration(conf);
tableName = dbConf.getOutputTableName();
columnNames = dbConf.getOutputFieldNames();
columnCount = dbConf.getOutputFieldCount();
// Get the SQL Failure handler to be used for recovering failed write
// operations
failureHandler = getSQLFailureHandler();
failureHandler.initialize(conf);
}
示例10: ExportCallRecordWriter
import org.apache.sqoop.mapreduce.db.DBConfiguration; //導入依賴的package包/類
public ExportCallRecordWriter(TaskAttemptContext context)
throws ClassNotFoundException, SQLException {
super(context);
Configuration conf = getConf();
DBConfiguration dbConf = new DBConfiguration(conf);
procedureName = dbConf.getOutputTableName();
columnNames = dbConf.getOutputFieldNames();
columnCount = dbConf.getOutputFieldCount();
}
示例11: initialize
import org.apache.sqoop.mapreduce.db.DBConfiguration; //導入依賴的package包/類
@Override
public void initialize(InputSplit inputSplit,
TaskAttemptContext taskAttemptContext)
throws IOException, InterruptedException {
split = (MainframeDatasetInputSplit)inputSplit;
conf = taskAttemptContext.getConfiguration();
inputClass = (Class<T>) (conf.getClass(
DBConfiguration.INPUT_CLASS_PROPERTY, null));
key = null;
datasetRecord = null;
numberRecordRead = 0;
datasetProcessed = 0;
}
示例12: configureOutputFormat
import org.apache.sqoop.mapreduce.db.DBConfiguration; //導入依賴的package包/類
@Override
protected void configureOutputFormat(Job job, String tableName,
String tableClassName) throws IOException {
String procedureName = job.getConfiguration().get(SQOOP_EXPORT_CALL_KEY);
ConnManager mgr = context.getConnManager();
try {
if (Strings.isNullOrEmpty(options.getUsername())) {
DBConfiguration.configureDB(job.getConfiguration(),
mgr.getDriverClass(),
options.getConnectString(),
options.getConnectionParams());
} else {
DBConfiguration.configureDB(job.getConfiguration(),
mgr.getDriverClass(),
options.getConnectString(),
options.getUsername(),
options.getPassword(),
options.getConnectionParams());
}
String [] colNames = options.getColumns();
if (null == colNames) {
colNames = mgr.getColumnNamesForProcedure(procedureName);
}
DBOutputFormat.setOutput(
job,
mgr.escapeTableName(procedureName),
colNames);
job.setOutputFormatClass(getOutputFormatClass());
job.getConfiguration().set(SQOOP_EXPORT_TABLE_CLASS_KEY, tableClassName);
} catch (ClassNotFoundException cnfe) {
throw new IOException("Could not load OutputFormat", cnfe);
}
}
示例13: testWrongUsername
import org.apache.sqoop.mapreduce.db.DBConfiguration; //導入依賴的package包/類
@Test
public void testWrongUsername() {
try {
when(mockFTPClient.login("user", "pssword")).thenReturn(true);
when(mockFTPClient.logout()).thenReturn(true);
when(mockFTPClient.isConnected()).thenReturn(false);
when(mockFTPClient.getReplyCode()).thenReturn(200);
} catch (IOException e) {
fail("No IOException should be thrown!");
}
FTPClient ftp = null;
conf.set(DBConfiguration.URL_PROPERTY, "localhost:11111");
conf.set(DBConfiguration.USERNAME_PROPERTY, "userr");
conf.set(DBConfiguration.PASSWORD_PROPERTY, "pssword");
// set the password in the secure credentials object
Text PASSWORD_SECRET_KEY = new Text(DBConfiguration.PASSWORD_PROPERTY);
conf.getCredentials().addSecretKey(PASSWORD_SECRET_KEY,
"pssword".getBytes());
try {
ftp = MainframeFTPClientUtils.getFTPConnection(conf);
} catch (IOException ioe) {
Assert.assertEquals(
"java.io.IOException: Could not login to server localhost:",
ioe.toString());
}
Assert.assertNull(ftp);
}
示例14: testNotListDatasets
import org.apache.sqoop.mapreduce.db.DBConfiguration; //導入依賴的package包/類
@Test
public void testNotListDatasets() {
try {
when(mockFTPClient.login("user", "pssword")).thenReturn(true);
when(mockFTPClient.logout()).thenReturn(true);
when(mockFTPClient.isConnected()).thenReturn(false);
when(mockFTPClient.getReplyCode()).thenReturn(200);
} catch (IOException e) {
fail("No IOException should be thrown!");
}
conf.set(DBConfiguration.URL_PROPERTY, "localhost:11111");
conf.set(DBConfiguration.USERNAME_PROPERTY, "userr");
conf.set(DBConfiguration.PASSWORD_PROPERTY, "pssword");
// set the password in the secure credentials object
Text PASSWORD_SECRET_KEY = new Text(DBConfiguration.PASSWORD_PROPERTY);
conf.getCredentials().addSecretKey(PASSWORD_SECRET_KEY,
"pssword".getBytes());
try {
MainframeFTPClientUtils.listSequentialDatasets("pdsName", conf);
} catch (IOException ioe) {
Assert.assertEquals("java.io.IOException: "
+ "Could not list datasets from pdsName:"
+ "java.io.IOException: Could not login to server localhost:",
ioe.toString());
}
}
示例15: testPasswordNotInJobConf
import org.apache.sqoop.mapreduce.db.DBConfiguration; //導入依賴的package包/類
public void testPasswordNotInJobConf() throws Exception {
JobConf jobConf = new JobConf(getConf());
DBConfiguration.configureDB(jobConf, "org.hsqldb.jdbcDriver",
getConnectString(), "username", "password", null, null);
assertNull(jobConf.get(DBConfiguration.PASSWORD_PROPERTY, null));
}