Skip to content

Commit

Permalink
Using already existing data base filename loader
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenplieger committed Sep 13, 2024
1 parent a48c9d2 commit 552e28c
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 40 deletions.
59 changes: 37 additions & 22 deletions adagucserverEC/CAutoConfigure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,26 +463,7 @@ int CAutoConfigure::autoConfigureStyles(CDataSource *dataSource) {
return 0;
}

int CAutoConfigure::justLoadAFileHeader(CDataSource *dataSource) {

if (dataSource == NULL) {
CDBError("datasource == NULL");
return 1;
}
if (dataSource->cfgLayer == NULL) {
CDBError("datasource->cfgLayer == NULL");
return 1;
}
if (dataSource->getNumDataObjects() == 0) {
CDBError("dataSource->getNumDataObjects()==0");
return 1;
}
if (dataSource->getDataObject(0)->cdfVariable != NULL) {
#ifdef CAUTOCONFIGURE_DEBUG
CDBDebug("already loaded: dataSource->getDataObject(0)->cdfVariable!=NULL");
#endif
return 0;
}
int CAutoConfigure::getFileNameForDataSource(CDataSource *dataSource, std::string &fileName) {

CT::string foundFileName = dataSource->getFileName();
if (foundFileName.empty()) {
Expand All @@ -499,7 +480,12 @@ int CAutoConfigure::justLoadAFileHeader(CDataSource *dataSource) {
if (dataSource->requiredDims.size() == 0) {
removeRequiredDims = true;
if (dataSource->cfgLayer->Dimension.size() > 0) {
CRequest::fillDimValuesForDataSource(dataSource, dataSource->srvParams);
try {
CRequest::fillDimValuesForDataSource(dataSource, dataSource->srvParams);
} catch (ServiceExceptionCode e) {
CDBDebug("Unable to fillDimValuesForDataSource");
return 1;
}
} else {
CDBDebug("Required dims is still zero, add none now");
COGCDims *ogcDim = new COGCDims();
Expand All @@ -510,7 +496,7 @@ int CAutoConfigure::justLoadAFileHeader(CDataSource *dataSource) {
ogcDim->netCDFDimName.copy("none");
}
}
CDBStore::Store *store = CDBFactory::getDBAdapter(dataSource->srvParams->cfg)->getFilesAndIndicesForDimensions(dataSource, 1000);
CDBStore::Store *store = CDBFactory::getDBAdapter(dataSource->srvParams->cfg)->getFilesAndIndicesForDimensions(dataSource, 1);
if (store != NULL && store->getSize() > 0) {
CT::string fileNamestr = store->getRecord(0)->get(0)->c_str();
// CDBDebug("fileName from DB: %s", fileNamestr.c_str());
Expand All @@ -532,7 +518,36 @@ int CAutoConfigure::justLoadAFileHeader(CDataSource *dataSource) {
return 1;
}
}
fileName = foundFileName.c_str();
return 0;
}

int CAutoConfigure::justLoadAFileHeader(CDataSource *dataSource) {
if (dataSource == NULL) {
CDBError("datasource == NULL");
return 1;
}
if (dataSource->cfgLayer == NULL) {
CDBError("datasource->cfgLayer == NULL");
return 1;
}
if (dataSource->getNumDataObjects() == 0) {
CDBError("dataSource->getNumDataObjects()==0");
return 1;
}
if (dataSource->getDataObject(0)->cdfVariable != NULL) {
#ifdef CAUTOCONFIGURE_DEBUG
CDBDebug("already loaded: dataSource->getDataObject(0)->cdfVariable!=NULL");
#endif
return 0;
}

std::string foundFileName;

if (getFileNameForDataSource(dataSource, foundFileName) != 0) {
CDBDebug("Unable to getFileNameForDataSource");
return 1;
}
/* Open a file */
try {
// CDBDebug("Loading header [%s]", foundFileName.c_str());
Expand Down
8 changes: 8 additions & 0 deletions adagucserverEC/CAutoConfigure.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,13 @@ class CAutoConfigure {
public:
static int autoConfigureDimensions(CDataSource *dataSource);
static int autoConfigureStyles(CDataSource *dataSource);

/**
* Find the default filename for a datasource from the database
* @param dataSource
* @param fileName - The filename to return
* @returns Zero on success.
*/
static int getFileNameForDataSource(CDataSource *dataSource, std::string &fileName);
};
#endif
21 changes: 6 additions & 15 deletions adagucserverEC/CDBFileScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -958,23 +958,14 @@ int CDBFileScanner::updatedb(CDataSource *dataSource, CT::string *_tailPath, CT:
CDBDebug("Obtained filename from layer configuration [%s]", dataSource->cfgLayer->FilePath[0]->value.c_str());
} else {
CDBDebug("CDBFILESCANNER_UPDATEDB_ONLYFILEFROMDEFAULTQUERY");
int status = CRequest::setDimValuesForDataSource(dataSource, dataSource->srvParams);
if (status != 0) {
CDBError("setDimValuesForDataSource");
return 1;
}
status = CRequest::fillDimValuesForDataSource(dataSource, dataSource->srvParams);
if (status != 0) {
CDBError("fillDimValuesForDataSource");
return 1;
}
status = CRequest::queryDimValuesForDataSource(dataSource, dataSource->srvParams);
if (status != 0) {
CDBError("queryDimValuesForDataSource");

std::string fileName;
if (CAutoConfigure::getFileNameForDataSource(dataSource, fileName) != 0) {
CDBDebug("Unable to getFileNameForDataSource");
return 1;
}
fileList.push_back(dataSource->getFileName());
CDBDebug("Queried file from database with filename [%s]", dataSource->getFileName());
fileList.push_back(fileName);
CDBDebug("Queried file from database with filename [%s]", fileName.c_str());
}
} else {
fileList = searchFileNames(dataSource->cfgLayer->FilePath[0]->value.c_str(), filter.c_str(), tailPath.c_str());
Expand Down
12 changes: 9 additions & 3 deletions adagucserverEC/utils/UpdateLayerMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#include <CDebugger.h>
#include <CRequest.h>
#include "ConfigurationUtils.h"
#include <CDBFactory.h>
#include <CDBStore.h>
#include <json_adaguc.h>

void serverLogFunctionNothing(const char *) {}

Expand Down Expand Up @@ -33,7 +36,7 @@ int updateLayerMetadata(CRequest &request) {
CServerParams *srvParam = request.getServerParams();

auto datasetList = getEnabledDatasetsConfigurations(srvParam);
// TODO: Remove datasets in metadatable which don't have a matching configuration
// TODO: Remove datasets and layers in metadatable which don't have a matching configuration
// TODO: Remove dimension tables which don't have a matching configuration

for (auto &dataset : datasetList) {
Expand All @@ -46,11 +49,14 @@ int updateLayerMetadata(CRequest &request) {
int status = setCRequestConfigFromEnvironment(&requestPerDataset, dataset.c_str());
if (status != 0) {
CDBError("Unable to read configuration file");
return 1;
continue;
}
status = requestPerDataset.updatedb(nullptr, nullptr, CDBFILESCANNER_UPDATEDB | CDBFILESCANNER_DONTREMOVEDATAFROMDB | CDBFILESCANNER_UPDATEDB_ONLYFILEFROMDEFAULTQUERY, "");
CT::string layerPathToScan;
CT::string tailPath;
status = requestPerDataset.updatedb(&tailPath, &layerPathToScan, CDBFILESCANNER_UPDATEDB | CDBFILESCANNER_DONTREMOVEDATAFROMDB | CDBFILESCANNER_UPDATEDB_ONLYFILEFROMDEFAULTQUERY, "");
if (status != 0) {
CDBError("Error occured in updating the database");
continue;
}
// return 0;
}
Expand Down

0 comments on commit 552e28c

Please sign in to comment.