Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
ognots committed Jul 20, 2021
2 parents 759a2f8 + 4f947ab commit e799292
Show file tree
Hide file tree
Showing 17 changed files with 286 additions and 99 deletions.
42 changes: 0 additions & 42 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,27 +137,6 @@ workflows:
branches:
only:
- main
- deploy-lotusinfra:
matrix:
parameters:
release:
- dealbot-daemon-bundle-0
- dealbot-daemon-bundle-1
- dealbot-daemon-bundle-2
name: deploy-nerpanet-daemons
chart: filecoin/lotus-bundle
chart_version: 0.0.2
circle_context: filecoin-mainnet-aws
kubernetes_cluster: mainnet-us-east-1-eks
aws_region: us-east-1
namespace: ntwk-mainnet-dealbot
requires:
- build-push
filters:
branches:
ignore: /.*/
tags:
only: /^v[0-9]+(\.[0-9]+)*$/
- deploy-lotusinfra:
name: deploy-mainnet-controller
chart: filecoin/dealbot
Expand All @@ -174,24 +153,3 @@ workflows:
ignore: /.*/
tags:
only: /^v[0-9]+(\.[0-9]+)*$/
- deploy-lotusinfra:
matrix:
parameters:
release:
- dealbot-daemon-bundle-0
- dealbot-daemon-bundle-1
- dealbot-daemon-bundle-2
name: deploy-mainnet-daemons
chart: filecoin/lotus-bundle
chart_version: 0.0.3
circle_context: filecoin-mainnet-aws
kubernetes_cluster: mainnet-us-east-1-eks
aws_region: us-east-1
namespace: ntwk-mainnet-dealbot
requires:
- build-push
filters:
branches:
ignore: /.*/
tags:
only: /^v[0-9]+(\.[0-9]+)*$/
Binary file removed .dealbot.key
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dealbot.toml
.dealbot.key
*~
controller/static/script.js
node_modules
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN npm install
FROM golang:alpine AS builder
RUN apk update
RUN apk upgrade
RUN apk add --update gcc>=9.3.0 g++>=9.3.0 alpine-sdk linux-headers
RUN apk add --update gcc>=9.3.0 g++>=9.3.0 alpine-sdk linux-headers binutils-gold

WORKDIR /go/src/app/

Expand Down
149 changes: 127 additions & 22 deletions controller/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@ import "bootstrap-table";
import "bootstrap-cron-picker/dist/cron-picker";
import { FilecoinNumber } from "@glif/filecoin-number"
import prettyBytes from 'pretty-bytes'
import { data } from "jquery";

let auth = "";
let regionList = [];
window.setauth = (a) => {
auth = a;
};

let modal = null
let shutdownDaemonID = ""
let shutdownDaemonIndex = 0
let notificationMessage = null
$().ready(() => {
modal = new bootstrap.Modal(document.getElementById('confirmationModal'), {})
notificationMessage = new bootstrap.Toast(document.getElementById('notificationMessage'), {})

$('#newSchedule').cronPicker();
$('#newretafterstoreSchedule').cronPicker();

Expand Down Expand Up @@ -58,6 +66,7 @@ $().ready(() => {
$("#addbot button").on('click', doCreateBot);
$("#botlist").hide()

$("#shutdownConfirm").on('click', confirmShutdown)
fetch("./regions", { method: "GET", headers: getHeaders()}).then((response) => response.json()).then(gotRegions)
syncData()
})
Expand All @@ -68,7 +77,7 @@ function syncData() {
}

function operate(val, row) {
return '<a class="remove" title="remove">Cancel</a>';
return '<div class="remove btn btn-primary" title="remove">Cancel</div>';
}

let firstLoad = true
Expand Down Expand Up @@ -102,6 +111,8 @@ function gotTasks(data) {
}
}

let currentRegion = ""

function gotRegions(data) {
regionList = data["regions"]
$.each(regionList, (reg) => {
Expand All @@ -111,48 +122,56 @@ function gotRegions(data) {
.on('click', function() {
$("#regionList .list-group-item").removeClass("active")
$(this).addClass("active")
currentRegion = regionList[reg]
fetch(`./regions/${regionList[reg]}`, { method: "GET", headers: getHeaders()}).then((response) => response.json()).then(gotDaemons)
})
.appendTo($("#regionlist"));
});
}


function operateDaemon(val, row) {
return `
<div class="drain btn btn-primary" title="drain">Drain</div>
<div class="reset btn btn-primary" title="reset">Reset</div>
<div class="complete btn btn-primary" title="reset">Complete</div>
<div class="shutdown btn btn-danger" title="shutdown">Shutdown</div>`;
}

let firstDaemonsLoad = true
function gotDaemons(data) {
const daemons = data["daemons"]
const processedDaemons = daemons.map((daemon) => {
let daemonData = daemon.daemon
daemonData.minfil = new FilecoinNumber(daemonData.minfil, 'attofil')
daemonData.mincap = BigInt(daemonData.mincap)
if (daemon.funds) {
daemonData.balance = daemon.funds.balance
daemonData.datacap = daemon.funds.datacap
daemonData.balance = new FilecoinNumber(daemon.funds.balance, 'attofil')
daemonData.datacap = BigInt(daemon.funds.datacap)
}
return daemonData
})
if (firstDaemonsLoad) {
let filFormatter = (d) => d ? (new FilecoinNumber(d, 'attofil')).toFil() + " FIL" : "-"
let capFormatter = (c) => c ? prettyBytes(c) : "-"
let filFormatter = (d) => d ? d.toFil() + " FIL" : "-"
let capFormatter = (c) => c ? prettyBytes(Number(c)) : "-"
let capStyler = (value, row) => {
// assume no value + no data-cap = miner making unverified deals = no styling
if (!value && !row.mincap) {
if (value == 0 && row.mincap == 0) {
return {}
}
const valNumber = value || 0
const minCap = row.mincap || 0
if (valNumber < minCap) {
if (value < row.mincap) {
return { classes: 'table-danger' }
}
if (valNumber - minCap < ((1 << 30)*32)) {
if (value - row.mincap < ((1 << 30)*32)) {
return { classes: 'table-warning' }
}
return { classes: 'table-success' }
}
let filStyler = (value, row) => {
const minBal = row.minbal || 0
const valNumber = value || 0
if (value < row.minbal) {
if (value < row.minfil) {
return { classes: 'table-danger' }
}
if (valNumber - minBal < Math.pow(10, 18)) {
if (value - row.minfil < 1) {
return { classes: 'table-warning' }
}
return { classes: 'table-success' }
Expand All @@ -166,7 +185,8 @@ function gotDaemons(data) {
{title:'Region', field:'region'},
{title:'Wallet', field:'wallet.address'},
{title: 'Balance', field: 'balance', formatter: filFormatter, cellStyle: filStyler},
{title: 'Data Cap', field: 'datacap', formatter: capFormatter, cellStyle: capStyler}
{title: 'Data Cap', field: 'datacap', formatter: capFormatter, cellStyle: capStyler},
{title:'Actions', field: 'operate', align: 'center', formatter: operateDaemon, events: { 'click .drain': drain, 'click .reset': reset, 'click .complete': complete,'click .shutdown': shutdown}}
],
data: processedDaemons,
});
Expand All @@ -176,13 +196,98 @@ function gotDaemons(data) {
}
}

function errorToast(message) {
$('#notificationMessage').removeClass('bg-primary')
$('#notificationMessage').addClass("bg-danger")
$('#notificationMessage .toast-body').text(message)
notificationMessage.show()
}

function successToast(message) {
$('#notificationMessage').removeClass('bg-danger')
$('#notificationMessage').addClass("bg-primary")
$('#notificationMessage .toast-body').text(message)
notificationMessage.show()
}

function drain(e, value, row, index) {
if (e.preventDefault) {
e.preventDefault()
}
let url = `./drain/${row.id}`
fetch(url, { method: "POST", headers: getHeaders()}).then((response) => {
if (response.ok) {
successToast(`Daemon ${row.id} will receive no new tasks`)
} else {
errorToast(`Error attempting to drain daemon ${row.id}`)
}
});
}

function reset(e, value, row, index) {
if (e.preventDefault) {
e.preventDefault()
}
let url = `./reset-worker/${row.id}`
fetch(url, { method: "POST", headers: getHeaders()}).then((response) => {
if (response.ok) {
successToast(`All tasks on daemon ${row.id} will be reset to unstarted`)
} else {
errorToast(`Error attempting to reset daemon ${row.id}`)
}
});
}

function complete(e, value, row, index) {
if (e.preventDefault) {
e.preventDefault()
}
let url = `./complete/${row.id}`
fetch(url, { method: "POST", headers: getHeaders()}).then((response) => {
if (response.ok) {
successToast(`Tasks for daemon ${row.id} will be published`)
} else {
errorToast(`Error attempting to publish tasks for daemon ${row.id}`)
}
});
}


function shutdown(e, value, row, index) {
if (e.preventDefault) {
e.preventDefault()
}
shutdownDaemonID = row.id
shutdownDaemonIndex = index
modal.show()
}

function confirmShutdown(e) {
modal.hide()
let url = `./regions/${currentRegion}/${shutdownDaemonID}`
fetch(url, { method: "DELETE", headers: getHeaders()}).then((response) => {
if (response.ok) {
$("#botdetail").bootstrapTable('hideRow', { index: shutdownDaemonIndex })
successToast(`Daemon ${row.id} has been shutdown`)
} else {
errorToast(`Error attempting to shutdown daemon ${row.id}`)
}
});
}


function cancel(e, value, row, index) {
if (e.preventDefault) {
e.preventDefault()
}
let url = `./tasks/${row.UUID}`
fetch(url, { method: "DELETE", headers: getHeaders()}).then((_) => {
$("#taskTable").bootstrapTable('hideRow', { index })
fetch(url, { method: "DELETE", headers: getHeaders()}).then((response) => {
if (response.ok) {
$("#taskTable").bootstrapTable('hideRow', { index })
successToast(`Task ${row.UUID} has been cancelled`)
} else {
errorToast(`Error attempting to cancel task ${row.id}`)
}
});
}

Expand Down Expand Up @@ -244,7 +349,7 @@ function doSubmit(e) {
}

Promise.all(requests).then((_) => {
$("#addDone").show()
successToast("Tasks scheduled!")
syncData()
})

Expand All @@ -255,12 +360,12 @@ function doCreateBot(e) {
let region = $("#newBotRegion").val()
let url = `./regions/${region}`

data = {
let data = {
"id": $("#newBotId").val(),
"tags": $("#newBotTags").val().trim().split('\n'),
"workers": parseInt($("#newBotWorkers").val()),
"mincap": parseInt($("#newBotMinCap").val()),
"minfil": parseInt($("#newBotMinFil").val()),
"mincap": $("#newBotMinCap").val(),
"minfil": (new FilecoinNumber($("#newBotMinFil").val(), 'fil')).toAttoFil(),
"wallet": {
"address": $("#newBotWalletAddress").val(),
"exported": $("#newBotWalletExported").val(),
Expand All @@ -271,6 +376,6 @@ function doCreateBot(e) {
"lotusdockertag": $("#newBotLotusDockerTag").val()
}
fetch(url, {method: "POST", headers: getHeaders(), body: JSON.stringify(data)}).then(() => {
$("#addBotDone").show()
successToast("Bot created!")
})
}
34 changes: 34 additions & 0 deletions controller/app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e799292

Please sign in to comment.