Search in sources :

Example 1 with ServerInformationDao

use of com.khartec.waltz.data.server_information.ServerInformationDao in project waltz by khartec.

the class ServerHarness method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    ServerInformationService serverInfoService = ctx.getBean(ServerInformationService.class);
    ServerInformationDao serverInfoDao = ctx.getBean(ServerInformationDao.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    IdSelectionOptions options = ImmutableIdSelectionOptions.builder().entityReference(ImmutableEntityReference.builder().kind(EntityKind.ORG_UNIT).id(10).build()).scope(HierarchyQueryScope.CHILDREN).build();
    for (int i = 0; i < 5; i++) {
        HarnessUtilities.time("stats", () -> serverInfoService.findStatsForAppSelector(options));
    }
    String sql = "\n" + "select \n" + "  coalesce(\n" + "    sum(case [server_information].[is_virtual] when 1 then 1\n" + "                                               else 0\n" + "        end), \n" + "    0) [virtual_count], \n" + "  coalesce(\n" + "    sum(case [server_information].[is_virtual] when 1 then 0\n" + "                                               else 1\n" + "        end), \n" + "    0) [physical_count]\n" + "from [server_information]\n" + "where [server_information].[asset_code] in (\n" + "  select [application].[asset_code]\n" + "  from [application]\n" + "  where [application].[id] in (\n" + "    select [application].[id]\n" + "    from [application]\n" + "    where [application].[organisational_unit_id] in (\n" + "      130, 260, 70, 200, 10, 140, 270, 80, 210, 20, 150, 280, 90, 220, 30, 160, \n" + "      290, 100, 230, 40, 170, 300, 110, 240, 50, 180, 120, 250, 60, 190\n" + "    )\n" + "  )\n" + ");\n";
    FunctionUtilities.time("raw q", () -> {
        dsl.connection(conn -> {
            PreparedStatement stmt = conn.prepareStatement(sql);
            ResultSet rs = stmt.executeQuery();
            while (rs.next()) {
                System.out.println(rs.getBigDecimal(1) + " - " + rs.getBigDecimal(2));
            }
        });
        return null;
    });
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ServerInformationDao(com.khartec.waltz.data.server_information.ServerInformationDao) ServerInformationService(com.khartec.waltz.service.server_information.ServerInformationService) ResultSet(java.sql.ResultSet) DSLContext(org.jooq.DSLContext) PreparedStatement(java.sql.PreparedStatement)

Example 2 with ServerInformationDao

use of com.khartec.waltz.data.server_information.ServerInformationDao in project waltz by khartec.

the class ServerGenerator method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    ServerInformationDao serverDao = ctx.getBean(ServerInformationDao.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    dsl.delete(SERVER_INFORMATION).where(SERVER_INFORMATION.PROVENANCE.eq("RANDOM_GENERATOR")).execute();
    commonHostNames.clear();
    List<ServerInformation> servers = ListUtilities.newArrayList();
    IntStream.range(0, 10_000).forEach(i -> {
        String hostName = mkHostName(i);
        boolean isCommonHost = commonHostNames.contains(hostName);
        servers.add(ImmutableServerInformation.builder().hostname(hostName).environment(isCommonHost ? SampleData.environments[0] : randomPick(SampleData.environments)).location(isCommonHost ? SampleData.locations[0] : randomPick(SampleData.locations)).operatingSystem(isCommonHost ? SampleData.operatingSystems[0] : randomPick(SampleData.operatingSystems)).operatingSystemVersion(isCommonHost ? SampleData.operatingSystemVersions[0] : randomPick(SampleData.operatingSystemVersions)).country("UK").assetCode("wltz-0" + rnd.nextInt(4000)).hardwareEndOfLifeDate(rnd.nextInt(10) > 5 ? Date.valueOf(LocalDate.now().plusMonths(rnd.nextInt(12 * 6) - (12 * 3))) : null).operatingSystemEndOfLifeDate(rnd.nextInt(10) > 5 ? Date.valueOf(LocalDate.now().plusMonths(rnd.nextInt(12 * 6) - (12 * 3))) : null).virtual(isCommonHost || rnd.nextInt(10) > 7).provenance("RANDOM_GENERATOR").lifecycleStatus(randomPick(LifecycleStatus.values())).build());
    });
    // servers.forEach(System.out::println);
    serverDao.bulkSave(servers);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ServerInformationDao(com.khartec.waltz.data.server_information.ServerInformationDao) ServerInformation(com.khartec.waltz.model.server_information.ServerInformation) ImmutableServerInformation(com.khartec.waltz.model.server_information.ImmutableServerInformation) DSLContext(org.jooq.DSLContext)

Aggregations

ServerInformationDao (com.khartec.waltz.data.server_information.ServerInformationDao)2 DSLContext (org.jooq.DSLContext)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 ImmutableServerInformation (com.khartec.waltz.model.server_information.ImmutableServerInformation)1 ServerInformation (com.khartec.waltz.model.server_information.ServerInformation)1 ServerInformationService (com.khartec.waltz.service.server_information.ServerInformationService)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1