Skip to content
Snippets Groups Projects
Commit 9b53f751 authored by Zhibin Mai's avatar Zhibin Mai
Browse files

Remove the feature flag for geo-shape decimation

parent e8a23c6b
No related branches found
No related tags found
1 merge request!486Enable the feature flag for geo-shape decimation by default
Pipeline #167045 failed
......@@ -33,7 +33,6 @@ 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;
......@@ -58,8 +57,6 @@ 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) {
......@@ -243,7 +240,7 @@ public class StorageIndexerPayloadMapper {
// No VirtualProperties.DefaultLocation.Wgs84Coordinates defined, use the default geo-shape property
if (originalGeoShapeProperty == null)
originalGeoShapeProperty = getDefaultGeoShapeProperty(dataCollectorMap);
if(originalGeoShapeProperty != null && decimationSetting.isDecimationEnabled()) {
if(originalGeoShapeProperty != null) {
try {
decimateGeoShape(originalGeoShapeProperty, dataCollectorMap);
} catch (JsonProcessingException ex) {
......
/*
* Copyright © Schlumberger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0 *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.indexer.util.geo.decimator;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
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.*;
import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient;
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";
@Lazy
@Autowired
private DecimationSettingCache cache;
@Autowired
private JaxRsDpsLog logger;
@Autowired
private DpsHeaders headers;
@Autowired
private IPartitionFactory factory;
@Autowired
private IServiceAccountJwtClient tokenService;
public boolean isDecimationEnabled() {
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 = getPartitionInfo(dataPartitionId);
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 PartitionInfo getPartitionInfo(String dataPartitionId) {
try {
DpsHeaders partitionHeaders = DpsHeaders.createFromMap(headers.getHeaders());
partitionHeaders.put(DpsHeaders.AUTHORIZATION, this.tokenService.getIdToken(dataPartitionId));
IPartitionProvider partitionProvider = this.factory.create(partitionHeaders);
PartitionInfo partitionInfo = partitionProvider.get(dataPartitionId);
return partitionInfo;
} catch (PartitionException e) {
throw new AppException(HttpStatus.SC_FORBIDDEN, "Service unavailable", String.format("Error getting partition info for data-partition: %s", dataPartitionId), e);
}
}
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;
}
}
......@@ -12,7 +12,6 @@ import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.indexer.IndexSchema;
import org.opengroup.osdu.core.common.model.indexer.JobStatus;
import org.opengroup.osdu.core.common.partition.*;
import org.opengroup.osdu.indexer.schema.converter.config.SchemaConverterPropertiesConfig;
import org.opengroup.osdu.indexer.schema.converter.exeption.SchemaProcessingException;
import org.opengroup.osdu.indexer.schema.converter.interfaces.IVirtualPropertiesSchemaCache;
......@@ -21,7 +20,10 @@ import org.opengroup.osdu.indexer.service.mock.PartitionFactoryMock;
import org.opengroup.osdu.indexer.service.mock.PartitionProviderMock;
import org.opengroup.osdu.indexer.service.mock.ServiceAccountJwtClientMock;
import org.opengroup.osdu.indexer.service.mock.VirtualPropertiesSchemaCacheMock;
import org.opengroup.osdu.indexer.util.geo.decimator.*;
import org.opengroup.osdu.indexer.util.geo.decimator.DecimationSettingCache;
import org.opengroup.osdu.indexer.util.geo.decimator.DouglasPeuckerReducer;
import org.opengroup.osdu.indexer.util.geo.decimator.GeoShapeDecimator;
import org.opengroup.osdu.indexer.util.geo.decimator.GeometryDecimator;
import org.opengroup.osdu.indexer.util.parser.BooleanParser;
import org.opengroup.osdu.indexer.util.parser.DateTimeParser;
import org.opengroup.osdu.indexer.util.parser.GeoShapeParser;
......@@ -45,7 +47,7 @@ import static org.junit.Assert.*;
@SpringBootTest(classes = {StorageIndexerPayloadMapper.class, AttributeParsingServiceImpl.class, NumberParser.class,
BooleanParser.class, DateTimeParser.class, GeoShapeParser.class, DouglasPeuckerReducer.class, GeoShapeDecimator.class,
GeometryDecimator.class, GeometryConversionService.class, DecimationSettingCache.class,
GeoShapeDecimationSetting.class, DpsHeaders.class, JobStatus.class, SchemaConverterPropertiesConfig.class, JaxRsDpsLog.class,
DpsHeaders.class, JobStatus.class, SchemaConverterPropertiesConfig.class, JaxRsDpsLog.class,
PartitionFactoryMock.class, PartitionProviderMock.class, ServiceAccountJwtClientMock.class, VirtualPropertiesSchemaCacheMock.class, })
public class StorageIndexerPayloadMapperTest {
......
/*
* Copyright © Schlumberger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0 *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.indexer.util.geo.decimator;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.partition.*;
import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.HashMap;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(SpringRunner.class)
public class GeoShapeDecimationSettingTest {
private static final String PROPERTY_NAME = "indexer-decimation-enabled";
@InjectMocks
private GeoShapeDecimationSetting sut;
@Mock
private DecimationSettingCache cache;
@Mock
private JaxRsDpsLog logger;
@Mock
private DpsHeaders headers;
@Mock
private IPartitionFactory factory;
@Mock
private IServiceAccountJwtClient tokenService;
@Mock
IPartitionProvider partitionProvider;
@Before
public void setup() {
when(this.headers.getPartitionId()).thenReturn("dataPartitionId");
when(this.headers.getHeaders()).thenReturn(new HashMap());
when(this.factory.create(any())).thenReturn(partitionProvider);
when(this.tokenService.getIdToken(anyString())).thenReturn("token");
}
@Test
public void isDecimationEnabled_return_true() throws PartitionException {
PartitionInfo partitionInfo = new PartitionInfo();
Property property = new Property();
property.setSensitive(false);
property.setValue("true");
partitionInfo.getProperties().put(PROPERTY_NAME, property);
when(this.partitionProvider.get(anyString())).thenReturn(partitionInfo);
boolean enabled = sut.isDecimationEnabled();
Assert.assertTrue(enabled);
}
@Test
public void isDecimationEnabled_return_false_when_property_set_to_false() throws PartitionException {
PartitionInfo partitionInfo = new PartitionInfo();
Property property = new Property();
property.setSensitive(false);
property.setValue("false");
partitionInfo.getProperties().put(PROPERTY_NAME, property);
when(this.partitionProvider.get(anyString())).thenReturn(partitionInfo);
boolean enabled = sut.isDecimationEnabled();
Assert.assertFalse(enabled);
}
@Test
public void isDecimationEnabled_return_false_when_property_does_not_exist() throws PartitionException {
PartitionInfo partitionInfo = new PartitionInfo();
when(this.partitionProvider.get(anyString())).thenReturn(partitionInfo);
boolean enabled = sut.isDecimationEnabled();
Assert.assertFalse(enabled);
}
@Test
public void isDecimationEnabled_return_false_when_partitionProvider_throws_exception() throws PartitionException {
when(this.partitionProvider.get(anyString())).thenThrow(PartitionException.class);
boolean enabled = sut.isDecimationEnabled();
Assert.assertFalse(enabled);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment