Add deploy API in wizard

Change-Id: Id16d714b72e790f0a6cad35db947fe58647541b2
This commit is contained in:
jiahuay 2014-07-18 15:05:19 -07:00
parent be3cb8ac8c
commit cf01911249
2 changed files with 55 additions and 31 deletions

View File

@ -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) {

View File

@ -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
};
})