Skip to content

Commit

Permalink
cluster fixes, would not update list on new cluster creation
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanWright committed Jun 21, 2016
1 parent a8197f0 commit efcdcae
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/pages/Preferences/Cluster/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const ClusterPrefs = React.createClass({

clusterHasSimulation(id) {
for (let i = 0; i < this.props.taskflows.length; i++) {
if (this.props.taskflows[i].flow && this.props.taskflows[i].flow.meta.cluster._id === id) {
if (this.props.taskflows[i].flow && get(this.props.taskflows[i].flow, 'meta.cluster._id') === id) {
return this.props.taskflows[i].simulation;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/redux/actions/clusters.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,17 +284,17 @@ export function testCluster(index, cluster) {
const action = netActions.addNetworkCall('test_cluster', 'Test cluster');
dispatch(pendingNetworkCall(true));
dispatch({ type: TESTING_CLUSTER, index });
return client.testCluster(cluster._id)
client.testCluster(cluster._id)
.then(
resp => {
dispatch(netActions.successNetworkCall(action.id, resp));
dispatch(pendingNetworkCall(false));
dispatch(fetchClusters());
},
error => {
dispatch(netActions.errorNetworkCall(action.id, error));
dispatch(pendingNetworkCall(false));
});
return action;
};
}

Expand Down
4 changes: 4 additions & 0 deletions src/redux/actions/taskflows.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ client.onEvent((resp) => {
break;
}
case 'cluster': {
if (status === 'created') {
// we need to fetch some new cluster props when this happens
dispatch(clusterActions.fetchCluster(id));
}
dispatch(clusterActions.updateClusterStatus(id, status));
break;
}
Expand Down
24 changes: 22 additions & 2 deletions src/redux/reducers/clusters.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,20 @@ export default function clustersReducer(state = initialState, action) {

case Actions.ADD_EXISTING_CLUSTER: {
const newCluster = action.cluster;
const list = [].concat(state.list);
const mapById = Object.assign({}, state.mapById);
mapById[newCluster._id] = newCluster;
return Object.assign({}, state, { mapById });
if (newCluster.type === 'trad' && list.some((el) => el._id === newCluster._id)) {
for (let i = 0; i < list.length; i++) {
if (list[i]._id === newCluster._id) {
list[i].status = newCluster.status;
break;
}
}
} else if (newCluster.type === 'trad') {
list.push(newCluster);
}
return Object.assign({}, state, { list, mapById });
}

case Actions.REMOVE_CLUSTER: {
Expand Down Expand Up @@ -159,11 +170,20 @@ export default function clustersReducer(state = initialState, action) {
}

case Actions.UPDATE_CLUSTER_STATUS: {
const list = [].concat(state.list);
const mapById = Object.assign({}, state.mapById);
const cluster = Object.assign({}, state.mapById[action.id]);
cluster.status = action.status;
mapById[action.id] = cluster;
return Object.assign({}, state, { mapById });
if (cluster.type === 'trad') {
for (let i = 0; i < list.length; i++) {
if (list[i]._id === action.id) {
list[i].status = action.status;
break;
}
}
}
return Object.assign({}, state, { list, mapById });
}

case Actions.CLUSTER_APPLY_PRESET: {
Expand Down
24 changes: 18 additions & 6 deletions test/redux/clusters.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ function setSpy(target, method, data) {
Object.freeze(initialState);

describe('cluster actions', () => {
const cluster = { _id: 'a1', name: 'myCluster',
const cluster = { _id: 'a1',
type: 'trad',
name: 'myCluster',
status: 'unknown',
log: [{ entry: 'created...' }, { entry: 'running...' }],
};
describe('simple actions', () => {
Expand All @@ -45,6 +48,7 @@ describe('cluster actions', () => {

const newState = deepClone(initialState);
newState.mapById[cluster._id] = cluster;
newState.list = [cluster];
expect(clustersReducer(initialState, expectedAction))
.toEqual(newState);
});
Expand Down Expand Up @@ -159,11 +163,19 @@ describe('cluster actions', () => {

// we only test the reducer here
it('should update a cluster\'s status', () => {
const thisState = Object.assign({}, initialState);
thisState.mapById = { a1: { status: 'created' } };
const action = { type: Actions.UPDATE_CLUSTER_STATUS, id: 'a1', status: 'terminated' };
expect(clustersReducer(thisState, action).mapById.a1.status)
.toEqual('terminated');
const newStatus = 'terminated';
const myCluster = deepClone(cluster);
const givenState = deepClone(initialState);
givenState.mapById[myCluster._id] = myCluster;
givenState.list.push(myCluster);

const expectedState = deepClone(givenState);
expectedState.mapById[myCluster._id].status = newStatus;
expectedState.list[0].status = newStatus;

const action = { type: Actions.UPDATE_CLUSTER_STATUS, id: cluster._id, status: newStatus };
expect(clustersReducer(givenState, action))
.toEqual(expectedState);
});
});

Expand Down

0 comments on commit efcdcae

Please sign in to comment.