Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions src/components/core/handler/ddoHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,15 @@ export class GetDdoHandler extends CommandHandler {
return validationResponse
}
try {
const ddo = await this.getOceanNode().getDatabase().ddo.retrieve(task.id)
const database = this.getOceanNode().getDatabase()
if (!database || !database.ddo) {
CORE_LOGGER.error('DDO database is not available')
return {
stream: null,
status: { httpStatus: 503, error: 'DDO database is not available' }
}
}
const ddo = await database.ddo.retrieve(task.id)
if (!ddo) {
return {
stream: null,
Expand Down Expand Up @@ -590,9 +598,12 @@ export class FindDdoHandler extends CommandHandler {
updatedCache = true
// also store it locally on db
if (configuration.hasIndexer) {
const ddoExistsLocally = await node.getDatabase().ddo.retrieve(ddo.id)
if (!ddoExistsLocally) {
p2pNode.storeAndAdvertiseDDOS([ddo])
const database = node.getDatabase()
if (database && database.ddo) {
const ddoExistsLocally = await database.ddo.retrieve(ddo.id)
if (!ddoExistsLocally) {
p2pNode.storeAndAdvertiseDDOS([ddo])
}
}
}
} else {
Expand Down Expand Up @@ -736,8 +747,16 @@ export class FindDdoHandler extends CommandHandler {
// First try to find the DDO Locally if findDDO is not enforced
if (!force) {
try {
const ddo = await node.getDatabase().ddo.retrieve(ddoId)
return ddo as DDO
const database = node.getDatabase()
if (database && database.ddo) {
const ddo = await database.ddo.retrieve(ddoId)
return ddo as DDO
} else {
CORE_LOGGER.logMessage(
`DDO database is not available. Proceeding to call findDDO`,
true
)
}
} catch (error) {
CORE_LOGGER.logMessage(
`Unable to find DDO locally. Proceeding to call findDDO`,
Expand Down
9 changes: 8 additions & 1 deletion src/components/core/handler/policyServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@ export class PolicyServerInitializeHandler extends CommandHandler {
}
// resolve DDO first
try {
const ddo = await this.getOceanNode().getDatabase().ddo.retrieve(task.documentId)
const database = this.getOceanNode().getDatabase()
if (!database || !database.ddo) {
return {
stream: null,
status: { httpStatus: 503, error: 'DDO database is not available' }
}
}
const ddo = await database.ddo.retrieve(task.documentId)
if (!ddo) {
return {
stream: null,
Expand Down
21 changes: 19 additions & 2 deletions src/components/core/handler/queryHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ export class QueryHandler extends CommandHandler {
return validationResponse
}
try {
let result = await this.getOceanNode().getDatabase().ddo.search(task.query)
const database = this.getOceanNode().getDatabase()
if (!database || !database.ddo) {
CORE_LOGGER.error('DDO database is not available')
return {
stream: null,
status: { httpStatus: 503, error: 'DDO database is not available' }
}
}
let result = await database.ddo.search(task.query)
if (!result) {
result = []
}
Expand All @@ -45,7 +53,16 @@ export class QueryDdoStateHandler extends QueryHandler {
return buildInvalidParametersResponse(validation)
}
try {
const result = await this.getOceanNode().getDatabase().ddoState.search(task.query)
const database = this.getOceanNode().getDatabase()
if (!database || !database.ddoState) {
CORE_LOGGER.error('DDO State database is not available')
return {
stream: null,
status: { httpStatus: 503, error: 'DDO State database is not available' }
}
}

const result = await database.ddoState.search(task.query)

CORE_LOGGER.debug(`DDO State search result: ${JSON.stringify(result)}`)

Expand Down
12 changes: 11 additions & 1 deletion src/components/core/utils/findDdoHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,17 @@ export async function findDDOLocally(
node: OceanNode,
id: string
): Promise<FindDDOResponse> | undefined {
const ddo = await node.getDatabase().ddo.retrieve(id)
const database = node.getDatabase()
if (!database || !database.ddo) {
CORE_LOGGER.log(
LOG_LEVELS_STR.LEVEL_WARN,
'DDO database is not available. Cannot retrieve DDO locally.',
true
)
return undefined
}

const ddo = await database.ddo.retrieve(id)
if (ddo) {
// node has ddo
const p2pNode: OceanP2P = node.getP2PNode()
Expand Down
11 changes: 9 additions & 2 deletions src/components/core/utils/statusHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,15 @@ async function getIndexerBlockInfo(
): Promise<string> {
let blockNr = '0'
try {
const { indexer: indexerDatabase } = oceanNode.getDatabase()
const { lastIndexedBlock } = await indexerDatabase.retrieve(supportedNetwork.chainId)
const database = oceanNode.getDatabase()
if (!database || !database.indexer) {
CORE_LOGGER.log(
LOG_LEVELS_STR.LEVEL_WARN,
`Indexer database is not available for network ${supportedNetwork.network}`
)
return blockNr
}
const { lastIndexedBlock } = await database.indexer.retrieve(supportedNetwork.chainId)
blockNr = lastIndexedBlock.toString()
} catch (error) {
CORE_LOGGER.log(
Expand Down
7 changes: 6 additions & 1 deletion src/components/httpRoutes/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ logRoutes.post('/logs', express.json(), validateRequest, async (req, res) => {
logRoutes.post('/log/:id', express.json(), validateRequest, async (req, res) => {
try {
const logId = req.params.id
const log = await req.oceanNode.getDatabase().logs.retrieveLog(logId)
const database = req.oceanNode.getDatabase()
if (!database || !database.logs) {
res.status(503).send('Logs database is not available')
return
}
const log = await database.logs.retrieveLog(logId)
if (log) {
res.json(log)
} else {
Expand Down
Loading