Extract Mistral action and workflow names into constants

Change-Id: I03e2f10282e3d958727b1a5830d1f8664fb79124
This commit is contained in:
Ana Krivokapic 2016-09-07 13:21:09 +02:00
parent 092fd11f57
commit fee99f5966
15 changed files with 84 additions and 52 deletions

View File

@ -6,6 +6,7 @@ import NodesActions from '../../js/actions/NodesActions';
import NotificationActions from '../../js/actions/NotificationActions';
import NodesConstants from '../../js/constants/NodesConstants';
import * as utils from '../../js/services/utils';
import MistralConstants from '../../js/constants/MistralConstants';
const mockGetNodesResponse = [
{ uuid: 1 },
@ -153,8 +154,8 @@ describe('Asynchronous Introspect Nodes Action', () => {
it('dispatches startOperation', () => {
const nodeIds = ['598612eb-f21b-435e-a868-7bb74e576cc2'];
expect(MistralApiService.runWorkflow).toHaveBeenCalledWith('tripleo.baremetal.v1.introspect',
{ node_uuids: nodeIds });
expect(MistralApiService.runWorkflow).toHaveBeenCalledWith(
MistralConstants.BAREMETAL_INTROSPECT, { node_uuids: nodeIds });
expect(NodesActions.startOperation).toHaveBeenCalledWith(nodeIds);
});
});
@ -228,7 +229,7 @@ describe('startProvideNodes Action', () => {
});
it('dispatches startOperation', () => {
expect(MistralApiService.runWorkflow).toHaveBeenCalledWith('tripleo.baremetal.v1.provide',
expect(MistralApiService.runWorkflow).toHaveBeenCalledWith(MistralConstants.BAREMETAL_PROVIDE,
{ node_uuids: nodeIds });
expect(NodesActions.startOperation).toHaveBeenCalledWith(nodeIds);
});

View File

@ -4,6 +4,7 @@ import * as utils from '../../js/services/utils';
import ParametersActions from '../../js/actions/ParametersActions';
import ParametersConstants from '../../js/constants/ParametersConstants';
import MistralApiService from '../../js/services/MistralApiService';
import MistralConstants from '../../js/constants/MistralConstants';
// Use this to mock asynchronous functions which return a promise.
@ -67,7 +68,7 @@ describe('ParametersActions', () => {
});
it('calls the Mistral API', () => {
expect(MistralApiService.runAction).toHaveBeenCalledWith('tripleo.parameters.get',
expect(MistralApiService.runAction).toHaveBeenCalledWith(MistralConstants.PARAMETERS_GET,
{ container: 'overcloud' });
});
@ -107,7 +108,7 @@ describe('ParametersActions', () => {
it('calls the Mistral API', () => {
expect(MistralApiService.runAction).toHaveBeenCalledWith(
'tripleo.parameters.update',
MistralConstants.PARAMETERS_UPDATE,
{
container: 'overcloud',
parameters: { foo: 'bar' }

View File

@ -7,6 +7,7 @@ import ValidationsConstants from '../../js/constants/ValidationsConstants';
import WorkflowExecutionsActions from '../../js/actions/WorkflowExecutionsActions';
import { WorkflowExecution } from '../../js/immutableRecords/workflowExecutions';
import * as utils from '../../js/services/utils';
import MistralConstants from '../../js/constants/MistralConstants';
let createResolvingPromise = (data) => {
return () => {
@ -74,7 +75,7 @@ describe('FetchValidations action', () => {
it('dispatches appropriate actions and normalizes the response', () => {
expect(ValidationsActions.fetchValidationsPending).toHaveBeenCalled();
expect(MistralApiService.runAction)
.toHaveBeenCalledWith('tripleo.validations.list_validations');
.toHaveBeenCalledWith(MistralConstants.VALIDATIONS_LIST);
expect(ValidationsActions.fetchValidationsSuccess).toHaveBeenCalled();
});
});
@ -90,7 +91,7 @@ describe('RunValidation action', () => {
created_at: '2016-07-19 13:22:29.588140',
description: '',
state: 'RUNNING',
workflow_name: 'tripleo.validations.v1.run_validation',
workflow_name: MistralConstants.VALIDATIONS_RUN,
task_execution_id: null,
updated_at: '2016-07-19 13:22:29.592989',
workflow_id: 'f8b280bb-5ba2-486b-9384-ddd79300d987',
@ -111,7 +112,7 @@ describe('RunValidation action', () => {
it('dispatches appropriate actions', () => {
expect(MistralApiService.runWorkflow)
.toHaveBeenCalledWith('tripleo.validations.v1.run_validation',
.toHaveBeenCalledWith(MistralConstants.VALIDATIONS_RUN,
{ validation_name: '512e',
plan: 'overcloud' });
});
@ -157,7 +158,7 @@ xdescribe('runValidationMessage action', () => {
state: 'RUNNING',
state_info: undefined,
updated_at: undefined,
workflow_name: 'tripleo.validations.v1.run_validation'
workflow_name: MistralConstants.VALIDATIONS_RUN
});
ValidationsActions.runValidationMessage(messagePayload)(() => {}, () => {});

View File

@ -4,6 +4,7 @@ import { Map, OrderedMap } from 'immutable';
import { WorkflowExecution } from '../../js/immutableRecords/workflowExecutions';
import WorkflowExecutionsConstants from '../../js/constants/WorkflowExecutionsConstants';
import workflowExecutionsReducer from '../../js/reducers/workflowExecutionsReducer';
import MistralConstants from '../../js/constants/MistralConstants';
describe('workflowExecutionsReducer', () => {
beforeEach(() => {
@ -36,7 +37,7 @@ describe('workflowExecutionsReducer', () => {
task_execution_id: null,
updated_at: NaN,
workflow_id: 'f8b280bb-5ba2-486b-9384-ddd79300d987',
workflow_name: 'tripleo.validations.v1.run_validation'
workflow_name: MistralConstants.VALIDATIONS_RUN
})
})
});
@ -70,7 +71,7 @@ describe('workflowExecutionsReducer', () => {
task_execution_id: null,
updated_at: '2016-07-18 14:05:08',
workflow_id: 'f8b280bb-5ba2-486b-9384-ddd79300d987',
workflow_name: 'tripleo.validations.v1.run_validation'
workflow_name: MistralConstants.VALIDATIONS_RUN
}
}
};
@ -103,7 +104,7 @@ describe('workflowExecutionsReducer', () => {
task_execution_id: null,
updated_at: '2016-07-18 14:05:08',
workflow_id: 'f8b280bb-5ba2-486b-9384-ddd79300d987',
workflow_name: 'tripleo.validations.v1.run_validation'
workflow_name: MistralConstants.VALIDATIONS_RUN
}
};
const newState = workflowExecutionsReducer(initialState, action);
@ -129,7 +130,7 @@ describe('workflowExecutionsReducer', () => {
task_execution_id: null,
updated_at: NaN,
workflow_id: 'f8b280bb-5ba2-486b-9384-ddd79300d987',
workflow_name: 'tripleo.validations.v1.run_validation'
workflow_name: MistralConstants.VALIDATIONS_RUN
})
};
const newState = workflowExecutionsReducer(initialState, action);

View File

@ -5,6 +5,7 @@ import * as selectors from '../../js/selectors/validations';
import { Validation } from '../../js/immutableRecords/validations';
import { CurrentPlanState } from '../../js/immutableRecords/currentPlan';
import { WorkflowExecution } from '../../js/immutableRecords/workflowExecutions';
import MistralConstants from '../../js/constants/MistralConstants';
describe(' validations selectors', () => {
beforeEach(() => {
@ -66,7 +67,7 @@ describe(' validations selectors', () => {
state: 'SUCCESS',
state_info: null,
updated_at: 1468905005000,
workflow_name: 'tripleo.validations.v1.run_validation'
workflow_name: MistralConstants.VALIDATIONS_RUN
}),
'2a': new WorkflowExecution({
description: '',
@ -88,7 +89,7 @@ describe(' validations selectors', () => {
state: 'SUCCESS',
state_info: null,
updated_at: 1468905005001,
workflow_name: 'tripleo.validations.v1.run_validation'
workflow_name: MistralConstants.VALIDATIONS_RUN
})
})
})

View File

@ -6,13 +6,14 @@ import MistralApiService from '../services/MistralApiService';
import NotificationActions from '../actions/NotificationActions';
import MistralApiErrorHandler from '../services/MistralApiErrorHandler';
import { topicSchema } from '../normalizrSchemas/environmentConfiguration';
import MistralConstants from '../constants/MistralConstants';
export default {
fetchEnvironmentConfiguration(planName, redirectPath) {
return dispatch => {
dispatch(this.fetchEnvironmentConfigurationPending());
MistralApiService.runAction('tripleo.heat_capabilities.get', { container: planName })
MistralApiService.runAction(MistralConstants.CAPABILITIES_GET, { container: planName })
.then(response => {
const entities = normalize(JSON.parse(response.output).result,
arrayOf(topicSchema)).entities || {};
@ -52,7 +53,7 @@ export default {
updateEnvironmentConfiguration(planName, data, formFields, redirectPath) {
return dispatch => {
dispatch(this.updateEnvironmentConfigurationPending());
MistralApiService.runAction('tripleo.heat_capabilities.update',
MistralApiService.runAction(MistralConstants.CAPABILITIES_UPDATE,
{ environments: data, container: planName })
.then(response => {
const enabledEnvs = JSON.parse(response.output).result.environments.map(env => env.path);

View File

@ -10,6 +10,7 @@ import MistralApiErrorHandler from '../services/MistralApiErrorHandler';
import NodesConstants from '../constants/NodesConstants';
import NotificationActions from './NotificationActions';
import { nodeSchema } from '../normalizrSchemas/nodes';
import MistralConstants from '../constants/MistralConstants';
export default {
startOperation(nodeIds) {
@ -101,7 +102,7 @@ export default {
startNodesIntrospection(nodeIds) {
return (dispatch, getState) => {
dispatch(this.startOperation(nodeIds));
MistralApiService.runWorkflow('tripleo.baremetal.v1.introspect',
MistralApiService.runWorkflow(MistralConstants.BAREMETAL_INTROSPECT,
{ node_uuids: nodeIds })
.then((response) => {
if(response.state === 'ERROR') {
@ -154,7 +155,7 @@ export default {
startProvideNodes(nodeIds) {
return (dispatch, getState) => {
dispatch(this.startOperation(nodeIds));
MistralApiService.runWorkflow('tripleo.baremetal.v1.provide',
MistralApiService.runWorkflow(MistralConstants.BAREMETAL_PROVIDE,
{ node_uuids: nodeIds })
.then((response) => {
if(response.state === 'ERROR') {

View File

@ -4,6 +4,7 @@ import NotificationActions from '../actions/NotificationActions';
import ParametersConstants from '../constants/ParametersConstants';
import MistralApiService from '../services/MistralApiService';
import MistralApiErrorHandler from '../services/MistralApiErrorHandler';
import MistralConstants from '../constants/MistralConstants';
export default {
fetchParametersPending() {
@ -28,7 +29,7 @@ export default {
fetchParameters(planName, parentPath) {
return dispatch => {
dispatch(this.fetchParametersPending());
MistralApiService.runAction('tripleo.parameters.get', { container: planName })
MistralApiService.runAction(MistralConstants.PARAMETERS_GET, { container: planName })
.then(response => {
const resourceTree = JSON.parse(response.output).result.heat_resource_tree;
const mistralParameters = JSON.parse(response.output).result.mistral_environment_parameters;
@ -71,7 +72,7 @@ export default {
updateParameters(planName, data, inputFieldNames, url) {
return dispatch => {
dispatch(this.updateParametersPending());
MistralApiService.runAction('tripleo.parameters.update',
MistralApiService.runAction(MistralConstants.PARAMETERS_UPDATE,
{ container: planName, parameters: data })
.then(response => {
dispatch(this.updateParametersSuccess());

View File

@ -12,6 +12,7 @@ import { planFileSchema } from '../normalizrSchemas/plans';
import StackActions from '../actions/StacksActions';
import SwiftApiErrorHandler from '../services/SwiftApiErrorHandler';
import SwiftApiService from '../services/SwiftApiService';
import MistralConstants from '../constants/MistralConstants';
export default {
requestPlans() {
@ -30,7 +31,7 @@ export default {
fetchPlans() {
return dispatch => {
dispatch(this.requestPlans());
MistralApiService.runAction('tripleo.plan.list').then((response) => {
MistralApiService.runAction(MistralConstants.PLAN_LIST).then((response) => {
let plans = JSON.parse(response.output).result || [];
dispatch(this.receivePlans(plans));
dispatch(CurrentPlanActions.detectPlan(plans));
@ -202,7 +203,7 @@ export default {
// Once all files are uploaded, start plan creation workflow.
MistralApiService.runWorkflow(
'tripleo.plan_management.v1.create_deployment_plan',
MistralConstants.PLAN_CREATE,
{ container: planName }
).then((response) => {
if(response.state === 'ERROR') {
@ -269,7 +270,7 @@ export default {
dispatch(this.createPlanPending());
SwiftApiService.uploadTarball(planName, file).then((response) => {
MistralApiService.runWorkflow(
'tripleo.plan_management.v1.create_deployment_plan',
MistralConstants.PLAN_CREATE,
{ container: planName }
).then((response) => {
if(response.state === 'ERROR') {
@ -346,21 +347,22 @@ export default {
return dispatch => {
dispatch(this.deletePlanPending(planName));
browserHistory.push('/plans/list');
MistralApiService.runAction('tripleo.plan.delete', { container: planName }).then(response => {
dispatch(this.deletePlanSuccess(planName));
dispatch(NotificationActions.notify({
title: 'Plan Deleted',
message: `The plan ${planName} was successfully deleted.`,
type: 'success'
}));
}).catch(error => {
console.error('Error deleting plan MistralApiService.runAction', error); //eslint-disable-line no-console
dispatch(this.planDeleted(planName));
let errorHandler = new MistralApiErrorHandler(error);
errorHandler.errors.forEach((error) => {
dispatch(NotificationActions.notify(error));
MistralApiService.runAction(MistralConstants.PLAN_DELETE, { container: planName })
.then(response => {
dispatch(this.deletePlanSuccess(planName));
dispatch(NotificationActions.notify({
title: 'Plan Deleted',
message: `The plan ${planName} was successfully deleted.`,
type: 'success'
}));
}).catch(error => {
console.error('Error deleting plan MistralApiService.runAction', error); //eslint-disable-line no-console
dispatch(this.planDeleted(planName));
let errorHandler = new MistralApiErrorHandler(error);
errorHandler.errors.forEach((error) => {
dispatch(NotificationActions.notify(error));
});
});
});
};
},
@ -406,7 +408,7 @@ export default {
return dispatch => {
dispatch(this.deployPlanPending(planName));
MistralApiService.runWorkflow(
'tripleo.deployment.v1.deploy_plan',
MistralConstants.DEPLOYMENT_DEPLOY_PLAN,
{ container: planName, timeout: 240
}).then((response) => {
dispatch(StackActions.fetchStacks());

View File

@ -9,6 +9,7 @@ import NotificationActions from './NotificationActions';
import NodesActions from './NodesActions';
import { nodeSchema } from '../normalizrSchemas/nodes';
import ValidationsActions from './ValidationsActions';
import MistralConstants from '../constants/MistralConstants';
export default {
addNode(node) {
@ -42,7 +43,7 @@ export default {
startNodesRegistration(nodes, redirectPath) {
return (dispatch, getState) => {
dispatch(this.startNodesRegistrationPending(nodes));
MistralApiService.runWorkflow('tripleo.baremetal.v1.register_or_update',
MistralApiService.runWorkflow(MistralConstants.BAREMETAL_REGISTER_OR_UPDATE,
{ nodes_json: nodes.toList().toJS() })
.then((response) => {
if(response.state === 'ERROR') {

View File

@ -2,13 +2,14 @@ import NotificationActions from './NotificationActions';
import RolesConstants from '../constants/RolesConstants';
import MistralApiService from '../services/MistralApiService';
import MistralApiErrorHandler from '../services/MistralApiErrorHandler';
import MistralConstants from '../constants/MistralConstants';
export default {
fetchRoles(planName) {
return (dispatch, getState) => {
dispatch(this.fetchRolesPending());
MistralApiService.runAction('tripleo.role.list', { container: planName })
MistralApiService.runAction(MistralConstants.ROLE_LIST, { container: planName })
.then((response) => {
dispatch(this.fetchRolesSuccess(JSON.parse(response.output).result));
}).catch((error) => {

View File

@ -8,12 +8,13 @@ import MistralApiErrorHandler from '../services/MistralApiErrorHandler';
import ValidationsConstants from '../constants/ValidationsConstants';
import { validationSchema } from '../normalizrSchemas/validations';
import { WorkflowExecution } from '../immutableRecords/workflowExecutions';
import MistralConstants from '../constants/MistralConstants';
export default {
fetchValidations() {
return (dispatch, getState) => {
dispatch(this.fetchValidationsPending());
MistralApiService.runAction('tripleo.validations.list_validations').then((response) => {
MistralApiService.runAction(MistralConstants.VALIDATIONS_LIST).then((response) => {
const actionResult = JSON.parse(response.output).result;
const validations = normalize(actionResult,
arrayOf(validationSchema)).entities.validations || {};
@ -50,7 +51,7 @@ export default {
runValidation(id, currentPlanName) {
return (dispatch, getState) => {
MistralApiService.runWorkflow('tripleo.validations.v1.run_validation',
MistralApiService.runWorkflow(MistralConstants.VALIDATIONS_RUN,
{ validation_name: id,
plan: currentPlanName })
.then((response) => {
@ -73,7 +74,7 @@ export default {
runValidationMessage(messagePayload) {
return (dispatch, getState) => {
const execution = new WorkflowExecution(fromJS(messagePayload.execution))
.set('workflow_name', 'tripleo.validations.v1.run_validation')
.set('workflow_name', MistralConstants.VALIDATIONS_RUN)
.set('state', messagePayload.status)
.set('output', fromJS({...messagePayload}).delete('execution'));
dispatch(WorkflowExecutionsActions.addWorkflowExecutionFromMessage(execution));
@ -82,7 +83,7 @@ export default {
runValidationGroups(groups, currentPlanName) {
return (dispatch, getState) => {
MistralApiService.runWorkflow('tripleo.validations.v1.run_groups',
MistralApiService.runWorkflow(MistralConstants.VALIDATIONS_RUN_GROUPS,
{ group_names: groups,
plan: currentPlanName })
.then((response) => {

View File

@ -2,35 +2,36 @@ import NodesActions from './NodesActions';
import PlansActions from './PlansActions';
import RegisterNodesActions from './RegisterNodesActions';
import ValidationsActions from './ValidationsActions';
import MistralConstants from '../constants/MistralConstants';
export default {
messageReceived(message) {
return (dispatch, getState) => {
const { type, payload } = message.body;
switch (type) {
case ('tripleo.baremetal.v1.register_or_update'):
case (MistralConstants.BAREMETAL_REGISTER_OR_UPDATE):
dispatch(RegisterNodesActions.nodesRegistrationFinished(payload));
break;
case ('tripleo.baremetal.v1.introspect'):
case (MistralConstants.BAREMETAL_INTROSPECT):
dispatch(NodesActions.nodesIntrospectionFinished(payload));
break;
case ('tripleo.baremetal.v1.provide'):
case (MistralConstants.BAREMETAL_PROVIDE):
dispatch(NodesActions.provideNodesFinished(payload));
break;
case ('tripleo.validations.v1.run_validation'): {
case (MistralConstants.VALIDATIONS_RUN): {
dispatch(ValidationsActions.runValidationMessage(payload));
break;
}
case ('tripleo.plan_management.v1.create_deployment_plan'): {
case (MistralConstants.PLAN_CREATE): {
dispatch(PlansActions.createPlanFinished(payload));
break;
}
case ('tripleo.deployment.v1.deploy_plan'): {
case (MistralConstants.DEPLOYMENT_DEPLOY_PLAN): {
dispatch(PlansActions.deployPlanFinished(payload));
break;
}

View File

@ -0,0 +1,17 @@
export default {
BAREMETAL_INTROSPECT: 'tripleo.baremetal.v1.introspect',
BAREMETAL_PROVIDE: 'tripleo.baremetal.v1.provide',
BAREMETAL_REGISTER_OR_UPDATE: 'tripleo.baremetal.v1.register_or_update',
CAPABILITIES_GET: 'tripleo.heat_capabilities.get',
CAPABILITIES_UPDATE: 'tripleo.heat_capabilities.update',
DEPLOYMENT_DEPLOY_PLAN: 'tripleo.deployment.v1.deploy_plan',
PARAMETERS_GET: 'tripleo.parameters.get',
PARAMETERS_UPDATE: 'tripleo.parameters.update',
PLAN_CREATE: 'tripleo.plan_management.v1.create_deployment_plan',
PLAN_DELETE: 'tripleo.plan.delete',
PLAN_LIST: 'tripleo.plan.list',
ROLE_LIST: 'tripleo.role.list',
VALIDATIONS_LIST: 'tripleo.validations.list_validations',
VALIDATIONS_RUN: 'tripleo.validations.v1.run_validation',
VALIDATIONS_RUN_GROUPS: 'tripleo.validations.v1.run_groups'
};

View File

@ -1,6 +1,7 @@
import { createSelector } from 'reselect';
import { currentPlanNameSelector } from './plans';
import MistralConstants from '../constants/MistralConstants';
const validations = (state) => state.validations.get('validations');
const executions = (state) => state.executions.get('executions');
@ -11,7 +12,7 @@ const executions = (state) => state.executions.get('executions');
export const getValidationExecutionsForCurrentPlan = createSelector(
[executions, currentPlanNameSelector], (executions, currentPlanName) => {
return executions.filter(execution =>
execution.get('workflow_name') === 'tripleo.validations.v1.run_validation' &&
execution.get('workflow_name') === MistralConstants.VALIDATIONS_RUN &&
execution.getIn(['input', 'plan']) === currentPlanName);
}
);