Skip to content

Commit

Permalink
feat: renterd autopilot config evaluation api
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Apr 19, 2024
1 parent 7416ee6 commit 3a98380
Show file tree
Hide file tree
Showing 26 changed files with 279 additions and 100 deletions.
6 changes: 6 additions & 0 deletions .changeset/dull-eggs-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@siafoundation/renterd-js': minor
'@siafoundation/renterd-react': minor
---

Added a method for each known bus setting, in addition to the generic setting method.
5 changes: 5 additions & 0 deletions .changeset/famous-lemons-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@siafoundation/renterd-js': patch
---

Fixed a typo in the naming of the config method.
5 changes: 5 additions & 0 deletions .changeset/new-bananas-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@siafoundation/request': minor
---

Updated type naming.
7 changes: 7 additions & 0 deletions .changeset/nine-crabs-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@siafoundation/renterd-js': minor
'@siafoundation/renterd-react': minor
'@siafoundation/renterd-types': minor
---

Added support for autopilot config evaluation.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useContractSetSettings } from '../../../hooks/useContractSetSettings'
import { useSettingContractSet } from '@siafoundation/renterd-react'

export function useDefaultContractSetNotSet() {
const css = useContractSetSettings()
const css = useSettingContractSet()

return {
active: css.data && !css.data?.default,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useSettingRedundancy } from '@siafoundation/renterd-react'
import { useContracts } from '../../../contexts/contracts'
import { useRedundancySettings } from '../../../hooks/useRedundancySettings'

export function useNotEnoughContracts() {
const redundancy = useRedundancySettings()
const redundancy = useSettingRedundancy()
const { datasetCount, isLoading: isContractsLoading } = useContracts()

const active =
Expand Down
8 changes: 5 additions & 3 deletions apps/renterd/components/Keys/KeyContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import {
truncate,
} from '@siafoundation/design-system'
import { CaretDown16, Delete16 } from '@siafoundation/react-icons'
import { useSettingUpdate } from '@siafoundation/renterd-react'
import { useS3AuthenticationSettings } from '../../hooks/useS3AuthenticationSettings'
import {
useSettingS3Authentication,
useSettingUpdate,
} from '@siafoundation/renterd-react'
import { useCallback } from 'react'
import { omit } from '@technically/lodash'
import { useDialog } from '../../contexts/dialog'
Expand All @@ -25,7 +27,7 @@ type Props = {

export function KeyContextMenu({ s3Key, contentProps, buttonProps }: Props) {
const { openConfirmDialog } = useDialog()
const s3AuthenticationSettings = useS3AuthenticationSettings()
const s3AuthenticationSettings = useSettingS3Authentication()
const update = useSettingUpdate()
const deleteKey = useCallback(async () => {
const newKeys = omit(s3AuthenticationSettings.data?.v4Keypairs, s3Key)
Expand Down
8 changes: 5 additions & 3 deletions apps/renterd/components/Keys/KeysCreateDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import {
import { useCallback, useMemo } from 'react'
import { useForm } from 'react-hook-form'
import { useDialog } from '../../contexts/dialog'
import { useS3AuthenticationSettings } from '../../hooks/useS3AuthenticationSettings'
import { useSettingUpdate } from '@siafoundation/renterd-react'
import {
useSettingS3Authentication,
useSettingUpdate,
} from '@siafoundation/renterd-react'
import { Reset16 } from '@carbon/icons-react'

type Props = {
Expand Down Expand Up @@ -98,7 +100,7 @@ function getFields({

export function KeysCreateDialog({ trigger, open, onOpenChange }: Props) {
const { closeDialog } = useDialog()
const s3AuthenticationSettings = useS3AuthenticationSettings()
const s3AuthenticationSettings = useSettingS3Authentication()
const update = useSettingUpdate()

const form = useForm({
Expand Down
20 changes: 11 additions & 9 deletions apps/renterd/contexts/config/useResources.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { minutesInMilliseconds } from '@siafoundation/design-system'
import { useAutopilotConfig } from '@siafoundation/renterd-react'
import {
useAutopilotConfig,
useSettingContractSet,
useSettingGouging,
useSettingRedundancy,
useSettingUploadPacking,
} from '@siafoundation/renterd-react'
import { useSyncContractSet } from './useSyncContractSet'
import { useAppSettings } from '@siafoundation/react-core'
import { useContractSetSettings } from '../../hooks/useContractSetSettings'
import { useGougingSettings } from '../../hooks/useGougingSettings'
import { useRedundancySettings } from '../../hooks/useRedundancySettings'
import { useUploadPackingSettings } from '../../hooks/useUploadPackingSettings'
import { useSiaCentralHostsNetworkAverages } from '@siafoundation/sia-central-react'
import { useApp } from '../app'

Expand All @@ -21,7 +23,7 @@ export function useResources() {
},
},
})
const contractSet = useContractSetSettings({
const contractSet = useSettingContractSet({
config: {
swr: {
errorRetryCount: 0,
Expand All @@ -30,21 +32,21 @@ export function useResources() {
},
})
// settings with initial defaults
const gouging = useGougingSettings({
const gouging = useSettingGouging({
config: {
swr: {
refreshInterval: minutesInMilliseconds(1),
},
},
})
const redundancy = useRedundancySettings({
const redundancy = useSettingRedundancy({
config: {
swr: {
refreshInterval: minutesInMilliseconds(1),
},
},
})
const uploadPacking = useUploadPackingSettings({
const uploadPacking = useSettingUploadPacking({
config: {
swr: {
refreshInterval: minutesInMilliseconds(1),
Expand Down
8 changes: 5 additions & 3 deletions apps/renterd/contexts/config/useSyncContractSet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ import {
triggerSuccessToast,
} from '@siafoundation/design-system'
import { useCallback } from 'react'
import { useSettingUpdate } from '@siafoundation/renterd-react'
import {
useSettingContractSet,
useSettingUpdate,
} from '@siafoundation/renterd-react'
import useLocalStorageState from 'use-local-storage-state'
import { transformUpContractSet } from '../../contexts/config/transform'
import { useContractSetSettings } from '../../hooks/useContractSetSettings'

export function useSyncContractSet() {
const [shouldSyncDefaultContractSet, setShouldSyncDefaultContractSet] =
useLocalStorageState<boolean>('v0/autopilot/syncDefaultContractSet', {
defaultValue: true,
})
const contractSet = useContractSetSettings({
const contractSet = useSettingContractSet({
config: {
swr: {
errorRetryCount: 0,
Expand Down
4 changes: 2 additions & 2 deletions apps/renterd/contexts/contracts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useRouter } from 'next/router'
import {
useContracts as useContractsData,
useContractSets,
useSettingContractSet,
} from '@siafoundation/renterd-react'
import {
createContext,
Expand All @@ -34,7 +35,6 @@ import { useSiascanUrl } from '../../hooks/useSiascanUrl'
import { blockHeightToTime } from '@siafoundation/units'
import { useContractMetrics } from './useContractMetrics'
import { useContractSetMetrics } from './useContractSetMetrics'
import { useContractSetSettings } from '../../hooks/useContractSetSettings'
import { defaultDatasetRefreshInterval } from '../../config/swr'

const defaultLimit = 50
Expand Down Expand Up @@ -179,7 +179,7 @@ function useContractsMain() {

const siascanUrl = useSiascanUrl()

const contractSetSettings = useContractSetSettings()
const contractSetSettings = useSettingContractSet()
const cellContext = useMemo(
() => ({
currentHeight: syncStatus.estimatedBlockHeight,
Expand Down
4 changes: 2 additions & 2 deletions apps/renterd/contexts/filesManager/uploads.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
useMultipartUploadPart,
useMultipartUploadComplete,
useMultipartUploadCreate,
useSettingRedundancy,
} from '@siafoundation/renterd-react'
import { throttle } from '@technically/lodash'
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
Expand All @@ -22,7 +23,6 @@ import {
import { MultipartUpload } from '../../lib/multipartUpload'
import { MiBToBytes } from '@siafoundation/units'
import { useMutate } from '@siafoundation/react-core'
import { useRedundancySettings } from '../../hooks/useRedundancySettings'
import { useWarnActiveUploadsOnClose } from './useWarnActiveUploadsOnClose'

const maxConcurrentUploads = 5
Expand All @@ -42,7 +42,7 @@ export function useUploads({ activeDirectoryPath }: Props) {
const busUploadCreate = useMultipartUploadCreate()
const busUploadAbort = useMultipartUploadAbort()
const [uploadsMap, setUploadsMap] = useState<UploadsMap>({})
const redundancy = useRedundancySettings({
const redundancy = useSettingRedundancy({
config: {
swr: {
refreshInterval: minutesInMilliseconds(1),
Expand Down
4 changes: 2 additions & 2 deletions apps/renterd/contexts/keys/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ import {
sortOptions,
} from './types'
import { columns } from './columns'
import { useS3AuthenticationSettings } from '../../hooks/useS3AuthenticationSettings'
import { defaultDatasetRefreshInterval } from '../../config/swr'
import { useSettingS3Authentication } from '@siafoundation/renterd-react'

const defaultLimit = 50

function useKeysMain() {
const router = useRouter()
const limit = Number(router.query.limit || defaultLimit)
const offset = Number(router.query.offset || 0)
const response = useS3AuthenticationSettings({
const response = useSettingS3Authentication({
config: {
swr: {
refreshInterval: defaultDatasetRefreshInterval,
Expand Down
12 changes: 0 additions & 12 deletions apps/renterd/hooks/useContractSetSettings.tsx

This file was deleted.

10 changes: 0 additions & 10 deletions apps/renterd/hooks/useGougingSettings.tsx

This file was deleted.

8 changes: 5 additions & 3 deletions apps/renterd/hooks/useIsApcsEqDcs.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { useAutopilotConfig } from '@siafoundation/renterd-react'
import {
useAutopilotConfig,
useSettingContractSet,
} from '@siafoundation/renterd-react'
import { useApp } from '../contexts/app'
import { useContractSetSettings } from './useContractSetSettings'

// is the autopilot contract set the same as the default contract set
export function useIsApcsEqDcs() {
const { autopilot } = useApp()
const apc = useAutopilotConfig({
disabled: autopilot.status !== 'on',
})
const css = useContractSetSettings()
const css = useSettingContractSet()

return {
isValidating: apc.isValidating || css.isValidating,
Expand Down
12 changes: 0 additions & 12 deletions apps/renterd/hooks/useRedundancySettings.tsx

This file was deleted.

12 changes: 0 additions & 12 deletions apps/renterd/hooks/useS3AuthenticationSettings.tsx

This file was deleted.

12 changes: 0 additions & 12 deletions apps/renterd/hooks/useUploadPackingSettings.tsx

This file was deleted.

3 changes: 2 additions & 1 deletion libs/renterd-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"license": "MIT",
"dependencies": {
"@siafoundation/renterd-types": "0.1.0",
"@siafoundation/request": "0.1.0"
"@siafoundation/request": "0.1.0",
"axios": "^0.27.2"
},
"types": "./src/index.d.ts"
}
10 changes: 9 additions & 1 deletion libs/renterd-js/src/autopilot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import {
AutopilotConfigEvaluateParams,
AutopilotConfigEvaluatePayload,
AutopilotConfigEvaluateResponse,
AutopilotConfigParams,
AutopilotConfigPayload,
AutopilotConfigResponse,
Expand Down Expand Up @@ -36,7 +39,7 @@ export function Autopilot({
AutopilotStatePayload,
AutopilotStateResponse
>(axios, 'get', autopilotStateRoute),
confg: buildRequestHandler<
config: buildRequestHandler<
AutopilotConfigParams,
AutopilotConfigPayload,
AutopilotConfigResponse
Expand All @@ -46,6 +49,11 @@ export function Autopilot({
AutopilotConfigUpdatePayload,
AutopilotConfigUpdateResponse
>(axios, 'put', autopilotConfigRoute),
configEvaluate: buildRequestHandler<
AutopilotConfigEvaluateParams,
AutopilotConfigEvaluatePayload,
AutopilotConfigEvaluateResponse
>(axios, 'post', autopilotConfigRoute),
hostsSearch: buildRequestHandler<
AutopilotHostsSearchParams,
AutopilotHostsSearchPayload,
Expand Down
Loading

0 comments on commit 3a98380

Please sign in to comment.