Search in sources :

Example 1 with ApplicationDescriptor2

use of io.codekvast.dashboard.dashboard.model.status.ApplicationDescriptor2 in project codekvast by crispab.

the class DashboardServiceImpl method getApplications.

private List<ApplicationDescriptor2> getApplications(Long customerId, PricePlan pricePlan) {
    val startedAt = clock.instant();
    List<ApplicationDescriptor2> result = new ArrayList<>();
    jdbcTemplate.query("SELECT a.name AS appName, e.name AS envName, ad.collectedSince, ad.collectedTo\n" + "FROM application_descriptors ad\n" + "       INNER JOIN applications a ON ad.applicationId = a.id\n" + "       INNER JOIN environments e ON ad.environmentId = e.id\n" + "WHERE ad.customerId = ?\n" + "GROUP BY appName, envName\n" + "ORDER BY appName, envName\n", rs -> {
        result.add(ApplicationDescriptor2.builder().appName(rs.getString("appName")).environment(rs.getString("envName")).collectedSinceMillis(pricePlan.adjustTimestampMillis(rs.getTimestamp("collectedSince").getTime(), clock)).collectedToMillis(pricePlan.adjustTimestampMillis(rs.getTimestamp("collectedTo").getTime(), clock)).build());
    }, customerId);
    logger.debug("Fetched {} applications for customer {} in {}", result.size(), customerId, Duration.between(startedAt, clock.instant()));
    return result;
}
Also used : lombok.val(lombok.val) ApplicationDescriptor2(io.codekvast.dashboard.dashboard.model.status.ApplicationDescriptor2) ArrayList(java.util.ArrayList)

Example 2 with ApplicationDescriptor2

use of io.codekvast.dashboard.dashboard.model.status.ApplicationDescriptor2 in project codekvast by crispab.

the class DashboardServiceImpl method getStatus.

@Override
@Transactional(readOnly = true)
public GetStatusResponse getStatus() {
    long startedAt = clock.millis();
    Long customerId = customerIdProvider.getCustomerId();
    CustomerData customerData = customerService.getCustomerDataByCustomerId(customerId);
    PricePlan pricePlan = customerData.getPricePlan();
    List<EnvironmentStatusDescriptor> environments = getEnvironments(customerId);
    List<ApplicationDescriptor2> applications = getApplications(customerId, pricePlan);
    List<AgentDescriptor> agents = getAgents(customerId, pricePlan.getPublishIntervalSeconds());
    Instant now = clock.instant();
    Instant collectionStartedAt = customerData.getCollectionStartedAt();
    Instant trialPeriodEndsAt = customerData.getTrialPeriodEndsAt();
    Duration trialPeriodDuration = collectionStartedAt == null || trialPeriodEndsAt == null ? null : Duration.between(collectionStartedAt, trialPeriodEndsAt);
    Duration trialPeriodProgress = trialPeriodDuration == null ? null : Duration.between(collectionStartedAt, now);
    Integer trialPeriodPercent = trialPeriodProgress == null ? null : Math.min(100, Math.toIntExact(trialPeriodProgress.toMillis() * 100L / trialPeriodDuration.toMillis()));
    return GetStatusResponse.builder().timestamp(startedAt).queryTimeMillis(clock.millis() - startedAt).pricePlan(pricePlan.getName()).retentionPeriodDays(pricePlan.getRetentionPeriodDays()).collectionResolutionSeconds(pricePlan.getPublishIntervalSeconds()).maxNumberOfAgents(pricePlan.getMaxNumberOfAgents()).maxNumberOfMethods(pricePlan.getMaxMethods()).collectedSinceMillis(pricePlan.adjustInstantToMillis(collectionStartedAt, clock)).trialPeriodEndsAtMillis(trialPeriodEndsAt == null ? null : trialPeriodEndsAt.toEpochMilli()).trialPeriodExpired(customerData.isTrialPeriodExpired(now)).trialPeriodPercent(trialPeriodPercent).numMethods(customerService.countMethods(customerId)).numAgents(agents.size()).numLiveAgents((int) agents.stream().filter(AgentDescriptor::isAgentAlive).count()).numLiveEnabledAgents((int) agents.stream().filter(AgentDescriptor::isAgentLiveAndEnabled).count()).environments(environments).applications(applications).agents(agents).build();
}
Also used : AgentDescriptor(io.codekvast.dashboard.dashboard.model.status.AgentDescriptor) CustomerData(io.codekvast.common.customer.CustomerData) Instant(java.time.Instant) Duration(java.time.Duration) EnvironmentStatusDescriptor(io.codekvast.dashboard.dashboard.model.status.EnvironmentStatusDescriptor) PricePlan(io.codekvast.common.customer.PricePlan) ApplicationDescriptor2(io.codekvast.dashboard.dashboard.model.status.ApplicationDescriptor2) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ApplicationDescriptor2 (io.codekvast.dashboard.dashboard.model.status.ApplicationDescriptor2)2 CustomerData (io.codekvast.common.customer.CustomerData)1 PricePlan (io.codekvast.common.customer.PricePlan)1 AgentDescriptor (io.codekvast.dashboard.dashboard.model.status.AgentDescriptor)1 EnvironmentStatusDescriptor (io.codekvast.dashboard.dashboard.model.status.EnvironmentStatusDescriptor)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 lombok.val (lombok.val)1 Transactional (org.springframework.transaction.annotation.Transactional)1