Search in sources :

Example 1 with DatabaseInformationRecord

use of com.khartec.waltz.schema.tables.records.DatabaseInformationRecord in project waltz by khartec.

the class DatabaseGenerator method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    List<String> codes = dsl.select(APPLICATION.ASSET_CODE).from(APPLICATION).fetch(APPLICATION.ASSET_CODE);
    List<DatabaseInformationRecord> databaseRecords = new LinkedList<>();
    for (int i = 0; i < 300; i++) {
        int num = rnd.nextInt(10);
        for (int j = 0; j < num; j++) {
            SoftwarePackage pkg = ArrayUtilities.randomPick(DatabaseSoftwarePackages.dbs);
            DatabaseInformationRecord databaseRecord = dsl.newRecord(DATABASE_INFORMATION);
            databaseRecord.setDatabaseName("DB_LON_" + i + "_" + j);
            databaseRecord.setInstanceName("DB_INST_" + i);
            databaseRecord.setEnvironment(ArrayUtilities.randomPick("PROD", "PROD", "QA", "DEV", "DEV"));
            databaseRecord.setDbmsVendor(pkg.vendor());
            databaseRecord.setDbmsName(pkg.name());
            databaseRecord.setDbmsVersion(pkg.version());
            databaseRecord.setExternalId("ext_" + i + "_" + j);
            databaseRecord.setProvenance("RANDOM_GENERATOR");
            databaseRecord.setAssetCode(randomPick(codes));
            databaseRecord.setLifecycleStatus(ArrayUtilities.randomPick(LifecycleStatus.values()).toString());
            databaseRecord.setEndOfLifeDate(rnd.nextInt(10) > 5 ? Date.valueOf(LocalDate.now().plusMonths(rnd.nextInt(12 * 6) - (12 * 3))) : null);
            databaseRecords.add(databaseRecord);
        }
    }
    // insert duplicate database instance records (more than one app using the same database)
    SoftwarePackage dupDbPackage = ArrayUtilities.randomPick(DatabaseSoftwarePackages.dbs);
    String dupDbEnvironment = ArrayUtilities.randomPick("PROD", "PROD", "QA", "DEV", "DEV");
    Date dupDbEolDate = rnd.nextInt(10) > 5 ? Date.valueOf(LocalDate.now().plusMonths(rnd.nextInt(12 * 6) - (12 * 3))) : null;
    for (int i = 0; i < 10; i++) {
        DatabaseInformationRecord databaseRecord = dsl.newRecord(DATABASE_INFORMATION);
        databaseRecord.setDatabaseName("DB_LON_REF_DATA");
        databaseRecord.setInstanceName("DB_INST_REF_DATA");
        databaseRecord.setEnvironment(dupDbEnvironment);
        databaseRecord.setDbmsVendor(dupDbPackage.vendor());
        databaseRecord.setDbmsName(dupDbPackage.name());
        databaseRecord.setDbmsVersion(dupDbPackage.version());
        databaseRecord.setExternalId("ext_ref_data");
        databaseRecord.setProvenance("RANDOM_GENERATOR");
        databaseRecord.setAssetCode(randomPick(codes));
        databaseRecord.setLifecycleStatus(ArrayUtilities.randomPick(LifecycleStatus.values()).toString());
        databaseRecord.setEndOfLifeDate(dupDbEolDate);
        databaseRecords.add(databaseRecord);
    }
    System.out.println("-- deleting db records");
    dsl.deleteFrom(DATABASE_INFORMATION).where(DATABASE_INFORMATION.PROVENANCE.eq("RANDOM_GENERATOR")).execute();
    System.out.println("-- storing db records ( " + databaseRecords.size() + " )");
    databaseRecords.forEach(r -> r.store());
    System.out.println("-- done inserting db records");
    System.out.println("-- done");
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DatabaseInformationRecord(com.khartec.waltz.schema.tables.records.DatabaseInformationRecord) DSLContext(org.jooq.DSLContext) SoftwarePackage(com.khartec.waltz.model.software_catalog.SoftwarePackage) LinkedList(java.util.LinkedList) Date(java.sql.Date) LocalDate(java.time.LocalDate)

Aggregations

SoftwarePackage (com.khartec.waltz.model.software_catalog.SoftwarePackage)1 DatabaseInformationRecord (com.khartec.waltz.schema.tables.records.DatabaseInformationRecord)1 Date (java.sql.Date)1 LocalDate (java.time.LocalDate)1 LinkedList (java.util.LinkedList)1 DSLContext (org.jooq.DSLContext)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1