Skip to content

Commit

Permalink
discovery api changes
Browse files Browse the repository at this point in the history
  • Loading branch information
soson committed Aug 30, 2024
1 parent 1ab4294 commit c83a73a
Show file tree
Hide file tree
Showing 9 changed files with 310 additions and 377 deletions.
275 changes: 152 additions & 123 deletions src/__generated__/topology-discovery.graphql.ts

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/context.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ExpressContextFunctionArgument } from '@apollo/server/express4';
import { PrismaClient } from '@prisma/client';
import { IncomingHttpHeaders } from 'http';
import topologyDiscoveryAPI, { TopologyDiscoveryAPI } from './external-api/topology-discovery';
// import topologyDiscoveryAPI, { TopologyDiscoveryAPI } from './external-api/topology-discovery';
import getTopologyDiscoveryApi, { TopologyDiscoveryGraphQLAPI } from './external-api/topology-discovery-graphql';
import uniconfigAPI, { UniConfigAPI } from './external-api/uniconfig';
import prismaClient from './prisma-client';
Expand All @@ -14,7 +14,7 @@ export type Context = {
prisma: PrismaClient;
tenantId: string;
uniconfigAPI: UniConfigAPI;
topologyDiscoveryAPI: TopologyDiscoveryAPI;
// topologyDiscoveryAPI: TopologyDiscoveryAPI;
topologyDiscoveryGraphQLAPI?: TopologyDiscoveryGraphQLAPI;
performanceMonitoringAPI: PerformanceMonitoringAPI;
inventoryKafka: typeof kafkaProducers | null;
Expand Down Expand Up @@ -44,7 +44,7 @@ export default async function createContext(context: ExpressContextFunctionArgum
prisma: prismaClient,
tenantId,
uniconfigAPI,
topologyDiscoveryAPI,
// topologyDiscoveryAPI,
topologyDiscoveryGraphQLAPI: getTopologyDiscoveryApi(),
performanceMonitoringAPI: getPerformanceMonitoringAPI(),
...(config.kafkaEnabled ? { kafka, inventoryKafka: kafkaProducers } : { kafka: null, inventoryKafka: null }),
Expand Down
109 changes: 54 additions & 55 deletions src/external-api/topology-discovery-graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type CoordinatesParam = {

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

Expand Down Expand Up @@ -70,8 +70,8 @@ const GET_TOPOLOGY_DEVICES = gql`
y
}
details {
sw_version
device_type
swVersion
deviceType
}
phyInterfaces {
edges {
Expand Down Expand Up @@ -115,8 +115,8 @@ const GET_NET_TOPOLOGY_DEVICES = gql`
name
status
details {
device_type
sw_version
deviceType
swVersion
}
labels
routerId
Expand Down Expand Up @@ -183,8 +183,8 @@ const GET_BACKUPS = gql`

const GET_TOPOLOGY_DIFF = gql`
query topologyDiff($new_db: String!, $old_db: String!, $collection_type: TopologyType!) {
topologyDiff(new_db: $new_db, old_db: $old_db, collection_type: $collection_type) {
diff_data
topologyDiff(newDb: $new_db, oldDb: $old_db, collectionType: $collection_type) {
diffData
}
}
`;
Expand All @@ -203,18 +203,18 @@ const GET_PTP_DIFF_SYNCE = gql`

const GET_COMMON_NODES = gql`
query getCommonNodes($selectedNodes: [String!]!) {
commonNodes(selected_nodes: $selectedNodes) {
common_nodes
commonNodes(selectedNodes: $selectedNodes) {
commonNodes
}
}
`;

const UPDATE_COORDINATES = gql`
mutation UpdateCoordinates($coordinates: [CoordinatesInput!]!, $topology_type: TopologyType) {
updateCoordinates(coordinates_list: $coordinates, topology_type: $topology_type) {
not_installed
updateCoordinates(coordinatesList: $coordinates, topologyType: $topology_type) {
notInstalled
installed {
not_updated
notUpdated
updated
}
}
Expand All @@ -230,18 +230,18 @@ const PTP_TOPOLOGY = gql`
y
}
details {
clock_type
clockType
domain
ptp_profile
clock_id
parent_clock_id
gm_clock_id
clock_class
clock_accuracy
clock_variance
time_recovery_status
global_priority
user_priority
ptpProfile
clockId
parentClockId
gmClockId
clockClass
clockAccuracy
clockVariance
timeRecoveryStatus
globalPriority
userPriority
}
status
labels
Expand All @@ -251,9 +251,9 @@ const PTP_TOPOLOGY = gql`
node {
...PtpInterfaceParts
details {
ptp_status
ptsf_unusable
admin_oper_status
ptpStatus
ptsfUnusable
adminOperStatus
}
}
}
Expand Down Expand Up @@ -332,7 +332,7 @@ const SYNCE_TOPOLOGY = gql`
y
}
details {
selected_for_use
selectedForUse
}
status
labels
Expand All @@ -342,11 +342,11 @@ const SYNCE_TOPOLOGY = gql`
node {
...SynceInterfaceParts
details {
synce_enabled
rx_quality_level
qualified_for_use
not_qualified_due_to
not_selected_due_to
synceEnabled
rxQualityLevel
qualifiedForUse
notQualifiedDueTo
notSelectedDueTo
}
}
}
Expand Down Expand Up @@ -460,22 +460,21 @@ const MPLS_TOPOLOGY = gql`
}
}
details {
router_id
mpls_data {
lsp_id
in_label
in_interface
out_interface
out_label
ldp_prefix
mpls_operation
oper_state
routerId
mplsData {
lspId
inLabel
inInterface
outInterface
outLabel
mplsOperation
operState
signalisation
}
lsp_tunnels {
lsp_id
from_device
to_device
lspTunnels {
lspId
fromDevice
toDevice
signalisation
uptime
}
Expand Down Expand Up @@ -542,10 +541,10 @@ const MPLS_TOPOLOGY = gql`

const MPLS_LSP_COUNT = gql`
query MplsLspCount($deviceId: ID!) {
mplsLspCount(device_id: $deviceId) {
to_device
incoming_lsps
outcoming_lsps
mplsLspCount(deviceId: $deviceId) {
toDevice
incomingLsps
outcomingLsps
}
}
`;
Expand All @@ -561,7 +560,7 @@ function getTopologyDiscoveryApi() {
const response = await client.request<GetShortestPathQuery, GetShortestPathQueryVariables>(GET_SHORTEST_PATH, {
deviceFrom: from,
deviceTo: to,
collection: 'NetInterface',
collection: 'NET_INTERFACE',
});

return response;
Expand Down Expand Up @@ -598,7 +597,7 @@ function getTopologyDiscoveryApi() {
// eslint-disable-next-line @typescript-eslint/naming-convention
collection_type: collectionType,
});
const json = decodeTopologyDiffOutput(response.topologyDiff.diff_data);
const json = decodeTopologyDiffOutput(response.topologyDiff.diffData);

return json;
}
Expand All @@ -608,15 +607,15 @@ function getTopologyDiscoveryApi() {
selectedNodes,
});

return response.commonNodes.common_nodes;
return response.commonNodes.commonNodes;
}

async function updateCoordinates(coordinates: CoordinatesParam[], topologyType?: TopologyType): Promise<string[]> {
const coordinatesInput: CoordinatesInput[] = coordinates.map((c) => ({
// eslint-disable-next-line @typescript-eslint/naming-convention
node_name: c.device,
nodeName: c.device,
// eslint-disable-next-line @typescript-eslint/naming-convention
node_type: 'device',
nodeType: 'DEVICE',
x: c.x,
y: c.y,
}));
Expand Down
110 changes: 0 additions & 110 deletions src/external-api/topology-discovery.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/external-api/topology-network-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const NetInterface = t.type({
ip_address: t.string,
});
export type NetInterface = t.TypeOf<typeof NetInterface>;
const StatusValidator = t.union([t.literal('ok'), t.literal('unknown')]);
const StatusValidator = t.union([t.literal('OK'), t.literal('UNKNOWN')]);
const InterfaceWithStatusValidator = t.intersection([
Interface,
t.type({
Expand Down
Loading

0 comments on commit c83a73a

Please sign in to comment.