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

Fr 327 show overlay topology #462

Merged
merged 3 commits into from
Aug 16, 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
10 changes: 8 additions & 2 deletions src/external-api/topology-discovery-graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ type CoordinatesParam = {
y: number;
};

type DeviceMetadataFilters = {
deviceName?: string | null;
topologyType?: 'PhysicalTopology' | 'PtpTopology' | 'EthTopology' | 'NetworkTopology' | 'MplsTopology' | null;
polygon?: number[][][] | null;
};

const GET_SHORTEST_PATH = gql`
query GetShortestPath($deviceFrom: ID!, $deviceTo: ID!, $collection: NetRoutingPathOutputCollections) {
netRoutingPaths(deviceFrom: $deviceFrom, deviceTo: $deviceTo, outputCollection: $collection) {
Expand Down Expand Up @@ -640,9 +646,9 @@ function getTopologyDiscoveryApi() {
return response.syncePathToGm.nodes;
}

async function getDeviceMetadata(): Promise<DeviceMetadataQuery> {
async function getDeviceMetadata(filters?: DeviceMetadataFilters): Promise<DeviceMetadataQuery> {
const response = await client.request<DeviceMetadataQuery, DeviceMetadataQueryVariables>(DEVICE_METADATA, {
filters: undefined,
filters,
});
return response;
}
Expand Down
20 changes: 19 additions & 1 deletion src/schema/api.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,12 @@ input FilterDevicesInput {
labels: [String!]
}

input FilterDevicesMetadatasInput {
deviceName: String
polygon: PolygonInput
topologyType: TopologyType
}

input FilterLabelsInput {
name: String!
}
Expand Down Expand Up @@ -636,6 +642,10 @@ type PhyTopologyVersionData {
nodes: [GraphVersionNode!]!
}

input PolygonInput {
polygon: [[[Float!]!]!]
}

type PtpDeviceDetails {
clockAccuracy: String
clockClass: Int
Expand Down Expand Up @@ -702,7 +712,7 @@ type Query {
calculatedDiff(deviceId: String!, transactionId: String!): CalculatedDiffPayload!
countries(after: String, before: String, first: Int, last: Int): CountryConnection!
dataStore(deviceId: String!, transactionId: String!): DataStore
deviceMetadata: DeviceMetadata
deviceMetadata(filter: FilterDevicesMetadatasInput): DeviceMetadata
devices(
after: String
before: String
Expand Down Expand Up @@ -874,6 +884,14 @@ enum TopologyLayer {
PtpTopology
}

enum TopologyType {
EthTopology
MplsTopology
NetworkTopology
PhysicalTopology
PtpTopology
}

type Transaction {
changes: [TransactionChange!]!
lastCommitTime: String!
Expand Down
15 changes: 15 additions & 0 deletions src/schema/nexus-typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ export interface NexusGenInputs {
deviceName?: string | null; // String
labels?: string[] | null; // [String!]
};
FilterDevicesMetadatasInput: {
// input type
deviceName?: string | null; // String
polygon?: NexusGenInputs['PolygonInput'] | null; // PolygonInput
topologyType?: NexusGenEnums['TopologyType'] | null; // TopologyType
};
FilterLabelsInput: {
// input type
name: string; // String!
Expand All @@ -157,6 +163,10 @@ export interface NexusGenInputs {
x: number; // Float!
y: number; // Float!
};
PolygonInput: {
// input type
polygon?: number[][][] | null; // [[[Float!]!]!]
};
StreamOrderByInput: {
// input type
direction: NexusGenEnums['SortDirection']; // SortDirection!
Expand Down Expand Up @@ -218,6 +228,7 @@ export interface NexusGenEnums {
SortDirection: 'ASC' | 'DESC';
SortStreamBy: 'createdAt' | 'deviceName' | 'streamName';
TopologyLayer: 'EthTopology' | 'MplsTopology' | 'PhysicalTopology' | 'PtpTopology';
TopologyType: 'EthTopology' | 'MplsTopology' | 'NetworkTopology' | 'PhysicalTopology' | 'PtpTopology';
}

export interface NexusGenScalars {
Expand Down Expand Up @@ -2518,6 +2529,10 @@ export interface NexusGenArgTypes {
deviceId: string; // String!
transactionId: string; // String!
};
deviceMetadata: {
// args
filter?: NexusGenInputs['FilterDevicesMetadatasInput'] | null; // FilterDevicesMetadatasInput
};
devices: {
// args
after?: string | null; // String
Expand Down
32 changes: 31 additions & 1 deletion src/schema/topology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
enumType,
interfaceType,
queryField,
arg,
} from 'nexus';
import config from '../config';
import { fromGraphId } from '../helpers/id-helper';
Expand Down Expand Up @@ -850,13 +851,42 @@ export const DeviceMetadata = objectType({
},
});

export const TopologyType = enumType({
name: 'TopologyType',
members: ['PhysicalTopology', 'PtpTopology', 'EthTopology', 'NetworkTopology', 'MplsTopology'],
});

export const PolygonInputType = inputObjectType({
name: 'PolygonInput',
definition(t) {
t.list.nonNull.list.nonNull.list.nonNull.float('polygon');
},
});

export const FilterDevicesMetadatasInput = inputObjectType({
name: 'FilterDevicesMetadatasInput',
definition: (t) => {
t.string('deviceName');
t.field('topologyType', { type: TopologyType });
t.field('polygon', { type: PolygonInputType });
},
});

export const deviceMetadataQuery = queryField('deviceMetadata', {
type: DeviceMetadata,
args: {
plehocky marked this conversation as resolved.
Show resolved Hide resolved
filter: FilterDevicesMetadatasInput,
},
resolve: async (_, args, { prisma, topologyDiscoveryGraphQLAPI }) => {
if (!topologyDiscoveryGraphQLAPI) {
return null;
}
const deviceMetadataResult = await topologyDiscoveryGraphQLAPI.getDeviceMetadata();

const deviceMetadataResult = await topologyDiscoveryGraphQLAPI.getDeviceMetadata({
deviceName: args.filter?.deviceName,
topologyType: args.filter?.topologyType,
polygon: args.filter?.polygon?.polygon,
});

const dbDevices = await prisma.device.findMany({
include: {
Expand Down