in odps-sqoop/src/java/org/apache/sqoop/manager/oracle/OraOopManagerFactory.java [274:392]
private void setMapperConnectionDetails(OraOopConnManager oraOopConnManager,
JobData jobData) {
// Ensure we have a connection to the database...
Connection connection = null;
try {
connection = oraOopConnManager.getConnection();
} catch (SQLException ex) {
throw new RuntimeException(String.format(
"Unable to connect to the Oracle database at %s\n" + "Error:%s",
jobData.getSqoopOptions().getConnectString(), ex.getMessage()));
}
// Query v$active_instances to get a list of all instances in the Oracle RAC
// (assuming this *could* be a RAC)...
List<OracleActiveInstance> activeInstances = null;
try {
activeInstances =
OraOopOracleQueries.getOracleActiveInstances(connection);
} catch (SQLException ex) {
throw new RuntimeException(
"An error was encountered when attempting to determine the "
+ "configuration of the Oracle RAC.",
ex);
}
if (activeInstances == null) {
LOG.info("This Oracle database is not a RAC.");
} else {
LOG.info("This Oracle database is a RAC.");
}
// Is dynamic JDBC URL generation disabled?...
if (OraOopUtilities.oracleJdbcUrlGenerationDisabled(jobData
.getSqoopOptions().getConf())) {
LOG.info(String
.format(
"%s will not use dynamically generated JDBC URLs - this feature "
+ "has been disabled.",
OraOopConstants.ORAOOP_PRODUCT_NAME));
return;
}
boolean generateRacBasedJdbcUrls = false;
// Decide whether this is a multi-instance RAC, and whether we need to do
// anything more...
if (activeInstances != null) {
generateRacBasedJdbcUrls = true;
if (activeInstances.size() < OraOopUtilities
.getMinNumberOfOracleRacActiveInstancesForDynamicJdbcUrlUse(jobData
.getSqoopOptions().getConf())) {
LOG.info(String.format(
"There are only %d active instances in the Oracle RAC. "
+ "%s will not bother utilizing dynamically generated JDBC URLs.",
activeInstances.size(), OraOopConstants.ORAOOP_PRODUCT_NAME));
generateRacBasedJdbcUrls = false;
}
}
// E.g. jdbc:oracle:thin:@localhost.localdomain:1521:orcl
String jdbcConnectStr = jobData.getSqoopOptions().getConnectString();
// Parse the JDBC URL to obtain the port number for the TNS listener...
String jdbcHost = "";
int jdbcPort = 0;
String jdbcSid = "";
String jdbcService = "";
String jdbcTnsName = "";
try {
OraOopJdbcUrl oraOopJdbcUrl = new OraOopJdbcUrl(jdbcConnectStr);
OraOopUtilities.JdbcOracleThinConnection jdbcConnection =
oraOopJdbcUrl.parseJdbcOracleThinConnectionString();
jdbcHost = jdbcConnection.getHost();
jdbcPort = jdbcConnection.getPort();
jdbcSid = jdbcConnection.getSid();
jdbcService = jdbcConnection.getService();
jdbcTnsName = jdbcConnection.getTnsName();
} catch (JdbcOracleThinConnectionParsingError ex) {
LOG.info(String.format(
"Unable to parse the JDBC connection URL \"%s\" as a connection "
+ "that uses the Oracle 'thin' JDBC driver.\n"
+ "This problem prevents %s from being able to dynamically generate "
+ "JDBC URLs that specify 'dedicated server connections' or spread "
+ "mapper sessions across multiple Oracle instances.\n"
+ "If the JDBC driver-type is 'OCI' (instead of 'thin'), then "
+ "load-balancing should be appropriately managed automatically.",
jdbcConnectStr, OraOopConstants.ORAOOP_PRODUCT_NAME, ex));
return;
}
if (generateRacBasedJdbcUrls) {
// Retrieve the Oracle service name to use when connecting to the RAC...
String oracleServiceName =
OraOopUtilities.getOracleServiceName(jobData.getSqoopOptions()
.getConf());
// Generate JDBC URLs for each of the mappers...
if (!oracleServiceName.isEmpty()) {
if (!generateRacJdbcConnectionUrlsByServiceName(jdbcHost, jdbcPort,
oracleServiceName, jobData)) {
throw new RuntimeException(String.format(
"Unable to connect to the Oracle database at %s "
+ "via the service name \"%s\".", jobData.getSqoopOptions()
.getConnectString(), oracleServiceName));
}
} else {
generateJdbcConnectionUrlsByActiveInstance(activeInstances, jdbcPort,
jobData);
}
} else {
generateJdbcConnectionUrlsByTnsnameSidOrService(jdbcHost, jdbcPort,
jdbcSid, jdbcService, jdbcTnsName, jobData);
}
}