-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gateways: add rule gateway and endpoints
- Loading branch information
Showing
15 changed files
with
622 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { BaseDTO } from "@/lib/sdk/dto"; | ||
import { LockState, Rule } from "../entity/rucio"; | ||
|
||
/** | ||
* The Data Transfer Object for the ListRulesEndpoint which contains the stream | ||
*/ | ||
export interface RuleDTO extends BaseDTO, Rule {} | ||
|
||
/** | ||
* Data Transfer Object for Rule Replica Locks | ||
*/ | ||
export interface RuleReplicaLockStateDTO extends BaseDTO { | ||
scope: string; | ||
name: string; | ||
rse: string; | ||
state: LockState; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { BaseStreamableDTO } from "@/lib/sdk/dto"; | ||
import { RuleDTO } from "../../dto/rule-dto"; | ||
|
||
export default interface RuleGatewayOutputPort { | ||
|
||
/** | ||
* Gets the details of the given Rule from Rucio. | ||
* @param rucioAuthToken A valid Rucio Auth Token. | ||
* @param ruleId The rule to get. | ||
*/ | ||
getRule(rucioAuthToken: string, ruleId: string): Promise<RuleDTO> | ||
|
||
/** | ||
* Lists all rules for a given account. | ||
* @param rucioAuthToken A valid Rucio Auth Token. | ||
*/ | ||
listRules(rucioAuthToken: string): Promise<BaseStreamableDTO> | ||
|
||
/** | ||
* Lists all locks for a given rule. | ||
* @param rucioAuthToken A valid Rucio Auth Token. | ||
* @param ruleId The rule to list locks for. | ||
*/ | ||
listRuleReplicaLockStates(rucioAuthToken: string, ruleId: string): Promise<BaseStreamableDTO> | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
src/lib/infrastructure/gateway/rule-gateway/endpoints/get-rule-endpoints.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { RuleDTO } from "@/lib/core/dto/rule-dto"; | ||
import { BaseEndpoint } from "@/lib/sdk/gateway-endpoints"; | ||
import { HTTPRequest } from "@/lib/sdk/http"; | ||
import { convertToRuleDTO, getEmptyRuleDTO, TRucioRule } from "../rule-gateway-utils"; | ||
import { Response } from "node-fetch"; | ||
|
||
export default class GetRuleEndpoint extends BaseEndpoint<RuleDTO> { | ||
constructor( | ||
private readonly rucioAuthToken: string, | ||
private readonly ruleId: string, | ||
){ | ||
super() | ||
} | ||
|
||
async initialize(): Promise<void> { | ||
await super.initialize() | ||
const rucioHost = await this.envConfigGateway.rucioHost() | ||
const endpoint = `${rucioHost}/rules/${this.ruleId}` | ||
const request: HTTPRequest = { | ||
method: 'GET', | ||
url: endpoint, | ||
headers: { | ||
'X-Rucio-Auth-Token': this.rucioAuthToken, | ||
'Content-Type': 'application/json', | ||
}, | ||
} | ||
this.request = request | ||
this.initialized = true | ||
} | ||
|
||
/** | ||
* If this method is called, it means that the response from Rucio was not in any of the error types in ${@link handleCommonGatewayEndpointErrors} | ||
* @param statusCode The status code returned from Rucio | ||
* @param response The reponse containing error data | ||
* @returns | ||
*/ | ||
async reportErrors(statusCode: number, response: Response): Promise<RuleDTO | undefined> { | ||
const data = await response.json() | ||
const errorDTO: RuleDTO = { | ||
...getEmptyRuleDTO(), | ||
status: 'error', | ||
errorMessage: data, | ||
errorCode: statusCode, | ||
errorName: 'Unknown Error', | ||
errorType: 'gateway-endpoint-error', | ||
} | ||
return Promise.resolve(errorDTO) | ||
} | ||
|
||
/** | ||
* Converts stream elements into RSEDTO objects | ||
* @param response The individual RSE object streamed from Rucio | ||
* @returns The RSEDTO object | ||
*/ | ||
createDTO(data: TRucioRule): RuleDTO { | ||
const dto: RuleDTO = convertToRuleDTO(data) | ||
return dto | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...b/infrastructure/gateway/rule-gateway/endpoints/list-rule-replica-lock-states-endpoint.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { RuleReplicaLockStateDTO } from "@/lib/core/dto/rule-dto" | ||
import { BaseStreamableDTO } from "@/lib/sdk/dto" | ||
import { BaseStreamableEndpoint } from "@/lib/sdk/gateway-endpoints" | ||
import { HTTPRequest } from "@/lib/sdk/http" | ||
import { Response } from "node-fetch" | ||
import { convertToRuleReplicaLockDTO, TRucioRuleReplicaLock } from "../rule-gateway-utils" | ||
export default class ListRuleReplicaLockStatesEndpoint extends BaseStreamableEndpoint<BaseStreamableDTO, RuleReplicaLockStateDTO> { | ||
constructor( | ||
private readonly rucioAuthToken: string, | ||
private readonly ruleId: string, | ||
){ | ||
super(true) | ||
} | ||
|
||
async initialize(): Promise<void> { | ||
await super.initialize() | ||
const rucioHost = await this.envConfigGateway.rucioHost() | ||
const endpoint = `${rucioHost}/rules/${this.ruleId}/locks` | ||
const request: HTTPRequest = { | ||
method: 'GET', | ||
url: endpoint, | ||
headers: { | ||
'X-Rucio-Auth-Token': this.rucioAuthToken, | ||
'Content-Type': 'application/x-json-stream', | ||
}, | ||
} | ||
this.request = request | ||
this.initialized = true | ||
} | ||
|
||
/** | ||
* If this method is called, it means that the response from Rucio was not in any of the error types in ${@link handleCommonGatewayEndpointErrors} | ||
* @param statusCode The status code returned from Rucio | ||
* @param response The reponse containing error data | ||
* @returns | ||
*/ | ||
async reportErrors(statusCode: number, response: Response): Promise<BaseStreamableDTO | undefined> { | ||
const data = await response.json() | ||
const errorDTO: BaseStreamableDTO = { | ||
status: 'error', | ||
errorMessage: data, | ||
errorCode: statusCode, | ||
errorName: 'Unknown Error', | ||
errorType: 'gateway-endpoint-error', | ||
stream: null, | ||
} | ||
return Promise.resolve(errorDTO) | ||
|
||
} | ||
|
||
/** | ||
* Converts stream elements into RSEDTO objects | ||
* @param response The individual RSE object streamed from Rucio | ||
* @returns The RSEDTO object | ||
*/ | ||
createDTO(response: Buffer): RuleReplicaLockStateDTO { | ||
const data: TRucioRuleReplicaLock = JSON.parse(JSON.parse(response.toString())) | ||
const dto: RuleReplicaLockStateDTO = convertToRuleReplicaLockDTO(data) | ||
return dto | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/lib/infrastructure/gateway/rule-gateway/endpoints/list-rules-for-account-endpoint.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { RuleDTO } from "@/lib/core/dto/rule-dto"; | ||
import { BaseStreamableDTO } from "@/lib/sdk/dto"; | ||
import { BaseStreamableEndpoint } from "@/lib/sdk/gateway-endpoints"; | ||
import { HTTPRequest } from "@/lib/sdk/http"; | ||
import { Response } from "node-fetch"; | ||
import { convertToRuleDTO, TRucioRule } from "../rule-gateway-utils"; | ||
|
||
|
||
/** | ||
* Endpoint for listing rules for an account | ||
*/ | ||
export default class ListRulesEndpoint extends BaseStreamableEndpoint<BaseStreamableDTO, RuleDTO> { | ||
constructor( | ||
private readonly rucioAuthToken: string, | ||
){ | ||
super(true) | ||
} | ||
|
||
async initialize(): Promise<void> { | ||
await super.initialize() | ||
const rucioHost = await this.envConfigGateway.rucioHost() | ||
const endpoint = `${rucioHost}/rules/` | ||
const request: HTTPRequest = { | ||
method: 'GET', | ||
url: endpoint, | ||
headers: { | ||
'X-Rucio-Auth-Token': this.rucioAuthToken, | ||
'Content-Type': 'application/x-json-stream', | ||
}, | ||
} | ||
this.request = request | ||
this.initialized = true | ||
} | ||
|
||
/** | ||
* If this method is called, it means that the response from Rucio was not in any of the error types in ${@link handleCommonGatewayEndpointErrors} | ||
* @param statusCode The status code returned from Rucio | ||
* @param response The reponse containing error data | ||
* @returns | ||
*/ | ||
async reportErrors(statusCode: number, response: Response): Promise<BaseStreamableDTO | undefined> { | ||
const data = await response.json() | ||
const errorDTO: BaseStreamableDTO = { | ||
status: 'error', | ||
errorMessage: data, | ||
errorCode: statusCode, | ||
errorName: 'Unknown Error', | ||
errorType: 'gateway-endpoint-error', | ||
stream: null, | ||
} | ||
return Promise.resolve(errorDTO) | ||
|
||
} | ||
|
||
/** | ||
* Converts stream elements into RSEDTO objects | ||
* @param response The individual RSE object streamed from Rucio | ||
* @returns The RSEDTO object | ||
*/ | ||
|
||
createDTO(response: Buffer): RuleDTO { | ||
const data: TRucioRule = JSON.parse(JSON.parse(response.toString())) | ||
const dto: RuleDTO = convertToRuleDTO(data) | ||
return dto | ||
} | ||
|
||
} |
Oops, something went wrong.