@Override protected void validate(List<TableInfo> tableInfos) { if (!clusterManager.hasBucket(databaseName)) { throw new SchemaGenerationException("Bucket [" + databaseName + "] does not exist."); } }
@Override public void dropSchema() { try { if (operation != null && ("create-drop").equalsIgnoreCase(operation)) { r.dbDrop(databaseName); } } catch (Exception e) { logger.error("Error while dropping schema", e); throw new SchemaGenerationException(e, "RethinkDB"); } }
/** * Creates schema and table for the list of tableInfos. * * @param tableInfos * list of TableInfos. */ protected void create(List<TableInfo> tableInfos) { try { createOrUpdateKeyspace(tableInfos); } catch (Exception ex) { throw new SchemaGenerationException(ex); } }
/** * update method update schema and table for the list of tableInfos. * * @param tableInfos * list of TableInfos. */ protected void update(List<TableInfo> tableInfos) { try { createOrUpdateKeyspace(tableInfos); } catch (Exception ex) { log.error("Error occurred while creating {}, Caused by: .", databaseName, ex); throw new SchemaGenerationException(ex); } }
/** * drop schema method drop the table from keyspace. * */ public void dropSchema() { if (operation != null && operation.equalsIgnoreCase("create-drop")) { try { dropKeyspaceOrCFs(); } catch (Exception ex) { log.error("Error during dropping schema in cassandra, Caused by: .", ex); throw new SchemaGenerationException(ex, "Cassandra"); } } cassandra_client = null; }
@Override protected boolean initiateClient() { for (String host : hosts) { if (host == null || !StringUtils.isNumeric(port) || port.isEmpty()) { logger.error("Host or port should not be null / port should be numeric"); throw new IllegalArgumentException("Host or port should not be null / port should be numeric"); } try { client = new KuduClient.KuduClientBuilder(host + ":" + port).build(); } catch (Exception e) { logger.error("Database host cannot be resolved, Caused by: " + e.getMessage()); throw new SchemaGenerationException("Database host cannot be resolved, Caused by: " + e.getMessage()); } } return true; }
@Override public void dropSchema() { for (TableInfo tableInfo : tableInfos) { try { client.deleteTable(tableInfo.getTableName()); } catch (Exception ex) { logger.error("Error during deleting tables in kudu, Caused by: ", ex); throw new SchemaGenerationException(ex, "Kudu"); } } }
@Override public void dropSchema() { // dropping all the tables in the Oracle NoSQL store if (operation != null && operation.equalsIgnoreCase("create-drop")) { for (TableInfo tableInfo : tableInfos) { try { StatementResult result = tableAPI.executeSync("DROP TABLE IF EXISTS " + tableInfo.getTableName()); if (!result.isSuccessful()) { throw new SchemaGenerationException("Unable to DROP TABLE " + tableInfo.getTableName()); } } catch (IllegalArgumentException e) { logger.error("Invalid DROP TABLE Statement. Caused By: ", e); throw new SchemaGenerationException(e, "Invalid DROP TABLE Statement. Caused By: "); } catch (FaultException e) { logger.error("DROP TABLE Statement couldn't be executed. Caused By: ", e); throw new SchemaGenerationException(e, "Invalid DROP TABLE Statement is executed. Caused By: "); } } } }
/** * validate method validate schema and table for the list of tableInfos. * * @param tableInfos * list of TableInfos. */ protected void validate(List<TableInfo> tableInfos) { try { KsDef ksDef = cassandra_client.describe_keyspace(databaseName); onValidateTables(tableInfos, ksDef); } catch (Exception ex) { log.error("Error occurred while validating {}, Caused by: .", databaseName, ex); throw new SchemaGenerationException(ex); } }
@Override protected boolean initiateClient() { for (String host : hosts) { if (host == null || !StringUtils.isNumeric(port) || port.isEmpty()) { logger.error("Host or port should not be null / port should be numeric"); throw new IllegalArgumentException("Host or port should not be null / port should be numeric"); } try { connection = r.connection().hostname(host).port(Integer.parseInt(port)).connect(); } catch (Exception e) { logger.error("Database host/port cannot be resolved, Caused by: " + e.getMessage()); throw new SchemaGenerationException("Database host/port cannot be resolved, Caused by: " + e.getMessage()); } } return true; }
/** * Checks if is namespace available. * * @param databaseName * the database name * @return true, if is namespace available */ private boolean isNamespaceAvailable(String databaseName) { try { for (NamespaceDescriptor ns : admin.listNamespaceDescriptors()) { if (ns.getName().equals(databaseName)) { return true; } } return false; } catch (IOException ioex) { logger.error("Either table isn't in enabled state or some network problem, Caused by: ", ioex); throw new SchemaGenerationException(ioex, "Either table isn't in enabled state or some network problem."); } }
/** * Validate compound key. * * @param tableInfo * the table info */ private void validateCompoundKey(TableInfo tableInfo) { if (tableInfo.getType() != null && tableInfo.getType().equals(Type.SUPER_COLUMN_FAMILY.name())) { throw new SchemaGenerationException( "Composite/Compound columns are not yet supported over Super column family by Cassandra", "cassandra", databaseName); } }
@Override protected void validate(List<TableInfo> tableInfos) { for (TableInfo tableInfo : tableInfos) { try { if (!client.tableExists(tableInfo.getTableName())) { throw new SchemaGenerationException("Table: " + tableInfo.getTableName() + " does not exist "); } } catch (Exception e) { logger.error("Error while validating tables, Caused by: " + e.getMessage()); throw new KunderaException("Error while validating tables, Caused by: " + e.getMessage()); } } }
@Test public void testSchemaGenerationException() { SchemaGenerationException exception = new SchemaGenerationException("Error with string"); Assert.assertNotNull(exception); exception = new SchemaGenerationException(new RuntimeException()); Assert.assertNotNull(exception); exception = new SchemaGenerationException(new RuntimeException(),"KunderaTests"); Assert.assertNotNull(exception); exception = new SchemaGenerationException(new RuntimeException(),"KunderaTests","test"); Assert.assertNotNull(exception); exception = new SchemaGenerationException(new RuntimeException(),"KunderaTests","test"); Assert.assertNotNull(exception); exception = new SchemaGenerationException("error with string ",new RuntimeException(),"KunderaTests","test"); Assert.assertNotNull(exception); exception = new SchemaGenerationException("error with string ", "cassandra", "KunderaTests","test"); Assert.assertNotNull(exception); exception = new SchemaGenerationException("error with string ","KunderaTests","test"); Assert.assertNotNull(exception); exception = new SchemaGenerationException("error with string ",new RuntimeException(),"KunderaTests"); Assert.assertNotNull(exception); }
@Override protected void validate(List<TableInfo> tableInfos) { for (TableInfo tableInfo : tableInfos) { try { if (tableAPI.getTable(tableInfo.getTableName()) == null) { logger.error("No table found for " + tableInfo.getTableName()); throw new SchemaGenerationException("No table found for " + tableInfo.getTableName()); } } catch (FaultException e) { logger.error("Error while getting table " + tableInfo.getTableName() + ". Caused By: ", e); throw new SchemaGenerationException(e, "Error while getting table " + tableInfo.getTableName() + ". Caused By: "); } } }
@Override protected void validate(List<TableInfo> tableInfos) { List listTables = r.db(databaseName).tableList().run(connection); for (TableInfo tableInfo : tableInfos) { try { if (!listTables.contains(tableInfo.getTableName())) { throw new SchemaGenerationException("Table: " + tableInfo.getTableName() + " does not exist "); } } catch (Exception e) { logger.error("Error while validating tables, Caused by: " + e.getMessage()); throw new KunderaException("Error while validating tables, Caused by: " + e.getMessage()); } } }
/** * Creates the or update table. * * @param tablename * the tablename * @param hTableDescriptor * the h table descriptor */ private void createOrUpdateTable(String tablename, HTableDescriptor hTableDescriptor) { try { if (admin.isTableAvailable(tablename)) { admin.modifyTable(tablename, hTableDescriptor); } else { admin.createTable(hTableDescriptor); } } catch (IOException ioex) { logger.error("Either table isn't in enabled state or some network problem, Caused by: ", ioex); throw new SchemaGenerationException(ioex, "Either table isn't in enabled state or some network problem."); } }
/** * update method update schema and table for the list of tableInfos * * @param tableInfos * list of TableInfos. */ protected void update(List<TableInfo> tableInfos) { try { if (admin.isTableAvailable(databaseName)) { HTableDescriptor hTableDescriptor = admin.getTableDescriptor(databaseName.getBytes()); addColumnFamilies(tableInfos, hTableDescriptor, true); } else { createTable(tableInfos); } } catch (IOException ioe) { logger.error("Either check for network connection or table isn't in enabled state, Caused by:", ioe); throw new SchemaGenerationException(ioe, "Hbase"); } }
/** * Creates the namespace. * * @param isUpdate * the is update */ private void createNamespace(boolean isUpdate) { boolean isNameSpaceAvailable = isNamespaceAvailable(databaseName); if (isNameSpaceAvailable && !isUpdate) { drop(); } if (!(isNameSpaceAvailable && isUpdate)) { try { NamespaceDescriptor descriptor = NamespaceDescriptor.create(databaseName).build(); admin.createNamespace(descriptor); } catch (IOException ioex) { logger.error("Either table isn't in enabled state or some network problem, Caused by: ", ioex); throw new SchemaGenerationException(ioex, "Hbase"); } } }
/** * Assert drop. */ private void assertDrop() { try { for (NamespaceDescriptor ns : admin.listNamespaceDescriptors()) { if (ns.getName().equals(SCHEMA)) { Assert.assertTrue(false); break; } } } catch (IOException ioex) { throw new SchemaGenerationException(ioex, "Hbase"); } }