Merge "Supporting user config task parameters in GUI"
authorJack Chan <chenjiankun1@huawei.com>
Fri, 16 Mar 2018 09:01:07 +0000 (09:01 +0000)
committerGerrit Code Review <gerrit@opnfv.org>
Fri, 16 Mar 2018 09:01:07 +0000 (09:01 +0000)
api/database/v2/models.py
api/resources/v2/tasks.py
gui/app/scripts/controllers/projectDetail.controller.js
gui/app/scripts/controllers/taskModify.controller.js
gui/app/scripts/factory/main.factory.js
gui/app/views/modal/taskCreate.html
gui/app/views/taskmodify.html

index 59dab3e..0ee8116 100644 (file)
@@ -92,6 +92,7 @@ class V2Task(Base):
     case_name = Column(String(30))
     suite = Column(Boolean)
     content = Column(Text)
+    params = Column(Text)
     result = Column(Text)
     error = Column(Text)
     status = Column(Integer)
index 25a9cf1..17241ed 100644 (file)
@@ -38,6 +38,8 @@ class V2Tasks(ApiResource):
         for t in tasks:
             result = t['result']
             t['result'] = jsonutils.loads(result) if result else None
+            params = t['params']
+            t['params'] = jsonutils.loads(params) if params else None
 
         return result_handler(consts.API_SUCCESS, {'tasks': tasks})
 
@@ -94,6 +96,9 @@ class V2Task(ApiResource):
         result = task_info['result']
         task_info['result'] = jsonutils.loads(result) if result else None
 
+        params = task_info['params']
+        task_info['params'] = jsonutils.loads(params) if params else None
+
         return result_handler(consts.API_SUCCESS, {'task': task_info})
 
     def delete(self, task_id):
@@ -127,7 +132,6 @@ class V2Task(ApiResource):
         return result_handler(consts.API_SUCCESS, {'task': task_id})
 
     def put(self, task_id):
-
         try:
             uuid.UUID(task_id)
         except ValueError:
@@ -166,6 +170,21 @@ class V2Task(ApiResource):
 
         return result_handler(consts.API_SUCCESS, {'uuid': task_id})
 
+    def add_params(self, args):
+        task_id = args['task_id']
+        try:
+            params = args['params']
+        except KeyError:
+            return result_handler(consts.API_ERROR, 'params must be provided')
+
+        LOG.info('update params info in task')
+
+        task_handler = V2TaskHandler()
+        task_update_data = {'params': jsonutils.dumps(params)}
+        task_handler.update_attr(task_id, task_update_data)
+
+        return result_handler(consts.API_SUCCESS, {'uuid': task_id})
+
     def add_case(self, args):
         task_id = args['task_id']
         try:
@@ -243,7 +262,8 @@ class V2Task(ApiResource):
 
         data = {
             'inputfile': ['/tmp/{}.yaml'.format(task.case_name)],
-            'task_id': task_id
+            'task_id': task_id,
+            'task-args': task.params
         }
         if task.suite:
             data.update({'suite': True})
index e846804..353e02b 100644 (file)
@@ -439,15 +439,36 @@ angular.module('yardStickGui2App')
 
                         $scope.displayTable = false;
                         $scope.contentInfo = response.result.testcase;
+                        $scope.optionalParams = response.result.args;
 
                     }
                 }, function(error) {
-                    toaster.pop({
-                        type: 'error',
-                        title: 'fail',
-                        body: 'unknow error',
-                        timeout: 3000
-                    });
+                    mainFactory.errorHandler2(error);
+                })
+            }
+
+
+            function addParamsToTask(){
+                var params = {}
+                angular.forEach($scope.optionalParams, function(value, name){
+                    if(value.value){
+                        params[name] = value.value;
+                    }
+                });
+
+                mainFactory.taskAddParams().put({
+                    'taskId': $scope.newUUID,
+                    'action': 'add_params',
+                    'args': {
+                        'params': params
+                    }
+                }).$promise.then(function(resp) {
+                    if (resp.status == 1) {
+                    } else {
+                        mainFactory.errorHandler1(resp);
+                    }
+                }, function(error) {
+                    mainFactory.errorHandler2(error);
                 })
             }
 
@@ -530,6 +551,7 @@ angular.module('yardStickGui2App')
             function confirmAddCaseOrSuite(content) {
                 if ($scope.selectType.name == "Test Case") {
                     addCasetoTask(content);
+                    addParamsToTask();
                 } else {
                     addSuitetoTask(content);
                 }
index 757d658..c9672fe 100644 (file)
@@ -20,6 +20,7 @@ angular.module('yardStickGui2App')
                 $scope.constructTestSuit = constructTestSuit;
                 $scope.constructTestCase = constructTestCase;
                 $scope.getTestDeatil = getTestDeatil;
+                $scope.getTestcaseArgs = getTestcaseArgs;
                 $scope.confirmToServer = confirmToServer;
                 $scope.addEnvToTask = addEnvToTask;
             }
@@ -46,6 +47,8 @@ angular.module('yardStickGui2App')
                             getItemIdDetail($scope.taskDetailData.environment_id);
                         }
 
+                        getTestcaseArgs();
+
                     }
                 }, function(error) {
                     toaster.pop({
@@ -277,7 +280,6 @@ angular.module('yardStickGui2App')
 
             function getTestDeatil() {
 
-
                 if ($scope.selectType.name == 'Test Case') {
                     getTestcaseDetail();
                 } else {
@@ -307,6 +309,29 @@ angular.module('yardStickGui2App')
             }
 
 
+            function getTestcaseArgs(){
+                mainFactory.getTestcaseDetail().get({
+                    'testcasename': $scope.taskDetailData.case_name
+                }).$promise.then(function(resp){
+                    if(resp.status == 1){
+                        $scope.optionalParams = resp.result.args;
+                        var params = $scope.taskDetailData.params;
+                        if(params){
+                            angular.forEach($scope.optionalParams, function(value, name){
+                                if(name in params){
+                                    value.value = params[name];
+                                }
+                            });
+                        }
+                    }else{
+                        mainFactory.errorHandler1(resp);
+                    }
+                }, function(error){
+                    mainFactory.errorHandler2(error);
+                });
+            }
+
+
             function getTestcaseDetail() {
                 mainFactory.getTestcaseDetail().get({
                     'testcasename': $scope.selectCase
@@ -316,15 +341,13 @@ angular.module('yardStickGui2App')
 
                         $scope.displayTable = false;
                         $scope.contentInfo = response.result.testcase;
+                        $scope.optionalParams = response.result.args;
 
+                    }else{
+                        mainFactory.errorHandler1(response);
                     }
                 }, function(error) {
-                    toaster.pop({
-                        type: 'error',
-                        title: 'fail',
-                        body: 'unknow error',
-                        timeout: 3000
-                    });
+                    mainFactory.errorHandler2(error);
                 })
             }
 
@@ -426,12 +449,38 @@ angular.module('yardStickGui2App')
                 if ($scope.selectCase == 'Test Case' || $scope.taskDetailData.suite == false) {
 
                     addCasetoTask(content);
+                    addParamsToTask();
                 } else {
                     addSuitetoTask(content);
                 }
             }
 
 
+            function addParamsToTask(){
+                var params = {}
+                angular.forEach($scope.optionalParams, function(value, name){
+                    if(value.value){
+                        params[name] = value.value;
+                    }
+                });
+
+                mainFactory.taskAddParams().put({
+                    'taskId': $stateParams.taskId,
+                    'action': 'add_params',
+                    'args': {
+                        'params': params
+                    }
+                }).$promise.then(function(resp) {
+                    if (resp.status == 1) {
+                    } else {
+                        mainFactory.errorHandler1(resp);
+                    }
+                }, function(error) {
+                    mainFactory.errorHandler2(error);
+                })
+            }
+
+
             function addEnvToTask() {
 
                 mainFactory.taskAddEnv().put({
index 16e9c81..f753693 100644 (file)
@@ -221,6 +221,14 @@ angular.module('yardStickGui2App')
                     }
                 })
             },
+
+            taskAddParams: function() {
+                return $resource(Base_URL + '/api/v2/yardstick/tasks/:taskId', { taskId: "@taskId" }, {
+                    'put': {
+                        method: 'PUT'
+                    }
+                })
+            },
             //delete operate
             deleteEnv: function() {
                 return $resource(Base_URL + '/api/v2/yardstick/environments/:env_id', { env_id: '@env_id' }, {
index 2d7f1dc..ab6ff0c 100644 (file)
             </div>
         </div>
 
-        <div ng-show="displayTable==false">
-            <textarea ng-model="contentInfo" spellcheck="false">
-
-
-            </textarea>
-
 
+        <div ng-show="displayTable==false" style="display:flex;flex-direction:row;justify-content:space-between;margin-top:10px;">
+            <textarea class="col-md-8" ng-model="contentInfo" style="margin-top:5px;" spellcheck="false"></textarea>
+            <div class="col-md-4" style="border:1px solid #e8e8e8;margin-top:5px;margin-left:10px;padding-top:30px;">
+                <h4>Optional Paramters:</h4>
+                <form class="form-horizontal col-md-offset-2" style="margin-top:20px">
+                    <div ng-repeat="(name, value) in optionalParams" class="form-group">
+                        <label for="param{{$index}}" class="col-md-5" style="font-weight:normal;">{{ name }}:</label>
+                        <div class="col-md-5">
+                            <input type="text" ng-model="value.value" class="form-control" id="param{{$index}}">
+                        </div>
+                    </div>
+                </form>
+            </div>
         </div>
 
 
index d12df4b..24b3d94 100644 (file)
                 <button class="btn btn-default" style="float:right" ng-disabled="sourceShow==null" ng-click="confirmToServer(contentInfo,taskDetailData.content)">Confirm</button>
             </div>
 
-
-            <textarea ng-model="taskDetailData.content" ng-show="sourceShow==false" style="margin-top:5px;" spellcheck="false">
-
-
-            </textarea>
+            <div ng-show="sourceShow==false" style="display:flex;flex-direction:row;justify-content:space-between;margin-top:10px;">
+                <textarea class="col-md-8" ng-model="taskDetailData.content" style="margin-top:5px;" spellcheck="false"></textarea>
+                <div class="col-md-4" style="border:1px solid #e8e8e8;margin-top:5px;margin-left:10px;padding-top:30px;">
+                    <h4>Optional Paramters:</h4>
+                    <form class="form-horizontal col-md-offset-2" style="margin-top:20px">
+                        <div ng-repeat="(name, value) in optionalParams" class="form-group">
+                            <label for="param{{$index}}" class="col-md-5" style="font-weight:normal;">{{ name }}:</label>
+                            <div class="col-md-5">
+                                <input type="text" ng-model="value.value" class="form-control" id="param{{$index}}">
+                            </div>
+                        </div>
+                    </form>
+                </div>
+            </div>
 
             <div ng-show="sourceShow==true">
                 <div style="display:flex;flex-direction:row">
 
                 <div ng-show="displayTable==false">
                     <textarea ng-model="contentInfo" spellcheck="false">
-            </textarea>
-
-
+                    </textarea>
                 </div>
             </div>