@@ -843,77 +843,83 @@ public Boolean runTableSql(TableMirror tblMirror, Environment environment) {
843
843
public Boolean runTableSql (List <Pair > sqlList , TableMirror tblMirror , Environment environment ) {
844
844
Boolean rtn = Boolean .TRUE ;
845
845
HmsMirrorConfig config = executeSessionService .getSession ().getConfig ();
846
+ // Check if there is anything to run.
847
+ if (nonNull (sqlList ) && !sqlList .isEmpty ()) {
848
+ // Check if the cluster is connected. This could happen if the cluster is a virtual cluster created as a place holder for processing.
849
+ if (nonNull (config .getCluster (environment )) && nonNull (config .getCluster (environment ).getHiveServer2 ()) &&
850
+ !config .getCluster (environment ).getHiveServer2 ().isDisconnected ()) {
851
+ // Skip this if using test data.
852
+ if (!config .isLoadingTestData ()) {
853
+
854
+ try (Connection conn = getConnectionPoolService ().getHS2EnvironmentConnection (environment )) {
855
+ if (isNull (conn ) && config .isExecute () && !config .getCluster (environment ).getHiveServer2 ().isDisconnected ()) {
856
+ // this is a problem.
857
+ rtn = Boolean .FALSE ;
858
+ tblMirror .addIssue (environment , "Connection missing. This is a bug." );
859
+ }
846
860
847
- // Skip this if using test data.
848
- if (!config .isLoadingTestData ()) {
849
-
850
- try (Connection conn = getConnectionPoolService ().getHS2EnvironmentConnection (environment )) {
851
- if (isNull (conn ) && config .isExecute () && !config .getCluster (environment ).getHiveServer2 ().isDisconnected ()) {
852
- // this is a problem.
853
- rtn = Boolean .FALSE ;
854
- tblMirror .addIssue (environment , "Connection missing. This is a bug." );
855
- }
856
-
857
- if (isNull (conn ) && config .getCluster (environment ).getHiveServer2 ().isDisconnected ()) {
858
- tblMirror .addIssue (environment , "Running in 'disconnected' mode. NO RIGHT operations will be done. " +
859
- "The scripts will need to be run 'manually'." );
860
- }
861
+ if (isNull (conn ) && config .getCluster (environment ).getHiveServer2 ().isDisconnected ()) {
862
+ tblMirror .addIssue (environment , "Running in 'disconnected' mode. NO RIGHT operations will be done. " +
863
+ "The scripts will need to be run 'manually'." );
864
+ }
861
865
862
- if (rtn && nonNull (conn )) {
863
- try (Statement stmt = conn .createStatement ()) {
864
- for (Pair pair : sqlList ) {
865
- String action = pair .getAction ();
866
- if (action .trim ().isEmpty () || action .trim ().startsWith ("--" )) {
867
- continue ;
868
- } else {
869
- log .debug ("{}:SQL:{}:{}" , environment , pair .getDescription (), pair .getAction ());
870
- tblMirror .setMigrationStageMessage ("Executing SQL: " + pair .getDescription ());
871
- if (config .isExecute ()) {
872
- // Log the Return of 'set' commands.
873
- if (pair .getAction ().trim ().toLowerCase ().startsWith ("set" )) {
874
- stmt .execute (pair .getAction ());
875
- try {
876
- // Check for a result set and print result if present.
877
- ResultSet resultSet = stmt .getResultSet ();
878
- if (!isNull (resultSet )) {
879
- while (resultSet .next ()) {
880
- tblMirror .addStep (environment .toString (), "Sql Run Complete for: " + pair .getDescription () + " : " + resultSet .getString (1 ));
881
- log .info ("{}:{}" , pair .getAction (), resultSet .getString (1 ));
866
+ if (rtn && nonNull (conn )) {
867
+ try (Statement stmt = conn .createStatement ()) {
868
+ for (Pair pair : sqlList ) {
869
+ String action = pair .getAction ();
870
+ if (action .trim ().isEmpty () || action .trim ().startsWith ("--" )) {
871
+ continue ;
872
+ } else {
873
+ log .debug ("{}:SQL:{}:{}" , environment , pair .getDescription (), pair .getAction ());
874
+ tblMirror .setMigrationStageMessage ("Executing SQL: " + pair .getDescription ());
875
+ if (config .isExecute ()) {
876
+ // Log the Return of 'set' commands.
877
+ if (pair .getAction ().trim ().toLowerCase ().startsWith ("set" )) {
878
+ stmt .execute (pair .getAction ());
879
+ try {
880
+ // Check for a result set and print result if present.
881
+ ResultSet resultSet = stmt .getResultSet ();
882
+ if (!isNull (resultSet )) {
883
+ while (resultSet .next ()) {
884
+ tblMirror .addStep (environment .toString (), "Sql Run Complete for: " + pair .getDescription () + " : " + resultSet .getString (1 ));
885
+ log .info ("{}:{}" , pair .getAction (), resultSet .getString (1 ));
886
+ }
887
+ } else {
888
+ tblMirror .addStep (environment .toString (), "Sql Run Complete for: " + pair .getDescription ());
889
+ }
890
+ } catch (SQLException se ) {
891
+ // Otherwise, just log command.
892
+ tblMirror .addStep (environment .toString (), "Sql Run Complete for: " + pair .getDescription ());
882
893
}
883
894
} else {
895
+ stmt .execute (pair .getAction ());
884
896
tblMirror .addStep (environment .toString (), "Sql Run Complete for: " + pair .getDescription ());
885
897
}
886
- } catch (SQLException se ) {
887
- // Otherwise, just log command.
888
- tblMirror .addStep (environment .toString (), "Sql Run Complete for: " + pair .getDescription ());
898
+ } else {
899
+ tblMirror .addStep (environment .toString (), "Sql Run SKIPPED (DRY-RUN) for: " + pair .getDescription ());
889
900
}
890
- } else {
891
- stmt .execute (pair .getAction ());
892
- tblMirror .addStep (environment .toString (), "Sql Run Complete for: " + pair .getDescription ());
893
901
}
894
- } else {
895
- tblMirror .addStep (environment .toString (), "Sql Run SKIPPED (DRY-RUN) for: " + pair .getDescription ());
896
902
}
903
+ } catch (SQLException throwables ) {
904
+ log .error ("{}:{}" , environment .toString (), throwables .getMessage (), throwables );
905
+ String message = throwables .getMessage ();
906
+ if (throwables .getMessage ().contains ("HiveAccessControlException Permission denied" )) {
907
+ message = message + " See [Hive SQL Exception / HDFS Permissions Issues](https://github.com/cloudera-labs/hms-mirror#hive-sql-exception--hdfs-permissions-issues)" ;
908
+ }
909
+ if (throwables .getMessage ().contains ("AvroSerdeException" )) {
910
+ message = message + ". It's possible the `avro.schema.url` referenced file doesn't exist at the target. " +
911
+ "Use the `-asm` option and hms-mirror will attempt to copy it to the new cluster." ;
912
+ }
913
+ tblMirror .getEnvironmentTable (environment ).addError (message );
914
+ rtn = Boolean .FALSE ;
897
915
}
898
916
}
899
917
} catch (SQLException throwables ) {
918
+ tblMirror .getEnvironmentTable (environment ).addError ("Connecting: " + throwables .getMessage ());
900
919
log .error ("{}:{}" , environment .toString (), throwables .getMessage (), throwables );
901
- String message = throwables .getMessage ();
902
- if (throwables .getMessage ().contains ("HiveAccessControlException Permission denied" )) {
903
- message = message + " See [Hive SQL Exception / HDFS Permissions Issues](https://github.com/cloudera-labs/hms-mirror#hive-sql-exception--hdfs-permissions-issues)" ;
904
- }
905
- if (throwables .getMessage ().contains ("AvroSerdeException" )) {
906
- message = message + ". It's possible the `avro.schema.url` referenced file doesn't exist at the target. " +
907
- "Use the `-asm` option and hms-mirror will attempt to copy it to the new cluster." ;
908
- }
909
- tblMirror .getEnvironmentTable (environment ).addError (message );
910
920
rtn = Boolean .FALSE ;
911
921
}
912
922
}
913
- } catch (SQLException throwables ) {
914
- tblMirror .getEnvironmentTable (environment ).addError ("Connecting: " + throwables .getMessage ());
915
- log .error ("{}:{}" , environment .toString (), throwables .getMessage (), throwables );
916
- rtn = Boolean .FALSE ;
917
923
}
918
924
}
919
925
return rtn ;
0 commit comments