Skip to content

Commit

Permalink
Fr 327 show overlay topology (#462)
Browse files Browse the repository at this point in the history
* added filtering arguments to the DeviceMetaData query

* formatting

* adjusted filter parameters
  • Loading branch information
plehocky authored Aug 16, 2024
1 parent bce4941 commit 8477694
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 4 deletions.
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 @@ -644,9 +650,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 @@ -639,6 +645,10 @@ type PhyTopologyVersionData {
nodes: [GraphVersionNode!]!
}

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

type PtpDeviceDetails {
clockAccuracy: String
clockClass: Int
Expand Down Expand Up @@ -705,7 +715,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 @@ -877,6 +887,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 @@ -2527,6 +2538,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 @@ -853,13 +854,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: {
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

0 comments on commit 8477694

Please sign in to comment.