Search in sources :

Example 1 with ServerInformationDao

use of org.finos.waltz.data.server_information.ServerInformationDao in project waltz by khartec.

the class ServerGenerator method create.

@Override
public Map<String, Integer> create(ApplicationContext ctx) {
    ServerInformationDao serverDao = ctx.getBean(ServerInformationDao.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    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).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").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(SAMPLE_DATA_PROVENANCE).lifecycleStatus(randomPick(LifecycleStatus.values())).externalId(mkExernalId(i)).build());
    });
    serverDao.bulkSave(servers);
    // create server usages
    List<Long> appIds = getAppIds(dsl);
    List<Long> serverIds = getServerIds(dsl);
    HashSet<Tuple2<Long, Long>> serverAppMappings = new HashSet<>();
    IntStream.range(0, 20_000).forEach(i -> {
        serverAppMappings.add(Tuple.tuple(randomPick(serverIds), randomPick(appIds)));
    });
    List<ServerUsageRecord> serverUsages = serverAppMappings.stream().map(t -> mkServerUsageRecord(t.v1, t.v2)).collect(Collectors.toList());
    dsl.batchInsert(serverUsages).execute();
    return null;
}
Also used : IntStream(java.util.stream.IntStream) java.util(java.util) EntityKind(org.finos.waltz.model.EntityKind) ImmutableServerInformation(org.finos.waltz.model.server_information.ImmutableServerInformation) ServerInformationDao(org.finos.waltz.data.server_information.ServerInformationDao) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) LifecycleStatus(org.finos.waltz.model.LifecycleStatus) Date(java.sql.Date) RandomUtilities(org.finos.waltz.common.RandomUtilities) Tuple2(org.jooq.lambda.tuple.Tuple2) SERVER_USAGE(org.finos.waltz.schema.tables.ServerUsage.SERVER_USAGE) Tuple(org.jooq.lambda.tuple.Tuple) SERVER_INFORMATION(org.finos.waltz.schema.tables.ServerInformation.SERVER_INFORMATION) ListUtilities(org.finos.waltz.common.ListUtilities) ServerInformation(org.finos.waltz.model.server_information.ServerInformation) LocalDate(java.time.LocalDate) RandomUtilities.randomPick(org.finos.waltz.common.RandomUtilities.randomPick) DSLContext(org.jooq.DSLContext) ServerUsageRecord(org.finos.waltz.schema.tables.records.ServerUsageRecord) ServerInformationDao(org.finos.waltz.data.server_information.ServerInformationDao) DSLContext(org.jooq.DSLContext) ImmutableServerInformation(org.finos.waltz.model.server_information.ImmutableServerInformation) ServerInformation(org.finos.waltz.model.server_information.ServerInformation) Tuple2(org.jooq.lambda.tuple.Tuple2) ServerUsageRecord(org.finos.waltz.schema.tables.records.ServerUsageRecord)

Example 2 with ServerInformationDao

use of org.finos.waltz.data.server_information.ServerInformationDao in project waltz by khartec.

the class ServerHarness method main.

public static void main(String[] args) {
    System.out.println("start");
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIBaseConfiguration.class);
    ServerInformationDao serverInfoDao = ctx.getBean(ServerInformationDao.class);
    IdSelectionOptions mOpts = mkOpts(mkRef(EntityKind.MEASURABLE, 1), HierarchyQueryScope.CHILDREN);
    IdSelectionOptions pOpts = mkOpts(mkRef(EntityKind.PERSON, 2), HierarchyQueryScope.CHILDREN);
    IdSelectionOptions ouOpts = mkOpts(mkRef(EntityKind.ORG_UNIT, 3), HierarchyQueryScope.CHILDREN);
    IdSelectionOptions agOpts = mkOpts(mkRef(EntityKind.APP_GROUP, 4), HierarchyQueryScope.EXACT);
    System.out.println("start timer");
    ListUtilities.asList(mOpts, pOpts, ouOpts, agOpts).forEach(opts -> {
        FunctionUtilities.time("stats: " + opts.entityReference(), () -> {
            Select<Record1<Long>> selector = new ApplicationIdSelectorFactory().apply(opts);
            return serverInfoDao.calculateStatsForAppSelector(selector);
        });
    });
    System.out.println("end");
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ServerInformationDao(org.finos.waltz.data.server_information.ServerInformationDao) ApplicationIdSelectorFactory(org.finos.waltz.data.application.ApplicationIdSelectorFactory) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) Record1(org.jooq.Record1)

Aggregations

ServerInformationDao (org.finos.waltz.data.server_information.ServerInformationDao)2 Date (java.sql.Date)1 LocalDate (java.time.LocalDate)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 ListUtilities (org.finos.waltz.common.ListUtilities)1 RandomUtilities (org.finos.waltz.common.RandomUtilities)1 RandomUtilities.randomPick (org.finos.waltz.common.RandomUtilities.randomPick)1 ApplicationIdSelectorFactory (org.finos.waltz.data.application.ApplicationIdSelectorFactory)1 EntityKind (org.finos.waltz.model.EntityKind)1 IdSelectionOptions (org.finos.waltz.model.IdSelectionOptions)1 LifecycleStatus (org.finos.waltz.model.LifecycleStatus)1 ImmutableServerInformation (org.finos.waltz.model.server_information.ImmutableServerInformation)1 ServerInformation (org.finos.waltz.model.server_information.ServerInformation)1 SERVER_INFORMATION (org.finos.waltz.schema.tables.ServerInformation.SERVER_INFORMATION)1 SERVER_USAGE (org.finos.waltz.schema.tables.ServerUsage.SERVER_USAGE)1 ServerUsageRecord (org.finos.waltz.schema.tables.records.ServerUsageRecord)1 DSLContext (org.jooq.DSLContext)1 Record1 (org.jooq.Record1)1