You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by ni...@apache.org on 2019/08/29 15:04:49 UTC

[kylin] branch master updated: KYLIN-4149 Allow user to edit streaming v2 table's kafka cluster address and topic name

This is an automated email from the ASF dual-hosted git repository.

nic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kylin.git


The following commit(s) were added to refs/heads/master by this push:
     new dee88f9  KYLIN-4149 Allow user to edit streaming v2 table's kafka cluster address and topic name
dee88f9 is described below

commit dee88f9aa572525cef80ee2cc37ca67ad2dd8f00
Author: luguosheng1314 <55...@qq.com>
AuthorDate: Tue Aug 27 18:54:09 2019 +0800

    KYLIN-4149 Allow user to edit streaming v2 table's kafka cluster address and topic name
---
 webapp/app/js/controllers/sourceMeta.js            | 114 +++++++++++++++++----
 webapp/app/js/services/streaming.js                |   1 +
 .../partials/tables/streamingv2_config_edit.html   |  76 ++++++++++++++
 webapp/app/partials/tables/table_detail.html       |   5 +
 webapp/app/partials/tables/table_load.html         |   4 +
 5 files changed, 180 insertions(+), 20 deletions(-)

diff --git a/webapp/app/js/controllers/sourceMeta.js b/webapp/app/js/controllers/sourceMeta.js
index 32a5c6b..63887c1 100755
--- a/webapp/app/js/controllers/sourceMeta.js
+++ b/webapp/app/js/controllers/sourceMeta.js
@@ -483,6 +483,31 @@ KylinApp
 
     }
 
+    $scope.editStreamingConfigV2 = function(streamingConfig){
+      var modalInstance = $modal.open({
+        templateUrl: 'editStreamingTableV2.html',
+        controller: EditStreamingSourceV2Ctrl,
+        backdrop : 'static',
+        resolve: {
+          streamingConfig: function () {
+            return streamingConfig;
+          },
+          projectName: function () {
+            return $scope.projectModel.selectedProject;
+          },
+          scope: function () {
+            return $scope;
+          }
+        }
+      });
+
+      modalInstance.result.then(function () {
+        $scope.$broadcast('StreamingConfigEdited');
+      }, function () {
+        $scope.$broadcast('StreamingConfigEdited');
+      });
+    }
+
     //streaming model
     $scope.openStreamingSourceModal = function () {
       if(!$scope.projectModel.selectedProject){
@@ -506,7 +531,19 @@ KylinApp
         }
       });
     };
-
+    function bootstrapServerValidation(bootstrapServers) {
+      var flag = false;
+      if (bootstrapServers && bootstrapServers.length > 0) {
+        angular.forEach(bootstrapServers, function(bootstrapServer, ind) {
+          if (!bootstrapServer.host || !bootstrapServer.port || bootstrapServer.host.length === 0 || bootstrapServer.port.length === 0) {
+            flag = true;
+          }
+        });
+      } else {
+        flag = true;
+      }
+      return flag;
+    };
     var EditStreamingSourceCtrl = function ($scope, $interpolate, $templateCache, tableName, $modalInstance, tableNames, MessageService, projectName, scope, tableConfig,cubeConfig,StreamingModel,StreamingService) {
 
       $scope.state = {
@@ -529,12 +566,6 @@ KylinApp
         $scope.kafkaMeta = val;
       }
 
-      $scope.streamingResultTmpl = function (notification) {
-        // Get the static notification template.
-        var tmpl = notification.type == 'success' ? 'streamingResultSuccess.html' : 'streamingResultError.html';
-        return $interpolate($templateCache.get(tmpl))(notification);
-      };
-
       $scope.updateStreamingSchema = function(){
         StreamingService.update({}, {
           project: $scope.projectName,
@@ -578,6 +609,61 @@ KylinApp
       }
 
     }
+
+    var EditStreamingSourceV2Ctrl = function ($scope, ResponseUtil, $modalInstance, projectName,StreamingServiceV2, streamingConfig) {
+      $scope.cancel = function () {
+        $modalInstance.dismiss('cancel');
+      };
+      $scope.streamingConfig = streamingConfig;
+      $scope.streamingConfig.properties.bootstrapServers = streamingConfig.properties['bootstrap.servers'].split(',').map(function(address){
+        return {
+          host: address.split(':')[0],
+          port: +address.split(':')[1]
+        }
+      })
+      $scope.addBootstrapServer = function() {
+        if (!$scope.streamingConfig.properties.bootstrapServers) {
+          $scope.streamingConfig.properties.bootstrapServers = [];
+        }
+        $scope.streamingConfig.properties.bootstrapServers.push({host: '', port: 9092});
+      }
+      $scope.removeBootstrapServer = function(index) {
+        $scope.streamingConfig.properties.bootstrapServers.splice(index, 1);
+      };
+      $scope.projectName = projectName;
+      $scope.updateStreamingMeta = function(val){
+        $scope.streamingMeta = val;
+      }
+      $scope.updateKafkaMeta = function(val){
+        $scope.kafkaMeta = val;
+      }
+      $scope.bootstrapServerValidation = bootstrapServerValidation
+      $scope.updateStreamingV2Config = function(){
+        loadingRequest.show();
+        $scope.streamingConfig.properties['bootstrap.servers'] = $scope.streamingConfig.properties.bootstrapServers.map(function(address){
+          return address.host + ':' + address.port;
+        }).join(',');
+        delete $scope.streamingConfig.properties.bootstrapServers;
+        var updateConfig = {
+          project: $scope.projectName,
+          streamingConfig: JSON.stringify($scope.streamingConfig)
+        }
+        StreamingServiceV2.update({}, updateConfig, function (request) {
+          if (request.successful) {
+            MessageBox.successNotify('Updated the streaming successfully.');
+            $scope.cancel();
+          } else {
+            ResponseUtil.handleError({
+              data: {exception: request.message}
+            })
+          }
+          loadingRequest.hide();
+        }, function (e) {
+          ResponseUtil.handleError(e)
+          loadingRequest.hide();
+        })
+      }
+    }
     // 推断列的类型
     function checkColumnValType(val,key){
       var defaultType;
@@ -1002,19 +1088,7 @@ KylinApp
         $scope.streamingConfig.properties.bootstrapServers.push({host: '', port: '9092'});
       }
 
-      $scope.bootstrapServerValidation = function(bootstrapServers) {
-        var flag = false;
-        if (bootstrapServers && bootstrapServers.length > 0) {
-          angular.forEach(bootstrapServers, function(bootstrapServer, ind) {
-            if (!bootstrapServer.host || !bootstrapServer.port || bootstrapServer.host.length === 0 || bootstrapServer.port.length === 0) {
-              flag = true;
-            }
-          });
-        } else {
-          flag = true;
-        }
-        return flag;
-      };
+      $scope.bootstrapServerValidation = bootstrapServerValidation;
 
       // streaming table
       $scope.streaming = {
diff --git a/webapp/app/js/services/streaming.js b/webapp/app/js/services/streaming.js
index b5c2900..1c05e8b 100644
--- a/webapp/app/js/services/streaming.js
+++ b/webapp/app/js/services/streaming.js
@@ -32,6 +32,7 @@ KylinApp.factory('StreamingServiceV2', ['$resource', function ($resource, config
         'getConfig': {method: 'GET',params: {action:'getConfig'},isArray:true},
         'getParserTemplate': {method: 'GET', params: {propName:'parserTemplate'}, isArray: false},
         save: {method: 'POST', params: {}, isArray: false},
+        update: {method: 'PUT', params: {action: 'updateConfig'}, isArray: false}
     });
 }]);
 
diff --git a/webapp/app/partials/tables/streamingv2_config_edit.html b/webapp/app/partials/tables/streamingv2_config_edit.html
new file mode 100644
index 0000000..c4aeee7
--- /dev/null
+++ b/webapp/app/partials/tables/streamingv2_config_edit.html
@@ -0,0 +1,76 @@
+<!--
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+-->
+<form class="form-horizontal" name="kafka_config_from_v2" novalidate>
+  <div class="modal-header">
+    <div class="box-header">
+      <h3 class="box-title">Kafka Config Edit</h3>
+      <div class="box-tools pull-right">
+        <button type="button" class="btn btn-box-tool" ng-click="cancel()"><i class="fa fa-times"></i></button>
+      </div>
+    </div>
+  </div>
+  <div class="modal-body streaming-source">
+    <div class="form-group required row">
+      <label for="topic" class="col-sm-3 control-label font-color-default">Topic</label>
+      <div class="col-sm-6">
+        <input type="text" class="form-control" id="topic" ng-model="streamingConfig.properties.topic" name="topic" placeholder="Input Kafka Topic" required autofocus>
+        <small class="help-block" ng-show="kafka_config_from_v2.topic.$error.required && kafka_config_from_v2.topic.$dirty">
+          Topic is empty
+        </small>
+      </div>
+    </div>
+    <div class="form-group required row">
+      <label class="col-sm-3 control-label font-color-default">Bootstrap Servers</label>
+      <div class="col-sm-9">
+        <div class="row">
+          <div class="col-sm-5 font-color-default text-center" style="font-weight:bolder;">Host</div>
+          <div class="col-sm-3 font-color-default text-center" style="font-weight:bolder;">Port</div>
+          <div class="col-sm-2 font-color-default text-center" style="font-weight:bolder;">Action</div>
+        </div>
+        <div ng-repeat="bootstrapServer in streamingConfig.properties.bootstrapServers track by $index" class="row"  style="margin-top:5px;">
+          <div class="col-sm-5">
+            <input type="text" class="form-control" ng-model="bootstrapServer.host" name="host" placeholder="Enter Bootstrap Server Host" required autofocus>
+          </div>
+          <div class="col-sm-3">
+            <input type="number" class="form-control" ng-model="bootstrapServer.port" name="port" placeholder="Enter Bootstrap Server Port" required>
+          </div>
+          <div class="col-sm-2 text-center">
+            <i class="fa fa-minus" style="margin-top:10px;cursor:pointer;" ng-click="removeBootstrapServer($index)"></i>
+          </div>
+        </div>
+        <div class="row">
+          <div class="col-sm-offset-8 col-sm-2 text-center">
+            <i class="fa fa-plus" style="margin-top:10px;cursor:pointer;" ng-click="addBootstrapServer()"></i>
+          </div>
+        </div>
+      </div>
+    </div>
+  </div>
+  <div class="modal-footer">
+    <div class="row">
+      <div class="col-sm-4 col-sm-offset-8">
+        <button id="nextButton" class="btn"  ng-click="cancel()">
+          Cancel
+        </button>
+        <button id="nextButton" class="btn btn-primary"  ng-click="updateStreamingV2Config()"  ng-disabled="kafka_config_from_v2.topic.$error.required || bootstrapServerValidation(streamingConfig.properties.bootstrapServers)">
+          Save
+        </button>
+      </div>
+    </div>
+  </div>
+</form>
diff --git a/webapp/app/partials/tables/table_detail.html b/webapp/app/partials/tables/table_detail.html
index 0cf4ed8..e1a3806 100644
--- a/webapp/app/partials/tables/table_detail.html
+++ b/webapp/app/partials/tables/table_detail.html
@@ -179,6 +179,11 @@
         <!--streamingV2-->
         <div id="streamingV2" ng-if="values(tableConfig.streamingSourceType).indexOf(tableModel.selectedSrcTable.source_type) > -1" class="tab-pane" ng-controller="StreamConfigDisplayCtrl">
           <div class="table-responsive">
+            <div class="col-xs-12 pdb-12 pdt-12" ng-if="userService.hasRole('ROLE_ADMIN')">
+              <div class="ofh">
+                <a class="btn btn-info floatR" ng-click="editStreamingConfigV2(currentStreamingConfig)"><i class="fa fa-edit"></i> Edit</a>
+              </div>
+            </div>
             <table class="table">
               <tbody>
                 <tr>
diff --git a/webapp/app/partials/tables/table_load.html b/webapp/app/partials/tables/table_load.html
index 309fa98..ffaff83 100644
--- a/webapp/app/partials/tables/table_load.html
+++ b/webapp/app/partials/tables/table_load.html
@@ -77,6 +77,9 @@
   <div ng-show="steps.curStep==1" ng-include="'partials/tables/loadStreamingSourceConfig.html'"></div>
   <div ng-show="steps.curStep==2" ng-include="'partials/tables/loadStreamingTableConfig.html'"></div>
 </script>
+<script type="text/ng-template" id="editStreamingTableV2.html">
+  <div ng-include="'partials/tables/streamingv2_config_edit.html'"></div>
+</script>
 
 <script type="text/ng-template" id="editStreamingSource.html">
 
@@ -108,6 +111,7 @@
   </div>
 </script>
 
+
 <script type="text/ng-template" id="reloadTable.html">
   <div class="modal-header">
     <h4>Reload Table Metadata</h4>