Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
0oM4R committed Oct 21, 2024
2 parents 750c9c9 + ca42e22 commit dfb6a2f
Show file tree
Hide file tree
Showing 19 changed files with 270 additions and 134 deletions.
6 changes: 3 additions & 3 deletions packages/playground/src/components/deployment_data_dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<v-btn> JSON</v-btn>
</v-btn-toggle>
</div>

<v-tabs v-model="activeTab" align-tabs="center" class="my-4 mx-auto" v-if="showType === 0">
<v-tab
v-for="(item, index) in contracts"
Expand Down Expand Up @@ -228,7 +227,8 @@ async function getGrafanaUrl() {
}
isLoading.value = false;
}
getGrafanaUrl();
onMounted(async () => await getGrafanaUrl());
async function getGPUInfo() {
loadingCard.value = true;
Expand Down Expand Up @@ -320,6 +320,7 @@ function getTooltipText(contract: any, index: number) {
<script lang="ts">
import type { GridClient } from "@threefold/grid_client";
import { onMounted } from "vue";
import { ContractType } from "@/utils/contracts";
import { createCustomToast, ToastType } from "@/utils/custom_toast";
Expand All @@ -339,4 +340,3 @@ export default {
},
};
</script>
@/utils/get_metrics_url
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async function deploy(layout: any) {
await layout.validateBalance(grid);
const vm = await addMachine(grid!, {
const vms = await addMachine(grid!, {
name: worker.value.name,
deploymentName: props.master.name,
cpu: worker.value.solution!.cpu,
Expand Down Expand Up @@ -144,10 +144,7 @@ async function deploy(layout: any) {
}),
});
const [leader, ...workers] = vm;
leader.workers = workers;
leader.projectName = props.projectName;
leader.deploymentName = leader.name;
const leader = setCaproverWorkers(vms, props.projectName);
caproverData.value = leader;
deployedDialog.value = true;
layout.setStatus("success", `Successfully add a new worker to Caprover('${props.master.name}') Instance.`);
Expand All @@ -159,8 +156,6 @@ async function deploy(layout: any) {
async function onDelete(cb: (workers: any[]) => void) {
deleting.value = true;
for (const worker of selectedWorkers.value) {
console.log(props.master.name, worker.name);
try {
await deleteMachine(grid!, {
deploymentName: props.master.name,
Expand All @@ -185,6 +180,8 @@ async function onDelete(cb: (workers: any[]) => void) {
<script lang="ts">
import { calculateRootFileSystem, type GridClient } from "@threefold/grid_client";
import { setCaproverWorkers } from "@/utils/deploy_helpers";
import CaproverWorker, { createWorker } from "../components/caprover_worker.vue";
import ListTable from "../components/list_table.vue";
import { updateGrid } from "../utils/grid";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default {
size: window.env.PAGE_SIZE,
page: Math.max(1, pagination.value.page),
farmId: enableCustomDomain.value ? props.farm?.farmId : undefined,
availableFor: gridStore.client.twinId,
availableFor: gridStore.client?.twinId,
}));
const selectedDomain = ref<NodeInfo | null>(null);
const loadDomains = () => domainsTask.value.run(gridStore, filters.value);
Expand Down
23 changes: 11 additions & 12 deletions packages/playground/src/components/vm_deployment_table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -257,19 +257,17 @@ async function loadDeployments() {

const vms = mergeLoadedDeployments(chunk1, chunk2, chunk3 as any);
failedDeployments.value = vms.failedDeployments;

count.value = vms.count;
items.value = vms.items
.map((vm: any) => {
if (props.projectName.toLowerCase() === ProjectName.Caprover.toLowerCase()) {
const [leader, ...workers] = vm;
leader.workers = workers;
return leader;
}

return vm;
})
.flat();
const updatedVMS = vms.items.map((_vms: any) => {
const leader = setCaproverWorkers(_vms);
return leader || _vms;
});

const has_leader = updatedVMS.filter(vm => vm.env && vm.env["SWM_NODE_MODE"] === "leader").length > 0;

if (has_leader) {
items.value = updatedVMS;
}
} catch (err) {
errorMessage.value = `Failed to load Deployments: ${err}`;
} finally {
Expand Down Expand Up @@ -460,6 +458,7 @@ defineExpose({ loadDeployments });

<script lang="ts">
import toHumanDate from "@/utils/date";
import { setCaproverWorkers } from "@/utils/deploy_helpers";

import { ProjectName } from "../types";
import { migrateModule } from "../utils/migration";
Expand Down
27 changes: 8 additions & 19 deletions packages/playground/src/dashboard/components/create_farm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
<v-card-text>
<form-validator v-model="valid">
<input-validator
:value="$props.name"
:value="farmName"
:rules="[
validators.required('Farm name is required.'),
name => validators.isAlpha('Farm name must start with an alphabet char.')(name[0]),
(farmName: string) => validators.isAlpha('Farm name must start with an alphabet char.')(farmName[0]),
validators.minLength('Farm name minimum length is 3 chars.', 3),
validators.maxLength('Farm name maximum length is 40 chars.', 40),
validators.pattern('Farm name should not contain whitespaces.', {
Expand All @@ -34,13 +34,7 @@
:async-rules="[validateFarmName]"
#="{ props }"
>
<v-text-field
:model-value="$props.name"
v-bind:="props"
@update:model-value="$emit('update:name', $event)"
outlined
label="Farm name"
></v-text-field>
<v-text-field v-model="farmName" v-bind:="props" outlined label="Farm name"></v-text-field>
</input-validator>
</form-validator>
</v-card-text>
Expand All @@ -65,26 +59,20 @@ import { createCustomToast, ToastType } from "../../utils/custom_toast";
export default {
name: "CreateFarm",
props: {
name: {
type: String,
required: true,
},
},
setup(props, context) {
setup() {
const showDialogue = ref(false);
const isCreating = ref(false);
const gridStore = useGrid();
const valid = ref(false);
const farmName = ref("");
async function createFarm() {
try {
isCreating.value = true;
await gridStore.grid.farms.create({ name: props.name });
await gridStore.grid.farms.create({ name: farmName.value });
createCustomToast("Farm created successfully.", ToastType.success);
showDialogue.value = false;
context.emit("farm-created");
farmName.value = "";
notifyDelaying();
} catch (error) {
console.log(error);
Expand All @@ -109,6 +97,7 @@ export default {
showDialogue,
isCreating,
valid,
farmName,
createFarm,
validateFarmName,
};
Expand Down
44 changes: 27 additions & 17 deletions packages/playground/src/dashboard/components/public_ips_table.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
<template>
<div>
<ListTable :headers="headers" :items="publicIps" :loading="loading" :deleting="isRemoving" v-model="selectedItems">
<ListTable
:headers="headers"
:items="publicIps"
:loading="loading"
:items-per-page-options="[
{ value: 5, title: '5' },
{ value: 10, title: '10' },
{ value: 20, title: '20' },
{ value: 50, title: '50' },
]"
:deleting="isRemoving"
v-model="selectedItems"
>
<template v-slot:top>
<v-alert>
<h4 class="text-center font-weight-medium">Public IPs</h4>
Expand All @@ -16,23 +28,21 @@
<template #[`item.contractId`]="{ item }">
{{ item.contractId ?? "-" }}
</template>
<template #bottom>
<div v-if="publicIps.length > 0" class="d-flex align-end justify-end">
<v-btn
class="ma-3"
color="error"
prepend-icon="mdi-delete"
:disabled="selectedItems.length === 0 || isRemoving"
@click="showDialogue = true"
>
Delete
</v-btn>
</div>
<div v-else>
<p class="my-4">No IPs added on this farm.</p>
</div>
</template>
</ListTable>
<div v-if="publicIps.length > 0" class="d-flex align-end justify-end">
<v-btn
class="ma-3"
color="error"
prepend-icon="mdi-delete"
:disabled="selectedItems.length === 0 || isRemoving"
@click="showDialogue = true"
>
Delete
</v-btn>
</div>
<div v-else>
<p class="my-4">No IPs added on this farm.</p>
</div>
<v-dialog v-model="showDialogue" max-width="600" attach="#modals">
<v-card>
<v-card-title class="text-subtitle-1">
Expand Down
5 changes: 1 addition & 4 deletions packages/playground/src/dashboard/farms_view.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<v-card-title class="pa-0">Farms</v-card-title>
</v-card>

<CreateFarm v-model:name="name" class="mt-4" @farm-created="farmsReload = true" />
<CreateFarm class="mt-4" @farm-created="farmsReload = true" />
<UserFarms ref="userFarms" :reloadFarms="farmsReload" />
<UserNodes />
</div>
Expand All @@ -17,7 +17,6 @@ import { ref } from "vue";
import CreateFarm from "./components/create_farm.vue";
import UserFarms from "./components/user_farms.vue";
import UserNodes from "./components/user_nodes.vue";
export default {
name: "DashboardFarms",
components: {
Expand All @@ -26,11 +25,9 @@ export default {
CreateFarm,
},
setup() {
const name = ref<string>("");
const farmsReload = ref<boolean>(false);
return {
name,
farmsReload,
};
},
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ function createDeployRoutes(): RouteRecordRaw[] {
{
path: DashboardRoutes.Deploy.Domains,
component: () => import("@/views/domains_view.vue"),
meta: { title: "Domains", publicPath: true },
meta: { title: "Domains" },
},
{
path: DashboardRoutes.Deploy.NodeFinder,
Expand Down
26 changes: 25 additions & 1 deletion packages/playground/src/utils/deploy_helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NetworkModel } from "@threefold/grid_client";
import { NetworkModel, type ZmachineData } from "@threefold/grid_client";

import { generateName } from "./strings";

Expand All @@ -11,6 +11,30 @@ export function createNetwork(network: Network = {}): NetworkModel {
return nw;
}

export function setCaproverWorkers(vms: ZmachineData[], projectName: string | undefined = undefined): ZmachineData {
let leader: any = null;
const workers: any[] = [];

vms.forEach((vm: any) => {
if (vm.env["SWM_NODE_MODE"] === "leader") {
leader = vm;
} else if (vm.env["SWM_NODE_MODE"] === "worker") {
workers.push(vm);
}

if (projectName && leader) {
vm.projectName = projectName;
vm.deploymentName = leader.name;
}
});

if (leader) {
leader.workers = workers;
}

return leader as ZmachineData;
}

export interface Network {
name?: string;
ipRange?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/src/utils/manual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const manual = {
tft_bridges: `${BASE}/documentation/threefold_token/tft_bridges/tft_bridges.html`,
buy_sell_tft: `${BASE}/documentation/threefold_token/buy_sell_tft/buy_sell_tft.html`,
farmers: `${BASE}/documentation/farmers/farmers.html`,
governance: `${BASE}/knowledge_base/about/governance.html`,
governance: `${BASE}/documentation/dashboard/tfchain/tf_dao.html`,
pricing: `${BASE}/knowledge_base/cloud/pricing/pricing.html`,
dao: `${BASE}/documentation/dashboard/tfchain/tf_dao.html`,
caprover: `${BASE}/documentation/dashboard/solutions/caprover.html`,
Expand Down
1 change: 1 addition & 0 deletions packages/tfchain_client/chainMeta.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ declare module "@polkadot/api-base/types/consts" {
* Max Authorities in use
**/
maxAuthorities: u32 & AugmentedConst<ApiType>;
/**
* The maximum number of nominators for each validator.
**/
maxNominators: u32 & AugmentedConst<ApiType>;
/**
* The maximum number of entries to keep in the set id to session index mapping.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ declare module "@polkadot/api-base/types/errors" {
* Account is not a member
**/
NotMember: AugmentedError<ApiType>;
/**
* Prime account is not a member
**/
PrimeAccountNotMember: AugmentedError<ApiType>;
/**
* Proposal must exist
**/
Expand Down Expand Up @@ -245,6 +249,7 @@ declare module "@polkadot/api-base/types/errors" {
CanOnlyIncreaseFrequency: AugmentedError<ApiType>;
ContractIsNotUnique: AugmentedError<ApiType>;
ContractNotExists: AugmentedError<ApiType>;
ContractPaymentStateNotExists: AugmentedError<ApiType>;
ContractWrongBillingLoopIndex: AugmentedError<ApiType>;
FailedToFreeIPs: AugmentedError<ApiType>;
FailedToReserveIP: AugmentedError<ApiType>;
Expand Down Expand Up @@ -274,6 +279,7 @@ declare module "@polkadot/api-base/types/errors" {
OffchainSignedTxCannotSign: AugmentedError<ApiType>;
OffchainSignedTxNoLocalAccountAvailable: AugmentedError<ApiType>;
PricingPolicyNotExists: AugmentedError<ApiType>;
RewardDistributionError: AugmentedError<ApiType>;
ServiceContractApprovalNotAllowed: AugmentedError<ApiType>;
ServiceContractBillingNotApprovedByBoth: AugmentedError<ApiType>;
ServiceContractBillingVariableAmountTooHigh: AugmentedError<ApiType>;
Expand Down
Loading

0 comments on commit dfb6a2f

Please sign in to comment.