From cf019112498759418bb55350edfd2023a1c20f26 Mon Sep 17 00:00:00 2001 From: jiahuay Date: Fri, 18 Jul 2014 15:05:19 -0700 Subject: [PATCH] Add deploy API in wizard Change-Id: Id16d714b72e790f0a6cad35db947fe58647541b2 --- v2/src/app/appDev.js | 22 ++++++++----- v2/src/app/wizard/wizard.js | 64 ++++++++++++++++++++++++------------- 2 files changed, 55 insertions(+), 31 deletions(-) diff --git a/v2/src/app/appDev.js b/v2/src/app/appDev.js index 5bd5f3b..0d6a4d0 100644 --- a/v2/src/app/appDev.js +++ b/v2/src/app/appDev.js @@ -440,16 +440,22 @@ compassAppDev.run(function($httpBackend, settings, $http) { }); */ - $httpBackend.whenPOST(/\.*\/clusters\/[1-9][0-9]*\/action/).respond(function(method, url, data) { + $httpBackend.whenPOST(/\.*\/clusters\/([0-9]|[1-9][0-9])\/action/).respond(function(method, url, data) { console.log(method, url, data); - var machines = JSON.parse(data)["add_hosts"]["machines"]; - angular.forEach(machines, function(machine) { - machine.id = Math.floor((Math.random() * 500) + 1); - }) - var actionResponse = { - "hosts": machines - }; + var postData = JSON.parse(data); + var actionResponse = {}; + + if (postData["add_hosts"] !== undefined) { + var machines = postData["add_hosts"]["machines"]; + angular.forEach(machines, function(machine) { + machine.id = Math.floor((Math.random() * 500) + 1); + }) + actionResponse = { + "hosts": machines + }; + } else if (postData["deploy"] !== undefined) {} return [200, actionResponse, {}]; + }); $httpBackend.whenPUT(/\.*\/hosts\/[1-9][0-9]*/).respond(function(method, url, data) { diff --git a/v2/src/app/wizard/wizard.js b/v2/src/app/wizard/wizard.js index 6e485e8..ef8d899 100644 --- a/v2/src/app/wizard/wizard.js +++ b/v2/src/app/wizard/wizard.js @@ -61,29 +61,12 @@ angular.module('compass.wizard', [ $scope.$watch(function() { return wizardFactory.getCommitState() }, function(newCommitState, oldCommitState) { - switch (newCommitState.name) { - case "sv_selection": - case "os_global": - case "network": - case "partition": - case "security": - case "role_assign": - case "network_mapping": - if (newCommitState.name == $scope.steps[$scope.currentStep - 1].name && newCommitState.state == "success") { - console.warn("### catch success in wizardCtrl ###", newCommitState, oldCommitState); - $scope.next(); - } else if (newCommitState.state == "error") { - // TODO: error handling / display error message - console.warn("### catch error in wizardCtrl ###", newCommitState, oldCommitState); - } - break; - case "review": - $state.go("cluster.overview", { - 'id': $scope.cluster.id - }); - break; - default: - break; + if (newCommitState.name == $scope.steps[$scope.currentStep - 1].name && newCommitState.state == "success") { + console.warn("### catch success in wizardCtrl ###", newCommitState, oldCommitState); + $scope.next(); + } else if (newCommitState.state == "error") { + // TODO: error handling / display error message + console.warn("### catch error in wizardCtrl ###", newCommitState, oldCommitState); } }) }; @@ -91,6 +74,11 @@ angular.module('compass.wizard', [ $scope.next = function() { if ($scope.currentStep < $scope.steps.length) $scope.currentStep = $scope.currentStep + 1; + else if ($scope.currentStep == $scope.steps.length) { + $state.go("cluster.overview", { + 'id': $scope.cluster.id + }); + } } // go to previous step @@ -972,4 +960,34 @@ angular.module('compass.wizard', [ } }); + $scope.$watch(function() { + return wizardFactory.getCommitState() + }, function(newCommitState, oldCommitState) { + if (newCommitState !== undefined) { + if (newCommitState.name == "review" && newCommitState.state == "triggered") { + $scope.commit(); + } + } + }); + + $scope.commit = function() { + var deployAction = { + "deploy": { + "hosts": [] + } + }; + angular.forEach($scope.servers, function(server) { + deployAction.deploy.hosts.push(server.host_id); + }); + + dataService.postClusterActions(cluster.id, deployAction).success(function(data) { + var commitState = { + "name": "review", + "state": "success", + "message": "" + }; + wizardFactory.setCommitState(commitState); + }) + //TODO: error handling + }; })