Skip to content

Commit

Permalink
Not getting all nodes in the resource view.
Browse files Browse the repository at this point in the history
  • Loading branch information
fbarl committed Mar 15, 2017
1 parent a173fa7 commit b31443a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 19 deletions.
28 changes: 19 additions & 9 deletions client/app/scripts/actions/app-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import {
doControlRequest,
getAllNodes,
getResourceViewNodesSnapshot,
getNodesDelta,
getNodeDetails,
getTopologies,
Expand All @@ -23,8 +24,15 @@ import {
import { getCurrentTopologyUrl } from '../utils/topology-utils';
import { storageSet } from '../utils/storage-utils';
import { loadTheme } from '../utils/contrast-utils';
import { activeTopologyOptionsSelector } from '../selectors/topology';
import { RESOURCE_VIEW_MODE, GRAPH_VIEW_MODE, TABLE_VIEW_MODE } from '../constants/naming';
import {
activeTopologyOptionsSelector,
isResourceViewModeSelector,
} from '../selectors/topology';
import {
GRAPH_VIEW_MODE,
TABLE_VIEW_MODE,
RESOURCE_VIEW_MODE,
} from '../constants/naming';

const log = debug('scope:app-actions');

Expand Down Expand Up @@ -282,9 +290,8 @@ export function setResourceView() {
viewMode: RESOURCE_VIEW_MODE,
});
updateRoute(getState);
setTimeout(() => {
getAllNodes(getState, dispatch);
}, 1200);
// Update the nodes for all topologies that appear in the current resource view.
getResourceViewNodesSnapshot(getState, dispatch);
};
}

Expand Down Expand Up @@ -721,10 +728,13 @@ export function route(urlState) {
state.get('nodeDetails'),
dispatch
);
// TODO: Remove this
setTimeout(() => {
getAllNodes(getState, dispatch);
}, 1200);
// If we are landing on the resource view page, we need to fetch not only all the
// nodes for the current topology, but also the nodes of all the topologies that make
// the layers in the resource view.
if (isResourceViewModeSelector(state)) {
// Get all the nodes for the current resource view layout in the next run-cycle.
setTimeout(() => { getResourceViewNodesSnapshot(getState, dispatch); }, 0);
}
};
}

Expand Down
16 changes: 13 additions & 3 deletions client/app/scripts/reducers/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { fromJS, is as isDeepEqual, List as makeList, Map as makeMap,
OrderedMap as makeOrderedMap, Set as makeSet } from 'immutable';

import ActionTypes from '../constants/action-types';
import { EDGE_ID_SEPARATOR, GRAPH_VIEW_MODE, TABLE_VIEW_MODE } from '../constants/naming';
import {
EDGE_ID_SEPARATOR,
GRAPH_VIEW_MODE,
TABLE_VIEW_MODE,
RESOURCE_VIEW_MODE,
} from '../constants/naming';
import {
graphExceedsComplexityThreshSelector,
activeTopologyZoomCacheKeyPathSelector,
Expand Down Expand Up @@ -53,7 +58,7 @@ export const initialState = makeMap({
nodeDetails: makeOrderedMap(), // nodeId -> details
nodes: makeOrderedMap(), // nodeId -> node
nodesLoaded: false,
// nodes cache, infrequently updated, used for search
// nodes cache, infrequently updated, used for search & resource view
nodesByTopology: makeMap(), // topologyId -> nodes
pinnedMetric: null,
// class of metric, e.g. 'cpu', rather than 'host_cpu' or 'process_cpu'.
Expand Down Expand Up @@ -618,7 +623,12 @@ export function rootReducer(state = initialState, action) {
}

// update nodes cache
return state.setIn(['nodesByTopology', state.get('currentTopologyId')], state.get('nodes'));
if (state.get('topologyViewMode') !== RESOURCE_VIEW_MODE) {
state = state.setIn(
['nodesByTopology', state.get('currentTopologyId')], state.get('nodes'));
}

return state;
}

case ActionTypes.RECEIVE_NODES_FOR_TOPOLOGY: {
Expand Down
30 changes: 23 additions & 7 deletions client/app/scripts/utils/web-api-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import debug from 'debug';
import reqwest from 'reqwest';
import trimStart from 'lodash/trimStart';
import defaults from 'lodash/defaults';
import { Map as makeMap } from 'immutable';

import { blurSearch, clearControlError, closeWebsocket, openWebsocket, receiveError,
receiveApiDetails, receiveNodesDelta, receiveNodeDetails, receiveControlError,
receiveControlNodeRemoved, receiveControlPipe, receiveControlPipeStatus,
receiveControlSuccess, receiveTopologies, receiveNotFound,
receiveNodesForTopology } from '../actions/app-actions';

import { layersTopologyIdsSelector } from '../selectors/resource-view/layers';
import { API_INTERVAL, TOPOLOGY_INTERVAL } from '../constants/timer';

const log = debug('scope:web-api-utils');
Expand Down Expand Up @@ -153,14 +155,10 @@ function doRequest(opts) {
return reqwest(config);
}

/**
* Gets nodes for all topologies (for search)
*/
export function getAllNodes(getState, dispatch) {
const state = getState();
const topologyOptions = state.get('topologyOptions');
function getNodesForTopologies(getState, dispatch, topologyIds, topologyOptions = makeMap()) {
// fetch sequentially
state.get('topologyUrlsById')
getState().get('topologyUrlsById')
.filter((_, topologyId) => topologyIds.contains(topologyId))
.reduce((sequence, topologyUrl, topologyId) => sequence.then(() => {
const optionsQuery = buildOptionsQuery(topologyOptions.get(topologyId));
// Trim the leading slash from the url before requesting.
Expand All @@ -172,6 +170,24 @@ export function getAllNodes(getState, dispatch) {
Promise.resolve());
}

/**
* Gets nodes for all topologies (for search)
*/
export function getAllNodes(getState, dispatch) {
const state = getState();
const topologyIds = state.get('topologies').map(topology => topology.get('id'));
const topologyOptions = state.get('topologyOptions');
getNodesForTopologies(getState, dispatch, topologyIds, topologyOptions);
}

// NOTE: At the moment we are only getting their one-time snapshot (instead of polling),
// because we intentionally want to keep the resource view layout static. Later on, we
// will probably want to change this.
export function getResourceViewNodesSnapshot(getState, dispatch) {
const topologyIds = layersTopologyIdsSelector(getState());
getNodesForTopologies(getState, dispatch, topologyIds);
}

export function getTopologies(options, dispatch) {
clearTimeout(topologyTimer);
const optionsQuery = buildOptionsQuery(options);
Expand Down

0 comments on commit b31443a

Please sign in to comment.