Skip to content

Commit

Permalink
SWATCH-2018: Report filtered instance data to Export Service in JSON
Browse files Browse the repository at this point in the history
- configured the export listener for the tally service (worker profile)
- report the instances data as JSON
- generated instances export POJOs from JSON schemas
  • Loading branch information
Sgitario authored and jcarvaja committed Apr 18, 2024
1 parent 7772006 commit 7169f8f
Show file tree
Hide file tree
Showing 17 changed files with 899 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public interface DataExporterService<T extends Serializable, U> {

Stream<T> fetchData(ExportServiceRequest request);

U mapDataItem(T item);
U mapDataItem(T item, ExportServiceRequest request);

default U mapDataItem(Object item) {
return mapDataItem(getDataClass().cast(item));
default U mapDataItem(Object item, ExportServiceRequest request) {
return mapDataItem(getDataClass().cast(item), request);
}

Class<T> getDataClass();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import com.redhat.swatch.clients.export.api.model.DownloadExportErrorRequest;
import com.redhat.swatch.clients.export.api.resources.ExportApi;
import io.micrometer.core.annotation.Timed;
import jakarta.transaction.Transactional;
import jakarta.ws.rs.core.Response.Status;
import java.io.File;
import java.io.FileOutputStream;
Expand All @@ -49,6 +48,7 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/** Listener for Export messages from Kafka */
@Service
Expand Down Expand Up @@ -82,7 +82,7 @@ protected ExportSubscriptionListener(
}

@Timed("rhsm-subscriptions.exports.upload")
@Transactional
@Transactional(readOnly = true)
@KafkaListener(
id = "#{__listener.groupId}",
topics = "#{__listener.topic}",
Expand Down Expand Up @@ -159,7 +159,7 @@ private void uploadJson(
var serializer =
serializerProvider.findTypedValueSerializer(
exporterService.getExportItemClass(), false, null);
data.map(exporterService::mapDataItem)
data.map(i -> exporterService.mapDataItem(i, request))
.forEach(
item -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ private static Sort toSort(String sort, SortDirection dir) {
return sortValue;
}

private static Boolean isPayg(Optional<Variant> variant) {
public static boolean isPayg(Optional<Variant> variant) {
return variant
.map(Variant::getSubscription)
.map(SubscriptionDefinition::isPaygEligible)
Expand Down Expand Up @@ -346,7 +346,7 @@ private static List<Double> getInstanceMeasurements(
return measurementList;
}

private static List<HardwareMeasurementType> getHardwareMeasurementTypesFromCategory(
public static List<HardwareMeasurementType> getHardwareMeasurementTypesFromCategory(
ReportCategory reportCategory) {
if (Objects.isNull(reportCategory)) {
return new ArrayList<>();
Expand All @@ -355,7 +355,7 @@ private static List<HardwareMeasurementType> getHardwareMeasurementTypesFromCate
}
}

private static ReportCategory getCategoryByMeasurementType(
public static ReportCategory getCategoryByMeasurementType(
HardwareMeasurementType measurementType) {
if (HardwareMeasurementType.isSupportedCloudProvider(measurementType.name())) {
return ReportCategory.CLOUD;
Expand All @@ -368,7 +368,7 @@ private static ReportCategory getCategoryByMeasurementType(
};
}

private static CloudProvider getCloudProviderByMeasurementType(
public static CloudProvider getCloudProviderByMeasurementType(
HardwareMeasurementType measurementType) {
return switch (measurementType) {
case AWS -> CloudProvider.AWS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public Stream<Subscription> fetchData(ExportServiceRequest request) {
}

@Override
public SubscriptionsExportItem mapDataItem(Subscription dataItem) {
public SubscriptionsExportItem mapDataItem(Subscription dataItem, ExportServiceRequest request) {
var item = new SubscriptionsExportItem();
item.setOrgId(dataItem.getOrgId());
item.setMeasurements(new ArrayList<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.candlepin.subscriptions.db.AccountServiceInventoryRepository;
import org.candlepin.subscriptions.db.HostRepository;
import org.candlepin.subscriptions.db.TallySnapshotRepository;
import org.candlepin.subscriptions.export.ExportSubscriptionConfiguration;
import org.candlepin.subscriptions.inventory.db.InventoryDataSourceConfiguration;
import org.candlepin.subscriptions.json.BillableUsage;
import org.candlepin.subscriptions.json.EnabledOrgsRequest;
Expand Down Expand Up @@ -92,7 +93,8 @@
TaskConsumerConfiguration.class,
BillingProducerConfiguration.class,
InventoryDataSourceConfiguration.class,
ProductConfiguration.class
ProductConfiguration.class,
ExportSubscriptionConfiguration.class
})
@ComponentScan(
basePackages = {
Expand Down
Loading

0 comments on commit 7169f8f

Please sign in to comment.