From debf5ade01496ab94609861c03cfcdd4a823c1db Mon Sep 17 00:00:00 2001 From: Heemin Kim Date: Mon, 26 Jun 2023 13:12:41 -0700 Subject: [PATCH] Changed class name and package Signed-off-by: Heemin Kim --- .../DeleteDatasourceTransportAction.java | 40 ++++++++--------- .../action/GetDatasourceTransportAction.java | 14 +++--- .../action/PutDatasourceTransportAction.java | 16 +++---- .../UpdateDatasourceTransportAction.java | 14 +++--- .../geospatial/ip2geo/cache/Ip2GeoCache.java | 10 ++--- .../DatasourceDao.java} | 11 ++--- .../GeoIpDataDao.java} | 12 ++--- .../Ip2GeoProcessorDao.java} | 9 ++-- .../ip2geo/jobscheduler/DatasourceRunner.java | 14 +++--- .../jobscheduler/DatasourceUpdateService.java | 36 +++++++-------- .../ip2geo/listener/Ip2GeoListener.java | 14 +++--- .../ip2geo/processor/Ip2GeoProcessor.java | 32 +++++++------- .../geospatial/plugin/GeospatialPlugin.java | 27 +++++------- .../geospatial/ip2geo/Ip2GeoTestCase.java | 16 +++---- .../DeleteDatasourceTransportActionTests.java | 42 +++++++++--------- .../GetDatasourceTransportActionTests.java | 6 +-- .../PutDatasourceTransportActionTests.java | 12 ++--- .../UpdateDatasourceTransportActionTests.java | 20 ++++----- .../ip2geo/cache/Ip2GeoCacheTests.java | 22 +++++----- .../DatasourceDaoTests.java} | 44 +++++++++---------- .../GeoIpDataDaoTests.java} | 35 ++++++++------- .../Ip2GeoProcessorDaoTests.java} | 14 +++--- .../jobscheduler/DatasourceRunnerTests.java | 22 +++++----- .../DatasourceUpdateServiceTests.java | 40 +++++++---------- .../ip2geo/listener/Ip2GeoListenerTests.java | 8 ++-- .../processor/Ip2GeoProcessorTests.java | 8 ++-- .../plugin/GeospatialPluginTests.java | 8 ++-- 27 files changed, 269 insertions(+), 277 deletions(-) rename src/main/java/org/opensearch/geospatial/ip2geo/{common/DatasourceFacade.java => dao/DatasourceDao.java} (97%) rename src/main/java/org/opensearch/geospatial/ip2geo/{common/GeoIpDataFacade.java => dao/GeoIpDataDao.java} (97%) rename src/main/java/org/opensearch/geospatial/ip2geo/{common/Ip2GeoProcessorFacade.java => dao/Ip2GeoProcessorDao.java} (85%) rename src/test/java/org/opensearch/geospatial/ip2geo/{common/DatasourceFacadeTests.java => dao/DatasourceDaoTests.java} (91%) rename src/test/java/org/opensearch/geospatial/ip2geo/{common/GeoIpDataFacadeTests.java => dao/GeoIpDataDaoTests.java} (91%) rename src/test/java/org/opensearch/geospatial/ip2geo/{common/Ip2GeoProcessorFacadeTests.java => dao/Ip2GeoProcessorDaoTests.java} (90%) diff --git a/src/main/java/org/opensearch/geospatial/ip2geo/action/DeleteDatasourceTransportAction.java b/src/main/java/org/opensearch/geospatial/ip2geo/action/DeleteDatasourceTransportAction.java index f9a13f9e..8046f6ff 100644 --- a/src/main/java/org/opensearch/geospatial/ip2geo/action/DeleteDatasourceTransportAction.java +++ b/src/main/java/org/opensearch/geospatial/ip2geo/action/DeleteDatasourceTransportAction.java @@ -18,11 +18,11 @@ import org.opensearch.geospatial.annotation.VisibleForTesting; import org.opensearch.geospatial.exceptions.ConcurrentModificationException; import org.opensearch.geospatial.exceptions.ResourceInUseException; -import org.opensearch.geospatial.ip2geo.common.DatasourceFacade; import org.opensearch.geospatial.ip2geo.common.DatasourceState; -import org.opensearch.geospatial.ip2geo.common.GeoIpDataFacade; import org.opensearch.geospatial.ip2geo.common.Ip2GeoLockService; -import org.opensearch.geospatial.ip2geo.common.Ip2GeoProcessorFacade; +import org.opensearch.geospatial.ip2geo.dao.DatasourceDao; +import org.opensearch.geospatial.ip2geo.dao.GeoIpDataDao; +import org.opensearch.geospatial.ip2geo.dao.Ip2GeoProcessorDao; import org.opensearch.geospatial.ip2geo.jobscheduler.Datasource; import org.opensearch.ingest.IngestService; import org.opensearch.tasks.Task; @@ -37,9 +37,9 @@ public class DeleteDatasourceTransportAction extends HandledTransportAction { - private final DatasourceFacade datasourceFacade; + private final DatasourceDao datasourceDao; /** * Default constructor * @param transportService the transport service * @param actionFilters the action filters - * @param datasourceFacade the datasource facade + * @param datasourceDao the datasource facade */ @Inject public GetDatasourceTransportAction( final TransportService transportService, final ActionFilters actionFilters, - final DatasourceFacade datasourceFacade + final DatasourceDao datasourceDao ) { super(GetDatasourceAction.NAME, transportService, actionFilters, GetDatasourceRequest::new); - this.datasourceFacade = datasourceFacade; + this.datasourceDao = datasourceDao; } @Override protected void doExecute(final Task task, final GetDatasourceRequest request, final ActionListener listener) { if (shouldGetAllDatasource(request)) { // We don't expect too many data sources. Therefore, querying all data sources without pagination should be fine. - datasourceFacade.getAllDatasources(newActionListener(listener)); + datasourceDao.getAllDatasources(newActionListener(listener)); } else { - datasourceFacade.getDatasources(request.getNames(), newActionListener(listener)); + datasourceDao.getDatasources(request.getNames(), newActionListener(listener)); } } diff --git a/src/main/java/org/opensearch/geospatial/ip2geo/action/PutDatasourceTransportAction.java b/src/main/java/org/opensearch/geospatial/ip2geo/action/PutDatasourceTransportAction.java index 75b30f29..ed4d1ee7 100644 --- a/src/main/java/org/opensearch/geospatial/ip2geo/action/PutDatasourceTransportAction.java +++ b/src/main/java/org/opensearch/geospatial/ip2geo/action/PutDatasourceTransportAction.java @@ -22,9 +22,9 @@ import org.opensearch.common.inject.Inject; import org.opensearch.geospatial.annotation.VisibleForTesting; import org.opensearch.geospatial.exceptions.ConcurrentModificationException; -import org.opensearch.geospatial.ip2geo.common.DatasourceFacade; import org.opensearch.geospatial.ip2geo.common.DatasourceState; import org.opensearch.geospatial.ip2geo.common.Ip2GeoLockService; +import org.opensearch.geospatial.ip2geo.dao.DatasourceDao; import org.opensearch.geospatial.ip2geo.jobscheduler.Datasource; import org.opensearch.geospatial.ip2geo.jobscheduler.DatasourceUpdateService; import org.opensearch.index.engine.VersionConflictEngineException; @@ -39,7 +39,7 @@ @Log4j2 public class PutDatasourceTransportAction extends HandledTransportAction { private final ThreadPool threadPool; - private final DatasourceFacade datasourceFacade; + private final DatasourceDao datasourceDao; private final DatasourceUpdateService datasourceUpdateService; private final Ip2GeoLockService lockService; @@ -48,7 +48,7 @@ public class PutDatasourceTransportAction extends HandledTransportAction listener ) { StepListener createIndexStep = new StepListener<>(); - datasourceFacade.createIndexIfNotExists(createIndexStep); + datasourceDao.createIndexIfNotExists(createIndexStep); createIndexStep.whenComplete(v -> { Datasource datasource = Datasource.Builder.build(request); - datasourceFacade.putDatasource(datasource, getIndexResponseListener(datasource, lock, listener)); + datasourceDao.putDatasource(datasource, getIndexResponseListener(datasource, lock, listener)); }, exception -> { lockService.releaseLock(lock); listener.onFailure(exception); @@ -165,7 +165,7 @@ private void markDatasourceAsCreateFailed(final Datasource datasource) { datasource.getUpdateStats().setLastFailedAt(Instant.now()); datasource.setState(DatasourceState.CREATE_FAILED); try { - datasourceFacade.updateDatasource(datasource); + datasourceDao.updateDatasource(datasource); } catch (Exception e) { log.error("Failed to mark datasource state as CREATE_FAILED for {}", datasource.getName(), e); } diff --git a/src/main/java/org/opensearch/geospatial/ip2geo/action/UpdateDatasourceTransportAction.java b/src/main/java/org/opensearch/geospatial/ip2geo/action/UpdateDatasourceTransportAction.java index bc247b70..c832dc89 100644 --- a/src/main/java/org/opensearch/geospatial/ip2geo/action/UpdateDatasourceTransportAction.java +++ b/src/main/java/org/opensearch/geospatial/ip2geo/action/UpdateDatasourceTransportAction.java @@ -23,9 +23,9 @@ import org.opensearch.common.inject.Inject; import org.opensearch.geospatial.exceptions.ConcurrentModificationException; import org.opensearch.geospatial.exceptions.IncompatibleDatasourceException; -import org.opensearch.geospatial.ip2geo.common.DatasourceFacade; import org.opensearch.geospatial.ip2geo.common.DatasourceManifest; import org.opensearch.geospatial.ip2geo.common.Ip2GeoLockService; +import org.opensearch.geospatial.ip2geo.dao.DatasourceDao; import org.opensearch.geospatial.ip2geo.jobscheduler.Datasource; import org.opensearch.geospatial.ip2geo.jobscheduler.DatasourceTask; import org.opensearch.geospatial.ip2geo.jobscheduler.DatasourceUpdateService; @@ -41,7 +41,7 @@ public class UpdateDatasourceTransportAction extends HandledTransportAction { private static final long LOCK_DURATION_IN_SECONDS = 300l; private final Ip2GeoLockService lockService; - private final DatasourceFacade datasourceFacade; + private final DatasourceDao datasourceDao; private final DatasourceUpdateService datasourceUpdateService; private final ThreadPool threadPool; @@ -51,7 +51,7 @@ public class UpdateDatasourceTransportAction extends HandledTransportAction { try { - Datasource datasource = datasourceFacade.getDatasource(request.getName()); + Datasource datasource = datasourceDao.getDatasource(request.getName()); if (datasource == null) { throw new ResourceNotFoundException("no such datasource exist"); } @@ -124,7 +124,7 @@ private void updateIfChanged(final UpdateDatasourceRequest request, final Dataso } if (isChanged) { - datasourceFacade.updateDatasource(datasource); + datasourceDao.updateDatasource(datasource); } } diff --git a/src/main/java/org/opensearch/geospatial/ip2geo/cache/Ip2GeoCache.java b/src/main/java/org/opensearch/geospatial/ip2geo/cache/Ip2GeoCache.java index a42b31de..1249655b 100644 --- a/src/main/java/org/opensearch/geospatial/ip2geo/cache/Ip2GeoCache.java +++ b/src/main/java/org/opensearch/geospatial/ip2geo/cache/Ip2GeoCache.java @@ -17,8 +17,8 @@ import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentParser; -import org.opensearch.geospatial.ip2geo.common.DatasourceFacade; import org.opensearch.geospatial.ip2geo.common.DatasourceState; +import org.opensearch.geospatial.ip2geo.dao.DatasourceDao; import org.opensearch.geospatial.ip2geo.jobscheduler.Datasource; import org.opensearch.index.engine.Engine; import org.opensearch.index.shard.IndexingOperationListener; @@ -26,11 +26,11 @@ @Log4j2 public class Ip2GeoCache implements IndexingOperationListener { - private final DatasourceFacade datasourceFacade; + private final DatasourceDao datasourceDao; private Map data; - public Ip2GeoCache(final DatasourceFacade datasourceFacade) { - this.datasourceFacade = datasourceFacade; + public Ip2GeoCache(final DatasourceDao datasourceDao) { + this.datasourceDao = datasourceDao; } public String getIndexName(final String datasourceName) { @@ -58,7 +58,7 @@ private Map getData() { return data; } Map tempData = new ConcurrentHashMap<>(); - datasourceFacade.getAllDatasources() + datasourceDao.getAllDatasources() .stream() .forEach(datasource -> tempData.put(datasource.getName(), new DatasourceMetadata(datasource))); data = tempData; diff --git a/src/main/java/org/opensearch/geospatial/ip2geo/common/DatasourceFacade.java b/src/main/java/org/opensearch/geospatial/ip2geo/dao/DatasourceDao.java similarity index 97% rename from src/main/java/org/opensearch/geospatial/ip2geo/common/DatasourceFacade.java rename to src/main/java/org/opensearch/geospatial/ip2geo/dao/DatasourceDao.java index d0e13cd5..ec8e6f81 100644 --- a/src/main/java/org/opensearch/geospatial/ip2geo/common/DatasourceFacade.java +++ b/src/main/java/org/opensearch/geospatial/ip2geo/dao/DatasourceDao.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package org.opensearch.geospatial.ip2geo.common; +package org.opensearch.geospatial.ip2geo.dao; import java.io.BufferedReader; import java.io.IOException; @@ -47,6 +47,7 @@ import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentParser; +import org.opensearch.geospatial.ip2geo.common.Ip2GeoSettings; import org.opensearch.geospatial.ip2geo.jobscheduler.Datasource; import org.opensearch.geospatial.ip2geo.jobscheduler.DatasourceExtension; import org.opensearch.geospatial.shared.StashedThreadContext; @@ -56,16 +57,16 @@ import org.opensearch.search.SearchHit; /** - * Facade class for datasource + * Data access object for datasource */ @Log4j2 -public class DatasourceFacade { +public class DatasourceDao { private static final Integer MAX_SIZE = 1000; private final Client client; private final ClusterService clusterService; private final ClusterSettings clusterSettings; - public DatasourceFacade(final Client client, final ClusterService clusterService) { + public DatasourceDao(final Client client, final ClusterService clusterService) { this.client = client; this.clusterService = clusterService; this.clusterSettings = clusterService.getClusterSettings(); @@ -103,7 +104,7 @@ public void onFailure(final Exception e) { private String getIndexMapping() { try { - try (InputStream is = DatasourceFacade.class.getResourceAsStream("/mappings/ip2geo_datasource.json")) { + try (InputStream is = DatasourceDao.class.getResourceAsStream("/mappings/ip2geo_datasource.json")) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) { return reader.lines().map(String::trim).collect(Collectors.joining()); } diff --git a/src/main/java/org/opensearch/geospatial/ip2geo/common/GeoIpDataFacade.java b/src/main/java/org/opensearch/geospatial/ip2geo/dao/GeoIpDataDao.java similarity index 97% rename from src/main/java/org/opensearch/geospatial/ip2geo/common/GeoIpDataFacade.java rename to src/main/java/org/opensearch/geospatial/ip2geo/dao/GeoIpDataDao.java index 6b3d71d7..2c0c5d72 100644 --- a/src/main/java/org/opensearch/geospatial/ip2geo/common/GeoIpDataFacade.java +++ b/src/main/java/org/opensearch/geospatial/ip2geo/dao/GeoIpDataDao.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package org.opensearch.geospatial.ip2geo.common; +package org.opensearch.geospatial.ip2geo.dao; import static org.opensearch.geospatial.ip2geo.jobscheduler.Datasource.IP2GEO_DATA_INDEX_NAME_PREFIX; @@ -58,16 +58,18 @@ import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.geospatial.annotation.VisibleForTesting; import org.opensearch.geospatial.constants.IndexSetting; +import org.opensearch.geospatial.ip2geo.common.DatasourceManifest; +import org.opensearch.geospatial.ip2geo.common.Ip2GeoSettings; import org.opensearch.geospatial.shared.Constants; import org.opensearch.geospatial.shared.StashedThreadContext; import org.opensearch.index.query.BoolQueryBuilder; import org.opensearch.index.query.QueryBuilders; /** - * Facade class for GeoIp data + * Data access object for GeoIp data */ @Log4j2 -public class GeoIpDataFacade { +public class GeoIpDataDao { public static final int BUNDLE_SIZE = 128; private static final String IP_RANGE_FIELD_NAME = "_cidr"; private static final String DATA_FIELD_NAME = "_data"; @@ -91,7 +93,7 @@ public class GeoIpDataFacade { private final ClusterSettings clusterSettings; private final Client client; - public GeoIpDataFacade(final ClusterService clusterService, final Client client) { + public GeoIpDataDao(final ClusterService clusterService, final Client client) { this.clusterService = clusterService; this.clusterSettings = clusterService.getClusterSettings(); this.client = client; @@ -150,7 +152,7 @@ private void freezeIndex(final String indexName) { */ private String getIndexMapping() { try { - try (InputStream is = DatasourceFacade.class.getResourceAsStream("/mappings/ip2geo_geoip.json")) { + try (InputStream is = DatasourceDao.class.getResourceAsStream("/mappings/ip2geo_geoip.json")) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) { return reader.lines().map(String::trim).collect(Collectors.joining()); } diff --git a/src/main/java/org/opensearch/geospatial/ip2geo/common/Ip2GeoProcessorFacade.java b/src/main/java/org/opensearch/geospatial/ip2geo/dao/Ip2GeoProcessorDao.java similarity index 85% rename from src/main/java/org/opensearch/geospatial/ip2geo/common/Ip2GeoProcessorFacade.java rename to src/main/java/org/opensearch/geospatial/ip2geo/dao/Ip2GeoProcessorDao.java index 0f1b764f..55e1152d 100644 --- a/src/main/java/org/opensearch/geospatial/ip2geo/common/Ip2GeoProcessorFacade.java +++ b/src/main/java/org/opensearch/geospatial/ip2geo/dao/Ip2GeoProcessorDao.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package org.opensearch.geospatial.ip2geo.common; +package org.opensearch.geospatial.ip2geo.dao; import java.util.Collections; import java.util.List; @@ -14,11 +14,14 @@ import org.opensearch.ingest.IngestMetadata; import org.opensearch.ingest.IngestService; -public class Ip2GeoProcessorFacade { +/** + * Data access object for Ip2Geo processors + */ +public class Ip2GeoProcessorDao { private final IngestService ingestService; @Inject - public Ip2GeoProcessorFacade(final IngestService ingestService) { + public Ip2GeoProcessorDao(final IngestService ingestService) { this.ingestService = ingestService; } diff --git a/src/main/java/org/opensearch/geospatial/ip2geo/jobscheduler/DatasourceRunner.java b/src/main/java/org/opensearch/geospatial/ip2geo/jobscheduler/DatasourceRunner.java index b92a58a8..fe4aa36b 100644 --- a/src/main/java/org/opensearch/geospatial/ip2geo/jobscheduler/DatasourceRunner.java +++ b/src/main/java/org/opensearch/geospatial/ip2geo/jobscheduler/DatasourceRunner.java @@ -15,10 +15,10 @@ import org.opensearch.cluster.service.ClusterService; import org.opensearch.geospatial.annotation.VisibleForTesting; -import org.opensearch.geospatial.ip2geo.common.DatasourceFacade; import org.opensearch.geospatial.ip2geo.common.DatasourceState; import org.opensearch.geospatial.ip2geo.common.Ip2GeoExecutor; import org.opensearch.geospatial.ip2geo.common.Ip2GeoLockService; +import org.opensearch.geospatial.ip2geo.dao.DatasourceDao; import org.opensearch.jobscheduler.spi.JobExecutionContext; import org.opensearch.jobscheduler.spi.LockModel; import org.opensearch.jobscheduler.spi.ScheduledJobParameter; @@ -57,7 +57,7 @@ public static DatasourceRunner getJobRunnerInstance() { private ClusterService clusterService; private DatasourceUpdateService datasourceUpdateService; private Ip2GeoExecutor ip2GeoExecutor; - private DatasourceFacade datasourceFacade; + private DatasourceDao datasourceDao; private Ip2GeoLockService ip2GeoLockService; private boolean initialized; @@ -72,13 +72,13 @@ public void initialize( final ClusterService clusterService, final DatasourceUpdateService datasourceUpdateService, final Ip2GeoExecutor ip2GeoExecutor, - final DatasourceFacade datasourceFacade, + final DatasourceDao datasourceDao, final Ip2GeoLockService ip2GeoLockService ) { this.clusterService = clusterService; this.datasourceUpdateService = datasourceUpdateService; this.ip2GeoExecutor = ip2GeoExecutor; - this.datasourceFacade = datasourceFacade; + this.datasourceDao = datasourceDao; this.ip2GeoLockService = ip2GeoLockService; this.initialized = true; } @@ -131,7 +131,7 @@ protected Runnable updateDatasourceRunner(final ScheduledJobParameter jobParamet @VisibleForTesting protected void updateDatasource(final ScheduledJobParameter jobParameter, final Runnable renewLock) throws IOException { - Datasource datasource = datasourceFacade.getDatasource(jobParameter.getName()); + Datasource datasource = datasourceDao.getDatasource(jobParameter.getName()); /** * If delete request comes while update task is waiting on a queue for other update tasks to complete, * because update task for this datasource didn't acquire a lock yet, delete request is processed. @@ -147,7 +147,7 @@ protected void updateDatasource(final ScheduledJobParameter jobParameter, final log.error("Invalid datasource state. Expecting {} but received {}", DatasourceState.AVAILABLE, datasource.getState()); datasource.disable(); datasource.getUpdateStats().setLastFailedAt(Instant.now()); - datasourceFacade.updateDatasource(datasource); + datasourceDao.updateDatasource(datasource); return; } @@ -160,7 +160,7 @@ protected void updateDatasource(final ScheduledJobParameter jobParameter, final } catch (Exception e) { log.error("Failed to update datasource for {}", datasource.getName(), e); datasource.getUpdateStats().setLastFailedAt(Instant.now()); - datasourceFacade.updateDatasource(datasource); + datasourceDao.updateDatasource(datasource); } finally { postProcessing(datasource); } diff --git a/src/main/java/org/opensearch/geospatial/ip2geo/jobscheduler/DatasourceUpdateService.java b/src/main/java/org/opensearch/geospatial/ip2geo/jobscheduler/DatasourceUpdateService.java index d4e55f79..f14dd1f1 100644 --- a/src/main/java/org/opensearch/geospatial/ip2geo/jobscheduler/DatasourceUpdateService.java +++ b/src/main/java/org/opensearch/geospatial/ip2geo/jobscheduler/DatasourceUpdateService.java @@ -22,28 +22,28 @@ import org.opensearch.OpenSearchException; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.settings.ClusterSettings; -import org.opensearch.geospatial.ip2geo.common.DatasourceFacade; import org.opensearch.geospatial.ip2geo.common.DatasourceManifest; import org.opensearch.geospatial.ip2geo.common.DatasourceState; -import org.opensearch.geospatial.ip2geo.common.GeoIpDataFacade; +import org.opensearch.geospatial.ip2geo.dao.DatasourceDao; +import org.opensearch.geospatial.ip2geo.dao.GeoIpDataDao; import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule; @Log4j2 public class DatasourceUpdateService { private final ClusterService clusterService; private final ClusterSettings clusterSettings; - private final DatasourceFacade datasourceFacade; - private final GeoIpDataFacade geoIpDataFacade; + private final DatasourceDao datasourceDao; + private final GeoIpDataDao geoIpDataDao; public DatasourceUpdateService( final ClusterService clusterService, - final DatasourceFacade datasourceFacade, - final GeoIpDataFacade geoIpDataFacade + final DatasourceDao datasourceDao, + final GeoIpDataDao geoIpDataDao ) { this.clusterService = clusterService; this.clusterSettings = clusterService.getClusterSettings(); - this.datasourceFacade = datasourceFacade; - this.geoIpDataFacade = geoIpDataFacade; + this.datasourceDao = datasourceDao; + this.geoIpDataDao = geoIpDataDao; } /** @@ -64,7 +64,7 @@ public void updateOrCreateGeoIpData(final Datasource datasource, final Runnable if (shouldUpdate(datasource, manifest) == false) { log.info("Skipping GeoIP database update. Update is not required for {}", datasource.getName()); datasource.getUpdateStats().setLastSkippedAt(Instant.now()); - datasourceFacade.updateDatasource(datasource); + datasourceDao.updateDatasource(datasource); return; } @@ -72,7 +72,7 @@ public void updateOrCreateGeoIpData(final Datasource datasource, final Runnable String indexName = setupIndex(datasource); String[] header; List fieldsToStore; - try (CSVParser reader = geoIpDataFacade.getDatabaseReader(manifest)) { + try (CSVParser reader = geoIpDataDao.getDatabaseReader(manifest)) { CSVRecord headerLine = reader.iterator().next(); header = validateHeader(headerLine).values(); fieldsToStore = Arrays.asList(header).subList(1, header.length); @@ -83,7 +83,7 @@ public void updateOrCreateGeoIpData(final Datasource datasource, final Runnable datasource.getDatabase().getFields().toString() ); } - geoIpDataFacade.putGeoIpData(indexName, header, reader.iterator(), renewLock); + geoIpDataDao.putGeoIpData(indexName, header, reader.iterator(), renewLock); } Instant endTime = Instant.now(); @@ -103,7 +103,7 @@ public List getHeaderFields(String manifestUrl) throws IOException { URL url = new URL(manifestUrl); DatasourceManifest manifest = DatasourceManifest.Builder.build(url); - try (CSVParser reader = geoIpDataFacade.getDatabaseReader(manifest)) { + try (CSVParser reader = geoIpDataDao.getDatabaseReader(manifest)) { String[] fields = reader.iterator().next().values(); return Arrays.asList(fields).subList(1, fields.length); } @@ -125,7 +125,7 @@ public void deleteUnusedIndices(final Datasource datasource) { if (deletedIndices.isEmpty() == false) { datasource.getIndices().removeAll(deletedIndices); - datasourceFacade.updateDatasource(datasource); + datasourceDao.updateDatasource(datasource); } } catch (Exception e) { log.error("Failed to delete old indices for {}", datasource.getName(), e); @@ -151,7 +151,7 @@ public void updateDatasource(final Datasource datasource, final IntervalSchedule } if (updated) { - datasourceFacade.updateDatasource(datasource); + datasourceDao.updateDatasource(datasource); } } @@ -164,7 +164,7 @@ private List deleteIndices(final List indicesToDelete) { } try { - geoIpDataFacade.deleteIp2GeoDataIndex(index); + geoIpDataDao.deleteIp2GeoDataIndex(index); deletedIndices.add(index); } catch (Exception e) { log.error("Failed to delete an index [{}]", index, e); @@ -212,7 +212,7 @@ private void updateDatasourceAsSucceeded( datasource.getUpdateStats().setLastProcessingTimeInMillis(endTime.toEpochMilli() - startTime.toEpochMilli()); datasource.enable(); datasource.setState(DatasourceState.AVAILABLE); - datasourceFacade.updateDatasource(datasource); + datasourceDao.updateDatasource(datasource); log.info( "GeoIP database creation succeeded for {} and took {} seconds", datasource.getName(), @@ -229,8 +229,8 @@ private void updateDatasourceAsSucceeded( private String setupIndex(final Datasource datasource) { String indexName = datasource.newIndexName(UUID.randomUUID().toString()); datasource.getIndices().add(indexName); - datasourceFacade.updateDatasource(datasource); - geoIpDataFacade.createIndexIfNotExists(indexName); + datasourceDao.updateDatasource(datasource); + geoIpDataDao.createIndexIfNotExists(indexName); return indexName; } diff --git a/src/main/java/org/opensearch/geospatial/ip2geo/listener/Ip2GeoListener.java b/src/main/java/org/opensearch/geospatial/ip2geo/listener/Ip2GeoListener.java index a06bb30c..e6fe98f9 100644 --- a/src/main/java/org/opensearch/geospatial/ip2geo/listener/Ip2GeoListener.java +++ b/src/main/java/org/opensearch/geospatial/ip2geo/listener/Ip2GeoListener.java @@ -25,8 +25,8 @@ import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.component.AbstractLifecycleComponent; import org.opensearch.common.inject.Inject; -import org.opensearch.geospatial.ip2geo.common.DatasourceFacade; -import org.opensearch.geospatial.ip2geo.common.GeoIpDataFacade; +import org.opensearch.geospatial.ip2geo.dao.DatasourceDao; +import org.opensearch.geospatial.ip2geo.dao.GeoIpDataDao; import org.opensearch.geospatial.ip2geo.jobscheduler.Datasource; import org.opensearch.geospatial.ip2geo.jobscheduler.DatasourceExtension; import org.opensearch.geospatial.ip2geo.jobscheduler.DatasourceTask; @@ -40,8 +40,8 @@ public class Ip2GeoListener extends AbstractLifecycleComponent implements Cluste private static final int DELAY_IN_MILLIS = 10000; private final ClusterService clusterService; private final ThreadPool threadPool; - private final DatasourceFacade datasourceFacade; - private final GeoIpDataFacade geoIpDataFacade; + private final DatasourceDao datasourceDao; + private final GeoIpDataDao geoIpDataDao; @Override public void clusterChanged(final ClusterChangedEvent event) { @@ -63,17 +63,17 @@ public void clusterChanged(final ClusterChangedEvent event) { .filter(index -> index.startsWith(IP2GEO_DATA_INDEX_NAME_PREFIX)) .collect(Collectors.toList()); if (ip2GeoDataIndices.isEmpty() == false) { - threadPool.generic().submit(() -> geoIpDataFacade.deleteIp2GeoDataIndex(ip2GeoDataIndices)); + threadPool.generic().submit(() -> geoIpDataDao.deleteIp2GeoDataIndex(ip2GeoDataIndices)); } } } private void forceUpdateGeoIpData() { - datasourceFacade.getAllDatasources(new ActionListener<>() { + datasourceDao.getAllDatasources(new ActionListener<>() { @Override public void onResponse(final List datasources) { datasources.stream().forEach(Ip2GeoListener.this::scheduleForceUpdate); - datasourceFacade.updateDatasource(datasources, new ActionListener<>() { + datasourceDao.updateDatasource(datasources, new ActionListener<>() { @Override public void onResponse(final BulkResponse bulkItemResponses) { log.info("Datasources are updated for cleanup"); diff --git a/src/main/java/org/opensearch/geospatial/ip2geo/processor/Ip2GeoProcessor.java b/src/main/java/org/opensearch/geospatial/ip2geo/processor/Ip2GeoProcessor.java index f051ed1c..4c8f404b 100644 --- a/src/main/java/org/opensearch/geospatial/ip2geo/processor/Ip2GeoProcessor.java +++ b/src/main/java/org/opensearch/geospatial/ip2geo/processor/Ip2GeoProcessor.java @@ -25,9 +25,9 @@ import org.opensearch.common.settings.ClusterSettings; import org.opensearch.geospatial.annotation.VisibleForTesting; import org.opensearch.geospatial.ip2geo.cache.Ip2GeoCache; -import org.opensearch.geospatial.ip2geo.common.DatasourceFacade; import org.opensearch.geospatial.ip2geo.common.DatasourceState; -import org.opensearch.geospatial.ip2geo.common.GeoIpDataFacade; +import org.opensearch.geospatial.ip2geo.dao.DatasourceDao; +import org.opensearch.geospatial.ip2geo.dao.GeoIpDataDao; import org.opensearch.ingest.AbstractProcessor; import org.opensearch.ingest.IngestDocument; import org.opensearch.ingest.IngestService; @@ -55,8 +55,8 @@ public final class Ip2GeoProcessor extends AbstractProcessor { private final Set properties; private final boolean ignoreMissing; private final ClusterSettings clusterSettings; - private final DatasourceFacade datasourceFacade; - private final GeoIpDataFacade geoIpDataFacade; + private final DatasourceDao datasourceDao; + private final GeoIpDataDao geoIpDataDao; private final Ip2GeoCache ip2GeoCache; /** @@ -74,8 +74,8 @@ public final class Ip2GeoProcessor extends AbstractProcessor { * @param properties the properties * @param ignoreMissing true if documents with a missing value for the field should be ignored * @param clusterSettings the cluster settings - * @param datasourceFacade the datasource facade - * @param geoIpDataFacade the geoip data facade + * @param datasourceDao the datasource facade + * @param geoIpDataDao the geoip data facade * @param ip2GeoCache the cache */ public Ip2GeoProcessor( @@ -87,8 +87,8 @@ public Ip2GeoProcessor( final Set properties, final boolean ignoreMissing, final ClusterSettings clusterSettings, - final DatasourceFacade datasourceFacade, - final GeoIpDataFacade geoIpDataFacade, + final DatasourceDao datasourceDao, + final GeoIpDataDao geoIpDataDao, final Ip2GeoCache ip2GeoCache ) { super(tag, description); @@ -98,8 +98,8 @@ public Ip2GeoProcessor( this.properties = properties; this.ignoreMissing = ignoreMissing; this.clusterSettings = clusterSettings; - this.datasourceFacade = datasourceFacade; - this.geoIpDataFacade = geoIpDataFacade; + this.datasourceDao = datasourceDao; + this.geoIpDataDao = geoIpDataDao; this.ip2GeoCache = ip2GeoCache; } @@ -161,7 +161,7 @@ protected void executeInternal( } try { - geoIpDataFacade.getGeoIpData(indexName, ip, getSingleGeoIpDataListener(ingestDocument, handler)); + geoIpDataDao.getGeoIpData(indexName, ip, getSingleGeoIpDataListener(ingestDocument, handler)); } catch (Exception e) { handler.accept(null, e); } @@ -249,7 +249,7 @@ protected void executeInternal( return; } - geoIpDataFacade.getGeoIpData(indexName, (List) ips, getMultiGeoIpDataListener(ingestDocument, handler)); + geoIpDataDao.getGeoIpData(indexName, (List) ips, getMultiGeoIpDataListener(ingestDocument, handler)); } @VisibleForTesting @@ -288,8 +288,8 @@ public String getType() { @AllArgsConstructor public static final class Factory implements Processor.Factory { private final IngestService ingestService; - private final DatasourceFacade datasourceFacade; - private final GeoIpDataFacade geoIpDataFacade; + private final DatasourceDao datasourceDao; + private final GeoIpDataDao geoIpDataDao; private final Ip2GeoCache ip2GeoCache; /** @@ -318,8 +318,8 @@ public Ip2GeoProcessor create( propertyNames == null ? null : new HashSet<>(propertyNames), ignoreMissing, ingestService.getClusterService().getClusterSettings(), - datasourceFacade, - geoIpDataFacade, + datasourceDao, + geoIpDataDao, ip2GeoCache ); } diff --git a/src/main/java/org/opensearch/geospatial/plugin/GeospatialPlugin.java b/src/main/java/org/opensearch/geospatial/plugin/GeospatialPlugin.java index 6f9af628..b62206a1 100644 --- a/src/main/java/org/opensearch/geospatial/plugin/GeospatialPlugin.java +++ b/src/main/java/org/opensearch/geospatial/plugin/GeospatialPlugin.java @@ -52,11 +52,11 @@ import org.opensearch.geospatial.ip2geo.action.UpdateDatasourceAction; import org.opensearch.geospatial.ip2geo.action.UpdateDatasourceTransportAction; import org.opensearch.geospatial.ip2geo.cache.Ip2GeoCache; -import org.opensearch.geospatial.ip2geo.common.DatasourceFacade; -import org.opensearch.geospatial.ip2geo.common.GeoIpDataFacade; import org.opensearch.geospatial.ip2geo.common.Ip2GeoExecutor; import org.opensearch.geospatial.ip2geo.common.Ip2GeoLockService; import org.opensearch.geospatial.ip2geo.common.Ip2GeoSettings; +import org.opensearch.geospatial.ip2geo.dao.DatasourceDao; +import org.opensearch.geospatial.ip2geo.dao.GeoIpDataDao; import org.opensearch.geospatial.ip2geo.jobscheduler.DatasourceExtension; import org.opensearch.geospatial.ip2geo.jobscheduler.DatasourceRunner; import org.opensearch.geospatial.ip2geo.jobscheduler.DatasourceUpdateService; @@ -95,8 +95,8 @@ @Log4j2 public class GeospatialPlugin extends Plugin implements IngestPlugin, ActionPlugin, MapperPlugin, SearchPlugin, SystemIndexPlugin { private Ip2GeoCache ip2GeoCache; - private DatasourceFacade datasourceFacade; - private GeoIpDataFacade geoIpDataFacade; + private DatasourceDao datasourceDao; + private GeoIpDataDao geoIpDataDao; @Override public Collection getSystemIndexDescriptors(Settings settings) { @@ -105,15 +105,12 @@ public Collection getSystemIndexDescriptors(Settings sett @Override public Map getProcessors(Processor.Parameters parameters) { - this.datasourceFacade = new DatasourceFacade(parameters.client, parameters.ingestService.getClusterService()); - this.geoIpDataFacade = new GeoIpDataFacade(parameters.ingestService.getClusterService(), parameters.client); - this.ip2GeoCache = new Ip2GeoCache(datasourceFacade); + this.datasourceDao = new DatasourceDao(parameters.client, parameters.ingestService.getClusterService()); + this.geoIpDataDao = new GeoIpDataDao(parameters.ingestService.getClusterService(), parameters.client); + this.ip2GeoCache = new Ip2GeoCache(datasourceDao); return MapBuilder.newMapBuilder() .put(FeatureProcessor.TYPE, new FeatureProcessor.Factory()) - .put( - Ip2GeoProcessor.TYPE, - new Ip2GeoProcessor.Factory(parameters.ingestService, datasourceFacade, geoIpDataFacade, ip2GeoCache) - ) + .put(Ip2GeoProcessor.TYPE, new Ip2GeoProcessor.Factory(parameters.ingestService, datasourceDao, geoIpDataDao, ip2GeoCache)) .immutableMap(); } @@ -156,7 +153,7 @@ public Collection createComponents( IndexNameExpressionResolver indexNameExpressionResolver, Supplier repositoriesServiceSupplier ) { - DatasourceUpdateService datasourceUpdateService = new DatasourceUpdateService(clusterService, datasourceFacade, geoIpDataFacade); + DatasourceUpdateService datasourceUpdateService = new DatasourceUpdateService(clusterService, datasourceDao, geoIpDataDao); Ip2GeoExecutor ip2GeoExecutor = new Ip2GeoExecutor(threadPool); Ip2GeoLockService ip2GeoLockService = new Ip2GeoLockService(clusterService, client); /** @@ -164,14 +161,14 @@ public Collection createComponents( * does not use DI but it calls DatasourceExtension#getJobRunner to get DatasourceRunner instance. */ DatasourceRunner.getJobRunnerInstance() - .initialize(clusterService, datasourceUpdateService, ip2GeoExecutor, datasourceFacade, ip2GeoLockService); + .initialize(clusterService, datasourceUpdateService, ip2GeoExecutor, datasourceDao, ip2GeoLockService); return List.of( UploadStats.getInstance(), datasourceUpdateService, - datasourceFacade, + datasourceDao, ip2GeoExecutor, - geoIpDataFacade, + geoIpDataDao, ip2GeoLockService, ip2GeoCache ); diff --git a/src/test/java/org/opensearch/geospatial/ip2geo/Ip2GeoTestCase.java b/src/test/java/org/opensearch/geospatial/ip2geo/Ip2GeoTestCase.java index 5cf42fa6..cb641d49 100644 --- a/src/test/java/org/opensearch/geospatial/ip2geo/Ip2GeoTestCase.java +++ b/src/test/java/org/opensearch/geospatial/ip2geo/Ip2GeoTestCase.java @@ -44,13 +44,13 @@ import org.opensearch.common.util.concurrent.OpenSearchExecutors; import org.opensearch.geospatial.GeospatialTestHelper; import org.opensearch.geospatial.ip2geo.cache.Ip2GeoCache; -import org.opensearch.geospatial.ip2geo.common.DatasourceFacade; import org.opensearch.geospatial.ip2geo.common.DatasourceState; -import org.opensearch.geospatial.ip2geo.common.GeoIpDataFacade; import org.opensearch.geospatial.ip2geo.common.Ip2GeoExecutor; import org.opensearch.geospatial.ip2geo.common.Ip2GeoLockService; -import org.opensearch.geospatial.ip2geo.common.Ip2GeoProcessorFacade; import org.opensearch.geospatial.ip2geo.common.Ip2GeoSettings; +import org.opensearch.geospatial.ip2geo.dao.DatasourceDao; +import org.opensearch.geospatial.ip2geo.dao.GeoIpDataDao; +import org.opensearch.geospatial.ip2geo.dao.Ip2GeoProcessorDao; import org.opensearch.geospatial.ip2geo.jobscheduler.Datasource; import org.opensearch.geospatial.ip2geo.jobscheduler.DatasourceTask; import org.opensearch.geospatial.ip2geo.jobscheduler.DatasourceUpdateService; @@ -73,11 +73,11 @@ public abstract class Ip2GeoTestCase extends RestActionTestCase { @Mock protected DatasourceUpdateService datasourceUpdateService; @Mock - protected DatasourceFacade datasourceFacade; + protected DatasourceDao datasourceDao; @Mock protected Ip2GeoExecutor ip2GeoExecutor; @Mock - protected GeoIpDataFacade geoIpDataFacade; + protected GeoIpDataDao geoIpDataDao; @Mock protected Ip2GeoCache ip2GeoCache; @Mock @@ -95,7 +95,7 @@ public abstract class Ip2GeoTestCase extends RestActionTestCase { @Mock protected Ip2GeoLockService ip2GeoLockService; @Mock - protected Ip2GeoProcessorFacade ip2GeoProcessorFacade; + protected Ip2GeoProcessorDao ip2GeoProcessorDao; protected IngestMetadata ingestMetadata; protected NoOpNodeClient client; protected VerifyingClient verifyingClient; @@ -264,8 +264,8 @@ protected Ip2GeoProcessor randomIp2GeoProcessor(String datasourceName) { properties, true, clusterSettings, - datasourceFacade, - geoIpDataFacade, + datasourceDao, + geoIpDataDao, ip2GeoCache ); return ip2GeoProcessor; diff --git a/src/test/java/org/opensearch/geospatial/ip2geo/action/DeleteDatasourceTransportActionTests.java b/src/test/java/org/opensearch/geospatial/ip2geo/action/DeleteDatasourceTransportActionTests.java index ce5c91d4..3abf3c9d 100644 --- a/src/test/java/org/opensearch/geospatial/ip2geo/action/DeleteDatasourceTransportActionTests.java +++ b/src/test/java/org/opensearch/geospatial/ip2geo/action/DeleteDatasourceTransportActionTests.java @@ -46,9 +46,9 @@ public void init() { actionFilters, ip2GeoLockService, ingestService, - datasourceFacade, - geoIpDataFacade, - ip2GeoProcessorFacade, + datasourceDao, + geoIpDataDao, + ip2GeoProcessorDao, threadPool ); } @@ -74,7 +74,7 @@ public void testDoExecute_whenException_thenError() { private void validateDoExecute(final LockModel lockModel, final Exception exception) throws IOException { Task task = mock(Task.class); Datasource datasource = randomDatasource(); - when(datasourceFacade.getDatasource(datasource.getName())).thenReturn(datasource); + when(datasourceDao.getDatasource(datasource.getName())).thenReturn(datasource); DeleteDatasourceRequest request = new DeleteDatasourceRequest(datasource.getName()); ActionListener listener = mock(ActionListener.class); @@ -113,45 +113,43 @@ public void testDeleteDatasource_whenNull_thenThrowException() { @SneakyThrows public void testDeleteDatasource_whenSafeToDelete_thenDelete() { Datasource datasource = randomDatasource(); - when(datasourceFacade.getDatasource(datasource.getName())).thenReturn(datasource); - when(ip2GeoProcessorFacade.getProcessors(datasource.getName())).thenReturn(Collections.emptyList()); + when(datasourceDao.getDatasource(datasource.getName())).thenReturn(datasource); + when(ip2GeoProcessorDao.getProcessors(datasource.getName())).thenReturn(Collections.emptyList()); // Run action.deleteDatasource(datasource.getName()); // Verify assertEquals(DatasourceState.DELETING, datasource.getState()); - verify(datasourceFacade).updateDatasource(datasource); - InOrder inOrder = Mockito.inOrder(geoIpDataFacade, datasourceFacade); - inOrder.verify(geoIpDataFacade).deleteIp2GeoDataIndex(datasource.getIndices()); - inOrder.verify(datasourceFacade).deleteDatasource(datasource); + verify(datasourceDao).updateDatasource(datasource); + InOrder inOrder = Mockito.inOrder(geoIpDataDao, datasourceDao); + inOrder.verify(geoIpDataDao).deleteIp2GeoDataIndex(datasource.getIndices()); + inOrder.verify(datasourceDao).deleteDatasource(datasource); } @SneakyThrows public void testDeleteDatasource_whenProcessorIsUsingDatasource_thenThrowException() { Datasource datasource = randomDatasource(); datasource.setState(DatasourceState.AVAILABLE); - when(datasourceFacade.getDatasource(datasource.getName())).thenReturn(datasource); - when(ip2GeoProcessorFacade.getProcessors(datasource.getName())).thenReturn( - Arrays.asList(randomIp2GeoProcessor(datasource.getName())) - ); + when(datasourceDao.getDatasource(datasource.getName())).thenReturn(datasource); + when(ip2GeoProcessorDao.getProcessors(datasource.getName())).thenReturn(Arrays.asList(randomIp2GeoProcessor(datasource.getName()))); // Run expectThrows(OpenSearchException.class, () -> action.deleteDatasource(datasource.getName())); // Verify assertEquals(DatasourceState.AVAILABLE, datasource.getState()); - verify(datasourceFacade, never()).updateDatasource(datasource); - verify(geoIpDataFacade, never()).deleteIp2GeoDataIndex(datasource.getIndices()); - verify(datasourceFacade, never()).deleteDatasource(datasource); + verify(datasourceDao, never()).updateDatasource(datasource); + verify(geoIpDataDao, never()).deleteIp2GeoDataIndex(datasource.getIndices()); + verify(datasourceDao, never()).deleteDatasource(datasource); } @SneakyThrows public void testDeleteDatasource_whenProcessorIsCreatedDuringDeletion_thenThrowException() { Datasource datasource = randomDatasource(); datasource.setState(DatasourceState.AVAILABLE); - when(datasourceFacade.getDatasource(datasource.getName())).thenReturn(datasource); - when(ip2GeoProcessorFacade.getProcessors(datasource.getName())).thenReturn( + when(datasourceDao.getDatasource(datasource.getName())).thenReturn(datasource); + when(ip2GeoProcessorDao.getProcessors(datasource.getName())).thenReturn( Collections.emptyList(), Arrays.asList(randomIp2GeoProcessor(datasource.getName())) ); @@ -160,8 +158,8 @@ public void testDeleteDatasource_whenProcessorIsCreatedDuringDeletion_thenThrowE expectThrows(OpenSearchException.class, () -> action.deleteDatasource(datasource.getName())); // Verify - verify(datasourceFacade, times(2)).updateDatasource(datasource); - verify(geoIpDataFacade, never()).deleteIp2GeoDataIndex(datasource.getIndices()); - verify(datasourceFacade, never()).deleteDatasource(datasource); + verify(datasourceDao, times(2)).updateDatasource(datasource); + verify(geoIpDataDao, never()).deleteIp2GeoDataIndex(datasource.getIndices()); + verify(datasourceDao, never()).deleteDatasource(datasource); } } diff --git a/src/test/java/org/opensearch/geospatial/ip2geo/action/GetDatasourceTransportActionTests.java b/src/test/java/org/opensearch/geospatial/ip2geo/action/GetDatasourceTransportActionTests.java index 0404da0f..b7732a31 100644 --- a/src/test/java/org/opensearch/geospatial/ip2geo/action/GetDatasourceTransportActionTests.java +++ b/src/test/java/org/opensearch/geospatial/ip2geo/action/GetDatasourceTransportActionTests.java @@ -26,7 +26,7 @@ public class GetDatasourceTransportActionTests extends Ip2GeoTestCase { @Before public void init() { - action = new GetDatasourceTransportAction(transportService, actionFilters, datasourceFacade); + action = new GetDatasourceTransportAction(transportService, actionFilters, datasourceDao); } public void testDoExecute_whenAll_thenSucceed() { @@ -38,7 +38,7 @@ public void testDoExecute_whenAll_thenSucceed() { action.doExecute(task, request, listener); // Verify - verify(datasourceFacade).getAllDatasources(any(ActionListener.class)); + verify(datasourceDao).getAllDatasources(any(ActionListener.class)); } public void testDoExecute_whenNames_thenSucceed() { @@ -53,7 +53,7 @@ public void testDoExecute_whenNames_thenSucceed() { action.doExecute(task, request, listener); // Verify - verify(datasourceFacade).getDatasources(eq(datasourceNames), any(ActionListener.class)); + verify(datasourceDao).getDatasources(eq(datasourceNames), any(ActionListener.class)); } public void testNewActionListener_whenOnResponse_thenSucceed() { diff --git a/src/test/java/org/opensearch/geospatial/ip2geo/action/PutDatasourceTransportActionTests.java b/src/test/java/org/opensearch/geospatial/ip2geo/action/PutDatasourceTransportActionTests.java index ff838b84..ef426cc5 100644 --- a/src/test/java/org/opensearch/geospatial/ip2geo/action/PutDatasourceTransportActionTests.java +++ b/src/test/java/org/opensearch/geospatial/ip2geo/action/PutDatasourceTransportActionTests.java @@ -42,7 +42,7 @@ public void init() { transportService, actionFilters, threadPool, - datasourceFacade, + datasourceDao, datasourceUpdateService, ip2GeoLockService ); @@ -74,7 +74,7 @@ private void validateDoExecute(final LockModel lockModel, final Exception before PutDatasourceRequest request = new PutDatasourceRequest(datasource.getName()); ActionListener listener = mock(ActionListener.class); if (after != null) { - doThrow(after).when(datasourceFacade).createIndexIfNotExists(any(StepListener.class)); + doThrow(after).when(datasourceDao).createIndexIfNotExists(any(StepListener.class)); } // Run @@ -118,14 +118,14 @@ public void testInternalDoExecute_whenValidInput_thenSucceed() { // Verify ArgumentCaptor captor = ArgumentCaptor.forClass(StepListener.class); - verify(datasourceFacade).createIndexIfNotExists(captor.capture()); + verify(datasourceDao).createIndexIfNotExists(captor.capture()); // Run captor.getValue().onResponse(null); // Verify ArgumentCaptor datasourceCaptor = ArgumentCaptor.forClass(Datasource.class); ArgumentCaptor actionListenerCaptor = ArgumentCaptor.forClass(ActionListener.class); - verify(datasourceFacade).putDatasource(datasourceCaptor.capture(), actionListenerCaptor.capture()); + verify(datasourceDao).putDatasource(datasourceCaptor.capture(), actionListenerCaptor.capture()); assertEquals(request.getName(), datasourceCaptor.getValue().getName()); assertEquals(request.getEndpoint(), datasourceCaptor.getValue().getEndpoint()); assertEquals(request.getUpdateInterval().days(), datasourceCaptor.getValue().getUserSchedule().getInterval()); @@ -162,7 +162,7 @@ public void testCreateDatasource_whenInvalidState_thenUpdateStateAsFailed() { // Verify assertEquals(DatasourceState.CREATE_FAILED, datasource.getState()); assertNotNull(datasource.getUpdateStats().getLastFailedAt()); - verify(datasourceFacade).updateDatasource(datasource); + verify(datasourceDao).updateDatasource(datasource); verify(datasourceUpdateService, never()).updateOrCreateGeoIpData(any(Datasource.class), any(Runnable.class)); } @@ -177,7 +177,7 @@ public void testCreateDatasource_whenExceptionHappens_thenUpdateStateAsFailed() // Verify assertEquals(DatasourceState.CREATE_FAILED, datasource.getState()); assertNotNull(datasource.getUpdateStats().getLastFailedAt()); - verify(datasourceFacade).updateDatasource(datasource); + verify(datasourceDao).updateDatasource(datasource); } @SneakyThrows diff --git a/src/test/java/org/opensearch/geospatial/ip2geo/action/UpdateDatasourceTransportActionTests.java b/src/test/java/org/opensearch/geospatial/ip2geo/action/UpdateDatasourceTransportActionTests.java index 32272f62..e0a94a75 100644 --- a/src/test/java/org/opensearch/geospatial/ip2geo/action/UpdateDatasourceTransportActionTests.java +++ b/src/test/java/org/opensearch/geospatial/ip2geo/action/UpdateDatasourceTransportActionTests.java @@ -44,7 +44,7 @@ public void init() { transportService, actionFilters, ip2GeoLockService, - datasourceFacade, + datasourceDao, datasourceUpdateService, threadPool ); @@ -94,7 +94,7 @@ public void testDoExecute_whenValidInput_thenUpdate() { request.setUpdateInterval(TimeValue.timeValueDays(datasource.getSchedule().getInterval())); Task task = mock(Task.class); - when(datasourceFacade.getDatasource(datasource.getName())).thenReturn(datasource); + when(datasourceDao.getDatasource(datasource.getName())).thenReturn(datasource); when(datasourceUpdateService.getHeaderFields(request.getEndpoint())).thenReturn(datasource.getDatabase().getFields()); ActionListener listener = mock(ActionListener.class); LockModel lockModel = randomLockModel(); @@ -110,8 +110,8 @@ public void testDoExecute_whenValidInput_thenUpdate() { captor.getValue().onResponse(lockModel); // Verify - verify(datasourceFacade).getDatasource(datasource.getName()); - verify(datasourceFacade).updateDatasource(datasource); + verify(datasourceDao).getDatasource(datasource.getName()); + verify(datasourceDao).updateDatasource(datasource); verify(datasourceUpdateService).getHeaderFields(request.getEndpoint()); assertEquals(request.getEndpoint(), datasource.getEndpoint()); assertEquals(request.getUpdateInterval().days(), datasource.getUserSchedule().getInterval()); @@ -128,7 +128,7 @@ public void testDoExecute_whenNoChangesInValues_thenNoUpdate() { request.setEndpoint(datasource.getEndpoint()); Task task = mock(Task.class); - when(datasourceFacade.getDatasource(datasource.getName())).thenReturn(datasource); + when(datasourceDao.getDatasource(datasource.getName())).thenReturn(datasource); ActionListener listener = mock(ActionListener.class); LockModel lockModel = randomLockModel(); @@ -143,9 +143,9 @@ public void testDoExecute_whenNoChangesInValues_thenNoUpdate() { captor.getValue().onResponse(lockModel); // Verify - verify(datasourceFacade).getDatasource(datasource.getName()); + verify(datasourceDao).getDatasource(datasource.getName()); verify(datasourceUpdateService, never()).getHeaderFields(anyString()); - verify(datasourceFacade, never()).updateDatasource(datasource); + verify(datasourceDao, never()).updateDatasource(datasource); verify(listener).onResponse(new AcknowledgedResponse(true)); verify(ip2GeoLockService).releaseLock(eq(lockModel)); } @@ -184,7 +184,7 @@ public void testDoExecute_whenIncompatibleFields_thenError() { request.setEndpoint(sampleManifestUrl()); Task task = mock(Task.class); - when(datasourceFacade.getDatasource(datasource.getName())).thenReturn(datasource); + when(datasourceDao.getDatasource(datasource.getName())).thenReturn(datasource); List newFields = datasource.getDatabase().getFields().subList(0, 0); when(datasourceUpdateService.getHeaderFields(request.getEndpoint())).thenReturn(newFields); ActionListener listener = mock(ActionListener.class); @@ -215,7 +215,7 @@ public void testDoExecute_whenLargeUpdateInterval_thenError() { request.setUpdateInterval(TimeValue.timeValueDays(datasource.getDatabase().getValidForInDays())); Task task = mock(Task.class); - when(datasourceFacade.getDatasource(datasource.getName())).thenReturn(datasource); + when(datasourceDao.getDatasource(datasource.getName())).thenReturn(datasource); ActionListener listener = mock(ActionListener.class); LockModel lockModel = randomLockModel(); @@ -246,7 +246,7 @@ public void testDoExecute_whenExpireWithNewUpdateInterval_thenError() { request.setUpdateInterval(TimeValue.timeValueDays(1)); Task task = mock(Task.class); - when(datasourceFacade.getDatasource(datasource.getName())).thenReturn(datasource); + when(datasourceDao.getDatasource(datasource.getName())).thenReturn(datasource); ActionListener listener = mock(ActionListener.class); LockModel lockModel = randomLockModel(); diff --git a/src/test/java/org/opensearch/geospatial/ip2geo/cache/Ip2GeoCacheTests.java b/src/test/java/org/opensearch/geospatial/ip2geo/cache/Ip2GeoCacheTests.java index 01dc2fc5..28549905 100644 --- a/src/test/java/org/opensearch/geospatial/ip2geo/cache/Ip2GeoCacheTests.java +++ b/src/test/java/org/opensearch/geospatial/ip2geo/cache/Ip2GeoCacheTests.java @@ -28,12 +28,12 @@ public class Ip2GeoCacheTests extends Ip2GeoTestCase { @Before public void init() { - ip2GeoCache = new Ip2GeoCache(datasourceFacade); + ip2GeoCache = new Ip2GeoCache(datasourceDao); } public void testGetIndexName_whenCalled_thenReturnIndexName() { Datasource datasource = randomDatasource(); - when(datasourceFacade.getAllDatasources()).thenReturn(Arrays.asList(datasource)); + when(datasourceDao.getAllDatasources()).thenReturn(Arrays.asList(datasource)); // Run String indexName = ip2GeoCache.getIndexName(datasource.getName()); @@ -46,7 +46,7 @@ public void testIsExpired_whenExpired_thenReturnTrue() { Datasource datasource = randomDatasource(); datasource.getUpdateStats().setLastSucceededAt(Instant.MIN); datasource.getUpdateStats().setLastSkippedAt(null); - when(datasourceFacade.getAllDatasources()).thenReturn(Arrays.asList(datasource)); + when(datasourceDao.getAllDatasources()).thenReturn(Arrays.asList(datasource)); // Run boolean isExpired = ip2GeoCache.isExpired(datasource.getName()); @@ -59,7 +59,7 @@ public void testIsExpired_whenNotExpired_thenReturnFalse() { Datasource datasource = randomDatasource(); datasource.getUpdateStats().setLastSucceededAt(Instant.now()); datasource.getUpdateStats().setLastSkippedAt(null); - when(datasourceFacade.getAllDatasources()).thenReturn(Arrays.asList(datasource)); + when(datasourceDao.getAllDatasources()).thenReturn(Arrays.asList(datasource)); // Run boolean isExpired = ip2GeoCache.isExpired(datasource.getName()); @@ -70,7 +70,7 @@ public void testIsExpired_whenNotExpired_thenReturnFalse() { public void testHas_whenHasDatasource_thenReturnTrue() { Datasource datasource = randomDatasource(); - when(datasourceFacade.getAllDatasources()).thenReturn(Arrays.asList(datasource)); + when(datasourceDao.getAllDatasources()).thenReturn(Arrays.asList(datasource)); // Run boolean hasDatasource = ip2GeoCache.has(datasource.getName()); @@ -81,7 +81,7 @@ public void testHas_whenHasDatasource_thenReturnTrue() { public void testHas_whenNoDatasource_thenReturnFalse() { Datasource datasource = randomDatasource(); - when(datasourceFacade.getAllDatasources()).thenReturn(Arrays.asList(datasource)); + when(datasourceDao.getAllDatasources()).thenReturn(Arrays.asList(datasource)); String datasourceName = GeospatialTestHelper.randomLowerCaseString(); // Run @@ -93,7 +93,7 @@ public void testHas_whenNoDatasource_thenReturnFalse() { public void testGetState_whenCalled_thenReturnState() { Datasource datasource = randomDatasource(); - when(datasourceFacade.getAllDatasources()).thenReturn(Arrays.asList(datasource)); + when(datasourceDao.getAllDatasources()).thenReturn(Arrays.asList(datasource)); // Run DatasourceState state = ip2GeoCache.getState(datasource.getName()); @@ -104,7 +104,7 @@ public void testGetState_whenCalled_thenReturnState() { @SneakyThrows public void testPostIndex_whenFailed_thenNoUpdate() { - when(datasourceFacade.getAllDatasources()).thenReturn(Arrays.asList()); + when(datasourceDao.getAllDatasources()).thenReturn(Arrays.asList()); Datasource datasource = randomDatasource(); ShardId shardId = mock(ShardId.class); @@ -126,7 +126,7 @@ public void testPostIndex_whenFailed_thenNoUpdate() { @SneakyThrows public void testPostIndex_whenSucceed_thenUpdate() { - when(datasourceFacade.getAllDatasources()).thenReturn(Arrays.asList()); + when(datasourceDao.getAllDatasources()).thenReturn(Arrays.asList()); Datasource datasource = randomDatasource(); ShardId shardId = mock(ShardId.class); @@ -148,7 +148,7 @@ public void testPostIndex_whenSucceed_thenUpdate() { public void testPostDelete_whenFailed_thenNoUpdate() { Datasource datasource = randomDatasource(); - when(datasourceFacade.getAllDatasources()).thenReturn(Arrays.asList(datasource)); + when(datasourceDao.getAllDatasources()).thenReturn(Arrays.asList(datasource)); ShardId shardId = mock(ShardId.class); Engine.Delete index = mock(Engine.Delete.class); @@ -164,7 +164,7 @@ public void testPostDelete_whenFailed_thenNoUpdate() { public void testPostDelete_whenSucceed_thenUpdate() { Datasource datasource = randomDatasource(); - when(datasourceFacade.getAllDatasources()).thenReturn(Arrays.asList(datasource)); + when(datasourceDao.getAllDatasources()).thenReturn(Arrays.asList(datasource)); ShardId shardId = mock(ShardId.class); Engine.Delete index = mock(Engine.Delete.class); diff --git a/src/test/java/org/opensearch/geospatial/ip2geo/common/DatasourceFacadeTests.java b/src/test/java/org/opensearch/geospatial/ip2geo/dao/DatasourceDaoTests.java similarity index 91% rename from src/test/java/org/opensearch/geospatial/ip2geo/common/DatasourceFacadeTests.java rename to src/test/java/org/opensearch/geospatial/ip2geo/dao/DatasourceDaoTests.java index 748e6ab4..09e2dd46 100644 --- a/src/test/java/org/opensearch/geospatial/ip2geo/common/DatasourceFacadeTests.java +++ b/src/test/java/org/opensearch/geospatial/ip2geo/dao/DatasourceDaoTests.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package org.opensearch.geospatial.ip2geo.common; +package org.opensearch.geospatial.ip2geo.dao; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; @@ -53,12 +53,12 @@ import org.opensearch.search.SearchHit; import org.opensearch.search.SearchHits; -public class DatasourceFacadeTests extends Ip2GeoTestCase { - private DatasourceFacade datasourceFacade; +public class DatasourceDaoTests extends Ip2GeoTestCase { + private DatasourceDao datasourceDao; @Before public void init() { - datasourceFacade = new DatasourceFacade(verifyingClient, clusterService); + datasourceDao = new DatasourceDao(verifyingClient, clusterService); } public void testCreateIndexIfNotExists_whenIndexExist_thenCreateRequestIsNotCalled() { @@ -69,7 +69,7 @@ public void testCreateIndexIfNotExists_whenIndexExist_thenCreateRequestIsNotCall // Run StepListener stepListener = new StepListener<>(); - datasourceFacade.createIndexIfNotExists(stepListener); + datasourceDao.createIndexIfNotExists(stepListener); // Verify stepListener is called stepListener.result(); @@ -92,7 +92,7 @@ public void testCreateIndexIfNotExists_whenIndexExist_thenCreateRequestIsCalled( // Run StepListener stepListener = new StepListener<>(); - datasourceFacade.createIndexIfNotExists(stepListener); + datasourceDao.createIndexIfNotExists(stepListener); // Verify stepListener is called stepListener.result(); @@ -106,7 +106,7 @@ public void testCreateIndexIfNotExists_whenIndexCreatedAlready_thenExceptionIsIg // Run StepListener stepListener = new StepListener<>(); - datasourceFacade.createIndexIfNotExists(stepListener); + datasourceDao.createIndexIfNotExists(stepListener); // Verify stepListener is called stepListener.result(); @@ -118,7 +118,7 @@ public void testCreateIndexIfNotExists_whenExceptionIsThrown_thenExceptionIsThro // Run StepListener stepListener = new StepListener<>(); - datasourceFacade.createIndexIfNotExists(stepListener); + datasourceDao.createIndexIfNotExists(stepListener); // Verify stepListener is called expectThrows(RuntimeException.class, () -> stepListener.result()); @@ -144,7 +144,7 @@ public void testUpdateDatasource_whenValidInput_thenSucceed() throws Exception { return null; }); - datasourceFacade.updateDatasource(datasource); + datasourceDao.updateDatasource(datasource); assertTrue(previousTime.isBefore(datasource.getLastUpdateTime())); } @@ -164,36 +164,36 @@ public void testPutDatasource_whenValidInpu_thenSucceed() { return null; }); - datasourceFacade.putDatasource(datasource, mock(ActionListener.class)); + datasourceDao.putDatasource(datasource, mock(ActionListener.class)); assertTrue(previousTime.isBefore(datasource.getLastUpdateTime())); } public void testGetDatasource_whenException_thenNull() throws Exception { Datasource datasource = setupClientForGetRequest(true, new IndexNotFoundException(DatasourceExtension.JOB_INDEX_NAME)); - assertNull(datasourceFacade.getDatasource(datasource.getName())); + assertNull(datasourceDao.getDatasource(datasource.getName())); } public void testGetDatasource_whenExist_thenReturnDatasource() throws Exception { Datasource datasource = setupClientForGetRequest(true, null); - assertEquals(datasource, datasourceFacade.getDatasource(datasource.getName())); + assertEquals(datasource, datasourceDao.getDatasource(datasource.getName())); } public void testGetDatasource_whenNotExist_thenNull() throws Exception { Datasource datasource = setupClientForGetRequest(false, null); - assertNull(datasourceFacade.getDatasource(datasource.getName())); + assertNull(datasourceDao.getDatasource(datasource.getName())); } public void testGetDatasource_whenExistWithListener_thenListenerIsCalledWithDatasource() { Datasource datasource = setupClientForGetRequest(true, null); ActionListener listener = mock(ActionListener.class); - datasourceFacade.getDatasource(datasource.getName(), listener); + datasourceDao.getDatasource(datasource.getName(), listener); verify(listener).onResponse(eq(datasource)); } public void testGetDatasource_whenNotExistWithListener_thenListenerIsCalledWithNull() { Datasource datasource = setupClientForGetRequest(false, null); ActionListener listener = mock(ActionListener.class); - datasourceFacade.getDatasource(datasource.getName(), listener); + datasourceDao.getDatasource(datasource.getName(), listener); verify(listener).onResponse(null); } @@ -231,7 +231,7 @@ public void testDeleteDatasource_whenValidInput_thenSucceed() { }); // Run - datasourceFacade.deleteDatasource(datasource); + datasourceDao.deleteDatasource(datasource); } public void testDeleteDatasource_whenIndexNotFound_thenThrowException() { @@ -243,7 +243,7 @@ public void testDeleteDatasource_whenIndexNotFound_thenThrowException() { }); // Run - expectThrows(ResourceNotFoundException.class, () -> datasourceFacade.deleteDatasource(datasource)); + expectThrows(ResourceNotFoundException.class, () -> datasourceDao.deleteDatasource(datasource)); } public void testGetDatasources_whenValidInput_thenSucceed() { @@ -273,7 +273,7 @@ public void testGetDatasources_whenValidInput_thenSucceed() { }); // Run - datasourceFacade.getDatasources(names, listener); + datasourceDao.getDatasources(names, listener); // Verify ArgumentCaptor> captor = ArgumentCaptor.forClass(List.class); @@ -302,7 +302,7 @@ public void testGetAllDatasources_whenAsynchronous_thenSucceed() { }); // Run - datasourceFacade.getAllDatasources(listener); + datasourceDao.getAllDatasources(listener); // Verify ArgumentCaptor> captor = ArgumentCaptor.forClass(List.class); @@ -329,10 +329,10 @@ public void testGetAllDatasources_whenSynchronous_thenSucceed() { }); // Run - datasourceFacade.getAllDatasources(); + datasourceDao.getAllDatasources(); // Verify - assertEquals(datasources, datasourceFacade.getAllDatasources()); + assertEquals(datasources, datasourceDao.getAllDatasources()); } public void testUpdateDatasource_whenValidInput_thenUpdate() { @@ -353,7 +353,7 @@ public void testUpdateDatasource_whenValidInput_thenUpdate() { return null; }); - datasourceFacade.updateDatasource(datasources, mock(ActionListener.class)); + datasourceDao.updateDatasource(datasources, mock(ActionListener.class)); } private SearchHits getMockedSearchHits(List datasources) { diff --git a/src/test/java/org/opensearch/geospatial/ip2geo/common/GeoIpDataFacadeTests.java b/src/test/java/org/opensearch/geospatial/ip2geo/dao/GeoIpDataDaoTests.java similarity index 91% rename from src/test/java/org/opensearch/geospatial/ip2geo/common/GeoIpDataFacadeTests.java rename to src/test/java/org/opensearch/geospatial/ip2geo/dao/GeoIpDataDaoTests.java index 9e51f23b..13872a27 100644 --- a/src/test/java/org/opensearch/geospatial/ip2geo/common/GeoIpDataFacadeTests.java +++ b/src/test/java/org/opensearch/geospatial/ip2geo/dao/GeoIpDataDaoTests.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package org.opensearch.geospatial.ip2geo.common; +package org.opensearch.geospatial.ip2geo.dao; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; @@ -50,29 +50,30 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.geospatial.GeospatialTestHelper; import org.opensearch.geospatial.ip2geo.Ip2GeoTestCase; +import org.opensearch.geospatial.ip2geo.common.DatasourceManifest; import org.opensearch.geospatial.shared.Constants; import org.opensearch.index.query.QueryBuilders; import org.opensearch.search.SearchHit; import org.opensearch.search.SearchHits; @SuppressForbidden(reason = "unit test") -public class GeoIpDataFacadeTests extends Ip2GeoTestCase { +public class GeoIpDataDaoTests extends Ip2GeoTestCase { private static final String IP_RANGE_FIELD_NAME = "_cidr"; private static final String DATA_FIELD_NAME = "_data"; - private GeoIpDataFacade noOpsGeoIpDataFacade; - private GeoIpDataFacade verifyingGeoIpDataFacade; + private GeoIpDataDao noOpsGeoIpDataDao; + private GeoIpDataDao verifyingGeoIpDataDao; @Before public void init() { - noOpsGeoIpDataFacade = new GeoIpDataFacade(clusterService, client); - verifyingGeoIpDataFacade = new GeoIpDataFacade(clusterService, verifyingClient); + noOpsGeoIpDataDao = new GeoIpDataDao(clusterService, client); + verifyingGeoIpDataDao = new GeoIpDataDao(clusterService, verifyingClient); } public void testCreateIndexIfNotExistsWithExistingIndex() { String index = GeospatialTestHelper.randomLowerCaseString(); when(metadata.hasIndex(index)).thenReturn(true); verifyingClient.setExecuteVerifier((actionResponse, actionRequest) -> { throw new RuntimeException("Shouldn't get called"); }); - verifyingGeoIpDataFacade.createIndexIfNotExists(index); + verifyingGeoIpDataDao.createIndexIfNotExists(index); } public void testCreateIndexIfNotExistsWithoutExistingIndex() { @@ -94,7 +95,7 @@ public void testCreateIndexIfNotExistsWithoutExistingIndex() { ); return null; }); - verifyingGeoIpDataFacade.createIndexIfNotExists(index); + verifyingGeoIpDataDao.createIndexIfNotExists(index); } @SneakyThrows @@ -103,7 +104,7 @@ public void testCreateDocument_whenBlankValue_thenDoNotAdd() { String[] values = { "1.0.0.0/25", "USA", " ", "Seattle" }; assertEquals( "{\"_cidr\":\"1.0.0.0/25\",\"_data\":{\"country\":\"USA\",\"city\":\"Seattle\"}}", - Strings.toString(noOpsGeoIpDataFacade.createDocument(names, values)) + Strings.toString(noOpsGeoIpDataDao.createDocument(names, values)) ); } @@ -117,7 +118,7 @@ public void testGetDatabaseReader() throws Exception { Instant.now().toEpochMilli(), "tester" ); - CSVParser parser = noOpsGeoIpDataFacade.getDatabaseReader(manifest); + CSVParser parser = noOpsGeoIpDataDao.getDatabaseReader(manifest); String[] expectedHeader = { "network", "country_name" }; assertArrayEquals(expectedHeader, parser.iterator().next().values()); String[] expectedValues = { "1.0.0.0/24", "Australia" }; @@ -134,7 +135,7 @@ public void testGetDatabaseReaderNoFile() throws Exception { Instant.now().toEpochMilli(), "tester" ); - OpenSearchException exception = expectThrows(OpenSearchException.class, () -> noOpsGeoIpDataFacade.getDatabaseReader(manifest)); + OpenSearchException exception = expectThrows(OpenSearchException.class, () -> noOpsGeoIpDataDao.getDatabaseReader(manifest)); assertTrue(exception.getMessage().contains("does not exist")); } @@ -154,7 +155,7 @@ public void testInternalGetDatabaseReader_whenCalled_thenSetUserAgent() { when(connection.getInputStream()).thenReturn(new FileInputStream(zipFile)); // Run - noOpsGeoIpDataFacade.internalGetDatabaseReader(manifest, connection); + noOpsGeoIpDataDao.internalGetDatabaseReader(manifest, connection); // Verify verify(connection).addRequestProperty(Constants.USER_AGENT_KEY, Constants.USER_AGENT_VALUE); @@ -169,12 +170,12 @@ public void testDeleteIp2GeoDataIndex_whenCalled_thenDeleteIndex() { assertEquals(index, request.indices()[0]); return new AcknowledgedResponse(true); }); - verifyingGeoIpDataFacade.deleteIp2GeoDataIndex(index); + verifyingGeoIpDataDao.deleteIp2GeoDataIndex(index); } public void testDeleteIp2GeoDataIndexWithNonIp2GeoDataIndex() { String index = GeospatialTestHelper.randomLowerCaseString(); - Exception e = expectThrows(OpenSearchException.class, () -> verifyingGeoIpDataFacade.deleteIp2GeoDataIndex(index)); + Exception e = expectThrows(OpenSearchException.class, () -> verifyingGeoIpDataDao.deleteIp2GeoDataIndex(index)); assertTrue(e.getMessage().contains("not ip2geo data index")); verify(verifyingClient, never()).index(any()); } @@ -216,7 +217,7 @@ public void testPutGeoIpData_whenValidInput_thenSucceed() { try (CSVParser csvParser = CSVParser.parse(sampleIp2GeoFile(), StandardCharsets.UTF_8, CSVFormat.RFC4180)) { Iterator iterator = csvParser.iterator(); String[] fields = iterator.next().values(); - verifyingGeoIpDataFacade.putGeoIpData(index, fields, iterator, renewLock); + verifyingGeoIpDataDao.putGeoIpData(index, fields, iterator, renewLock); verify(renewLock, times(2)).run(); } } @@ -247,7 +248,7 @@ public void testGetGeoIpData_whenSingleIp_thenSucceed() { return response; }); ActionListener> listener = mock(ActionListener.class); - verifyingGeoIpDataFacade.getGeoIpData(indexName, ip, listener); + verifyingGeoIpDataDao.getGeoIpData(indexName, ip, listener); ArgumentCaptor> captor = ArgumentCaptor.forClass(Map.class); verify(listener).onResponse(captor.capture()); assertEquals("seattle", captor.getValue().get("city")); @@ -279,7 +280,7 @@ public void testGetGeoIpData_whenMultiIps_thenSucceed() { return response; }); ActionListener>> listener = mock(ActionListener.class); - verifyingGeoIpDataFacade.getGeoIpData(indexName, Arrays.asList(ip), listener); + verifyingGeoIpDataDao.getGeoIpData(indexName, Arrays.asList(ip), listener); ArgumentCaptor>> captor = ArgumentCaptor.forClass(List.class); verify(listener).onResponse(captor.capture()); assertEquals("seattle", captor.getValue().get(0).get("city")); diff --git a/src/test/java/org/opensearch/geospatial/ip2geo/common/Ip2GeoProcessorFacadeTests.java b/src/test/java/org/opensearch/geospatial/ip2geo/dao/Ip2GeoProcessorDaoTests.java similarity index 90% rename from src/test/java/org/opensearch/geospatial/ip2geo/common/Ip2GeoProcessorFacadeTests.java rename to src/test/java/org/opensearch/geospatial/ip2geo/dao/Ip2GeoProcessorDaoTests.java index 05fed2ca..b298d8ef 100644 --- a/src/test/java/org/opensearch/geospatial/ip2geo/common/Ip2GeoProcessorFacadeTests.java +++ b/src/test/java/org/opensearch/geospatial/ip2geo/dao/Ip2GeoProcessorDaoTests.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package org.opensearch.geospatial.ip2geo.common; +package org.opensearch.geospatial.ip2geo.dao; import static org.mockito.Mockito.when; @@ -23,19 +23,19 @@ import org.opensearch.ingest.IngestMetadata; import org.opensearch.ingest.PipelineConfiguration; -public class Ip2GeoProcessorFacadeTests extends Ip2GeoTestCase { - private Ip2GeoProcessorFacade ip2GeoProcessorFacade; +public class Ip2GeoProcessorDaoTests extends Ip2GeoTestCase { + private Ip2GeoProcessorDao ip2GeoProcessorDao; @Before public void init() { - ip2GeoProcessorFacade = new Ip2GeoProcessorFacade(ingestService); + ip2GeoProcessorDao = new Ip2GeoProcessorDao(ingestService); } public void testGetProcessors_whenNullMetadata_thenReturnEmpty() { String datasourceName = GeospatialTestHelper.randomLowerCaseString(); when(metadata.custom(IngestMetadata.TYPE)).thenReturn(null); - List ip2GeoProcessorList = ip2GeoProcessorFacade.getProcessors(datasourceName); + List ip2GeoProcessorList = ip2GeoProcessorDao.getProcessors(datasourceName); assertTrue(ip2GeoProcessorList.isEmpty()); } @@ -50,7 +50,7 @@ public void testGetProcessors_whenNoProcessorForGivenDatasource_thenReturnEmpty( Ip2GeoProcessor ip2GeoProcessor = randomIp2GeoProcessor(datasourceBeingUsed); when(ingestService.getProcessorsInPipeline(pipelineId, Ip2GeoProcessor.class)).thenReturn(Arrays.asList(ip2GeoProcessor)); - List ip2GeoProcessorList = ip2GeoProcessorFacade.getProcessors(datasourceNotBeingUsed); + List ip2GeoProcessorList = ip2GeoProcessorDao.getProcessors(datasourceNotBeingUsed); assertTrue(ip2GeoProcessorList.isEmpty()); } @@ -64,7 +64,7 @@ public void testGetProcessors_whenProcessorsForGivenDatasource_thenReturnProcess Ip2GeoProcessor ip2GeoProcessor = randomIp2GeoProcessor(datasourceName); when(ingestService.getProcessorsInPipeline(pipelineId, Ip2GeoProcessor.class)).thenReturn(Arrays.asList(ip2GeoProcessor)); - List ip2GeoProcessorList = ip2GeoProcessorFacade.getProcessors(datasourceName); + List ip2GeoProcessorList = ip2GeoProcessorDao.getProcessors(datasourceName); assertEquals(1, ip2GeoProcessorList.size()); assertEquals(ip2GeoProcessor.getDatasourceName(), ip2GeoProcessorList.get(0).getDatasourceName()); } diff --git a/src/test/java/org/opensearch/geospatial/ip2geo/jobscheduler/DatasourceRunnerTests.java b/src/test/java/org/opensearch/geospatial/ip2geo/jobscheduler/DatasourceRunnerTests.java index cc7deb03..1800cdb6 100644 --- a/src/test/java/org/opensearch/geospatial/ip2geo/jobscheduler/DatasourceRunnerTests.java +++ b/src/test/java/org/opensearch/geospatial/ip2geo/jobscheduler/DatasourceRunnerTests.java @@ -38,7 +38,7 @@ public class DatasourceRunnerTests extends Ip2GeoTestCase { @Before public void init() { DatasourceRunner.getJobRunnerInstance() - .initialize(clusterService, datasourceUpdateService, ip2GeoExecutor, datasourceFacade, ip2GeoLockService); + .initialize(clusterService, datasourceUpdateService, ip2GeoExecutor, datasourceDao, ip2GeoLockService); } public void testRunJob_whenInvalidClass_thenThrowException() { @@ -70,7 +70,7 @@ public void testRunJob_whenValidInput_thenSucceed() { // Verify verify(ip2GeoLockService).acquireLock(datasource.getName(), Ip2GeoLockService.LOCK_DURATION_IN_SECONDS); - verify(datasourceFacade).getDatasource(datasource.getName()); + verify(datasourceDao).getDatasource(datasource.getName()); verify(ip2GeoLockService).releaseLock(lockModel); } @@ -97,7 +97,7 @@ public void testUpdateDatasourceRunner_whenExceptionAfterAcquiringLock_thenRelea when(ip2GeoLockService.acquireLock(jobParameter.getName(), Ip2GeoLockService.LOCK_DURATION_IN_SECONDS)).thenReturn( Optional.of(lockModel) ); - when(datasourceFacade.getDatasource(jobParameter.getName())).thenThrow(new RuntimeException()); + when(datasourceDao.getDatasource(jobParameter.getName())).thenThrow(new RuntimeException()); // Run DatasourceRunner.getJobRunnerInstance().updateDatasourceRunner(jobParameter).run(); @@ -123,7 +123,7 @@ public void testUpdateDatasource_whenInvalidState_thenUpdateLastFailedAt() { datasource.enable(); datasource.getUpdateStats().setLastFailedAt(null); datasource.setState(randomStateExcept(DatasourceState.AVAILABLE)); - when(datasourceFacade.getDatasource(datasource.getName())).thenReturn(datasource); + when(datasourceDao.getDatasource(datasource.getName())).thenReturn(datasource); // Run DatasourceRunner.getJobRunnerInstance().updateDatasource(datasource, mock(Runnable.class)); @@ -131,14 +131,14 @@ public void testUpdateDatasource_whenInvalidState_thenUpdateLastFailedAt() { // Verify assertFalse(datasource.isEnabled()); assertNotNull(datasource.getUpdateStats().getLastFailedAt()); - verify(datasourceFacade).updateDatasource(datasource); + verify(datasourceDao).updateDatasource(datasource); } @SneakyThrows public void testUpdateDatasource_whenValidInput_thenSucceed() { Datasource datasource = randomDatasource(); datasource.setState(DatasourceState.AVAILABLE); - when(datasourceFacade.getDatasource(datasource.getName())).thenReturn(datasource); + when(datasourceDao.getDatasource(datasource.getName())).thenReturn(datasource); Runnable renewLock = mock(Runnable.class); // Run @@ -155,7 +155,7 @@ public void testUpdateDatasource_whenDeleteTask_thenDeleteOnly() { Datasource datasource = randomDatasource(); datasource.setState(DatasourceState.AVAILABLE); datasource.setTask(DatasourceTask.DELETE_UNUSED_INDICES); - when(datasourceFacade.getDatasource(datasource.getName())).thenReturn(datasource); + when(datasourceDao.getDatasource(datasource.getName())).thenReturn(datasource); Runnable renewLock = mock(Runnable.class); // Run @@ -174,7 +174,7 @@ public void testUpdateDatasource_whenExpired_thenDeleteIndicesAgain() { datasource.getUpdateStats() .setLastSucceededAt(Instant.now().minus(datasource.getDatabase().getValidForInDays() + 1, ChronoUnit.DAYS)); datasource.setState(DatasourceState.AVAILABLE); - when(datasourceFacade.getDatasource(datasource.getName())).thenReturn(datasource); + when(datasourceDao.getDatasource(datasource.getName())).thenReturn(datasource); Runnable renewLock = mock(Runnable.class); // Run @@ -193,7 +193,7 @@ public void testUpdateDatasource_whenWillExpire_thenScheduleDeleteTask() { datasource.getUpdateStats() .setLastSucceededAt(Instant.now().minus(datasource.getDatabase().getValidForInDays(), ChronoUnit.DAYS).plusSeconds(60)); datasource.setState(DatasourceState.AVAILABLE); - when(datasourceFacade.getDatasource(datasource.getName())).thenReturn(datasource); + when(datasourceDao.getDatasource(datasource.getName())).thenReturn(datasource); Runnable renewLock = mock(Runnable.class); // Run @@ -213,7 +213,7 @@ public void testUpdateDatasourceExceptionHandling() { Datasource datasource = new Datasource(); datasource.setName(randomLowerCaseString()); datasource.getUpdateStats().setLastFailedAt(null); - when(datasourceFacade.getDatasource(datasource.getName())).thenReturn(datasource); + when(datasourceDao.getDatasource(datasource.getName())).thenReturn(datasource); doThrow(new RuntimeException("test failure")).when(datasourceUpdateService).deleteUnusedIndices(any()); // Run @@ -221,6 +221,6 @@ public void testUpdateDatasourceExceptionHandling() { // Verify assertNotNull(datasource.getUpdateStats().getLastFailedAt()); - verify(datasourceFacade).updateDatasource(datasource); + verify(datasourceDao).updateDatasource(datasource); } } diff --git a/src/test/java/org/opensearch/geospatial/ip2geo/jobscheduler/DatasourceUpdateServiceTests.java b/src/test/java/org/opensearch/geospatial/ip2geo/jobscheduler/DatasourceUpdateServiceTests.java index b110ddea..80a3beac 100644 --- a/src/test/java/org/opensearch/geospatial/ip2geo/jobscheduler/DatasourceUpdateServiceTests.java +++ b/src/test/java/org/opensearch/geospatial/ip2geo/jobscheduler/DatasourceUpdateServiceTests.java @@ -41,7 +41,7 @@ public class DatasourceUpdateServiceTests extends Ip2GeoTestCase { @Before public void init() { - datasourceUpdateService = new DatasourceUpdateService(clusterService, datasourceFacade, geoIpDataFacade); + datasourceUpdateService = new DatasourceUpdateService(clusterService, datasourceDao, geoIpDataDao); } @SneakyThrows @@ -61,7 +61,7 @@ public void testUpdateOrCreateGeoIpData_whenHashValueIsSame_thenSkipUpdate() { // Verify assertNotNull(datasource.getUpdateStats().getLastSkippedAt()); - verify(datasourceFacade).updateDatasource(datasource); + verify(datasourceDao).updateDatasource(datasource); } @SneakyThrows @@ -70,7 +70,7 @@ public void testUpdateOrCreateGeoIpData_whenExpired_thenUpdate() { DatasourceManifest manifest = DatasourceManifest.Builder.build(manifestFile.toURI().toURL()); File sampleFile = new File(this.getClass().getClassLoader().getResource("ip2geo/sample_valid.csv").getFile()); - when(geoIpDataFacade.getDatabaseReader(any())).thenReturn(CSVParser.parse(sampleFile, StandardCharsets.UTF_8, CSVFormat.RFC4180)); + when(geoIpDataDao.getDatabaseReader(any())).thenReturn(CSVParser.parse(sampleFile, StandardCharsets.UTF_8, CSVFormat.RFC4180)); Datasource datasource = new Datasource(); datasource.setState(DatasourceState.AVAILABLE); @@ -84,12 +84,7 @@ public void testUpdateOrCreateGeoIpData_whenExpired_thenUpdate() { datasourceUpdateService.updateOrCreateGeoIpData(datasource, mock(Runnable.class)); // Verify - verify(geoIpDataFacade).putGeoIpData( - eq(datasource.currentIndexName()), - isA(String[].class), - any(Iterator.class), - any(Runnable.class) - ); + verify(geoIpDataDao).putGeoIpData(eq(datasource.currentIndexName()), isA(String[].class), any(Iterator.class), any(Runnable.class)); } @SneakyThrows @@ -100,7 +95,7 @@ public void testUpdateOrCreateGeoIpData_whenInvalidData_thenThrowException() { File sampleFile = new File( this.getClass().getClassLoader().getResource("ip2geo/sample_invalid_less_than_two_fields.csv").getFile() ); - when(geoIpDataFacade.getDatabaseReader(any())).thenReturn(CSVParser.parse(sampleFile, StandardCharsets.UTF_8, CSVFormat.RFC4180)); + when(geoIpDataDao.getDatabaseReader(any())).thenReturn(CSVParser.parse(sampleFile, StandardCharsets.UTF_8, CSVFormat.RFC4180)); Datasource datasource = new Datasource(); datasource.setState(DatasourceState.AVAILABLE); @@ -119,7 +114,7 @@ public void testUpdateOrCreateGeoIpData_whenIncompatibleFields_thenThrowExceptio DatasourceManifest manifest = DatasourceManifest.Builder.build(manifestFile.toURI().toURL()); File sampleFile = new File(this.getClass().getClassLoader().getResource("ip2geo/sample_valid.csv").getFile()); - when(geoIpDataFacade.getDatabaseReader(any())).thenReturn(CSVParser.parse(sampleFile, StandardCharsets.UTF_8, CSVFormat.RFC4180)); + when(geoIpDataDao.getDatabaseReader(any())).thenReturn(CSVParser.parse(sampleFile, StandardCharsets.UTF_8, CSVFormat.RFC4180)); Datasource datasource = new Datasource(); datasource.setState(DatasourceState.AVAILABLE); @@ -138,7 +133,7 @@ public void testUpdateOrCreateGeoIpData_whenValidInput_thenSucceed() { DatasourceManifest manifest = DatasourceManifest.Builder.build(manifestFile.toURI().toURL()); File sampleFile = new File(this.getClass().getClassLoader().getResource("ip2geo/sample_valid.csv").getFile()); - when(geoIpDataFacade.getDatabaseReader(any())).thenReturn(CSVParser.parse(sampleFile, StandardCharsets.UTF_8, CSVFormat.RFC4180)); + when(geoIpDataDao.getDatabaseReader(any())).thenReturn(CSVParser.parse(sampleFile, StandardCharsets.UTF_8, CSVFormat.RFC4180)); Datasource datasource = new Datasource(); datasource.setState(DatasourceState.AVAILABLE); @@ -159,13 +154,8 @@ public void testUpdateOrCreateGeoIpData_whenValidInput_thenSucceed() { assertEquals(manifest.getValidForInDays(), datasource.getDatabase().getValidForInDays()); assertNotNull(datasource.getUpdateStats().getLastSucceededAt()); assertNotNull(datasource.getUpdateStats().getLastProcessingTimeInMillis()); - verify(datasourceFacade, times(2)).updateDatasource(datasource); - verify(geoIpDataFacade).putGeoIpData( - eq(datasource.currentIndexName()), - isA(String[].class), - any(Iterator.class), - any(Runnable.class) - ); + verify(datasourceDao, times(2)).updateDatasource(datasource); + verify(geoIpDataDao).putGeoIpData(eq(datasource.currentIndexName()), isA(String[].class), any(Iterator.class), any(Runnable.class)); } @SneakyThrows @@ -173,7 +163,7 @@ public void testGetHeaderFields_whenValidInput_thenReturnCorrectValue() { File manifestFile = new File(this.getClass().getClassLoader().getResource("ip2geo/manifest.json").getFile()); File sampleFile = new File(this.getClass().getClassLoader().getResource("ip2geo/sample_valid.csv").getFile()); - when(geoIpDataFacade.getDatabaseReader(any())).thenReturn(CSVParser.parse(sampleFile, StandardCharsets.UTF_8, CSVFormat.RFC4180)); + when(geoIpDataDao.getDatabaseReader(any())).thenReturn(CSVParser.parse(sampleFile, StandardCharsets.UTF_8, CSVFormat.RFC4180)); // Run assertEquals(Arrays.asList("country_name"), datasourceUpdateService.getHeaderFields(manifestFile.toURI().toURL().toExternalForm())); @@ -203,8 +193,8 @@ public void testDeleteUnusedIndices_whenValidInput_thenSucceed() { assertEquals(1, datasource.getIndices().size()); assertEquals(currentIndex, datasource.getIndices().get(0)); - verify(datasourceFacade).updateDatasource(datasource); - verify(geoIpDataFacade).deleteIp2GeoDataIndex(oldIndex); + verify(datasourceDao).updateDatasource(datasource); + verify(geoIpDataDao).deleteIp2GeoDataIndex(oldIndex); } public void testUpdateDatasource_whenNoChange_thenNoUpdate() { @@ -214,7 +204,7 @@ public void testUpdateDatasource_whenNoChange_thenNoUpdate() { datasourceUpdateService.updateDatasource(datasource, datasource.getSystemSchedule(), datasource.getTask()); // Verify - verify(datasourceFacade, never()).updateDatasource(any()); + verify(datasourceDao, never()).updateDatasource(any()); } public void testUpdateDatasource_whenChange_thenUpdate() { @@ -230,14 +220,14 @@ public void testUpdateDatasource_whenChange_thenUpdate() { datasourceUpdateService.updateDatasource(datasource, datasource.getSystemSchedule(), DatasourceTask.DELETE_UNUSED_INDICES); // Verify - verify(datasourceFacade, times(2)).updateDatasource(any()); + verify(datasourceDao, times(2)).updateDatasource(any()); } @SneakyThrows public void testGetHeaderFields_whenValidInput_thenSucceed() { File manifestFile = new File(this.getClass().getClassLoader().getResource("ip2geo/manifest.json").getFile()); File sampleFile = new File(this.getClass().getClassLoader().getResource("ip2geo/sample_valid.csv").getFile()); - when(geoIpDataFacade.getDatabaseReader(any())).thenReturn(CSVParser.parse(sampleFile, StandardCharsets.UTF_8, CSVFormat.RFC4180)); + when(geoIpDataDao.getDatabaseReader(any())).thenReturn(CSVParser.parse(sampleFile, StandardCharsets.UTF_8, CSVFormat.RFC4180)); // Run List fields = datasourceUpdateService.getHeaderFields(manifestFile.toURI().toURL().toExternalForm()); diff --git a/src/test/java/org/opensearch/geospatial/ip2geo/listener/Ip2GeoListenerTests.java b/src/test/java/org/opensearch/geospatial/ip2geo/listener/Ip2GeoListenerTests.java index a72a5a1b..d31f38bc 100644 --- a/src/test/java/org/opensearch/geospatial/ip2geo/listener/Ip2GeoListenerTests.java +++ b/src/test/java/org/opensearch/geospatial/ip2geo/listener/Ip2GeoListenerTests.java @@ -36,7 +36,7 @@ public class Ip2GeoListenerTests extends Ip2GeoTestCase { @Before public void init() { - ip2GeoListener = new Ip2GeoListener(clusterService, threadPool, datasourceFacade, geoIpDataFacade); + ip2GeoListener = new Ip2GeoListener(clusterService, threadPool, datasourceDao, geoIpDataDao); } public void testDoStart_whenClusterManagerNode_thenAddListener() { @@ -151,7 +151,7 @@ public void testClusterChanged_whenDatasourceIndexIsRestored_thenUpdate() { // Verify verify(threadPool).generic(); ArgumentCaptor>> captor = ArgumentCaptor.forClass(ActionListener.class); - verify(datasourceFacade).getAllDatasources(captor.capture()); + verify(datasourceDao).getAllDatasources(captor.capture()); // Run List datasources = Arrays.asList(randomDatasource(), randomDatasource()); @@ -167,7 +167,7 @@ public void testClusterChanged_whenDatasourceIndexIsRestored_thenUpdate() { assertTrue(datasource.getSystemSchedule().getNextExecutionTime(Instant.now()).isAfter(Instant.now())); assertTrue(datasource.getSystemSchedule().getNextExecutionTime(Instant.now()).isBefore(Instant.now().plusSeconds(60))); }); - verify(datasourceFacade).updateDatasource(eq(datasources), any()); + verify(datasourceDao).updateDatasource(eq(datasources), any()); } public void testClusterChanged_whenGeoIpDataIsRestored_thenDelete() { @@ -193,7 +193,7 @@ public void testClusterChanged_whenGeoIpDataIsRestored_thenDelete() { // Verify verify(threadPool).generic(); - verify(geoIpDataFacade).deleteIp2GeoDataIndex(Arrays.asList(datasource.currentIndexName())); + verify(geoIpDataDao).deleteIp2GeoDataIndex(Arrays.asList(datasource.currentIndexName())); } } diff --git a/src/test/java/org/opensearch/geospatial/ip2geo/processor/Ip2GeoProcessorTests.java b/src/test/java/org/opensearch/geospatial/ip2geo/processor/Ip2GeoProcessorTests.java index 656375ca..aa3b52aa 100644 --- a/src/test/java/org/opensearch/geospatial/ip2geo/processor/Ip2GeoProcessorTests.java +++ b/src/test/java/org/opensearch/geospatial/ip2geo/processor/Ip2GeoProcessorTests.java @@ -41,7 +41,7 @@ public class Ip2GeoProcessorTests extends Ip2GeoTestCase { @Before public void init() { - factory = new Ip2GeoProcessor.Factory(ingestService, datasourceFacade, geoIpDataFacade, ip2GeoCache); + factory = new Ip2GeoProcessor.Factory(ingestService, datasourceDao, geoIpDataDao, ip2GeoCache); } public void testExecuteWithNoIpAndIgnoreMissing() throws Exception { @@ -154,7 +154,7 @@ public void testExecuteInternal_whenSingleIp_thenGetDatasourceIsCalled() { processor.executeInternal(document, handler, ip); // Verify - verify(geoIpDataFacade).getGeoIpData(anyString(), anyString(), any(ActionListener.class)); + verify(geoIpDataDao).getGeoIpData(anyString(), anyString(), any(ActionListener.class)); } @SneakyThrows @@ -282,7 +282,7 @@ public void testExecuteInternal_whenMultiIps_thenGetDatasourceIsCalled() { processor.executeInternal(document, handler, ips); // Verify - verify(geoIpDataFacade).getGeoIpData(anyString(), anyList(), any(ActionListener.class)); + verify(geoIpDataDao).getGeoIpData(anyString(), anyList(), any(ActionListener.class)); } private Ip2GeoProcessor createProcessor(final String datasourceName, final Map config) throws Exception { @@ -294,7 +294,7 @@ private Ip2GeoProcessor createProcessor(final String datasourceName, final Map config) throws Exception { - when(datasourceFacade.getDatasource(datasource.getName())).thenReturn(datasource); + when(datasourceDao.getDatasource(datasource.getName())).thenReturn(datasource); Map baseConfig = new HashMap<>(); baseConfig.put(CONFIG_FIELD_KEY, "ip"); baseConfig.put(CONFIG_DATASOURCE_KEY, datasource.getName()); diff --git a/src/test/java/org/opensearch/geospatial/plugin/GeospatialPluginTests.java b/src/test/java/org/opensearch/geospatial/plugin/GeospatialPluginTests.java index 7e2e9e01..92e5b63a 100644 --- a/src/test/java/org/opensearch/geospatial/plugin/GeospatialPluginTests.java +++ b/src/test/java/org/opensearch/geospatial/plugin/GeospatialPluginTests.java @@ -38,11 +38,11 @@ import org.opensearch.geospatial.ip2geo.action.RestPutDatasourceHandler; import org.opensearch.geospatial.ip2geo.action.RestUpdateDatasourceHandler; import org.opensearch.geospatial.ip2geo.cache.Ip2GeoCache; -import org.opensearch.geospatial.ip2geo.common.DatasourceFacade; -import org.opensearch.geospatial.ip2geo.common.GeoIpDataFacade; import org.opensearch.geospatial.ip2geo.common.Ip2GeoExecutor; import org.opensearch.geospatial.ip2geo.common.Ip2GeoLockService; import org.opensearch.geospatial.ip2geo.common.Ip2GeoSettings; +import org.opensearch.geospatial.ip2geo.dao.DatasourceDao; +import org.opensearch.geospatial.ip2geo.dao.GeoIpDataDao; import org.opensearch.geospatial.ip2geo.jobscheduler.DatasourceUpdateService; import org.opensearch.geospatial.ip2geo.listener.Ip2GeoListener; import org.opensearch.geospatial.processor.FeatureProcessor; @@ -77,9 +77,9 @@ public class GeospatialPluginTests extends OpenSearchTestCase { private final Set SUPPORTED_COMPONENTS = Set.of( UploadStats.class, DatasourceUpdateService.class, - DatasourceFacade.class, + DatasourceDao.class, Ip2GeoExecutor.class, - GeoIpDataFacade.class, + GeoIpDataDao.class, Ip2GeoLockService.class, Ip2GeoCache.class );