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

Undo the deletion of FF client and address issues from reviewer

parent df70df74
No related branches found
No related tags found
1 merge request!558Remove feature flag for geoshape decimation
Pipeline #190316 failed
Pipeline: Indexer

#190317

    Showing
    with 218 additions and 108 deletions
    ## Geoshape Decimation
    In order to improve indexing and search performance for documents with large geometry, the geo-shape of the following
    GeoJSON types in the original shape attribute and virtual shape attribute if exists are decimated
    by implementing Ramer–Douglas–Peucker algorithm:
    - LineString
    - MultiLineString
    - Polygon
    - MultiPolygon
    The feature is enabled for all data partitions since M19.
    ## Index extension
    OSDU Standard index extensions are defined by OSDU Data Definition work-streams with the intent to provide
    ......
    ......@@ -13,7 +13,7 @@
    * limitations under the License.
    */
    package org.opengroup.osdu.indexer.util.geo.decimator;
    package org.opengroup.osdu.indexer.cache;
    import org.opengroup.osdu.core.common.cache.VmCache;
    import org.springframework.stereotype.Component;
    ......
    package org.opengroup.osdu.indexer.util;
    import org.opengroup.osdu.core.common.feature.IFeatureFlag;
    import org.opengroup.osdu.core.common.model.http.DpsHeaders;
    import org.opengroup.osdu.indexer.util.geo.decimator.FeatureFlagCache;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.annotation.Lazy;
    import org.springframework.stereotype.Component;
    @Component
    public class AugmenterSetting {
    private static final String PROPERTY_NAME = "index-augmenter-enabled";
    @Lazy
    @Autowired
    private FeatureFlagCache cache;
    @Autowired
    private DpsHeaders headers;
    @Autowired
    private IFeatureFlag iFeatureFlag;
    private BooleanFeatureFlagClient booleanFeatureFlagClient;
    public boolean isEnabled() {
    String dataPartitionId = headers.getPartitionId();
    String cacheKey = String.format("%s-%s", dataPartitionId, PROPERTY_NAME);
    if (cache != null && cache.containsKey(cacheKey))
    return cache.get(cacheKey);
    boolean isEnabled = iFeatureFlag.isFeatureEnabled(PROPERTY_NAME);
    this.cache.put(cacheKey, isEnabled);
    return isEnabled;
    return booleanFeatureFlagClient.isEnabled(PROPERTY_NAME, false);
    }
    }
    package org.opengroup.osdu.indexer.util;
    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.opengroup.osdu.indexer.cache.FeatureFlagCache;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.annotation.Lazy;
    import org.springframework.stereotype.Component;
    @Component
    public class BooleanFeatureFlagClient {
    private static final String TOKEN_PREFIX = "Bearer ";
    @Lazy
    @Autowired
    private FeatureFlagCache cache;
    @Autowired
    private JaxRsDpsLog logger;
    @Autowired
    private DpsHeaders headers;
    @Autowired
    private IPartitionFactory factory;
    @Autowired
    private IServiceAccountJwtClient tokenService;
    public boolean isEnabled(String featureName, boolean defaultValue) {
    String dataPartitionId = headers.getPartitionId();
    String cacheKey = String.format("%s-%s", dataPartitionId, featureName);
    if (cache != null && cache.containsKey(cacheKey))
    return cache.get(cacheKey);
    boolean isEnabled = defaultValue;
    try {
    PartitionInfo partitionInfo = getPartitionInfo(dataPartitionId);
    isEnabled = getFeatureValue(partitionInfo, featureName, defaultValue);
    } catch (Exception e) {
    this.logger.error(String.format("PartitionService: Error getting %s for dataPartition with Id: %s. Turn on the feature flag by default.", featureName, dataPartitionId), e);
    }
    this.cache.put(cacheKey, isEnabled);
    return isEnabled;
    }
    private PartitionInfo getPartitionInfo(String dataPartitionId) throws PartitionException {
    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) {
    logger.error(String.format("Error getting partition info for data-partition: %s", dataPartitionId), e);
    throw e;
    }
    }
    private boolean getFeatureValue(PartitionInfo partitionInfo, String featureName, boolean defaultValue) {
    if(partitionInfo == null || partitionInfo.getProperties() == null)
    return defaultValue;
    if(partitionInfo.getProperties().containsKey(featureName)) {
    Property property = partitionInfo.getProperties().get(featureName);
    return Boolean.parseBoolean((String)property.getValue());
    }
    return defaultValue;
    }
    }
    ......@@ -12,13 +12,12 @@ 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.indexer.cache.FeatureFlagCache;
    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;
    import org.opengroup.osdu.indexer.schema.converter.tags.SchemaRoot;
    import org.opengroup.osdu.indexer.schema.converter.tags.VirtualProperties;
    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.*;
    ......@@ -46,7 +45,7 @@ import static org.junit.Assert.*;
    BooleanParser.class, DateTimeParser.class, GeoShapeParser.class, DouglasPeuckerReducer.class, GeoShapeDecimator.class,
    GeometryDecimator.class, GeometryConversionService.class, FeatureFlagCache.class,
    DpsHeaders.class, JobStatus.class, SchemaConverterPropertiesConfig.class, JaxRsDpsLog.class,
    PartitionFactoryMock.class, PartitionProviderMock.class, ServiceAccountJwtClientMock.class, VirtualPropertiesSchemaCacheMock.class, })
    ServiceAccountJwtClientMock.class, VirtualPropertiesSchemaCacheMock.class, })
    public class StorageIndexerPayloadMapperTest {
    public static final String FIRST_OBJECT_INNER_PROPERTY = "FirstObjectInnerProperty";
    ......
    /*
    * 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.service.mock;
    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;
    public class PartitionFactoryMock implements IPartitionFactory {
    @Override
    public IPartitionProvider create(DpsHeaders dpsHeaders) {
    return new PartitionProviderMock();
    }
    }
    /*
    * 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.service.mock;
    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.partition.Property;
    import java.util.List;
    public class PartitionProviderMock implements IPartitionProvider {
    private static final String PROPERTY_NAME = "indexer-decimation-enabled";
    @Override
    public PartitionInfo get(String s) throws PartitionException {
    PartitionInfo partitionInfo = new PartitionInfo();
    Property property = new Property();
    property.setSensitive(false);
    property.setValue("true");
    partitionInfo.getProperties().put(PROPERTY_NAME, property);
    return partitionInfo;
    }
    @Override
    public PartitionInfo create(String s, PartitionInfo partitionInfo) throws PartitionException {
    return null;
    }
    @Override
    public void update(String s, PartitionInfo partitionInfo) throws PartitionException {
    }
    @Override
    public void delete(String s) throws PartitionException {
    }
    @Override
    public List<String> list() throws PartitionException {
    return null;
    }
    }
    /*
    * 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;
    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.opengroup.osdu.indexer.cache.FeatureFlagCache;
    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 BooleanFeatureFlagClientTest {
    private static final String PROPERTY_NAME = "indexer-decimation-enabled";
    @InjectMocks
    private BooleanFeatureFlagClient sut;
    @Mock
    private FeatureFlagCache 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);
    // Default value won't take any effect
    boolean enabled = sut.isEnabled(PROPERTY_NAME, true);
    Assert.assertTrue(enabled);
    enabled = sut.isEnabled(PROPERTY_NAME, false);
    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);
    // Default value won't take any effect
    boolean enabled = sut.isEnabled(PROPERTY_NAME, true);
    Assert.assertFalse(enabled);
    enabled = sut.isEnabled(PROPERTY_NAME, false);
    Assert.assertFalse(enabled);
    }
    @Test
    public void isDecimationEnabled_return_default_value_when_property_does_not_exist() throws PartitionException {
    // The feature flag is enabled by default
    PartitionInfo partitionInfo = new PartitionInfo();
    when(this.partitionProvider.get(anyString())).thenReturn(partitionInfo);
    boolean enabled = sut.isEnabled(PROPERTY_NAME, true);;
    Assert.assertTrue(enabled);
    enabled = sut.isEnabled(PROPERTY_NAME, false);;
    Assert.assertFalse(enabled);
    }
    @Test
    public void isDecimationEnabled_return_default_value_when_partitionProvider_throws_exception() throws PartitionException {
    // The feature flag is enabled by default
    when(this.partitionProvider.get(anyString())).thenThrow(PartitionException.class);
    boolean enabled = sut.isEnabled(PROPERTY_NAME, true);;
    Assert.assertTrue(enabled);
    enabled = sut.isEnabled(PROPERTY_NAME, false);;
    Assert.assertFalse(enabled);
    }
    }
    ......@@ -19,6 +19,7 @@ import org.junit.Assert;
    import org.junit.Before;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.opengroup.osdu.indexer.cache.FeatureFlagCache;
    import org.springframework.test.context.junit4.SpringRunner;
    @RunWith(SpringRunner.class)
    ......
    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