frontends and data plane connections to owned shares (#323)

This commit is contained in:
Michael Quigley 2023-05-17 13:21:01 -04:00
parent 4119ab4e2b
commit 05b53df6ba
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
7 changed files with 83 additions and 12 deletions

View File

@ -38,16 +38,6 @@ func (h *overviewHandler) Handle(_ metadata.OverviewParams, principal *rest_mode
} }
ovr := &rest_model_zrok.Overview{AccountLimited: accountLimited} ovr := &rest_model_zrok.Overview{AccountLimited: accountLimited}
for _, env := range envs { for _, env := range envs {
shrs, err := str.FindSharesForEnvironment(env.Id, trx)
if err != nil {
logrus.Errorf("error finding shares for environment '%v': %v", env.ZId, err)
return metadata.NewOverviewInternalServerError()
}
slm, err := newSharesLimitedMap(shrs, trx)
if err != nil {
logrus.Errorf("error finding limited shares for environment '%v': %v", env.ZId, err)
return metadata.NewOverviewInternalServerError()
}
envRes := &rest_model_zrok.EnvironmentAndResources{ envRes := &rest_model_zrok.EnvironmentAndResources{
Environment: &rest_model_zrok.Environment{ Environment: &rest_model_zrok.Environment{
Address: env.Address, Address: env.Address,
@ -59,6 +49,16 @@ func (h *overviewHandler) Handle(_ metadata.OverviewParams, principal *rest_mode
UpdatedAt: env.UpdatedAt.UnixMilli(), UpdatedAt: env.UpdatedAt.UnixMilli(),
}, },
} }
shrs, err := str.FindSharesForEnvironment(env.Id, trx)
if err != nil {
logrus.Errorf("error finding shares for environment '%v': %v", env.ZId, err)
return metadata.NewOverviewInternalServerError()
}
slm, err := newSharesLimitedMap(shrs, trx)
if err != nil {
logrus.Errorf("error finding limited shares for environment '%v': %v", env.ZId, err)
return metadata.NewOverviewInternalServerError()
}
for _, shr := range shrs { for _, shr := range shrs {
feEndpoint := "" feEndpoint := ""
if shr.FrontendEndpoint != nil { if shr.FrontendEndpoint != nil {
@ -87,6 +87,28 @@ func (h *overviewHandler) Handle(_ metadata.OverviewParams, principal *rest_mode
} }
envRes.Shares = append(envRes.Shares, envShr) envRes.Shares = append(envRes.Shares, envShr)
} }
fes, err := str.FindFrontendsForEnvironment(env.Id, trx)
if err != nil {
logrus.Errorf("error finding frontends for environment '%v': %v", env.ZId, err)
return metadata.NewOverviewInternalServerError()
}
for _, fe := range fes {
envFe := &rest_model_zrok.Frontend{
ID: int64(fe.Id),
ZID: fe.ZId,
CreatedAt: fe.CreatedAt.UnixMilli(),
UpdatedAt: fe.UpdatedAt.UnixMilli(),
}
if fe.PrivateShareId != nil {
feShr, err := str.GetShare(*fe.PrivateShareId, trx)
if err != nil {
logrus.Errorf("error getting share for frontend '%v': %v", fe.ZId, err)
return metadata.NewOverviewInternalServerError()
}
envFe.ShrToken = feShr.Token
}
envRes.Frontends = append(envRes.Frontends, envFe)
}
ovr.Environments = append(ovr.Environments, envRes) ovr.Environments = append(ovr.Environments, envRes)
} }
return metadata.NewOverviewOK().WithPayload(ovr) return metadata.NewOverviewOK().WithPayload(ovr)

View File

@ -20,6 +20,9 @@ type Frontend struct {
// created at // created at
CreatedAt int64 `json:"createdAt,omitempty"` CreatedAt int64 `json:"createdAt,omitempty"`
// id
ID int64 `json:"id,omitempty"`
// shr token // shr token
ShrToken string `json:"shrToken,omitempty"` ShrToken string `json:"shrToken,omitempty"`

View File

@ -1144,6 +1144,9 @@ func init() {
"createdAt": { "createdAt": {
"type": "integer" "type": "integer"
}, },
"id": {
"type": "integer"
},
"shrToken": { "shrToken": {
"type": "string" "type": "string"
}, },
@ -2655,6 +2658,9 @@ func init() {
"createdAt": { "createdAt": {
"type": "integer" "type": "integer"
}, },
"id": {
"type": "integer"
},
"shrToken": { "shrToken": {
"type": "string" "type": "string"
}, },

View File

@ -734,6 +734,8 @@ definitions:
frontend: frontend:
type: object type: object
properties: properties:
id:
type: integer
shrToken: shrToken:
type: string type: string
zId: zId:

View File

@ -106,6 +106,7 @@
* @typedef frontend * @typedef frontend
* @memberof module:types * @memberof module:types
* *
* @property {number} id
* @property {string} shrToken * @property {string} shrToken
* @property {string} zId * @property {string} zId
* @property {number} createdAt * @property {number} createdAt

View File

@ -3,10 +3,11 @@ import {useEffect, useRef} from "react";
import {ForceGraph2D} from "react-force-graph"; import {ForceGraph2D} from "react-force-graph";
import * as d3 from "d3-force-3d"; import * as d3 from "d3-force-3d";
import {roundRect} from "./draw"; import {roundRect} from "./draw";
import {mdiShareVariant, mdiConsole, mdiAccount, mdiAlertOctagram} from "@mdi/js"; import {mdiShareVariant, mdiConsole, mdiAccount, mdiAlertOctagram, mdiAccessPointNetwork} from "@mdi/js";
const accountIcon = new Path2D(mdiAccount); const accountIcon = new Path2D(mdiAccount);
const environmentIcon = new Path2D(mdiConsole); const environmentIcon = new Path2D(mdiConsole);
const frontendIcon = new Path2D(mdiAccessPointNetwork);
const limitIcon = new Path2D(mdiAlertOctagram); const limitIcon = new Path2D(mdiAlertOctagram);
const shareIcon = new Path2D(mdiShareVariant); const shareIcon = new Path2D(mdiShareVariant);
@ -46,6 +47,9 @@ const Network = (props) => {
case "environment": case "environment":
nodeIcon.addPath(environmentIcon, xform); nodeIcon.addPath(environmentIcon, xform);
break; break;
case "frontend":
nodeIcon.addPath(frontendIcon, xform);
break;
case "account": case "account":
nodeIcon.addPath(accountIcon, xform); nodeIcon.addPath(accountIcon, xform);
break; break;
@ -84,7 +88,8 @@ const Network = (props) => {
height={800} height={800}
onNodeClick={nodeClicked} onNodeClick={nodeClicked}
linkOpacity={.75} linkOpacity={.75}
linkWidth={1.5} linkWidth={(l) => l.type === "data" ? 3.0 : 1.5 }
linkLineDash={(l) => l.type === "data" ? [3, 3] : [] }
nodeCanvasObject={paintNode} nodeCanvasObject={paintNode}
backgroundColor={"linear-gradient(180deg, #0E0238 0%, #231069 100%);"} backgroundColor={"linear-gradient(180deg, #0E0238 0%, #231069 100%);"}
cooldownTicks={300} cooldownTicks={300}

View File

@ -31,6 +31,8 @@ export const mergeGraph = (oldGraph, user, accountLimited, newOverview) => {
newGraph.nodes.push(accountNode); newGraph.nodes.push(accountNode);
if(newOverview) { if(newOverview) {
let allShares = {};
let allFrontends = [];
newOverview.forEach(env => { newOverview.forEach(env => {
let limited = !!env.limited; let limited = !!env.limited;
let envNode = { let envNode = {
@ -60,6 +62,7 @@ export const mergeGraph = (oldGraph, user, accountLimited, newOverview) => {
limited: !!shr.limited || envNode.limited, limited: !!shr.limited || envNode.limited,
val: 50 val: 50
}; };
allShares[shr.token] = shrNode;
newGraph.nodes.push(shrNode); newGraph.nodes.push(shrNode);
newGraph.links.push({ newGraph.links.push({
target: envNode.id, target: envNode.id,
@ -68,6 +71,35 @@ export const mergeGraph = (oldGraph, user, accountLimited, newOverview) => {
}); });
}); });
} }
if(env.frontends) {
env.frontends.forEach(fe => {
let feNode = {
id: fe.id,
target: fe.shrToken,
label: fe.shrToken,
type: "frontend",
val: 50
}
allFrontends.push(feNode);
newGraph.nodes.push(feNode);
newGraph.links.push({
target: envNode.id,
source: feNode.id,
color: "#04adef"
});
});
}
});
allFrontends.forEach(fe => {
let target = allShares[fe.target];
if(target) {
newGraph.links.push({
target: target.id,
source: fe.id,
color: "#9BF316",
type: "data",
});
}
}); });
} }
newGraph.nodes = sortNodes(newGraph.nodes); newGraph.nodes = sortNodes(newGraph.nodes);