Search in sources :

Example 1 with ManagedResourceStatus

use of com.redhat.service.smartevents.infra.models.dto.ManagedResourceStatus in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class MetricsServiceImplTest method onOperationComplete_forProcessor.

@ParameterizedTest
@EnumSource(MetricsOperation.class)
public void onOperationComplete_forProcessor(MetricsOperation metricsOperation) {
    Bridge bridge = Fixtures.createBridge();
    ManagedResourceStatus status = metricsOperation == MetricsOperation.DELETE ? ManagedResourceStatus.DELETED : ManagedResourceStatus.READY;
    Processor processor = Fixtures.createProcessor(bridge, status);
    processor.setSubmittedAt(ZonedDateTime.now().minusMinutes(4));
    processor.setPublishedAt(ZonedDateTime.now().minusMinutes(3));
    processor.setModifiedAt(ZonedDateTime.now().minusMinutes(2));
    processor.setDeletionRequestedAt(ZonedDateTime.now().minusMinutes(1));
    metricsService.onOperationComplete(processor, metricsOperation);
    List<Tag> expectedTags = createdExpectedTags(processor, metricsOperation);
    assertThat(meterRegistry.counter(operationTotalSuccessCountMetricName, expectedTags).count()).isEqualTo(1.0);
    assertThat(meterRegistry.timer(operatonDurationMetricName, expectedTags).totalTime(TimeUnit.MINUTES)).isNotEqualTo(0);
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor) ManagedResourceStatus(com.redhat.service.smartevents.infra.models.dto.ManagedResourceStatus) Tag(io.micrometer.core.instrument.Tag) Bridge(com.redhat.service.smartevents.manager.models.Bridge) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with ManagedResourceStatus

use of com.redhat.service.smartevents.infra.models.dto.ManagedResourceStatus in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorDAO method getProcessorIds.

private ProcessorResults getProcessorIds(String customerId, String bridgeId, QueryProcessorResourceInfo queryInfo, Set<ProcessorType> restrictTypes) {
    Parameters parameters = Parameters.with("customerId", customerId).and("bridgeId", bridgeId);
    PanacheQuery<Processor> query = find("#PROCESSOR.findByBridgeIdAndCustomerIdNoFilter", parameters);
    // filter by name
    String filterName = queryInfo.getFilterInfo().getFilterName();
    if (Objects.nonNull(filterName)) {
        query.filter("byName", Parameters.with("name", filterName + "%"));
    }
    // filter by status
    Set<ManagedResourceStatus> filterStatus = queryInfo.getFilterInfo().getFilterStatus();
    if (Objects.nonNull(filterStatus) && !filterStatus.isEmpty()) {
        query.filter("byStatus", Parameters.with("status", filterStatus));
    }
    // filter by type, considering onlyUserVisible flag
    ProcessorType filterType = queryInfo.getFilterInfo().getFilterType();
    if (restrictTypes != null) {
        if (Objects.isNull(filterType)) {
            query.filter(BY_TYPE_FILTER_NAME, Parameters.with(BY_TYPE_FILTER_PARAM, restrictTypes));
        } else {
            if (restrictTypes.contains(filterType)) {
                query.filter(BY_TYPE_FILTER_NAME, Parameters.with(BY_TYPE_FILTER_PARAM, Set.of(filterType)));
            } else {
                return new ProcessorResults(emptyList(), 0);
            }
        }
    } else {
        if (Objects.nonNull(filterType)) {
            query.filter(BY_TYPE_FILTER_NAME, Parameters.with(BY_TYPE_FILTER_PARAM, Set.of(filterType)));
        }
    }
    long total = query.count();
    List<Processor> processors = query.page(queryInfo.getPageNumber(), queryInfo.getPageSize()).list();
    List<String> ids = processors.stream().map(Processor::getId).collect(Collectors.toList());
    return new ProcessorResults(ids, total);
}
Also used : Parameters(io.quarkus.panache.common.Parameters) Processor(com.redhat.service.smartevents.manager.models.Processor) ProcessorType(com.redhat.service.smartevents.infra.models.processors.ProcessorType) ManagedResourceStatus(com.redhat.service.smartevents.infra.models.dto.ManagedResourceStatus)

Example 3 with ManagedResourceStatus

use of com.redhat.service.smartevents.infra.models.dto.ManagedResourceStatus in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeDAO method findByCustomerId.

public ListResult<Bridge> findByCustomerId(String customerId, QueryResourceInfo queryInfo) {
    Parameters parameters = Parameters.with("customerId", customerId);
    PanacheQuery<Bridge> query = find("#BRIDGE.findByCustomerId", parameters);
    String filterName = queryInfo.getFilterInfo().getFilterName();
    Set<ManagedResourceStatus> filterStatus = queryInfo.getFilterInfo().getFilterStatus();
    if (Objects.nonNull(filterName)) {
        query.filter("byName", Parameters.with("name", filterName + "%"));
    }
    if (Objects.nonNull(filterStatus) && !filterStatus.isEmpty()) {
        query.filter("byStatus", Parameters.with("status", filterStatus));
    }
    long total = query.count();
    List<Bridge> bridges = query.page(queryInfo.getPageNumber(), queryInfo.getPageSize()).list();
    return new ListResult<>(bridges, queryInfo.getPageNumber(), total);
}
Also used : ListResult(com.redhat.service.smartevents.infra.models.ListResult) Parameters(io.quarkus.panache.common.Parameters) ManagedResourceStatus(com.redhat.service.smartevents.infra.models.dto.ManagedResourceStatus) Bridge(com.redhat.service.smartevents.manager.models.Bridge)

Example 4 with ManagedResourceStatus

use of com.redhat.service.smartevents.infra.models.dto.ManagedResourceStatus in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class MetricsServiceImplTest method onOperationStart_forProcessor.

@ParameterizedTest
@EnumSource(MetricsOperation.class)
public void onOperationStart_forProcessor(MetricsOperation metricsOperation) {
    Bridge bridge = Fixtures.createBridge();
    ManagedResourceStatus status = metricsOperation == MetricsOperation.DELETE ? ManagedResourceStatus.DEPROVISION : ManagedResourceStatus.ACCEPTED;
    Processor processor = Fixtures.createProcessor(bridge, status);
    metricsService.onOperationStart(processor, metricsOperation);
    List<Tag> expectedTags = createdExpectedTags(processor, metricsOperation);
    assertThat(meterRegistry.counter(operationTotalCountMetricName, expectedTags).count()).isEqualTo(1.0);
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor) ManagedResourceStatus(com.redhat.service.smartevents.infra.models.dto.ManagedResourceStatus) Tag(io.micrometer.core.instrument.Tag) Bridge(com.redhat.service.smartevents.manager.models.Bridge) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with ManagedResourceStatus

use of com.redhat.service.smartevents.infra.models.dto.ManagedResourceStatus in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class MetricsServiceImplTest method onOperationComplete_forBridge.

@ParameterizedTest
@EnumSource(MetricsOperation.class)
public void onOperationComplete_forBridge(MetricsOperation metricsOperation) {
    Bridge bridge = Fixtures.createBridge();
    ManagedResourceStatus status = metricsOperation == MetricsOperation.DELETE ? ManagedResourceStatus.DELETED : ManagedResourceStatus.READY;
    bridge.setSubmittedAt(ZonedDateTime.now().minusMinutes(4));
    bridge.setPublishedAt(ZonedDateTime.now().minusMinutes(3));
    bridge.setModifiedAt(ZonedDateTime.now().minusMinutes(3));
    bridge.setDeletionRequestedAt(ZonedDateTime.now().minusMinutes(1));
    bridge.setStatus(status);
    metricsService.onOperationComplete(bridge, metricsOperation);
    List<Tag> expectedTags = createdExpectedTags(bridge, metricsOperation);
    assertThat(meterRegistry.counter(operationTotalSuccessCountMetricName, expectedTags).count()).isEqualTo(1.0);
    assertThat(meterRegistry.timer(operatonDurationMetricName, expectedTags).totalTime(TimeUnit.MINUTES)).isNotEqualTo(0);
}
Also used : ManagedResourceStatus(com.redhat.service.smartevents.infra.models.dto.ManagedResourceStatus) Tag(io.micrometer.core.instrument.Tag) Bridge(com.redhat.service.smartevents.manager.models.Bridge) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ManagedResourceStatus (com.redhat.service.smartevents.infra.models.dto.ManagedResourceStatus)6 Bridge (com.redhat.service.smartevents.manager.models.Bridge)5 Tag (io.micrometer.core.instrument.Tag)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 EnumSource (org.junit.jupiter.params.provider.EnumSource)4 Processor (com.redhat.service.smartevents.manager.models.Processor)3 Parameters (io.quarkus.panache.common.Parameters)2 ListResult (com.redhat.service.smartevents.infra.models.ListResult)1 ProcessorType (com.redhat.service.smartevents.infra.models.processors.ProcessorType)1