Skip to content

Commit

Permalink
spline #1155 Foxx :: split routes into "producer", "consumer" and "ad…
Browse files Browse the repository at this point in the history
…min" sub-routes
  • Loading branch information
wajda committed Oct 6, 2024
1 parent 2b1ae28 commit 554b46b
Show file tree
Hide file tree
Showing 19 changed files with 228 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package za.co.absa.spline.consumer.service.model

import java.util.UUID

import io.swagger.annotations.{ApiModel, ApiModelProperty}
import za.co.absa.spline.consumer.service.model.ExecutionPlanInfo.Id

import java.util.UUID

@ApiModel(description = "Execution plan information")
case class ExecutionPlanInfo
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { createRouter } from '@arangodb/foxx'
import joi from 'joi'
import { pruneBefore } from '../services/prune-database'
import { pruneBefore } from '../../services/prune-database'


export const adminRouter = createRouter()
Expand Down
20 changes: 20 additions & 0 deletions arangodb-foxx-services/src/main/routes/admin/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2022 ABSA Group Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { adminRouter } from './admin-router'


export default adminRouter
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,16 @@
import { createRouter } from '@arangodb/foxx'
import Joi from 'joi'

import { lineageOverview } from '../services/lineage-overview'
import { impactOverview } from '../services/impact-overview'
import { Progress } from '../../external/persistence-api.model'
import {
checkExecutionEventExists,
listExecutionEventInfo_groupedByDataSource,
listExecutionEvents,
storeExecutionEvent
} from '../services/execution-event-store'
import { lineageOverview } from '../../services/lineage-overview'
import { impactOverview } from '../../services/impact-overview'
import { listExecutionEventInfo_groupedByDataSource, listExecutionEvents } from '../../services/execution-event-store'
import { LineageOverview } from '../../model'
import { ExecutionEventInfo, Frame } from '../../../external/consumer-api.model'


export const eventsRouter: Foxx.Router = createRouter()


// Store execution event
eventsRouter
.post('/',
(req: Foxx.Request, res: Foxx.Response) => {
const execEvent: Progress = req.body
storeExecutionEvent(execEvent)
res.status('created')
})
.body(['application/json'], 'Execution Event (Progress) JSON')
.response(201, 'Execution event recorded')
.summary('Record a new execution event')


// List execution events
eventsRouter
.get('/',
Expand Down Expand Up @@ -89,21 +72,22 @@ eventsRouter
eventsRouter
.get('/_grouped-by-ds',
(req: Foxx.Request, res: Foxx.Response) => {
const events = listExecutionEventInfo_groupedByDataSource(
req.queryParams.asAtTime,
req.queryParams.timestampStart,
req.queryParams.timestampEnd,
req.queryParams.searchTerm,
req.queryParams.writeAppends,
req.queryParams.includeNoWrite,
req.queryParams.applicationId,
req.queryParams.dataSourceUri,
req.queryParams.labels,
req.queryParams.sortField,
req.queryParams.sortOrder,
req.queryParams.offset,
req.queryParams.limit,
)
const events: Frame<Partial<ExecutionEventInfo>> =
listExecutionEventInfo_groupedByDataSource(
req.queryParams.asAtTime,
req.queryParams.timestampStart,
req.queryParams.timestampEnd,
req.queryParams.searchTerm,
req.queryParams.writeAppends,
req.queryParams.includeNoWrite,
req.queryParams.applicationId,
req.queryParams.dataSourceUri,
req.queryParams.labels,
req.queryParams.sortField,
req.queryParams.sortOrder,
req.queryParams.offset,
req.queryParams.limit,
)
res.send(events)
})
.queryParam('asAtTime', Joi.number().required())
Expand All @@ -128,29 +112,13 @@ eventsRouter
.summary('List execution events')


// Check if execution event exists
eventsRouter
.get('/:eventId/_exists',
(req: Foxx.Request, res: Foxx.Response) => {
const exists = checkExecutionEventExists(
req.pathParams.eventId,
req.queryParams.discriminator
)
res.send(exists)
})
.pathParam('eventId', Joi.string().min(1).required(), 'Execution Event ID')
.queryParam('discriminator', Joi.string().optional(), 'Execution Event Discriminator')
.response(200, ['application/json'], 'Boolean value indicating if the execution event exists')
.summary('Check if the execution event with the given parameters exists')


// Get execution event lineage overview
eventsRouter
.get('/:eventKey/lineage-overview/:maxDepth',
(req: Foxx.Request, res: Foxx.Response) => {
const eventKey = req.pathParams.eventKey
const maxDepth = req.pathParams.maxDepth
const overview = lineageOverview(eventKey, maxDepth)
const eventKey: string = req.pathParams.eventKey
const maxDepth: number = req.pathParams.maxDepth
const overview: LineageOverview = lineageOverview(eventKey, maxDepth)
if (overview) {
res.send(overview)
}
Expand All @@ -170,9 +138,9 @@ eventsRouter
eventsRouter
.get('/:eventKey/impact-overview/:maxDepth',
(req: Foxx.Request, res: Foxx.Response) => {
const eventKey = req.pathParams.eventKey
const maxDepth = req.pathParams.maxDepth
const overview = impactOverview(eventKey, maxDepth)
const eventKey: string = req.pathParams.eventKey
const maxDepth: number = req.pathParams.maxDepth
const overview: LineageOverview = impactOverview(eventKey, maxDepth)
if (overview) {
res.send(overview)
}
Expand Down
30 changes: 30 additions & 0 deletions arangodb-foxx-services/src/main/routes/consumer/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2022 ABSA Group Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { createRouter } from '@arangodb/foxx'

import { plansRouter } from './plans-router'
import { eventsRouter } from './events-router'
import { operationsRouter } from './operations-router'


const consumerRouter: Foxx.Router = createRouter()

consumerRouter.use('/execution-plans', plansRouter)
consumerRouter.use('/execution-events', eventsRouter)
consumerRouter.use('/operations', operationsRouter)

export default consumerRouter
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

import { createRouter } from '@arangodb/foxx'
import Joi from 'joi'
import { getOperationById } from '../services/operation-store'
import { ExpressionGraph, OperationDetails } from '../../external/consumer-api.model'
import { expressionGraphUsedByOperation } from '../services/expressions-store'
import { getOperationById } from '../../services/operation-store'
import { ExpressionGraph, OperationDetails } from '../../../external/consumer-api.model'
import { expressionGraphUsedByOperation } from '../../services/expressions-store'


export const operationsRouter: Foxx.Router = createRouter()
Expand Down
37 changes: 37 additions & 0 deletions arangodb-foxx-services/src/main/routes/consumer/plans-router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2022 ABSA Group Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { createRouter } from '@arangodb/foxx'
import { DataSourceActionType } from '../../../external/consumer-api.model'
import { getDataSourceURIsByActionType } from '../../services/execution-plan-store'
import Joi from 'joi'


export const plansRouter: Foxx.Router = createRouter()


plansRouter
.get('/:planId/data-sources',
(req: Foxx.Request, res: Foxx.Response) => {
const uris: string[] = getDataSourceURIsByActionType(
req.pathParams.planId,
req.queryParams.access
)
res.send(uris)
})
.pathParam('planId', Joi.string().min(1).required(), 'Execution Plan ID')
.queryParam('access', Joi.string().optional().valid(DataSourceActionType.values).default(null), 'Access type (read/write) to filter by')
.response(200, ['application/json'], 'Array of data source URIs')
14 changes: 5 additions & 9 deletions arangodb-foxx-services/src/main/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
import { createRouter } from '@arangodb/foxx'
import { context } from '@arangodb/locals'

import { adminRouter } from './admin-router'
import { plansRouter } from './plans-router'
import { eventsRouter } from './events-router'
import { dsRouter } from './data-sources-router'
import { operationsRouter } from './operations-router'
import { RequestLogger } from '../middleware/request-logger.middleware'
import adminRouter from './admin'
import producerRouter from './producer'
import consumerRouter from './consumer'


const rootRouter: Foxx.Router = createRouter()
Expand All @@ -32,9 +30,7 @@ if (context.isDevelopment) {
}

rootRouter.use('/admin', adminRouter)
rootRouter.use('/execution-plans', plansRouter)
rootRouter.use('/execution-events', eventsRouter)
rootRouter.use('/data-sources', dsRouter)
rootRouter.use('/operations', operationsRouter)
rootRouter.use('/producer', producerRouter)
rootRouter.use('/consumer', consumerRouter)

export default rootRouter
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/

import { createRouter } from '@arangodb/foxx'
import { DataSource } from '../../external/persistence-api.model'
import { storeDataSources } from '../services/data-source-store'
import { DataSource } from '../../../external/persistence-api.model'
import { storeDataSources } from '../../services/data-source-store'


export const dsRouter: Foxx.Router = createRouter()
Expand Down
53 changes: 53 additions & 0 deletions arangodb-foxx-services/src/main/routes/producer/events-router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2022 ABSA Group Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { createRouter } from '@arangodb/foxx'
import Joi from 'joi'
import { Progress } from '../../../external/persistence-api.model'
import { checkExecutionEventExists, storeExecutionEvent } from '../../services/execution-event-store'


export const eventsRouter: Foxx.Router = createRouter()


// Store execution event
eventsRouter
.post('/',
(req: Foxx.Request, res: Foxx.Response) => {
const execEvent: Progress = req.body
storeExecutionEvent(execEvent)
res.status('created')
})
.body(['application/json'], 'Execution Event (Progress) JSON')
.response(201, 'Execution event recorded')
.summary('Record a new execution event')


// Check if execution event exists
eventsRouter
.get('/:eventId/_exists',
(req: Foxx.Request, res: Foxx.Response) => {
const exists = checkExecutionEventExists(
req.pathParams.eventId,
req.queryParams.discriminator
)
res.send(exists)
})
.pathParam('eventId', Joi.string().min(1).required(), 'Execution Event ID')
.queryParam('discriminator', Joi.string().optional(), 'Execution Event Discriminator')
.response(200, ['application/json'], 'Boolean value indicating if the execution event exists')
.summary('Check if the execution event with the given parameters exists')

29 changes: 29 additions & 0 deletions arangodb-foxx-services/src/main/routes/producer/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2022 ABSA Group Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { createRouter } from '@arangodb/foxx'
import { dsRouter } from './data-sources-router'
import { plansRouter } from './plans-router'
import { eventsRouter } from './events-router'


const producerRouter: Foxx.Router = createRouter()

producerRouter.use('/data-sources', dsRouter)
producerRouter.use('/execution-plans', plansRouter)
producerRouter.use('/execution-events', eventsRouter)

export default producerRouter
Loading

0 comments on commit 554b46b

Please sign in to comment.