You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eagle.apache.org by ji...@apache.org on 2016/11/03 02:27:31 UTC
incubator-eagle git commit: [EAGLE-720] Policy edit ui auto generate
description
Repository: incubator-eagle
Updated Branches:
refs/heads/master 8beda32da -> 2bc25969a
[EAGLE-720] Policy edit ui auto generate description
Policy edit ui auto generate description
Author: zombieJ <sm...@gmail.com>
Closes #600 from zombieJ/EAGLE-720.
Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/2bc25969
Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/2bc25969
Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/2bc25969
Branch: refs/heads/master
Commit: 2bc25969a14972a4922270acba536798d49d96da
Parents: 8beda32
Author: zombieJ <sm...@gmail.com>
Authored: Thu Nov 3 10:27:17 2016 +0800
Committer: zombieJ <sm...@gmail.com>
Committed: Thu Nov 3 10:27:17 2016 +0800
----------------------------------------------------------------------
.../partials/alert/policyEdit/advancedMode.html | 25 +-
.../dev/public/js/ctrls/alertEditCtrl.bac.js | 297 -------------------
.../app/dev/public/js/ctrls/alertEditCtrl.js | 43 ++-
3 files changed, 43 insertions(+), 322 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/2bc25969/eagle-server/src/main/webapp/app/dev/partials/alert/policyEdit/advancedMode.html
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/webapp/app/dev/partials/alert/policyEdit/advancedMode.html b/eagle-server/src/main/webapp/app/dev/partials/alert/policyEdit/advancedMode.html
index 5097d33..c436ae7 100644
--- a/eagle-server/src/main/webapp/app/dev/partials/alert/policyEdit/advancedMode.html
+++ b/eagle-server/src/main/webapp/app/dev/partials/alert/policyEdit/advancedMode.html
@@ -41,11 +41,19 @@
<input type="text" class="form-control" placeholder="Search..." ng-model="searchSourceKey" />
<span class="fa fa-search"></span>
</div>
- <div ng-repeat="(app, streams) in getSearchApplication() track by app" class="policy-app-list">
+ <p>
+ Group Type:
+ <a ng-class="{'text-bold': searchType === 'app'}" ng-click="searchType = 'app'">Application</a>
+ /
+ <a ng-class="{'text-bold': searchType === 'site'}" ng-click="searchType = 'site'">Site</a>
+ </p>
+
+ <p ng-hide="getSearchApplication()" class="text-warning">No stream match</p>
+ <div ng-show="getSearchApplication()" ng-repeat="(app, streams) in getSearchApplication() track by app" class="policy-app-list">
<a data-toggle="collapse" href="[data-id='SP_{{app}}']">
<strong>{{app}}</strong>
</a>
- <ul data-id="SP_{{app}}" class="collapse in list-unstyled">
+ <ul data-id="SP_{{app}}" class="collapse list-unstyled">
<li ng-repeat="stream in streams track by stream.streamId">
<a data-toggle="collapse" href="[data-id='SP_{{app}}_{{stream.streamId}}']">
<span class="fa fa-{{isInputStreamSelected(stream.streamId) ? 'check-square' : 'square'}}"></span>
@@ -91,14 +99,14 @@
<div class="col-md-12">
<div class="form-group">
<label>Name *</label>
- <input type="text" style="text-transform:uppercase" class="form-control" ng-model="policy.name" ng-readonly="!newPolicy" ng-disabled="policyLock" />
+ <input type="text" class="form-control" ng-model="policy.name" ng-readonly="!newPolicy" ng-disabled="policyLock" />
</div>
</div>
</div>
<div class="form-group">
<label>Description</label>
- <textarea class="form-control" ng-model="policy.description" rows="2" ng-disabled="policyLock"></textarea>
+ <textarea class="form-control" ng-model="policy.description" ng-change="autoPolicyDescription = false" rows="2" ng-disabled="policyLock"></textarea>
</div>
<!--label>
@@ -130,13 +138,9 @@
<p class="text-danger">{{definitionMessage}}</p>
</div>
- <!--<label>-->
- <!--Alert Stream-->
- <!--</label>-->
-
- <p class="text-danger" ng-if="policy.outputStreams.length === 0"><i class="fa fa-fw fa-warning"></i> No alert stream defined</p>
<ul class="sm-padding">
+ <li class="text-danger" ng-if="policy.outputStreams.length === 0"><i class="fa fa-fw fa-warning"></i> No alert stream defined</li>
<li ng-repeat="stream in outputStreams track by $index">
<label>
<input type="checkbox" ng-checked="isOutputStreamSelected(stream)" ng-click="checkOutputStream(stream)" ng-disabled="policyLock" />
@@ -149,9 +153,8 @@
Publish Alerts
</label>
- <p class="text-danger" ng-if="policyPublisherList.length === 0"><i class="fa fa-fw fa-warning"></i> No alert publisher defined </p>
-
<ul class="sm-padding">
+ <li class="text-danger" ng-if="policyPublisherList.length === 0"><i class="fa fa-fw fa-warning"></i> No alert publisher defined </li>
<li ng-repeat="publisher in policyPublisherList track by $index">
<span>
[<a class="fa fa-times" ng-click="removePublisher(publisher)"></a>]
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/2bc25969/eagle-server/src/main/webapp/app/dev/public/js/ctrls/alertEditCtrl.bac.js
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/webapp/app/dev/public/js/ctrls/alertEditCtrl.bac.js b/eagle-server/src/main/webapp/app/dev/public/js/ctrls/alertEditCtrl.bac.js
deleted file mode 100644
index ce32013..0000000
--- a/eagle-server/src/main/webapp/app/dev/public/js/ctrls/alertEditCtrl.bac.js
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- * 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.
- */
-
-(function() {
- 'use strict';
-
- var eagleControllers = angular.module('eagleControllers');
-
- var publisherTypes = {
- 'org.apache.eagle.alert.engine.publisher.impl.AlertEmailPublisher': ["subject", "template", "sender", "recipients", "mail.smtp.host", "connection", "mail.smtp.port"],
- 'org.apache.eagle.alert.engine.publisher.impl.AlertKafkaPublisher': ["topic", "kafka_broker", "rawAlertNamespaceLabel", "rawAlertNamespaceValue"],
- 'org.apache.eagle.alert.engine.publisher.impl.AlertSlackPublisher': ["token", "channels", "severitys", "urltemplate"]
- };
-
- // ======================================================================================
- // = Policy Create =
- // ======================================================================================
- function connectPolicyEditController(entity, args) {
- var newArgs = [entity];
- Array.prototype.push.apply(newArgs, args);
- /* jshint validthis: true */
- policyEditController.apply(this, newArgs);
- }
-
- eagleControllers.controller('policyCreateCtrl', function ($scope, $wrapState, PageConfig, Entity) {
- PageConfig.subTitle = "Define Alert Policy";
- connectPolicyEditController({}, arguments);
- });
- eagleControllers.controller('policyEditCtrl', function ($scope, $wrapState, PageConfig, Entity) {
- PageConfig.subTitle = "Edit Alert Policy";
- var args = arguments;
-
- // TODO: Wait for backend data update
- $scope.policyList = Entity.queryMetadata("policies/" + encodeURIComponent($wrapState.param.name));
-
- $scope.policyList._promise.then(function () {
- var policy = $scope.policyList[0];
-
- if(policy) {
- connectPolicyEditController(policy, args);
- } else {
- $.dialog({
- title: "OPS",
- content: "Policy '" + $wrapState.param.name + "' not found!"
- }, function () {
- $wrapState.go("policyList");
- });
- }
- });
- });
-
- function policyEditController(policy, $scope, $wrapState, PageConfig, Entity) {
- $scope.newPolicy = !policy.name;
- $scope.policyLock = false;
-
- $scope.publisherTypes = publisherTypes;
-
- $scope.selectedApplication = null;
- $scope.selectedStream = null;
-
- $scope.outputStream = "";
-
- $scope.partitionStream = null;
- $scope.partitionType = "GROUPBY";
- $scope.partitionColumns = {};
-
- $scope.publisherType = "org.apache.eagle.alert.engine.publisher.impl.AlertEmailPublisher";
- $scope.publisher = {
- dedupIntervalMin: "PT1M"
- };
- $scope.publisherProps = {};
-
- $scope.policy = common.merge({
- name: "",
- description: "",
- inputStreams: [],
- outputStreams: [],
- definition: {
- type: "siddhi",
- value: ""
- },
- partitionSpec: [],
- parallelismHint: 2
- }, policy);
-
- $scope.policy.definition = {
- type: $scope.policy.definition.type,
- value: $scope.policy.definition.value
- };
-
- console.log("[Policy]", $scope.policy);
-
- // =========================================================
- // = Check Logic =
- // =========================================================
- $scope.checkBasicInfo = function () {
- return !!$scope.policy.name;
- };
-
- $scope.checkAlertStream = function () {
- return $scope.checkBasicInfo() &&
- $scope.policy.inputStreams.length > 0 &&
- $scope.policy.outputStreams.length > 0;
- };
-
- $scope.checkNumber = function (str) {
- str = (str + "").trim();
- return str !== "" && common.number.isNumber(Number(str));
- };
-
- $scope.checkDefinition = function () {
- return $scope.checkAlertStream() &&
- !!$scope.policy.definition.value.trim() &&
- $scope.policy.parallelismHint > 0;
- };
-
- // =========================================================
- // = Stream =
- // =========================================================
- $scope.refreshStreamSelect = function() {
- var appStreamList;
-
- if(!$scope.selectedApplication) {
- $scope.selectedApplication = common.getKeys($scope.applications)[0];
- }
-
- appStreamList = $scope.applications[$scope.selectedApplication] || [];
- if(!common.array.find($scope.selectedStream, appStreamList)) {
- $scope.selectedStream = appStreamList[0].streamId;
- }
- if(!common.array.find($scope.partitionStream, $scope.policy.inputStreams)) {
- $scope.partitionStream = $scope.policy.inputStreams[0];
- }
- };
-
- $scope.streamList = Entity.queryMetadata("streams");
- $scope.streamList._then(function () {
- $scope.applications = {};
-
- $.each($scope.streamList, function (i, stream) {
- var list = $scope.applications[stream.dataSource] = $scope.applications[stream.dataSource] || [];
- list.push(stream);
- });
-
- console.log("=>", $scope.streamList);
- $scope.refreshStreamSelect();
- });
-
- $scope.getStreamList = function () {
- return common.array.minus($scope.streamList, $scope.policy.inputStreams, "streamId", "");
- };
-
- $scope.addStream = function () {
- $scope.policy.inputStreams.push($scope.selectedStream);
- $scope.refreshStreamSelect();
- };
-
- $scope.removeStream = function (streamId) {
- $scope.policy.inputStreams = common.array.remove(streamId, $scope.policy.inputStreams);
- $scope.refreshStreamSelect();
- };
-
- $scope.checkAddStream = function (streamId) {
- return !common.array.find(streamId, $scope.policy.inputStreams);
- };
-
- $scope.addOutputStream = function () {
- $scope.policy.outputStreams.push($scope.outputStream);
- $scope.outputStream = "";
- };
-
- $scope.removeOutputStream = function (streamId) {
- $scope.policy.outputStreams = common.array.remove(streamId, $scope.policy.outputStreams);
- };
-
- $scope.checkAddOutputStream = function () {
- return $scope.outputStream !== "" && !common.array.find($scope.outputStream, $scope.policy.outputStreams);
- };
-
- // =========================================================
- // = Definition =
- // =========================================================
- $scope.getPartitionColumns = function () {
- var stream = common.array.find($scope.partitionStream, $scope.streamList, "streamId");
- return (stream || {}).columns;
- };
-
- $scope.addPartition = function () {
- $scope.policy.partitionSpec.push({
- streamId: $scope.partitionStream,
- type: $scope.partitionType,
- columns: $.map($scope.getPartitionColumns(), function (column) {
- return $scope.partitionColumns[column.name] ? column.name : null;
- })
- });
-
- $scope.partitionColumns = {};
- };
-
- $scope.checkAddPartition = function () {
- var match = false;
-
- $.each($scope.getPartitionColumns(), function (i, column) {
- if($scope.partitionColumns[column.name]) {
- match = true;
- return false;
- }
- });
-
- return match;
- };
-
- $scope.removePartition = function (partition) {
- $scope.policy.partitionSpec = common.array.remove(partition, $scope.policy.partitionSpec);
- };
-
- // =========================================================
- // = Publisher =
- // =========================================================
- $scope.publisherList = [];
-
- if(!$scope.newPolicy) {
- $scope.publisherList = Entity.queryMetadata("policies/" + encodeURIComponent($scope.policy.name) + "/publishments");
- }
-
- $scope.addPublisher = function () {
- var publisherProps = {};
- $.each($scope.publisherTypes[$scope.publisherType], function (i, field) {
- publisherProps[field] = $scope.publisherProps[field] || "";
- });
- $scope.publisherList.push({
- name: $scope.publisher.name,
- type: $scope.publisherType,
- policyIds: [$scope.policy.name],
- properties: publisherProps,
- dedupIntervalMin: $scope.publisher.dedupIntervalMin,
- serializer : "org.apache.eagle.alert.engine.publisher.impl.StringEventSerializer"
- });
- $scope.publisher = {
- dedupIntervalMin: "PT1M"
- };
- $scope.publisherProps = {};
- };
-
- $scope.removePublisher = function (publisher) {
- $scope.publisherList = common.array.remove(publisher, $scope.publisherList);
- };
-
- $scope.checkAddPublisher = function () {
- return $scope.publisher.name &&
- !common.array.find($scope.publisher.name, $scope.publisherList, "name");
- };
-
- // =========================================================
- // = Policy =
- // =========================================================
- $scope.createPolicy = function () {
- // TODO: Need check the policy or publisher exist.
-
- $scope.policyLock = true;
-
- var policyPromise = Entity.create("metadata/policies", $scope.policy)._promise;
- var publisherPromiseList = $.map($scope.publisherList, function (publisher) {
- return Entity.create("metadata/publishments", publisher)._promise;
- });
- common.deferred.all(publisherPromiseList.concat(policyPromise)).then(function () {
- $.dialog({
- title: "Done",
- content: "Close dialog to go to the policy detail page."
- }, function () {
- $wrapState.go("policyDetail", {name: $scope.policy.name});
- });
- }, function (failedList) {
- $.dialog({
- title: "OPS",
- content: $("<pre>").text(JSON.stringify(failedList, null, "\t"))
- });
- $scope.policyLock = false;
- });
- };
- }
-})();
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/2bc25969/eagle-server/src/main/webapp/app/dev/public/js/ctrls/alertEditCtrl.js
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/webapp/app/dev/public/js/ctrls/alertEditCtrl.js b/eagle-server/src/main/webapp/app/dev/public/js/ctrls/alertEditCtrl.js
index 1c1e018..ed61919 100644
--- a/eagle-server/src/main/webapp/app/dev/public/js/ctrls/alertEditCtrl.js
+++ b/eagle-server/src/main/webapp/app/dev/public/js/ctrls/alertEditCtrl.js
@@ -97,11 +97,15 @@
}, $scope.policy);
console.log("[Policy]", $scope.policy);
+ var cacheSearchType;
var cacheSearchSourceKey;
var searchApplications;
+
+ $scope.searchType = "app";
$scope.searchSourceKey = "";
$scope.applications = {};
$scope.newPolicy = !$scope.policy.name;
+ $scope.autoPolicyDescription = $scope.newPolicy && !$scope.policy.description;
PageConfig.navPath = [
{title: "Policy List", path: "/policies"},
@@ -120,26 +124,29 @@
// = Input Stream =
// ==============================================================
$scope.getSearchApplication = function() {
- if(cacheSearchSourceKey !== $scope.searchSourceKey.toUpperCase()) {
+ if(cacheSearchSourceKey !== $scope.searchSourceKey.toUpperCase() || cacheSearchType !== $scope.searchType) {
+ var match = false;
cacheSearchSourceKey = $scope.searchSourceKey.toUpperCase();
+ cacheSearchType = $scope.searchType;
searchApplications = {};
$.each($scope.applications, function (appName, streams) {
- if(appName.toUpperCase().indexOf(cacheSearchSourceKey) >= 0) {
- searchApplications[appName] = streams;
- } else {
- var streamList = [];
- $.each(streams, function (i, stream) {
- if(stream.streamId.toUpperCase().indexOf(cacheSearchSourceKey) >= 0) {
- streamList.push(stream);
- }
- });
-
- if(streamList.length > 0) {
- searchApplications[appName] = streamList;
+ $.each(streams, function (i, stream) {
+ var groupName = cacheSearchType === "app" ? stream.dataSource : stream.siteId;
+ if(
+ groupName.toUpperCase().indexOf(cacheSearchSourceKey) >= 0 ||
+ stream.streamId.toUpperCase().indexOf(cacheSearchSourceKey) >= 0
+ ) {
+ match = true;
+ var group = searchApplications[groupName] = searchApplications[groupName] || [];
+ group.push(stream);
}
- }
+ });
});
+
+ if(!match) {
+ searchApplications = null;
+ }
}
return searchApplications;
};
@@ -172,6 +179,12 @@
// ==============================================================
// = Definition =
// ==============================================================
+ function autoDescription() {
+ if(!$scope.autoPolicyDescription) return;
+
+ $scope.policy.description = "Policy for " + $scope.policy.outputStreams.join(", ");
+ }
+
var checkPromise;
$scope.definitionMessage = "";
$scope.checkDefinition = function () {
@@ -194,6 +207,7 @@
});
$scope.policy.outputStreams = outputStreams.concat();
$scope.outputStreams = outputStreams;
+ autoDescription();
// Partition
$scope.policy.partitionSpec = data.policyExecutionPlan.streamPartitions;
@@ -220,6 +234,7 @@
} else {
$scope.policy.outputStreams.push(streamId);
}
+ autoDescription();
};
// ==============================================================