Skip to content

Commit

Permalink
Fix type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
MytsV committed Nov 14, 2024
1 parent 25eda8e commit 8dc69fa
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/app/(rucio)/rule/page/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use client';

import { DetailsRule } from '@/component-library/pages/Rule/details/DetailsRule';
import {useEffect} from "react";
import { useEffect } from 'react';

export default function PageRule({ params }: { params: { id: string } }) {
useEffect(() => {
document.title = 'Rule - Rucio';
}, []);

return <DetailsRule id={params.id} />;
}
17 changes: 17 additions & 0 deletions src/lib/core/dto/rse-dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BaseDTO, BaseStreamableDTO } from '@/lib/sdk/dto';
import { RSE, RSEAttribute, RSEDetails, RSEProtocol, RSEType } from '@/lib/core/entity/rucio';
import { undefined } from 'zod';

/**
* The Data Transfer Object for the ListRSEsEndpoint which contains the stream
Expand All @@ -11,6 +12,22 @@ export interface ListRSEsDTO extends BaseStreamableDTO {}
*/
export interface RSEDetailsDTO extends BaseDTO, RSEDetails {}

export const getEmptyRSEDetailsDTO = (): RSEDetailsDTO => {
return {
availability_delete: false,
availability_read: false,
availability_write: false,
deterministic: false,
id: '',
name: '',
protocols: [],
rse_type: RSEType.UNKNOWN,
staging_area: false,
status: 'error',
volatile: false,
};
};

/**
* Data Transfer Object for GET RSE Protocols Endpoint
*/
Expand Down
6 changes: 3 additions & 3 deletions src/lib/core/use-case/list-account-rse-quotas-usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { collectStreamedData } from '@/lib/sdk/utils';
import { injectable } from 'inversify';
import { Transform, Readable, PassThrough } from 'stream';
import { AccountRSELimitDTO, AccountRSEUsageDTO } from '../dto/account-dto';
import { ListRSEsDTO, RSEDTO } from '../dto/rse-dto';
import { ListRSEsDTO, RSEDetailsDTO } from '../dto/rse-dto';
import { DIDLong } from '../entity/rucio';
import { TAccountRSEUsageAndLimits, TRSESummaryRow } from '../entity/rule-summary';
import type { ListAccountRSEQuotasInputPort, ListAccountRSEQuotasOutputPort } from '../port/primary/list-account-rse-quotas-ports';
Expand All @@ -24,7 +24,7 @@ export default class ListAccountRSEQuotasUseCase
AuthenticatedRequestModel<ListAccountRSEQuotasRequest>,
ListAccountRSEQuotasResponse,
ListAccountRSEQuotasError,
RSEDTO,
RSEDetailsDTO,
RSEAccountUsageLimitViewModel
>
implements ListAccountRSEQuotasInputPort
Expand Down Expand Up @@ -133,7 +133,7 @@ export default class ListAccountRSEQuotasUseCase
}
}

processStreamedData(rse: RSEDTO): { data: ListAccountRSEQuotasResponse | ListAccountRSEQuotasError; status: 'success' | 'error' } {
processStreamedData(rse: RSEDetailsDTO): { data: ListAccountRSEQuotasResponse | ListAccountRSEQuotasError; status: 'success' | 'error' } {
const quotaInfo: (TRSESummaryRow & { status: 'success' }) | BaseErrorResponseModel = getQuotaInfo(
rse,
this.account,
Expand Down
7 changes: 3 additions & 4 deletions src/lib/core/use-case/list-all-rses-usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { ListAllRSEsError, ListAllRSEsRequest, ListAllRSEsResponse } from '@/lib
import { ListAllRSEsInputPort, type ListAllRSEsOutputPort } from '@/lib/core/port/primary/list-all-rses-ports';
import { RSEViewModel } from '@/lib/infrastructure/data/view-model/rse';

import { ListRSEsDTO } from '@/lib/core/dto/rse-dto';
import { RSEDTO } from '@/lib/core/dto/rse-dto';
import { ListRSEsDTO, RSEDetailsDTO } from '@/lib/core/dto/rse-dto';
import type RSEGatewayOutputPort from '@/lib/core/port/secondary/rse-gateway-output-port';

@injectable()
Expand All @@ -17,7 +16,7 @@ export default class ListAllRSEsUseCase
ListAllRSEsResponse,
ListAllRSEsError,
ListRSEsDTO,
RSEDTO,
RSEDetailsDTO,
RSEViewModel
>
implements ListAllRSEsInputPort
Expand Down Expand Up @@ -51,7 +50,7 @@ export default class ListAllRSEsUseCase
} as ListAllRSEsError;
}

processStreamedData(dto: RSEDTO): { data: ListAllRSEsResponse | ListAllRSEsError; status: 'success' | 'error' } {
processStreamedData(dto: RSEDetailsDTO): { data: ListAllRSEsResponse | ListAllRSEsError; status: 'success' | 'error' } {
if (dto.status === 'error') {
const errorModel: ListAllRSEsError = {
status: 'error',
Expand Down
6 changes: 3 additions & 3 deletions src/lib/core/use-case/list-rses/list-rses-usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { RSEViewModel } from '@/lib/infrastructure/data/view-model/rse';

import type RSEGatewayOutputPort from '@/lib/core/port/secondary/rse-gateway-output-port';
import { ListRSEsDTO } from '@/lib/core/dto/rse-dto';
import { RSEDTO } from '@/lib/core/dto/rse-dto';
import { RSEDetailsDTO } from '@/lib/core/dto/rse-dto';

import { ListRSEsInputPort, type ListRSEsOutputPort } from '@/lib/core/port/primary/list-rses-ports';

Expand All @@ -20,7 +20,7 @@ export default class ListRSEsUseCase
ListRSEsResponse,
ListRSEsError,
ListRSEsDTO,
RSEDTO,
RSEDetailsDTO,
RSEViewModel
>
implements ListRSEsInputPort
Expand Down Expand Up @@ -69,7 +69,7 @@ export default class ListRSEsUseCase
} as ListRSEsError;
}

processStreamedData(dto: RSEDTO): { data: ListRSEsResponse | ListRSEsError; status: 'success' | 'error' } {
processStreamedData(dto: RSEDetailsDTO): { data: ListRSEsResponse | ListRSEsError; status: 'success' | 'error' } {
if (dto.status === 'error') {
const errorModel: ListRSEsError = {
status: 'error',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import { BaseStreamingPostProcessingPipelineElement } from '@/lib/sdk/postprocessing-pipeline-elements';
import { AuthenticatedRequestModel } from '@/lib/sdk/usecase-models';

import { RSEDTO, getEmptyRSEDTO } from '@/lib/core/dto/rse-dto';
import { getEmptyRSEDetailsDTO, RSEDetailsDTO } from '@/lib/core/dto/rse-dto';
import RSEGatewayOutputPort from '@/lib/core/port/secondary/rse-gateway-output-port';
import { ListRSEsError, ListRSEsRequest, ListRSEsResponse } from '@/lib/core/usecase-models/list-rses-usecase-models';

export default class GetRSEPipelineElement extends BaseStreamingPostProcessingPipelineElement<
ListRSEsRequest,
ListRSEsResponse,
ListRSEsError,
RSEDTO
RSEDetailsDTO
> {
constructor(private gateway: RSEGatewayOutputPort) {
super();
}
async makeGatewayRequest(requestModel: AuthenticatedRequestModel<ListRSEsRequest>, responseModel: ListRSEsResponse): Promise<RSEDTO> {
async makeGatewayRequest(requestModel: AuthenticatedRequestModel<ListRSEsRequest>, responseModel: ListRSEsResponse): Promise<RSEDetailsDTO> {
try {
const { rucioAuthToken } = requestModel;
const rseName = responseModel.name;
if (!rseName) {
const errorDTO: RSEDTO = getEmptyRSEDTO();
const errorDTO: RSEDetailsDTO = getEmptyRSEDetailsDTO();
errorDTO.status = 'error';
errorDTO.errorCode = 400;
errorDTO.errorName = 'Invalid Request';
errorDTO.errorMessage = 'RSE Name not found in response model';
return errorDTO;
}
const dto: RSEDTO = await this.gateway.getRSE(rucioAuthToken, rseName);
const dto: RSEDetailsDTO = await this.gateway.getRSE(rucioAuthToken, rseName);
return dto;
} catch (error: any) {
const errorDTO: RSEDTO = getEmptyRSEDTO();
const errorDTO: RSEDetailsDTO = getEmptyRSEDetailsDTO();
errorDTO.status = 'error';
errorDTO.errorCode = 500;
errorDTO.errorName = 'Gateway Error';
Expand All @@ -38,7 +38,7 @@ export default class GetRSEPipelineElement extends BaseStreamingPostProcessingPi
}
}

handleGatewayError(dto: RSEDTO): ListRSEsError {
handleGatewayError(dto: RSEDetailsDTO): ListRSEsError {
const errorModel: ListRSEsError = {
status: 'error',
name: dto.name,
Expand All @@ -48,7 +48,7 @@ export default class GetRSEPipelineElement extends BaseStreamingPostProcessingPi
return errorModel;
}

transformResponseModel(responseModel: ListRSEsResponse, dto: RSEDTO): ListRSEsResponse {
transformResponseModel(responseModel: ListRSEsResponse, dto: RSEDetailsDTO): ListRSEsResponse {
responseModel.id = dto.id;
responseModel.deterministic = dto.deterministic;
responseModel.rse_type = dto.rse_type;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/core/utils/create-rule-utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseErrorResponseModel } from '@/lib/sdk/usecase-models';
import { AccountRSELimitDTO, AccountRSEUsageDTO } from '../dto/account-dto';
import { RSEDTO } from '../dto/rse-dto';
import { RSEDetailsDTO } from '../dto/rse-dto';
import { DIDLong, DIDType, RSEAccountUsage } from '../entity/rucio';
import { TAccountRSEUsageAndLimits, TDIDSummaryRow, TRSESummaryRow } from '../entity/rule-summary';
import { BaseDTO } from '@/lib/sdk/dto';
Expand Down Expand Up @@ -83,7 +83,7 @@ export const createAccountRSEUsageAndLimitMap = (
* If the account has no limits specified, a BaseErrorResponseModel is returned.
*/
export const getQuotaInfo = (
rse: RSEDTO,
rse: RSEDetailsDTO,
account: string,
accountRSEUsageAndLimits: TAccountRSEUsageAndLimits,
totalDIDBytesRequested: number,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ListRSEsDTO, RSEDTO } from '@/lib/core/dto/rse-dto';
import { ListRSEsDTO, RSEDetailsDTO } from '@/lib/core/dto/rse-dto';
import { BaseStreamableEndpoint } from '@/lib/sdk/gateway-endpoints';
import { HTTPRequest } from '@/lib/sdk/http';
import { Response } from 'node-fetch';
import { convertToRSEDTO, TRucioRSE } from '../rse-gateway-utils';

export default class ListRSEsEndpoint extends BaseStreamableEndpoint<ListRSEsDTO, RSEDTO> {
export default class ListRSEsEndpoint extends BaseStreamableEndpoint<ListRSEsDTO, RSEDetailsDTO> {
constructor(private readonly rucioAuthToken: string, private readonly rseExpression: string) {
super(true);
}
Expand Down Expand Up @@ -53,9 +53,9 @@ export default class ListRSEsEndpoint extends BaseStreamableEndpoint<ListRSEsDTO
* @param response The individual RSE object streamed from Rucio
* @returns The RSEDTO object
*/
createDTO(response: Buffer): RSEDTO {
createDTO(response: Buffer): RSEDetailsDTO {
const data: TRucioRSE = JSON.parse(JSON.parse(response.toString()));
const dto: RSEDTO = convertToRSEDTO(data);
const dto: RSEDetailsDTO = convertToRSEDTO(data);
return dto;
}
}
10 changes: 7 additions & 3 deletions src/lib/infrastructure/gateway/rse-gateway/rse-gateway-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RSEDTO, RSEProtocolDTO } from '@/lib/core/dto/rse-dto';
import { RSEDetailsDTO, RSEProtocolDTO } from '@/lib/core/dto/rse-dto';
import { RSEProtocol, RSEType } from '@/lib/core/entity/rucio';
/**
* Represents the data returned by Rucio Server for a RSE.
Expand Down Expand Up @@ -75,8 +75,12 @@ function getRSEType(rseType: string): RSEType {
* @param rse The RSE of type {@link TRucioRSE} to convert to a DTO
* @returns A {@link RSEDTO} object
*/
export function convertToRSEDTO(rse: TRucioRSE): RSEDTO {
const dto: RSEDTO = {
export function convertToRSEDTO(rse: TRucioRSE): RSEDetailsDTO {
const dto: RSEDetailsDTO = {
availability_delete: false,
availability_read: false,
availability_write: false,
protocols: [],
status: 'success',
id: rse.id,
name: rse.rse,
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/table-fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
RSEBlockState,
RSEProtocol,
RSEType,
RuleGrouping,
RuleNotification,
RuleState,
SubscriptionState,
Expand Down Expand Up @@ -168,7 +169,7 @@ export function fixtureRuleMetaViewModel(): RuleMetaViewModel {
created_at: faker.date.past().toISOString(),
did_type: faker.helpers.arrayElement<DIDType>([DIDType.CONTAINER, DIDType.DATASET, DIDType.FILE]),
expires_at: faker.date.future().toISOString(),
grouping: faker.helpers.arrayElement<DIDType>([DIDType.CONTAINER, DIDType.DATASET, DIDType.FILE]),
grouping: faker.helpers.arrayElement<RuleGrouping>([RuleGrouping.ALL, RuleGrouping.DATASET, RuleGrouping.NONE]),
id: faker.string.uuid(),
ignore_account_limit: faker.datatype.boolean(),
ignore_availability: faker.datatype.boolean(),
Expand Down

0 comments on commit 8dc69fa

Please sign in to comment.