Skip to content
Snippets Groups Projects
Commit b6f30a6b authored by Zhibin Mai's avatar Zhibin Mai Committed by David Diederich
Browse files

Add feature flag using Partition Service to flag whether to enable geoshape...

Add feature flag using Partition Service to flag whether to enable geoshape decimation or not for a given data partition

(cherry picked from commit a2784096)
parent ea57fa3c
Branches
Tags
6 merge requests!604Merge Delta changes from M16 master to M18 master,!600Merge Delta changes from M16 master to M18 master,!599Merge Delta changes from M16 to M18 master,!598Merged from M16,!522M14 cherrypick to m16 master,!405Cherry-pick 'Geoshape decimation' into release/0.17
package org.opengroup.osdu.indexer.service;
import org.opengroup.osdu.core.common.partition.PartitionInfo;
public interface IPartitionService {
PartitionInfo getPartitionInfo();
}
package org.opengroup.osdu.indexer.service;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.partition.IPartitionFactory;
import org.opengroup.osdu.core.common.partition.IPartitionProvider;
import org.opengroup.osdu.core.common.partition.PartitionException;
import org.opengroup.osdu.core.common.partition.PartitionInfo;
import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class PartitionServiceImpl implements IPartitionService {
@Autowired
private DpsHeaders headers;
@Autowired
private IPartitionFactory factory;
@Autowired
private IServiceAccountJwtClient tokenService;
@Override
public PartitionInfo getPartitionInfo() {
try {
DpsHeaders partitionHeaders = DpsHeaders.createFromMap(headers.getHeaders());
partitionHeaders.put(DpsHeaders.AUTHORIZATION, this.tokenService.getIdToken(this.headers.getPartitionId()));
IPartitionProvider serviceClient = this.factory.create(partitionHeaders);
PartitionInfo partitionInfo = serviceClient.get(this.headers.getPartitionId());
return partitionInfo;
} catch (PartitionException e) {
throw new AppException(HttpStatus.SC_FORBIDDEN, "Service unavailable", String.format("Error getting partition info for data-partition: %s", this.headers.getPartitionId()), e);
}
}
}
......@@ -33,6 +33,7 @@ import org.opengroup.osdu.indexer.schema.converter.tags.VirtualProperty;
import org.opengroup.osdu.indexer.util.VirtualPropertyUtil;
import org.opengroup.osdu.indexer.util.geo.decimator.DecimatedResult;
import org.opengroup.osdu.indexer.util.geo.decimator.GeoShapeDecimator;
import org.opengroup.osdu.indexer.util.geo.decimator.GeoShapeDecimationSetting;
import org.springframework.stereotype.Component;
import javax.inject.Inject;
......@@ -54,6 +55,8 @@ public class StorageIndexerPayloadMapper {
private IVirtualPropertiesSchemaCache virtualPropertiesSchemaCache;
@Inject
private GeoShapeDecimator decimator;
@Inject
private GeoShapeDecimationSetting decimationSetting;
public Map<String, Object> mapDataPayload(IndexSchema storageSchema, Map<String, Object> storageRecordData,
String recordId) {
......@@ -236,13 +239,14 @@ public class StorageIndexerPayloadMapper {
// No VirtualProperties.DefaultLocation.Wgs84Coordinates defined, use the default geo-shape property
String defaultGeoShapeProperty = "SpatialLocation.Wgs84Coordinates";
if(originalGeoShapeProperty == null && dataCollectorMap.containsKey(defaultGeoShapeProperty))
if (originalGeoShapeProperty == null && dataCollectorMap.containsKey(defaultGeoShapeProperty))
originalGeoShapeProperty = defaultGeoShapeProperty;
try {
decimateGeoShape(originalGeoShapeProperty, dataCollectorMap);
}
catch(JsonProcessingException ex) {
this.log.warning(String.format("record-id: %s | error decimating geoshape | error: %s", recordId, ex.getMessage()));
if(decimationSetting.isDecimationEnabled()) {
try {
decimateGeoShape(originalGeoShapeProperty, dataCollectorMap);
} catch (JsonProcessingException ex) {
this.log.warning(String.format("record-id: %s | error decimating geoshape | error: %s", recordId, ex.getMessage()));
}
}
}
......
package org.opengroup.osdu.indexer.util.geo.decimator;
import org.opengroup.osdu.core.common.cache.VmCache;
import org.springframework.stereotype.Component;
@Component
public class DecimationSettingCache extends VmCache<String, Boolean> {
public DecimationSettingCache() {
super(300, 1000);
}
public boolean containsKey(final String key) {
return this.get(key) != null;
}
}
package org.opengroup.osdu.indexer.util.geo.decimator;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.partition.PartitionInfo;
import org.opengroup.osdu.core.common.partition.Property;
import org.opengroup.osdu.indexer.service.IPartitionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
@Component
public class GeoShapeDecimationSetting {
private static final String PROPERTY_NAME = "indexer-decimation-enabled";
@Autowired(required = false)
private IPartitionService partitionService;
@Lazy
@Autowired
private DecimationSettingCache cache;
@Autowired
private JaxRsDpsLog logger;
@Autowired
private DpsHeaders headers;
public boolean isDecimationEnabled() {
if (partitionService == null)
return false;
String dataPartitionId = headers.getPartitionId();
String cacheKey = String.format("%s-%s", dataPartitionId, PROPERTY_NAME);
if (cache != null && cache.containsKey(cacheKey))
return cache.get(cacheKey);
boolean decimationEnabled = false;
try {
PartitionInfo partitionInfo = partitionService.getPartitionInfo();
decimationEnabled = getDecimationSetting(partitionInfo);
} catch (Exception e) {
this.logger.error(String.format("PartitionService: Error getting %s for dataPartition with Id: %s", PROPERTY_NAME, dataPartitionId), e);
}
this.cache.put(cacheKey, decimationEnabled);
return decimationEnabled;
}
private boolean getDecimationSetting(PartitionInfo partitionInfo) {
if(partitionInfo == null || partitionInfo.getProperties() == null)
return false;
if(partitionInfo.getProperties().containsKey(PROPERTY_NAME)) {
Property property = partitionInfo.getProperties().get(PROPERTY_NAME);
return Boolean.parseBoolean((String)property.getValue());
}
return false;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment