Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule gateway #392

Merged
merged 2 commits into from
Nov 29, 2023
Merged
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
3 changes: 1 addition & 2 deletions src/component-library/Pages/Helpers/Heading.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { DIDType, LockState } from "@/lib/core/entity/rucio";
import { DIDType } from "@/lib/core/entity/rucio";
import { StoryFn, Meta } from "@storybook/react";
import { DIDTypeTag } from "../../Tags/DIDTypeTag";
import { LockStateTag } from "../../Tags/LockStateTag";
import { Heading as H } from "./Heading";

export default {
Expand Down
4 changes: 2 additions & 2 deletions src/component-library/Tags/LockStateTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export const LockStateTag: (
<span
className={twMerge(
lockState === LockState.OK ? "bg-green-300 border-green-700 dark:bg-green-700 dark:border-green-200" : (
lockState === LockState.Stuck ? "bg-amber-300 border-amber-700 dark:bg-amber-700 dark:border-amber-200" : (
lockState === LockState.Replicating ? "bg-red-400 border-red-700 dark:bg-red-700 dark:border-red-200" :
lockState === LockState.STUCK ? "bg-amber-300 border-amber-700 dark:bg-amber-700 dark:border-amber-200" : (
lockState === LockState.REPLICATING ? "bg-red-400 border-red-700 dark:bg-red-700 dark:border-red-200" :
""
)
),
Expand Down
17 changes: 17 additions & 0 deletions src/lib/core/dto/rule-dto.ts
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;
}
5 changes: 3 additions & 2 deletions src/lib/core/entity/rucio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,10 @@ export type RSEAttribute = {

// rucio.db.sqla.constants::LockState
export enum LockState {
Replicating = "R",
REPLICATING = "R",
OK = "O",
Stuck = "S",
STUCK = "S",
UNKNOWN = "U",
}

// rucio.db.sqla.constants::RuleNotification
Expand Down
26 changes: 26 additions & 0 deletions src/lib/core/port/secondary/rule-gateway-output-port.ts
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>

}
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
}
}
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
}
}
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
}

}
Loading