Skip to content

Commit

Permalink
matches new registry-common API
Browse files Browse the repository at this point in the history
  • Loading branch information
Al Niessner authored and Al Niessner committed Jan 30, 2024
1 parent 35fc53c commit 0062779
Show file tree
Hide file tree
Showing 18 changed files with 73 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
import java.util.TreeSet;

import org.apache.commons.cli.CommandLine;
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.client.RestClient;

import gov.nasa.pds.registry.common.es.client.EsClientFactory;
import gov.nasa.pds.registry.common.es.client.EsUtils;
import gov.nasa.pds.registry.common.EstablishConnectionFactory;
import gov.nasa.pds.registry.common.ResponseException;
import gov.nasa.pds.registry.common.RestClient;
import gov.nasa.pds.registry.common.es.dao.ProductDao;
import gov.nasa.pds.registry.common.es.service.ProductService;
import gov.nasa.pds.registry.common.util.CloseUtils;
Expand Down Expand Up @@ -62,15 +60,15 @@ public void run(CommandLine cmdLine) throws Exception
try
{
// Call Elasticsearch
client = EsClientFactory.createRestClient(esUrl, authPath);
client = EstablishConnectionFactory.directly(esUrl, authPath).createRestClient();
ProductDao dao = new ProductDao(client, indexName);
ProductService srv = new ProductService(dao);

srv.updateArchveStatus(lidvid, status);
}
catch(ResponseException ex)
{
throw new Exception(EsUtils.extractErrorMessage(ex));
throw new Exception(ex.extractErrorMessage());
}
finally
{
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/gov/nasa/pds/registry/mgr/cmd/dd/LoadDDCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.apache.commons.cli.CommandLine;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import gov.nasa.pds.registry.common.EstablishConnectionFactory;
import gov.nasa.pds.registry.common.cfg.RegistryCfg;
import gov.nasa.pds.registry.common.dd.LddUtils;
import gov.nasa.pds.registry.common.es.dao.DataLoader;
Expand Down Expand Up @@ -131,7 +131,7 @@ private void loadLdd(String path, String namespace) throws Exception

// Init LDD loader
DataDictionaryDao ddDao = RegistryManager.getInstance().getDataDictionaryDao();
JsonLddLoader loader = new JsonLddLoader(ddDao, cfg.url, cfg.indexName, cfg.authFile);
JsonLddLoader loader = new JsonLddLoader(ddDao, EstablishConnectionFactory.directly(cfg.url, cfg.authFile).setIndexName(cfg.indexName));
loader.loadPds2EsDataTypeMap(LddUtils.getPds2EsDataTypeCfgFile("REGISTRY_MANAGER_HOME"));

//Load LDD
Expand All @@ -150,7 +150,7 @@ private void loadDataDump(String path) throws Exception
Logger log = LogManager.getLogger(this.getClass());
log.info("Data dump: " + path);

DataLoader loader = new DataLoader(cfg.url, cfg.indexName + "-dd", cfg.authFile);
DataLoader loader = new DataLoader(EstablishConnectionFactory.directly(cfg.url, cfg.authFile).setIndexName( cfg.indexName + "-dd"));
loader.loadFile(new File(path));
}

Expand Down
11 changes: 6 additions & 5 deletions src/main/java/gov/nasa/pds/registry/mgr/cmd/dd/UpgradeDDCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import java.io.File;

import org.apache.commons.cli.CommandLine;
import org.elasticsearch.client.RestClient;

import gov.nasa.pds.registry.common.es.client.EsClientFactory;
import gov.nasa.pds.registry.common.ConnectionFactory;
import gov.nasa.pds.registry.common.EstablishConnectionFactory;
import gov.nasa.pds.registry.common.RestClient;
import gov.nasa.pds.registry.common.es.dao.DataLoader;
import gov.nasa.pds.registry.common.util.CloseUtils;
import gov.nasa.pds.registry.mgr.Constants;
Expand Down Expand Up @@ -51,7 +51,8 @@ public void run(CommandLine cmdLine) throws Exception

try
{
client = EsClientFactory.createRestClient(esUrl, authPath);
ConnectionFactory conFact = EstablishConnectionFactory.directly(esUrl, authPath);
client = conFact.createRestClient();

if(replace)
{
Expand All @@ -61,7 +62,7 @@ public void run(CommandLine cmdLine) throws Exception
}

// Load data
DataLoader dl = new DataLoader(esUrl, indexName + "-dd", authPath);
DataLoader dl = new DataLoader(conFact.setIndexName(indexName + "-dd"));
File zipFile = IndexService.getDataDicFile();
dl.loadZippedFile(zipFile, "dd.json");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import java.io.File;

import org.apache.commons.cli.CommandLine;
import org.elasticsearch.client.RestClient;

import gov.nasa.pds.registry.common.es.client.EsClientFactory;
import gov.nasa.pds.registry.common.ConnectionFactory;
import gov.nasa.pds.registry.common.EstablishConnectionFactory;
import gov.nasa.pds.registry.common.RestClient;
import gov.nasa.pds.registry.common.es.dao.DataLoader;
import gov.nasa.pds.registry.common.util.CloseUtils;
import gov.nasa.pds.registry.mgr.Constants;
Expand Down Expand Up @@ -50,7 +50,8 @@ public void run(CommandLine cmdLine) throws Exception

try
{
client = EsClientFactory.createRestClient(esUrl, authPath);
ConnectionFactory conFact = EstablishConnectionFactory.directly(esUrl, authPath);
client = conFact.createRestClient();
IndexService srv = new IndexService(client);

// Registry
Expand All @@ -62,7 +63,7 @@ public void run(CommandLine cmdLine) throws Exception
// Data dictionary
srv.createIndex("elastic/data-dic.json", indexName + "-dd", 1, replicas);
// Load data
DataLoader dl = new DataLoader(esUrl, indexName + "-dd", authPath);
DataLoader dl = new DataLoader(conFact.setIndexName(indexName + "-dd"));
File zipFile = IndexService.getDataDicFile();
dl.loadZippedFile(zipFile, "dd.json");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package gov.nasa.pds.registry.mgr.cmd.reg;

import org.apache.commons.cli.CommandLine;
import org.elasticsearch.client.RestClient;

import gov.nasa.pds.registry.common.es.client.EsClientFactory;
import gov.nasa.pds.registry.common.EstablishConnectionFactory;
import gov.nasa.pds.registry.common.RestClient;
import gov.nasa.pds.registry.common.util.CloseUtils;
import gov.nasa.pds.registry.mgr.Constants;
import gov.nasa.pds.registry.mgr.cmd.CliCommand;
Expand Down Expand Up @@ -43,7 +42,7 @@ public void run(CommandLine cmdLine) throws Exception

try
{
client = EsClientFactory.createRestClient(esUrl, authPath);
client = EstablishConnectionFactory.directly(esUrl, authPath).createRestClient();
IndexService srv = new IndexService(client);

srv.deleteIndex(indexName);
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/gov/nasa/pds/registry/mgr/dao/IndexDao.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package gov.nasa.pds.registry.mgr.dao;

import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;

import gov.nasa.pds.registry.common.Request;
import gov.nasa.pds.registry.common.Response;
import gov.nasa.pds.registry.common.RestClient;
import gov.nasa.pds.registry.mgr.dao.resp.SettingsResponseParser;


Expand Down Expand Up @@ -33,7 +32,7 @@ public IndexDao(RestClient client)
*/
public boolean indexExists(String indexName) throws Exception
{
Request req = new Request("HEAD", "/" + indexName);
Request req = client.createRequest(Request.Method.HEAD, "/" + indexName);
Response resp = client.performRequest(req);
return resp.getStatusLine().getStatusCode() == 200;
}
Expand All @@ -47,7 +46,7 @@ public boolean indexExists(String indexName) throws Exception
*/
public IndexSettings getIndexSettings(String indexName) throws Exception
{
Request req = new Request("GET", "/" + indexName + "/_settings");
Request req = client.createRequest(Request.Method.GET, "/" + indexName + "/_settings");
Response resp = client.performRequest(req);

SettingsResponseParser parser = new SettingsResponseParser();
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/gov/nasa/pds/registry/mgr/dao/RegistryDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;

import gov.nasa.pds.registry.common.es.client.SearchResponseParser;
import gov.nasa.pds.registry.common.Request;
import gov.nasa.pds.registry.common.Response;
import gov.nasa.pds.registry.common.RestClient;
import gov.nasa.pds.registry.common.es.dao.BulkResponseParser;
import gov.nasa.pds.registry.common.util.CloseUtils;
import gov.nasa.pds.registry.common.util.SearchResponseParser;
import gov.nasa.pds.registry.mgr.dao.resp.GetAltIdsParser;

/**
Expand Down Expand Up @@ -70,7 +69,7 @@ public Map<String, Set<String>> getAlternateIds(Collection<String> ids) throws E
String reqUrl = "/" + indexName + "/_search";
if(pretty) reqUrl += "?pretty";

Request req = new Request("GET", reqUrl);
Request req = client.createRequest(Request.Method.GET, reqUrl);
req.setJsonEntity(jsonReq);
Response resp = client.performRequest(req);

Expand Down Expand Up @@ -99,7 +98,7 @@ public void updateAlternateIds(Map<String, Set<String>> newIds) throws Exception
log.debug("Request:\n" + json);

String reqUrl = "/" + indexName + "/_bulk"; //?refresh=wait_for";
Request req = new Request("POST", reqUrl);
Request req = client.createRequest(Request.Method.POST, reqUrl);
req.setJsonEntity(json);

Response resp = client.performRequest(req);
Expand Down
17 changes: 8 additions & 9 deletions src/main/java/gov/nasa/pds/registry/mgr/dao/RegistryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.client.RestClient;

import gov.nasa.pds.registry.common.EstablishConnectionFactory;
import gov.nasa.pds.registry.common.RestClient;
import gov.nasa.pds.registry.common.cfg.RegistryCfg;
import gov.nasa.pds.registry.common.es.client.EsClientFactory;
import gov.nasa.pds.registry.common.es.dao.dd.DataDictionaryDao;
import gov.nasa.pds.registry.common.util.CloseUtils;
import gov.nasa.pds.registry.common.es.dao.schema.SchemaDao;
Expand All @@ -20,7 +19,7 @@ public class RegistryManager
{
private static RegistryManager instance = null;

private RestClient esClient;
private RestClient client;
private SchemaDao schemaDao;
private DataDictionaryDao dataDictionaryDao;
private RegistryDao registryDao;
Expand All @@ -35,7 +34,7 @@ private RegistryManager(RegistryCfg cfg) throws Exception
{
if(cfg.url == null || cfg.url.isEmpty()) throw new IllegalArgumentException("Missing Registry URL");

esClient = EsClientFactory.createRestClient(cfg.url, cfg.authFile);
client = EstablishConnectionFactory.directly(cfg.url, cfg.authFile).createRestClient();

String indexName = cfg.indexName;
if(indexName == null || indexName.isEmpty())
Expand All @@ -47,9 +46,9 @@ private RegistryManager(RegistryCfg cfg) throws Exception
log.info("Registry URL: " + cfg.url);
log.info("Registry index: " + indexName);

schemaDao = new SchemaDao(esClient, indexName);
dataDictionaryDao = new DataDictionaryDao(esClient, indexName);
registryDao = new RegistryDao(esClient, indexName);
schemaDao = new SchemaDao(client, indexName);
dataDictionaryDao = new DataDictionaryDao(client, indexName);
registryDao = new RegistryDao(client, indexName);
}


Expand All @@ -71,7 +70,7 @@ public static void destroy()
{
if(instance == null) return;

CloseUtils.close(instance.esClient);
CloseUtils.close(instance.client);
instance = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.TreeMap;
import java.util.TreeSet;

import gov.nasa.pds.registry.common.es.client.SearchResponseParser;
import gov.nasa.pds.registry.common.util.SearchResponseParser;


public class GetAltIdsParser implements SearchResponseParser.Callback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import java.io.InputStream;
import java.io.InputStreamReader;

import org.elasticsearch.client.Response;

import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;

import gov.nasa.pds.registry.common.Response;
import gov.nasa.pds.registry.mgr.dao.IndexSettings;

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gov/nasa/pds/registry/mgr/dd/CsvLddLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.apache.logging.log4j.Logger;

import com.opencsv.CSVReader;

import gov.nasa.pds.registry.common.EstablishConnectionFactory;
import gov.nasa.pds.registry.common.dd.DDNJsonWriter;
import gov.nasa.pds.registry.common.dd.DDRecord;
import gov.nasa.pds.registry.common.es.dao.DataLoader;
Expand All @@ -34,7 +34,7 @@ public class CsvLddLoader
public CsvLddLoader(String esUrl, String indexName, String authFilePath) throws Exception
{
log = LogManager.getLogger(this.getClass());
loader = new DataLoader(esUrl, indexName + "-dd", authFilePath);
loader = new DataLoader(EstablishConnectionFactory.directly(esUrl, authFilePath).setIndexName(indexName + "-dd"));
}


Expand Down
22 changes: 10 additions & 12 deletions src/main/java/gov/nasa/pds/registry/mgr/srv/IndexService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.client.RestClient;

import gov.nasa.pds.registry.common.es.client.EsUtils;
import gov.nasa.pds.registry.common.Request;
import gov.nasa.pds.registry.common.Response;
import gov.nasa.pds.registry.common.ResponseException;
import gov.nasa.pds.registry.common.RestClient;
import gov.nasa.pds.registry.mgr.dao.IndexDao;
import gov.nasa.pds.registry.mgr.dao.IndexSettings;
import gov.nasa.pds.registry.mgr.dao.RegistryRequestBuilder;
Expand Down Expand Up @@ -62,18 +60,18 @@ public void createIndex(String relativeSchemaPath, String indexName, int shards,
log.info("Replicas: " + replicas);

// Create request
Request req = new Request("PUT", "/" + indexName);
Request req = client.createRequest(Request.Method.PUT, "/" + indexName);
RegistryRequestBuilder bld = new RegistryRequestBuilder();
String jsonReq = bld.createCreateIndexRequest(schemaFile, shards, replicas);
req.setJsonEntity(jsonReq);

// Execute request
Response resp = client.performRequest(req);
EsUtils.printWarnings(resp);
resp.printWarnings();
}
catch(ResponseException ex)
{
throw new Exception(EsUtils.extractErrorMessage(ex));
throw new Exception(ex.extractErrorMessage());
}
}

Expand Down Expand Up @@ -167,15 +165,15 @@ public void deleteIndex(String indexName) throws Exception
}

// Create request
Request req = new Request("DELETE", "/" + indexName);
Request req = client.createRequest(Request.Method.DELETE, "/" + indexName);

// Execute request
Response resp = client.performRequest(req);
EsUtils.printWarnings(resp);
resp.printWarnings();
}
catch(ResponseException ex)
{
throw new Exception(EsUtils.extractErrorMessage(ex));
throw new Exception(ex.extractErrorMessage());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/tools/LoadLdds.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

import gov.nasa.pds.registry.common.EstablishConnectionFactory;
import gov.nasa.pds.registry.common.cfg.RegistryCfg;
import gov.nasa.pds.registry.common.es.dao.dd.DataDictionaryDao;
import gov.nasa.pds.registry.common.es.service.JsonLddLoader;
Expand All @@ -27,7 +27,7 @@ public static void main(String[] args) throws Exception
RegistryManager.init(cfg);

DataDictionaryDao ddDao = RegistryManager.getInstance().getDataDictionaryDao();
JsonLddLoader loader = new JsonLddLoader(ddDao, "http://localhost:9200", "registry", null);
JsonLddLoader loader = new JsonLddLoader(ddDao, EstablishConnectionFactory.directly("http://localhost:9200").setIndexName("registry"));
loader.loadPds2EsDataTypeMap(new File("src/main/resources/elastic/data-dic-types.cfg"));

File baseDir = new File("/tmp/schema");
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/tt/TestDataLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import java.io.File;
import java.net.HttpURLConnection;

import gov.nasa.pds.registry.common.EstablishConnectionFactory;
import gov.nasa.pds.registry.common.es.dao.DataLoader;


Expand All @@ -14,7 +14,7 @@ public static void main(String[] args) throws Exception
{
HttpURLConnection.setFollowRedirects(true);

DataLoader dl = new DataLoader("localhost", "t1", null);
DataLoader dl = new DataLoader(EstablishConnectionFactory.directly("localhost").setIndexName("t1"));
//dl.setBatchSize(10);

try
Expand Down
Loading

0 comments on commit 0062779

Please sign in to comment.