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

refactor(renterd-libs): move autopilot routes #834

Merged
merged 1 commit into from
Dec 6, 2024
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
7 changes: 7 additions & 0 deletions .changeset/selfish-queens-fold.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
---

The host checks field is now just HostAutopilotChecks.
7 changes: 7 additions & 0 deletions .changeset/ten-lies-draw.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
---

Autopilot config routes moved to the bus.
7 changes: 7 additions & 0 deletions .changeset/violet-peas-press.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
---

Removed the autopilotID parameter from the hosts API.
2 changes: 1 addition & 1 deletion apps/hostd-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"executor": "nx:run-commands",
"options": {
"commands": [
// "cd internal/cluster && go get -u go.sia.tech/hostd@master",
"cd internal/cluster && go get -u go.sia.tech/hostd@master",
"cd internal/cluster && go get -u go.sia.tech/renterd@dev",
"cd internal/cluster && go get -u go.sia.tech/walletd@master",
"cd internal/cluster && go mod tidy",
Expand Down
2 changes: 1 addition & 1 deletion apps/renterd-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"executor": "nx:run-commands",
"options": {
"commands": [
// "cd internal/cluster && go get -u go.sia.tech/hostd@master",
"cd internal/cluster && go get -u go.sia.tech/hostd@master",
"cd internal/cluster && go get -u go.sia.tech/renterd@dev",
"cd internal/cluster && go get -u go.sia.tech/walletd@master",
"cd internal/cluster && go mod tidy",
Expand Down
7 changes: 1 addition & 6 deletions apps/renterd/contexts/hosts/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ import { objectEntries } from '@siafoundation/design-system'
export function useDataset({
response,
allContracts,
autopilotID,
allowlist,
blocklist,
isAllowlistActive,
geoHosts,
onHostSelect,
}: {
response: ReturnType<typeof useHosts>
autopilotID?: string
allContracts: ContractData[]
allowlist: ReturnType<typeof useHostsAllowlist>
blocklist: ReturnType<typeof useHostsBlocklist>
Expand All @@ -47,16 +45,13 @@ export function useDataset({
blocklist: block,
isAllowlistActive,
}),
...getAutopilotFields(
autopilotID ? host.checks?.[autopilotID] : undefined
),
...getAutopilotFields(host.checks),
location: sch?.location,
countryCode: sch?.country_code,
}
})
}, [
onHostSelect,
autopilotID,
response.data,
allContracts,
allowlist.data,
Expand Down
1 change: 0 additions & 1 deletion apps/renterd/contexts/hosts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ function useHostsMain() {
const dataset = useDataset({
response,
allContracts,
autopilotID: autopilotState.data?.id,
allowlist,
blocklist,
isAllowlistActive,
Expand Down
2 changes: 1 addition & 1 deletion apps/walletd-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"executor": "nx:run-commands",
"options": {
"commands": [
// "cd internal/cluster && go get -u go.sia.tech/hostd@master",
"cd internal/cluster && go get -u go.sia.tech/hostd@master",
"cd internal/cluster && go get -u go.sia.tech/renterd@dev",
"cd internal/cluster && go get -u go.sia.tech/walletd@master",
"cd internal/cluster && go mod tidy",
Expand Down
1 change: 0 additions & 1 deletion libs/clusterd/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ export async function waitForContracts({
await mine(1)
const hosts = await bus.hosts({
data: {
autopilotID: 'autopilot',
filterMode: 'allowed',
usabilityMode: 'usable',
limit: 50,
Expand Down
1 change: 0 additions & 1 deletion libs/renterd-js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export async function example() {

const hosts = await bus.hosts({
data: {
autopilotID: 'autopilot',
filterMode: 'allowed',
usabilityMode: 'usable',
addressContains: 'example.com',
Expand Down
20 changes: 2 additions & 18 deletions libs/renterd-js/src/autopilot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@ import {
AutopilotConfigEvaluateParams,
AutopilotConfigEvaluatePayload,
AutopilotConfigEvaluateResponse,
AutopilotConfigParams,
AutopilotConfigPayload,
AutopilotConfigResponse,
AutopilotConfigUpdateParams,
AutopilotConfigUpdatePayload,
AutopilotConfigUpdateResponse,
AutopilotStateParams,
AutopilotStatePayload,
AutopilotStateResponse,
AutopilotTriggerParams,
AutopilotTriggerPayload,
AutopilotTriggerResponse,
autopilotConfigRoute,
autopilotStateRoute,
autopilotTriggerRoute,
autopilotConfigEvaluateRoute,
} from '@siafoundation/renterd-types'
import { buildRequestHandler, initAxios } from '@siafoundation/request'

Expand All @@ -35,21 +29,11 @@ export function Autopilot({
AutopilotStatePayload,
AutopilotStateResponse
>(axios, 'get', autopilotStateRoute),
config: buildRequestHandler<
AutopilotConfigParams,
AutopilotConfigPayload,
AutopilotConfigResponse
>(axios, 'get', autopilotConfigRoute),
configUpdate: buildRequestHandler<
AutopilotConfigUpdateParams,
AutopilotConfigUpdatePayload,
AutopilotConfigUpdateResponse
>(axios, 'put', autopilotConfigRoute),
configEvaluate: buildRequestHandler<
AutopilotConfigEvaluateParams,
AutopilotConfigEvaluatePayload,
AutopilotConfigEvaluateResponse
>(axios, 'post', autopilotConfigRoute),
>(axios, 'post', autopilotConfigEvaluateRoute),
trigger: buildRequestHandler<
AutopilotTriggerParams,
AutopilotTriggerPayload,
Expand Down
17 changes: 17 additions & 0 deletions libs/renterd-js/src/bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ import {
HostScanPayload,
HostScanResponse,
busHostHostKeyScanRoute,
AutopilotConfigParams,
AutopilotConfigPayload,
AutopilotConfigResponse,
AutopilotConfigUpdateParams,
AutopilotConfigUpdatePayload,
AutopilotConfigUpdateResponse,
busAutopilotRoute,
} from '@siafoundation/renterd-types'
import { buildRequestHandler, initAxios } from '@siafoundation/request'

Expand Down Expand Up @@ -598,5 +605,15 @@ export function Bus({ api, password }: { api: string; password?: string }) {
MultipartUploadAddPartPayload,
MultipartUploadAddPartResponse
>(axios, 'post', busMultipartPartRoute),
autopilotConfig: buildRequestHandler<
AutopilotConfigParams,
AutopilotConfigPayload,
AutopilotConfigResponse
>(axios, 'get', busAutopilotRoute),
autopilotConfigUpdate: buildRequestHandler<
AutopilotConfigUpdateParams,
AutopilotConfigUpdatePayload,
AutopilotConfigUpdateResponse
>(axios, 'put', busAutopilotRoute),
}
}
1 change: 0 additions & 1 deletion libs/renterd-js/src/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export async function example() {

const hosts = await bus.hosts({
data: {
autopilotID: 'autopilot-id',
filterMode: 'allowed',
usabilityMode: 'usable',
addressContains: 'example.com',
Expand Down
42 changes: 2 additions & 40 deletions libs/renterd-react/src/autopilot.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import {
useGetSwr,
usePostSwr,
usePutFunc,
HookArgsSwr,
HookArgsCallback,
HookArgsWithPayloadSwr,
delay,
usePostFunc,
} from '@siafoundation/react-core'
import {
AutopilotConfigParams,
AutopilotConfigResponse,
AutopilotConfigUpdateParams,
AutopilotConfigUpdatePayload,
AutopilotConfigUpdateResponse,
AutopilotConfigEvaluateParams,
AutopilotConfigEvaluatePayload,
AutopilotConfigEvaluateResponse,
Expand All @@ -22,9 +15,9 @@ import {
AutopilotTriggerParams,
AutopilotTriggerPayload,
AutopilotTriggerResponse,
autopilotConfigRoute,
autopilotStateRoute,
autopilotTriggerRoute,
autopilotConfigEvaluateRoute,
} from '@siafoundation/renterd-types'

export function useAutopilotState(
Expand All @@ -36,45 +29,14 @@ export function useAutopilotState(
})
}

export function useAutopilotConfig(
args?: HookArgsSwr<AutopilotConfigParams, AutopilotConfigResponse>
) {
return useGetSwr({
...args,
route: autopilotConfigRoute,
})
}

export function useAutopilotConfigUpdate(
args?: HookArgsCallback<
AutopilotConfigUpdateParams,
AutopilotConfigUpdatePayload,
AutopilotConfigUpdateResponse
>
) {
return usePutFunc(
{ ...args, route: autopilotConfigRoute },
async (mutate) => {
mutate((key) => key === autopilotConfigRoute)
// Might need a delay before revalidating status which returns whether
// or not autopilot is configured.
const func = async () => {
await delay(1000)
mutate((key) => key === autopilotStateRoute)
}
func()
}
)
}

export function useAutopilotConfigEvaluate(
args: HookArgsWithPayloadSwr<
AutopilotConfigEvaluateParams,
AutopilotConfigEvaluatePayload,
AutopilotConfigEvaluateResponse
>
) {
return usePostSwr({ ...args, route: autopilotConfigRoute })
return usePostSwr({ ...args, route: autopilotConfigEvaluateRoute })
}

export function useAutopilotTrigger(
Expand Down
37 changes: 37 additions & 0 deletions libs/renterd-react/src/bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ import {
AlertsDismissResponse,
AlertsParams,
AlertsResponse,
AutopilotConfigParams,
AutopilotConfigResponse,
AutopilotConfigUpdateParams,
AutopilotConfigUpdatePayload,
AutopilotConfigUpdateResponse,
busAutopilotRoute,
BucketCreateParams,
BucketCreatePayload,
BucketCreateResponse,
Expand Down Expand Up @@ -247,6 +253,7 @@ import {
HostScanResponse,
busHostHostKeyScanRoute,
Host,
autopilotStateRoute,
} from '@siafoundation/renterd-types'

// state
Expand Down Expand Up @@ -1024,3 +1031,33 @@ export function useMultipartUploadAddPart(
}
)
}

// autopilot

export function useAutopilotConfig(
args?: HookArgsSwr<AutopilotConfigParams, AutopilotConfigResponse>
) {
return useGetSwr({
...args,
route: busAutopilotRoute,
})
}

export function useAutopilotConfigUpdate(
args?: HookArgsCallback<
AutopilotConfigUpdateParams,
AutopilotConfigUpdatePayload,
AutopilotConfigUpdateResponse
>
) {
return usePutFunc({ ...args, route: busAutopilotRoute }, async (mutate) => {
mutate((key) => key === busAutopilotRoute)
// Might need a delay before revalidating status which returns whether
// or not autopilot is configured.
const func = async () => {
await delay(1000)
mutate((key) => key === autopilotStateRoute)
}
func()
})
}
3 changes: 2 additions & 1 deletion libs/renterd-types/src/autopilot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { BuildState } from './bus'
import { AutopilotConfig, SettingsGouging, SettingsRedundancy } from './types'

export const autopilotStateRoute = '/autopilot/state'
export const autopilotConfigRoute = '/autopilot/config'
export const autopilotConfigEvaluateRoute = '/autopilot/config/evaluate'
export const autopilotTriggerRoute = '/autopilot/trigger'
export const busAutopilotRoute = '/bus/autopilot'

type AutopilotStatus = {
id: string
Expand Down
1 change: 0 additions & 1 deletion libs/renterd-types/src/bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ export type HostsParams = void
export type HostsFilterMode = 'all' | 'allowed' | 'blocked'
export type HostsUsabilityMode = 'all' | 'usable' | 'unusable'
export type HostsPayload = {
autopilotID?: string
filterMode: HostsFilterMode
usabilityMode?: HostsUsabilityMode
addressContains?: string
Expand Down
2 changes: 1 addition & 1 deletion libs/renterd-types/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export type Host = {
storedData: number
resolvedAddresses?: string[]
subnets?: string[]
checks?: Record<string, HostAutopilotChecks>
checks?: HostAutopilotChecks
}

export type HostAutopilotChecks = {
Expand Down
Loading